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