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

Side by Side 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: Compile fixed, postResult added 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/automation/automation_util.h" 8 #include "chrome/browser/automation/automation_util.h"
9 #include "chrome/browser/extensions/extension_apitest.h" 9 #include "chrome/browser/extensions/extension_apitest.h"
10 #include "chrome/browser/extensions/extension_browsertest.h" 10 #include "chrome/browser/extensions/extension_browsertest.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 ExtensionService* service = browser()->profile()->GetExtensionService(); 67 ExtensionService* service = browser()->profile()->GetExtensionService();
68 const Extension* extension = service->GetExtensionById( 68 const Extension* extension = service->GetExtensionById(
69 last_loaded_extension_id_, false); 69 last_loaded_extension_id_, false);
70 EXPECT_TRUE(extension); 70 EXPECT_TRUE(extension);
71 71
72 Browser::OpenApplication( 72 Browser::OpenApplication(
73 browser()->profile(), 73 browser()->profile(),
74 extension, 74 extension,
75 extension_misc::LAUNCH_NONE, 75 extension_misc::LAUNCH_NONE,
76 GURL(), 76 GURL(),
77 NEW_WINDOW); 77 NEW_WINDOW,
78 NULL);
78 79
79 app_loaded_observer.Wait(); 80 app_loaded_observer.Wait();
80 } 81 }
81 82
82 // Gets the WebContents associated with the first shell window that is found 83 // Gets the WebContents associated with the first shell window that is found
83 // (most tests only deal with one platform app window, so this is good 84 // (most tests only deal with one platform app window, so this is good
84 // enough). 85 // enough).
85 WebContents* GetFirstShellWindowWebContents() { 86 WebContents* GetFirstShellWindowWebContents() {
86 ShellWindowRegistry* app_registry = 87 ShellWindowRegistry* app_registry =
87 ShellWindowRegistry::Get(browser()->profile()); 88 ShellWindowRegistry::Get(browser()->profile());
88 ShellWindowRegistry::const_iterator iter; 89 ShellWindowRegistry::const_iterator iter;
89 ShellWindowRegistry::ShellWindowSet shell_windows = 90 ShellWindowRegistry::ShellWindowSet shell_windows =
90 app_registry->shell_windows(); 91 app_registry->shell_windows();
91 for (iter = shell_windows.begin(); iter != shell_windows.end(); ++iter) { 92 for (iter = shell_windows.begin(); iter != shell_windows.end(); ++iter) {
92 return (*iter)->web_contents(); 93 return (*iter)->web_contents();
93 } 94 }
94 95
95 return NULL; 96 return NULL;
96 } 97 }
98
99 // The command line already has an argument on it - about:blank, which
100 // is set by InProcessBrowserTest::PrepareTestCommandLine. For platform app
101 // launch tests we need to clear this.
102 void ClearCommandLineArgs() {
103 CommandLine* command_line = CommandLine::ForCurrentProcess();
104 CommandLine::StringVector args = command_line->GetArgs();
105 CommandLine::StringVector argv = command_line->argv();
106 for (size_t i=0; i<args.size(); i++)
Mihai Parparita -not on Chrome 2012/05/18 04:26:04 Nit: add space before/after = and <
benwells 2012/05/22 13:15:03 Done.
107 argv.pop_back();
108 command_line->InitFromArgv(argv);
109 }
110
111 void SetCommandLineArg(const std::string& test_file) {
112 ClearCommandLineArgs();
113 CommandLine* command_line = CommandLine::ForCurrentProcess();
114 FilePath test_doc(test_data_dir_.AppendASCII(test_file));
115 command_line->AppendArg(test_doc.value());
116 }
97 }; 117 };
98 118
99 // Tests that platform apps received the "launch" event when launched. 119 // Tests that platform apps received the "launch" event when launched.
100 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OnLaunchedEvent) { 120 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OnLaunchedEvent) {
101 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_; 121 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_;
102 } 122 }
103 123
104 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) { 124 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) {
105 ExtensionTestMessageListener launched_listener("Launched", false); 125 ExtensionTestMessageListener launched_listener("Launched", false);
106 LoadAndLaunchPlatformApp("empty_context_menu"); 126 LoadAndLaunchPlatformApp("empty_context_menu");
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 set_cookie_url, 206 set_cookie_url,
187 browser()->GetWebContentsAt(0), 207 browser()->GetWebContentsAt(0),
188 &cookie_size, 208 &cookie_size,
189 &cookie_value); 209 &cookie_value);
190 ASSERT_EQ("testCookie=1", cookie_value); 210 ASSERT_EQ("testCookie=1", cookie_value);
191 211
192 // Let the platform app request the same URL, and make sure that it doesn't 212 // Let the platform app request the same URL, and make sure that it doesn't
193 // see the cookie. 213 // see the cookie.
194 ASSERT_TRUE(RunPlatformAppTest("platform_apps/isolation")) << message_; 214 ASSERT_TRUE(RunPlatformAppTest("platform_apps/isolation")) << message_;
195 } 215 }
216
217 // Tests that command line parameters get passed through to platform apps
218 // via launchData correctly when launching with a file.
219 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithFile) {
220 SetCommandLineArg( "platform_apps/launch_files/test.txt");
221 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_file"))
222 << message_;
223 }
224
225 // Tests that no launch data is sent through if the platform app provides
226 // an intent with the wrong action.
227 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithWrongIntent) {
228 SetCommandLineArg("platform_apps/launch_files/test.txt");
229 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_intent"))
230 << message_;
231 }
232
233 // Tests that no launch data is sent through if the file is of the wrong MIME
234 // type.
235 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithWrongType) {
236 SetCommandLineArg("platform_apps/launch_files/test.txt");
237 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_type"))
238 << message_;
239 }
240
241 // Tests that no launch data is sent through if the platform app does not
242 // provide an intent.
243 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithNoIntent) {
244 SetCommandLineArg("platform_apps/launch_files/test.txt");
245 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_no_intent"))
246 << message_;
247 }
248
249 // Tests that no launch data is sent through if the file MIME type cannot
250 // be read.
251 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchNoType) {
252 SetCommandLineArg("platform_apps/launch_files/test.unknownextension");
253 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid"))
254 << message_;
255 }
256
257 // Tests that no launch data is sent through if the file does not exist.
258 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchNoFile) {
259 SetCommandLineArg("platform_apps/launch_files/doesnotexist.txt");
260 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid"))
261 << message_;
262 }
263
264 // Tests that no launch data is sent through if the argument is a directory.
265 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithDirectory) {
266 SetCommandLineArg("platform_apps/launch_files");
267 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid"))
268 << message_;
269 }
270
271 // Tests that no launch data is sent through if there are no arguments passed
272 // on the command line
273 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithNothing) {
274 ClearCommandLineArgs();
275 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_nothing"))
276 << message_;
277 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698