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

Side by Side Diff: ios/clean/chrome/browser/ui/root/root_container_view_controller_unittest.mm

Issue 2800313002: [ios] RootCoordinator and view controller. (Closed)
Patch Set: More unittests and cleanup. Created 3 years, 8 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "ios/clean/chrome/browser/ui/root/root_container_view_controller.h"
6
7 #include "base/macros.h"
8 #import "ios/clean/chrome/browser/ui/animators/zoom_transition_delegate.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "testing/platform_test.h"
11 #import "third_party/ocmock/OCMock/OCMock.h"
12
13 #if !defined(__has_feature) || !__has_feature(objc_arc)
14 #error "This file requires ARC support."
15 #endif
16
17 namespace {
18
19 class RootContainerViewControllerTest : public PlatformTest {
20 public:
21 RootContainerViewControllerTest() {
22 rootViewController_ = [[RootContainerViewController alloc] init];
23 contentViewController_ = [[UIViewController alloc] init];
24 }
25
26 protected:
27 RootContainerViewController* rootViewController_;
28 UIViewController* contentViewController_;
29
30 private:
31 DISALLOW_COPY_AND_ASSIGN(RootContainerViewControllerTest);
32 };
33
34 // Tests that RootContainerViewController conforms to ZoomTransitionDelegate.
35 TEST_F(RootContainerViewControllerTest, TestConformsToZoomTransitionDelegate) {
36 EXPECT_TRUE([RootContainerViewController
37 conformsToProtocol:@protocol(ZoomTransitionDelegate)]);
38 }
39
40 // Tests that calls to |rectForZoomWithKey| are forwarded to the
41 // contentViewController.
42 TEST_F(RootContainerViewControllerTest, TestForwardingMethod) {
43 id contentViewController = OCMProtocolMock(@protocol(ZoomTransitionDelegate));
44 rootViewController_.contentViewController = contentViewController;
45 [rootViewController_ rectForZoomWithKey:nil inView:nil];
46 [[contentViewController verify] rectForZoomWithKey:[OCMArg any]
47 inView:[OCMArg any]];
48 }
49
50 // Tests that there are no child view controllers before loading the view.
51 TEST_F(RootContainerViewControllerTest, TestNotLoadingView) {
52 EXPECT_EQ(0u, rootViewController_.childViewControllers.count);
53 rootViewController_.contentViewController = contentViewController_;
54 EXPECT_EQ(0u, rootViewController_.childViewControllers.count);
55 }
56
57 // Tests setting the content view before loading the view controller.
58 TEST_F(RootContainerViewControllerTest, TestSettingContentBeforeLoadingView) {
59 rootViewController_.contentViewController = contentViewController_;
60 EXPECT_EQ(0u, rootViewController_.childViewControllers.count);
61 [rootViewController_ loadViewIfNeeded];
62 EXPECT_EQ(1u, rootViewController_.childViewControllers.count);
63 EXPECT_EQ([rootViewController_.childViewControllers lastObject],
64 contentViewController_);
65 }
66
67 // Tests setting the content view after loading the view controller.
68 TEST_F(RootContainerViewControllerTest, TestSettingContentAfterLoadingView) {
69 [rootViewController_ loadViewIfNeeded];
70 EXPECT_EQ(0u, rootViewController_.childViewControllers.count);
71 rootViewController_.contentViewController = contentViewController_;
72 EXPECT_EQ(1u, rootViewController_.childViewControllers.count);
73 EXPECT_EQ([rootViewController_.childViewControllers lastObject],
74 contentViewController_);
75 }
76
77 // Tests that content has changed properly.
78 TEST_F(RootContainerViewControllerTest, TestChangingContent) {
79 rootViewController_.contentViewController = contentViewController_;
80 [rootViewController_ loadViewIfNeeded];
81 UIViewController* differentViewController = [[UIViewController alloc] init];
82 rootViewController_.contentViewController = differentViewController;
83 EXPECT_EQ(1u, rootViewController_.childViewControllers.count);
84 EXPECT_EQ([rootViewController_.childViewControllers lastObject],
85 differentViewController);
86 }
87
88 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698