Commit 998c1103 authored by Eugene But's avatar Eugene But Committed by Commit Bot

Correctly handle 'Copy to Chrome' when Chrome is running in multitasking mode.

This CL fixes 'Copy to Chrome' in multitasking mode when
kExternalFilesLoadedInWebState flag is enabled.

URL is set to completeURL (which is file:// URL) and virtualURL is
set to externalURL (which is chrome:// URL). This is necessary because
WebState knows how to render file URLs but can not render chrome:// URL.

The code was copied from UserAcrtivityHandler, so this CL can be
cherry-picked to M73. Code duplication cleanup will be done in a follow
up CL.

Bug: 934789
Change-Id: I490cea33171b25ff73ef713c8610a64da9d8145f
Reviewed-on: https://chromium-review.googlesource.com/c/1484631
Commit-Queue: Mark Cogan <marq@chromium.org>
Auto-Submit: Eugene But <eugenebut@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635222}
parent 332f7d52
......@@ -12,6 +12,7 @@
#import "ios/chrome/app/application_delegate/tab_opening.h"
#include "ios/chrome/app/startup/chrome_app_startup_parameters.h"
#import "ios/chrome/browser/chrome_url_util.h"
#include "ios/chrome/browser/system_flags.h"
#include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......@@ -63,12 +64,29 @@ const char* const kUMAMobileSessionStartFromAppsHistogram =
[startupInformation setStartupParameters:nil];
};
// TODO(crbug.com/935019): Exacly the same copy of this code is present in
// +[UserAcrtivityHandler
// handleStartupParametersWithTabOpener:startupInformation:interfaceProvider:]
GURL URL;
GURL virtualURL;
if ([params completeURL].SchemeIsFile() &&
base::FeatureList::IsEnabled(
experimental_flags::kExternalFilesLoadedInWebState)) {
// External URL will be loaded by WebState, which expects |completeURL|.
// Omnibox however suppose to display |externalURL|, which is used as
// virtual URL.
URL = [params completeURL];
virtualURL = [params externalURL];
} else {
URL = [params externalURL];
}
[tabOpener
dismissModalsAndOpenSelectedTabInMode:[params launchInIncognito]
? ApplicationMode::INCOGNITO
: ApplicationMode::NORMAL
withURL:[params externalURL]
virtualURL:GURL::EmptyGURL()
withURL:URL
virtualURL:virtualURL
dismissOmnibox:[params postOpeningAction] !=
FOCUS_OMNIBOX
transition:ui::PAGE_TRANSITION_LINK
......
......@@ -6,11 +6,13 @@
#import <Foundation/Foundation.h>
#include "base/test/scoped_feature_list.h"
#include "ios/chrome/app/application_delegate/app_state.h"
#include "ios/chrome/app/application_delegate/mock_tab_opener.h"
#include "ios/chrome/app/application_delegate/startup_information.h"
#include "ios/chrome/app/startup/chrome_app_startup_parameters.h"
#include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
#include "ios/chrome/browser/system_flags.h"
#import "ios/chrome/browser/tabs/tab_model.h"
#import "ios/chrome/browser/ui/main/test/stub_browser_interface.h"
#import "ios/chrome/browser/ui/main/test/stub_browser_interface_provider.h"
......@@ -26,6 +28,13 @@
#error "This file requires ARC support."
#endif
// URLOpenerTest is parameterized on this enum to test with
// enabled and disabled kExternalFilesLoadedInWebState feature flag.
enum class ExternalFilesLoadedInWebStateFeature {
Disabled = 0,
Enabled,
};
@interface StubStartupInformation : NSObject <StartupInformation>
@end
@implementation StubStartupInformation
......@@ -55,17 +64,26 @@
@end
class URLOpenerTest : public PlatformTest {
class URLOpenerTest
: public PlatformTest,
public testing::WithParamInterface<ExternalFilesLoadedInWebStateFeature> {
protected:
void TearDown() override {
PlatformTest::TearDown();
URLOpenerTest() {
if (GetParam() == ExternalFilesLoadedInWebStateFeature::Enabled) {
scoped_feature_list_.InitAndEnableFeature(
experimental_flags::kExternalFilesLoadedInWebState);
} else {
scoped_feature_list_.InitAndDisableFeature(
experimental_flags::kExternalFilesLoadedInWebState);
}
}
private:
web::TestWebThreadBundle thread_bundle_;
base::test::ScopedFeatureList scoped_feature_list_;
};
TEST_F(URLOpenerTest, HandleOpenURL) {
TEST_P(URLOpenerTest, HandleOpenURL) {
// A set of tests for robustness of
// application:openURL:options:tabOpener:startupInformation:
// It verifies that the function handles correctly different URLs parsed by
......@@ -168,7 +186,21 @@ TEST_F(URLOpenerTest, HandleOpenURL) {
else
EXPECT_EQ(nil, startupInformation.startupParameters);
} else if (result) {
EXPECT_EQ([params externalURL], [tabOpener url]);
if (GetParam() == ExternalFilesLoadedInWebStateFeature::Enabled) {
if ([params completeURL].SchemeIsFile()) {
// External file:// URL will be loaded by WebState, which
// expects complete // file:// URL. chrome:// URL is expected to
// be displayed in the omnibox, and omnibox shows virtual URL.
EXPECT_EQ([params completeURL], [tabOpener url]);
EXPECT_EQ([params externalURL], [tabOpener virtualURL]);
} else {
// External chromium-x-callback:// URL will be loaded by
// WebState, which expects externalURL URL.
EXPECT_EQ([params externalURL], [tabOpener url]);
}
} else {
EXPECT_EQ([params externalURL], [tabOpener url]);
}
tabOpener.completionBlock();
EXPECT_EQ(nil, startupInformation.startupParameters);
}
......@@ -179,7 +211,7 @@ TEST_F(URLOpenerTest, HandleOpenURL) {
}
// Tests that -handleApplication set startup parameters as expected.
TEST_F(URLOpenerTest, VerifyLaunchOptions) {
TEST_P(URLOpenerTest, VerifyLaunchOptions) {
// Setup.
NSURL* url = [NSURL URLWithString:@"chromium://www.google.com"];
NSDictionary* launchOptions = @{
......@@ -230,7 +262,7 @@ TEST_F(URLOpenerTest, VerifyLaunchOptions) {
// Tests that -handleApplication set startup parameters as expected with options
// as nil.
TEST_F(URLOpenerTest, VerifyLaunchOptionsNil) {
TEST_P(URLOpenerTest, VerifyLaunchOptionsNil) {
// Creates a mock with no stub. This test will pass only if we don't use these
// objects.
id startupInformationMock =
......@@ -247,7 +279,7 @@ TEST_F(URLOpenerTest, VerifyLaunchOptionsNil) {
// Tests that -handleApplication set startup parameters as expected with no
// source application.
TEST_F(URLOpenerTest, VerifyLaunchOptionsWithNoSourceApplication) {
TEST_P(URLOpenerTest, VerifyLaunchOptionsWithNoSourceApplication) {
// Setup.
NSURL* url = [NSURL URLWithString:@"chromium://www.google.com"];
NSDictionary* launchOptions = @{
......@@ -269,7 +301,7 @@ TEST_F(URLOpenerTest, VerifyLaunchOptionsWithNoSourceApplication) {
}
// Tests that -handleApplication set startup parameters as expected with no url.
TEST_F(URLOpenerTest, VerifyLaunchOptionsWithNoURL) {
TEST_P(URLOpenerTest, VerifyLaunchOptionsWithNoURL) {
// Setup.
NSDictionary* launchOptions = @{
UIApplicationLaunchOptionsSourceApplicationKey : @"com.apple.mobilesafari"
......@@ -291,7 +323,7 @@ TEST_F(URLOpenerTest, VerifyLaunchOptionsWithNoURL) {
// Tests that -handleApplication set startup parameters as expected with a bad
// url.
TEST_F(URLOpenerTest, VerifyLaunchOptionsWithBadURL) {
TEST_P(URLOpenerTest, VerifyLaunchOptionsWithBadURL) {
// Setup.
NSURL* url = [NSURL URLWithString:@"chromium.www.google.com"];
NSDictionary* launchOptions = @{
......@@ -339,3 +371,9 @@ TEST_F(URLOpenerTest, VerifyLaunchOptionsWithBadURL) {
EXPECT_TRUE(hasBeenCalled);
EXPECT_OCMOCK_VERIFY(startupInformationMock);
}
INSTANTIATE_TEST_SUITE_P(
ProgrammaticURLOpenerTest,
URLOpenerTest,
::testing::Values(ExternalFilesLoadedInWebStateFeature::Enabled,
ExternalFilesLoadedInWebStateFeature::Disabled));
......@@ -255,6 +255,10 @@ NSString* const kShortcutQRScanner = @"OpenQRScanner";
if ([tabOpener shouldCompletePaymentRequestOnCurrentTab:startupInformation])
return;
// TODO(crbug.com/935019): Exacly the same copy of this code is present in
// +[URLOpener
// openURL:applicationActive:options:tabOpener:startupInformation:]
// The app is already active so the applicationDidBecomeActive: method
// will never be called. Open the requested URL after all modal UIs have
// been dismissed. |_startupParameters| must be retained until all deferred
......
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