[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] | b3c019b | 2012-08-28 02:43:48 | [diff] [blame^] | 5 | #include "base/utf_string_conversions.h" |
[email protected] | ad687a7 | 2012-06-08 06:03:11 | [diff] [blame] | 6 | #include "chrome/app/chrome_command_ids.h" |
[email protected] | 605fb810 | 2012-05-04 01:36:55 | [diff] [blame] | 7 | #include "chrome/browser/automation/automation_util.h" |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 8 | #include "chrome/browser/tab_contents/render_view_context_menu.h" |
[email protected] | 25977110 | 2012-05-31 16:52:20 | [diff] [blame] | 9 | #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 10 | #include "chrome/browser/extensions/platform_app_browsertest_util.h" |
| 11 | #include "chrome/browser/extensions/shell_window_registry.h" |
[email protected] | cfc6cca | 2011-12-01 02:30:06 | [diff] [blame] | 12 | #include "chrome/browser/ui/browser.h" |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 13 | #include "chrome/browser/ui/browser_tabstrip.h" |
[email protected] | a5a0be0 | 2012-07-18 05:51:54 | [diff] [blame] | 14 | #include "chrome/browser/ui/extensions/application_launch.h" |
[email protected] | d72d3a6 | 2012-05-10 03:45:08 | [diff] [blame] | 15 | #include "chrome/browser/ui/extensions/shell_window.h" |
[email protected] | 5b1a04b4 | 2012-06-15 00:41:44 | [diff] [blame] | 16 | #include "chrome/common/chrome_notification_types.h" |
[email protected] | cfc6cca | 2011-12-01 02:30:06 | [diff] [blame] | 17 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | fb29e6cf | 2012-07-12 21:27:20 | [diff] [blame] | 18 | #include "content/public/browser/render_process_host.h" |
[email protected] | cfc6cca | 2011-12-01 02:30:06 | [diff] [blame] | 19 | |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 20 | using content::WebContents; |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 21 | |
| 22 | namespace extensions { |
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 23 | |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 24 | namespace { |
| 25 | // Non-abstract RenderViewContextMenu class. |
| 26 | class PlatformAppContextMenu : public RenderViewContextMenu { |
| 27 | public: |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 28 | PlatformAppContextMenu(WebContents* web_contents, |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 29 | const content::ContextMenuParams& params) |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 30 | : RenderViewContextMenu(web_contents, params) {} |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 31 | |
[email protected] | ad687a7 | 2012-06-08 06:03:11 | [diff] [blame] | 32 | bool HasCommandWithId(int command_id) { |
| 33 | return menu_model_.GetIndexOfCommandId(command_id) != -1; |
| 34 | } |
| 35 | |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 36 | protected: |
| 37 | // These two functions implement pure virtual methods of |
| 38 | // RenderViewContextMenu. |
| 39 | virtual bool GetAcceleratorForCommandId(int command_id, |
| 40 | ui::Accelerator* accelerator) { |
| 41 | return false; |
| 42 | } |
| 43 | virtual void PlatformInit() {} |
[email protected] | f5d5cd0 | 2012-05-04 13:59:30 | [diff] [blame] | 44 | virtual void PlatformCancel() {} |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | } // namespace |
| 48 | |
[email protected] | eb4bcac | 2012-06-27 01:32:08 | [diff] [blame] | 49 | // Tests that CreateShellWindow doesn't crash if you close it straight away. |
| 50 | // LauncherPlatformAppBrowserTest relies on this behaviour, but is only run for |
| 51 | // ash, so we test that it works here. |
| 52 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, CreateAndCloseShellWindow) { |
| 53 | const Extension* extension = LoadAndLaunchPlatformApp("minimal"); |
| 54 | ShellWindow* window = CreateShellWindow(extension); |
| 55 | CloseShellWindow(window); |
| 56 | } |
| 57 | |
[email protected] | dc37b00 | 2012-04-23 23:02:26 | [diff] [blame] | 58 | // Tests that platform apps received the "launch" event when launched. |
| 59 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OnLaunchedEvent) { |
| 60 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_; |
[email protected] | cfc6cca | 2011-12-01 02:30:06 | [diff] [blame] | 61 | } |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 62 | |
[email protected] | 567230b | 2012-08-21 21:11:44 | [diff] [blame] | 63 | // Tests that platform apps cannot use certain disabled window properties, but |
| 64 | // can override them and then use them. |
| 65 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisabledWindowProperties) { |
| 66 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/disabled_window_properties")) |
| 67 | << message_; |
| 68 | } |
| 69 | |
[email protected] | edd7ed69 | 2012-02-08 02:50:03 | [diff] [blame] | 70 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) { |
[email protected] | dc37b00 | 2012-04-23 23:02:26 | [diff] [blame] | 71 | ExtensionTestMessageListener launched_listener("Launched", false); |
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 72 | LoadAndLaunchPlatformApp("minimal"); |
[email protected] | dc37b00 | 2012-04-23 23:02:26 | [diff] [blame] | 73 | |
| 74 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 75 | |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 76 | // 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] | 77 | // only include the developer tools. |
[email protected] | d72d3a6 | 2012-05-10 03:45:08 | [diff] [blame] | 78 | WebContents* web_contents = GetFirstShellWindowWebContents(); |
[email protected] | a4465720 | 2012-01-09 05:48:31 | [diff] [blame] | 79 | ASSERT_TRUE(web_contents); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 80 | WebKit::WebContextMenuData data; |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 81 | content::ContextMenuParams params(data); |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 82 | PlatformAppContextMenu* menu = new PlatformAppContextMenu(web_contents, |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 83 | params); |
| 84 | menu->Init(); |
[email protected] | ad687a7 | 2012-06-08 06:03:11 | [diff] [blame] | 85 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
| 86 | ASSERT_TRUE(menu->HasCommandWithId(IDC_RELOAD)); |
| 87 | ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 88 | ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 89 | } |
| 90 | |
[email protected] | edd7ed69 | 2012-02-08 02:50:03 | [diff] [blame] | 91 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) { |
[email protected] | dc37b00 | 2012-04-23 23:02:26 | [diff] [blame] | 92 | ExtensionTestMessageListener launched_listener("Launched", false); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 93 | LoadAndLaunchPlatformApp("context_menu"); |
| 94 | |
[email protected] | dc37b00 | 2012-04-23 23:02:26 | [diff] [blame] | 95 | // Wait for the extension to tell us it's initialized its context menus and |
| 96 | // launched a window. |
| 97 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 98 | |
[email protected] | 271d01c | 2012-08-27 23:48:05 | [diff] [blame] | 99 | // The context_menu app has two context menu items. These, along with a |
[email protected] | 0cfacd8 | 2012-02-09 01:55:33 | [diff] [blame] | 100 | // separator and the developer tools, is all that should be in the menu. |
[email protected] | d72d3a6 | 2012-05-10 03:45:08 | [diff] [blame] | 101 | WebContents* web_contents = GetFirstShellWindowWebContents(); |
[email protected] | a4465720 | 2012-01-09 05:48:31 | [diff] [blame] | 102 | ASSERT_TRUE(web_contents); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 103 | WebKit::WebContextMenuData data; |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 104 | content::ContextMenuParams params(data); |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 105 | PlatformAppContextMenu* menu = new PlatformAppContextMenu(web_contents, |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 106 | params); |
| 107 | menu->Init(); |
[email protected] | ad687a7 | 2012-06-08 06:03:11 | [diff] [blame] | 108 | ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
[email protected] | 271d01c | 2012-08-27 23:48:05 | [diff] [blame] | 109 | ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1)); |
[email protected] | ad687a7 | 2012-06-08 06:03:11 | [diff] [blame] | 110 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
| 111 | ASSERT_TRUE(menu->HasCommandWithId(IDC_RELOAD)); |
| 112 | ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 113 | ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
[email protected] | b3c019b | 2012-08-28 02:43:48 | [diff] [blame^] | 114 | ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
| 115 | } |
| 116 | |
| 117 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuTextField) { |
| 118 | ExtensionTestMessageListener launched_listener("Launched", false); |
| 119 | LoadAndLaunchPlatformApp("context_menu"); |
| 120 | |
| 121 | // Wait for the extension to tell us it's initialized its context menus and |
| 122 | // launched a window. |
| 123 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 124 | |
| 125 | // The context_menu app has one context menu item. This, along with a |
| 126 | // separator and the developer tools, is all that should be in the menu. |
| 127 | WebContents* web_contents = GetFirstShellWindowWebContents(); |
| 128 | ASSERT_TRUE(web_contents); |
| 129 | WebKit::WebContextMenuData data; |
| 130 | content::ContextMenuParams params(data); |
| 131 | params.is_editable = true; |
| 132 | PlatformAppContextMenu* menu = new PlatformAppContextMenu(web_contents, |
| 133 | params); |
| 134 | menu->Init(); |
| 135 | ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
| 136 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
| 137 | ASSERT_TRUE(menu->HasCommandWithId(IDC_RELOAD)); |
| 138 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
| 139 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); |
| 140 | ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 141 | ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
| 142 | } |
| 143 | |
| 144 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuSelection) { |
| 145 | ExtensionTestMessageListener launched_listener("Launched", false); |
| 146 | LoadAndLaunchPlatformApp("context_menu"); |
| 147 | |
| 148 | // Wait for the extension to tell us it's initialized its context menus and |
| 149 | // launched a window. |
| 150 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 151 | |
| 152 | // The context_menu app has one context menu item. This, along with a |
| 153 | // separator and the developer tools, is all that should be in the menu. |
| 154 | WebContents* web_contents = GetFirstShellWindowWebContents(); |
| 155 | ASSERT_TRUE(web_contents); |
| 156 | WebKit::WebContextMenuData data; |
| 157 | content::ContextMenuParams params(data); |
| 158 | params.selection_text = ASCIIToUTF16("Hello World"); |
| 159 | PlatformAppContextMenu* menu = new PlatformAppContextMenu(web_contents, |
| 160 | params); |
| 161 | menu->Init(); |
| 162 | ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
| 163 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
| 164 | ASSERT_TRUE(menu->HasCommandWithId(IDC_RELOAD)); |
| 165 | ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
| 166 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); |
| 167 | ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 168 | ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 169 | } |
[email protected] | 5f000f27 | 2012-01-19 05:25:08 | [diff] [blame] | 170 | |
[email protected] | dc83c58 | 2012-08-17 02:18:14 | [diff] [blame] | 171 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuClicked) { |
| 172 | ExtensionTestMessageListener launched_listener("Launched", false); |
| 173 | LoadAndLaunchPlatformApp("context_menu_click"); |
| 174 | |
| 175 | // Wait for the extension to tell us it's initialized its context menus and |
| 176 | // launched a window. |
| 177 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 178 | |
| 179 | // Test that the menu item shows up |
| 180 | WebContents* web_contents = GetFirstShellWindowWebContents(); |
| 181 | ASSERT_TRUE(web_contents); |
| 182 | WebKit::WebContextMenuData data; |
| 183 | content::ContextMenuParams params(data); |
| 184 | params.page_url = GURL("http://foo.bar"); |
| 185 | PlatformAppContextMenu* menu = new PlatformAppContextMenu(web_contents, |
| 186 | params); |
| 187 | menu->Init(); |
| 188 | ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
| 189 | |
| 190 | // Execute the menu item |
| 191 | ExtensionTestMessageListener onclicked_listener("onClicked fired for id1", |
| 192 | false); |
| 193 | menu->ExecuteCommand(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST); |
| 194 | |
| 195 | ASSERT_TRUE(onclicked_listener.WaitUntilSatisfied()); |
| 196 | } |
| 197 | |
[email protected] | edd7ed69 | 2012-02-08 02:50:03 | [diff] [blame] | 198 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowNavigation) { |
[email protected] | dc37b00 | 2012-04-23 23:02:26 | [diff] [blame] | 199 | ASSERT_TRUE(StartTestServer()); |
| 200 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/navigation")) << message_; |
[email protected] | 5f000f27 | 2012-01-19 05:25:08 | [diff] [blame] | 201 | } |
[email protected] | 863e647 | 2012-01-24 19:33:58 | [diff] [blame] | 202 | |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 203 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Iframes) { |
| 204 | ASSERT_TRUE(StartTestServer()); |
| 205 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/iframes")) << message_; |
| 206 | } |
| 207 | |
[email protected] | 2aac7ff | 2012-01-25 18:05:11 | [diff] [blame] | 208 | // Tests that localStorage and WebSQL are disabled for platform apps. |
[email protected] | edd7ed69 | 2012-02-08 02:50:03 | [diff] [blame] | 209 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowStorage) { |
[email protected] | 2aac7ff | 2012-01-25 18:05:11 | [diff] [blame] | 210 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/storage")) << message_; |
| 211 | } |
[email protected] | 6a5a2e5 | 2012-03-22 03:21:12 | [diff] [blame] | 212 | |
[email protected] | c0cecd1f | 2012-04-05 16:50:12 | [diff] [blame] | 213 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Restrictions) { |
| 214 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/restrictions")) << message_; |
| 215 | } |
| 216 | |
[email protected] | f0233ff | 2012-07-20 20:14:50 | [diff] [blame] | 217 | // Tests that platform apps can use the chrome.app.window.* API. |
[email protected] | dc37b00 | 2012-04-23 23:02:26 | [diff] [blame] | 218 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApi) { |
[email protected] | 6a5a2e5 | 2012-03-22 03:21:12 | [diff] [blame] | 219 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/windows_api")) << message_; |
| 220 | } |
[email protected] | 605fb810 | 2012-05-04 01:36:55 | [diff] [blame] | 221 | |
| 222 | // Tests that platform apps have isolated storage by default. |
| 223 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Isolation) { |
| 224 | ASSERT_TRUE(StartTestServer()); |
| 225 | |
| 226 | // Load a (non-app) page under the "localhost" origin that sets a cookie. |
| 227 | GURL set_cookie_url = test_server()->GetURL( |
| 228 | "files/extensions/platform_apps/isolation/set_cookie.html"); |
| 229 | GURL::Replacements replace_host; |
| 230 | std::string host_str("localhost"); // Must stay in scope with replace_host. |
| 231 | replace_host.SetHostStr(host_str); |
| 232 | set_cookie_url = set_cookie_url.ReplaceComponents(replace_host); |
| 233 | |
| 234 | ui_test_utils::NavigateToURLWithDisposition( |
| 235 | browser(), set_cookie_url, |
| 236 | CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 237 | |
| 238 | // Make sure the cookie is set. |
| 239 | int cookie_size; |
| 240 | std::string cookie_value; |
| 241 | automation_util::GetCookies( |
| 242 | set_cookie_url, |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 243 | chrome::GetWebContentsAt(browser(), 0), |
[email protected] | 605fb810 | 2012-05-04 01:36:55 | [diff] [blame] | 244 | &cookie_size, |
| 245 | &cookie_value); |
| 246 | ASSERT_EQ("testCookie=1", cookie_value); |
| 247 | |
| 248 | // Let the platform app request the same URL, and make sure that it doesn't |
| 249 | // see the cookie. |
| 250 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/isolation")) << message_; |
| 251 | } |
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 252 | |
| 253 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ExtensionWindowingApis) { |
| 254 | // Initially there should be just the one browser window visible to the |
| 255 | // extensions API. |
| 256 | const Extension* extension = LoadExtension( |
| 257 | test_data_dir_.AppendASCII("common/background_page")); |
| 258 | ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(extension)); |
| 259 | |
| 260 | // And no shell windows. |
| 261 | ASSERT_EQ(0U, GetShellWindowCount()); |
| 262 | |
| 263 | // Launch a platform app that shows a window. |
| 264 | ExtensionTestMessageListener launched_listener("Launched", false); |
[email protected] | ad5bb8a9 | 2012-06-07 03:55:58 | [diff] [blame] | 265 | LoadAndLaunchPlatformApp("minimal"); |
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 266 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 267 | ASSERT_EQ(1U, GetShellWindowCount()); |
| 268 | ShellWindowRegistry::ShellWindowSet shell_windows = |
| 269 | ShellWindowRegistry::Get(browser()->profile())->shell_windows(); |
| 270 | int shell_window_id = (*shell_windows.begin())->session_id().id(); |
| 271 | |
| 272 | // But it's not visible to the extensions API, it still thinks there's just |
| 273 | // one browser window. |
| 274 | ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(extension)); |
| 275 | // It can't look it up by ID either |
| 276 | ASSERT_FALSE(RunGetWindowFunctionForExtension(shell_window_id, extension)); |
| 277 | |
| 278 | // The app can also only see one window (its own). |
[email protected] | ad5bb8a9 | 2012-06-07 03:55:58 | [diff] [blame] | 279 | // TODO(jeremya): add an extension function to get a shell window by ID, and |
| 280 | // 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] | 281 | |
| 282 | // Launch another platform app that also shows a window. |
| 283 | ExtensionTestMessageListener launched_listener2("Launched", false); |
[email protected] | ad5bb8a9 | 2012-06-07 03:55:58 | [diff] [blame] | 284 | LoadAndLaunchPlatformApp("context_menu"); |
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 285 | ASSERT_TRUE(launched_listener2.WaitUntilSatisfied()); |
| 286 | |
| 287 | // There are two total shell windows, but each app can only see its own. |
| 288 | ASSERT_EQ(2U, GetShellWindowCount()); |
[email protected] | ad5bb8a9 | 2012-06-07 03:55:58 | [diff] [blame] | 289 | // TODO(jeremya): as above, this requires more extension functions. |
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 290 | } |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 291 | |
| 292 | // TODO(benwells): fix these tests for ChromeOS. |
| 293 | #if !defined(OS_CHROMEOS) |
| 294 | // Tests that command line parameters get passed through to platform apps |
| 295 | // via launchData correctly when launching with a file. |
| 296 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithFile) { |
| 297 | SetCommandLineArg( "platform_apps/launch_files/test.txt"); |
| 298 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_file")) |
| 299 | << message_; |
| 300 | } |
| 301 | |
[email protected] | a5a0be0 | 2012-07-18 05:51:54 | [diff] [blame] | 302 | // Tests that relative paths can be passed through to the platform app. |
| 303 | // This test doesn't use the normal test infrastructure as it needs to open |
| 304 | // the application differently to all other platform app tests, by setting |
| 305 | // the application_launch::LaunchParams.current_directory field. |
| 306 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithRelativeFile) { |
| 307 | // Setup the command line |
| 308 | ClearCommandLineArgs(); |
| 309 | CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 310 | FilePath relative_test_doc = FilePath::FromUTF8Unsafe( |
| 311 | "platform_apps/launch_files/test.txt"); |
| 312 | relative_test_doc = relative_test_doc.NormalizePathSeparators(); |
| 313 | command_line->AppendArgPath(relative_test_doc); |
| 314 | |
| 315 | // Load the extension |
| 316 | ResultCatcher catcher; |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 317 | const Extension* extension = LoadExtension( |
[email protected] | a5a0be0 | 2012-07-18 05:51:54 | [diff] [blame] | 318 | test_data_dir_.AppendASCII("platform_apps/launch_file")); |
| 319 | ASSERT_TRUE(extension); |
| 320 | |
| 321 | // Run the test |
| 322 | application_launch::LaunchParams params(browser()->profile(), extension, |
| 323 | extension_misc::LAUNCH_NONE, |
| 324 | NEW_WINDOW); |
| 325 | params.command_line = CommandLine::ForCurrentProcess(); |
| 326 | params.current_directory = test_data_dir_; |
| 327 | application_launch::OpenApplication(params); |
| 328 | |
| 329 | if (!catcher.GetNextResult()) { |
| 330 | message_ = catcher.message(); |
| 331 | ASSERT_TRUE(0); |
| 332 | } |
| 333 | } |
| 334 | |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 335 | // Tests that no launch data is sent through if the platform app provides |
| 336 | // an intent with the wrong action. |
| 337 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithWrongIntent) { |
| 338 | SetCommandLineArg("platform_apps/launch_files/test.txt"); |
| 339 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_intent")) |
| 340 | << message_; |
| 341 | } |
| 342 | |
| 343 | // Tests that no launch data is sent through if the file is of the wrong MIME |
| 344 | // type. |
| 345 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithWrongType) { |
| 346 | SetCommandLineArg("platform_apps/launch_files/test.txt"); |
| 347 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_type")) |
| 348 | << message_; |
| 349 | } |
| 350 | |
| 351 | // Tests that no launch data is sent through if the platform app does not |
| 352 | // provide an intent. |
| 353 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithNoIntent) { |
| 354 | SetCommandLineArg("platform_apps/launch_files/test.txt"); |
| 355 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_no_intent")) |
| 356 | << message_; |
| 357 | } |
| 358 | |
| 359 | // Tests that no launch data is sent through if the file MIME type cannot |
| 360 | // be read. |
| 361 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchNoType) { |
| 362 | SetCommandLineArg("platform_apps/launch_files/test.unknownextension"); |
| 363 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid")) |
| 364 | << message_; |
| 365 | } |
| 366 | |
| 367 | // Tests that no launch data is sent through if the file does not exist. |
| 368 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchNoFile) { |
| 369 | SetCommandLineArg("platform_apps/launch_files/doesnotexist.txt"); |
| 370 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid")) |
| 371 | << message_; |
| 372 | } |
| 373 | |
| 374 | // Tests that no launch data is sent through if the argument is a directory. |
| 375 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithDirectory) { |
| 376 | SetCommandLineArg("platform_apps/launch_files"); |
| 377 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid")) |
| 378 | << message_; |
| 379 | } |
| 380 | |
| 381 | // Tests that no launch data is sent through if there are no arguments passed |
| 382 | // on the command line |
| 383 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithNothing) { |
| 384 | ClearCommandLineArgs(); |
| 385 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_nothing")) |
| 386 | << message_; |
| 387 | } |
[email protected] | ffc7b4d | 2012-06-08 00:05:32 | [diff] [blame] | 388 | |
| 389 | // Test that platform apps can use the chrome.fileSystem.getDisplayPath |
| 390 | // function to get the native file system path of a file they are launched with. |
| 391 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, GetDisplayPath) { |
| 392 | SetCommandLineArg("platform_apps/launch_files/test.txt"); |
| 393 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/get_display_path")) |
| 394 | << message_; |
| 395 | } |
| 396 | |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 397 | #endif // defined(OS_CHROMEOS) |
[email protected] | 5b1a04b4 | 2012-06-15 00:41:44 | [diff] [blame] | 398 | |
| 399 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OpenLink) { |
| 400 | ASSERT_TRUE(StartTestServer()); |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 401 | content::WindowedNotificationObserver observer( |
[email protected] | 5b1a04b4 | 2012-06-15 00:41:44 | [diff] [blame] | 402 | chrome::NOTIFICATION_TAB_ADDED, |
| 403 | content::Source<content::WebContentsDelegate>(browser())); |
| 404 | LoadAndLaunchPlatformApp("open_link"); |
| 405 | observer.Wait(); |
| 406 | ASSERT_EQ(2, browser()->tab_count()); |
| 407 | } |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 408 | |
[email protected] | 3a8e6194 | 2012-08-23 01:46:45 | [diff] [blame] | 409 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MutationEventsDisabled) { |
| 410 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/mutation_events")) << message_; |
| 411 | } |
| 412 | |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 413 | } // namespace extensions |