[email protected] | a4465720 | 2012-01-09 05:48:31 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | cfc6cca | 2011-12-01 02:30:06 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | a6db612 | 2012-09-03 06:00:23 | [diff] [blame] | 5 | #include "base/bind.h" |
[email protected] | 939532d0 | 2012-08-31 23:37:33 | [diff] [blame] | 6 | #include "base/test/test_timeouts.h" |
| 7 | #include "base/threading/platform_thread.h" |
[email protected] | b3c019b | 2012-08-28 02:43:48 | [diff] [blame] | 8 | #include "base/utf_string_conversions.h" |
[email protected] | ad687a7 | 2012-06-08 06:03:11 | [diff] [blame] | 9 | #include "chrome/app/chrome_command_ids.h" |
[email protected] | 605fb810 | 2012-05-04 01:36:55 | [diff] [blame] | 10 | #include "chrome/browser/automation/automation_util.h" |
[email protected] | 7001915 | 2012-12-19 11:44:19 | [diff] [blame] | 11 | #include "chrome/browser/devtools/devtools_window.h" |
[email protected] | ddf4216 | 2012-11-06 21:14:55 | [diff] [blame] | 12 | #include "chrome/browser/extensions/api/permissions/permissions_api.h" |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 13 | #include "chrome/browser/extensions/app_restore_service_factory.h" |
| 14 | #include "chrome/browser/extensions/app_restore_service.h" |
[email protected] | a6db612 | 2012-09-03 06:00:23 | [diff] [blame] | 15 | #include "chrome/browser/extensions/extension_browsertest.h" |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 16 | #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] | 25977110 | 2012-05-31 16:52:20 | [diff] [blame] | 19 | #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 20 | #include "chrome/browser/extensions/platform_app_browsertest_util.h" |
[email protected] | a6db612 | 2012-09-03 06:00:23 | [diff] [blame] | 21 | #include "chrome/browser/extensions/platform_app_launcher.h" |
[email protected] | 25977110 | 2012-05-31 16:52:20 | [diff] [blame] | 22 | #include "chrome/browser/extensions/shell_window_registry.h" |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 23 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | e85cc64 | 2012-10-24 06:14:23 | [diff] [blame] | 24 | #include "chrome/browser/tab_contents/render_view_context_menu.h" |
[email protected] | cfc6cca | 2011-12-01 02:30:06 | [diff] [blame] | 25 | #include "chrome/browser/ui/browser.h" |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 26 | #include "chrome/browser/ui/browser_tabstrip.h" |
[email protected] | ddf4216 | 2012-11-06 21:14:55 | [diff] [blame] | 27 | #include "chrome/browser/ui/constrained_window_tab_helper.h" |
[email protected] | a5a0be0 | 2012-07-18 05:51:54 | [diff] [blame] | 28 | #include "chrome/browser/ui/extensions/application_launch.h" |
[email protected] | 1b1989f5 | 2012-12-03 08:33:54 | [diff] [blame] | 29 | #include "chrome/browser/ui/extensions/native_app_window.h" |
[email protected] | d72d3a6 | 2012-05-10 03:45:08 | [diff] [blame] | 30 | #include "chrome/browser/ui/extensions/shell_window.h" |
[email protected] | 5b1a04b4 | 2012-06-15 00:41:44 | [diff] [blame] | 31 | #include "chrome/common/chrome_notification_types.h" |
[email protected] | 4d007b31 | 2012-10-17 03:00:48 | [diff] [blame] | 32 | #include "chrome/common/url_constants.h" |
[email protected] | cfc6cca | 2011-12-01 02:30:06 | [diff] [blame] | 33 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | e85cc64 | 2012-10-24 06:14:23 | [diff] [blame] | 34 | #include "content/public/browser/devtools_agent_host_registry.h" |
[email protected] | fb29e6cf | 2012-07-12 21:27:20 | [diff] [blame] | 35 | #include "content/public/browser/render_process_host.h" |
[email protected] | a6db612 | 2012-09-03 06:00:23 | [diff] [blame] | 36 | #include "content/public/browser/web_intents_dispatcher.h" |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 37 | #include "content/public/test/test_utils.h" |
[email protected] | a6db612 | 2012-09-03 06:00:23 | [diff] [blame] | 38 | #include "googleurl/src/gurl.h" |
| 39 | #include "webkit/glue/web_intent_data.h" |
[email protected] | cfc6cca | 2011-12-01 02:30:06 | [diff] [blame] | 40 | |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 41 | using content::WebContents; |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 42 | |
| 43 | namespace extensions { |
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 44 | |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 45 | namespace { |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 46 | |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 47 | // Non-abstract RenderViewContextMenu class. |
| 48 | class PlatformAppContextMenu : public RenderViewContextMenu { |
| 49 | public: |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 50 | PlatformAppContextMenu(WebContents* web_contents, |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 51 | const content::ContextMenuParams& params) |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 52 | : RenderViewContextMenu(web_contents, params) {} |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 53 | |
[email protected] | ad687a7 | 2012-06-08 06:03:11 | [diff] [blame] | 54 | bool HasCommandWithId(int command_id) { |
| 55 | return menu_model_.GetIndexOfCommandId(command_id) != -1; |
| 56 | } |
| 57 | |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 58 | protected: |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 59 | // RenderViewContextMenu implementation. |
| 60 | virtual bool GetAcceleratorForCommandId( |
| 61 | int command_id, |
| 62 | ui::Accelerator* accelerator) OVERRIDE { |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 63 | return false; |
| 64 | } |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 65 | virtual void PlatformInit() OVERRIDE {} |
| 66 | virtual void PlatformCancel() OVERRIDE {} |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 67 | }; |
| 68 | |
[email protected] | a6db612 | 2012-09-03 06:00:23 | [diff] [blame] | 69 | // State holder for the LaunchReply test. This provides an WebIntentsDispatcher |
| 70 | // that will, when used to launch a Web Intent, will return its reply via this |
| 71 | // class. The result may then be waited on via WaitUntilReply(). |
| 72 | class LaunchReplyHandler { |
| 73 | public: |
| 74 | explicit LaunchReplyHandler(webkit_glue::WebIntentData& data) |
| 75 | : data_(data), |
| 76 | replied_(false), |
| 77 | weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 78 | intents_dispatcher_ = content::WebIntentsDispatcher::Create(data); |
| 79 | intents_dispatcher_->RegisterReplyNotification(base::Bind( |
| 80 | &LaunchReplyHandler::OnReply, weak_ptr_factory_.GetWeakPtr())); |
| 81 | } |
| 82 | |
| 83 | content::WebIntentsDispatcher* intents_dispatcher() { |
| 84 | return intents_dispatcher_; |
| 85 | } |
| 86 | |
| 87 | // Waits until a reply to this Web Intent is provided via the |
| 88 | // WebIntentsDispatcher. |
| 89 | bool WaitUntilReply() { |
| 90 | if (replied_) |
| 91 | return true; |
| 92 | waiting_ = true; |
| 93 | content::RunMessageLoop(); |
| 94 | waiting_ = false; |
| 95 | return replied_; |
| 96 | } |
| 97 | |
| 98 | private: |
| 99 | void OnReply(webkit_glue::WebIntentReplyType reply) { |
| 100 | // Note that the ReplyNotification registered on WebIntentsDispatcher does |
| 101 | // not include the result data: this is reserved for the source page (which |
| 102 | // we don't care about). |
| 103 | replied_ = true; |
| 104 | if (waiting_) |
| 105 | MessageLoopForUI::current()->Quit(); |
| 106 | } |
| 107 | |
| 108 | webkit_glue::WebIntentData data_; |
| 109 | bool replied_; |
| 110 | bool waiting_; |
| 111 | content::WebIntentsDispatcher* intents_dispatcher_; |
| 112 | base::WeakPtrFactory<LaunchReplyHandler> weak_ptr_factory_; |
| 113 | }; |
| 114 | |
[email protected] | 4d007b31 | 2012-10-17 03:00:48 | [diff] [blame] | 115 | // This class keeps track of tabs as they are added to the browser. It will be |
| 116 | // "done" (i.e. won't block on Wait()) once |observations| tabs have been added. |
| 117 | class TabsAddedNotificationObserver |
| 118 | : public content::WindowedNotificationObserver { |
| 119 | public: |
| 120 | explicit TabsAddedNotificationObserver(size_t observations) |
| 121 | : content::WindowedNotificationObserver( |
| 122 | chrome::NOTIFICATION_TAB_ADDED, |
| 123 | content::NotificationService::AllSources()), |
| 124 | observations_(observations) { |
| 125 | } |
| 126 | |
| 127 | virtual void Observe(int type, |
| 128 | const content::NotificationSource& source, |
| 129 | const content::NotificationDetails& details) OVERRIDE { |
| 130 | observed_tabs_.push_back( |
| 131 | content::Details<WebContents>(details).ptr()); |
| 132 | if (observed_tabs_.size() == observations_) |
| 133 | content::WindowedNotificationObserver::Observe(type, source, details); |
| 134 | } |
| 135 | |
| 136 | const std::vector<content::WebContents*>& tabs() { return observed_tabs_; } |
| 137 | |
| 138 | private: |
| 139 | size_t observations_; |
| 140 | std::vector<content::WebContents*> observed_tabs_; |
| 141 | |
| 142 | DISALLOW_COPY_AND_ASSIGN(TabsAddedNotificationObserver); |
| 143 | }; |
| 144 | |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 145 | const char kTestFilePath[] = "platform_apps/launch_files/test.txt"; |
| 146 | |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 147 | } // namespace |
| 148 | |
[email protected] | eb4bcac | 2012-06-27 01:32:08 | [diff] [blame] | 149 | // Tests that CreateShellWindow doesn't crash if you close it straight away. |
| 150 | // LauncherPlatformAppBrowserTest relies on this behaviour, but is only run for |
| 151 | // ash, so we test that it works here. |
| 152 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, CreateAndCloseShellWindow) { |
| 153 | const Extension* extension = LoadAndLaunchPlatformApp("minimal"); |
| 154 | ShellWindow* window = CreateShellWindow(extension); |
| 155 | CloseShellWindow(window); |
| 156 | } |
| 157 | |
[email protected] | dc37b00 | 2012-04-23 23:02:26 | [diff] [blame] | 158 | // Tests that platform apps received the "launch" event when launched. |
| 159 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OnLaunchedEvent) { |
| 160 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_; |
[email protected] | cfc6cca | 2011-12-01 02:30:06 | [diff] [blame] | 161 | } |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 162 | |
[email protected] | a6db612 | 2012-09-03 06:00:23 | [diff] [blame] | 163 | // Tests that platform apps can reply to "launch" events that contain a Web |
| 164 | // Intent. This test does not test the mechanics of invoking a Web Intent |
| 165 | // from a source page, and short-circuits to LaunchPlatformAppWithWebIntent. |
| 166 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchReply) { |
| 167 | FilePath path = test_data_dir_.AppendASCII("platform_apps/launch_reply"); |
| 168 | const extensions::Extension* extension = LoadExtension(path); |
| 169 | ASSERT_TRUE(extension) << "Failed to load extension."; |
| 170 | |
| 171 | webkit_glue::WebIntentData data( |
| 172 | UTF8ToUTF16("http://webintents.org/view"), |
| 173 | UTF8ToUTF16("text/plain"), |
| 174 | UTF8ToUTF16("irrelevant unserialized string data")); |
| 175 | LaunchReplyHandler handler(data); |
| 176 | |
| 177 | // Navigate to a boring page: we don't care what it is, but we require some |
| 178 | // source WebContents to launch the Web Intent "from". |
| 179 | ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 180 | WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
| 181 | ASSERT_TRUE(web_contents); |
| 182 | |
| 183 | extensions::LaunchPlatformAppWithWebIntent( |
| 184 | browser()->profile(), |
| 185 | extension, |
| 186 | handler.intents_dispatcher(), |
| 187 | web_contents); |
| 188 | |
| 189 | ASSERT_TRUE(handler.WaitUntilReply()); |
| 190 | } |
| 191 | |
[email protected] | 567230b | 2012-08-21 21:11:44 | [diff] [blame] | 192 | // Tests that platform apps cannot use certain disabled window properties, but |
| 193 | // can override them and then use them. |
| 194 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisabledWindowProperties) { |
| 195 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/disabled_window_properties")) |
| 196 | << message_; |
| 197 | } |
| 198 | |
[email protected] | edd7ed69 | 2012-02-08 02:50:03 | [diff] [blame] | 199 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) { |
[email protected] | d9d0276 | 2012-12-04 05:18:58 | [diff] [blame] | 200 | ExtensionTestMessageListener launched_listener("Launched", false); |
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 201 | LoadAndLaunchPlatformApp("minimal"); |
[email protected] | dc37b00 | 2012-04-23 23:02:26 | [diff] [blame] | 202 | |
[email protected] | d9d0276 | 2012-12-04 05:18:58 | [diff] [blame] | 203 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 204 | |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 205 | // The empty app doesn't add any context menu items, so its menu should |
[email protected] | 0cfacd8 | 2012-02-09 01:55:33 | [diff] [blame] | 206 | // only include the developer tools. |
[email protected] | d72d3a6 | 2012-05-10 03:45:08 | [diff] [blame] | 207 | WebContents* web_contents = GetFirstShellWindowWebContents(); |
[email protected] | a4465720 | 2012-01-09 05:48:31 | [diff] [blame] | 208 | ASSERT_TRUE(web_contents); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 209 | WebKit::WebContextMenuData data; |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 210 | content::ContextMenuParams params(data); |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 211 | scoped_ptr<PlatformAppContextMenu> menu; |
| 212 | menu.reset(new PlatformAppContextMenu(web_contents, params)); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 213 | menu->Init(); |
[email protected] | ad687a7 | 2012-06-08 06:03:11 | [diff] [blame] | 214 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
[email protected] | 65992d5 | 2012-09-19 23:05:31 | [diff] [blame] | 215 | ASSERT_TRUE( |
| 216 | menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
[email protected] | 671c970 | 2012-09-27 07:51:19 | [diff] [blame] | 217 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); |
[email protected] | ad687a7 | 2012-06-08 06:03:11 | [diff] [blame] | 218 | ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 219 | ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 220 | } |
| 221 | |
[email protected] | edd7ed69 | 2012-02-08 02:50:03 | [diff] [blame] | 222 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) { |
[email protected] | d9d0276 | 2012-12-04 05:18:58 | [diff] [blame] | 223 | ExtensionTestMessageListener launched_listener("Launched", false); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 224 | LoadAndLaunchPlatformApp("context_menu"); |
| 225 | |
[email protected] | d9d0276 | 2012-12-04 05:18:58 | [diff] [blame] | 226 | // Wait for the extension to tell us it's initialized its context menus and |
| 227 | // launched a window. |
| 228 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 229 | |
[email protected] | 271d01c | 2012-08-27 23:48:05 | [diff] [blame] | 230 | // The context_menu app has two context menu items. These, along with a |
[email protected] | 0cfacd8 | 2012-02-09 01:55:33 | [diff] [blame] | 231 | // separator and the developer tools, is all that should be in the menu. |
[email protected] | d72d3a6 | 2012-05-10 03:45:08 | [diff] [blame] | 232 | WebContents* web_contents = GetFirstShellWindowWebContents(); |
[email protected] | a4465720 | 2012-01-09 05:48:31 | [diff] [blame] | 233 | ASSERT_TRUE(web_contents); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 234 | WebKit::WebContextMenuData data; |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 235 | content::ContextMenuParams params(data); |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 236 | scoped_ptr<PlatformAppContextMenu> menu; |
| 237 | menu.reset(new PlatformAppContextMenu(web_contents, params)); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 238 | menu->Init(); |
[email protected] | ad687a7 | 2012-06-08 06:03:11 | [diff] [blame] | 239 | ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
[email protected] | 271d01c | 2012-08-27 23:48:05 | [diff] [blame] | 240 | ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1)); |
[email protected] | ad687a7 | 2012-06-08 06:03:11 | [diff] [blame] | 241 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
[email protected] | 65992d5 | 2012-09-19 23:05:31 | [diff] [blame] | 242 | ASSERT_TRUE( |
| 243 | menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
[email protected] | 671c970 | 2012-09-27 07:51:19 | [diff] [blame] | 244 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); |
[email protected] | ad687a7 | 2012-06-08 06:03:11 | [diff] [blame] | 245 | ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 246 | ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
[email protected] | b3c019b | 2012-08-28 02:43:48 | [diff] [blame] | 247 | ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
| 248 | } |
| 249 | |
[email protected] | 65992d5 | 2012-09-19 23:05:31 | [diff] [blame] | 250 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, InstalledAppWithContextMenu) { |
[email protected] | d9d0276 | 2012-12-04 05:18:58 | [diff] [blame] | 251 | ExtensionTestMessageListener launched_listener("Launched", false); |
[email protected] | 65992d5 | 2012-09-19 23:05:31 | [diff] [blame] | 252 | InstallAndLaunchPlatformApp("context_menu"); |
| 253 | |
[email protected] | d9d0276 | 2012-12-04 05:18:58 | [diff] [blame] | 254 | // Wait for the extension to tell us it's initialized its context menus and |
| 255 | // launched a window. |
| 256 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 257 | |
[email protected] | 65992d5 | 2012-09-19 23:05:31 | [diff] [blame] | 258 | // The context_menu app has two context menu items. For an installed app |
| 259 | // these are all that should be in the menu. |
| 260 | WebContents* web_contents = GetFirstShellWindowWebContents(); |
| 261 | ASSERT_TRUE(web_contents); |
| 262 | WebKit::WebContextMenuData data; |
| 263 | content::ContextMenuParams params(data); |
| 264 | scoped_ptr<PlatformAppContextMenu> menu; |
| 265 | menu.reset(new PlatformAppContextMenu(web_contents, params)); |
| 266 | menu->Init(); |
| 267 | ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
| 268 | ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1)); |
| 269 | ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
| 270 | ASSERT_FALSE( |
| 271 | menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
[email protected] | 671c970 | 2012-09-27 07:51:19 | [diff] [blame] | 272 | ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); |
[email protected] | 65992d5 | 2012-09-19 23:05:31 | [diff] [blame] | 273 | ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 274 | ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
| 275 | ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
| 276 | } |
| 277 | |
[email protected] | b3c019b | 2012-08-28 02:43:48 | [diff] [blame] | 278 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuTextField) { |
[email protected] | d9d0276 | 2012-12-04 05:18:58 | [diff] [blame] | 279 | ExtensionTestMessageListener launched_listener("Launched", false); |
[email protected] | b3c019b | 2012-08-28 02:43:48 | [diff] [blame] | 280 | LoadAndLaunchPlatformApp("context_menu"); |
| 281 | |
[email protected] | d9d0276 | 2012-12-04 05:18:58 | [diff] [blame] | 282 | // Wait for the extension to tell us it's initialized its context menus and |
| 283 | // launched a window. |
| 284 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 285 | |
[email protected] | b3c019b | 2012-08-28 02:43:48 | [diff] [blame] | 286 | // The context_menu app has one context menu item. This, along with a |
| 287 | // separator and the developer tools, is all that should be in the menu. |
| 288 | WebContents* web_contents = GetFirstShellWindowWebContents(); |
| 289 | ASSERT_TRUE(web_contents); |
| 290 | WebKit::WebContextMenuData data; |
| 291 | content::ContextMenuParams params(data); |
| 292 | params.is_editable = true; |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 293 | scoped_ptr<PlatformAppContextMenu> menu; |
| 294 | menu.reset(new PlatformAppContextMenu(web_contents, params)); |
[email protected] | b3c019b | 2012-08-28 02:43:48 | [diff] [blame] | 295 | menu->Init(); |
| 296 | ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
| 297 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
[email protected] | 65992d5 | 2012-09-19 23:05:31 | [diff] [blame] | 298 | ASSERT_TRUE( |
| 299 | menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
[email protected] | 671c970 | 2012-09-27 07:51:19 | [diff] [blame] | 300 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); |
[email protected] | b3c019b | 2012-08-28 02:43:48 | [diff] [blame] | 301 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
| 302 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); |
| 303 | ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 304 | ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
| 305 | } |
| 306 | |
| 307 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuSelection) { |
[email protected] | d9d0276 | 2012-12-04 05:18:58 | [diff] [blame] | 308 | ExtensionTestMessageListener launched_listener("Launched", false); |
[email protected] | b3c019b | 2012-08-28 02:43:48 | [diff] [blame] | 309 | LoadAndLaunchPlatformApp("context_menu"); |
| 310 | |
[email protected] | d9d0276 | 2012-12-04 05:18:58 | [diff] [blame] | 311 | // Wait for the extension to tell us it's initialized its context menus and |
| 312 | // launched a window. |
| 313 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 314 | |
[email protected] | b3c019b | 2012-08-28 02:43:48 | [diff] [blame] | 315 | // The context_menu app has one context menu item. This, along with a |
| 316 | // separator and the developer tools, is all that should be in the menu. |
| 317 | WebContents* web_contents = GetFirstShellWindowWebContents(); |
| 318 | ASSERT_TRUE(web_contents); |
| 319 | WebKit::WebContextMenuData data; |
| 320 | content::ContextMenuParams params(data); |
| 321 | params.selection_text = ASCIIToUTF16("Hello World"); |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 322 | scoped_ptr<PlatformAppContextMenu> menu; |
| 323 | menu.reset(new PlatformAppContextMenu(web_contents, params)); |
[email protected] | b3c019b | 2012-08-28 02:43:48 | [diff] [blame] | 324 | menu->Init(); |
| 325 | ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
| 326 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
[email protected] | 65992d5 | 2012-09-19 23:05:31 | [diff] [blame] | 327 | ASSERT_TRUE( |
| 328 | menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
[email protected] | 671c970 | 2012-09-27 07:51:19 | [diff] [blame] | 329 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); |
[email protected] | b3c019b | 2012-08-28 02:43:48 | [diff] [blame] | 330 | ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
| 331 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); |
| 332 | ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 333 | ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 334 | } |
[email protected] | 5f000f27 | 2012-01-19 05:25:08 | [diff] [blame] | 335 | |
[email protected] | dc83c58 | 2012-08-17 02:18:14 | [diff] [blame] | 336 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuClicked) { |
[email protected] | d9d0276 | 2012-12-04 05:18:58 | [diff] [blame] | 337 | ExtensionTestMessageListener launched_listener("Launched", false); |
[email protected] | dc83c58 | 2012-08-17 02:18:14 | [diff] [blame] | 338 | LoadAndLaunchPlatformApp("context_menu_click"); |
| 339 | |
[email protected] | d9d0276 | 2012-12-04 05:18:58 | [diff] [blame] | 340 | // Wait for the extension to tell us it's initialized its context menus and |
| 341 | // launched a window. |
| 342 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 343 | |
[email protected] | dc83c58 | 2012-08-17 02:18:14 | [diff] [blame] | 344 | // Test that the menu item shows up |
| 345 | WebContents* web_contents = GetFirstShellWindowWebContents(); |
| 346 | ASSERT_TRUE(web_contents); |
| 347 | WebKit::WebContextMenuData data; |
| 348 | content::ContextMenuParams params(data); |
| 349 | params.page_url = GURL("http://foo.bar"); |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 350 | scoped_ptr<PlatformAppContextMenu> menu; |
| 351 | menu.reset(new PlatformAppContextMenu(web_contents, params)); |
[email protected] | dc83c58 | 2012-08-17 02:18:14 | [diff] [blame] | 352 | menu->Init(); |
| 353 | ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
| 354 | |
| 355 | // Execute the menu item |
| 356 | ExtensionTestMessageListener onclicked_listener("onClicked fired for id1", |
| 357 | false); |
| 358 | menu->ExecuteCommand(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST); |
| 359 | |
| 360 | ASSERT_TRUE(onclicked_listener.WaitUntilSatisfied()); |
| 361 | } |
| 362 | |
[email protected] | edd7ed69 | 2012-02-08 02:50:03 | [diff] [blame] | 363 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowNavigation) { |
[email protected] | 4d007b31 | 2012-10-17 03:00:48 | [diff] [blame] | 364 | TabsAddedNotificationObserver observer(2); |
| 365 | |
[email protected] | dc37b00 | 2012-04-23 23:02:26 | [diff] [blame] | 366 | ASSERT_TRUE(StartTestServer()); |
[email protected] | d9d0276 | 2012-12-04 05:18:58 | [diff] [blame] | 367 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/navigation")) << message_; |
[email protected] | 4d007b31 | 2012-10-17 03:00:48 | [diff] [blame] | 368 | |
| 369 | observer.Wait(); |
| 370 | ASSERT_EQ(2U, observer.tabs().size()); |
| 371 | EXPECT_EQ(std::string(chrome::kExtensionInvalidRequestURL), |
| 372 | observer.tabs()[0]->GetURL().spec()); |
| 373 | EXPECT_EQ("http://chromium.org/", |
| 374 | observer.tabs()[1]->GetURL().spec()); |
[email protected] | 5f000f27 | 2012-01-19 05:25:08 | [diff] [blame] | 375 | } |
[email protected] | 863e647 | 2012-01-24 19:33:58 | [diff] [blame] | 376 | |
[email protected] | 40eefd5 | 2012-10-04 22:54:22 | [diff] [blame] | 377 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Iframes) { |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 378 | ASSERT_TRUE(StartTestServer()); |
| 379 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/iframes")) << message_; |
| 380 | } |
| 381 | |
[email protected] | 2aac7ff | 2012-01-25 18:05:11 | [diff] [blame] | 382 | // Tests that localStorage and WebSQL are disabled for platform apps. |
[email protected] | edd7ed69 | 2012-02-08 02:50:03 | [diff] [blame] | 383 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowStorage) { |
[email protected] | 2aac7ff | 2012-01-25 18:05:11 | [diff] [blame] | 384 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/storage")) << message_; |
| 385 | } |
[email protected] | 6a5a2e5 | 2012-03-22 03:21:12 | [diff] [blame] | 386 | |
[email protected] | c0cecd1f | 2012-04-05 16:50:12 | [diff] [blame] | 387 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Restrictions) { |
| 388 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/restrictions")) << message_; |
| 389 | } |
| 390 | |
[email protected] | f0233ff | 2012-07-20 20:14:50 | [diff] [blame] | 391 | // Tests that platform apps can use the chrome.app.window.* API. |
[email protected] | 4ebed74dd | 2012-12-20 18:39:26 | [diff] [blame^] | 392 | // Flaky, http://crbug.com/167097 . |
| 393 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DISABLED_WindowsApi) { |
[email protected] | 6a5a2e5 | 2012-03-22 03:21:12 | [diff] [blame] | 394 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/windows_api")) << message_; |
| 395 | } |
[email protected] | 605fb810 | 2012-05-04 01:36:55 | [diff] [blame] | 396 | |
[email protected] | 1df2204 | 2012-08-30 19:48:55 | [diff] [blame] | 397 | // Tests that extensions can't use platform-app-only APIs. |
| 398 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, PlatformAppsOnly) { |
| 399 | ASSERT_TRUE(RunExtensionTestIgnoreManifestWarnings( |
| 400 | "platform_apps/apps_only")) << message_; |
| 401 | } |
| 402 | |
[email protected] | 605fb810 | 2012-05-04 01:36:55 | [diff] [blame] | 403 | // Tests that platform apps have isolated storage by default. |
| 404 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Isolation) { |
| 405 | ASSERT_TRUE(StartTestServer()); |
| 406 | |
| 407 | // Load a (non-app) page under the "localhost" origin that sets a cookie. |
| 408 | GURL set_cookie_url = test_server()->GetURL( |
| 409 | "files/extensions/platform_apps/isolation/set_cookie.html"); |
| 410 | GURL::Replacements replace_host; |
| 411 | std::string host_str("localhost"); // Must stay in scope with replace_host. |
| 412 | replace_host.SetHostStr(host_str); |
| 413 | set_cookie_url = set_cookie_url.ReplaceComponents(replace_host); |
| 414 | |
| 415 | ui_test_utils::NavigateToURLWithDisposition( |
| 416 | browser(), set_cookie_url, |
| 417 | CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 418 | |
| 419 | // Make sure the cookie is set. |
| 420 | int cookie_size; |
| 421 | std::string cookie_value; |
| 422 | automation_util::GetCookies( |
| 423 | set_cookie_url, |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 424 | chrome::GetWebContentsAt(browser(), 0), |
[email protected] | 605fb810 | 2012-05-04 01:36:55 | [diff] [blame] | 425 | &cookie_size, |
| 426 | &cookie_value); |
| 427 | ASSERT_EQ("testCookie=1", cookie_value); |
| 428 | |
| 429 | // Let the platform app request the same URL, and make sure that it doesn't |
| 430 | // see the cookie. |
| 431 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/isolation")) << message_; |
| 432 | } |
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 433 | |
| 434 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ExtensionWindowingApis) { |
| 435 | // Initially there should be just the one browser window visible to the |
| 436 | // extensions API. |
| 437 | const Extension* extension = LoadExtension( |
| 438 | test_data_dir_.AppendASCII("common/background_page")); |
| 439 | ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(extension)); |
| 440 | |
| 441 | // And no shell windows. |
| 442 | ASSERT_EQ(0U, GetShellWindowCount()); |
| 443 | |
| 444 | // Launch a platform app that shows a window. |
[email protected] | d9d0276 | 2012-12-04 05:18:58 | [diff] [blame] | 445 | ExtensionTestMessageListener launched_listener("Launched", false); |
[email protected] | ad5bb8a9 | 2012-06-07 03:55:58 | [diff] [blame] | 446 | LoadAndLaunchPlatformApp("minimal"); |
[email protected] | d9d0276 | 2012-12-04 05:18:58 | [diff] [blame] | 447 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 448 | ASSERT_EQ(1U, GetShellWindowCount()); |
| 449 | ShellWindowRegistry::ShellWindowSet shell_windows = |
| 450 | ShellWindowRegistry::Get(browser()->profile())->shell_windows(); |
| 451 | int shell_window_id = (*shell_windows.begin())->session_id().id(); |
| 452 | |
| 453 | // But it's not visible to the extensions API, it still thinks there's just |
| 454 | // one browser window. |
| 455 | ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(extension)); |
| 456 | // It can't look it up by ID either |
| 457 | ASSERT_FALSE(RunGetWindowFunctionForExtension(shell_window_id, extension)); |
| 458 | |
| 459 | // The app can also only see one window (its own). |
[email protected] | ad5bb8a9 | 2012-06-07 03:55:58 | [diff] [blame] | 460 | // TODO(jeremya): add an extension function to get a shell window by ID, and |
| 461 | // to get a list of all the shell windows, so we can test this. |
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 462 | |
| 463 | // Launch another platform app that also shows a window. |
[email protected] | d9d0276 | 2012-12-04 05:18:58 | [diff] [blame] | 464 | ExtensionTestMessageListener launched_listener2("Launched", false); |
[email protected] | ad5bb8a9 | 2012-06-07 03:55:58 | [diff] [blame] | 465 | LoadAndLaunchPlatformApp("context_menu"); |
[email protected] | d9d0276 | 2012-12-04 05:18:58 | [diff] [blame] | 466 | ASSERT_TRUE(launched_listener2.WaitUntilSatisfied()); |
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 467 | |
| 468 | // There are two total shell windows, but each app can only see its own. |
| 469 | ASSERT_EQ(2U, GetShellWindowCount()); |
[email protected] | ad5bb8a9 | 2012-06-07 03:55:58 | [diff] [blame] | 470 | // TODO(jeremya): as above, this requires more extension functions. |
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 471 | } |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 472 | |
[email protected] | a2ece52 | 2012-10-16 03:41:10 | [diff] [blame] | 473 | // ChromeOS does not support passing arguments on the command line, so the tests |
| 474 | // that rely on this functionality are disabled. |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 475 | #if !defined(OS_CHROMEOS) |
| 476 | // Tests that command line parameters get passed through to platform apps |
| 477 | // via launchData correctly when launching with a file. |
[email protected] | 7d0cbb6 | 2012-11-22 04:41:07 | [diff] [blame] | 478 | // TODO(benwells/jeremya): tests need a way to specify a handler ID. |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 479 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithFile) { |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 480 | SetCommandLineArg(kTestFilePath); |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 481 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_file")) |
| 482 | << message_; |
| 483 | } |
| 484 | |
[email protected] | a5a0be0 | 2012-07-18 05:51:54 | [diff] [blame] | 485 | // Tests that relative paths can be passed through to the platform app. |
| 486 | // This test doesn't use the normal test infrastructure as it needs to open |
| 487 | // the application differently to all other platform app tests, by setting |
| 488 | // the application_launch::LaunchParams.current_directory field. |
| 489 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithRelativeFile) { |
| 490 | // Setup the command line |
| 491 | ClearCommandLineArgs(); |
| 492 | CommandLine* command_line = CommandLine::ForCurrentProcess(); |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 493 | FilePath relative_test_doc = FilePath::FromUTF8Unsafe(kTestFilePath); |
[email protected] | a5a0be0 | 2012-07-18 05:51:54 | [diff] [blame] | 494 | relative_test_doc = relative_test_doc.NormalizePathSeparators(); |
| 495 | command_line->AppendArgPath(relative_test_doc); |
| 496 | |
| 497 | // Load the extension |
| 498 | ResultCatcher catcher; |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 499 | const Extension* extension = LoadExtension( |
[email protected] | a5a0be0 | 2012-07-18 05:51:54 | [diff] [blame] | 500 | test_data_dir_.AppendASCII("platform_apps/launch_file")); |
| 501 | ASSERT_TRUE(extension); |
| 502 | |
| 503 | // Run the test |
| 504 | application_launch::LaunchParams params(browser()->profile(), extension, |
| 505 | extension_misc::LAUNCH_NONE, |
| 506 | NEW_WINDOW); |
| 507 | params.command_line = CommandLine::ForCurrentProcess(); |
| 508 | params.current_directory = test_data_dir_; |
| 509 | application_launch::OpenApplication(params); |
| 510 | |
| 511 | if (!catcher.GetNextResult()) { |
| 512 | message_ = catcher.message(); |
| 513 | ASSERT_TRUE(0); |
| 514 | } |
| 515 | } |
| 516 | |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 517 | // Tests that no launch data is sent through if the file is of the wrong MIME |
| 518 | // type. |
| 519 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithWrongType) { |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 520 | SetCommandLineArg(kTestFilePath); |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 521 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_type")) |
| 522 | << message_; |
| 523 | } |
| 524 | |
| 525 | // Tests that no launch data is sent through if the platform app does not |
| 526 | // provide an intent. |
| 527 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithNoIntent) { |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 528 | SetCommandLineArg(kTestFilePath); |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 529 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_no_intent")) |
| 530 | << message_; |
| 531 | } |
| 532 | |
| 533 | // Tests that no launch data is sent through if the file MIME type cannot |
| 534 | // be read. |
| 535 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchNoType) { |
| 536 | SetCommandLineArg("platform_apps/launch_files/test.unknownextension"); |
| 537 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid")) |
| 538 | << message_; |
| 539 | } |
| 540 | |
| 541 | // Tests that no launch data is sent through if the file does not exist. |
| 542 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchNoFile) { |
| 543 | SetCommandLineArg("platform_apps/launch_files/doesnotexist.txt"); |
| 544 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid")) |
| 545 | << message_; |
| 546 | } |
| 547 | |
| 548 | // Tests that no launch data is sent through if the argument is a directory. |
| 549 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithDirectory) { |
| 550 | SetCommandLineArg("platform_apps/launch_files"); |
| 551 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid")) |
| 552 | << message_; |
| 553 | } |
| 554 | |
| 555 | // Tests that no launch data is sent through if there are no arguments passed |
| 556 | // on the command line |
| 557 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithNothing) { |
| 558 | ClearCommandLineArgs(); |
| 559 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_nothing")) |
| 560 | << message_; |
| 561 | } |
[email protected] | ffc7b4d | 2012-06-08 00:05:32 | [diff] [blame] | 562 | |
| 563 | // Test that platform apps can use the chrome.fileSystem.getDisplayPath |
| 564 | // function to get the native file system path of a file they are launched with. |
| 565 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, GetDisplayPath) { |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 566 | SetCommandLineArg(kTestFilePath); |
[email protected] | ffc7b4d | 2012-06-08 00:05:32 | [diff] [blame] | 567 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/get_display_path")) |
| 568 | << message_; |
| 569 | } |
| 570 | |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 571 | #endif // defined(OS_CHROMEOS) |
[email protected] | 5b1a04b4 | 2012-06-15 00:41:44 | [diff] [blame] | 572 | |
| 573 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OpenLink) { |
| 574 | ASSERT_TRUE(StartTestServer()); |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 575 | content::WindowedNotificationObserver observer( |
[email protected] | 5b1a04b4 | 2012-06-15 00:41:44 | [diff] [blame] | 576 | chrome::NOTIFICATION_TAB_ADDED, |
| 577 | content::Source<content::WebContentsDelegate>(browser())); |
| 578 | LoadAndLaunchPlatformApp("open_link"); |
| 579 | observer.Wait(); |
| 580 | ASSERT_EQ(2, browser()->tab_count()); |
| 581 | } |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 582 | |
[email protected] | 3a8e6194 | 2012-08-23 01:46:45 | [diff] [blame] | 583 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MutationEventsDisabled) { |
| 584 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/mutation_events")) << message_; |
| 585 | } |
| 586 | |
[email protected] | 939532d0 | 2012-08-31 23:37:33 | [diff] [blame] | 587 | // Test that windows created with an id will remember and restore their |
| 588 | // geometry when opening new windows. |
[email protected] | 6908083 | 2012-11-20 20:31:47 | [diff] [blame] | 589 | // Originally disabled due to flakiness (see http://crbug.com/155459) |
| 590 | // but now because a regression breaks the test (http://crbug.com/160343). |
[email protected] | 19a0f75d | 2012-11-29 02:28:31 | [diff] [blame] | 591 | #if defined(TOOLKIT_GTK) |
[email protected] | 329c4e9 | 2012-11-09 06:04:24 | [diff] [blame] | 592 | #define MAYBE_ShellWindowRestorePosition DISABLED_ShellWindowRestorePosition |
[email protected] | 19a0f75d | 2012-11-29 02:28:31 | [diff] [blame] | 593 | #else |
| 594 | #define MAYBE_ShellWindowRestorePosition ShellWindowRestorePosition |
| 595 | #endif |
[email protected] | 9d53c1c | 2012-10-18 00:49:54 | [diff] [blame] | 596 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, |
[email protected] | 329c4e9 | 2012-11-09 06:04:24 | [diff] [blame] | 597 | MAYBE_ShellWindowRestorePosition) { |
[email protected] | 939532d0 | 2012-08-31 23:37:33 | [diff] [blame] | 598 | ExtensionTestMessageListener page2_listener("WaitForPage2", true); |
[email protected] | 939532d0 | 2012-08-31 23:37:33 | [diff] [blame] | 599 | ExtensionTestMessageListener done_listener("Done1", false); |
| 600 | ExtensionTestMessageListener done2_listener("Done2", false); |
[email protected] | 939532d0 | 2012-08-31 23:37:33 | [diff] [blame] | 601 | |
| 602 | ASSERT_TRUE(LoadAndLaunchPlatformApp("geometry")); |
| 603 | |
| 604 | // Wait for the app to be launched (although this is mostly to have a |
| 605 | // message to reply to to let the script know it should create its second |
| 606 | // window. |
| 607 | ASSERT_TRUE(page2_listener.WaitUntilSatisfied()); |
| 608 | |
| 609 | // Wait for the first window to verify its geometry was correctly set |
| 610 | // from the default* attributes passed to the create function. |
| 611 | ASSERT_TRUE(done_listener.WaitUntilSatisfied()); |
| 612 | |
| 613 | // Programatically move and resize the window. |
| 614 | ShellWindow* window = GetFirstShellWindow(); |
| 615 | ASSERT_TRUE(window); |
| 616 | gfx::Rect bounds(137, 143, 203, 187); |
| 617 | window->GetBaseWindow()->SetBounds(bounds); |
| 618 | |
| 619 | #if defined(TOOLKIT_GTK) |
| 620 | // TODO(mek): On GTK we have to wait for a roundtrip to the X server before |
| 621 | // a resize actually happens: |
| 622 | // "if you call gtk_window_resize() then immediately call |
| 623 | // gtk_window_get_size(), the size won't have taken effect yet. After the |
| 624 | // window manager processes the resize request, GTK+ receives notification |
| 625 | // that the size has changed via a configure event, and the size of the |
| 626 | // window gets updated." |
| 627 | // Because of this we have to wait for an unknown time for the resize to |
| 628 | // actually take effect. So wait some time or until the resize got |
| 629 | // handled. |
| 630 | base::TimeTicks end_time = base::TimeTicks::Now() + |
| 631 | TestTimeouts::action_timeout(); |
| 632 | while (base::TimeTicks::Now() < end_time && |
| 633 | bounds != window->GetBaseWindow()->GetBounds()) { |
| 634 | content::RunAllPendingInMessageLoop(); |
| 635 | } |
| 636 | |
| 637 | // In the GTK ShellWindow implementation there also is a delay between |
[email protected] | 99d8f09 | 2012-11-28 04:42:43 | [diff] [blame] | 638 | // getting the correct bounds and it calling SaveWindowPosition, so call a |
[email protected] | 939532d0 | 2012-08-31 23:37:33 | [diff] [blame] | 639 | // method explicitly to make sure the value was stored. |
[email protected] | 99d8f09 | 2012-11-28 04:42:43 | [diff] [blame] | 640 | window->OnNativeWindowChanged(); |
[email protected] | 939532d0 | 2012-08-31 23:37:33 | [diff] [blame] | 641 | #endif // defined(TOOLKIT_GTK) |
| 642 | |
| 643 | // Make sure the window was properly moved&resized. |
| 644 | ASSERT_EQ(bounds, window->GetBaseWindow()->GetBounds()); |
| 645 | |
| 646 | // Tell javascript to open a second window. |
| 647 | page2_listener.Reply("continue"); |
| 648 | |
| 649 | // Wait for javascript to verify that the second window got the updated |
| 650 | // coordinates, ignoring the default coordinates passed to the create method. |
| 651 | ASSERT_TRUE(done2_listener.WaitUntilSatisfied()); |
[email protected] | 939532d0 | 2012-08-31 23:37:33 | [diff] [blame] | 652 | } |
[email protected] | 939532d0 | 2012-08-31 23:37:33 | [diff] [blame] | 653 | |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 654 | // Tests that a running app is recorded in the preferences as such. |
| 655 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, RunningAppsAreRecorded) { |
| 656 | content::WindowedNotificationObserver extension_suspended( |
| 657 | chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 658 | content::NotificationService::AllSources()); |
| 659 | |
| 660 | const Extension* extension = LoadExtension( |
| 661 | test_data_dir_.AppendASCII("platform_apps/restart_test")); |
| 662 | ASSERT_TRUE(extension); |
| 663 | ExtensionService* extension_service = |
| 664 | ExtensionSystem::Get(browser()->profile())->extension_service(); |
| 665 | ExtensionPrefs* extension_prefs = extension_service->extension_prefs(); |
| 666 | |
| 667 | // App is running. |
| 668 | ASSERT_TRUE(extension_prefs->IsExtensionRunning(extension->id())); |
| 669 | |
| 670 | // Wait for the extension to get suspended. |
| 671 | extension_suspended.Wait(); |
| 672 | |
| 673 | // App isn't running because it got suspended. |
| 674 | ASSERT_FALSE(extension_prefs->IsExtensionRunning(extension->id())); |
| 675 | |
| 676 | // Pretend that the app is supposed to be running. |
| 677 | extension_prefs->SetExtensionRunning(extension->id(), true); |
| 678 | |
| 679 | ExtensionTestMessageListener restart_listener("onRestarted", false); |
[email protected] | 11945462 | 2012-10-18 09:48:32 | [diff] [blame] | 680 | AppRestoreServiceFactory::GetForProfile(browser()->profile())-> |
| 681 | HandleStartup(true); |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 682 | restart_listener.WaitUntilSatisfied(); |
| 683 | } |
| 684 | |
[email protected] | 545b531 | 2012-11-07 12:18:21 | [diff] [blame] | 685 | namespace { |
| 686 | |
| 687 | class PlatformAppDevToolsBrowserTest : public PlatformAppBrowserTest { |
| 688 | protected: |
| 689 | enum TestFlags { |
| 690 | RELAUNCH = 0x1, |
| 691 | HAS_ID = 0x2, |
| 692 | }; |
| 693 | // Runs a test inside a harness that opens DevTools on a shell window. |
| 694 | void RunTestWithDevTools(const char* name, int test_flags); |
| 695 | }; |
| 696 | |
| 697 | void PlatformAppDevToolsBrowserTest::RunTestWithDevTools( |
| 698 | const char* name, int test_flags) { |
[email protected] | e85cc64 | 2012-10-24 06:14:23 | [diff] [blame] | 699 | using content::DevToolsAgentHostRegistry; |
[email protected] | d9d0276 | 2012-12-04 05:18:58 | [diff] [blame] | 700 | ExtensionTestMessageListener launched_listener("Launched", false); |
[email protected] | 545b531 | 2012-11-07 12:18:21 | [diff] [blame] | 701 | const Extension* extension = LoadAndLaunchPlatformApp(name); |
[email protected] | e85cc64 | 2012-10-24 06:14:23 | [diff] [blame] | 702 | ASSERT_TRUE(extension); |
[email protected] | d9d0276 | 2012-12-04 05:18:58 | [diff] [blame] | 703 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
[email protected] | e85cc64 | 2012-10-24 06:14:23 | [diff] [blame] | 704 | ShellWindow* window = GetFirstShellWindow(); |
| 705 | ASSERT_TRUE(window); |
[email protected] | 545b531 | 2012-11-07 12:18:21 | [diff] [blame] | 706 | ASSERT_EQ(window->window_key().empty(), (test_flags & HAS_ID) == 0); |
[email protected] | e85cc64 | 2012-10-24 06:14:23 | [diff] [blame] | 707 | content::RenderViewHost* rvh = window->web_contents()->GetRenderViewHost(); |
| 708 | ASSERT_TRUE(rvh); |
| 709 | |
| 710 | // Ensure no DevTools open for the ShellWindow, then open one. |
| 711 | ASSERT_FALSE(DevToolsAgentHostRegistry::HasDevToolsAgentHost(rvh)); |
| 712 | DevToolsWindow* devtools_window = DevToolsWindow::OpenDevToolsWindow(rvh); |
| 713 | content::WindowedNotificationObserver loaded_observer( |
| 714 | content::NOTIFICATION_LOAD_STOP, |
| 715 | content::Source<content::NavigationController>( |
[email protected] | ee2202a | 2012-12-11 01:07:20 | [diff] [blame] | 716 | &devtools_window->web_contents()->GetController())); |
[email protected] | e85cc64 | 2012-10-24 06:14:23 | [diff] [blame] | 717 | loaded_observer.Wait(); |
| 718 | ASSERT_TRUE(DevToolsAgentHostRegistry::HasDevToolsAgentHost(rvh)); |
| 719 | |
[email protected] | 545b531 | 2012-11-07 12:18:21 | [diff] [blame] | 720 | if (test_flags & RELAUNCH) { |
| 721 | // Close the ShellWindow, and ensure it is gone. |
| 722 | CloseShellWindow(window); |
| 723 | ASSERT_FALSE(GetFirstShellWindow()); |
[email protected] | e85cc64 | 2012-10-24 06:14:23 | [diff] [blame] | 724 | |
[email protected] | 545b531 | 2012-11-07 12:18:21 | [diff] [blame] | 725 | // Relaunch the app and get a new ShellWindow. |
| 726 | content::WindowedNotificationObserver app_loaded_observer( |
| 727 | content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 728 | content::NotificationService::AllSources()); |
| 729 | application_launch::OpenApplication(application_launch::LaunchParams( |
| 730 | browser()->profile(), extension, extension_misc::LAUNCH_NONE, |
| 731 | NEW_WINDOW)); |
| 732 | app_loaded_observer.Wait(); |
| 733 | window = GetFirstShellWindow(); |
| 734 | ASSERT_TRUE(window); |
[email protected] | e85cc64 | 2012-10-24 06:14:23 | [diff] [blame] | 735 | |
[email protected] | 545b531 | 2012-11-07 12:18:21 | [diff] [blame] | 736 | // DevTools should have reopened with the relaunch. |
| 737 | rvh = window->web_contents()->GetRenderViewHost(); |
| 738 | ASSERT_TRUE(rvh); |
| 739 | ASSERT_TRUE(DevToolsAgentHostRegistry::HasDevToolsAgentHost(rvh)); |
| 740 | } |
[email protected] | e85cc64 | 2012-10-24 06:14:23 | [diff] [blame] | 741 | } |
| 742 | |
[email protected] | 545b531 | 2012-11-07 12:18:21 | [diff] [blame] | 743 | } // namespace |
| 744 | |
| 745 | IN_PROC_BROWSER_TEST_F(PlatformAppDevToolsBrowserTest, ReOpenedWithID) { |
| 746 | RunTestWithDevTools("minimal_id", RELAUNCH | HAS_ID); |
| 747 | } |
| 748 | |
| 749 | IN_PROC_BROWSER_TEST_F(PlatformAppDevToolsBrowserTest, ReOpenedWithURL) { |
| 750 | RunTestWithDevTools("minimal", RELAUNCH); |
| 751 | } |
| 752 | |
[email protected] | ddf4216 | 2012-11-06 21:14:55 | [diff] [blame] | 753 | // Test that showing a permission request as a constrained window works and is |
| 754 | // correctly parented. |
| 755 | #if defined(OS_MACOSX) |
[email protected] | cd20266 | 2012-11-07 19:11:41 | [diff] [blame] | 756 | #define MAYBE_ConstrainedWindowRequest DISABLED_ConstrainedWindowRequest |
[email protected] | ddf4216 | 2012-11-06 21:14:55 | [diff] [blame] | 757 | #else |
| 758 | // TODO(sail): Enable this on other platforms once http://crbug.com/95455 is |
| 759 | // fixed. |
| 760 | #define MAYBE_ConstrainedWindowRequest DISABLED_ConstrainedWindowRequest |
| 761 | #endif |
| 762 | |
| 763 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_ConstrainedWindowRequest) { |
| 764 | RequestPermissionsFunction::SetIgnoreUserGestureForTests(true); |
| 765 | const Extension* extension = |
| 766 | LoadAndLaunchPlatformApp("optional_permission_request"); |
| 767 | ASSERT_TRUE(extension) << "Failed to load extension."; |
| 768 | |
| 769 | WebContents* web_contents = GetFirstShellWindowWebContents(); |
| 770 | ASSERT_TRUE(web_contents); |
| 771 | |
| 772 | // Verify that the shell window has a constrained window attached. |
| 773 | ConstrainedWindowTabHelper* constrained_window_tab_helper = |
| 774 | ConstrainedWindowTabHelper::FromWebContents(web_contents); |
| 775 | EXPECT_EQ(1u, constrained_window_tab_helper->constrained_window_count()); |
| 776 | |
| 777 | // Close the constrained window and wait for the reply to the permission |
| 778 | // request. |
| 779 | ExtensionTestMessageListener listener("PermissionRequestDone", false); |
| 780 | constrained_window_tab_helper->CloseConstrainedWindows(); |
| 781 | ASSERT_TRUE(listener.WaitUntilSatisfied()); |
[email protected] | ddf4216 | 2012-11-06 21:14:55 | [diff] [blame] | 782 | } |
| 783 | |
[email protected] | bf1be4e | 2012-11-07 20:32:27 | [diff] [blame] | 784 | // Tests that an app calling chrome.runtime.reload will reload the app and |
| 785 | // relaunch it if it was running. |
| 786 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ReloadRelaunches) { |
| 787 | ExtensionTestMessageListener launched_listener("Launched", true); |
[email protected] | d9d0276 | 2012-12-04 05:18:58 | [diff] [blame] | 788 | const Extension* extension = LoadAndLaunchPlatformApp("reload"); |
[email protected] | bf1be4e | 2012-11-07 20:32:27 | [diff] [blame] | 789 | ASSERT_TRUE(extension); |
[email protected] | bf1be4e | 2012-11-07 20:32:27 | [diff] [blame] | 790 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 791 | ASSERT_TRUE(GetFirstShellWindow()); |
| 792 | |
| 793 | // Now tell the app to reload itself |
| 794 | ExtensionTestMessageListener launched_listener2("Launched", false); |
| 795 | launched_listener.Reply("reload"); |
| 796 | ASSERT_TRUE(launched_listener2.WaitUntilSatisfied()); |
| 797 | ASSERT_TRUE(GetFirstShellWindow()); |
[email protected] | bf1be4e | 2012-11-07 20:32:27 | [diff] [blame] | 798 | } |
| 799 | |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 800 | namespace { |
| 801 | |
| 802 | // Simple observer to check for NOTIFICATION_EXTENSION_INSTALLED events to |
| 803 | // ensure installation does or does not occur in certain scenarios. |
| 804 | class CheckExtensionInstalledObserver : public content::NotificationObserver { |
| 805 | public: |
| 806 | CheckExtensionInstalledObserver() : seen_(false) { |
| 807 | registrar_.Add(this, |
| 808 | chrome::NOTIFICATION_EXTENSION_INSTALLED, |
| 809 | content::NotificationService::AllSources()); |
| 810 | } |
| 811 | |
| 812 | bool seen() const { |
| 813 | return seen_; |
| 814 | }; |
| 815 | |
| 816 | // NotificationObserver: |
| 817 | virtual void Observe(int type, |
| 818 | const content::NotificationSource& source, |
| 819 | const content::NotificationDetails& details) OVERRIDE { |
| 820 | EXPECT_FALSE(seen_); |
| 821 | seen_ = true; |
| 822 | } |
| 823 | |
| 824 | private: |
| 825 | bool seen_; |
| 826 | content::NotificationRegistrar registrar_; |
| 827 | }; |
| 828 | |
| 829 | } // namespace |
| 830 | |
| 831 | // Component App Test 1 of 3: ensure that the initial load of a component |
| 832 | // extension utilizing a background page (e.g. a v2 platform app) has its |
| 833 | // background page run and is launchable. Waits for the Launched response from |
| 834 | // the script resource in the opened shell window. |
| 835 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, |
| 836 | PRE_PRE_ComponentAppBackgroundPage) { |
| 837 | CheckExtensionInstalledObserver should_install; |
| 838 | |
| 839 | // Ensure that we wait until the background page is run (to register the |
| 840 | // OnLaunched listener) before trying to open the application. This is similar |
| 841 | // to LoadAndLaunchPlatformApp, but we want to load as a component extension. |
| 842 | content::WindowedNotificationObserver app_loaded_observer( |
| 843 | content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 844 | content::NotificationService::AllSources()); |
| 845 | |
| 846 | const Extension* extension = LoadExtensionAsComponent( |
| 847 | test_data_dir_.AppendASCII("platform_apps").AppendASCII("component")); |
| 848 | ASSERT_TRUE(extension); |
| 849 | |
| 850 | app_loaded_observer.Wait(); |
| 851 | ASSERT_TRUE(should_install.seen()); |
| 852 | |
| 853 | ExtensionTestMessageListener launched_listener("Launched", false); |
| 854 | application_launch::OpenApplication(application_launch::LaunchParams( |
| 855 | browser()->profile(), extension, extension_misc::LAUNCH_NONE, |
| 856 | NEW_WINDOW)); |
| 857 | |
| 858 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 859 | } |
| 860 | |
| 861 | // Component App Test 2 of 3: ensure an installed component app can be launched |
| 862 | // on a subsequent browser start, without requiring any install/upgrade logic |
| 863 | // to be run, then perform setup for step 3. |
| 864 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, |
| 865 | PRE_ComponentAppBackgroundPage) { |
| 866 | |
| 867 | // Since the component app is now installed, re-adding it in the same profile |
| 868 | // should not cause it to be re-installed. Instead, we wait for the OnLaunched |
| 869 | // in a different observer (which would timeout if not the app was not |
| 870 | // previously installed properly) and then check this observer to make sure it |
| 871 | // never saw the NOTIFICATION_EXTENSION_INSTALLED event. |
| 872 | CheckExtensionInstalledObserver should_not_install; |
| 873 | const Extension* extension = LoadExtensionAsComponent( |
| 874 | test_data_dir_.AppendASCII("platform_apps").AppendASCII("component")); |
| 875 | ASSERT_TRUE(extension); |
| 876 | |
| 877 | ExtensionTestMessageListener launched_listener("Launched", false); |
| 878 | application_launch::OpenApplication(application_launch::LaunchParams( |
| 879 | browser()->profile(), extension, extension_misc::LAUNCH_NONE, |
| 880 | NEW_WINDOW)); |
| 881 | |
| 882 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 883 | ASSERT_FALSE(should_not_install.seen()); |
| 884 | |
| 885 | // Simulate a "downgrade" from version 2 in the test manifest.json to 1. |
| 886 | ExtensionPrefs* extension_prefs = |
| 887 | extensions::ExtensionSystem::Get(browser()->profile())-> |
| 888 | extension_service()->extension_prefs(); |
| 889 | |
| 890 | // Clear the registered events to ensure they are updated. |
| 891 | extension_prefs->SetRegisteredEvents(extension->id(), |
| 892 | std::set<std::string>()); |
| 893 | |
| 894 | const base::StringValue old_version("1"); |
| 895 | std::string pref_path("extensions.settings."); |
| 896 | pref_path += extension->id(); |
| 897 | pref_path += ".manifest.version"; |
| 898 | extension_prefs->pref_service()->RegisterStringPref( |
| 899 | pref_path.c_str(), std::string(), PrefServiceBase::UNSYNCABLE_PREF); |
| 900 | extension_prefs->pref_service()->Set(pref_path.c_str(), old_version); |
| 901 | } |
| 902 | |
| 903 | // Component App Test 3 of 3: simulate a component extension upgrade that |
| 904 | // re-adds the OnLaunched event, and allows the app to be launched. |
| 905 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ComponentAppBackgroundPage) { |
| 906 | CheckExtensionInstalledObserver should_install; |
| 907 | // Since we are forcing an upgrade, we need to wait for the load again. |
| 908 | content::WindowedNotificationObserver app_loaded_observer( |
| 909 | content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 910 | content::NotificationService::AllSources()); |
| 911 | |
| 912 | const Extension* extension = LoadExtensionAsComponent( |
| 913 | test_data_dir_.AppendASCII("platform_apps").AppendASCII("component")); |
| 914 | ASSERT_TRUE(extension); |
| 915 | app_loaded_observer.Wait(); |
| 916 | ASSERT_TRUE(should_install.seen()); |
| 917 | |
| 918 | ExtensionTestMessageListener launched_listener("Launched", false); |
| 919 | application_launch::OpenApplication(application_launch::LaunchParams( |
| 920 | browser()->profile(), extension, extension_misc::LAUNCH_NONE, |
| 921 | NEW_WINDOW)); |
| 922 | |
| 923 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 924 | } |
| 925 | |
[email protected] | 481a87e6 | 2012-12-19 23:00:27 | [diff] [blame] | 926 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Messaging) { |
| 927 | ExtensionApiTest::ResultCatcher result_catcher; |
| 928 | LoadAndLaunchPlatformApp("messaging/app2"); |
| 929 | LoadAndLaunchPlatformApp("messaging/app1"); |
| 930 | EXPECT_TRUE(result_catcher.GetNextResult()); |
| 931 | } |
| 932 | |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 933 | } // namespace extensions |