| 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/utf_string_conversions.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" |
| (...skipping 59 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 #if defined(OS_WIN) |
| 150 command_line->AppendArg(UTF16ToASCII(test_doc.value())); |
| 151 #else |
| 152 command_line->AppendArg(test_doc.value()); |
| 153 #endif |
| 154 } |
| 131 }; | 155 }; |
| 132 | 156 |
| 133 // Tests that platform apps received the "launch" event when launched. | 157 // Tests that platform apps received the "launch" event when launched. |
| 134 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OnLaunchedEvent) { | 158 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OnLaunchedEvent) { |
| 135 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_; | 159 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_; |
| 136 } | 160 } |
| 137 | 161 |
| 138 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) { | 162 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) { |
| 139 ExtensionTestMessageListener launched_listener("Launched", false); | 163 ExtensionTestMessageListener launched_listener("Launched", false); |
| 140 LoadAndLaunchPlatformApp("minimal"); | 164 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. | 289 // Launch another platform app that also shows a window. |
| 266 ExtensionTestMessageListener launched_listener2("Launched", false); | 290 ExtensionTestMessageListener launched_listener2("Launched", false); |
| 267 const Extension* platform_app2 = LoadAndLaunchPlatformApp("context_menu"); | 291 const Extension* platform_app2 = LoadAndLaunchPlatformApp("context_menu"); |
| 268 ASSERT_TRUE(launched_listener2.WaitUntilSatisfied()); | 292 ASSERT_TRUE(launched_listener2.WaitUntilSatisfied()); |
| 269 | 293 |
| 270 // There are two total shell windows, but each app can only see its own. | 294 // There are two total shell windows, but each app can only see its own. |
| 271 ASSERT_EQ(2U, GetShellWindowCount()); | 295 ASSERT_EQ(2U, GetShellWindowCount()); |
| 272 ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(platform_app)); | 296 ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(platform_app)); |
| 273 ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(platform_app2)); | 297 ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(platform_app2)); |
| 274 } | 298 } |
| 299 |
| 300 #if !defined(OS_CHROMEOS) |
| 301 // Tests that command line parameters get passed through to platform apps |
| 302 // via launchData correctly when launching with a file. |
| 303 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithFile) { |
| 304 SetCommandLineArg( "platform_apps/launch_files/test.txt"); |
| 305 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_file")) |
| 306 << message_; |
| 307 } |
| 308 |
| 309 // Tests that no launch data is sent through if the platform app provides |
| 310 // an intent with the wrong action. |
| 311 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithWrongIntent) { |
| 312 SetCommandLineArg("platform_apps/launch_files/test.txt"); |
| 313 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_intent")) |
| 314 << message_; |
| 315 } |
| 316 |
| 317 // Tests that no launch data is sent through if the file is of the wrong MIME |
| 318 // type. |
| 319 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithWrongType) { |
| 320 SetCommandLineArg("platform_apps/launch_files/test.txt"); |
| 321 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_type")) |
| 322 << message_; |
| 323 } |
| 324 |
| 325 // Tests that no launch data is sent through if the platform app does not |
| 326 // provide an intent. |
| 327 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithNoIntent) { |
| 328 SetCommandLineArg("platform_apps/launch_files/test.txt"); |
| 329 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_no_intent")) |
| 330 << message_; |
| 331 } |
| 332 |
| 333 // Tests that no launch data is sent through if the file MIME type cannot |
| 334 // be read. |
| 335 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchNoType) { |
| 336 SetCommandLineArg("platform_apps/launch_files/test.unknownextension"); |
| 337 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid")) |
| 338 << message_; |
| 339 } |
| 340 |
| 341 // Tests that no launch data is sent through if the file does not exist. |
| 342 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchNoFile) { |
| 343 SetCommandLineArg("platform_apps/launch_files/doesnotexist.txt"); |
| 344 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid")) |
| 345 << message_; |
| 346 } |
| 347 |
| 348 // Tests that no launch data is sent through if the argument is a directory. |
| 349 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithDirectory) { |
| 350 SetCommandLineArg("platform_apps/launch_files"); |
| 351 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid")) |
| 352 << message_; |
| 353 } |
| 354 |
| 355 // Tests that no launch data is sent through if there are no arguments passed |
| 356 // on the command line |
| 357 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithNothing) { |
| 358 ClearCommandLineArgs(); |
| 359 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_nothing")) |
| 360 << message_; |
| 361 } |
| 362 #endif // defined(OS_CHROMEOS) |
| OLD | NEW |