blob: b6dbf6935aab88676c1847614ff98581b8209286 [file] [log] [blame]
[email protected]a44657202012-01-09 05:48:311// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]cfc6cca2011-12-01 02:30:062// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]939532d02012-08-31 23:37:335#include "base/test/test_timeouts.h"
6#include "base/threading/platform_thread.h"
[email protected]b3c019b2012-08-28 02:43:487#include "base/utf_string_conversions.h"
[email protected]ad687a72012-06-08 06:03:118#include "chrome/app/chrome_command_ids.h"
[email protected]605fb8102012-05-04 01:36:559#include "chrome/browser/automation/automation_util.h"
[email protected]375003a2011-12-13 02:53:2110#include "chrome/browser/tab_contents/render_view_context_menu.h"
[email protected]259771102012-05-31 16:52:2011#include "chrome/browser/extensions/extension_test_message_listener.h"
12#include "chrome/browser/extensions/platform_app_browsertest_util.h"
13#include "chrome/browser/extensions/shell_window_registry.h"
[email protected]cfc6cca2011-12-01 02:30:0614#include "chrome/browser/ui/browser.h"
[email protected]52877dbc62012-06-29 22:22:0315#include "chrome/browser/ui/browser_tabstrip.h"
[email protected]a5a0be02012-07-18 05:51:5416#include "chrome/browser/ui/extensions/application_launch.h"
[email protected]d72d3a62012-05-10 03:45:0817#include "chrome/browser/ui/extensions/shell_window.h"
[email protected]5b1a04b42012-06-15 00:41:4418#include "chrome/common/chrome_notification_types.h"
[email protected]cfc6cca2011-12-01 02:30:0619#include "chrome/test/base/ui_test_utils.h"
[email protected]fb29e6cf2012-07-12 21:27:2020#include "content/public/browser/render_process_host.h"
[email protected]cfc6cca2011-12-01 02:30:0621
[email protected]bb81f382012-01-03 22:45:4422using content::WebContents;
[email protected]d9ede582012-08-14 19:21:3823
24namespace extensions {
[email protected]31bdbfef2012-05-22 19:59:1525
[email protected]375003a2011-12-13 02:53:2126namespace {
[email protected]85d3d5e2012-08-31 21:19:1727
[email protected]375003a2011-12-13 02:53:2128// Non-abstract RenderViewContextMenu class.
29class PlatformAppContextMenu : public RenderViewContextMenu {
30 public:
[email protected]bb81f382012-01-03 22:45:4431 PlatformAppContextMenu(WebContents* web_contents,
[email protected]35be7ec2012-02-12 20:42:5132 const content::ContextMenuParams& params)
[email protected]bb81f382012-01-03 22:45:4433 : RenderViewContextMenu(web_contents, params) {}
[email protected]375003a2011-12-13 02:53:2134
[email protected]ad687a72012-06-08 06:03:1135 bool HasCommandWithId(int command_id) {
36 return menu_model_.GetIndexOfCommandId(command_id) != -1;
37 }
38
[email protected]375003a2011-12-13 02:53:2139 protected:
[email protected]85d3d5e2012-08-31 21:19:1740 // RenderViewContextMenu implementation.
41 virtual bool GetAcceleratorForCommandId(
42 int command_id,
43 ui::Accelerator* accelerator) OVERRIDE {
[email protected]375003a2011-12-13 02:53:2144 return false;
45 }
[email protected]85d3d5e2012-08-31 21:19:1746 virtual void PlatformInit() OVERRIDE {}
47 virtual void PlatformCancel() OVERRIDE {}
[email protected]375003a2011-12-13 02:53:2148};
49
[email protected]85d3d5e2012-08-31 21:19:1750const char kTestFilePath[] = "platform_apps/launch_files/test.txt";
51
[email protected]375003a2011-12-13 02:53:2152} // namespace
53
[email protected]eb4bcac2012-06-27 01:32:0854// Tests that CreateShellWindow doesn't crash if you close it straight away.
55// LauncherPlatformAppBrowserTest relies on this behaviour, but is only run for
56// ash, so we test that it works here.
57IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, CreateAndCloseShellWindow) {
58 const Extension* extension = LoadAndLaunchPlatformApp("minimal");
59 ShellWindow* window = CreateShellWindow(extension);
60 CloseShellWindow(window);
61}
62
[email protected]dc37b002012-04-23 23:02:2663// Tests that platform apps received the "launch" event when launched.
64IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OnLaunchedEvent) {
65 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_;
[email protected]cfc6cca2011-12-01 02:30:0666}
[email protected]375003a2011-12-13 02:53:2167
[email protected]567230b2012-08-21 21:11:4468// Tests that platform apps cannot use certain disabled window properties, but
69// can override them and then use them.
70IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisabledWindowProperties) {
71 ASSERT_TRUE(RunPlatformAppTest("platform_apps/disabled_window_properties"))
72 << message_;
73}
74
[email protected]edd7ed692012-02-08 02:50:0375IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) {
[email protected]dc37b002012-04-23 23:02:2676 ExtensionTestMessageListener launched_listener("Launched", false);
[email protected]31bdbfef2012-05-22 19:59:1577 LoadAndLaunchPlatformApp("minimal");
[email protected]dc37b002012-04-23 23:02:2678
79 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
[email protected]375003a2011-12-13 02:53:2180
[email protected]375003a2011-12-13 02:53:2181 // The empty app doesn't add any context menu items, so its menu should
[email protected]0cfacd82012-02-09 01:55:3382 // only include the developer tools.
[email protected]d72d3a62012-05-10 03:45:0883 WebContents* web_contents = GetFirstShellWindowWebContents();
[email protected]a44657202012-01-09 05:48:3184 ASSERT_TRUE(web_contents);
[email protected]375003a2011-12-13 02:53:2185 WebKit::WebContextMenuData data;
[email protected]35be7ec2012-02-12 20:42:5186 content::ContextMenuParams params(data);
[email protected]85d3d5e2012-08-31 21:19:1787 scoped_ptr<PlatformAppContextMenu> menu;
88 menu.reset(new PlatformAppContextMenu(web_contents, params));
[email protected]375003a2011-12-13 02:53:2189 menu->Init();
[email protected]ad687a72012-06-08 06:03:1190 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
91 ASSERT_TRUE(menu->HasCommandWithId(IDC_RELOAD));
92 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK));
93 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE));
[email protected]375003a2011-12-13 02:53:2194}
95
[email protected]edd7ed692012-02-08 02:50:0396IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) {
[email protected]dc37b002012-04-23 23:02:2697 ExtensionTestMessageListener launched_listener("Launched", false);
[email protected]375003a2011-12-13 02:53:2198 LoadAndLaunchPlatformApp("context_menu");
99
[email protected]dc37b002012-04-23 23:02:26100 // Wait for the extension to tell us it's initialized its context menus and
101 // launched a window.
102 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
[email protected]375003a2011-12-13 02:53:21103
[email protected]271d01c2012-08-27 23:48:05104 // The context_menu app has two context menu items. These, along with a
[email protected]0cfacd82012-02-09 01:55:33105 // separator and the developer tools, is all that should be in the menu.
[email protected]d72d3a62012-05-10 03:45:08106 WebContents* web_contents = GetFirstShellWindowWebContents();
[email protected]a44657202012-01-09 05:48:31107 ASSERT_TRUE(web_contents);
[email protected]375003a2011-12-13 02:53:21108 WebKit::WebContextMenuData data;
[email protected]35be7ec2012-02-12 20:42:51109 content::ContextMenuParams params(data);
[email protected]85d3d5e2012-08-31 21:19:17110 scoped_ptr<PlatformAppContextMenu> menu;
111 menu.reset(new PlatformAppContextMenu(web_contents, params));
[email protected]375003a2011-12-13 02:53:21112 menu->Init();
[email protected]ad687a72012-06-08 06:03:11113 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST));
[email protected]271d01c2012-08-27 23:48:05114 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1));
[email protected]ad687a72012-06-08 06:03:11115 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
116 ASSERT_TRUE(menu->HasCommandWithId(IDC_RELOAD));
117 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK));
118 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE));
[email protected]b3c019b2012-08-28 02:43:48119 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO));
120}
121
122IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuTextField) {
123 ExtensionTestMessageListener launched_listener("Launched", false);
124 LoadAndLaunchPlatformApp("context_menu");
125
126 // Wait for the extension to tell us it's initialized its context menus and
127 // launched a window.
128 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
129
130 // The context_menu app has one context menu item. This, along with a
131 // separator and the developer tools, is all that should be in the menu.
132 WebContents* web_contents = GetFirstShellWindowWebContents();
133 ASSERT_TRUE(web_contents);
134 WebKit::WebContextMenuData data;
135 content::ContextMenuParams params(data);
136 params.is_editable = true;
[email protected]85d3d5e2012-08-31 21:19:17137 scoped_ptr<PlatformAppContextMenu> menu;
138 menu.reset(new PlatformAppContextMenu(web_contents, params));
[email protected]b3c019b2012-08-28 02:43:48139 menu->Init();
140 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST));
141 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
142 ASSERT_TRUE(menu->HasCommandWithId(IDC_RELOAD));
143 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO));
144 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY));
145 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK));
146 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE));
147}
148
149IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuSelection) {
150 ExtensionTestMessageListener launched_listener("Launched", false);
151 LoadAndLaunchPlatformApp("context_menu");
152
153 // Wait for the extension to tell us it's initialized its context menus and
154 // launched a window.
155 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
156
157 // The context_menu app has one context menu item. This, along with a
158 // separator and the developer tools, is all that should be in the menu.
159 WebContents* web_contents = GetFirstShellWindowWebContents();
160 ASSERT_TRUE(web_contents);
161 WebKit::WebContextMenuData data;
162 content::ContextMenuParams params(data);
163 params.selection_text = ASCIIToUTF16("Hello World");
[email protected]85d3d5e2012-08-31 21:19:17164 scoped_ptr<PlatformAppContextMenu> menu;
165 menu.reset(new PlatformAppContextMenu(web_contents, params));
[email protected]b3c019b2012-08-28 02:43:48166 menu->Init();
167 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST));
168 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
169 ASSERT_TRUE(menu->HasCommandWithId(IDC_RELOAD));
170 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO));
171 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY));
172 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK));
173 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE));
[email protected]375003a2011-12-13 02:53:21174}
[email protected]5f000f272012-01-19 05:25:08175
[email protected]dc83c582012-08-17 02:18:14176IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuClicked) {
177 ExtensionTestMessageListener launched_listener("Launched", false);
178 LoadAndLaunchPlatformApp("context_menu_click");
179
180 // Wait for the extension to tell us it's initialized its context menus and
181 // launched a window.
182 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
183
184 // Test that the menu item shows up
185 WebContents* web_contents = GetFirstShellWindowWebContents();
186 ASSERT_TRUE(web_contents);
187 WebKit::WebContextMenuData data;
188 content::ContextMenuParams params(data);
189 params.page_url = GURL("http://foo.bar");
[email protected]85d3d5e2012-08-31 21:19:17190 scoped_ptr<PlatformAppContextMenu> menu;
191 menu.reset(new PlatformAppContextMenu(web_contents, params));
[email protected]dc83c582012-08-17 02:18:14192 menu->Init();
193 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST));
194
195 // Execute the menu item
196 ExtensionTestMessageListener onclicked_listener("onClicked fired for id1",
197 false);
198 menu->ExecuteCommand(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST);
199
200 ASSERT_TRUE(onclicked_listener.WaitUntilSatisfied());
201}
202
[email protected]edd7ed692012-02-08 02:50:03203IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowNavigation) {
[email protected]dc37b002012-04-23 23:02:26204 ASSERT_TRUE(StartTestServer());
205 ASSERT_TRUE(RunPlatformAppTest("platform_apps/navigation")) << message_;
[email protected]5f000f272012-01-19 05:25:08206}
[email protected]863e6472012-01-24 19:33:58207
[email protected]fd3238af2012-05-22 18:55:30208IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Iframes) {
209 ASSERT_TRUE(StartTestServer());
210 ASSERT_TRUE(RunPlatformAppTest("platform_apps/iframes")) << message_;
211}
212
[email protected]2aac7ff2012-01-25 18:05:11213// Tests that localStorage and WebSQL are disabled for platform apps.
[email protected]edd7ed692012-02-08 02:50:03214IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowStorage) {
[email protected]2aac7ff2012-01-25 18:05:11215 ASSERT_TRUE(RunPlatformAppTest("platform_apps/storage")) << message_;
216}
[email protected]6a5a2e52012-03-22 03:21:12217
[email protected]c0cecd1f2012-04-05 16:50:12218IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Restrictions) {
219 ASSERT_TRUE(RunPlatformAppTest("platform_apps/restrictions")) << message_;
220}
221
[email protected]f0233ff2012-07-20 20:14:50222// Tests that platform apps can use the chrome.app.window.* API.
[email protected]dc37b002012-04-23 23:02:26223IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApi) {
[email protected]6a5a2e52012-03-22 03:21:12224 ASSERT_TRUE(RunPlatformAppTest("platform_apps/windows_api")) << message_;
225}
[email protected]605fb8102012-05-04 01:36:55226
[email protected]1df22042012-08-30 19:48:55227// Tests that extensions can't use platform-app-only APIs.
228IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, PlatformAppsOnly) {
229 ASSERT_TRUE(RunExtensionTestIgnoreManifestWarnings(
230 "platform_apps/apps_only")) << message_;
231}
232
[email protected]605fb8102012-05-04 01:36:55233// Tests that platform apps have isolated storage by default.
234IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Isolation) {
235 ASSERT_TRUE(StartTestServer());
236
237 // Load a (non-app) page under the "localhost" origin that sets a cookie.
238 GURL set_cookie_url = test_server()->GetURL(
239 "files/extensions/platform_apps/isolation/set_cookie.html");
240 GURL::Replacements replace_host;
241 std::string host_str("localhost"); // Must stay in scope with replace_host.
242 replace_host.SetHostStr(host_str);
243 set_cookie_url = set_cookie_url.ReplaceComponents(replace_host);
244
245 ui_test_utils::NavigateToURLWithDisposition(
246 browser(), set_cookie_url,
247 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
248
249 // Make sure the cookie is set.
250 int cookie_size;
251 std::string cookie_value;
252 automation_util::GetCookies(
253 set_cookie_url,
[email protected]52877dbc62012-06-29 22:22:03254 chrome::GetWebContentsAt(browser(), 0),
[email protected]605fb8102012-05-04 01:36:55255 &cookie_size,
256 &cookie_value);
257 ASSERT_EQ("testCookie=1", cookie_value);
258
259 // Let the platform app request the same URL, and make sure that it doesn't
260 // see the cookie.
261 ASSERT_TRUE(RunPlatformAppTest("platform_apps/isolation")) << message_;
262}
[email protected]31bdbfef2012-05-22 19:59:15263
264IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ExtensionWindowingApis) {
265 // Initially there should be just the one browser window visible to the
266 // extensions API.
267 const Extension* extension = LoadExtension(
268 test_data_dir_.AppendASCII("common/background_page"));
269 ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(extension));
270
271 // And no shell windows.
272 ASSERT_EQ(0U, GetShellWindowCount());
273
274 // Launch a platform app that shows a window.
275 ExtensionTestMessageListener launched_listener("Launched", false);
[email protected]ad5bb8a92012-06-07 03:55:58276 LoadAndLaunchPlatformApp("minimal");
[email protected]31bdbfef2012-05-22 19:59:15277 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
278 ASSERT_EQ(1U, GetShellWindowCount());
279 ShellWindowRegistry::ShellWindowSet shell_windows =
280 ShellWindowRegistry::Get(browser()->profile())->shell_windows();
281 int shell_window_id = (*shell_windows.begin())->session_id().id();
282
283 // But it's not visible to the extensions API, it still thinks there's just
284 // one browser window.
285 ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(extension));
286 // It can't look it up by ID either
287 ASSERT_FALSE(RunGetWindowFunctionForExtension(shell_window_id, extension));
288
289 // The app can also only see one window (its own).
[email protected]ad5bb8a92012-06-07 03:55:58290 // TODO(jeremya): add an extension function to get a shell window by ID, and
291 // to get a list of all the shell windows, so we can test this.
[email protected]31bdbfef2012-05-22 19:59:15292
293 // Launch another platform app that also shows a window.
294 ExtensionTestMessageListener launched_listener2("Launched", false);
[email protected]ad5bb8a92012-06-07 03:55:58295 LoadAndLaunchPlatformApp("context_menu");
[email protected]31bdbfef2012-05-22 19:59:15296 ASSERT_TRUE(launched_listener2.WaitUntilSatisfied());
297
298 // There are two total shell windows, but each app can only see its own.
299 ASSERT_EQ(2U, GetShellWindowCount());
[email protected]ad5bb8a92012-06-07 03:55:58300 // TODO(jeremya): as above, this requires more extension functions.
[email protected]31bdbfef2012-05-22 19:59:15301}
[email protected]12e540452012-05-26 07:09:36302
303// TODO(benwells): fix these tests for ChromeOS.
304#if !defined(OS_CHROMEOS)
305// Tests that command line parameters get passed through to platform apps
306// via launchData correctly when launching with a file.
307IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithFile) {
[email protected]85d3d5e2012-08-31 21:19:17308 SetCommandLineArg(kTestFilePath);
[email protected]12e540452012-05-26 07:09:36309 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_file"))
310 << message_;
311}
312
[email protected]a5a0be02012-07-18 05:51:54313// Tests that relative paths can be passed through to the platform app.
314// This test doesn't use the normal test infrastructure as it needs to open
315// the application differently to all other platform app tests, by setting
316// the application_launch::LaunchParams.current_directory field.
317IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithRelativeFile) {
318 // Setup the command line
319 ClearCommandLineArgs();
320 CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]85d3d5e2012-08-31 21:19:17321 FilePath relative_test_doc = FilePath::FromUTF8Unsafe(kTestFilePath);
[email protected]a5a0be02012-07-18 05:51:54322 relative_test_doc = relative_test_doc.NormalizePathSeparators();
323 command_line->AppendArgPath(relative_test_doc);
324
325 // Load the extension
326 ResultCatcher catcher;
[email protected]d9ede582012-08-14 19:21:38327 const Extension* extension = LoadExtension(
[email protected]a5a0be02012-07-18 05:51:54328 test_data_dir_.AppendASCII("platform_apps/launch_file"));
329 ASSERT_TRUE(extension);
330
331 // Run the test
332 application_launch::LaunchParams params(browser()->profile(), extension,
333 extension_misc::LAUNCH_NONE,
334 NEW_WINDOW);
335 params.command_line = CommandLine::ForCurrentProcess();
336 params.current_directory = test_data_dir_;
337 application_launch::OpenApplication(params);
338
339 if (!catcher.GetNextResult()) {
340 message_ = catcher.message();
341 ASSERT_TRUE(0);
342 }
343}
344
[email protected]12e540452012-05-26 07:09:36345// Tests that no launch data is sent through if the platform app provides
346// an intent with the wrong action.
347IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithWrongIntent) {
[email protected]85d3d5e2012-08-31 21:19:17348 SetCommandLineArg(kTestFilePath);
[email protected]12e540452012-05-26 07:09:36349 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_intent"))
350 << message_;
351}
352
353// Tests that no launch data is sent through if the file is of the wrong MIME
354// type.
355IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithWrongType) {
[email protected]85d3d5e2012-08-31 21:19:17356 SetCommandLineArg(kTestFilePath);
[email protected]12e540452012-05-26 07:09:36357 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_type"))
358 << message_;
359}
360
361// Tests that no launch data is sent through if the platform app does not
362// provide an intent.
363IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithNoIntent) {
[email protected]85d3d5e2012-08-31 21:19:17364 SetCommandLineArg(kTestFilePath);
[email protected]12e540452012-05-26 07:09:36365 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_no_intent"))
366 << message_;
367}
368
369// Tests that no launch data is sent through if the file MIME type cannot
370// be read.
371IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchNoType) {
372 SetCommandLineArg("platform_apps/launch_files/test.unknownextension");
373 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid"))
374 << message_;
375}
376
377// Tests that no launch data is sent through if the file does not exist.
378IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchNoFile) {
379 SetCommandLineArg("platform_apps/launch_files/doesnotexist.txt");
380 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid"))
381 << message_;
382}
383
384// Tests that no launch data is sent through if the argument is a directory.
385IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithDirectory) {
386 SetCommandLineArg("platform_apps/launch_files");
387 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid"))
388 << message_;
389}
390
391// Tests that no launch data is sent through if there are no arguments passed
392// on the command line
393IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithNothing) {
394 ClearCommandLineArgs();
395 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_nothing"))
396 << message_;
397}
[email protected]ffc7b4d2012-06-08 00:05:32398
399// Test that platform apps can use the chrome.fileSystem.getDisplayPath
400// function to get the native file system path of a file they are launched with.
401IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, GetDisplayPath) {
[email protected]85d3d5e2012-08-31 21:19:17402 SetCommandLineArg(kTestFilePath);
[email protected]ffc7b4d2012-06-08 00:05:32403 ASSERT_TRUE(RunPlatformAppTest("platform_apps/get_display_path"))
404 << message_;
405}
406
[email protected]12e540452012-05-26 07:09:36407#endif // defined(OS_CHROMEOS)
[email protected]5b1a04b42012-06-15 00:41:44408
409IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OpenLink) {
410 ASSERT_TRUE(StartTestServer());
[email protected]a7fe9112012-07-20 02:34:45411 content::WindowedNotificationObserver observer(
[email protected]5b1a04b42012-06-15 00:41:44412 chrome::NOTIFICATION_TAB_ADDED,
413 content::Source<content::WebContentsDelegate>(browser()));
414 LoadAndLaunchPlatformApp("open_link");
415 observer.Wait();
416 ASSERT_EQ(2, browser()->tab_count());
417}
[email protected]d9ede582012-08-14 19:21:38418
[email protected]3a8e61942012-08-23 01:46:45419IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MutationEventsDisabled) {
420 ASSERT_TRUE(RunPlatformAppTest("platform_apps/mutation_events")) << message_;
421}
422
[email protected]939532d02012-08-31 23:37:33423// Only implemented in GTK so far.
424#if defined(TOOLKIT_GTK)
425// Test that windows created with an id will remember and restore their
426// geometry when opening new windows.
427IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ShellWindowRestorePosition) {
428 ExtensionTestMessageListener page2_listener("WaitForPage2", true);
429 ExtensionTestMessageListener page3_listener("WaitForPage3", true);
430 ExtensionTestMessageListener done_listener("Done1", false);
431 ExtensionTestMessageListener done2_listener("Done2", false);
432 ExtensionTestMessageListener done3_listener("Done3", false);
433
434 ASSERT_TRUE(LoadAndLaunchPlatformApp("geometry"));
435
436 // Wait for the app to be launched (although this is mostly to have a
437 // message to reply to to let the script know it should create its second
438 // window.
439 ASSERT_TRUE(page2_listener.WaitUntilSatisfied());
440
441 // Wait for the first window to verify its geometry was correctly set
442 // from the default* attributes passed to the create function.
443 ASSERT_TRUE(done_listener.WaitUntilSatisfied());
444
445 // Programatically move and resize the window.
446 ShellWindow* window = GetFirstShellWindow();
447 ASSERT_TRUE(window);
448 gfx::Rect bounds(137, 143, 203, 187);
449 window->GetBaseWindow()->SetBounds(bounds);
450
451#if defined(TOOLKIT_GTK)
452 // TODO(mek): On GTK we have to wait for a roundtrip to the X server before
453 // a resize actually happens:
454 // "if you call gtk_window_resize() then immediately call
455 // gtk_window_get_size(), the size won't have taken effect yet. After the
456 // window manager processes the resize request, GTK+ receives notification
457 // that the size has changed via a configure event, and the size of the
458 // window gets updated."
459 // Because of this we have to wait for an unknown time for the resize to
460 // actually take effect. So wait some time or until the resize got
461 // handled.
462 base::TimeTicks end_time = base::TimeTicks::Now() +
463 TestTimeouts::action_timeout();
464 while (base::TimeTicks::Now() < end_time &&
465 bounds != window->GetBaseWindow()->GetBounds()) {
466 content::RunAllPendingInMessageLoop();
467 }
468
469 // In the GTK ShellWindow implementation there also is a delay between
470 // getting the correct bounds and it calling SaveWindowPosition, so call that
471 // method explicitly to make sure the value was stored.
472 window->SaveWindowPosition();
473#endif // defined(TOOLKIT_GTK)
474
475 // Make sure the window was properly moved&resized.
476 ASSERT_EQ(bounds, window->GetBaseWindow()->GetBounds());
477
478 // Tell javascript to open a second window.
479 page2_listener.Reply("continue");
480
481 // Wait for javascript to verify that the second window got the updated
482 // coordinates, ignoring the default coordinates passed to the create method.
483 ASSERT_TRUE(done2_listener.WaitUntilSatisfied());
484
485 // Tell javascript to open a third window.
486 page3_listener.Reply("continue");
487
488 // Wait for javascript to verify that the third window got the restored size
489 // and explicitly specified coordinates.
490 ASSERT_TRUE(done3_listener.WaitUntilSatisfied());
491}
492#endif // defined(TOOLKIT_GTK)
493
[email protected]d9ede582012-08-14 19:21:38494} // namespace extensions