Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(885)

Unified Diff: ios/clean/chrome/browser/browser_coordinator_unittest.mm

Issue 2626033002: [Clean] Add unittest target and BrowserCoordinator tests. (Closed)
Patch Set: Review feedback. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/clean/chrome/browser/browser_coordinator+internal.h ('k') | ios/clean/chrome/test/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/clean/chrome/browser/browser_coordinator_unittest.mm
diff --git a/ios/clean/chrome/browser/browser_coordinator_unittest.mm b/ios/clean/chrome/browser/browser_coordinator_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..cf9a64e3696296c8936c692a34dafdc609b6df9d
--- /dev/null
+++ b/ios/clean/chrome/browser/browser_coordinator_unittest.mm
@@ -0,0 +1,137 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/clean/chrome/browser/browser_coordinator.h"
+#import "ios/clean/chrome/browser/browser_coordinator+internal.h"
+
+#include "base/logging.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/gtest_mac.h"
+#include "testing/platform_test.h"
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+@interface TestCoordinator : BrowserCoordinator
+@property(nonatomic) UIViewController* viewController;
+@property(nonatomic, copy) void (^stopHandler)();
+@end
+
+@implementation TestCoordinator
+@synthesize viewController = _viewController;
+@synthesize stopHandler = _stopHandler;
+
+- (instancetype)init {
+ if (!(self = [super init]))
+ return nil;
+
+ _viewController = [[UIViewController alloc] init];
+ return self;
+}
+
+- (void)stop {
+ if (self.stopHandler)
+ self.stopHandler();
+}
+
+@end
+
+@interface NonOverlayableCoordinator : TestCoordinator
+@end
+
+@implementation NonOverlayableCoordinator
+
+- (BOOL)canAddOverlayCoordinator:(BrowserCoordinator*)overlayCoordinator {
+ return NO;
+}
+
+@end
+
+TEST(BrowserCoordinatorTest, TestStopOnDealloc) {
+ __block BOOL called = NO;
+
+ {
+ TestCoordinator* coordinator = [[TestCoordinator alloc] init];
+ coordinator.stopHandler = ^{
+ called = YES;
+ };
+ }
+
+ EXPECT_TRUE(called);
+}
+
+TEST(BrowserCoordinatorTest, TestChildren) {
+ TestCoordinator* parent = [[TestCoordinator alloc] init];
+ TestCoordinator* child = [[TestCoordinator alloc] init];
+
+ [parent addChildCoordinator:child];
+ EXPECT_TRUE([parent.children containsObject:child]);
+ EXPECT_EQ(parent, child.parentCoordinator);
+ EXPECT_EQ(parent.viewController, child.rootViewController);
+
+ [parent removeChildCoordinator:child];
+ EXPECT_FALSE([parent.children containsObject:child]);
+ EXPECT_EQ(nil, child.parentCoordinator);
+ // Unparenting shouldn't change a child's rootViewController.
+ EXPECT_EQ(parent.viewController, child.rootViewController);
+
+ TestCoordinator* otherParent = [[TestCoordinator alloc] init];
+ TestCoordinator* otherChild = [[TestCoordinator alloc] init];
+ [otherParent addChildCoordinator:otherChild];
+
+ // -removeChildCoordinator of a non-child should have no affect.
+ [parent removeChildCoordinator:otherChild];
+ EXPECT_TRUE([otherParent.children containsObject:otherChild]);
+ EXPECT_EQ(otherParent, otherChild.parentCoordinator);
+}
+
+TEST(BrowserCoordinatorTest, TestOverlay) {
+ TestCoordinator* parent = [[TestCoordinator alloc] init];
+ TestCoordinator* child = [[TestCoordinator alloc] init];
+ TestCoordinator* grandchild = [[TestCoordinator alloc] init];
+ TestCoordinator* overlay = [[TestCoordinator alloc] init];
+ TestCoordinator* secondOverlay = [[TestCoordinator alloc] init];
+
+ EXPECT_TRUE([parent canAddOverlayCoordinator:overlay]);
+ [parent addChildCoordinator:child];
+ [child addChildCoordinator:grandchild];
+ EXPECT_FALSE([parent canAddOverlayCoordinator:overlay]);
+ EXPECT_FALSE([child canAddOverlayCoordinator:overlay]);
+ EXPECT_TRUE([grandchild canAddOverlayCoordinator:overlay]);
+ EXPECT_FALSE([grandchild canAddOverlayCoordinator:child]);
+
+ EXPECT_FALSE(overlay.overlaying);
+ [parent addOverlayCoordinator:overlay];
+ EXPECT_TRUE(overlay.overlaying);
+ EXPECT_EQ(overlay, parent.overlayCoordinator);
+ EXPECT_EQ(overlay, child.overlayCoordinator);
+ EXPECT_EQ(overlay, grandchild.overlayCoordinator);
+ EXPECT_TRUE([grandchild.children containsObject:overlay]);
+ EXPECT_EQ(grandchild, overlay.parentCoordinator);
+
+ // Shouldn't be able to add a second overlaying coordinator.
+ EXPECT_FALSE([grandchild canAddOverlayCoordinator:secondOverlay]);
+ EXPECT_FALSE(secondOverlay.overlaying);
+ [parent addOverlayCoordinator:secondOverlay];
+ EXPECT_FALSE(secondOverlay.overlaying);
+
+ [child removeOverlayCoordinator];
+ EXPECT_FALSE(overlay.overlaying);
+ EXPECT_EQ(nil, parent.overlayCoordinator);
+ EXPECT_EQ(nil, child.overlayCoordinator);
+ EXPECT_EQ(nil, grandchild.overlayCoordinator);
+ EXPECT_FALSE([grandchild.children containsObject:overlay]);
+ EXPECT_EQ(nil, overlay.parentCoordinator);
+
+ // An implementation that doesn't allow any overlays shouldn't get one.
+ NonOverlayableCoordinator* noOverlays =
+ [[NonOverlayableCoordinator alloc] init];
+ TestCoordinator* thirdOverlay = [[TestCoordinator alloc] init];
+
+ EXPECT_FALSE([noOverlays canAddOverlayCoordinator:thirdOverlay]);
+ EXPECT_FALSE(thirdOverlay.overlaying);
+ [noOverlays addOverlayCoordinator:thirdOverlay];
+ EXPECT_FALSE(thirdOverlay.overlaying);
+}
« no previous file with comments | « ios/clean/chrome/browser/browser_coordinator+internal.h ('k') | ios/clean/chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698