OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "ios/shared/chrome/browser/ui/coordinators/browser_coordinator+internal.
h" | 5 #import "ios/shared/chrome/browser/ui/coordinators/browser_coordinator+internal.
h" |
6 #import "ios/shared/chrome/browser/ui/coordinators/browser_coordinator.h" | 6 #import "ios/shared/chrome/browser/ui/coordinators/browser_coordinator.h" |
7 | 7 |
8 #import "ios/shared/chrome/browser/ui/coordinators/browser_coordinator_test.h" | 8 #import "ios/shared/chrome/browser/ui/coordinators/browser_coordinator_test.h" |
9 | 9 |
10 #if !defined(__has_feature) || !__has_feature(objc_arc) | 10 #if !defined(__has_feature) || !__has_feature(objc_arc) |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 TestCoordinator* otherParent = [[TestCoordinator alloc] init]; | 114 TestCoordinator* otherParent = [[TestCoordinator alloc] init]; |
115 TestCoordinator* otherChild = [[TestCoordinator alloc] init]; | 115 TestCoordinator* otherChild = [[TestCoordinator alloc] init]; |
116 [otherParent addChildCoordinator:otherChild]; | 116 [otherParent addChildCoordinator:otherChild]; |
117 | 117 |
118 // -removeChildCoordinator of a non-child should have no affect. | 118 // -removeChildCoordinator of a non-child should have no affect. |
119 [parent removeChildCoordinator:otherChild]; | 119 [parent removeChildCoordinator:otherChild]; |
120 EXPECT_TRUE([otherParent.children containsObject:otherChild]); | 120 EXPECT_TRUE([otherParent.children containsObject:otherChild]); |
121 EXPECT_EQ(otherParent, otherChild.parentCoordinator); | 121 EXPECT_EQ(otherParent, otherChild.parentCoordinator); |
122 } | 122 } |
123 | 123 |
124 TEST_F(BrowserCoordinatorTest, TestOverlay) { | |
125 TestCoordinator* parent = [[TestCoordinator alloc] init]; | |
126 TestCoordinator* child = [[TestCoordinator alloc] init]; | |
127 TestCoordinator* grandchild = [[TestCoordinator alloc] init]; | |
128 TestCoordinator* overlay = [[TestCoordinator alloc] init]; | |
129 TestCoordinator* secondOverlay = [[TestCoordinator alloc] init]; | |
130 | |
131 EXPECT_TRUE([parent canAddOverlayCoordinator:overlay]); | |
132 [parent addChildCoordinator:child]; | |
133 [child addChildCoordinator:grandchild]; | |
134 EXPECT_FALSE([parent canAddOverlayCoordinator:overlay]); | |
135 EXPECT_FALSE([child canAddOverlayCoordinator:overlay]); | |
136 EXPECT_TRUE([grandchild canAddOverlayCoordinator:overlay]); | |
137 EXPECT_FALSE([grandchild canAddOverlayCoordinator:child]); | |
138 | |
139 EXPECT_FALSE(overlay.overlaying); | |
140 [parent addOverlayCoordinator:overlay]; | |
141 EXPECT_TRUE(overlay.overlaying); | |
142 EXPECT_EQ(overlay, parent.overlayCoordinator); | |
143 EXPECT_EQ(overlay, child.overlayCoordinator); | |
144 EXPECT_EQ(overlay, grandchild.overlayCoordinator); | |
145 EXPECT_TRUE([grandchild.children containsObject:overlay]); | |
146 EXPECT_EQ(grandchild, overlay.parentCoordinator); | |
147 | |
148 // Shouldn't be able to add a second overlaying coordinator. | |
149 EXPECT_FALSE([grandchild canAddOverlayCoordinator:secondOverlay]); | |
150 EXPECT_FALSE(secondOverlay.overlaying); | |
151 [parent addOverlayCoordinator:secondOverlay]; | |
152 EXPECT_FALSE(secondOverlay.overlaying); | |
153 | |
154 [child removeOverlayCoordinator]; | |
155 EXPECT_FALSE(overlay.overlaying); | |
156 EXPECT_EQ(nil, parent.overlayCoordinator); | |
157 EXPECT_EQ(nil, child.overlayCoordinator); | |
158 EXPECT_EQ(nil, grandchild.overlayCoordinator); | |
159 EXPECT_FALSE([grandchild.children containsObject:overlay]); | |
160 EXPECT_EQ(nil, overlay.parentCoordinator); | |
161 | |
162 // An implementation that doesn't allow any overlays shouldn't get one. | |
163 NonOverlayableCoordinator* noOverlays = | |
164 [[NonOverlayableCoordinator alloc] init]; | |
165 TestCoordinator* thirdOverlay = [[TestCoordinator alloc] init]; | |
166 | |
167 EXPECT_FALSE([noOverlays canAddOverlayCoordinator:thirdOverlay]); | |
168 EXPECT_FALSE(thirdOverlay.overlaying); | |
169 [noOverlays addOverlayCoordinator:thirdOverlay]; | |
170 EXPECT_FALSE(thirdOverlay.overlaying); | |
171 } | |
172 | |
173 TEST_F(BrowserCoordinatorTest, AddedRemoved) { | 124 TEST_F(BrowserCoordinatorTest, AddedRemoved) { |
174 TestCoordinator* parent = [[TestCoordinator alloc] init]; | 125 TestCoordinator* parent = [[TestCoordinator alloc] init]; |
175 TestCoordinator* child = [[TestCoordinator alloc] init]; | 126 TestCoordinator* child = [[TestCoordinator alloc] init]; |
176 | 127 |
177 // Add to the parent. | 128 // Add to the parent. |
178 EXPECT_FALSE(child.wasAddedCalled); | 129 EXPECT_FALSE(child.wasAddedCalled); |
179 EXPECT_FALSE(child.willBeRemovedCalled); | 130 EXPECT_FALSE(child.willBeRemovedCalled); |
180 [parent addChildCoordinator:child]; | 131 [parent addChildCoordinator:child]; |
181 EXPECT_TRUE(child.wasAddedCalled); | 132 EXPECT_TRUE(child.wasAddedCalled); |
182 EXPECT_FALSE(child.willBeRemovedCalled); | 133 EXPECT_FALSE(child.willBeRemovedCalled); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 TestCoordinator* child = [[TestCoordinator alloc] init]; | 247 TestCoordinator* child = [[TestCoordinator alloc] init]; |
297 TestCoordinator* grandChild1 = [[TestCoordinator alloc] init]; | 248 TestCoordinator* grandChild1 = [[TestCoordinator alloc] init]; |
298 TestCoordinator* grandChild2 = [[TestCoordinator alloc] init]; | 249 TestCoordinator* grandChild2 = [[TestCoordinator alloc] init]; |
299 [child addChildCoordinator:grandChild1]; | 250 [child addChildCoordinator:grandChild1]; |
300 [child addChildCoordinator:grandChild2]; | 251 [child addChildCoordinator:grandChild2]; |
301 [parent addChildCoordinator:child]; | 252 [parent addChildCoordinator:child]; |
302 | 253 |
303 // Remove the child. | 254 // Remove the child. |
304 [parent removeChildCoordinator:child]; | 255 [parent removeChildCoordinator:child]; |
305 } | 256 } |
OLD | NEW |