[email protected] | a4465720 | 2012-01-09 05:48:31 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | cfc6cca | 2011-12-01 02:30:06 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 939532d0 | 2012-08-31 23:37:33 | [diff] [blame^] | 5 | #include "base/test/test_timeouts.h" |
| 6 | #include "base/threading/platform_thread.h" |
[email protected] | b3c019b | 2012-08-28 02:43:48 | [diff] [blame] | 7 | #include "base/utf_string_conversions.h" |
[email protected] | ad687a7 | 2012-06-08 06:03:11 | [diff] [blame] | 8 | #include "chrome/app/chrome_command_ids.h" |
[email protected] | 605fb810 | 2012-05-04 01:36:55 | [diff] [blame] | 9 | #include "chrome/browser/automation/automation_util.h" |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 10 | #include "chrome/browser/tab_contents/render_view_context_menu.h" |
[email protected] | 25977110 | 2012-05-31 16:52:20 | [diff] [blame] | 11 | #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 12 | #include "chrome/browser/extensions/platform_app_browsertest_util.h" |
| 13 | #include "chrome/browser/extensions/shell_window_registry.h" |
[email protected] | cfc6cca | 2011-12-01 02:30:06 | [diff] [blame] | 14 | #include "chrome/browser/ui/browser.h" |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 15 | #include "chrome/browser/ui/browser_tabstrip.h" |
[email protected] | a5a0be0 | 2012-07-18 05:51:54 | [diff] [blame] | 16 | #include "chrome/browser/ui/extensions/application_launch.h" |
[email protected] | d72d3a6 | 2012-05-10 03:45:08 | [diff] [blame] | 17 | #include "chrome/browser/ui/extensions/shell_window.h" |
[email protected] | 5b1a04b4 | 2012-06-15 00:41:44 | [diff] [blame] | 18 | #include "chrome/common/chrome_notification_types.h" |
[email protected] | cfc6cca | 2011-12-01 02:30:06 | [diff] [blame] | 19 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | fb29e6cf | 2012-07-12 21:27:20 | [diff] [blame] | 20 | #include "content/public/browser/render_process_host.h" |
[email protected] | cfc6cca | 2011-12-01 02:30:06 | [diff] [blame] | 21 | |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 22 | using content::WebContents; |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 23 | |
| 24 | namespace extensions { |
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 25 | |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 26 | namespace { |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 27 | |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 28 | // Non-abstract RenderViewContextMenu class. |
| 29 | class PlatformAppContextMenu : public RenderViewContextMenu { |
| 30 | public: |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 31 | PlatformAppContextMenu(WebContents* web_contents, |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 32 | const content::ContextMenuParams& params) |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 33 | : RenderViewContextMenu(web_contents, params) {} |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 34 | |
[email protected] | ad687a7 | 2012-06-08 06:03:11 | [diff] [blame] | 35 | bool HasCommandWithId(int command_id) { |
| 36 | return menu_model_.GetIndexOfCommandId(command_id) != -1; |
| 37 | } |
| 38 | |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 39 | protected: |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 40 | // RenderViewContextMenu implementation. |
| 41 | virtual bool GetAcceleratorForCommandId( |
| 42 | int command_id, |
| 43 | ui::Accelerator* accelerator) OVERRIDE { |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 44 | return false; |
| 45 | } |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 46 | virtual void PlatformInit() OVERRIDE {} |
| 47 | virtual void PlatformCancel() OVERRIDE {} |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 48 | }; |
| 49 | |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 50 | const char kTestFilePath[] = "platform_apps/launch_files/test.txt"; |
| 51 | |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 52 | } // namespace |
| 53 | |
[email protected] | eb4bcac | 2012-06-27 01:32:08 | [diff] [blame] | 54 | // Tests that CreateShellWindow doesn't crash if you close it straight away. |
| 55 | // LauncherPlatformAppBrowserTest relies on this behaviour, but is only run for |
| 56 | // ash, so we test that it works here. |
| 57 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, CreateAndCloseShellWindow) { |
| 58 | const Extension* extension = LoadAndLaunchPlatformApp("minimal"); |
| 59 | ShellWindow* window = CreateShellWindow(extension); |
| 60 | CloseShellWindow(window); |
| 61 | } |
| 62 | |
[email protected] | dc37b00 | 2012-04-23 23:02:26 | [diff] [blame] | 63 | // Tests that platform apps received the "launch" event when launched. |
| 64 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OnLaunchedEvent) { |
| 65 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_; |
[email protected] | cfc6cca | 2011-12-01 02:30:06 | [diff] [blame] | 66 | } |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 67 | |
[email protected] | 567230b | 2012-08-21 21:11:44 | [diff] [blame] | 68 | // Tests that platform apps cannot use certain disabled window properties, but |
| 69 | // can override them and then use them. |
| 70 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisabledWindowProperties) { |
| 71 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/disabled_window_properties")) |
| 72 | << message_; |
| 73 | } |
| 74 | |
[email protected] | edd7ed69 | 2012-02-08 02:50:03 | [diff] [blame] | 75 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) { |
[email protected] | dc37b00 | 2012-04-23 23:02:26 | [diff] [blame] | 76 | ExtensionTestMessageListener launched_listener("Launched", false); |
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 77 | LoadAndLaunchPlatformApp("minimal"); |
[email protected] | dc37b00 | 2012-04-23 23:02:26 | [diff] [blame] | 78 | |
| 79 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 80 | |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 81 | // The empty app doesn't add any context menu items, so its menu should |
[email protected] | 0cfacd8 | 2012-02-09 01:55:33 | [diff] [blame] | 82 | // only include the developer tools. |
[email protected] | d72d3a6 | 2012-05-10 03:45:08 | [diff] [blame] | 83 | WebContents* web_contents = GetFirstShellWindowWebContents(); |
[email protected] | a4465720 | 2012-01-09 05:48:31 | [diff] [blame] | 84 | ASSERT_TRUE(web_contents); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 85 | WebKit::WebContextMenuData data; |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 86 | content::ContextMenuParams params(data); |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 87 | scoped_ptr<PlatformAppContextMenu> menu; |
| 88 | menu.reset(new PlatformAppContextMenu(web_contents, params)); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 89 | menu->Init(); |
[email protected] | ad687a7 | 2012-06-08 06:03:11 | [diff] [blame] | 90 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
| 91 | ASSERT_TRUE(menu->HasCommandWithId(IDC_RELOAD)); |
| 92 | ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 93 | ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 94 | } |
| 95 | |
[email protected] | edd7ed69 | 2012-02-08 02:50:03 | [diff] [blame] | 96 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) { |
[email protected] | dc37b00 | 2012-04-23 23:02:26 | [diff] [blame] | 97 | ExtensionTestMessageListener launched_listener("Launched", false); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 98 | LoadAndLaunchPlatformApp("context_menu"); |
| 99 | |
[email protected] | dc37b00 | 2012-04-23 23:02:26 | [diff] [blame] | 100 | // Wait for the extension to tell us it's initialized its context menus and |
| 101 | // launched a window. |
| 102 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 103 | |
[email protected] | 271d01c | 2012-08-27 23:48:05 | [diff] [blame] | 104 | // The context_menu app has two context menu items. These, along with a |
[email protected] | 0cfacd8 | 2012-02-09 01:55:33 | [diff] [blame] | 105 | // separator and the developer tools, is all that should be in the menu. |
[email protected] | d72d3a6 | 2012-05-10 03:45:08 | [diff] [blame] | 106 | WebContents* web_contents = GetFirstShellWindowWebContents(); |
[email protected] | a4465720 | 2012-01-09 05:48:31 | [diff] [blame] | 107 | ASSERT_TRUE(web_contents); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 108 | WebKit::WebContextMenuData data; |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 109 | content::ContextMenuParams params(data); |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 110 | scoped_ptr<PlatformAppContextMenu> menu; |
| 111 | menu.reset(new PlatformAppContextMenu(web_contents, params)); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 112 | menu->Init(); |
[email protected] | ad687a7 | 2012-06-08 06:03:11 | [diff] [blame] | 113 | ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
[email protected] | 271d01c | 2012-08-27 23:48:05 | [diff] [blame] | 114 | ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1)); |
[email protected] | ad687a7 | 2012-06-08 06:03:11 | [diff] [blame] | 115 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
| 116 | ASSERT_TRUE(menu->HasCommandWithId(IDC_RELOAD)); |
| 117 | ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 118 | ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
[email protected] | b3c019b | 2012-08-28 02:43:48 | [diff] [blame] | 119 | ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
| 120 | } |
| 121 | |
| 122 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuTextField) { |
| 123 | ExtensionTestMessageListener launched_listener("Launched", false); |
| 124 | LoadAndLaunchPlatformApp("context_menu"); |
| 125 | |
| 126 | // Wait for the extension to tell us it's initialized its context menus and |
| 127 | // launched a window. |
| 128 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 129 | |
| 130 | // The context_menu app has one context menu item. This, along with a |
| 131 | // separator and the developer tools, is all that should be in the menu. |
| 132 | WebContents* web_contents = GetFirstShellWindowWebContents(); |
| 133 | ASSERT_TRUE(web_contents); |
| 134 | WebKit::WebContextMenuData data; |
| 135 | content::ContextMenuParams params(data); |
| 136 | params.is_editable = true; |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 137 | scoped_ptr<PlatformAppContextMenu> menu; |
| 138 | menu.reset(new PlatformAppContextMenu(web_contents, params)); |
[email protected] | b3c019b | 2012-08-28 02:43:48 | [diff] [blame] | 139 | menu->Init(); |
| 140 | ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
| 141 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
| 142 | ASSERT_TRUE(menu->HasCommandWithId(IDC_RELOAD)); |
| 143 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
| 144 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); |
| 145 | ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 146 | ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
| 147 | } |
| 148 | |
| 149 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuSelection) { |
| 150 | ExtensionTestMessageListener launched_listener("Launched", false); |
| 151 | LoadAndLaunchPlatformApp("context_menu"); |
| 152 | |
| 153 | // Wait for the extension to tell us it's initialized its context menus and |
| 154 | // launched a window. |
| 155 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 156 | |
| 157 | // The context_menu app has one context menu item. This, along with a |
| 158 | // separator and the developer tools, is all that should be in the menu. |
| 159 | WebContents* web_contents = GetFirstShellWindowWebContents(); |
| 160 | ASSERT_TRUE(web_contents); |
| 161 | WebKit::WebContextMenuData data; |
| 162 | content::ContextMenuParams params(data); |
| 163 | params.selection_text = ASCIIToUTF16("Hello World"); |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 164 | scoped_ptr<PlatformAppContextMenu> menu; |
| 165 | menu.reset(new PlatformAppContextMenu(web_contents, params)); |
[email protected] | b3c019b | 2012-08-28 02:43:48 | [diff] [blame] | 166 | menu->Init(); |
| 167 | ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
| 168 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
| 169 | ASSERT_TRUE(menu->HasCommandWithId(IDC_RELOAD)); |
| 170 | ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
| 171 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); |
| 172 | ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 173 | ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 174 | } |
[email protected] | 5f000f27 | 2012-01-19 05:25:08 | [diff] [blame] | 175 | |
[email protected] | dc83c58 | 2012-08-17 02:18:14 | [diff] [blame] | 176 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuClicked) { |
| 177 | ExtensionTestMessageListener launched_listener("Launched", false); |
| 178 | LoadAndLaunchPlatformApp("context_menu_click"); |
| 179 | |
| 180 | // Wait for the extension to tell us it's initialized its context menus and |
| 181 | // launched a window. |
| 182 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 183 | |
| 184 | // Test that the menu item shows up |
| 185 | WebContents* web_contents = GetFirstShellWindowWebContents(); |
| 186 | ASSERT_TRUE(web_contents); |
| 187 | WebKit::WebContextMenuData data; |
| 188 | content::ContextMenuParams params(data); |
| 189 | params.page_url = GURL("http://foo.bar"); |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 190 | scoped_ptr<PlatformAppContextMenu> menu; |
| 191 | menu.reset(new PlatformAppContextMenu(web_contents, params)); |
[email protected] | dc83c58 | 2012-08-17 02:18:14 | [diff] [blame] | 192 | menu->Init(); |
| 193 | ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
| 194 | |
| 195 | // Execute the menu item |
| 196 | ExtensionTestMessageListener onclicked_listener("onClicked fired for id1", |
| 197 | false); |
| 198 | menu->ExecuteCommand(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST); |
| 199 | |
| 200 | ASSERT_TRUE(onclicked_listener.WaitUntilSatisfied()); |
| 201 | } |
| 202 | |
[email protected] | edd7ed69 | 2012-02-08 02:50:03 | [diff] [blame] | 203 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowNavigation) { |
[email protected] | dc37b00 | 2012-04-23 23:02:26 | [diff] [blame] | 204 | ASSERT_TRUE(StartTestServer()); |
| 205 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/navigation")) << message_; |
[email protected] | 5f000f27 | 2012-01-19 05:25:08 | [diff] [blame] | 206 | } |
[email protected] | 863e647 | 2012-01-24 19:33:58 | [diff] [blame] | 207 | |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 208 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Iframes) { |
| 209 | ASSERT_TRUE(StartTestServer()); |
| 210 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/iframes")) << message_; |
| 211 | } |
| 212 | |
[email protected] | 2aac7ff | 2012-01-25 18:05:11 | [diff] [blame] | 213 | // Tests that localStorage and WebSQL are disabled for platform apps. |
[email protected] | edd7ed69 | 2012-02-08 02:50:03 | [diff] [blame] | 214 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowStorage) { |
[email protected] | 2aac7ff | 2012-01-25 18:05:11 | [diff] [blame] | 215 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/storage")) << message_; |
| 216 | } |
[email protected] | 6a5a2e5 | 2012-03-22 03:21:12 | [diff] [blame] | 217 | |
[email protected] | c0cecd1f | 2012-04-05 16:50:12 | [diff] [blame] | 218 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Restrictions) { |
| 219 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/restrictions")) << message_; |
| 220 | } |
| 221 | |
[email protected] | f0233ff | 2012-07-20 20:14:50 | [diff] [blame] | 222 | // Tests that platform apps can use the chrome.app.window.* API. |
[email protected] | dc37b00 | 2012-04-23 23:02:26 | [diff] [blame] | 223 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApi) { |
[email protected] | 6a5a2e5 | 2012-03-22 03:21:12 | [diff] [blame] | 224 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/windows_api")) << message_; |
| 225 | } |
[email protected] | 605fb810 | 2012-05-04 01:36:55 | [diff] [blame] | 226 | |
[email protected] | 1df2204 | 2012-08-30 19:48:55 | [diff] [blame] | 227 | // Tests that extensions can't use platform-app-only APIs. |
| 228 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, PlatformAppsOnly) { |
| 229 | ASSERT_TRUE(RunExtensionTestIgnoreManifestWarnings( |
| 230 | "platform_apps/apps_only")) << message_; |
| 231 | } |
| 232 | |
[email protected] | 605fb810 | 2012-05-04 01:36:55 | [diff] [blame] | 233 | // Tests that platform apps have isolated storage by default. |
| 234 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Isolation) { |
| 235 | ASSERT_TRUE(StartTestServer()); |
| 236 | |
| 237 | // Load a (non-app) page under the "localhost" origin that sets a cookie. |
| 238 | GURL set_cookie_url = test_server()->GetURL( |
| 239 | "files/extensions/platform_apps/isolation/set_cookie.html"); |
| 240 | GURL::Replacements replace_host; |
| 241 | std::string host_str("localhost"); // Must stay in scope with replace_host. |
| 242 | replace_host.SetHostStr(host_str); |
| 243 | set_cookie_url = set_cookie_url.ReplaceComponents(replace_host); |
| 244 | |
| 245 | ui_test_utils::NavigateToURLWithDisposition( |
| 246 | browser(), set_cookie_url, |
| 247 | CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 248 | |
| 249 | // Make sure the cookie is set. |
| 250 | int cookie_size; |
| 251 | std::string cookie_value; |
| 252 | automation_util::GetCookies( |
| 253 | set_cookie_url, |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 254 | chrome::GetWebContentsAt(browser(), 0), |
[email protected] | 605fb810 | 2012-05-04 01:36:55 | [diff] [blame] | 255 | &cookie_size, |
| 256 | &cookie_value); |
| 257 | ASSERT_EQ("testCookie=1", cookie_value); |
| 258 | |
| 259 | // Let the platform app request the same URL, and make sure that it doesn't |
| 260 | // see the cookie. |
| 261 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/isolation")) << message_; |
| 262 | } |
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 263 | |
| 264 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ExtensionWindowingApis) { |
| 265 | // Initially there should be just the one browser window visible to the |
| 266 | // extensions API. |
| 267 | const Extension* extension = LoadExtension( |
| 268 | test_data_dir_.AppendASCII("common/background_page")); |
| 269 | ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(extension)); |
| 270 | |
| 271 | // And no shell windows. |
| 272 | ASSERT_EQ(0U, GetShellWindowCount()); |
| 273 | |
| 274 | // Launch a platform app that shows a window. |
| 275 | ExtensionTestMessageListener launched_listener("Launched", false); |
[email protected] | ad5bb8a9 | 2012-06-07 03:55:58 | [diff] [blame] | 276 | LoadAndLaunchPlatformApp("minimal"); |
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 277 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 278 | ASSERT_EQ(1U, GetShellWindowCount()); |
| 279 | ShellWindowRegistry::ShellWindowSet shell_windows = |
| 280 | ShellWindowRegistry::Get(browser()->profile())->shell_windows(); |
| 281 | int shell_window_id = (*shell_windows.begin())->session_id().id(); |
| 282 | |
| 283 | // But it's not visible to the extensions API, it still thinks there's just |
| 284 | // one browser window. |
| 285 | ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(extension)); |
| 286 | // It can't look it up by ID either |
| 287 | ASSERT_FALSE(RunGetWindowFunctionForExtension(shell_window_id, extension)); |
| 288 | |
| 289 | // The app can also only see one window (its own). |
[email protected] | ad5bb8a9 | 2012-06-07 03:55:58 | [diff] [blame] | 290 | // TODO(jeremya): add an extension function to get a shell window by ID, and |
| 291 | // to get a list of all the shell windows, so we can test this. |
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 292 | |
| 293 | // Launch another platform app that also shows a window. |
| 294 | ExtensionTestMessageListener launched_listener2("Launched", false); |
[email protected] | ad5bb8a9 | 2012-06-07 03:55:58 | [diff] [blame] | 295 | LoadAndLaunchPlatformApp("context_menu"); |
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 296 | ASSERT_TRUE(launched_listener2.WaitUntilSatisfied()); |
| 297 | |
| 298 | // There are two total shell windows, but each app can only see its own. |
| 299 | ASSERT_EQ(2U, GetShellWindowCount()); |
[email protected] | ad5bb8a9 | 2012-06-07 03:55:58 | [diff] [blame] | 300 | // TODO(jeremya): as above, this requires more extension functions. |
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 301 | } |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 302 | |
| 303 | // TODO(benwells): fix these tests for ChromeOS. |
| 304 | #if !defined(OS_CHROMEOS) |
| 305 | // Tests that command line parameters get passed through to platform apps |
| 306 | // via launchData correctly when launching with a file. |
| 307 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithFile) { |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 308 | SetCommandLineArg(kTestFilePath); |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 309 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_file")) |
| 310 | << message_; |
| 311 | } |
| 312 | |
[email protected] | a5a0be0 | 2012-07-18 05:51:54 | [diff] [blame] | 313 | // Tests that relative paths can be passed through to the platform app. |
| 314 | // This test doesn't use the normal test infrastructure as it needs to open |
| 315 | // the application differently to all other platform app tests, by setting |
| 316 | // the application_launch::LaunchParams.current_directory field. |
| 317 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithRelativeFile) { |
| 318 | // Setup the command line |
| 319 | ClearCommandLineArgs(); |
| 320 | CommandLine* command_line = CommandLine::ForCurrentProcess(); |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 321 | FilePath relative_test_doc = FilePath::FromUTF8Unsafe(kTestFilePath); |
[email protected] | a5a0be0 | 2012-07-18 05:51:54 | [diff] [blame] | 322 | relative_test_doc = relative_test_doc.NormalizePathSeparators(); |
| 323 | command_line->AppendArgPath(relative_test_doc); |
| 324 | |
| 325 | // Load the extension |
| 326 | ResultCatcher catcher; |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 327 | const Extension* extension = LoadExtension( |
[email protected] | a5a0be0 | 2012-07-18 05:51:54 | [diff] [blame] | 328 | test_data_dir_.AppendASCII("platform_apps/launch_file")); |
| 329 | ASSERT_TRUE(extension); |
| 330 | |
| 331 | // Run the test |
| 332 | application_launch::LaunchParams params(browser()->profile(), extension, |
| 333 | extension_misc::LAUNCH_NONE, |
| 334 | NEW_WINDOW); |
| 335 | params.command_line = CommandLine::ForCurrentProcess(); |
| 336 | params.current_directory = test_data_dir_; |
| 337 | application_launch::OpenApplication(params); |
| 338 | |
| 339 | if (!catcher.GetNextResult()) { |
| 340 | message_ = catcher.message(); |
| 341 | ASSERT_TRUE(0); |
| 342 | } |
| 343 | } |
| 344 | |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 345 | // Tests that no launch data is sent through if the platform app provides |
| 346 | // an intent with the wrong action. |
| 347 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithWrongIntent) { |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 348 | SetCommandLineArg(kTestFilePath); |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 349 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_intent")) |
| 350 | << message_; |
| 351 | } |
| 352 | |
| 353 | // Tests that no launch data is sent through if the file is of the wrong MIME |
| 354 | // type. |
| 355 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithWrongType) { |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 356 | SetCommandLineArg(kTestFilePath); |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 357 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_type")) |
| 358 | << message_; |
| 359 | } |
| 360 | |
| 361 | // Tests that no launch data is sent through if the platform app does not |
| 362 | // provide an intent. |
| 363 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithNoIntent) { |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 364 | SetCommandLineArg(kTestFilePath); |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 365 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_no_intent")) |
| 366 | << message_; |
| 367 | } |
| 368 | |
| 369 | // Tests that no launch data is sent through if the file MIME type cannot |
| 370 | // be read. |
| 371 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchNoType) { |
| 372 | SetCommandLineArg("platform_apps/launch_files/test.unknownextension"); |
| 373 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid")) |
| 374 | << message_; |
| 375 | } |
| 376 | |
| 377 | // Tests that no launch data is sent through if the file does not exist. |
| 378 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchNoFile) { |
| 379 | SetCommandLineArg("platform_apps/launch_files/doesnotexist.txt"); |
| 380 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid")) |
| 381 | << message_; |
| 382 | } |
| 383 | |
| 384 | // Tests that no launch data is sent through if the argument is a directory. |
| 385 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithDirectory) { |
| 386 | SetCommandLineArg("platform_apps/launch_files"); |
| 387 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid")) |
| 388 | << message_; |
| 389 | } |
| 390 | |
| 391 | // Tests that no launch data is sent through if there are no arguments passed |
| 392 | // on the command line |
| 393 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithNothing) { |
| 394 | ClearCommandLineArgs(); |
| 395 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_nothing")) |
| 396 | << message_; |
| 397 | } |
[email protected] | ffc7b4d | 2012-06-08 00:05:32 | [diff] [blame] | 398 | |
| 399 | // Test that platform apps can use the chrome.fileSystem.getDisplayPath |
| 400 | // function to get the native file system path of a file they are launched with. |
| 401 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, GetDisplayPath) { |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 402 | SetCommandLineArg(kTestFilePath); |
[email protected] | ffc7b4d | 2012-06-08 00:05:32 | [diff] [blame] | 403 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/get_display_path")) |
| 404 | << message_; |
| 405 | } |
| 406 | |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 407 | #endif // defined(OS_CHROMEOS) |
[email protected] | 5b1a04b4 | 2012-06-15 00:41:44 | [diff] [blame] | 408 | |
| 409 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OpenLink) { |
| 410 | ASSERT_TRUE(StartTestServer()); |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 411 | content::WindowedNotificationObserver observer( |
[email protected] | 5b1a04b4 | 2012-06-15 00:41:44 | [diff] [blame] | 412 | chrome::NOTIFICATION_TAB_ADDED, |
| 413 | content::Source<content::WebContentsDelegate>(browser())); |
| 414 | LoadAndLaunchPlatformApp("open_link"); |
| 415 | observer.Wait(); |
| 416 | ASSERT_EQ(2, browser()->tab_count()); |
| 417 | } |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 418 | |
[email protected] | 3a8e6194 | 2012-08-23 01:46:45 | [diff] [blame] | 419 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MutationEventsDisabled) { |
| 420 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/mutation_events")) << message_; |
| 421 | } |
| 422 | |
[email protected] | 939532d0 | 2012-08-31 23:37:33 | [diff] [blame^] | 423 | // Only implemented in GTK so far. |
| 424 | #if defined(TOOLKIT_GTK) |
| 425 | // Test that windows created with an id will remember and restore their |
| 426 | // geometry when opening new windows. |
| 427 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ShellWindowRestorePosition) { |
| 428 | ExtensionTestMessageListener page2_listener("WaitForPage2", true); |
| 429 | ExtensionTestMessageListener page3_listener("WaitForPage3", true); |
| 430 | ExtensionTestMessageListener done_listener("Done1", false); |
| 431 | ExtensionTestMessageListener done2_listener("Done2", false); |
| 432 | ExtensionTestMessageListener done3_listener("Done3", false); |
| 433 | |
| 434 | ASSERT_TRUE(LoadAndLaunchPlatformApp("geometry")); |
| 435 | |
| 436 | // Wait for the app to be launched (although this is mostly to have a |
| 437 | // message to reply to to let the script know it should create its second |
| 438 | // window. |
| 439 | ASSERT_TRUE(page2_listener.WaitUntilSatisfied()); |
| 440 | |
| 441 | // Wait for the first window to verify its geometry was correctly set |
| 442 | // from the default* attributes passed to the create function. |
| 443 | ASSERT_TRUE(done_listener.WaitUntilSatisfied()); |
| 444 | |
| 445 | // Programatically move and resize the window. |
| 446 | ShellWindow* window = GetFirstShellWindow(); |
| 447 | ASSERT_TRUE(window); |
| 448 | gfx::Rect bounds(137, 143, 203, 187); |
| 449 | window->GetBaseWindow()->SetBounds(bounds); |
| 450 | |
| 451 | #if defined(TOOLKIT_GTK) |
| 452 | // TODO(mek): On GTK we have to wait for a roundtrip to the X server before |
| 453 | // a resize actually happens: |
| 454 | // "if you call gtk_window_resize() then immediately call |
| 455 | // gtk_window_get_size(), the size won't have taken effect yet. After the |
| 456 | // window manager processes the resize request, GTK+ receives notification |
| 457 | // that the size has changed via a configure event, and the size of the |
| 458 | // window gets updated." |
| 459 | // Because of this we have to wait for an unknown time for the resize to |
| 460 | // actually take effect. So wait some time or until the resize got |
| 461 | // handled. |
| 462 | base::TimeTicks end_time = base::TimeTicks::Now() + |
| 463 | TestTimeouts::action_timeout(); |
| 464 | while (base::TimeTicks::Now() < end_time && |
| 465 | bounds != window->GetBaseWindow()->GetBounds()) { |
| 466 | content::RunAllPendingInMessageLoop(); |
| 467 | } |
| 468 | |
| 469 | // In the GTK ShellWindow implementation there also is a delay between |
| 470 | // getting the correct bounds and it calling SaveWindowPosition, so call that |
| 471 | // method explicitly to make sure the value was stored. |
| 472 | window->SaveWindowPosition(); |
| 473 | #endif // defined(TOOLKIT_GTK) |
| 474 | |
| 475 | // Make sure the window was properly moved&resized. |
| 476 | ASSERT_EQ(bounds, window->GetBaseWindow()->GetBounds()); |
| 477 | |
| 478 | // Tell javascript to open a second window. |
| 479 | page2_listener.Reply("continue"); |
| 480 | |
| 481 | // Wait for javascript to verify that the second window got the updated |
| 482 | // coordinates, ignoring the default coordinates passed to the create method. |
| 483 | ASSERT_TRUE(done2_listener.WaitUntilSatisfied()); |
| 484 | |
| 485 | // Tell javascript to open a third window. |
| 486 | page3_listener.Reply("continue"); |
| 487 | |
| 488 | // Wait for javascript to verify that the third window got the restored size |
| 489 | // and explicitly specified coordinates. |
| 490 | ASSERT_TRUE(done3_listener.WaitUntilSatisfied()); |
| 491 | } |
| 492 | #endif // defined(TOOLKIT_GTK) |
| 493 | |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 494 | } // namespace extensions |