First step in enabling creating tabs without an Activity on Android.
This patch modifies the ContentBrowserClient::OpenURL method to pass a
callback, to be invoked when the content::WebContents* is available,
rather than returning it immediately as this will be an asynchronous
process on Android.
For actually opening a new tab, we create a ServiceTabCreator class which
has the ability to create tabs from Services. This method will fire
an intent to start the activity asynchronously.
The follow-up patch will make the activity communicate back a reference
to the created TabAndroid / WebContents, which allows the Service to
get it, and finalize the callback as expected.
BUG=454809
Review URL: https://codereview.chromium.org/897673002
Cr-Commit-Position: refs/heads/master@{#315855}
diff --git a/chrome/browser/chrome_content_browser_client_unittest.cc b/chrome/browser/chrome_content_browser_client_unittest.cc
index 42c45c5f..c0235f1 100644
--- a/chrome/browser/chrome_content_browser_client_unittest.cc
+++ b/chrome/browser/chrome_content_browser_client_unittest.cc
@@ -32,11 +32,18 @@
EXPECT_TRUE(client.ShouldAssignSiteForURL(GURL("https://www.google.com")));
}
-using ChromeContentBrowserClientWindowTest = BrowserWithTestWindowTest;
-
// BrowserWithTestWindowTest doesn't work on iOS and Android.
#if !defined(OS_ANDROID) && !defined(OS_IOS)
+using ChromeContentBrowserClientWindowTest = BrowserWithTestWindowTest;
+
+static void DidOpenURLForWindowTest(content::WebContents** target_contents,
+ content::WebContents* opened_contents) {
+ DCHECK(target_contents);
+
+ *target_contents = opened_contents;
+}
+
// This test opens two URLs using ContentBrowserClient::OpenURL. It expects the
// URLs to be opened in new tabs and activated, changing the active tabs after
// each call and increasing the tab count by 2.
@@ -54,13 +61,20 @@
NEW_FOREGROUND_TAB,
ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
false);
- content::WebContents* contents =
- client.OpenURL(browser()->profile(), params);
- EXPECT_TRUE(contents);
+ // TODO(peter): We should have more in-depth browser tests for the window
+ // opening functionality, which also covers Android. This test can currently
+ // only be ran on platforms where OpenURL is implemented synchronously.
+ // See https://crbug.com/457667.
+ content::WebContents* web_contents = nullptr;
+ client.OpenURL(browser()->profile(),
+ params,
+ base::Bind(&DidOpenURLForWindowTest, &web_contents));
+
+ EXPECT_TRUE(web_contents);
content::WebContents* active_contents = browser()->tab_strip_model()->
GetActiveWebContents();
- EXPECT_EQ(contents, active_contents);
+ EXPECT_EQ(web_contents, active_contents);
EXPECT_EQ(url, active_contents->GetVisibleURL());
}