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