Index: chrome/browser/apps/app_browsertest.cc |
diff --git a/chrome/browser/apps/app_browsertest.cc b/chrome/browser/apps/app_browsertest.cc |
index 951fd093297f88b534d1dbf3ffe5be655e2e1ab0..6aa41e1dcaec9d33562ceb4778d2cb9466968129 100644 |
--- a/chrome/browser/apps/app_browsertest.cc |
+++ b/chrome/browser/apps/app_browsertest.cc |
@@ -635,6 +635,86 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OpenLink) { |
ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
} |
+ |
+// Test that clicks on any type of links in a tab + window.open() launch |
+// an app that has a matching handler in url_handlers. |
+IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, |
+ UrlHandlersNavigationsInTabIntercepted) { |
not at google - send to devlin
2013/09/07 00:54:56
can you put these tests in a different file? This
sergeygs
2013/09/09 09:55:36
Done. If we start in this direction, it would be n
not at google - send to devlin
2013/09/09 19:01:13
Absolutely.
|
+ CommandLine::ForCurrentProcess()->AppendSwitch( |
+ switches::kDisablePopupBlocking); |
+ |
+ ASSERT_TRUE(StartEmbeddedTestServer()); |
+ |
+ InstallPlatformApp("url_handlers/handler"); |
+ |
+ const std::string href_root = |
+ "/extensions/platform_apps/url_handlers/launching_tabs/"; |
+ const std::string hrefs[] = { |
+ "click_link.html", |
+ "click_blank_link.html", |
+ "call_window_open.html", |
+ }; |
not at google - send to devlin
2013/09/07 00:54:56
might as well use const char*s here rather than st
sergeygs
2013/09/09 09:55:36
Done.
|
+ |
+ for (size_t i = 0; i < sizeof(hrefs) / sizeof(*hrefs); ++i) { |
not at google - send to devlin
2013/09/07 00:54:56
use arraysize(hrefs) or ARRAYSIZE_UNSAFE if that d
sergeygs
2013/09/09 09:55:36
Obsolete.
|
+ GURL url = embedded_test_server()->GetURL(href_root + hrefs[i]); |
+ |
+ ui_test_utils::NavigateToURLWithDisposition( |
+ browser(), url, |
+ CURRENT_TAB, |
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
+ |
+ ExtensionTestMessageListener handler_listener("Handler launched", false); |
+ ASSERT_TRUE(handler_listener.WaitUntilSatisfied()); |
+ } |
+ |
+ // The above navigations click on 2 links (regular and target blank) and call |
+ // 1 window.open(), all of which should be intercepted and launch the |
+ // handler app. |
+ ASSERT_EQ(3U, GetShellWindowCount()); |
not at google - send to devlin
2013/09/07 00:54:56
asserting based on the number of shell windows ope
sergeygs
2013/09/09 09:55:36
chrome.test.sendMessage _is_ used here, see the en
not at google - send to devlin
2013/09/09 19:01:13
Ah, I see. Thanks.
|
+} |
+ |
+// Test that a click on link in an app windows launches an app that has |
+// a matching handler in url_handlers. |
+IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, |
+ UrlHandlersClickInAppIntercepted) { |
+ ASSERT_TRUE(StartEmbeddedTestServer()); |
+ |
+ ExtensionTestMessageListener launcher_listener("Launcher launched", false); |
+ ExtensionTestMessageListener handler_listener("Handler launched", false); |
+ |
+ InstallPlatformApp("url_handlers/handler"); |
+ LoadAndLaunchPlatformApp("url_handlers/launcher"); |
+ |
+ ASSERT_TRUE(launcher_listener.WaitUntilSatisfied()); |
+ ASSERT_TRUE(handler_listener.WaitUntilSatisfied()); |
+ |
+ // The launcher clicks on a link, which gets intercepted and launches the |
+ // handler. |
+ ASSERT_EQ(2U, GetShellWindowCount()); |
+} |
+ |
+// Test that a webview can navigate to URLs even when there are apps installed |
+// that have matching url_handlers. |
+IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, |
+ UrlHandlersWebviewNavigationNotIntercepted) { |
+ ASSERT_TRUE(StartEmbeddedTestServer()); |
+ |
+ ExtensionTestMessageListener handler_listener("Handler launched", false); |
+ |
+ InstallPlatformApp("url_handlers/handler_with_webview"); |
+ LoadAndLaunchPlatformApp("url_handlers/launcher"); |
+ |
+ ASSERT_TRUE(handler_listener.WaitUntilSatisfied()); |
+ base::PlatformThread::Sleep(TestTimeouts::action_timeout()); |
+ |
+ // The launcher clicks on a link, which gets intercepted and launches the |
+ // handler. The handler also redirects an embedded webview to the URL. The |
+ // webview should just navigate without creating an endless loop of |
+ // navigate-intercept-launch sequences with multiplying handler's windows. |
+ // There should be 2 windows only: launcher's and handler's. |
+ ASSERT_EQ(2U, GetShellWindowCount()); |
+} |
+ |
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MutationEventsDisabled) { |
ASSERT_TRUE(RunPlatformAppTest("platform_apps/mutation_events")) << message_; |
} |