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