Commit b67c8f63 authored by David Jean's avatar David Jean Committed by Commit Bot

[ios] Fix Tab Usage recorder test for Multi-Window

Move life cycle to scene delegate instead of app delegate
when MW is active.

Bug: 1108363,1045579
Change-Id: I8acc693b8a277701d74b1e5d912ce797a74f5e44
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2332607
Commit-Queue: David Jean <djean@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Auto-Submit: David Jean <djean@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796776}
parent f95dd39a
...@@ -1271,7 +1271,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData( ...@@ -1271,7 +1271,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
@implementation MainController (TestingOnly) @implementation MainController (TestingOnly)
- (void)setStartupParametersWithURL:(const GURL&)launchURL { - (void)setStartupParametersWithURL:(const GURL&)launchURL {
DCHECK(!IsSceneStartupSupported());
NSString* sourceApplication = @"Fake App"; NSString* sourceApplication = @"Fake App";
SceneState* sceneState = self.appState.foregroundActiveScene; SceneState* sceneState = self.appState.foregroundActiveScene;
sceneState.controller.startupParameters = [ChromeAppStartupParameters sceneState.controller.startupParameters = [ChromeAppStartupParameters
......
...@@ -83,7 +83,7 @@ source_set("test_support") { ...@@ -83,7 +83,7 @@ source_set("test_support") {
"//ios/chrome/browser/ui/tab_grid", "//ios/chrome/browser/ui/tab_grid",
"//ios/chrome/browser/ui/tabs", "//ios/chrome/browser/ui/tabs",
"//ios/chrome/browser/ui/util", "//ios/chrome/browser/ui/util",
"//ios/chrome/browser/ui/util", "//ios/chrome/browser/ui/util:multiwindow_util",
"//ios/chrome/browser/url_loading", "//ios/chrome/browser/url_loading",
"//ios/chrome/browser/web_state_list", "//ios/chrome/browser/web_state_list",
"//ios/chrome/browser/web_state_list/web_usage_enabler", "//ios/chrome/browser/web_state_list/web_usage_enabler",
......
...@@ -30,11 +30,13 @@ ...@@ -30,11 +30,13 @@
#import "ios/chrome/browser/ui/main/scene_controller.h" #import "ios/chrome/browser/ui/main/scene_controller.h"
#import "ios/chrome/browser/ui/main/scene_controller_testing.h" #import "ios/chrome/browser/ui/main/scene_controller_testing.h"
#import "ios/chrome/browser/ui/main/scene_state.h" #import "ios/chrome/browser/ui/main/scene_state.h"
#import "ios/chrome/browser/ui/util/multi_window_support.h"
#include "ios/chrome/browser/ui/util/ui_util.h" #include "ios/chrome/browser/ui/util/ui_util.h"
#import "ios/chrome/test/app/tab_test_util.h" #import "ios/chrome/test/app/tab_test_util.h"
#import "ios/web/public/navigation/navigation_context.h" #import "ios/web/public/navigation/navigation_context.h"
#import "ios/web/public/navigation/navigation_manager.h" #import "ios/web/public/navigation/navigation_manager.h"
#include "ios/web/public/test/fakes/test_web_state_observer.h" #include "ios/web/public/test/fakes/test_web_state_observer.h"
#include "net/base/mac/url_conversions.h"
#import "third_party/breakpad/breakpad/src/client/ios/BreakpadController.h" #import "third_party/breakpad/breakpad/src/client/ios/BreakpadController.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
...@@ -59,6 +61,20 @@ ...@@ -59,6 +61,20 @@
} }
@end @end
// A subclass to pass instances of UIOpenURLContext to scene delegate during
// testing. UIOpenURLContext has no init available, so this can only be
// allocated. It uses obscuring properties for URL and options.
// TODO(crbug.com/1115018) Explore improving this which can become brittle.
API_AVAILABLE(ios(13.0)) @interface FakeUIOpenURLContext : UIOpenURLContext
@property(nonatomic, copy) NSURL* URL;
@property(nonatomic, strong) UISceneOpenURLOptions* options;
@end
@implementation FakeUIOpenURLContext
@synthesize URL = _URL;
@synthesize options = _options;
@end
namespace { namespace {
// Returns the original ChromeBrowserState if |incognito| is false. If // Returns the original ChromeBrowserState if |incognito| is false. If
// |ingonito| is true, returns an off-the-record ChromeBrowserState. // |ingonito| is true, returns an off-the-record ChromeBrowserState.
...@@ -219,12 +235,31 @@ void WaitForBreakpadQueue() { ...@@ -219,12 +235,31 @@ void WaitForBreakpadQueue() {
} }
void OpenChromeFromExternalApp(const GURL& url) { void OpenChromeFromExternalApp(const GURL& url) {
[[[UIApplication sharedApplication] delegate] if (IsMultiwindowSupported()) {
applicationWillResignActive:[UIApplication sharedApplication]]; if (@available(iOS 13, *)) {
[GetMainController() setStartupParametersWithURL:url]; UIScene* scene =
[[UIApplication sharedApplication].connectedScenes anyObject];
[scene.delegate sceneWillResignActive:scene];
// FakeUIOpenURLContext cannot be instanciated, but it is just needed
// for carrying the properties over to the scene delegate.
FakeUIOpenURLContext* context = [FakeUIOpenURLContext alloc];
context.URL = net::NSURLWithGURL(url);
NSSet<UIOpenURLContext*>* URLContexts =
[[NSSet alloc] initWithArray:@[ context ]];
[scene.delegate scene:scene openURLContexts:URLContexts];
[scene.delegate sceneDidBecomeActive:scene];
}
} else {
[[[UIApplication sharedApplication] delegate]
applicationWillResignActive:[UIApplication sharedApplication]];
[GetMainController() setStartupParametersWithURL:url];
[[[UIApplication sharedApplication] delegate] [[[UIApplication sharedApplication] delegate]
applicationDidBecomeActive:[UIApplication sharedApplication]]; applicationDidBecomeActive:[UIApplication sharedApplication]];
}
} }
bool PurgeCachedWebViewPages() { bool PurgeCachedWebViewPages() {
......
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