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