| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/stringprintf.h" | 6 #include "base/stringprintf.h" |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/string_util.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/automation/automation_util.h" | 9 #include "chrome/browser/automation/automation_util.h" |
| 10 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
| 11 #include "chrome/browser/extensions/extension_browsertest.h" | 11 #include "chrome/browser/extensions/extension_browsertest.h" |
| 12 #include "chrome/browser/extensions/extension_function_test_utils.h" | 12 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/extensions/extension_tabs_module.h" | 14 #include "chrome/browser/extensions/extension_tabs_module.h" |
| 15 #include "chrome/browser/extensions/extension_test_message_listener.h" | 15 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 16 #include "chrome/browser/extensions/shell_window_registry.h" | 16 #include "chrome/browser/extensions/shell_window_registry.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 70 |
| 71 const Extension* extension = LoadExtension( | 71 const Extension* extension = LoadExtension( |
| 72 test_data_dir_.AppendASCII("platform_apps").AppendASCII(name)); | 72 test_data_dir_.AppendASCII("platform_apps").AppendASCII(name)); |
| 73 EXPECT_TRUE(extension); | 73 EXPECT_TRUE(extension); |
| 74 | 74 |
| 75 application_launch::OpenApplication( | 75 application_launch::OpenApplication( |
| 76 browser()->profile(), | 76 browser()->profile(), |
| 77 extension, | 77 extension, |
| 78 extension_misc::LAUNCH_NONE, | 78 extension_misc::LAUNCH_NONE, |
| 79 GURL(), | 79 GURL(), |
| 80 NEW_WINDOW); | 80 NEW_WINDOW, |
| 81 NULL); |
| 81 | 82 |
| 82 app_loaded_observer.Wait(); | 83 app_loaded_observer.Wait(); |
| 83 | 84 |
| 84 return extension; | 85 return extension; |
| 85 } | 86 } |
| 86 | 87 |
| 87 // Gets the WebContents associated with the first shell window that is found | 88 // Gets the WebContents associated with the first shell window that is found |
| 88 // (most tests only deal with one platform app window, so this is good | 89 // (most tests only deal with one platform app window, so this is good |
| 89 // enough). | 90 // enough). |
| 90 WebContents* GetFirstShellWindowWebContents() { | 91 WebContents* GetFirstShellWindowWebContents() { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 121 base::StringPrintf("[%u]", window_id), | 122 base::StringPrintf("[%u]", window_id), |
| 122 browser(), | 123 browser(), |
| 123 utils::NONE); | 124 utils::NONE); |
| 124 return function->GetResultValue() != NULL; | 125 return function->GetResultValue() != NULL; |
| 125 } | 126 } |
| 126 | 127 |
| 127 size_t GetShellWindowCount() { | 128 size_t GetShellWindowCount() { |
| 128 return ShellWindowRegistry::Get(browser()->profile())-> | 129 return ShellWindowRegistry::Get(browser()->profile())-> |
| 129 shell_windows().size(); | 130 shell_windows().size(); |
| 130 } | 131 } |
| 132 |
| 133 // The command line already has an argument on it - about:blank, which |
| 134 // is set by InProcessBrowserTest::PrepareTestCommandLine. For platform app |
| 135 // launch tests we need to clear this. |
| 136 void ClearCommandLineArgs() { |
| 137 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 138 CommandLine::StringVector args = command_line->GetArgs(); |
| 139 CommandLine::StringVector argv = command_line->argv(); |
| 140 for (size_t i = 0; i < args.size(); i++) |
| 141 argv.pop_back(); |
| 142 command_line->InitFromArgv(argv); |
| 143 } |
| 144 |
| 145 void SetCommandLineArg(const std::string& test_file) { |
| 146 ClearCommandLineArgs(); |
| 147 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 148 FilePath test_doc(test_data_dir_.AppendASCII(test_file)); |
| 149 test_doc = test_doc.NormalizePathSeparators(); |
| 150 command_line->AppendArgPath(test_doc); |
| 151 } |
| 131 }; | 152 }; |
| 132 | 153 |
| 133 // Tests that platform apps received the "launch" event when launched. | 154 // Tests that platform apps received the "launch" event when launched. |
| 134 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OnLaunchedEvent) { | 155 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OnLaunchedEvent) { |
| 135 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_; | 156 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_; |
| 136 } | 157 } |
| 137 | 158 |
| 138 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) { | 159 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) { |
| 139 ExtensionTestMessageListener launched_listener("Launched", false); | 160 ExtensionTestMessageListener launched_listener("Launched", false); |
| 140 LoadAndLaunchPlatformApp("minimal"); | 161 LoadAndLaunchPlatformApp("minimal"); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 // Launch another platform app that also shows a window. | 286 // Launch another platform app that also shows a window. |
| 266 ExtensionTestMessageListener launched_listener2("Launched", false); | 287 ExtensionTestMessageListener launched_listener2("Launched", false); |
| 267 const Extension* platform_app2 = LoadAndLaunchPlatformApp("context_menu"); | 288 const Extension* platform_app2 = LoadAndLaunchPlatformApp("context_menu"); |
| 268 ASSERT_TRUE(launched_listener2.WaitUntilSatisfied()); | 289 ASSERT_TRUE(launched_listener2.WaitUntilSatisfied()); |
| 269 | 290 |
| 270 // There are two total shell windows, but each app can only see its own. | 291 // There are two total shell windows, but each app can only see its own. |
| 271 ASSERT_EQ(2U, GetShellWindowCount()); | 292 ASSERT_EQ(2U, GetShellWindowCount()); |
| 272 ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(platform_app)); | 293 ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(platform_app)); |
| 273 ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(platform_app2)); | 294 ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(platform_app2)); |
| 274 } | 295 } |
| 296 |
| 297 // TODO(benwells): fix these tests for ChromeOS. |
| 298 #if !defined(OS_CHROMEOS) |
| 299 // Tests that command line parameters get passed through to platform apps |
| 300 // via launchData correctly when launching with a file. |
| 301 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithFile) { |
| 302 SetCommandLineArg( "platform_apps/launch_files/test.txt"); |
| 303 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_file")) |
| 304 << message_; |
| 305 } |
| 306 |
| 307 // Tests that no launch data is sent through if the platform app provides |
| 308 // an intent with the wrong action. |
| 309 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithWrongIntent) { |
| 310 SetCommandLineArg("platform_apps/launch_files/test.txt"); |
| 311 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_intent")) |
| 312 << message_; |
| 313 } |
| 314 |
| 315 // Tests that no launch data is sent through if the file is of the wrong MIME |
| 316 // type. |
| 317 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithWrongType) { |
| 318 SetCommandLineArg("platform_apps/launch_files/test.txt"); |
| 319 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_type")) |
| 320 << message_; |
| 321 } |
| 322 |
| 323 // Tests that no launch data is sent through if the platform app does not |
| 324 // provide an intent. |
| 325 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithNoIntent) { |
| 326 SetCommandLineArg("platform_apps/launch_files/test.txt"); |
| 327 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_no_intent")) |
| 328 << message_; |
| 329 } |
| 330 |
| 331 // Tests that no launch data is sent through if the file MIME type cannot |
| 332 // be read. |
| 333 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchNoType) { |
| 334 SetCommandLineArg("platform_apps/launch_files/test.unknownextension"); |
| 335 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid")) |
| 336 << message_; |
| 337 } |
| 338 |
| 339 // Tests that no launch data is sent through if the file does not exist. |
| 340 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchNoFile) { |
| 341 SetCommandLineArg("platform_apps/launch_files/doesnotexist.txt"); |
| 342 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid")) |
| 343 << message_; |
| 344 } |
| 345 |
| 346 // Tests that no launch data is sent through if the argument is a directory. |
| 347 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithDirectory) { |
| 348 SetCommandLineArg("platform_apps/launch_files"); |
| 349 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid")) |
| 350 << message_; |
| 351 } |
| 352 |
| 353 // Tests that no launch data is sent through if there are no arguments passed |
| 354 // on the command line |
| 355 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithNothing) { |
| 356 ClearCommandLineArgs(); |
| 357 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_nothing")) |
| 358 << message_; |
| 359 } |
| 360 #endif // defined(OS_CHROMEOS) |
| OLD | NEW |