OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/apps/app_browsertest_util.h" | 5 #include "chrome/browser/apps/app_browsertest_util.h" |
6 | 6 |
7 #include "apps/app_window_contents.h" | 7 #include "apps/app_window_contents.h" |
8 #include "apps/native_app_window.h" | 8 #include "apps/native_app_window.h" |
9 #include "apps/shell_window_registry.h" | 9 #include "apps/shell_window_registry.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "chrome/browser/extensions/api/tabs/tabs_api.h" | 12 #include "chrome/browser/extensions/api/tabs/tabs_api.h" |
13 #include "chrome/browser/extensions/extension_function_test_utils.h" | 13 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 14 #include "chrome/browser/extensions/extension_test_message_listener.h" |
14 #include "chrome/browser/ui/apps/chrome_shell_window_delegate.h" | 15 #include "chrome/browser/ui/apps/chrome_shell_window_delegate.h" |
15 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/extensions/application_launch.h" | 17 #include "chrome/browser/ui/extensions/application_launch.h" |
17 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/test/base/ui_test_utils.h" |
18 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
| 21 #include "content/public/test/browser_test_base.h" |
19 #include "content/public/test/test_utils.h" | 22 #include "content/public/test/test_utils.h" |
20 #include "extensions/common/switches.h" | 23 #include "extensions/common/switches.h" |
| 24 #include "net/test/embedded_test_server/embedded_test_server.h" |
21 | 25 |
22 using apps::ShellWindow; | 26 using apps::ShellWindow; |
23 using apps::ShellWindowRegistry; | 27 using apps::ShellWindowRegistry; |
24 using content::WebContents; | 28 using content::WebContents; |
25 | 29 |
26 namespace utils = extension_function_test_utils; | 30 namespace utils = extension_function_test_utils; |
27 | 31 |
28 namespace extensions { | 32 namespace extensions { |
29 | 33 |
30 PlatformAppBrowserTest::PlatformAppBrowserTest() { | 34 PlatformAppBrowserTest::PlatformAppBrowserTest() { |
(...skipping 22 matching lines...) Expand all Loading... |
53 chrome::OpenApplication(chrome::AppLaunchParams(browser()->profile(), | 57 chrome::OpenApplication(chrome::AppLaunchParams(browser()->profile(), |
54 extension, | 58 extension, |
55 extension_misc::LAUNCH_NONE, | 59 extension_misc::LAUNCH_NONE, |
56 NEW_WINDOW)); | 60 NEW_WINDOW)); |
57 | 61 |
58 app_loaded_observer.Wait(); | 62 app_loaded_observer.Wait(); |
59 | 63 |
60 return extension; | 64 return extension; |
61 } | 65 } |
62 | 66 |
| 67 const Extension* PlatformAppBrowserTest::InstallPlatformApp( |
| 68 const char* name) { |
| 69 const Extension* extension = InstallExtension( |
| 70 test_data_dir_.AppendASCII("platform_apps").AppendASCII(name), 1); |
| 71 EXPECT_TRUE(extension); |
| 72 |
| 73 return extension; |
| 74 } |
| 75 |
63 const Extension* PlatformAppBrowserTest::InstallAndLaunchPlatformApp( | 76 const Extension* PlatformAppBrowserTest::InstallAndLaunchPlatformApp( |
64 const char* name) { | 77 const char* name) { |
65 content::WindowedNotificationObserver app_loaded_observer( | 78 content::WindowedNotificationObserver app_loaded_observer( |
66 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 79 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
67 content::NotificationService::AllSources()); | 80 content::NotificationService::AllSources()); |
68 | 81 |
69 const Extension* extension = InstallExtension( | 82 const Extension* extension = InstallPlatformApp(name); |
70 test_data_dir_.AppendASCII("platform_apps").AppendASCII(name), 1); | |
71 EXPECT_TRUE(extension); | |
72 | 83 |
73 chrome::OpenApplication(chrome::AppLaunchParams(browser()->profile(), | 84 chrome::OpenApplication(chrome::AppLaunchParams(browser()->profile(), |
74 extension, | 85 extension, |
75 extension_misc::LAUNCH_NONE, | 86 extension_misc::LAUNCH_NONE, |
76 NEW_WINDOW)); | 87 NEW_WINDOW)); |
77 | 88 |
78 app_loaded_observer.Wait(); | 89 app_loaded_observer.Wait(); |
79 | 90 |
80 return extension; | 91 return extension; |
81 } | 92 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 minimum_size, | 195 minimum_size, |
185 bounds); | 196 bounds); |
186 } | 197 } |
187 | 198 |
188 void ExperimentalPlatformAppBrowserTest::SetUpCommandLine( | 199 void ExperimentalPlatformAppBrowserTest::SetUpCommandLine( |
189 CommandLine* command_line) { | 200 CommandLine* command_line) { |
190 PlatformAppBrowserTest::SetUpCommandLine(command_line); | 201 PlatformAppBrowserTest::SetUpCommandLine(command_line); |
191 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); | 202 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); |
192 } | 203 } |
193 | 204 |
| 205 void PlatformAppUrlRedirectorBrowserTest::SetUpCommandLine( |
| 206 CommandLine* command_line) { |
| 207 PlatformAppBrowserTest::SetUpCommandLine(command_line); |
| 208 command_line->AppendSwitch(::switches::kDisablePopupBlocking); |
| 209 } |
| 210 |
| 211 void PlatformAppUrlRedirectorBrowserTest::TestNavigationInTab( |
| 212 const char* launcher_page_path, |
| 213 const char* handler_path, |
| 214 const char* handler_ack, |
| 215 size_t expected_shell_window_count) { |
| 216 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 217 |
| 218 InstallPlatformApp(handler_path); |
| 219 |
| 220 ExtensionTestMessageListener handler_listener(handler_ack, false); |
| 221 |
| 222 ui_test_utils::NavigateToURLWithDisposition( |
| 223 browser(), |
| 224 embedded_test_server()->GetURL(base::StringPrintf( |
| 225 "/extensions/platform_apps/%s", launcher_page_path)), |
| 226 CURRENT_TAB, |
| 227 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 228 |
| 229 ASSERT_TRUE(handler_listener.WaitUntilSatisfied()); |
| 230 |
| 231 // The above navigations click on 2 links (regular and target blank) and call |
| 232 // 1 window.open(), all of which should be intercepted and launch the |
| 233 // handler app. |
| 234 ASSERT_EQ(expected_shell_window_count, GetShellWindowCount()); |
| 235 } |
| 236 |
| 237 void PlatformAppUrlRedirectorBrowserTest::TestNavigationInApp( |
| 238 const char* launcher_path, |
| 239 const char* launcher_ack, |
| 240 const char* handler_path, |
| 241 const char* handler_ack, |
| 242 size_t expected_shell_window_count) { |
| 243 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 244 |
| 245 InstallPlatformApp(handler_path); |
| 246 |
| 247 ExtensionTestMessageListener launcher_listener(launcher_ack, false); |
| 248 ExtensionTestMessageListener handler_listener(handler_ack, false); |
| 249 |
| 250 LoadAndLaunchPlatformApp(launcher_path); |
| 251 |
| 252 ASSERT_TRUE(launcher_listener.WaitUntilSatisfied()); |
| 253 ASSERT_TRUE(handler_listener.WaitUntilSatisfied()); |
| 254 |
| 255 // The launcher clicks on a link, which gets intercepted and launches the |
| 256 // handler. |
| 257 ASSERT_EQ(expected_shell_window_count, GetShellWindowCount()); |
| 258 } |
| 259 |
194 } // namespace extensions | 260 } // namespace extensions |
OLD | NEW |