[email protected] | 35abc33 | 2012-02-24 23:48:38 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 32b7c49 | 2010-09-01 04:15:00 | [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 | |
| 5 | #include "base/command_line.h" |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 6 | #include "base/memory/scoped_vector.h" |
[email protected] | 46acbf1 | 2013-06-10 18:43:42 | [diff] [blame] | 7 | #include "base/strings/stringprintf.h" |
[email protected] | 32b7c49 | 2010-09-01 04:15:00 | [diff] [blame] | 8 | #include "chrome/browser/extensions/extension_apitest.h" |
[email protected] | 1dd66b7 | 2012-09-19 20:41:48 | [diff] [blame] | 9 | #include "chrome/browser/extensions/extension_host.h" |
| 10 | #include "chrome/browser/extensions/extension_process_manager.h" |
[email protected] | be93bba0 | 2012-10-24 16:44:03 | [diff] [blame] | 11 | #include "chrome/browser/extensions/extension_system.h" |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 12 | #include "chrome/browser/extensions/extension_test_message_listener.h" |
[email protected] | 2ad4a90 | 2010-11-17 06:05:13 | [diff] [blame] | 13 | #include "chrome/browser/ui/browser.h" |
[email protected] | d874814 | 2012-05-16 21:13:43 | [diff] [blame] | 14 | #include "chrome/browser/ui/browser_finder.h" |
[email protected] | bc44f414 | 2013-02-12 06:15:56 | [diff] [blame] | 15 | #include "chrome/browser/ui/browser_iterator.h" |
[email protected] | f6ffa7d | 2012-08-17 17:27:08 | [diff] [blame] | 16 | #include "chrome/browser/ui/panels/panel_manager.h" |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 17 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
[email protected] | 32b7c49 | 2010-09-01 04:15:00 | [diff] [blame] | 18 | #include "chrome/common/chrome_switches.h" |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 19 | #include "chrome/common/extensions/extension.h" |
[email protected] | af44e7fb | 2011-07-29 18:32:32 | [diff] [blame] | 20 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | 1dd66b7 | 2012-09-19 20:41:48 | [diff] [blame] | 21 | #include "content/public/browser/render_process_host.h" |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 22 | #include "content/public/browser/web_contents.h" |
[email protected] | 1dd66b7 | 2012-09-19 20:41:48 | [diff] [blame] | 23 | #include "content/public/common/result_codes.h" |
[email protected] | 7d478cb | 2012-07-24 17:19:42 | [diff] [blame] | 24 | #include "content/public/test/browser_test_utils.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 25 | #include "net/dns/mock_host_resolver.h" |
[email protected] | bc44f414 | 2013-02-12 06:15:56 | [diff] [blame] | 26 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 32b7c49 | 2010-09-01 04:15:00 | [diff] [blame] | 27 | |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 28 | #if defined(USE_ASH) |
| 29 | #include "chrome/browser/extensions/shell_window_registry.h" |
| 30 | #endif |
| 31 | |
[email protected] | 45c6f672 | 2013-07-23 03:02:19 | [diff] [blame] | 32 | #if defined(OS_WIN) && defined(USE_ASH) |
| 33 | #include "base/win/windows_version.h" |
| 34 | #endif |
| 35 | |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 36 | #if defined(USE_ASH) && !defined(OS_WIN) |
| 37 | // TODO(stevenjb): Figure out the correct behavior for Ash + Win |
| 38 | #define USE_ASH_PANELS |
| 39 | #endif |
| 40 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 41 | using content::OpenURLParams; |
| 42 | using content::Referrer; |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 43 | using content::WebContents; |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 44 | |
[email protected] | e78eb29 | 2010-12-22 08:35:39 | [diff] [blame] | 45 | // Disabled, http://crbug.com/64899. |
| 46 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpen) { |
[email protected] | 32b7c49 | 2010-09-01 04:15:00 | [diff] [blame] | 47 | CommandLine::ForCurrentProcess()->AppendSwitch( |
| 48 | switches::kEnableExperimentalExtensionApis); |
| 49 | |
| 50 | ResultCatcher catcher; |
| 51 | ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ |
| 52 | .AppendASCII("window_open").AppendASCII("spanning"))); |
| 53 | EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 54 | } |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 55 | |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 56 | int GetPanelCount(Browser* browser) { |
| 57 | #if defined(USE_ASH_PANELS) |
| 58 | return static_cast<int>(extensions::ShellWindowRegistry::Get( |
| 59 | browser->profile())->shell_windows().size()); |
| 60 | #else |
| 61 | return PanelManager::GetInstance()->num_panels(); |
| 62 | #endif |
| 63 | } |
| 64 | |
| 65 | bool WaitForTabsAndPopups(Browser* browser, |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 66 | int num_tabs, |
| 67 | int num_popups, |
| 68 | int num_panels) { |
[email protected] | 58b349b | 2011-11-23 02:07:15 | [diff] [blame] | 69 | SCOPED_TRACE( |
[email protected] | 7d3cbc9 | 2013-03-18 22:33:04 | [diff] [blame] | 70 | base::StringPrintf("WaitForTabsAndPopups tabs:%d, popups:%d, panels:%d", |
| 71 | num_tabs, num_popups, num_panels)); |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 72 | // We start with one tab and one browser already open. |
| 73 | ++num_tabs; |
[email protected] | f6ffa7d | 2012-08-17 17:27:08 | [diff] [blame] | 74 | size_t num_browsers = static_cast<size_t>(num_popups) + 1; |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 75 | |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 76 | const base::TimeDelta kWaitTime = base::TimeDelta::FromSeconds(10); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 77 | base::TimeTicks end_time = base::TimeTicks::Now() + kWaitTime; |
| 78 | while (base::TimeTicks::Now() < end_time) { |
[email protected] | c987a24 | 2013-02-28 01:17:41 | [diff] [blame] | 79 | if (chrome::GetBrowserCount(browser->profile(), |
| 80 | browser->host_desktop_type()) == num_browsers && |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 81 | browser->tab_strip_model()->count() == num_tabs && |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 82 | GetPanelCount(browser) == num_panels) |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 83 | break; |
| 84 | |
[email protected] | b8deecd | 2012-07-30 21:09:44 | [diff] [blame] | 85 | content::RunAllPendingInMessageLoop(); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 86 | } |
| 87 | |
[email protected] | c987a24 | 2013-02-28 01:17:41 | [diff] [blame] | 88 | EXPECT_EQ(num_browsers, |
| 89 | chrome::GetBrowserCount(browser->profile(), |
| 90 | browser->host_desktop_type())); |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 91 | EXPECT_EQ(num_tabs, browser->tab_strip_model()->count()); |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 92 | EXPECT_EQ(num_panels, GetPanelCount(browser)); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 93 | |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 94 | int num_popups_seen = 0; |
[email protected] | bc44f414 | 2013-02-12 06:15:56 | [diff] [blame] | 95 | for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) { |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 96 | if (*iter == browser) |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 97 | continue; |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 98 | |
[email protected] | f6ffa7d | 2012-08-17 17:27:08 | [diff] [blame] | 99 | EXPECT_TRUE((*iter)->is_type_popup()); |
[email protected] | f6ffa7d | 2012-08-17 17:27:08 | [diff] [blame] | 100 | ++num_popups_seen; |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 101 | } |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 102 | EXPECT_EQ(num_popups, num_popups_seen); |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 103 | |
[email protected] | c987a24 | 2013-02-28 01:17:41 | [diff] [blame] | 104 | return ((num_browsers == |
| 105 | chrome::GetBrowserCount(browser->profile(), |
| 106 | browser->host_desktop_type())) && |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 107 | (num_tabs == browser->tab_strip_model()->count()) && |
| 108 | (num_panels == GetPanelCount(browser)) && |
| 109 | (num_popups == num_popups_seen)); |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 110 | } |
| 111 | |
[email protected] | f112b0f | 2011-05-26 01:53:52 | [diff] [blame] | 112 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserIsApp) { |
| 113 | host_resolver()->AddRule("a.com", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 114 | ASSERT_TRUE(StartEmbeddedTestServer()); |
[email protected] | f112b0f | 2011-05-26 01:53:52 | [diff] [blame] | 115 | ASSERT_TRUE(LoadExtension( |
| 116 | test_data_dir_.AppendASCII("window_open").AppendASCII("browser_is_app"))); |
| 117 | |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 118 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 2, 0)); |
[email protected] | f112b0f | 2011-05-26 01:53:52 | [diff] [blame] | 119 | |
[email protected] | bc44f414 | 2013-02-12 06:15:56 | [diff] [blame] | 120 | for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) { |
[email protected] | f112b0f | 2011-05-26 01:53:52 | [diff] [blame] | 121 | if (*iter == browser()) |
[email protected] | bc44f414 | 2013-02-12 06:15:56 | [diff] [blame] | 122 | ASSERT_FALSE(iter->is_app()); |
[email protected] | f112b0f | 2011-05-26 01:53:52 | [diff] [blame] | 123 | else |
[email protected] | bc44f414 | 2013-02-12 06:15:56 | [diff] [blame] | 124 | ASSERT_TRUE(iter->is_app()); |
[email protected] | f112b0f | 2011-05-26 01:53:52 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 128 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupDefault) { |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 129 | ASSERT_TRUE(StartEmbeddedTestServer()); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 130 | ASSERT_TRUE(LoadExtension( |
| 131 | test_data_dir_.AppendASCII("window_open").AppendASCII("popup"))); |
| 132 | |
| 133 | const int num_tabs = 1; |
| 134 | const int num_popups = 0; |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 135 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0)); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupLarge) { |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 139 | ASSERT_TRUE(StartEmbeddedTestServer()); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 140 | ASSERT_TRUE(LoadExtension( |
| 141 | test_data_dir_.AppendASCII("window_open").AppendASCII("popup_large"))); |
| 142 | |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 143 | // On other systems this should open a new popup window. |
| 144 | const int num_tabs = 0; |
| 145 | const int num_popups = 1; |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 146 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0)); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupSmall) { |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 150 | ASSERT_TRUE(StartEmbeddedTestServer()); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 151 | ASSERT_TRUE(LoadExtension( |
| 152 | test_data_dir_.AppendASCII("window_open").AppendASCII("popup_small"))); |
| 153 | |
| 154 | // On ChromeOS this should open a new panel (acts like a new popup window). |
| 155 | // On other systems this should open a new popup window. |
| 156 | const int num_tabs = 0; |
| 157 | const int num_popups = 1; |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 158 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0)); |
[email protected] | 0a5bdc652 | 2011-06-08 19:04:49 | [diff] [blame] | 159 | } |
| 160 | |
[email protected] | 73fa1fce | 2013-02-21 20:10:05 | [diff] [blame] | 161 | // Disabled on Windows. Often times out or fails: crbug.com/177530 |
| 162 | #if defined(OS_WIN) |
| 163 | #define MAYBE_PopupBlockingExtension DISABLED_PopupBlockingExtension |
| 164 | #else |
| 165 | #define MAYBE_PopupBlockingExtension PopupBlockingExtension |
| 166 | #endif |
| 167 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_PopupBlockingExtension) { |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 168 | host_resolver()->AddRule("*", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 169 | ASSERT_TRUE(StartEmbeddedTestServer()); |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 170 | |
| 171 | ASSERT_TRUE(LoadExtension( |
| 172 | test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking") |
| 173 | .AppendASCII("extension"))); |
| 174 | |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 175 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), 5, 3, 0)); |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PopupBlockingHostedApp) { |
| 179 | host_resolver()->AddRule("*", "127.0.0.1"); |
| 180 | ASSERT_TRUE(test_server()->Start()); |
| 181 | |
| 182 | ASSERT_TRUE(LoadExtension( |
| 183 | test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking") |
| 184 | .AppendASCII("hosted_app"))); |
| 185 | |
[email protected] | fe304887 | 2010-10-18 14:58:59 | [diff] [blame] | 186 | // The app being tested owns the domain a.com . The test URLs we navigate |
| 187 | // to below must be within that domain, so that they fall within the app's |
| 188 | // web extent. |
| 189 | GURL::Replacements replace_host; |
| 190 | std::string a_dot_com = "a.com"; |
| 191 | replace_host.SetHostStr(a_dot_com); |
| 192 | |
| 193 | const std::string popup_app_contents_path( |
| 194 | "files/extensions/api_test/window_open/popup_blocking/hosted_app/"); |
| 195 | |
| 196 | GURL open_tab = |
| 197 | test_server()->GetURL(popup_app_contents_path + "open_tab.html") |
| 198 | .ReplaceComponents(replace_host); |
| 199 | GURL open_popup = |
| 200 | test_server()->GetURL(popup_app_contents_path + "open_popup.html") |
| 201 | .ReplaceComponents(replace_host); |
| 202 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 203 | browser()->OpenURL(OpenURLParams( |
| 204 | open_tab, Referrer(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED, |
| 205 | false)); |
| 206 | browser()->OpenURL(OpenURLParams( |
| 207 | open_popup, Referrer(), NEW_FOREGROUND_TAB, |
| 208 | content::PAGE_TRANSITION_TYPED, false)); |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 209 | |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 210 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), 3, 1, 0)); |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 211 | } |
[email protected] | d4db6c70 | 2011-03-28 21:49:14 | [diff] [blame] | 212 | |
[email protected] | e7f9056 | 2011-05-23 21:38:24 | [diff] [blame] | 213 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowArgumentsOverflow) { |
| 214 | ASSERT_TRUE(RunExtensionTest("window_open/argument_overflow")) << message_; |
| 215 | } |
| 216 | |
[email protected] | d5c1406 | 2011-10-27 00:02:13 | [diff] [blame] | 217 | class WindowOpenPanelDisabledTest : public ExtensionApiTest { |
[email protected] | 49aeab6 | 2013-02-07 02:53:11 | [diff] [blame] | 218 | virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
[email protected] | 08aa0c3 | 2011-04-11 22:18:37 | [diff] [blame] | 219 | ExtensionApiTest::SetUpCommandLine(command_line); |
[email protected] | 7e7a2809 | 2011-12-09 22:24:55 | [diff] [blame] | 220 | // TODO(jennb): Re-enable when panels are enabled by default. |
| 221 | // command_line->AppendSwitch(switches::kDisablePanels); |
[email protected] | 08aa0c3 | 2011-04-11 22:18:37 | [diff] [blame] | 222 | } |
| 223 | }; |
| 224 | |
[email protected] | 7e7a2809 | 2011-12-09 22:24:55 | [diff] [blame] | 225 | IN_PROC_BROWSER_TEST_F(WindowOpenPanelDisabledTest, |
| 226 | DISABLED_WindowOpenPanelNotEnabled) { |
[email protected] | d5c1406 | 2011-10-27 00:02:13 | [diff] [blame] | 227 | ASSERT_TRUE(RunExtensionTest("window_open/panel_not_enabled")) << message_; |
| 228 | } |
| 229 | |
[email protected] | af6b5451 | 2011-12-14 06:11:21 | [diff] [blame] | 230 | class WindowOpenPanelTest : public ExtensionApiTest { |
[email protected] | 49aeab6 | 2013-02-07 02:53:11 | [diff] [blame] | 231 | virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
[email protected] | af6b5451 | 2011-12-14 06:11:21 | [diff] [blame] | 232 | ExtensionApiTest::SetUpCommandLine(command_line); |
| 233 | command_line->AppendSwitch(switches::kEnablePanels); |
| 234 | } |
| 235 | }; |
| 236 | |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 237 | #if defined(USE_ASH_PANELS) |
[email protected] | 87d722a | 2012-07-12 15:38:33 | [diff] [blame] | 238 | // On Ash, this currently fails because we're currently opening new panel |
[email protected] | d101b0c | 2012-03-16 00:30:57 | [diff] [blame] | 239 | // windows as popup windows instead. |
[email protected] | e00ccc9 | 2012-11-01 17:32:30 | [diff] [blame] | 240 | #define MAYBE_WindowOpenPanel DISABLED_WindowOpenPanel |
[email protected] | d101b0c | 2012-03-16 00:30:57 | [diff] [blame] | 241 | #else |
| 242 | #define MAYBE_WindowOpenPanel WindowOpenPanel |
| 243 | #endif |
| 244 | IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenPanel) { |
[email protected] | 08aa0c3 | 2011-04-11 22:18:37 | [diff] [blame] | 245 | ASSERT_TRUE(RunExtensionTest("window_open/panel")) << message_; |
| 246 | } |
[email protected] | 54edcea | 2011-07-27 01:56:38 | [diff] [blame] | 247 | |
[email protected] | cb1849e | 2013-07-08 21:12:53 | [diff] [blame] | 248 | #if defined(USE_ASH_PANELS) |
[email protected] | ca29ed1 | 2012-09-06 09:10:50 | [diff] [blame] | 249 | // On Ash, this currently fails because we're currently opening new panel |
| 250 | // windows as popup windows instead. |
[email protected] | cb1849e | 2013-07-08 21:12:53 | [diff] [blame] | 251 | #define MAYBE_WindowOpenPanelDetached DISABLED_WindowOpenPanelDetached |
| 252 | #else |
| 253 | #define MAYBE_WindowOpenPanelDetached WindowOpenPanelDetached |
| 254 | #endif |
| 255 | IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenPanelDetached) { |
[email protected] | ca29ed1 | 2012-09-06 09:10:50 | [diff] [blame] | 256 | ASSERT_TRUE(RunExtensionTest("window_open/panel_detached")) << message_; |
| 257 | } |
| 258 | |
[email protected] | af6b5451 | 2011-12-14 06:11:21 | [diff] [blame] | 259 | IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 260 | CloseNonExtensionPanelsOnUninstall) { |
[email protected] | 45c6f672 | 2013-07-23 03:02:19 | [diff] [blame] | 261 | #if defined(OS_WIN) && defined(USE_ASH) |
| 262 | // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 263 | if (base::win::GetVersion() >= base::win::VERSION_WIN8) |
| 264 | return; |
| 265 | #endif |
| 266 | |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 267 | #if defined(USE_ASH_PANELS) |
[email protected] | 1dd66b7 | 2012-09-19 20:41:48 | [diff] [blame] | 268 | // On Ash, new panel windows open as popup windows instead. |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 269 | int num_popups, num_panels; |
| 270 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePanels)) { |
| 271 | num_popups = 2; |
| 272 | num_panels = 2; |
| 273 | } else { |
| 274 | num_popups = 4; |
| 275 | num_panels = 0; |
| 276 | } |
[email protected] | 1dd66b7 | 2012-09-19 20:41:48 | [diff] [blame] | 277 | #else |
| 278 | int num_popups = 2; |
| 279 | int num_panels = 2; |
| 280 | #endif |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 281 | ASSERT_TRUE(StartEmbeddedTestServer()); |
[email protected] | 1dd66b7 | 2012-09-19 20:41:48 | [diff] [blame] | 282 | |
| 283 | // Setup listeners to wait on strings we expect the extension pages to send. |
| 284 | std::vector<std::string> test_strings; |
| 285 | test_strings.push_back("content_tab"); |
| 286 | if (num_panels) |
| 287 | test_strings.push_back("content_panel"); |
| 288 | test_strings.push_back("content_popup"); |
| 289 | |
| 290 | ScopedVector<ExtensionTestMessageListener> listeners; |
| 291 | for (size_t i = 0; i < test_strings.size(); ++i) { |
| 292 | listeners.push_back( |
| 293 | new ExtensionTestMessageListener(test_strings[i], false)); |
| 294 | } |
| 295 | |
| 296 | const extensions::Extension* extension = LoadExtension( |
| 297 | test_data_dir_.AppendASCII("window_open").AppendASCII( |
| 298 | "close_panels_on_uninstall")); |
| 299 | ASSERT_TRUE(extension); |
| 300 | |
| 301 | // Two tabs. One in extension domain and one in non-extension domain. |
| 302 | // Two popups - one in extension domain and one in non-extension domain. |
| 303 | // Two panels - one in extension domain and one in non-extension domain. |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 304 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, num_panels)); |
[email protected] | 4cdd857 | 2013-02-15 00:33:25 | [diff] [blame] | 305 | |
| 306 | // Wait on test messages to make sure the pages loaded. |
| 307 | for (size_t i = 0; i < listeners.size(); ++i) |
| 308 | ASSERT_TRUE(listeners[i]->WaitUntilSatisfied()); |
| 309 | |
| 310 | UninstallExtension(extension->id()); |
| 311 | |
| 312 | // Wait for the tabs and popups in non-extension domain to stay open. |
| 313 | // Expect everything else, including panels, to close. |
[email protected] | 4cdd857 | 2013-02-15 00:33:25 | [diff] [blame] | 314 | num_popups -= 1; |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 315 | #if defined(USE_ASH_PANELS) |
| 316 | if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePanels)) { |
| 317 | // On Ash, new panel windows open as popup windows instead, so there are 2 |
| 318 | // extension domain popups that will close (instead of 1 popup on non-Ash). |
| 319 | num_popups -= 1; |
| 320 | } |
[email protected] | 4cdd857 | 2013-02-15 00:33:25 | [diff] [blame] | 321 | #endif |
[email protected] | 9111fff | 2013-06-12 18:01:55 | [diff] [blame] | 322 | #if defined(USE_ASH) |
| 323 | #if !defined(OS_WIN) |
| 324 | // On linux ash we close all popup applications when closing its extension. |
| 325 | num_popups = 0; |
| 326 | #endif |
| 327 | #endif |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 328 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), 1, num_popups, 0)); |
[email protected] | 4cdd857 | 2013-02-15 00:33:25 | [diff] [blame] | 329 | } |
| 330 | |
[email protected] | 4ad85f4 | 2013-07-24 02:31:57 | [diff] [blame^] | 331 | // This test isn't applicable on Chrome OS, which automatically reloads |
| 332 | // crashed pages. |
| 333 | #if !defined(OS_CHROMEOS) |
| 334 | IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, ClosePanelsOnExtensionCrash) { |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 335 | #if defined(USE_ASH_PANELS) |
[email protected] | 4cdd857 | 2013-02-15 00:33:25 | [diff] [blame] | 336 | // On Ash, new panel windows open as popup windows instead. |
| 337 | int num_popups = 4; |
| 338 | int num_panels = 0; |
| 339 | #else |
| 340 | int num_popups = 2; |
| 341 | int num_panels = 2; |
| 342 | #endif |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 343 | ASSERT_TRUE(StartEmbeddedTestServer()); |
[email protected] | 4cdd857 | 2013-02-15 00:33:25 | [diff] [blame] | 344 | |
| 345 | // Setup listeners to wait on strings we expect the extension pages to send. |
| 346 | std::vector<std::string> test_strings; |
| 347 | test_strings.push_back("content_tab"); |
| 348 | if (num_panels) |
| 349 | test_strings.push_back("content_panel"); |
| 350 | test_strings.push_back("content_popup"); |
| 351 | |
| 352 | ScopedVector<ExtensionTestMessageListener> listeners; |
| 353 | for (size_t i = 0; i < test_strings.size(); ++i) { |
| 354 | listeners.push_back( |
| 355 | new ExtensionTestMessageListener(test_strings[i], false)); |
| 356 | } |
| 357 | |
| 358 | const extensions::Extension* extension = LoadExtension( |
| 359 | test_data_dir_.AppendASCII("window_open").AppendASCII( |
| 360 | "close_panels_on_uninstall")); |
| 361 | ASSERT_TRUE(extension); |
| 362 | |
| 363 | // Two tabs. One in extension domain and one in non-extension domain. |
| 364 | // Two popups - one in extension domain and one in non-extension domain. |
| 365 | // Two panels - one in extension domain and one in non-extension domain. |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 366 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, num_panels)); |
[email protected] | 1dd66b7 | 2012-09-19 20:41:48 | [diff] [blame] | 367 | |
| 368 | // Wait on test messages to make sure the pages loaded. |
| 369 | for (size_t i = 0; i < listeners.size(); ++i) |
| 370 | ASSERT_TRUE(listeners[i]->WaitUntilSatisfied()); |
| 371 | |
| 372 | // Crash the extension. |
| 373 | extensions::ExtensionHost* extension_host = |
[email protected] | be93bba0 | 2012-10-24 16:44:03 | [diff] [blame] | 374 | extensions::ExtensionSystem::Get(browser()->profile())-> |
| 375 | process_manager()->GetBackgroundHostForExtension(extension->id()); |
[email protected] | 1dd66b7 | 2012-09-19 20:41:48 | [diff] [blame] | 376 | ASSERT_TRUE(extension_host); |
| 377 | base::KillProcess(extension_host->render_process_host()->GetHandle(), |
| 378 | content::RESULT_CODE_KILLED, false); |
| 379 | WaitForExtensionCrash(extension->id()); |
| 380 | |
| 381 | // Only expect panels to close. The rest stay open to show a sad-tab. |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 382 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, 0)); |
[email protected] | 1dd66b7 | 2012-09-19 20:41:48 | [diff] [blame] | 383 | } |
[email protected] | 4ad85f4 | 2013-07-24 02:31:57 | [diff] [blame^] | 384 | #endif // !defined(OS_CHROMEOS) |
[email protected] | 1dd66b7 | 2012-09-19 20:41:48 | [diff] [blame] | 385 | |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 386 | #if defined(USE_ASH_PANELS) |
| 387 | // This test is not applicable on Ash. The modified window.open behavior only |
| 388 | // applies to non-Ash panel windows. |
[email protected] | 99f4fdb9 | 2012-08-30 23:13:51 | [diff] [blame] | 389 | #define MAYBE_WindowOpenFromPanel DISABLED_WindowOpenFromPanel |
| 390 | #else |
| 391 | #define MAYBE_WindowOpenFromPanel WindowOpenFromPanel |
| 392 | #endif |
| 393 | IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenFromPanel) { |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 394 | ASSERT_TRUE(StartEmbeddedTestServer()); |
[email protected] | 6798c33 | 2012-08-29 02:16:51 | [diff] [blame] | 395 | |
[email protected] | 99f4fdb9 | 2012-08-30 23:13:51 | [diff] [blame] | 396 | // Load the extension that will open a panel which then calls window.open. |
[email protected] | 6798c33 | 2012-08-29 02:16:51 | [diff] [blame] | 397 | ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("window_open"). |
| 398 | AppendASCII("panel_window_open"))); |
[email protected] | 99f4fdb9 | 2012-08-30 23:13:51 | [diff] [blame] | 399 | |
| 400 | // Expect one panel (opened by extension) and one tab (from the panel calling |
| 401 | // window.open). Panels modify the WindowOpenDisposition in window.open |
| 402 | // to always open in a tab. |
[email protected] | f1c102b | 2013-02-15 07:44:12 | [diff] [blame] | 403 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), 1, 0, 1)); |
[email protected] | 6798c33 | 2012-08-29 02:16:51 | [diff] [blame] | 404 | } |
| 405 | |
[email protected] | 24c6bcfc | 2012-02-29 21:06:36 | [diff] [blame] | 406 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpener) { |
[email protected] | 54edcea | 2011-07-27 01:56:38 | [diff] [blame] | 407 | ASSERT_TRUE(RunExtensionTest("window_open/opener")) << message_; |
| 408 | } |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 409 | |
[email protected] | fa7c160 | 2013-04-03 23:00:20 | [diff] [blame] | 410 | #if defined(OS_MACOSX) |
| 411 | // Extension popup windows are incorrectly sized on OSX, crbug.com/225601 |
| 412 | #define MAYBE_WindowOpenSized DISABLED_WindowOpenSized |
| 413 | #else |
| 414 | #define MAYBE_WindowOpenSized WindowOpenSized |
| 415 | #endif |
| 416 | // Ensure that the width and height properties of a window opened with |
| 417 | // chrome.windows.create match the creation parameters. See crbug.com/173831. |
| 418 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_WindowOpenSized) { |
| 419 | ASSERT_TRUE(RunExtensionTest("window_open/window_size")) << message_; |
| 420 | EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 1, 0)); |
| 421 | } |
| 422 | |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 423 | // Tests that an extension page can call window.open to an extension URL and |
| 424 | // the new window has extension privileges. |
| 425 | IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenExtension) { |
| 426 | ASSERT_TRUE(LoadExtension( |
| 427 | test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); |
| 428 | |
| 429 | GURL start_url(std::string("chrome-extension://") + |
| 430 | last_loaded_extension_id_ + "/test.html"); |
| 431 | ui_test_utils::NavigateToURL(browser(), start_url); |
[email protected] | f3e73f6 | 2012-10-20 05:35:16 | [diff] [blame] | 432 | WebContents* newtab = NULL; |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 433 | ASSERT_NO_FATAL_FAILURE( |
| 434 | OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(), |
| 435 | start_url.Resolve("newtab.html"), true, &newtab)); |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 436 | |
| 437 | bool result = false; |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 438 | ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()", |
| 439 | &result)); |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 440 | EXPECT_TRUE(result); |
| 441 | } |
| 442 | |
| 443 | // Tests that if an extension page calls window.open to an invalid extension |
| 444 | // URL, the browser doesn't crash. |
| 445 | IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) { |
| 446 | ASSERT_TRUE(LoadExtension( |
| 447 | test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); |
| 448 | |
| 449 | GURL start_url(std::string("chrome-extension://") + |
| 450 | last_loaded_extension_id_ + "/test.html"); |
| 451 | ui_test_utils::NavigateToURL(browser(), start_url); |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 452 | ASSERT_NO_FATAL_FAILURE( |
| 453 | OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(), |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 454 | GURL("chrome-extension://thisissurelynotavalidextensionid/newtab.html"), |
| 455 | false, NULL)); |
| 456 | |
| 457 | // If we got to this point, we didn't crash, so we're good. |
| 458 | } |
| 459 | |
| 460 | // Tests that calling window.open from the newtab page to an extension URL |
| 461 | // gives the new window extension privileges - even though the opening page |
| 462 | // does not have extension privileges, we break the script connection, so |
| 463 | // there is no privilege leak. |
| 464 | IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) { |
| 465 | ASSERT_TRUE(LoadExtension( |
| 466 | test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); |
| 467 | |
| 468 | ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
[email protected] | f3e73f6 | 2012-10-20 05:35:16 | [diff] [blame] | 469 | WebContents* newtab = NULL; |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 470 | ASSERT_NO_FATAL_FAILURE( |
| 471 | OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(), |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 472 | GURL(std::string("chrome-extension://") + last_loaded_extension_id_ + |
| 473 | "/newtab.html"), false, &newtab)); |
| 474 | |
| 475 | // Extension API should succeed. |
| 476 | bool result = false; |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 477 | ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()", |
| 478 | &result)); |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 479 | EXPECT_TRUE(result); |
| 480 | } |