blob: 46b176fe4c0bde5af29c5616fad1812d1eb4f244 [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]a6db6122012-09-03 06:00:235#include "base/bind.h"
[email protected]939532d02012-08-31 23:37:336#include "base/test/test_timeouts.h"
7#include "base/threading/platform_thread.h"
[email protected]b3c019b2012-08-28 02:43:488#include "base/utf_string_conversions.h"
[email protected]ad687a72012-06-08 06:03:119#include "chrome/app/chrome_command_ids.h"
[email protected]605fb8102012-05-04 01:36:5510#include "chrome/browser/automation/automation_util.h"
[email protected]e85cc642012-10-24 06:14:2311#include "chrome/browser/debugger/devtools_window.h"
[email protected]ddf42162012-11-06 21:14:5512#include "chrome/browser/extensions/api/permissions/permissions_api.h"
[email protected]28c3eeb2012-10-15 05:47:5313#include "chrome/browser/extensions/app_restore_service_factory.h"
14#include "chrome/browser/extensions/app_restore_service.h"
[email protected]a6db6122012-09-03 06:00:2315#include "chrome/browser/extensions/extension_browsertest.h"
[email protected]28c3eeb2012-10-15 05:47:5316#include "chrome/browser/extensions/extension_prefs.h"
17#include "chrome/browser/extensions/extension_service.h"
18#include "chrome/browser/extensions/extension_system.h"
[email protected]259771102012-05-31 16:52:2019#include "chrome/browser/extensions/extension_test_message_listener.h"
20#include "chrome/browser/extensions/platform_app_browsertest_util.h"
[email protected]a6db6122012-09-03 06:00:2321#include "chrome/browser/extensions/platform_app_launcher.h"
[email protected]259771102012-05-31 16:52:2022#include "chrome/browser/extensions/shell_window_registry.h"
[email protected]e85cc642012-10-24 06:14:2323#include "chrome/browser/tab_contents/render_view_context_menu.h"
[email protected]cfc6cca2011-12-01 02:30:0624#include "chrome/browser/ui/browser.h"
[email protected]52877dbc62012-06-29 22:22:0325#include "chrome/browser/ui/browser_tabstrip.h"
[email protected]ddf42162012-11-06 21:14:5526#include "chrome/browser/ui/constrained_window_tab_helper.h"
[email protected]a5a0be02012-07-18 05:51:5427#include "chrome/browser/ui/extensions/application_launch.h"
[email protected]d72d3a62012-05-10 03:45:0828#include "chrome/browser/ui/extensions/shell_window.h"
[email protected]e85cc642012-10-24 06:14:2329#include "chrome/browser/ui/tab_contents/tab_contents.h"
[email protected]5b1a04b42012-06-15 00:41:4430#include "chrome/common/chrome_notification_types.h"
[email protected]4d007b312012-10-17 03:00:4831#include "chrome/common/url_constants.h"
[email protected]cfc6cca2011-12-01 02:30:0632#include "chrome/test/base/ui_test_utils.h"
[email protected]e85cc642012-10-24 06:14:2333#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]fb29e6cf2012-07-12 21:27:2034#include "content/public/browser/render_process_host.h"
[email protected]a6db6122012-09-03 06:00:2335#include "content/public/browser/web_intents_dispatcher.h"
[email protected]28c3eeb2012-10-15 05:47:5336#include "content/public/test/test_utils.h"
[email protected]a6db6122012-09-03 06:00:2337#include "googleurl/src/gurl.h"
38#include "webkit/glue/web_intent_data.h"
[email protected]cfc6cca2011-12-01 02:30:0639
[email protected]bb81f382012-01-03 22:45:4440using content::WebContents;
[email protected]d9ede582012-08-14 19:21:3841
42namespace extensions {
[email protected]31bdbfef2012-05-22 19:59:1543
[email protected]375003a2011-12-13 02:53:2144namespace {
[email protected]85d3d5e2012-08-31 21:19:1745
[email protected]375003a2011-12-13 02:53:2146// Non-abstract RenderViewContextMenu class.
47class PlatformAppContextMenu : public RenderViewContextMenu {
48 public:
[email protected]bb81f382012-01-03 22:45:4449 PlatformAppContextMenu(WebContents* web_contents,
[email protected]35be7ec2012-02-12 20:42:5150 const content::ContextMenuParams& params)
[email protected]bb81f382012-01-03 22:45:4451 : RenderViewContextMenu(web_contents, params) {}
[email protected]375003a2011-12-13 02:53:2152
[email protected]ad687a72012-06-08 06:03:1153 bool HasCommandWithId(int command_id) {
54 return menu_model_.GetIndexOfCommandId(command_id) != -1;
55 }
56
[email protected]375003a2011-12-13 02:53:2157 protected:
[email protected]85d3d5e2012-08-31 21:19:1758 // RenderViewContextMenu implementation.
59 virtual bool GetAcceleratorForCommandId(
60 int command_id,
61 ui::Accelerator* accelerator) OVERRIDE {
[email protected]375003a2011-12-13 02:53:2162 return false;
63 }
[email protected]85d3d5e2012-08-31 21:19:1764 virtual void PlatformInit() OVERRIDE {}
65 virtual void PlatformCancel() OVERRIDE {}
[email protected]375003a2011-12-13 02:53:2166};
67
[email protected]a6db6122012-09-03 06:00:2368// State holder for the LaunchReply test. This provides an WebIntentsDispatcher
69// that will, when used to launch a Web Intent, will return its reply via this
70// class. The result may then be waited on via WaitUntilReply().
71class LaunchReplyHandler {
72 public:
73 explicit LaunchReplyHandler(webkit_glue::WebIntentData& data)
74 : data_(data),
75 replied_(false),
76 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
77 intents_dispatcher_ = content::WebIntentsDispatcher::Create(data);
78 intents_dispatcher_->RegisterReplyNotification(base::Bind(
79 &LaunchReplyHandler::OnReply, weak_ptr_factory_.GetWeakPtr()));
80 }
81
82 content::WebIntentsDispatcher* intents_dispatcher() {
83 return intents_dispatcher_;
84 }
85
86 // Waits until a reply to this Web Intent is provided via the
87 // WebIntentsDispatcher.
88 bool WaitUntilReply() {
89 if (replied_)
90 return true;
91 waiting_ = true;
92 content::RunMessageLoop();
93 waiting_ = false;
94 return replied_;
95 }
96
97 private:
98 void OnReply(webkit_glue::WebIntentReplyType reply) {
99 // Note that the ReplyNotification registered on WebIntentsDispatcher does
100 // not include the result data: this is reserved for the source page (which
101 // we don't care about).
102 replied_ = true;
103 if (waiting_)
104 MessageLoopForUI::current()->Quit();
105 }
106
107 webkit_glue::WebIntentData data_;
108 bool replied_;
109 bool waiting_;
110 content::WebIntentsDispatcher* intents_dispatcher_;
111 base::WeakPtrFactory<LaunchReplyHandler> weak_ptr_factory_;
112};
113
[email protected]4d007b312012-10-17 03:00:48114// This class keeps track of tabs as they are added to the browser. It will be
115// "done" (i.e. won't block on Wait()) once |observations| tabs have been added.
116class TabsAddedNotificationObserver
117 : public content::WindowedNotificationObserver {
118 public:
119 explicit TabsAddedNotificationObserver(size_t observations)
120 : content::WindowedNotificationObserver(
121 chrome::NOTIFICATION_TAB_ADDED,
122 content::NotificationService::AllSources()),
123 observations_(observations) {
124 }
125
126 virtual void Observe(int type,
127 const content::NotificationSource& source,
128 const content::NotificationDetails& details) OVERRIDE {
129 observed_tabs_.push_back(
130 content::Details<WebContents>(details).ptr());
131 if (observed_tabs_.size() == observations_)
132 content::WindowedNotificationObserver::Observe(type, source, details);
133 }
134
135 const std::vector<content::WebContents*>& tabs() { return observed_tabs_; }
136
137 private:
138 size_t observations_;
139 std::vector<content::WebContents*> observed_tabs_;
140
141 DISALLOW_COPY_AND_ASSIGN(TabsAddedNotificationObserver);
142};
143
[email protected]85d3d5e2012-08-31 21:19:17144const char kTestFilePath[] = "platform_apps/launch_files/test.txt";
145
[email protected]375003a2011-12-13 02:53:21146} // namespace
147
[email protected]eb4bcac2012-06-27 01:32:08148// Tests that CreateShellWindow doesn't crash if you close it straight away.
149// LauncherPlatformAppBrowserTest relies on this behaviour, but is only run for
150// ash, so we test that it works here.
151IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, CreateAndCloseShellWindow) {
152 const Extension* extension = LoadAndLaunchPlatformApp("minimal");
153 ShellWindow* window = CreateShellWindow(extension);
154 CloseShellWindow(window);
155}
156
[email protected]688a1732012-10-18 20:19:31157// Tests that platform apps can be launched in incognito mode without crashing.
[email protected]50a04d32012-11-05 11:44:22158// Times out on ChromeOS: http://crbug.com/159392
159#if defined(OS_CHROMEOS)
160#define MAYBE_LaunchAppIncognito DISABLED_LaunchAppIncognito
161#else
162#define MAYBE_LaunchAppIncognito LaunchAppIncognito
163#endif
164IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_LaunchAppIncognito) {
[email protected]688a1732012-10-18 20:19:31165 Browser* browser_incognito = ui_test_utils::OpenURLOffTheRecord(
166 browser()->profile(), GURL("about:blank"));
167
168 ExtensionTestMessageListener launched_listener("Launched", false);
169
170 const Extension* extension = LoadExtensionIncognito(
171 test_data_dir_.AppendASCII("platform_apps").AppendASCII("minimal"));
172 EXPECT_TRUE(extension);
173
174 application_launch::OpenApplication(application_launch::LaunchParams(
175 browser_incognito->profile(), extension, extension_misc::LAUNCH_NONE,
176 NEW_WINDOW));
177
178 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
179}
180
[email protected]dc37b002012-04-23 23:02:26181// Tests that platform apps received the "launch" event when launched.
182IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OnLaunchedEvent) {
183 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_;
[email protected]cfc6cca2011-12-01 02:30:06184}
[email protected]375003a2011-12-13 02:53:21185
[email protected]a6db6122012-09-03 06:00:23186// Tests that platform apps can reply to "launch" events that contain a Web
187// Intent. This test does not test the mechanics of invoking a Web Intent
188// from a source page, and short-circuits to LaunchPlatformAppWithWebIntent.
189IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchReply) {
190 FilePath path = test_data_dir_.AppendASCII("platform_apps/launch_reply");
191 const extensions::Extension* extension = LoadExtension(path);
192 ASSERT_TRUE(extension) << "Failed to load extension.";
193
194 webkit_glue::WebIntentData data(
195 UTF8ToUTF16("http://webintents.org/view"),
196 UTF8ToUTF16("text/plain"),
197 UTF8ToUTF16("irrelevant unserialized string data"));
198 LaunchReplyHandler handler(data);
199
200 // Navigate to a boring page: we don't care what it is, but we require some
201 // source WebContents to launch the Web Intent "from".
202 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
203 WebContents* web_contents = chrome::GetActiveWebContents(browser());
204 ASSERT_TRUE(web_contents);
205
206 extensions::LaunchPlatformAppWithWebIntent(
207 browser()->profile(),
208 extension,
209 handler.intents_dispatcher(),
210 web_contents);
211
212 ASSERT_TRUE(handler.WaitUntilReply());
213}
214
[email protected]567230b2012-08-21 21:11:44215// Tests that platform apps cannot use certain disabled window properties, but
216// can override them and then use them.
217IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisabledWindowProperties) {
218 ASSERT_TRUE(RunPlatformAppTest("platform_apps/disabled_window_properties"))
219 << message_;
220}
221
[email protected]edd7ed692012-02-08 02:50:03222IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) {
[email protected]e92a3612012-11-08 18:44:58223 ExtensionTestMessageListener launched_listener("Launched", false);
[email protected]31bdbfef2012-05-22 19:59:15224 LoadAndLaunchPlatformApp("minimal");
[email protected]dc37b002012-04-23 23:02:26225
[email protected]e92a3612012-11-08 18:44:58226 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
227
[email protected]375003a2011-12-13 02:53:21228 // The empty app doesn't add any context menu items, so its menu should
[email protected]0cfacd82012-02-09 01:55:33229 // only include the developer tools.
[email protected]d72d3a62012-05-10 03:45:08230 WebContents* web_contents = GetFirstShellWindowWebContents();
[email protected]a44657202012-01-09 05:48:31231 ASSERT_TRUE(web_contents);
[email protected]375003a2011-12-13 02:53:21232 WebKit::WebContextMenuData data;
[email protected]35be7ec2012-02-12 20:42:51233 content::ContextMenuParams params(data);
[email protected]85d3d5e2012-08-31 21:19:17234 scoped_ptr<PlatformAppContextMenu> menu;
235 menu.reset(new PlatformAppContextMenu(web_contents, params));
[email protected]375003a2011-12-13 02:53:21236 menu->Init();
[email protected]ad687a72012-06-08 06:03:11237 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
[email protected]65992d52012-09-19 23:05:31238 ASSERT_TRUE(
239 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE));
[email protected]671c9702012-09-27 07:51:19240 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP));
[email protected]ad687a72012-06-08 06:03:11241 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK));
242 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE));
[email protected]375003a2011-12-13 02:53:21243}
244
[email protected]edd7ed692012-02-08 02:50:03245IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) {
[email protected]e92a3612012-11-08 18:44:58246 ExtensionTestMessageListener launched_listener("Launched", false);
[email protected]375003a2011-12-13 02:53:21247 LoadAndLaunchPlatformApp("context_menu");
248
[email protected]e92a3612012-11-08 18:44:58249 // Wait for the extension to tell us it's initialized its context menus and
250 // launched a window.
251 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
252
[email protected]271d01c2012-08-27 23:48:05253 // The context_menu app has two context menu items. These, along with a
[email protected]0cfacd82012-02-09 01:55:33254 // separator and the developer tools, is all that should be in the menu.
[email protected]d72d3a62012-05-10 03:45:08255 WebContents* web_contents = GetFirstShellWindowWebContents();
[email protected]a44657202012-01-09 05:48:31256 ASSERT_TRUE(web_contents);
[email protected]375003a2011-12-13 02:53:21257 WebKit::WebContextMenuData data;
[email protected]35be7ec2012-02-12 20:42:51258 content::ContextMenuParams params(data);
[email protected]85d3d5e2012-08-31 21:19:17259 scoped_ptr<PlatformAppContextMenu> menu;
260 menu.reset(new PlatformAppContextMenu(web_contents, params));
[email protected]375003a2011-12-13 02:53:21261 menu->Init();
[email protected]ad687a72012-06-08 06:03:11262 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST));
[email protected]271d01c2012-08-27 23:48:05263 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1));
[email protected]ad687a72012-06-08 06:03:11264 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
[email protected]65992d52012-09-19 23:05:31265 ASSERT_TRUE(
266 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE));
[email protected]671c9702012-09-27 07:51:19267 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP));
[email protected]ad687a72012-06-08 06:03:11268 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK));
269 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE));
[email protected]b3c019b2012-08-28 02:43:48270 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO));
271}
272
[email protected]65992d52012-09-19 23:05:31273IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, InstalledAppWithContextMenu) {
[email protected]e92a3612012-11-08 18:44:58274 ExtensionTestMessageListener launched_listener("Launched", false);
[email protected]65992d52012-09-19 23:05:31275 InstallAndLaunchPlatformApp("context_menu");
276
[email protected]e92a3612012-11-08 18:44:58277 // Wait for the extension to tell us it's initialized its context menus and
278 // launched a window.
279 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
280
[email protected]65992d52012-09-19 23:05:31281 // The context_menu app has two context menu items. For an installed app
282 // these are all that should be in the menu.
283 WebContents* web_contents = GetFirstShellWindowWebContents();
284 ASSERT_TRUE(web_contents);
285 WebKit::WebContextMenuData data;
286 content::ContextMenuParams params(data);
287 scoped_ptr<PlatformAppContextMenu> menu;
288 menu.reset(new PlatformAppContextMenu(web_contents, params));
289 menu->Init();
290 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST));
291 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1));
292 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
293 ASSERT_FALSE(
294 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE));
[email protected]671c9702012-09-27 07:51:19295 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP));
[email protected]65992d52012-09-19 23:05:31296 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK));
297 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE));
298 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO));
299}
300
[email protected]b3c019b2012-08-28 02:43:48301IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuTextField) {
[email protected]e92a3612012-11-08 18:44:58302 ExtensionTestMessageListener launched_listener("Launched", false);
[email protected]b3c019b2012-08-28 02:43:48303 LoadAndLaunchPlatformApp("context_menu");
304
[email protected]e92a3612012-11-08 18:44:58305 // Wait for the extension to tell us it's initialized its context menus and
306 // launched a window.
307 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
308
[email protected]b3c019b2012-08-28 02:43:48309 // The context_menu app has one context menu item. This, along with a
310 // separator and the developer tools, is all that should be in the menu.
311 WebContents* web_contents = GetFirstShellWindowWebContents();
312 ASSERT_TRUE(web_contents);
313 WebKit::WebContextMenuData data;
314 content::ContextMenuParams params(data);
315 params.is_editable = true;
[email protected]85d3d5e2012-08-31 21:19:17316 scoped_ptr<PlatformAppContextMenu> menu;
317 menu.reset(new PlatformAppContextMenu(web_contents, params));
[email protected]b3c019b2012-08-28 02:43:48318 menu->Init();
319 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST));
320 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
[email protected]65992d52012-09-19 23:05:31321 ASSERT_TRUE(
322 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE));
[email protected]671c9702012-09-27 07:51:19323 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP));
[email protected]b3c019b2012-08-28 02:43:48324 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO));
325 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY));
326 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK));
327 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE));
328}
329
330IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuSelection) {
[email protected]e92a3612012-11-08 18:44:58331 ExtensionTestMessageListener launched_listener("Launched", false);
[email protected]b3c019b2012-08-28 02:43:48332 LoadAndLaunchPlatformApp("context_menu");
333
[email protected]e92a3612012-11-08 18:44:58334 // Wait for the extension to tell us it's initialized its context menus and
335 // launched a window.
336 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
337
[email protected]b3c019b2012-08-28 02:43:48338 // The context_menu app has one context menu item. This, along with a
339 // separator and the developer tools, is all that should be in the menu.
340 WebContents* web_contents = GetFirstShellWindowWebContents();
341 ASSERT_TRUE(web_contents);
342 WebKit::WebContextMenuData data;
343 content::ContextMenuParams params(data);
344 params.selection_text = ASCIIToUTF16("Hello World");
[email protected]85d3d5e2012-08-31 21:19:17345 scoped_ptr<PlatformAppContextMenu> menu;
346 menu.reset(new PlatformAppContextMenu(web_contents, params));
[email protected]b3c019b2012-08-28 02:43:48347 menu->Init();
348 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST));
349 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
[email protected]65992d52012-09-19 23:05:31350 ASSERT_TRUE(
351 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE));
[email protected]671c9702012-09-27 07:51:19352 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP));
[email protected]b3c019b2012-08-28 02:43:48353 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO));
354 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY));
355 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK));
356 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE));
[email protected]375003a2011-12-13 02:53:21357}
[email protected]5f000f272012-01-19 05:25:08358
[email protected]dc83c582012-08-17 02:18:14359IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuClicked) {
[email protected]e92a3612012-11-08 18:44:58360 ExtensionTestMessageListener launched_listener("Launched", false);
[email protected]dc83c582012-08-17 02:18:14361 LoadAndLaunchPlatformApp("context_menu_click");
362
[email protected]e92a3612012-11-08 18:44:58363 // Wait for the extension to tell us it's initialized its context menus and
364 // launched a window.
365 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
366
[email protected]dc83c582012-08-17 02:18:14367 // Test that the menu item shows up
368 WebContents* web_contents = GetFirstShellWindowWebContents();
369 ASSERT_TRUE(web_contents);
370 WebKit::WebContextMenuData data;
371 content::ContextMenuParams params(data);
372 params.page_url = GURL("http://foo.bar");
[email protected]85d3d5e2012-08-31 21:19:17373 scoped_ptr<PlatformAppContextMenu> menu;
374 menu.reset(new PlatformAppContextMenu(web_contents, params));
[email protected]dc83c582012-08-17 02:18:14375 menu->Init();
376 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST));
377
378 // Execute the menu item
379 ExtensionTestMessageListener onclicked_listener("onClicked fired for id1",
380 false);
381 menu->ExecuteCommand(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST);
382
383 ASSERT_TRUE(onclicked_listener.WaitUntilSatisfied());
384}
385
[email protected]edd7ed692012-02-08 02:50:03386IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowNavigation) {
[email protected]4d007b312012-10-17 03:00:48387 TabsAddedNotificationObserver observer(2);
388
[email protected]dc37b002012-04-23 23:02:26389 ASSERT_TRUE(StartTestServer());
[email protected]e92a3612012-11-08 18:44:58390 ASSERT_TRUE(RunPlatformAppTest("platform_apps/navigation")) << message_;
[email protected]4d007b312012-10-17 03:00:48391
392 observer.Wait();
393 ASSERT_EQ(2U, observer.tabs().size());
394 EXPECT_EQ(std::string(chrome::kExtensionInvalidRequestURL),
395 observer.tabs()[0]->GetURL().spec());
396 EXPECT_EQ("http://chromium.org/",
397 observer.tabs()[1]->GetURL().spec());
[email protected]5f000f272012-01-19 05:25:08398}
[email protected]863e6472012-01-24 19:33:58399
[email protected]40eefd52012-10-04 22:54:22400IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Iframes) {
[email protected]fd3238af2012-05-22 18:55:30401 ASSERT_TRUE(StartTestServer());
402 ASSERT_TRUE(RunPlatformAppTest("platform_apps/iframes")) << message_;
403}
404
[email protected]2aac7ff2012-01-25 18:05:11405// Tests that localStorage and WebSQL are disabled for platform apps.
[email protected]edd7ed692012-02-08 02:50:03406IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowStorage) {
[email protected]2aac7ff2012-01-25 18:05:11407 ASSERT_TRUE(RunPlatformAppTest("platform_apps/storage")) << message_;
408}
[email protected]6a5a2e52012-03-22 03:21:12409
[email protected]c0cecd1f2012-04-05 16:50:12410IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Restrictions) {
411 ASSERT_TRUE(RunPlatformAppTest("platform_apps/restrictions")) << message_;
412}
413
[email protected]f0233ff2012-07-20 20:14:50414// Tests that platform apps can use the chrome.app.window.* API.
[email protected]5177f3a2012-11-08 17:51:29415IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApi) {
[email protected]6a5a2e52012-03-22 03:21:12416 ASSERT_TRUE(RunPlatformAppTest("platform_apps/windows_api")) << message_;
417}
[email protected]605fb8102012-05-04 01:36:55418
[email protected]1df22042012-08-30 19:48:55419// Tests that extensions can't use platform-app-only APIs.
420IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, PlatformAppsOnly) {
421 ASSERT_TRUE(RunExtensionTestIgnoreManifestWarnings(
422 "platform_apps/apps_only")) << message_;
423}
424
[email protected]605fb8102012-05-04 01:36:55425// Tests that platform apps have isolated storage by default.
426IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Isolation) {
427 ASSERT_TRUE(StartTestServer());
428
429 // Load a (non-app) page under the "localhost" origin that sets a cookie.
430 GURL set_cookie_url = test_server()->GetURL(
431 "files/extensions/platform_apps/isolation/set_cookie.html");
432 GURL::Replacements replace_host;
433 std::string host_str("localhost"); // Must stay in scope with replace_host.
434 replace_host.SetHostStr(host_str);
435 set_cookie_url = set_cookie_url.ReplaceComponents(replace_host);
436
437 ui_test_utils::NavigateToURLWithDisposition(
438 browser(), set_cookie_url,
439 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
440
441 // Make sure the cookie is set.
442 int cookie_size;
443 std::string cookie_value;
444 automation_util::GetCookies(
445 set_cookie_url,
[email protected]52877dbc62012-06-29 22:22:03446 chrome::GetWebContentsAt(browser(), 0),
[email protected]605fb8102012-05-04 01:36:55447 &cookie_size,
448 &cookie_value);
449 ASSERT_EQ("testCookie=1", cookie_value);
450
451 // Let the platform app request the same URL, and make sure that it doesn't
452 // see the cookie.
453 ASSERT_TRUE(RunPlatformAppTest("platform_apps/isolation")) << message_;
454}
[email protected]31bdbfef2012-05-22 19:59:15455
456IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ExtensionWindowingApis) {
457 // Initially there should be just the one browser window visible to the
458 // extensions API.
459 const Extension* extension = LoadExtension(
460 test_data_dir_.AppendASCII("common/background_page"));
461 ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(extension));
462
463 // And no shell windows.
464 ASSERT_EQ(0U, GetShellWindowCount());
465
466 // Launch a platform app that shows a window.
[email protected]e92a3612012-11-08 18:44:58467 ExtensionTestMessageListener launched_listener("Launched", false);
[email protected]ad5bb8a92012-06-07 03:55:58468 LoadAndLaunchPlatformApp("minimal");
[email protected]e92a3612012-11-08 18:44:58469 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
[email protected]31bdbfef2012-05-22 19:59:15470 ASSERT_EQ(1U, GetShellWindowCount());
471 ShellWindowRegistry::ShellWindowSet shell_windows =
472 ShellWindowRegistry::Get(browser()->profile())->shell_windows();
473 int shell_window_id = (*shell_windows.begin())->session_id().id();
474
475 // But it's not visible to the extensions API, it still thinks there's just
476 // one browser window.
477 ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(extension));
478 // It can't look it up by ID either
479 ASSERT_FALSE(RunGetWindowFunctionForExtension(shell_window_id, extension));
480
481 // The app can also only see one window (its own).
[email protected]ad5bb8a92012-06-07 03:55:58482 // TODO(jeremya): add an extension function to get a shell window by ID, and
483 // to get a list of all the shell windows, so we can test this.
[email protected]31bdbfef2012-05-22 19:59:15484
485 // Launch another platform app that also shows a window.
[email protected]e92a3612012-11-08 18:44:58486 ExtensionTestMessageListener launched_listener2("Launched", false);
[email protected]ad5bb8a92012-06-07 03:55:58487 LoadAndLaunchPlatformApp("context_menu");
[email protected]e92a3612012-11-08 18:44:58488 ASSERT_TRUE(launched_listener2.WaitUntilSatisfied());
[email protected]31bdbfef2012-05-22 19:59:15489
490 // There are two total shell windows, but each app can only see its own.
491 ASSERT_EQ(2U, GetShellWindowCount());
[email protected]ad5bb8a92012-06-07 03:55:58492 // TODO(jeremya): as above, this requires more extension functions.
[email protected]31bdbfef2012-05-22 19:59:15493}
[email protected]12e540452012-05-26 07:09:36494
[email protected]a2ece522012-10-16 03:41:10495// ChromeOS does not support passing arguments on the command line, so the tests
496// that rely on this functionality are disabled.
[email protected]12e540452012-05-26 07:09:36497#if !defined(OS_CHROMEOS)
498// Tests that command line parameters get passed through to platform apps
499// via launchData correctly when launching with a file.
[email protected]7d0cbb62012-11-22 04:41:07500// TODO(benwells/jeremya): tests need a way to specify a handler ID.
[email protected]12e540452012-05-26 07:09:36501IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithFile) {
[email protected]85d3d5e2012-08-31 21:19:17502 SetCommandLineArg(kTestFilePath);
[email protected]12e540452012-05-26 07:09:36503 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_file"))
504 << message_;
505}
506
[email protected]a5a0be02012-07-18 05:51:54507// Tests that relative paths can be passed through to the platform app.
508// This test doesn't use the normal test infrastructure as it needs to open
509// the application differently to all other platform app tests, by setting
510// the application_launch::LaunchParams.current_directory field.
511IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithRelativeFile) {
512 // Setup the command line
513 ClearCommandLineArgs();
514 CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]85d3d5e2012-08-31 21:19:17515 FilePath relative_test_doc = FilePath::FromUTF8Unsafe(kTestFilePath);
[email protected]a5a0be02012-07-18 05:51:54516 relative_test_doc = relative_test_doc.NormalizePathSeparators();
517 command_line->AppendArgPath(relative_test_doc);
518
519 // Load the extension
520 ResultCatcher catcher;
[email protected]d9ede582012-08-14 19:21:38521 const Extension* extension = LoadExtension(
[email protected]a5a0be02012-07-18 05:51:54522 test_data_dir_.AppendASCII("platform_apps/launch_file"));
523 ASSERT_TRUE(extension);
524
525 // Run the test
526 application_launch::LaunchParams params(browser()->profile(), extension,
527 extension_misc::LAUNCH_NONE,
528 NEW_WINDOW);
529 params.command_line = CommandLine::ForCurrentProcess();
530 params.current_directory = test_data_dir_;
531 application_launch::OpenApplication(params);
532
533 if (!catcher.GetNextResult()) {
534 message_ = catcher.message();
535 ASSERT_TRUE(0);
536 }
537}
538
[email protected]12e540452012-05-26 07:09:36539// Tests that no launch data is sent through if the file is of the wrong MIME
540// type.
541IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithWrongType) {
[email protected]85d3d5e2012-08-31 21:19:17542 SetCommandLineArg(kTestFilePath);
[email protected]12e540452012-05-26 07:09:36543 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_type"))
544 << message_;
545}
546
547// Tests that no launch data is sent through if the platform app does not
548// provide an intent.
549IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithNoIntent) {
[email protected]85d3d5e2012-08-31 21:19:17550 SetCommandLineArg(kTestFilePath);
[email protected]12e540452012-05-26 07:09:36551 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_no_intent"))
552 << message_;
553}
554
555// Tests that no launch data is sent through if the file MIME type cannot
556// be read.
557IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchNoType) {
558 SetCommandLineArg("platform_apps/launch_files/test.unknownextension");
559 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid"))
560 << message_;
561}
562
563// Tests that no launch data is sent through if the file does not exist.
564IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchNoFile) {
565 SetCommandLineArg("platform_apps/launch_files/doesnotexist.txt");
566 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid"))
567 << message_;
568}
569
570// Tests that no launch data is sent through if the argument is a directory.
571IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithDirectory) {
572 SetCommandLineArg("platform_apps/launch_files");
573 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid"))
574 << message_;
575}
576
577// Tests that no launch data is sent through if there are no arguments passed
578// on the command line
579IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithNothing) {
580 ClearCommandLineArgs();
581 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_nothing"))
582 << message_;
583}
[email protected]ffc7b4d2012-06-08 00:05:32584
585// Test that platform apps can use the chrome.fileSystem.getDisplayPath
586// function to get the native file system path of a file they are launched with.
587IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, GetDisplayPath) {
[email protected]85d3d5e2012-08-31 21:19:17588 SetCommandLineArg(kTestFilePath);
[email protected]ffc7b4d2012-06-08 00:05:32589 ASSERT_TRUE(RunPlatformAppTest("platform_apps/get_display_path"))
590 << message_;
591}
592
[email protected]12e540452012-05-26 07:09:36593#endif // defined(OS_CHROMEOS)
[email protected]5b1a04b42012-06-15 00:41:44594
595IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OpenLink) {
596 ASSERT_TRUE(StartTestServer());
[email protected]a7fe9112012-07-20 02:34:45597 content::WindowedNotificationObserver observer(
[email protected]5b1a04b42012-06-15 00:41:44598 chrome::NOTIFICATION_TAB_ADDED,
599 content::Source<content::WebContentsDelegate>(browser()));
600 LoadAndLaunchPlatformApp("open_link");
601 observer.Wait();
602 ASSERT_EQ(2, browser()->tab_count());
603}
[email protected]d9ede582012-08-14 19:21:38604
[email protected]3a8e61942012-08-23 01:46:45605IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MutationEventsDisabled) {
606 ASSERT_TRUE(RunPlatformAppTest("platform_apps/mutation_events")) << message_;
607}
608
[email protected]939532d02012-08-31 23:37:33609// Test that windows created with an id will remember and restore their
610// geometry when opening new windows.
[email protected]69080832012-11-20 20:31:47611// Originally disabled due to flakiness (see http://crbug.com/155459)
612// but now because a regression breaks the test (http://crbug.com/160343).
[email protected]329c4e92012-11-09 06:04:24613#define MAYBE_ShellWindowRestorePosition DISABLED_ShellWindowRestorePosition
[email protected]9d53c1c2012-10-18 00:49:54614IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
[email protected]329c4e92012-11-09 06:04:24615 MAYBE_ShellWindowRestorePosition) {
[email protected]939532d02012-08-31 23:37:33616 ExtensionTestMessageListener page2_listener("WaitForPage2", true);
617 ExtensionTestMessageListener page3_listener("WaitForPage3", true);
618 ExtensionTestMessageListener done_listener("Done1", false);
619 ExtensionTestMessageListener done2_listener("Done2", false);
620 ExtensionTestMessageListener done3_listener("Done3", false);
621
622 ASSERT_TRUE(LoadAndLaunchPlatformApp("geometry"));
623
624 // Wait for the app to be launched (although this is mostly to have a
625 // message to reply to to let the script know it should create its second
626 // window.
627 ASSERT_TRUE(page2_listener.WaitUntilSatisfied());
628
629 // Wait for the first window to verify its geometry was correctly set
630 // from the default* attributes passed to the create function.
631 ASSERT_TRUE(done_listener.WaitUntilSatisfied());
632
633 // Programatically move and resize the window.
634 ShellWindow* window = GetFirstShellWindow();
635 ASSERT_TRUE(window);
636 gfx::Rect bounds(137, 143, 203, 187);
637 window->GetBaseWindow()->SetBounds(bounds);
638
639#if defined(TOOLKIT_GTK)
640 // TODO(mek): On GTK we have to wait for a roundtrip to the X server before
641 // a resize actually happens:
642 // "if you call gtk_window_resize() then immediately call
643 // gtk_window_get_size(), the size won't have taken effect yet. After the
644 // window manager processes the resize request, GTK+ receives notification
645 // that the size has changed via a configure event, and the size of the
646 // window gets updated."
647 // Because of this we have to wait for an unknown time for the resize to
648 // actually take effect. So wait some time or until the resize got
649 // handled.
650 base::TimeTicks end_time = base::TimeTicks::Now() +
651 TestTimeouts::action_timeout();
652 while (base::TimeTicks::Now() < end_time &&
653 bounds != window->GetBaseWindow()->GetBounds()) {
654 content::RunAllPendingInMessageLoop();
655 }
656
657 // In the GTK ShellWindow implementation there also is a delay between
658 // getting the correct bounds and it calling SaveWindowPosition, so call that
659 // method explicitly to make sure the value was stored.
660 window->SaveWindowPosition();
661#endif // defined(TOOLKIT_GTK)
662
663 // Make sure the window was properly moved&resized.
664 ASSERT_EQ(bounds, window->GetBaseWindow()->GetBounds());
665
666 // Tell javascript to open a second window.
667 page2_listener.Reply("continue");
668
669 // Wait for javascript to verify that the second window got the updated
670 // coordinates, ignoring the default coordinates passed to the create method.
671 ASSERT_TRUE(done2_listener.WaitUntilSatisfied());
672
673 // Tell javascript to open a third window.
674 page3_listener.Reply("continue");
675
676 // Wait for javascript to verify that the third window got the restored size
677 // and explicitly specified coordinates.
678 ASSERT_TRUE(done3_listener.WaitUntilSatisfied());
679}
[email protected]939532d02012-08-31 23:37:33680
[email protected]28c3eeb2012-10-15 05:47:53681// Tests that a running app is recorded in the preferences as such.
682IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, RunningAppsAreRecorded) {
683 content::WindowedNotificationObserver extension_suspended(
684 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
685 content::NotificationService::AllSources());
686
687 const Extension* extension = LoadExtension(
688 test_data_dir_.AppendASCII("platform_apps/restart_test"));
689 ASSERT_TRUE(extension);
690 ExtensionService* extension_service =
691 ExtensionSystem::Get(browser()->profile())->extension_service();
692 ExtensionPrefs* extension_prefs = extension_service->extension_prefs();
693
694 // App is running.
695 ASSERT_TRUE(extension_prefs->IsExtensionRunning(extension->id()));
696
697 // Wait for the extension to get suspended.
698 extension_suspended.Wait();
699
700 // App isn't running because it got suspended.
701 ASSERT_FALSE(extension_prefs->IsExtensionRunning(extension->id()));
702
703 // Pretend that the app is supposed to be running.
704 extension_prefs->SetExtensionRunning(extension->id(), true);
705
706 ExtensionTestMessageListener restart_listener("onRestarted", false);
[email protected]119454622012-10-18 09:48:32707 AppRestoreServiceFactory::GetForProfile(browser()->profile())->
708 HandleStartup(true);
[email protected]28c3eeb2012-10-15 05:47:53709 restart_listener.WaitUntilSatisfied();
710}
711
[email protected]545b5312012-11-07 12:18:21712namespace {
713
714class PlatformAppDevToolsBrowserTest : public PlatformAppBrowserTest {
715 protected:
716 enum TestFlags {
717 RELAUNCH = 0x1,
718 HAS_ID = 0x2,
719 };
720 // Runs a test inside a harness that opens DevTools on a shell window.
721 void RunTestWithDevTools(const char* name, int test_flags);
722};
723
724void PlatformAppDevToolsBrowserTest::RunTestWithDevTools(
725 const char* name, int test_flags) {
[email protected]e85cc642012-10-24 06:14:23726 using content::DevToolsAgentHostRegistry;
[email protected]e92a3612012-11-08 18:44:58727 ExtensionTestMessageListener launched_listener("Launched", false);
[email protected]545b5312012-11-07 12:18:21728 const Extension* extension = LoadAndLaunchPlatformApp(name);
[email protected]e85cc642012-10-24 06:14:23729 ASSERT_TRUE(extension);
[email protected]e92a3612012-11-08 18:44:58730 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
[email protected]e85cc642012-10-24 06:14:23731 ShellWindow* window = GetFirstShellWindow();
732 ASSERT_TRUE(window);
[email protected]545b5312012-11-07 12:18:21733 ASSERT_EQ(window->window_key().empty(), (test_flags & HAS_ID) == 0);
[email protected]e85cc642012-10-24 06:14:23734 content::RenderViewHost* rvh = window->web_contents()->GetRenderViewHost();
735 ASSERT_TRUE(rvh);
736
737 // Ensure no DevTools open for the ShellWindow, then open one.
738 ASSERT_FALSE(DevToolsAgentHostRegistry::HasDevToolsAgentHost(rvh));
739 DevToolsWindow* devtools_window = DevToolsWindow::OpenDevToolsWindow(rvh);
740 content::WindowedNotificationObserver loaded_observer(
741 content::NOTIFICATION_LOAD_STOP,
742 content::Source<content::NavigationController>(
743 &devtools_window->tab_contents()->web_contents()->GetController()));
744 loaded_observer.Wait();
745 ASSERT_TRUE(DevToolsAgentHostRegistry::HasDevToolsAgentHost(rvh));
746
[email protected]545b5312012-11-07 12:18:21747 if (test_flags & RELAUNCH) {
748 // Close the ShellWindow, and ensure it is gone.
749 CloseShellWindow(window);
750 ASSERT_FALSE(GetFirstShellWindow());
[email protected]e85cc642012-10-24 06:14:23751
[email protected]545b5312012-11-07 12:18:21752 // Relaunch the app and get a new ShellWindow.
753 content::WindowedNotificationObserver app_loaded_observer(
754 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
755 content::NotificationService::AllSources());
756 application_launch::OpenApplication(application_launch::LaunchParams(
757 browser()->profile(), extension, extension_misc::LAUNCH_NONE,
758 NEW_WINDOW));
759 app_loaded_observer.Wait();
760 window = GetFirstShellWindow();
761 ASSERT_TRUE(window);
[email protected]e85cc642012-10-24 06:14:23762
[email protected]545b5312012-11-07 12:18:21763 // DevTools should have reopened with the relaunch.
764 rvh = window->web_contents()->GetRenderViewHost();
765 ASSERT_TRUE(rvh);
766 ASSERT_TRUE(DevToolsAgentHostRegistry::HasDevToolsAgentHost(rvh));
767 }
[email protected]e85cc642012-10-24 06:14:23768}
769
[email protected]545b5312012-11-07 12:18:21770} // namespace
771
772IN_PROC_BROWSER_TEST_F(PlatformAppDevToolsBrowserTest, ReOpenedWithID) {
773 RunTestWithDevTools("minimal_id", RELAUNCH | HAS_ID);
774}
775
776IN_PROC_BROWSER_TEST_F(PlatformAppDevToolsBrowserTest, ReOpenedWithURL) {
777 RunTestWithDevTools("minimal", RELAUNCH);
778}
779
[email protected]ddf42162012-11-06 21:14:55780// Test that showing a permission request as a constrained window works and is
781// correctly parented.
782#if defined(OS_MACOSX)
[email protected]cd202662012-11-07 19:11:41783#define MAYBE_ConstrainedWindowRequest DISABLED_ConstrainedWindowRequest
[email protected]ddf42162012-11-06 21:14:55784#else
785// TODO(sail): Enable this on other platforms once http://crbug.com/95455 is
786// fixed.
787#define MAYBE_ConstrainedWindowRequest DISABLED_ConstrainedWindowRequest
788#endif
789
790IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_ConstrainedWindowRequest) {
791 RequestPermissionsFunction::SetIgnoreUserGestureForTests(true);
792 const Extension* extension =
793 LoadAndLaunchPlatformApp("optional_permission_request");
794 ASSERT_TRUE(extension) << "Failed to load extension.";
795
796 WebContents* web_contents = GetFirstShellWindowWebContents();
797 ASSERT_TRUE(web_contents);
798
799 // Verify that the shell window has a constrained window attached.
800 ConstrainedWindowTabHelper* constrained_window_tab_helper =
801 ConstrainedWindowTabHelper::FromWebContents(web_contents);
802 EXPECT_EQ(1u, constrained_window_tab_helper->constrained_window_count());
803
804 // Close the constrained window and wait for the reply to the permission
805 // request.
806 ExtensionTestMessageListener listener("PermissionRequestDone", false);
807 constrained_window_tab_helper->CloseConstrainedWindows();
808 ASSERT_TRUE(listener.WaitUntilSatisfied());
[email protected]ddf42162012-11-06 21:14:55809}
810
[email protected]bf1be4e2012-11-07 20:32:27811// Tests that an app calling chrome.runtime.reload will reload the app and
812// relaunch it if it was running.
813IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ReloadRelaunches) {
814 ExtensionTestMessageListener launched_listener("Launched", true);
[email protected]e92a3612012-11-08 18:44:58815 const Extension* extension = LoadAndLaunchPlatformApp("reload");
[email protected]bf1be4e2012-11-07 20:32:27816 ASSERT_TRUE(extension);
[email protected]bf1be4e2012-11-07 20:32:27817 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
818 ASSERT_TRUE(GetFirstShellWindow());
819
820 // Now tell the app to reload itself
821 ExtensionTestMessageListener launched_listener2("Launched", false);
822 launched_listener.Reply("reload");
823 ASSERT_TRUE(launched_listener2.WaitUntilSatisfied());
824 ASSERT_TRUE(GetFirstShellWindow());
[email protected]bf1be4e2012-11-07 20:32:27825}
826
[email protected]d9ede582012-08-14 19:21:38827} // namespace extensions