Index: chrome/browser/apps/app_browsertest_util.cc |
diff --git a/chrome/browser/apps/app_browsertest_util.cc b/chrome/browser/apps/app_browsertest_util.cc |
index 7a2f9cee53d19d0c71688637bd2b3c2732dbac7f..1f1ff072706f75d2835a63fdc27b666b25258eab 100644 |
--- a/chrome/browser/apps/app_browsertest_util.cc |
+++ b/chrome/browser/apps/app_browsertest_util.cc |
@@ -11,13 +11,17 @@ |
#include "base/strings/stringprintf.h" |
#include "chrome/browser/extensions/api/tabs/tabs_api.h" |
#include "chrome/browser/extensions/extension_function_test_utils.h" |
+#include "chrome/browser/extensions/extension_test_message_listener.h" |
#include "chrome/browser/ui/apps/chrome_shell_window_delegate.h" |
#include "chrome/browser/ui/browser.h" |
#include "chrome/browser/ui/extensions/application_launch.h" |
#include "chrome/common/chrome_switches.h" |
+#include "chrome/test/base/ui_test_utils.h" |
#include "content/public/browser/notification_service.h" |
+#include "content/public/test/browser_test_base.h" |
#include "content/public/test/test_utils.h" |
#include "extensions/common/switches.h" |
+#include "net/test/embedded_test_server/embedded_test_server.h" |
using apps::ShellWindow; |
using apps::ShellWindowRegistry; |
@@ -60,15 +64,22 @@ const Extension* PlatformAppBrowserTest::LoadAndLaunchPlatformApp( |
return extension; |
} |
+const Extension* PlatformAppBrowserTest::InstallPlatformApp( |
+ const char* name) { |
+ const Extension* extension = InstallExtension( |
+ test_data_dir_.AppendASCII("platform_apps").AppendASCII(name), 1); |
+ EXPECT_TRUE(extension); |
+ |
+ return extension; |
+} |
+ |
const Extension* PlatformAppBrowserTest::InstallAndLaunchPlatformApp( |
const char* name) { |
content::WindowedNotificationObserver app_loaded_observer( |
content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
content::NotificationService::AllSources()); |
- const Extension* extension = InstallExtension( |
- test_data_dir_.AppendASCII("platform_apps").AppendASCII(name), 1); |
- EXPECT_TRUE(extension); |
+ const Extension* extension = InstallPlatformApp(name); |
chrome::OpenApplication(chrome::AppLaunchParams(browser()->profile(), |
extension, |
@@ -191,4 +202,59 @@ void ExperimentalPlatformAppBrowserTest::SetUpCommandLine( |
command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); |
} |
+void PlatformAppUrlRedirectorBrowserTest::SetUpCommandLine( |
+ CommandLine* command_line) { |
+ PlatformAppBrowserTest::SetUpCommandLine(command_line); |
+ command_line->AppendSwitch(::switches::kDisablePopupBlocking); |
+} |
+ |
+void PlatformAppUrlRedirectorBrowserTest::TestNavigationInTab( |
+ const char* launcher_page_path, |
+ const char* handler_path, |
+ const char* handler_ack, |
+ size_t expected_shell_window_count) { |
+ ASSERT_TRUE(StartEmbeddedTestServer()); |
+ |
+ InstallPlatformApp(handler_path); |
+ |
+ ExtensionTestMessageListener handler_listener(handler_ack, false); |
+ |
+ ui_test_utils::NavigateToURLWithDisposition( |
+ browser(), |
+ embedded_test_server()->GetURL(base::StringPrintf( |
+ "/extensions/platform_apps/%s", launcher_page_path)), |
+ CURRENT_TAB, |
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
+ |
+ 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(expected_shell_window_count, GetShellWindowCount()); |
+} |
+ |
+void PlatformAppUrlRedirectorBrowserTest::TestNavigationInApp( |
+ const char* launcher_path, |
+ const char* launcher_ack, |
+ const char* handler_path, |
+ const char* handler_ack, |
+ size_t expected_shell_window_count) { |
+ ASSERT_TRUE(StartEmbeddedTestServer()); |
+ |
+ InstallPlatformApp(handler_path); |
+ |
+ ExtensionTestMessageListener launcher_listener(launcher_ack, false); |
+ ExtensionTestMessageListener handler_listener(handler_ack, false); |
+ |
+ LoadAndLaunchPlatformApp(launcher_path); |
+ |
+ 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(expected_shell_window_count, GetShellWindowCount()); |
+} |
+ |
} // namespace extensions |