Commit b1f381c9 authored by edchin's avatar edchin Committed by Commit bot

[ios] RootCoordinator and view controller.

This CL places a root container at the root of the view controller hierarchy,
instead of the tab grid. The root container has a content view controller
that can be swapped between regular mode or incognito mode.
This refactor is required to enable switching to incognito mode.

BUG=686770

Review-Url: https://codereview.chromium.org/2800313002
Cr-Commit-Position: refs/heads/master@{#464420}
parent 78877323
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#import "ios/clean/chrome/app/steps/launch_to_background.h" #import "ios/clean/chrome/app/steps/launch_to_background.h"
#import "ios/clean/chrome/app/steps/launch_to_basic.h" #import "ios/clean/chrome/app/steps/launch_to_basic.h"
#import "ios/clean/chrome/app/steps/launch_to_foreground.h" #import "ios/clean/chrome/app/steps/launch_to_foreground.h"
#import "ios/clean/chrome/app/steps/tab_grid_coordinator+application_step.h" #import "ios/clean/chrome/app/steps/root_coordinator+application_step.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
...@@ -109,7 +109,7 @@ ...@@ -109,7 +109,7 @@
[[BeginForegrounding alloc] init], [[BeginForegrounding alloc] init],
[[PrepareForUI alloc] init], [[PrepareForUI alloc] init],
[[CompleteForegrounding alloc] init], [[CompleteForegrounding alloc] init],
[[TabGridCoordinator alloc] init], [[RootCoordinator alloc] init],
]]; ]];
} }
......
...@@ -10,8 +10,8 @@ source_set("steps") { ...@@ -10,8 +10,8 @@ source_set("steps") {
"launch_to_basic.mm", "launch_to_basic.mm",
"launch_to_foreground.h", "launch_to_foreground.h",
"launch_to_foreground.mm", "launch_to_foreground.mm",
"tab_grid_coordinator+application_step.h", "root_coordinator+application_step.h",
"tab_grid_coordinator+application_step.mm", "root_coordinator+application_step.mm",
] ]
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
...@@ -28,10 +28,28 @@ source_set("steps") { ...@@ -28,10 +28,28 @@ source_set("steps") {
"//ios/chrome/browser/content_settings", "//ios/chrome/browser/content_settings",
"//ios/chrome/browser/web:web_internal", "//ios/chrome/browser/web:web_internal",
"//ios/clean/chrome/app:application_state", "//ios/clean/chrome/app:application_state",
"//ios/clean/chrome/browser/ui/tab_grid", "//ios/clean/chrome/browser/ui/root",
"//ios/net", "//ios/net",
"//ios/shared/chrome/browser/ui/browser_list", "//ios/shared/chrome/browser/ui/browser_list",
"//ios/shared/chrome/browser/ui/coordinators", "//ios/shared/chrome/browser/ui/coordinators",
"//ios/web:web_arc", "//ios/web:web_arc",
] ]
} }
source_set("unit_tests") {
testonly = true
sources = [
"root_coordinator+application_step_unittest.mm",
]
configs += [ "//build/config/compiler:enable_arc" ]
deps = [
":steps",
"//base",
"//ios/clean/chrome/app:application_state",
"//testing/gtest",
"//third_party/ocmock",
]
}
// Copyright 2016 The Chromium Authors. All rights reserved. // Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef IOS_CLEAN_CHROME_APP_STEPS_TAB_GRID_COORDINATOR_APPLICATION_STEP_H_ #ifndef IOS_CLEAN_CHROME_APP_STEPS_ROOT_COORDINATOR_APPLICATION_STEP_H_
#define IOS_CLEAN_CHROME_APP_STEPS_TAB_GRID_COORDINATOR_APPLICATION_STEP_H_ #define IOS_CLEAN_CHROME_APP_STEPS_ROOT_COORDINATOR_APPLICATION_STEP_H_
#import <UIKit/UIKit.h>
#import "ios/clean/chrome/app/application_step.h" #import "ios/clean/chrome/app/application_step.h"
#import "ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.h" #import "ios/clean/chrome/browser/ui/root/root_coordinator.h"
// Category on TabGridCoordinator to allow it to act as an application step // Category on RootCoordinator to allow it to act as an application
// and control the root UI for the application when is starts. // step and control the root UI for the application when is starts.
// Creates the main window and makes it key, but doesn't make it visible yet. // Creates the main window and makes it key, but doesn't make it visible yet.
// Pre: Application phase is APPLICATION_FOREGROUNDED and the main window is // Pre: Application phase is APPLICATION_FOREGROUNDED and the main window is
// key. // key.
// Post: Application phase is (still) APPLICATION_FOREGROUNDED, the main window // Post: Application phase is (still) APPLICATION_FOREGROUNDED, the main window
// is visible and has a root view controller set. // is visible and has a root view controller set.
@interface TabGridCoordinator (ApplicationStep)<ApplicationStep> @interface RootCoordinator (ApplicationStep)<ApplicationStep>
@end @end
#endif // IOS_CLEAN_CHROME_APP_STEPS_TAB_GRID_COORDINATOR_APPLICATION_STEP_H_ #endif // IOS_CLEAN_CHROME_APP_STEPS_ROOT_COORDINATOR_APPLICATION_STEP_H_
// Copyright 2016 The Chromium Authors. All rights reserved. // Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#import "ios/clean/chrome/app/steps/tab_grid_coordinator+application_step.h" #import "ios/clean/chrome/app/steps/root_coordinator+application_step.h"
#import "base/supports_user_data.h" #import "base/supports_user_data.h"
#import "ios/clean/chrome/app/application_state.h" #import "ios/clean/chrome/app/application_state.h"
...@@ -31,10 +31,10 @@ class RootCoordinatorContainer : public base::SupportsUserData::Data { ...@@ -31,10 +31,10 @@ class RootCoordinatorContainer : public base::SupportsUserData::Data {
const char kRootCoordinatorContainerKey[] = "root_coordinator"; const char kRootCoordinatorContainerKey[] = "root_coordinator";
} // namespace } // namespace
@interface StopTabGridCoordinator : NSObject<ApplicationStep> @interface StopRootCoordinator : NSObject<ApplicationStep>
@end @end
@implementation TabGridCoordinator (ApplicationStep) @implementation RootCoordinator (ApplicationStep)
- (BOOL)canRunInState:(ApplicationState*)state { - (BOOL)canRunInState:(ApplicationState*)state {
return [state.window isKeyWindow] && state.phase == APPLICATION_FOREGROUNDED; return [state.window isKeyWindow] && state.phase == APPLICATION_FOREGROUNDED;
...@@ -61,12 +61,12 @@ const char kRootCoordinatorContainerKey[] = "root_coordinator"; ...@@ -61,12 +61,12 @@ const char kRootCoordinatorContainerKey[] = "root_coordinator";
new RootCoordinatorContainer(self)); new RootCoordinatorContainer(self));
// Add a termination step to remove this object. // Add a termination step to remove this object.
[[state terminationSteps] addObject:[[StopTabGridCoordinator alloc] init]]; [[state terminationSteps] addObject:[[StopRootCoordinator alloc] init]];
} }
@end @end
@implementation StopTabGridCoordinator @implementation StopRootCoordinator
- (BOOL)canRunInState:(ApplicationState*)state { - (BOOL)canRunInState:(ApplicationState*)state {
return state.phase = APPLICATION_TERMINATING; return state.phase = APPLICATION_TERMINATING;
......
// 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/app/steps/root_coordinator+application_step.h"
#include "base/macros.h"
#import "ios/clean/chrome/app/application_state.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#import "third_party/ocmock/OCMock/OCMock.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
class RootCoordinatorApplicationStepTest : public PlatformTest {
public:
RootCoordinatorApplicationStepTest() {
coordinator_ = [[RootCoordinator alloc] init];
state_ = [[ApplicationState alloc] init];
window_ = OCMClassMock([UIWindow class]);
}
protected:
RootCoordinator* coordinator_;
ApplicationState* state_;
id window_;
private:
DISALLOW_COPY_AND_ASSIGN(RootCoordinatorApplicationStepTest);
};
// Tests that the coordinator can run if the window is key and application is
// foregrounded.
TEST_F(RootCoordinatorApplicationStepTest, TestRunsInKeyWindow) {
state_.phase = APPLICATION_FOREGROUNDED;
state_.window = window_;
OCMStub([window_ isKeyWindow]).andReturn(YES);
EXPECT_TRUE([coordinator_ canRunInState:state_]);
}
// Tests that the coordinator cannot run if the window is not key.
TEST_F(RootCoordinatorApplicationStepTest, TestCannotRunWithoutKeyWindow) {
state_.phase = APPLICATION_FOREGROUNDED;
state_.window = window_;
OCMStub([window_ isKeyWindow]).andReturn(NO);
EXPECT_FALSE([coordinator_ canRunInState:state_]);
}
// Tests that the coordinator cannot run if application is not foregrounded.
TEST_F(RootCoordinatorApplicationStepTest, TestCannotRunIfNotForegrounded) {
state_.phase = APPLICATION_COLD;
state_.window = window_;
OCMStub([window_ isKeyWindow]).andReturn(YES);
EXPECT_FALSE([coordinator_ canRunInState:state_]);
}
} // namespace
# 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.
source_set("root") {
sources = [
"root_coordinator.h",
"root_coordinator.mm",
]
deps = [
":root_ui",
"//ios/clean/chrome/browser",
"//ios/clean/chrome/browser/ui/commands",
"//ios/clean/chrome/browser/ui/tab_grid",
"//ios/shared/chrome/browser/ui/browser_list",
"//ios/shared/chrome/browser/ui/commands",
"//ios/shared/chrome/browser/ui/coordinators",
]
configs += [ "//build/config/compiler:enable_arc" ]
}
source_set("root_ui") {
sources = [
"root_container_view_controller.h",
"root_container_view_controller.mm",
]
deps = [
"//base",
"//ios/clean/chrome/browser/ui/animators",
]
configs += [ "//build/config/compiler:enable_arc" ]
}
source_set("unit_tests") {
sources = [
"root_container_view_controller_unittest.mm",
"root_coordinator_unittest.mm",
]
deps = [
":root",
":root_ui",
"//base",
"//ios/clean/chrome/browser",
"//ios/clean/chrome/browser/ui/animators",
"//testing/gtest",
"//third_party/ocmock",
]
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
}
// 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.
#ifndef IOS_CLEAN_CHROME_BROWSER_UI_ROOT_ROOT_CONTAINER_VIEW_CONTROLLER_H_
#define IOS_CLEAN_CHROME_BROWSER_UI_ROOT_ROOT_CONTAINER_VIEW_CONTROLLER_H_
#import <UIKit/UIKit.h>
#import "ios/clean/chrome/browser/ui/animators/zoom_transition_delegate.h"
// View controller that wholly contains a content view controller.
@interface RootContainerViewController
: UIViewController<ZoomTransitionDelegate>
// View controller showing the main content.
@property(nonatomic, strong) UIViewController* contentViewController;
@end
#endif // IOS_CLEAN_CHROME_BROWSER_UI_ROOT_ROOT_CONTAINER_VIEW_CONTROLLER_H_
// 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/ui/root/root_container_view_controller.h"
#include "base/logging.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation RootContainerViewController
@synthesize contentViewController = _contentViewController;
#pragma mark - UIViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor blackColor];
[self attachChildViewController:self.contentViewController];
}
#pragma mark - Public properties
- (void)setContentViewController:(UIViewController*)contentViewController {
if (self.contentViewController == contentViewController)
return;
if ([self isViewLoaded]) {
[self detachChildViewController:self.contentViewController];
[self attachChildViewController:contentViewController];
}
_contentViewController = contentViewController;
}
#pragma mark - ChildViewController helper methods
- (void)attachChildViewController:(UIViewController*)viewController {
if (!viewController) {
return;
}
[self addChildViewController:viewController];
viewController.view.autoresizingMask =
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
viewController.view.frame = self.view.bounds;
[self.view addSubview:viewController.view];
[viewController didMoveToParentViewController:self];
}
- (void)detachChildViewController:(UIViewController*)viewController {
if (!viewController) {
return;
}
DCHECK_EQ(self, viewController.parentViewController);
[viewController willMoveToParentViewController:nil];
[viewController.view removeFromSuperview];
[viewController removeFromParentViewController];
}
#pragma mark - ZoomTransitionDelegate
- (CGRect)rectForZoomWithKey:(NSObject*)key inView:(UIView*)view {
if ([self.contentViewController
conformsToProtocol:@protocol(ZoomTransitionDelegate)]) {
return [static_cast<id<ZoomTransitionDelegate>>(self.contentViewController)
rectForZoomWithKey:key
inView:view];
}
return CGRectNull;
}
@end
// 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/ui/root/root_container_view_controller.h"
#include "base/macros.h"
#import "ios/clean/chrome/browser/ui/animators/zoom_transition_delegate.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#import "third_party/ocmock/OCMock/OCMock.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
class RootContainerViewControllerTest : public PlatformTest {
public:
RootContainerViewControllerTest() {
rootViewController_ = [[RootContainerViewController alloc] init];
contentViewController_ = [[UIViewController alloc] init];
}
protected:
RootContainerViewController* rootViewController_;
UIViewController* contentViewController_;
private:
DISALLOW_COPY_AND_ASSIGN(RootContainerViewControllerTest);
};
// Tests that RootContainerViewController conforms to ZoomTransitionDelegate.
TEST_F(RootContainerViewControllerTest, TestConformsToZoomTransitionDelegate) {
EXPECT_TRUE([RootContainerViewController
conformsToProtocol:@protocol(ZoomTransitionDelegate)]);
}
// Tests that calls to |rectForZoomWithKey| are forwarded to the
// contentViewController.
TEST_F(RootContainerViewControllerTest, TestForwardingMethod) {
id contentViewController = OCMProtocolMock(@protocol(ZoomTransitionDelegate));
rootViewController_.contentViewController = contentViewController;
[rootViewController_ rectForZoomWithKey:nil inView:nil];
[[contentViewController verify] rectForZoomWithKey:[OCMArg any]
inView:[OCMArg any]];
}
// Tests that there are no child view controllers before loading the view.
TEST_F(RootContainerViewControllerTest, TestNotLoadingView) {
EXPECT_EQ(0u, rootViewController_.childViewControllers.count);
rootViewController_.contentViewController = contentViewController_;
EXPECT_EQ(0u, rootViewController_.childViewControllers.count);
}
// Tests setting the content view before loading the view controller.
TEST_F(RootContainerViewControllerTest, TestSettingContentBeforeLoadingView) {
rootViewController_.contentViewController = contentViewController_;
EXPECT_EQ(0u, rootViewController_.childViewControllers.count);
[rootViewController_ loadViewIfNeeded];
EXPECT_EQ(1u, rootViewController_.childViewControllers.count);
EXPECT_EQ([rootViewController_.childViewControllers lastObject],
contentViewController_);
}
// Tests setting the content view after loading the view controller.
TEST_F(RootContainerViewControllerTest, TestSettingContentAfterLoadingView) {
[rootViewController_ loadViewIfNeeded];
EXPECT_EQ(0u, rootViewController_.childViewControllers.count);
rootViewController_.contentViewController = contentViewController_;
EXPECT_EQ(1u, rootViewController_.childViewControllers.count);
EXPECT_EQ([rootViewController_.childViewControllers lastObject],
contentViewController_);
}
// Tests that content has changed properly.
TEST_F(RootContainerViewControllerTest, TestChangingContent) {
rootViewController_.contentViewController = contentViewController_;
[rootViewController_ loadViewIfNeeded];
UIViewController* differentViewController = [[UIViewController alloc] init];
rootViewController_.contentViewController = differentViewController;
EXPECT_EQ(1u, rootViewController_.childViewControllers.count);
EXPECT_EQ([rootViewController_.childViewControllers lastObject],
differentViewController);
}
} // namespace
// 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.
#ifndef IOS_CLEAN_CHROME_BROWSER_UI_ROOT_ROOT_COORDINATOR_H_
#define IOS_CLEAN_CHROME_BROWSER_UI_ROOT_ROOT_COORDINATOR_H_
#import "ios/clean/chrome/browser/url_opening.h"
#import "ios/shared/chrome/browser/ui/coordinators/browser_coordinator.h"
// Coordinator that runs the root container.
@interface RootCoordinator : BrowserCoordinator<URLOpening>
@end
#endif // IOS_CLEAN_CHROME_BROWSER_UI_ROOT_ROOT_COORDINATOR_H_
// 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/ui/root/root_coordinator.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
#import "ios/clean/chrome/browser/ui/root/root_container_view_controller.h"
#import "ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.h"
#import "ios/shared/chrome/browser/ui/browser_list/browser.h"
#import "ios/shared/chrome/browser/ui/coordinators/browser_coordinator+internal.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface RootCoordinator ()
@property(nonatomic, strong) RootContainerViewController* viewController;
@property(nonatomic, weak) TabGridCoordinator* tabGridCoordinator;
@end
@implementation RootCoordinator
@synthesize viewController = _viewController;
@synthesize tabGridCoordinator = _tabGridCoordinator;
#pragma mark - BrowserCoordinator
- (void)start {
self.viewController = [[RootContainerViewController alloc] init];
TabGridCoordinator* tabGridCoordinator = [[TabGridCoordinator alloc] init];
[self addChildCoordinator:tabGridCoordinator];
[tabGridCoordinator start];
self.tabGridCoordinator = tabGridCoordinator;
[super start];
}
- (void)stop {
[super stop];
// PLACEHOLDER: Stop child coordinators here for now. We might deal with this
// differently later on.
for (BrowserCoordinator* child in self.children) {
[child stop];
[self removeChildCoordinator:child];
}
}
- (void)childCoordinatorDidStart:(BrowserCoordinator*)childCoordinator {
self.viewController.contentViewController = childCoordinator.viewController;
}
- (void)childCoordinatorWillStop:(BrowserCoordinator*)childCoordinator {
self.viewController.contentViewController = nil;
}
- (BOOL)canAddOverlayCoordinator:(BrowserCoordinator*)overlayCoordinator {
return YES;
}
#pragma mark - URLOpening
- (void)openURL:(NSURL*)URL {
[self.tabGridCoordinator openURL:URL];
}
@end
// 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/ui/root/root_coordinator.h"
#import "ios/clean/chrome/browser/url_opening.h"
#include "testing/gtest/include/gtest/gtest.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Tests that RootCoordinator conforms to the URLOpening protocol.
TEST(RootCoordinatorTest, TestConformsToURLOpening) {
EXPECT_TRUE([RootCoordinator conformsToProtocol:@protocol(URLOpening)]);
}
} // namespace
...@@ -88,6 +88,11 @@ ...@@ -88,6 +88,11 @@
- (void)stop { - (void)stop {
[super stop]; [super stop];
[self.browser->dispatcher() stopDispatchingToTarget:self]; [self.browser->dispatcher() stopDispatchingToTarget:self];
[self.mediator disconnect];
for (BrowserCoordinator* child in self.children) {
[child stop];
[self removeChildCoordinator:child];
}
} }
- (void)childCoordinatorDidStart:(BrowserCoordinator*)childCoordinator { - (void)childCoordinatorDidStart:(BrowserCoordinator*)childCoordinator {
......
...@@ -19,12 +19,14 @@ test("ios_clean_chrome_unittests") { ...@@ -19,12 +19,14 @@ test("ios_clean_chrome_unittests") {
ios_packed_resources_target, ios_packed_resources_target,
# Add unit_tests target here. # Add unit_tests target here.
"//ios/clean/chrome/app/steps:unit_tests",
"//ios/clean/chrome/browser/ui/bookmarks:unit_tests", "//ios/clean/chrome/browser/ui/bookmarks:unit_tests",
"//ios/clean/chrome/browser/ui/context_menu:unit_tests", "//ios/clean/chrome/browser/ui/context_menu:unit_tests",
"//ios/clean/chrome/browser/ui/find_in_page:unit_tests", "//ios/clean/chrome/browser/ui/find_in_page:unit_tests",
"//ios/clean/chrome/browser/ui/ntp:unit_tests", "//ios/clean/chrome/browser/ui/ntp:unit_tests",
"//ios/clean/chrome/browser/ui/omnibox:unit_tests", "//ios/clean/chrome/browser/ui/omnibox:unit_tests",
"//ios/clean/chrome/browser/ui/recent_tabs:unit_tests", "//ios/clean/chrome/browser/ui/recent_tabs:unit_tests",
"//ios/clean/chrome/browser/ui/root:unit_tests",
"//ios/clean/chrome/browser/ui/tab_collection:unit_tests", "//ios/clean/chrome/browser/ui/tab_collection:unit_tests",
"//ios/clean/chrome/browser/ui/tab_grid:unit_tests", "//ios/clean/chrome/browser/ui/tab_grid:unit_tests",
"//ios/clean/chrome/browser/ui/toolbar:unit_tests", "//ios/clean/chrome/browser/ui/toolbar:unit_tests",
......
...@@ -28,6 +28,7 @@ group("features") { ...@@ -28,6 +28,7 @@ group("features") {
"//ios/clean/chrome/browser/ui/tools:tools_ui", "//ios/clean/chrome/browser/ui/tools:tools_ui",
"//ios/showcase/content_suggestions", "//ios/showcase/content_suggestions",
"//ios/showcase/payments", "//ios/showcase/payments",
"//ios/showcase/root",
"//ios/showcase/settings", "//ios/showcase/settings",
"//ios/showcase/tab", "//ios/showcase/tab",
"//ios/showcase/tab_grid", "//ios/showcase/tab_grid",
...@@ -54,6 +55,7 @@ ios_eg_test("ios_showcase_egtests") { ...@@ -54,6 +55,7 @@ ios_eg_test("ios_showcase_egtests") {
"//ios/showcase/content_suggestions:eg_tests", "//ios/showcase/content_suggestions:eg_tests",
"//ios/showcase/core:eg_tests", "//ios/showcase/core:eg_tests",
"//ios/showcase/payments:eg_tests", "//ios/showcase/payments:eg_tests",
"//ios/showcase/root:eg_tests",
"//ios/showcase/tab:eg_tests", "//ios/showcase/tab:eg_tests",
"//ios/showcase/tab_grid:eg_tests", "//ios/showcase/tab_grid:eg_tests",
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#ifndef IOS_SHOWCASE_COMMON_COORDINATOR_H_ #ifndef IOS_SHOWCASE_COMMON_COORDINATOR_H_
#define IOS_SHOWCASE_COMMON_COORDINATOR_H_ #define IOS_SHOWCASE_COMMON_COORDINATOR_H_
#import <Foundation/Foundation.h> #import <UIKit/UIKit.h>
// This protocol is the common interface to the simple non-production // This protocol is the common interface to the simple non-production
// coordinators that will initialize, set up and present production view // coordinators that will initialize, set up and present production view
......
...@@ -36,6 +36,11 @@ ...@@ -36,6 +36,11 @@
showcase::kClassForInstantiationKey : @"SCPaymentsPickerCoordinator", showcase::kClassForInstantiationKey : @"SCPaymentsPickerCoordinator",
showcase::kUseCaseKey : @"Payment request picker view", showcase::kUseCaseKey : @"Payment request picker view",
}, },
@{
showcase::kClassForDisplayKey : @"RootContainerViewController",
showcase::kClassForInstantiationKey : @"SCRootCoordinator",
showcase::kUseCaseKey : @"Root container",
},
@{ @{
showcase::kClassForDisplayKey : @"SettingsViewController", showcase::kClassForDisplayKey : @"SettingsViewController",
showcase::kClassForInstantiationKey : @"SCSettingsCoordinator", showcase::kClassForInstantiationKey : @"SCSettingsCoordinator",
......
# 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.
source_set("root") {
sources = [
"sc_root_coordinator.h",
"sc_root_coordinator.mm",
]
deps = [
"//base",
"//ios/clean/chrome/browser/ui/root:root_ui",
"//ios/showcase/common",
]
libs = [ "UIKit.framework" ]
configs += [ "//build/config/compiler:enable_arc" ]
}
source_set("eg_tests") {
testonly = true
sources = [
"sc_root_egtest.mm",
]
deps = [
"//ios/showcase/test",
"//ios/third_party/earl_grey",
]
libs = [ "XCTest.framework" ]
configs += [ "//build/config/compiler:enable_arc" ]
}
// 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.
#ifndef IOS_SHOWCASE_ROOT_SC_ROOT_COORDINATOR_H_
#define IOS_SHOWCASE_ROOT_SC_ROOT_COORDINATOR_H_
#import <Foundation/Foundation.h>
#import "ios/showcase/common/navigation_coordinator.h"
@interface SCRootCoordinator : NSObject<NavigationCoordinator>
@end
#endif // IOS_SHOWCASE_ROOT_SC_ROOT_COORDINATOR_H_
// 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/showcase/root/sc_root_coordinator.h"
#import "ios/clean/chrome/browser/ui/root/root_container_view_controller.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation SCRootCoordinator
@synthesize baseViewController;
- (void)start {
RootContainerViewController* viewController =
[[RootContainerViewController alloc] init];
UIViewController* contentViewController = [[UIViewController alloc] init];
contentViewController.view.backgroundColor = [UIColor greenColor];
viewController.contentViewController = contentViewController;
viewController.title = @"Root container";
[self.baseViewController pushViewController:viewController animated:YES];
}
@end
// 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 <EarlGrey/EarlGrey.h>
#import "ios/showcase/test/showcase_eg_utils.h"
#import "ios/showcase/test/showcase_test_case.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
// Tests for the root container view controller.
@interface SCRootTestCase : ShowcaseTestCase
@end
@implementation SCRootTestCase
// Tests launching RootContainerViewController.
- (void)testLaunch {
showcase_utils::Open(@"RootContainerViewController");
showcase_utils::Close();
}
@end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment