Commit f5d6eaf4 authored by Nazerke's avatar Nazerke Committed by Commit Bot

[iOS][coordinator] Modernize App Launcher coordinator.

This CL updates AppLauncherCoordinator to use the browser-based
initializers, and updates unit tests.

Also this CL converts AppLauncherCoordinator to ChromeCoordinator
subclass.

Bug: 906541, 1029346
Change-Id: I327200dd6d7dfbfb9fa032e719996aa319233723
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2010863Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: Nazerke Kalidolda <nazerke@google.com>
Cr-Commit-Position: refs/heads/master@{#733438}
parent 35373736
...@@ -20,6 +20,7 @@ source_set("app_launcher") { ...@@ -20,6 +20,7 @@ source_set("app_launcher") {
"//ios/chrome/browser/app_launcher", "//ios/chrome/browser/app_launcher",
"//ios/chrome/browser/overlays", "//ios/chrome/browser/overlays",
"//ios/chrome/browser/overlays/public/web_content_area", "//ios/chrome/browser/overlays/public/web_content_area",
"//ios/chrome/browser/ui/coordinators:chrome_coordinators",
"//ios/chrome/browser/ui/dialogs:feature_flags", "//ios/chrome/browser/ui/dialogs:feature_flags",
"//ios/public/provider/chrome/browser", "//ios/public/provider/chrome/browser",
"//ios/public/provider/chrome/browser/mailto", "//ios/public/provider/chrome/browser/mailto",
...@@ -39,6 +40,7 @@ source_set("unit_tests") { ...@@ -39,6 +40,7 @@ source_set("unit_tests") {
"//base/test:test_support", "//base/test:test_support",
"//ios/chrome/app/strings:ios_strings_grit", "//ios/chrome/app/strings:ios_strings_grit",
"//ios/chrome/browser/app_launcher", "//ios/chrome/browser/app_launcher",
"//ios/chrome/browser/main:test_support",
"//ios/chrome/browser/overlays", "//ios/chrome/browser/overlays",
"//ios/chrome/browser/overlays/public/web_content_area", "//ios/chrome/browser/overlays/public/web_content_area",
"//ios/chrome/browser/ui/dialogs:feature_flags", "//ios/chrome/browser/ui/dialogs:feature_flags",
......
...@@ -8,18 +8,20 @@ ...@@ -8,18 +8,20 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "ios/chrome/browser/app_launcher/app_launcher_tab_helper_delegate.h" #import "ios/chrome/browser/app_launcher/app_launcher_tab_helper_delegate.h"
#import "ios/chrome/browser/ui/coordinators/chrome_coordinator.h"
// A coordinator that handles UI related to launching apps. // A coordinator that handles UI related to launching apps.
// TODO(crbug.com/906541) : Convert to ChromeCoordinator subclass. @interface AppLauncherCoordinator
@interface AppLauncherCoordinator : NSObject<AppLauncherTabHelperDelegate> : ChromeCoordinator <AppLauncherTabHelperDelegate>
// Initializes the coordinator with the |baseViewController|, from which to // Unavailable, use -initWithBaseViewController:browser:.
// present UI. - (instancetype)initWithBaseViewController:(UIViewController*)viewController
- (instancetype)initWithBaseViewController:(UIViewController*)baseViewController NS_UNAVAILABLE;
NS_DESIGNATED_INITIALIZER; // Unavailable, use -initWithBaseViewController:browser:.
- (instancetype)initWithBaseViewController:(UIViewController*)viewController
// Default designated initializer is unavailable. browserState:
- (instancetype)init NS_UNAVAILABLE; (ios::ChromeBrowserState*)browserState
NS_UNAVAILABLE;
@end @end
......
...@@ -57,22 +57,9 @@ void AppLauncherOverlayCallback(ProceduralBlockWithBool app_launch_completion, ...@@ -57,22 +57,9 @@ void AppLauncherOverlayCallback(ProceduralBlockWithBool app_launch_completion,
} // namespace } // namespace
@interface AppLauncherCoordinator ()
// The base view controller from which to present UI.
@property(nonatomic, weak) UIViewController* baseViewController;
@end
@implementation AppLauncherCoordinator @implementation AppLauncherCoordinator
@synthesize baseViewController = _baseViewController; @synthesize baseViewController = _baseViewController;
- (instancetype)initWithBaseViewController:
(UIViewController*)baseViewController {
if (self = [super init]) {
_baseViewController = baseViewController;
}
return self;
}
#pragma mark - Private methods #pragma mark - Private methods
// Alerts the user with |message| and buttons with titles // Alerts the user with |message| and buttons with titles
......
...@@ -7,7 +7,9 @@ ...@@ -7,7 +7,9 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "base/test/task_environment.h"
#import "ios/chrome/browser/app_launcher/app_launcher_tab_helper.h" #import "ios/chrome/browser/app_launcher/app_launcher_tab_helper.h"
#include "ios/chrome/browser/main/test_browser.h"
#include "ios/chrome/browser/overlays/public/overlay_request.h" #include "ios/chrome/browser/overlays/public/overlay_request.h"
#import "ios/chrome/browser/overlays/public/overlay_request_queue.h" #import "ios/chrome/browser/overlays/public/overlay_request_queue.h"
#import "ios/chrome/browser/overlays/public/web_content_area/app_launcher_alert_overlay.h" #import "ios/chrome/browser/overlays/public/web_content_area/app_launcher_alert_overlay.h"
...@@ -32,8 +34,10 @@ class AppLauncherCoordinatorTest : public PlatformTest { ...@@ -32,8 +34,10 @@ class AppLauncherCoordinatorTest : public PlatformTest {
AppLauncherCoordinatorTest() { AppLauncherCoordinatorTest() {
base_view_controller_ = [[UIViewController alloc] init]; base_view_controller_ = [[UIViewController alloc] init];
[scoped_key_window_.Get() setRootViewController:base_view_controller_]; [scoped_key_window_.Get() setRootViewController:base_view_controller_];
browser_ = std::make_unique<TestBrowser>();
coordinator_ = [[AppLauncherCoordinator alloc] coordinator_ = [[AppLauncherCoordinator alloc]
initWithBaseViewController:base_view_controller_]; initWithBaseViewController:base_view_controller_
browser:browser_.get()];
application_ = OCMClassMock([UIApplication class]); application_ = OCMClassMock([UIApplication class]);
OCMStub([application_ sharedApplication]).andReturn(application_); OCMStub([application_ sharedApplication]).andReturn(application_);
AppLauncherTabHelper::CreateForWebState(&web_state_, nil, nil); AppLauncherTabHelper::CreateForWebState(&web_state_, nil, nil);
...@@ -72,9 +76,12 @@ class AppLauncherCoordinatorTest : public PlatformTest { ...@@ -72,9 +76,12 @@ class AppLauncherCoordinatorTest : public PlatformTest {
} }
} }
base::test::TaskEnvironment task_environment_;
web::TestWebState web_state_; web::TestWebState web_state_;
UIViewController* base_view_controller_ = nil; UIViewController* base_view_controller_ = nil;
ScopedKeyWindow scoped_key_window_; ScopedKeyWindow scoped_key_window_;
std::unique_ptr<Browser> browser_;
AppLauncherCoordinator* coordinator_ = nil; AppLauncherCoordinator* coordinator_ = nil;
id application_ = nil; id application_ = nil;
}; };
......
...@@ -293,7 +293,9 @@ ...@@ -293,7 +293,9 @@
DCHECK(self.dispatcher); DCHECK(self.dispatcher);
self.appLauncherCoordinator = [[AppLauncherCoordinator alloc] self.appLauncherCoordinator = [[AppLauncherCoordinator alloc]
initWithBaseViewController:self.viewController]; initWithBaseViewController:self.viewController
browser:self.browser];
[self.appLauncherCoordinator start];
self.ARQuickLookCoordinator = [[ARQuickLookCoordinator alloc] self.ARQuickLookCoordinator = [[ARQuickLookCoordinator alloc]
initWithBaseViewController:self.viewController initWithBaseViewController:self.viewController
...@@ -355,8 +357,7 @@ ...@@ -355,8 +357,7 @@
[self.allPasswordCoordinator stop]; [self.allPasswordCoordinator stop];
self.allPasswordCoordinator = nil; self.allPasswordCoordinator = nil;
// TODO(crbug.com/906541) : AppLauncherCoordinator is not a subclass of [self.appLauncherCoordinator stop];
// ChromeCoordinator, and does not have a |-stop| method.
self.appLauncherCoordinator = nil; self.appLauncherCoordinator = nil;
[self.ARQuickLookCoordinator stop]; [self.ARQuickLookCoordinator stop];
......
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