Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3430)

Unified Diff: chrome/browser/extensions/platform_app_browsertest.cc

Issue 10332071: Pass command line arguments onto platform apps which provide the right intent. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Browser cleanup Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/platform_app_browsertest.cc
diff --git a/chrome/browser/extensions/platform_app_browsertest.cc b/chrome/browser/extensions/platform_app_browsertest.cc
index 325aff97c879f42bb89089b507c81c421b73fb4d..0e0dd6f07152de02110ed1434145235c4d1bfd19 100644
--- a/chrome/browser/extensions/platform_app_browsertest.cc
+++ b/chrome/browser/extensions/platform_app_browsertest.cc
@@ -77,7 +77,8 @@ class PlatformAppBrowserTest : public ExtensionApiTest {
extension,
extension_misc::LAUNCH_NONE,
GURL(),
- NEW_WINDOW);
+ NEW_WINDOW,
+ NULL);
app_loaded_observer.Wait();
@@ -128,6 +129,29 @@ class PlatformAppBrowserTest : public ExtensionApiTest {
return ShellWindowRegistry::Get(browser()->profile())->
shell_windows().size();
}
+
+ // The command line already has an argument on it - about:blank, which
+ // is set by InProcessBrowserTest::PrepareTestCommandLine. For platform app
+ // launch tests we need to clear this.
+ void ClearCommandLineArgs() {
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ CommandLine::StringVector args = command_line->GetArgs();
+ CommandLine::StringVector argv = command_line->argv();
+ for (size_t i = 0; i < args.size(); i++)
+ argv.pop_back();
+ command_line->InitFromArgv(argv);
+ }
+
+ void SetCommandLineArg(const std::string& test_file) {
+ ClearCommandLineArgs();
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ FilePath test_doc(test_data_dir_.AppendASCII(test_file));
+#if defined(OS_WIN)
+ command_line->AppendArg(UTF16ToASCII(test_doc.value()));
+#else
+ command_line->AppendArg(test_doc.value());
+#endif
+ }
};
// Tests that platform apps received the "launch" event when launched.
@@ -272,3 +296,67 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ExtensionWindowingApis) {
ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(platform_app));
ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(platform_app2));
}
+
+#if !defined(OS_CHROMEOS)
+// Tests that command line parameters get passed through to platform apps
+// via launchData correctly when launching with a file.
+IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithFile) {
+ SetCommandLineArg( "platform_apps/launch_files/test.txt");
+ ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_file"))
+ << message_;
+}
+
+// Tests that no launch data is sent through if the platform app provides
+// an intent with the wrong action.
+IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithWrongIntent) {
+ SetCommandLineArg("platform_apps/launch_files/test.txt");
+ ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_intent"))
+ << message_;
+}
+
+// Tests that no launch data is sent through if the file is of the wrong MIME
+// type.
+IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithWrongType) {
+ SetCommandLineArg("platform_apps/launch_files/test.txt");
+ ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_type"))
+ << message_;
+}
+
+// Tests that no launch data is sent through if the platform app does not
+// provide an intent.
+IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithNoIntent) {
+ SetCommandLineArg("platform_apps/launch_files/test.txt");
+ ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_no_intent"))
+ << message_;
+}
+
+// Tests that no launch data is sent through if the file MIME type cannot
+// be read.
+IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchNoType) {
+ SetCommandLineArg("platform_apps/launch_files/test.unknownextension");
+ ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid"))
+ << message_;
+}
+
+// Tests that no launch data is sent through if the file does not exist.
+IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchNoFile) {
+ SetCommandLineArg("platform_apps/launch_files/doesnotexist.txt");
+ ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid"))
+ << message_;
+}
+
+// Tests that no launch data is sent through if the argument is a directory.
+IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithDirectory) {
+ SetCommandLineArg("platform_apps/launch_files");
+ ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid"))
+ << message_;
+}
+
+// Tests that no launch data is sent through if there are no arguments passed
+// on the command line
+IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithNothing) {
+ ClearCommandLineArgs();
+ ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_nothing"))
+ << message_;
+}
+#endif // defined(OS_CHROMEOS)

Powered by Google App Engine
This is Rietveld 408576698