[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] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 11 | #include "chrome/browser/tab_contents/render_view_context_menu.h" |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 12 | #include "chrome/browser/extensions/app_restore_service_factory.h" |
| 13 | #include "chrome/browser/extensions/app_restore_service.h" |
[email protected] | a6db612 | 2012-09-03 06:00:23 | [diff] [blame] | 14 | #include "chrome/browser/extensions/extension_browsertest.h" |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 15 | #include "chrome/browser/extensions/extension_prefs.h" |
| 16 | #include "chrome/browser/extensions/extension_service.h" |
| 17 | #include "chrome/browser/extensions/extension_system.h" |
[email protected] | 25977110 | 2012-05-31 16:52:20 | [diff] [blame] | 18 | #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 19 | #include "chrome/browser/extensions/platform_app_browsertest_util.h" |
[email protected] | a6db612 | 2012-09-03 06:00:23 | [diff] [blame] | 20 | #include "chrome/browser/extensions/platform_app_launcher.h" |
[email protected] | 25977110 | 2012-05-31 16:52:20 | [diff] [blame] | 21 | #include "chrome/browser/extensions/shell_window_registry.h" |
[email protected] | cfc6cca | 2011-12-01 02:30:06 | [diff] [blame] | 22 | #include "chrome/browser/ui/browser.h" |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 23 | #include "chrome/browser/ui/browser_tabstrip.h" |
[email protected] | a5a0be0 | 2012-07-18 05:51:54 | [diff] [blame] | 24 | #include "chrome/browser/ui/extensions/application_launch.h" |
[email protected] | d72d3a6 | 2012-05-10 03:45:08 | [diff] [blame] | 25 | #include "chrome/browser/ui/extensions/shell_window.h" |
[email protected] | 5b1a04b4 | 2012-06-15 00:41:44 | [diff] [blame] | 26 | #include "chrome/common/chrome_notification_types.h" |
[email protected] | 4d007b31 | 2012-10-17 03:00:48 | [diff] [blame^] | 27 | #include "chrome/common/url_constants.h" |
[email protected] | cfc6cca | 2011-12-01 02:30:06 | [diff] [blame] | 28 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | fb29e6cf | 2012-07-12 21:27:20 | [diff] [blame] | 29 | #include "content/public/browser/render_process_host.h" |
[email protected] | a6db612 | 2012-09-03 06:00:23 | [diff] [blame] | 30 | #include "content/public/browser/web_intents_dispatcher.h" |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 31 | #include "content/public/test/test_utils.h" |
[email protected] | a6db612 | 2012-09-03 06:00:23 | [diff] [blame] | 32 | #include "googleurl/src/gurl.h" |
| 33 | #include "webkit/glue/web_intent_data.h" |
[email protected] | cfc6cca | 2011-12-01 02:30:06 | [diff] [blame] | 34 | |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 35 | using content::WebContents; |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 36 | |
| 37 | namespace extensions { |
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 38 | |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 39 | namespace { |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 40 | |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 41 | // Non-abstract RenderViewContextMenu class. |
| 42 | class PlatformAppContextMenu : public RenderViewContextMenu { |
| 43 | public: |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 44 | PlatformAppContextMenu(WebContents* web_contents, |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 45 | const content::ContextMenuParams& params) |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 46 | : RenderViewContextMenu(web_contents, params) {} |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 47 | |
[email protected] | ad687a7 | 2012-06-08 06:03:11 | [diff] [blame] | 48 | bool HasCommandWithId(int command_id) { |
| 49 | return menu_model_.GetIndexOfCommandId(command_id) != -1; |
| 50 | } |
| 51 | |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 52 | protected: |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 53 | // RenderViewContextMenu implementation. |
| 54 | virtual bool GetAcceleratorForCommandId( |
| 55 | int command_id, |
| 56 | ui::Accelerator* accelerator) OVERRIDE { |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 57 | return false; |
| 58 | } |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 59 | virtual void PlatformInit() OVERRIDE {} |
| 60 | virtual void PlatformCancel() OVERRIDE {} |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 61 | }; |
| 62 | |
[email protected] | a6db612 | 2012-09-03 06:00:23 | [diff] [blame] | 63 | // State holder for the LaunchReply test. This provides an WebIntentsDispatcher |
| 64 | // that will, when used to launch a Web Intent, will return its reply via this |
| 65 | // class. The result may then be waited on via WaitUntilReply(). |
| 66 | class LaunchReplyHandler { |
| 67 | public: |
| 68 | explicit LaunchReplyHandler(webkit_glue::WebIntentData& data) |
| 69 | : data_(data), |
| 70 | replied_(false), |
| 71 | weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 72 | intents_dispatcher_ = content::WebIntentsDispatcher::Create(data); |
| 73 | intents_dispatcher_->RegisterReplyNotification(base::Bind( |
| 74 | &LaunchReplyHandler::OnReply, weak_ptr_factory_.GetWeakPtr())); |
| 75 | } |
| 76 | |
| 77 | content::WebIntentsDispatcher* intents_dispatcher() { |
| 78 | return intents_dispatcher_; |
| 79 | } |
| 80 | |
| 81 | // Waits until a reply to this Web Intent is provided via the |
| 82 | // WebIntentsDispatcher. |
| 83 | bool WaitUntilReply() { |
| 84 | if (replied_) |
| 85 | return true; |
| 86 | waiting_ = true; |
| 87 | content::RunMessageLoop(); |
| 88 | waiting_ = false; |
| 89 | return replied_; |
| 90 | } |
| 91 | |
| 92 | private: |
| 93 | void OnReply(webkit_glue::WebIntentReplyType reply) { |
| 94 | // Note that the ReplyNotification registered on WebIntentsDispatcher does |
| 95 | // not include the result data: this is reserved for the source page (which |
| 96 | // we don't care about). |
| 97 | replied_ = true; |
| 98 | if (waiting_) |
| 99 | MessageLoopForUI::current()->Quit(); |
| 100 | } |
| 101 | |
| 102 | webkit_glue::WebIntentData data_; |
| 103 | bool replied_; |
| 104 | bool waiting_; |
| 105 | content::WebIntentsDispatcher* intents_dispatcher_; |
| 106 | base::WeakPtrFactory<LaunchReplyHandler> weak_ptr_factory_; |
| 107 | }; |
| 108 | |
[email protected] | 4d007b31 | 2012-10-17 03:00:48 | [diff] [blame^] | 109 | // This class keeps track of tabs as they are added to the browser. It will be |
| 110 | // "done" (i.e. won't block on Wait()) once |observations| tabs have been added. |
| 111 | class TabsAddedNotificationObserver |
| 112 | : public content::WindowedNotificationObserver { |
| 113 | public: |
| 114 | explicit TabsAddedNotificationObserver(size_t observations) |
| 115 | : content::WindowedNotificationObserver( |
| 116 | chrome::NOTIFICATION_TAB_ADDED, |
| 117 | content::NotificationService::AllSources()), |
| 118 | observations_(observations) { |
| 119 | } |
| 120 | |
| 121 | virtual void Observe(int type, |
| 122 | const content::NotificationSource& source, |
| 123 | const content::NotificationDetails& details) OVERRIDE { |
| 124 | observed_tabs_.push_back( |
| 125 | content::Details<WebContents>(details).ptr()); |
| 126 | if (observed_tabs_.size() == observations_) |
| 127 | content::WindowedNotificationObserver::Observe(type, source, details); |
| 128 | } |
| 129 | |
| 130 | const std::vector<content::WebContents*>& tabs() { return observed_tabs_; } |
| 131 | |
| 132 | private: |
| 133 | size_t observations_; |
| 134 | std::vector<content::WebContents*> observed_tabs_; |
| 135 | |
| 136 | DISALLOW_COPY_AND_ASSIGN(TabsAddedNotificationObserver); |
| 137 | }; |
| 138 | |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 139 | const char kTestFilePath[] = "platform_apps/launch_files/test.txt"; |
| 140 | |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 141 | } // namespace |
| 142 | |
[email protected] | eb4bcac | 2012-06-27 01:32:08 | [diff] [blame] | 143 | // Tests that CreateShellWindow doesn't crash if you close it straight away. |
| 144 | // LauncherPlatformAppBrowserTest relies on this behaviour, but is only run for |
| 145 | // ash, so we test that it works here. |
| 146 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, CreateAndCloseShellWindow) { |
| 147 | const Extension* extension = LoadAndLaunchPlatformApp("minimal"); |
| 148 | ShellWindow* window = CreateShellWindow(extension); |
| 149 | CloseShellWindow(window); |
| 150 | } |
| 151 | |
[email protected] | dc37b00 | 2012-04-23 23:02:26 | [diff] [blame] | 152 | // Tests that platform apps received the "launch" event when launched. |
| 153 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OnLaunchedEvent) { |
| 154 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_; |
[email protected] | cfc6cca | 2011-12-01 02:30:06 | [diff] [blame] | 155 | } |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 156 | |
[email protected] | a6db612 | 2012-09-03 06:00:23 | [diff] [blame] | 157 | // Tests that platform apps can reply to "launch" events that contain a Web |
| 158 | // Intent. This test does not test the mechanics of invoking a Web Intent |
| 159 | // from a source page, and short-circuits to LaunchPlatformAppWithWebIntent. |
| 160 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchReply) { |
| 161 | FilePath path = test_data_dir_.AppendASCII("platform_apps/launch_reply"); |
| 162 | const extensions::Extension* extension = LoadExtension(path); |
| 163 | ASSERT_TRUE(extension) << "Failed to load extension."; |
| 164 | |
| 165 | webkit_glue::WebIntentData data( |
| 166 | UTF8ToUTF16("http://webintents.org/view"), |
| 167 | UTF8ToUTF16("text/plain"), |
| 168 | UTF8ToUTF16("irrelevant unserialized string data")); |
| 169 | LaunchReplyHandler handler(data); |
| 170 | |
| 171 | // Navigate to a boring page: we don't care what it is, but we require some |
| 172 | // source WebContents to launch the Web Intent "from". |
| 173 | ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 174 | WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
| 175 | ASSERT_TRUE(web_contents); |
| 176 | |
| 177 | extensions::LaunchPlatformAppWithWebIntent( |
| 178 | browser()->profile(), |
| 179 | extension, |
| 180 | handler.intents_dispatcher(), |
| 181 | web_contents); |
| 182 | |
| 183 | ASSERT_TRUE(handler.WaitUntilReply()); |
| 184 | } |
| 185 | |
[email protected] | 567230b | 2012-08-21 21:11:44 | [diff] [blame] | 186 | // Tests that platform apps cannot use certain disabled window properties, but |
| 187 | // can override them and then use them. |
| 188 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisabledWindowProperties) { |
| 189 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/disabled_window_properties")) |
| 190 | << message_; |
| 191 | } |
| 192 | |
[email protected] | edd7ed69 | 2012-02-08 02:50:03 | [diff] [blame] | 193 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) { |
[email protected] | dc37b00 | 2012-04-23 23:02:26 | [diff] [blame] | 194 | ExtensionTestMessageListener launched_listener("Launched", false); |
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 195 | LoadAndLaunchPlatformApp("minimal"); |
[email protected] | dc37b00 | 2012-04-23 23:02:26 | [diff] [blame] | 196 | |
| 197 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 198 | |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 199 | // 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] | 200 | // only include the developer tools. |
[email protected] | d72d3a6 | 2012-05-10 03:45:08 | [diff] [blame] | 201 | WebContents* web_contents = GetFirstShellWindowWebContents(); |
[email protected] | a4465720 | 2012-01-09 05:48:31 | [diff] [blame] | 202 | ASSERT_TRUE(web_contents); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 203 | WebKit::WebContextMenuData data; |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 204 | content::ContextMenuParams params(data); |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 205 | scoped_ptr<PlatformAppContextMenu> menu; |
| 206 | menu.reset(new PlatformAppContextMenu(web_contents, params)); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 207 | menu->Init(); |
[email protected] | ad687a7 | 2012-06-08 06:03:11 | [diff] [blame] | 208 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
[email protected] | 65992d5 | 2012-09-19 23:05:31 | [diff] [blame] | 209 | ASSERT_TRUE( |
| 210 | menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
[email protected] | 671c970 | 2012-09-27 07:51:19 | [diff] [blame] | 211 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); |
[email protected] | ad687a7 | 2012-06-08 06:03:11 | [diff] [blame] | 212 | ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 213 | ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 214 | } |
| 215 | |
[email protected] | edd7ed69 | 2012-02-08 02:50:03 | [diff] [blame] | 216 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) { |
[email protected] | dc37b00 | 2012-04-23 23:02:26 | [diff] [blame] | 217 | ExtensionTestMessageListener launched_listener("Launched", false); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 218 | LoadAndLaunchPlatformApp("context_menu"); |
| 219 | |
[email protected] | dc37b00 | 2012-04-23 23:02:26 | [diff] [blame] | 220 | // Wait for the extension to tell us it's initialized its context menus and |
| 221 | // launched a window. |
| 222 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 223 | |
[email protected] | 271d01c | 2012-08-27 23:48:05 | [diff] [blame] | 224 | // The context_menu app has two context menu items. These, along with a |
[email protected] | 0cfacd8 | 2012-02-09 01:55:33 | [diff] [blame] | 225 | // separator and the developer tools, is all that should be in the menu. |
[email protected] | d72d3a6 | 2012-05-10 03:45:08 | [diff] [blame] | 226 | WebContents* web_contents = GetFirstShellWindowWebContents(); |
[email protected] | a4465720 | 2012-01-09 05:48:31 | [diff] [blame] | 227 | ASSERT_TRUE(web_contents); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 228 | WebKit::WebContextMenuData data; |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 229 | content::ContextMenuParams params(data); |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 230 | scoped_ptr<PlatformAppContextMenu> menu; |
| 231 | menu.reset(new PlatformAppContextMenu(web_contents, params)); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 232 | menu->Init(); |
[email protected] | ad687a7 | 2012-06-08 06:03:11 | [diff] [blame] | 233 | ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
[email protected] | 271d01c | 2012-08-27 23:48:05 | [diff] [blame] | 234 | ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1)); |
[email protected] | ad687a7 | 2012-06-08 06:03:11 | [diff] [blame] | 235 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
[email protected] | 65992d5 | 2012-09-19 23:05:31 | [diff] [blame] | 236 | ASSERT_TRUE( |
| 237 | menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
[email protected] | 671c970 | 2012-09-27 07:51:19 | [diff] [blame] | 238 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); |
[email protected] | ad687a7 | 2012-06-08 06:03:11 | [diff] [blame] | 239 | ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 240 | ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
[email protected] | b3c019b | 2012-08-28 02:43:48 | [diff] [blame] | 241 | ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
| 242 | } |
| 243 | |
[email protected] | 65992d5 | 2012-09-19 23:05:31 | [diff] [blame] | 244 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, InstalledAppWithContextMenu) { |
| 245 | ExtensionTestMessageListener launched_listener("Launched", false); |
| 246 | InstallAndLaunchPlatformApp("context_menu"); |
| 247 | |
| 248 | // Wait for the extension to tell us it's initialized its context menus and |
| 249 | // launched a window. |
| 250 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 251 | |
| 252 | // The context_menu app has two context menu items. For an installed app |
| 253 | // these are all that should be in the menu. |
| 254 | WebContents* web_contents = GetFirstShellWindowWebContents(); |
| 255 | ASSERT_TRUE(web_contents); |
| 256 | WebKit::WebContextMenuData data; |
| 257 | content::ContextMenuParams params(data); |
| 258 | scoped_ptr<PlatformAppContextMenu> menu; |
| 259 | menu.reset(new PlatformAppContextMenu(web_contents, params)); |
| 260 | menu->Init(); |
| 261 | ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
| 262 | ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1)); |
| 263 | ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
| 264 | ASSERT_FALSE( |
| 265 | menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
[email protected] | 671c970 | 2012-09-27 07:51:19 | [diff] [blame] | 266 | ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); |
[email protected] | 65992d5 | 2012-09-19 23:05:31 | [diff] [blame] | 267 | ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 268 | ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
| 269 | ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
| 270 | } |
| 271 | |
[email protected] | b3c019b | 2012-08-28 02:43:48 | [diff] [blame] | 272 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuTextField) { |
| 273 | ExtensionTestMessageListener launched_listener("Launched", false); |
| 274 | LoadAndLaunchPlatformApp("context_menu"); |
| 275 | |
| 276 | // Wait for the extension to tell us it's initialized its context menus and |
| 277 | // launched a window. |
| 278 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 279 | |
| 280 | // The context_menu app has one context menu item. This, along with a |
| 281 | // separator and the developer tools, is all that should be in the menu. |
| 282 | WebContents* web_contents = GetFirstShellWindowWebContents(); |
| 283 | ASSERT_TRUE(web_contents); |
| 284 | WebKit::WebContextMenuData data; |
| 285 | content::ContextMenuParams params(data); |
| 286 | params.is_editable = true; |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 287 | scoped_ptr<PlatformAppContextMenu> menu; |
| 288 | menu.reset(new PlatformAppContextMenu(web_contents, params)); |
[email protected] | b3c019b | 2012-08-28 02:43:48 | [diff] [blame] | 289 | menu->Init(); |
| 290 | ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
| 291 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
[email protected] | 65992d5 | 2012-09-19 23:05:31 | [diff] [blame] | 292 | ASSERT_TRUE( |
| 293 | menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
[email protected] | 671c970 | 2012-09-27 07:51:19 | [diff] [blame] | 294 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); |
[email protected] | b3c019b | 2012-08-28 02:43:48 | [diff] [blame] | 295 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
| 296 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); |
| 297 | ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 298 | ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
| 299 | } |
| 300 | |
| 301 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuSelection) { |
| 302 | ExtensionTestMessageListener launched_listener("Launched", false); |
| 303 | LoadAndLaunchPlatformApp("context_menu"); |
| 304 | |
| 305 | // 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 | |
| 309 | // 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.selection_text = ASCIIToUTF16("Hello World"); |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 316 | scoped_ptr<PlatformAppContextMenu> menu; |
| 317 | menu.reset(new PlatformAppContextMenu(web_contents, params)); |
[email protected] | b3c019b | 2012-08-28 02:43:48 | [diff] [blame] | 318 | menu->Init(); |
| 319 | ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
| 320 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
[email protected] | 65992d5 | 2012-09-19 23:05:31 | [diff] [blame] | 321 | ASSERT_TRUE( |
| 322 | menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
[email protected] | 671c970 | 2012-09-27 07:51:19 | [diff] [blame] | 323 | ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); |
[email protected] | b3c019b | 2012-08-28 02:43:48 | [diff] [blame] | 324 | ASSERT_FALSE(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)); |
[email protected] | 375003a | 2011-12-13 02:53:21 | [diff] [blame] | 328 | } |
[email protected] | 5f000f27 | 2012-01-19 05:25:08 | [diff] [blame] | 329 | |
[email protected] | dc83c58 | 2012-08-17 02:18:14 | [diff] [blame] | 330 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuClicked) { |
| 331 | ExtensionTestMessageListener launched_listener("Launched", false); |
| 332 | LoadAndLaunchPlatformApp("context_menu_click"); |
| 333 | |
| 334 | // 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 | |
| 338 | // Test that the menu item shows up |
| 339 | WebContents* web_contents = GetFirstShellWindowWebContents(); |
| 340 | ASSERT_TRUE(web_contents); |
| 341 | WebKit::WebContextMenuData data; |
| 342 | content::ContextMenuParams params(data); |
| 343 | params.page_url = GURL("http://foo.bar"); |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 344 | scoped_ptr<PlatformAppContextMenu> menu; |
| 345 | menu.reset(new PlatformAppContextMenu(web_contents, params)); |
[email protected] | dc83c58 | 2012-08-17 02:18:14 | [diff] [blame] | 346 | menu->Init(); |
| 347 | ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
| 348 | |
| 349 | // Execute the menu item |
| 350 | ExtensionTestMessageListener onclicked_listener("onClicked fired for id1", |
| 351 | false); |
| 352 | menu->ExecuteCommand(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST); |
| 353 | |
| 354 | ASSERT_TRUE(onclicked_listener.WaitUntilSatisfied()); |
| 355 | } |
| 356 | |
[email protected] | edd7ed69 | 2012-02-08 02:50:03 | [diff] [blame] | 357 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowNavigation) { |
[email protected] | 4d007b31 | 2012-10-17 03:00:48 | [diff] [blame^] | 358 | TabsAddedNotificationObserver observer(2); |
| 359 | |
[email protected] | dc37b00 | 2012-04-23 23:02:26 | [diff] [blame] | 360 | ASSERT_TRUE(StartTestServer()); |
| 361 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/navigation")) << message_; |
[email protected] | 4d007b31 | 2012-10-17 03:00:48 | [diff] [blame^] | 362 | |
| 363 | observer.Wait(); |
| 364 | ASSERT_EQ(2U, observer.tabs().size()); |
| 365 | EXPECT_EQ(std::string(chrome::kExtensionInvalidRequestURL), |
| 366 | observer.tabs()[0]->GetURL().spec()); |
| 367 | EXPECT_EQ("http://chromium.org/", |
| 368 | observer.tabs()[1]->GetURL().spec()); |
[email protected] | 5f000f27 | 2012-01-19 05:25:08 | [diff] [blame] | 369 | } |
[email protected] | 863e647 | 2012-01-24 19:33:58 | [diff] [blame] | 370 | |
[email protected] | 40eefd5 | 2012-10-04 22:54:22 | [diff] [blame] | 371 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Iframes) { |
[email protected] | fd3238af | 2012-05-22 18:55:30 | [diff] [blame] | 372 | ASSERT_TRUE(StartTestServer()); |
| 373 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/iframes")) << message_; |
| 374 | } |
| 375 | |
[email protected] | 2aac7ff | 2012-01-25 18:05:11 | [diff] [blame] | 376 | // Tests that localStorage and WebSQL are disabled for platform apps. |
[email protected] | edd7ed69 | 2012-02-08 02:50:03 | [diff] [blame] | 377 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowStorage) { |
[email protected] | 2aac7ff | 2012-01-25 18:05:11 | [diff] [blame] | 378 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/storage")) << message_; |
| 379 | } |
[email protected] | 6a5a2e5 | 2012-03-22 03:21:12 | [diff] [blame] | 380 | |
[email protected] | c0cecd1f | 2012-04-05 16:50:12 | [diff] [blame] | 381 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Restrictions) { |
| 382 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/restrictions")) << message_; |
| 383 | } |
| 384 | |
[email protected] | f0233ff | 2012-07-20 20:14:50 | [diff] [blame] | 385 | // Tests that platform apps can use the chrome.app.window.* API. |
[email protected] | dc37b00 | 2012-04-23 23:02:26 | [diff] [blame] | 386 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApi) { |
[email protected] | 6a5a2e5 | 2012-03-22 03:21:12 | [diff] [blame] | 387 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/windows_api")) << message_; |
| 388 | } |
[email protected] | 605fb810 | 2012-05-04 01:36:55 | [diff] [blame] | 389 | |
[email protected] | 1df2204 | 2012-08-30 19:48:55 | [diff] [blame] | 390 | // Tests that extensions can't use platform-app-only APIs. |
| 391 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, PlatformAppsOnly) { |
| 392 | ASSERT_TRUE(RunExtensionTestIgnoreManifestWarnings( |
| 393 | "platform_apps/apps_only")) << message_; |
| 394 | } |
| 395 | |
[email protected] | 605fb810 | 2012-05-04 01:36:55 | [diff] [blame] | 396 | // Tests that platform apps have isolated storage by default. |
| 397 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Isolation) { |
| 398 | ASSERT_TRUE(StartTestServer()); |
| 399 | |
| 400 | // Load a (non-app) page under the "localhost" origin that sets a cookie. |
| 401 | GURL set_cookie_url = test_server()->GetURL( |
| 402 | "files/extensions/platform_apps/isolation/set_cookie.html"); |
| 403 | GURL::Replacements replace_host; |
| 404 | std::string host_str("localhost"); // Must stay in scope with replace_host. |
| 405 | replace_host.SetHostStr(host_str); |
| 406 | set_cookie_url = set_cookie_url.ReplaceComponents(replace_host); |
| 407 | |
| 408 | ui_test_utils::NavigateToURLWithDisposition( |
| 409 | browser(), set_cookie_url, |
| 410 | CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 411 | |
| 412 | // Make sure the cookie is set. |
| 413 | int cookie_size; |
| 414 | std::string cookie_value; |
| 415 | automation_util::GetCookies( |
| 416 | set_cookie_url, |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 417 | chrome::GetWebContentsAt(browser(), 0), |
[email protected] | 605fb810 | 2012-05-04 01:36:55 | [diff] [blame] | 418 | &cookie_size, |
| 419 | &cookie_value); |
| 420 | ASSERT_EQ("testCookie=1", cookie_value); |
| 421 | |
| 422 | // Let the platform app request the same URL, and make sure that it doesn't |
| 423 | // see the cookie. |
| 424 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/isolation")) << message_; |
| 425 | } |
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 426 | |
| 427 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ExtensionWindowingApis) { |
| 428 | // Initially there should be just the one browser window visible to the |
| 429 | // extensions API. |
| 430 | const Extension* extension = LoadExtension( |
| 431 | test_data_dir_.AppendASCII("common/background_page")); |
| 432 | ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(extension)); |
| 433 | |
| 434 | // And no shell windows. |
| 435 | ASSERT_EQ(0U, GetShellWindowCount()); |
| 436 | |
| 437 | // Launch a platform app that shows a window. |
| 438 | ExtensionTestMessageListener launched_listener("Launched", false); |
[email protected] | ad5bb8a9 | 2012-06-07 03:55:58 | [diff] [blame] | 439 | LoadAndLaunchPlatformApp("minimal"); |
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 440 | ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 441 | ASSERT_EQ(1U, GetShellWindowCount()); |
| 442 | ShellWindowRegistry::ShellWindowSet shell_windows = |
| 443 | ShellWindowRegistry::Get(browser()->profile())->shell_windows(); |
| 444 | int shell_window_id = (*shell_windows.begin())->session_id().id(); |
| 445 | |
| 446 | // But it's not visible to the extensions API, it still thinks there's just |
| 447 | // one browser window. |
| 448 | ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(extension)); |
| 449 | // It can't look it up by ID either |
| 450 | ASSERT_FALSE(RunGetWindowFunctionForExtension(shell_window_id, extension)); |
| 451 | |
| 452 | // The app can also only see one window (its own). |
[email protected] | ad5bb8a9 | 2012-06-07 03:55:58 | [diff] [blame] | 453 | // TODO(jeremya): add an extension function to get a shell window by ID, and |
| 454 | // 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] | 455 | |
| 456 | // Launch another platform app that also shows a window. |
| 457 | ExtensionTestMessageListener launched_listener2("Launched", false); |
[email protected] | ad5bb8a9 | 2012-06-07 03:55:58 | [diff] [blame] | 458 | LoadAndLaunchPlatformApp("context_menu"); |
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 459 | ASSERT_TRUE(launched_listener2.WaitUntilSatisfied()); |
| 460 | |
| 461 | // There are two total shell windows, but each app can only see its own. |
| 462 | ASSERT_EQ(2U, GetShellWindowCount()); |
[email protected] | ad5bb8a9 | 2012-06-07 03:55:58 | [diff] [blame] | 463 | // TODO(jeremya): as above, this requires more extension functions. |
[email protected] | 31bdbfef | 2012-05-22 19:59:15 | [diff] [blame] | 464 | } |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 465 | |
[email protected] | a2ece52 | 2012-10-16 03:41:10 | [diff] [blame] | 466 | // ChromeOS does not support passing arguments on the command line, so the tests |
| 467 | // that rely on this functionality are disabled. |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 468 | #if !defined(OS_CHROMEOS) |
| 469 | // Tests that command line parameters get passed through to platform apps |
| 470 | // via launchData correctly when launching with a file. |
| 471 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithFile) { |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 472 | SetCommandLineArg(kTestFilePath); |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 473 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_file")) |
| 474 | << message_; |
| 475 | } |
| 476 | |
[email protected] | a5a0be0 | 2012-07-18 05:51:54 | [diff] [blame] | 477 | // Tests that relative paths can be passed through to the platform app. |
| 478 | // This test doesn't use the normal test infrastructure as it needs to open |
| 479 | // the application differently to all other platform app tests, by setting |
| 480 | // the application_launch::LaunchParams.current_directory field. |
| 481 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithRelativeFile) { |
| 482 | // Setup the command line |
| 483 | ClearCommandLineArgs(); |
| 484 | CommandLine* command_line = CommandLine::ForCurrentProcess(); |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 485 | FilePath relative_test_doc = FilePath::FromUTF8Unsafe(kTestFilePath); |
[email protected] | a5a0be0 | 2012-07-18 05:51:54 | [diff] [blame] | 486 | relative_test_doc = relative_test_doc.NormalizePathSeparators(); |
| 487 | command_line->AppendArgPath(relative_test_doc); |
| 488 | |
| 489 | // Load the extension |
| 490 | ResultCatcher catcher; |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 491 | const Extension* extension = LoadExtension( |
[email protected] | a5a0be0 | 2012-07-18 05:51:54 | [diff] [blame] | 492 | test_data_dir_.AppendASCII("platform_apps/launch_file")); |
| 493 | ASSERT_TRUE(extension); |
| 494 | |
| 495 | // Run the test |
| 496 | application_launch::LaunchParams params(browser()->profile(), extension, |
| 497 | extension_misc::LAUNCH_NONE, |
| 498 | NEW_WINDOW); |
| 499 | params.command_line = CommandLine::ForCurrentProcess(); |
| 500 | params.current_directory = test_data_dir_; |
| 501 | application_launch::OpenApplication(params); |
| 502 | |
| 503 | if (!catcher.GetNextResult()) { |
| 504 | message_ = catcher.message(); |
| 505 | ASSERT_TRUE(0); |
| 506 | } |
| 507 | } |
| 508 | |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 509 | // Tests that no launch data is sent through if the platform app provides |
| 510 | // an intent with the wrong action. |
| 511 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithWrongIntent) { |
[email protected] | 85d3d5e | 2012-08-31 21:19:17 | [diff] [blame] | 512 | SetCommandLineArg(kTestFilePath); |
[email protected] | 12e54045 | 2012-05-26 07:09:36 | [diff] [blame] | 513 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_intent")) |
| 514 | << message_; |
| 515 | } |
| 516 | |
| 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. |
| 589 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, ShellWindowRestorePosition) { |
| 590 | ExtensionTestMessageListener page2_listener("WaitForPage2", true); |
| 591 | ExtensionTestMessageListener page3_listener("WaitForPage3", true); |
| 592 | ExtensionTestMessageListener done_listener("Done1", false); |
| 593 | ExtensionTestMessageListener done2_listener("Done2", false); |
| 594 | ExtensionTestMessageListener done3_listener("Done3", false); |
| 595 | |
| 596 | ASSERT_TRUE(LoadAndLaunchPlatformApp("geometry")); |
| 597 | |
| 598 | // Wait for the app to be launched (although this is mostly to have a |
| 599 | // message to reply to to let the script know it should create its second |
| 600 | // window. |
| 601 | ASSERT_TRUE(page2_listener.WaitUntilSatisfied()); |
| 602 | |
| 603 | // Wait for the first window to verify its geometry was correctly set |
| 604 | // from the default* attributes passed to the create function. |
| 605 | ASSERT_TRUE(done_listener.WaitUntilSatisfied()); |
| 606 | |
| 607 | // Programatically move and resize the window. |
| 608 | ShellWindow* window = GetFirstShellWindow(); |
| 609 | ASSERT_TRUE(window); |
| 610 | gfx::Rect bounds(137, 143, 203, 187); |
| 611 | window->GetBaseWindow()->SetBounds(bounds); |
| 612 | |
| 613 | #if defined(TOOLKIT_GTK) |
| 614 | // TODO(mek): On GTK we have to wait for a roundtrip to the X server before |
| 615 | // a resize actually happens: |
| 616 | // "if you call gtk_window_resize() then immediately call |
| 617 | // gtk_window_get_size(), the size won't have taken effect yet. After the |
| 618 | // window manager processes the resize request, GTK+ receives notification |
| 619 | // that the size has changed via a configure event, and the size of the |
| 620 | // window gets updated." |
| 621 | // Because of this we have to wait for an unknown time for the resize to |
| 622 | // actually take effect. So wait some time or until the resize got |
| 623 | // handled. |
| 624 | base::TimeTicks end_time = base::TimeTicks::Now() + |
| 625 | TestTimeouts::action_timeout(); |
| 626 | while (base::TimeTicks::Now() < end_time && |
| 627 | bounds != window->GetBaseWindow()->GetBounds()) { |
| 628 | content::RunAllPendingInMessageLoop(); |
| 629 | } |
| 630 | |
| 631 | // In the GTK ShellWindow implementation there also is a delay between |
| 632 | // getting the correct bounds and it calling SaveWindowPosition, so call that |
| 633 | // method explicitly to make sure the value was stored. |
| 634 | window->SaveWindowPosition(); |
| 635 | #endif // defined(TOOLKIT_GTK) |
| 636 | |
| 637 | // Make sure the window was properly moved&resized. |
| 638 | ASSERT_EQ(bounds, window->GetBaseWindow()->GetBounds()); |
| 639 | |
| 640 | // Tell javascript to open a second window. |
| 641 | page2_listener.Reply("continue"); |
| 642 | |
| 643 | // Wait for javascript to verify that the second window got the updated |
| 644 | // coordinates, ignoring the default coordinates passed to the create method. |
| 645 | ASSERT_TRUE(done2_listener.WaitUntilSatisfied()); |
| 646 | |
| 647 | // Tell javascript to open a third window. |
| 648 | page3_listener.Reply("continue"); |
| 649 | |
| 650 | // Wait for javascript to verify that the third window got the restored size |
| 651 | // and explicitly specified coordinates. |
| 652 | ASSERT_TRUE(done3_listener.WaitUntilSatisfied()); |
| 653 | } |
[email protected] | 939532d0 | 2012-08-31 23:37:33 | [diff] [blame] | 654 | |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 655 | // Tests that a running app is recorded in the preferences as such. |
| 656 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, RunningAppsAreRecorded) { |
| 657 | content::WindowedNotificationObserver extension_suspended( |
| 658 | chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 659 | content::NotificationService::AllSources()); |
| 660 | |
| 661 | const Extension* extension = LoadExtension( |
| 662 | test_data_dir_.AppendASCII("platform_apps/restart_test")); |
| 663 | ASSERT_TRUE(extension); |
| 664 | ExtensionService* extension_service = |
| 665 | ExtensionSystem::Get(browser()->profile())->extension_service(); |
| 666 | ExtensionPrefs* extension_prefs = extension_service->extension_prefs(); |
| 667 | |
| 668 | // App is running. |
| 669 | ASSERT_TRUE(extension_prefs->IsExtensionRunning(extension->id())); |
| 670 | |
| 671 | // Wait for the extension to get suspended. |
| 672 | extension_suspended.Wait(); |
| 673 | |
| 674 | // App isn't running because it got suspended. |
| 675 | ASSERT_FALSE(extension_prefs->IsExtensionRunning(extension->id())); |
| 676 | |
| 677 | // Pretend that the app is supposed to be running. |
| 678 | extension_prefs->SetExtensionRunning(extension->id(), true); |
| 679 | |
| 680 | ExtensionTestMessageListener restart_listener("onRestarted", false); |
| 681 | AppRestoreServiceFactory::GetForProfile(browser()->profile())->RestoreApps(); |
| 682 | restart_listener.WaitUntilSatisfied(); |
| 683 | } |
| 684 | |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 685 | } // namespace extensions |