blob: b841b74ede25cbf5767425b08b4b8765b904d90c [file] [log] [blame]
[email protected]35abc332012-02-24 23:48:381// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]32b7c492010-09-01 04:15:002// 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]f9e82d92011-10-29 00:50:456#include "base/memory/scoped_vector.h"
[email protected]7c6ef352013-09-26 07:23:147#include "base/path_service.h"
[email protected]46acbf12013-06-10 18:43:428#include "base/strings/stringprintf.h"
[email protected]32b7c492010-09-01 04:15:009#include "chrome/browser/extensions/extension_apitest.h"
[email protected]f9e82d92011-10-29 00:50:4510#include "chrome/browser/extensions/extension_test_message_listener.h"
[email protected]01996a592013-09-13 06:55:0411#include "chrome/browser/profiles/profile.h"
[email protected]2ad4a902010-11-17 06:05:1312#include "chrome/browser/ui/browser.h"
[email protected]d8748142012-05-16 21:13:4313#include "chrome/browser/ui/browser_finder.h"
[email protected]bc44f4142013-02-12 06:15:5614#include "chrome/browser/ui/browser_iterator.h"
[email protected]f6ffa7d2012-08-17 17:27:0815#include "chrome/browser/ui/panels/panel_manager.h"
[email protected]e0448872013-01-11 19:35:0216#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]7c6ef352013-09-26 07:23:1417#include "chrome/common/chrome_paths.h"
[email protected]32b7c492010-09-01 04:15:0018#include "chrome/common/chrome_switches.h"
[email protected]b65d4bdcc2013-07-31 00:37:3319#include "chrome/test/base/test_switches.h"
[email protected]af44e7fb2011-07-29 18:32:3220#include "chrome/test/base/ui_test_utils.h"
[email protected]1dd66b72012-09-19 20:41:4821#include "content/public/browser/render_process_host.h"
[email protected]fad73672012-06-15 23:26:0622#include "content/public/browser/web_contents.h"
[email protected]1dd66b72012-09-19 20:41:4823#include "content/public/common/result_codes.h"
[email protected]99bee642014-05-31 22:36:4324#include "content/public/common/url_constants.h"
[email protected]7d478cb2012-07-24 17:19:4225#include "content/public/test/browser_test_utils.h"
[email protected]22401dc2014-03-21 01:38:5726#include "extensions/browser/extension_host.h"
[email protected]59b0e602014-01-30 00:41:2427#include "extensions/browser/extension_system.h"
[email protected]98b6d942013-11-10 00:34:0728#include "extensions/browser/process_manager.h"
[email protected]99bee642014-05-31 22:36:4329#include "extensions/common/constants.h"
[email protected]e4452d32013-11-15 23:07:4130#include "extensions/common/extension.h"
[email protected]c8d02992013-07-31 22:16:5131#include "extensions/common/switches.h"
yoze8dc2f12014-09-09 23:16:3232#include "extensions/test/result_catcher.h"
[email protected]f2cb3cf2013-03-21 01:40:5333#include "net/dns/mock_host_resolver.h"
[email protected]7c6ef352013-09-26 07:23:1434#include "net/test/embedded_test_server/embedded_test_server.h"
[email protected]bc44f4142013-02-12 06:15:5635#include "testing/gtest/include/gtest/gtest.h"
[email protected]32b7c492010-09-01 04:15:0036
[email protected]f1c102b2013-02-15 07:44:1237#if defined(USE_ASH)
hashimotoad3c6872014-08-29 09:46:5738#include "extensions/browser/app_window/app_window_registry.h"
[email protected]f1c102b2013-02-15 07:44:1239#endif
40
[email protected]15119302014-05-20 19:23:5841#if defined(USE_ASH) && defined(OS_CHROMEOS)
[email protected]f1c102b2013-02-15 07:44:1242// TODO(stevenjb): Figure out the correct behavior for Ash + Win
43#define USE_ASH_PANELS
44#endif
45
[email protected]e5d549d2011-12-28 01:29:2046using content::OpenURLParams;
47using content::Referrer;
[email protected]fad73672012-06-15 23:26:0648using content::WebContents;
[email protected]e5d549d2011-12-28 01:29:2049
[email protected]e78eb292010-12-22 08:35:3950// Disabled, http://crbug.com/64899.
51IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpen) {
[email protected]32b7c492010-09-01 04:15:0052 CommandLine::ForCurrentProcess()->AppendSwitch(
[email protected]c8d02992013-07-31 22:16:5153 extensions::switches::kEnableExperimentalExtensionApis);
[email protected]32b7c492010-09-01 04:15:0054
yoze8dc2f12014-09-09 23:16:3255 extensions::ResultCatcher catcher;
[email protected]32b7c492010-09-01 04:15:0056 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_
57 .AppendASCII("window_open").AppendASCII("spanning")));
58 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
59}
[email protected]4026ce1e2010-09-14 19:35:0460
[email protected]f1c102b2013-02-15 07:44:1261int GetPanelCount(Browser* browser) {
62#if defined(USE_ASH_PANELS)
hashimotoad3c6872014-08-29 09:46:5763 return static_cast<int>(extensions::AppWindowRegistry::Get(
64 browser->profile())->app_windows().size());
[email protected]f1c102b2013-02-15 07:44:1265#else
66 return PanelManager::GetInstance()->num_panels();
67#endif
68}
69
70bool WaitForTabsAndPopups(Browser* browser,
[email protected]f9e82d92011-10-29 00:50:4571 int num_tabs,
72 int num_popups,
73 int num_panels) {
[email protected]58b349b2011-11-23 02:07:1574 SCOPED_TRACE(
[email protected]7d3cbc92013-03-18 22:33:0475 base::StringPrintf("WaitForTabsAndPopups tabs:%d, popups:%d, panels:%d",
76 num_tabs, num_popups, num_panels));
[email protected]4026ce1e2010-09-14 19:35:0477 // We start with one tab and one browser already open.
78 ++num_tabs;
[email protected]f6ffa7d2012-08-17 17:27:0879 size_t num_browsers = static_cast<size_t>(num_popups) + 1;
[email protected]4026ce1e2010-09-14 19:35:0480
[email protected]f1c102b2013-02-15 07:44:1281 const base::TimeDelta kWaitTime = base::TimeDelta::FromSeconds(10);
[email protected]0a5bdc6522011-06-08 19:04:4982 base::TimeTicks end_time = base::TimeTicks::Now() + kWaitTime;
83 while (base::TimeTicks::Now() < end_time) {
[email protected]c987a242013-02-28 01:17:4184 if (chrome::GetBrowserCount(browser->profile(),
85 browser->host_desktop_type()) == num_browsers &&
[email protected]e0448872013-01-11 19:35:0286 browser->tab_strip_model()->count() == num_tabs &&
[email protected]f1c102b2013-02-15 07:44:1287 GetPanelCount(browser) == num_panels)
[email protected]0a5bdc6522011-06-08 19:04:4988 break;
89
[email protected]b8deecd2012-07-30 21:09:4490 content::RunAllPendingInMessageLoop();
[email protected]0a5bdc6522011-06-08 19:04:4991 }
92
[email protected]c987a242013-02-28 01:17:4193 EXPECT_EQ(num_browsers,
94 chrome::GetBrowserCount(browser->profile(),
95 browser->host_desktop_type()));
[email protected]e0448872013-01-11 19:35:0296 EXPECT_EQ(num_tabs, browser->tab_strip_model()->count());
[email protected]f1c102b2013-02-15 07:44:1297 EXPECT_EQ(num_panels, GetPanelCount(browser));
[email protected]0a5bdc6522011-06-08 19:04:4998
[email protected]f9e82d92011-10-29 00:50:4599 int num_popups_seen = 0;
[email protected]bc44f4142013-02-12 06:15:56100 for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) {
[email protected]0a5bdc6522011-06-08 19:04:49101 if (*iter == browser)
[email protected]4026ce1e2010-09-14 19:35:04102 continue;
[email protected]4026ce1e2010-09-14 19:35:04103
[email protected]f6ffa7d2012-08-17 17:27:08104 EXPECT_TRUE((*iter)->is_type_popup());
105 ++num_popups_seen;
[email protected]4026ce1e2010-09-14 19:35:04106 }
[email protected]f9e82d92011-10-29 00:50:45107 EXPECT_EQ(num_popups, num_popups_seen);
[email protected]f1c102b2013-02-15 07:44:12108
[email protected]c987a242013-02-28 01:17:41109 return ((num_browsers ==
110 chrome::GetBrowserCount(browser->profile(),
111 browser->host_desktop_type())) &&
[email protected]f1c102b2013-02-15 07:44:12112 (num_tabs == browser->tab_strip_model()->count()) &&
113 (num_panels == GetPanelCount(browser)) &&
114 (num_popups == num_popups_seen));
[email protected]4026ce1e2010-09-14 19:35:04115}
116
[email protected]f112b0f2011-05-26 01:53:52117IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserIsApp) {
118 host_resolver()->AddRule("a.com", "127.0.0.1");
[email protected]c1dffe82013-06-26 20:59:05119 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]f112b0f2011-05-26 01:53:52120 ASSERT_TRUE(LoadExtension(
121 test_data_dir_.AppendASCII("window_open").AppendASCII("browser_is_app")));
122
[email protected]f1c102b2013-02-15 07:44:12123 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 2, 0));
[email protected]f112b0f2011-05-26 01:53:52124
[email protected]bc44f4142013-02-12 06:15:56125 for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) {
[email protected]f112b0f2011-05-26 01:53:52126 if (*iter == browser())
[email protected]bc44f4142013-02-12 06:15:56127 ASSERT_FALSE(iter->is_app());
[email protected]f112b0f2011-05-26 01:53:52128 else
[email protected]bc44f4142013-02-12 06:15:56129 ASSERT_TRUE(iter->is_app());
[email protected]f112b0f2011-05-26 01:53:52130 }
131}
132
[email protected]0a5bdc6522011-06-08 19:04:49133IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupDefault) {
[email protected]c1dffe82013-06-26 20:59:05134 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]0a5bdc6522011-06-08 19:04:49135 ASSERT_TRUE(LoadExtension(
136 test_data_dir_.AppendASCII("window_open").AppendASCII("popup")));
137
138 const int num_tabs = 1;
139 const int num_popups = 0;
[email protected]f1c102b2013-02-15 07:44:12140 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0));
[email protected]0a5bdc6522011-06-08 19:04:49141}
142
[email protected]7c6ef352013-09-26 07:23:14143IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupIframe) {
144 ASSERT_TRUE(StartEmbeddedTestServer());
145 base::FilePath test_data_dir;
146 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
147 embedded_test_server()->ServeFilesFromDirectory(test_data_dir);
148 ASSERT_TRUE(LoadExtension(
149 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_iframe")));
150
jochenc5cfa642014-09-02 15:30:03151 const int num_tabs = 1;
152 const int num_popups = 0;
[email protected]7c6ef352013-09-26 07:23:14153 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0));
154}
155
[email protected]0a5bdc6522011-06-08 19:04:49156IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupLarge) {
[email protected]c1dffe82013-06-26 20:59:05157 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]0a5bdc6522011-06-08 19:04:49158 ASSERT_TRUE(LoadExtension(
159 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_large")));
160
[email protected]0a5bdc6522011-06-08 19:04:49161 // On other systems this should open a new popup window.
162 const int num_tabs = 0;
163 const int num_popups = 1;
[email protected]f1c102b2013-02-15 07:44:12164 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0));
[email protected]0a5bdc6522011-06-08 19:04:49165}
166
167IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupSmall) {
[email protected]c1dffe82013-06-26 20:59:05168 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]0a5bdc6522011-06-08 19:04:49169 ASSERT_TRUE(LoadExtension(
170 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_small")));
171
172 // On ChromeOS this should open a new panel (acts like a new popup window).
173 // On other systems this should open a new popup window.
174 const int num_tabs = 0;
175 const int num_popups = 1;
[email protected]f1c102b2013-02-15 07:44:12176 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0));
[email protected]0a5bdc6522011-06-08 19:04:49177}
178
[email protected]73fa1fce2013-02-21 20:10:05179// Disabled on Windows. Often times out or fails: crbug.com/177530
180#if defined(OS_WIN)
181#define MAYBE_PopupBlockingExtension DISABLED_PopupBlockingExtension
182#else
183#define MAYBE_PopupBlockingExtension PopupBlockingExtension
184#endif
185IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_PopupBlockingExtension) {
[email protected]4026ce1e2010-09-14 19:35:04186 host_resolver()->AddRule("*", "127.0.0.1");
[email protected]c1dffe82013-06-26 20:59:05187 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]4026ce1e2010-09-14 19:35:04188
189 ASSERT_TRUE(LoadExtension(
190 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking")
191 .AppendASCII("extension")));
192
[email protected]f1c102b2013-02-15 07:44:12193 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 5, 3, 0));
[email protected]4026ce1e2010-09-14 19:35:04194}
195
196IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PopupBlockingHostedApp) {
197 host_resolver()->AddRule("*", "127.0.0.1");
198 ASSERT_TRUE(test_server()->Start());
199
200 ASSERT_TRUE(LoadExtension(
201 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking")
202 .AppendASCII("hosted_app")));
203
[email protected]fe3048872010-10-18 14:58:59204 // The app being tested owns the domain a.com . The test URLs we navigate
205 // to below must be within that domain, so that they fall within the app's
206 // web extent.
207 GURL::Replacements replace_host;
208 std::string a_dot_com = "a.com";
209 replace_host.SetHostStr(a_dot_com);
210
211 const std::string popup_app_contents_path(
212 "files/extensions/api_test/window_open/popup_blocking/hosted_app/");
213
214 GURL open_tab =
215 test_server()->GetURL(popup_app_contents_path + "open_tab.html")
216 .ReplaceComponents(replace_host);
217 GURL open_popup =
218 test_server()->GetURL(popup_app_contents_path + "open_popup.html")
219 .ReplaceComponents(replace_host);
220
[email protected]e5d549d2011-12-28 01:29:20221 browser()->OpenURL(OpenURLParams(
222 open_tab, Referrer(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED,
223 false));
224 browser()->OpenURL(OpenURLParams(
225 open_popup, Referrer(), NEW_FOREGROUND_TAB,
226 content::PAGE_TRANSITION_TYPED, false));
[email protected]4026ce1e2010-09-14 19:35:04227
[email protected]f1c102b2013-02-15 07:44:12228 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 3, 1, 0));
[email protected]4026ce1e2010-09-14 19:35:04229}
[email protected]d4db6c702011-03-28 21:49:14230
[email protected]e7f90562011-05-23 21:38:24231IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowArgumentsOverflow) {
232 ASSERT_TRUE(RunExtensionTest("window_open/argument_overflow")) << message_;
233}
234
[email protected]d5c14062011-10-27 00:02:13235class WindowOpenPanelDisabledTest : public ExtensionApiTest {
[email protected]49aeab62013-02-07 02:53:11236 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
[email protected]08aa0c32011-04-11 22:18:37237 ExtensionApiTest::SetUpCommandLine(command_line);
[email protected]7e7a28092011-12-09 22:24:55238 // TODO(jennb): Re-enable when panels are enabled by default.
239 // command_line->AppendSwitch(switches::kDisablePanels);
[email protected]08aa0c32011-04-11 22:18:37240 }
241};
242
[email protected]7e7a28092011-12-09 22:24:55243IN_PROC_BROWSER_TEST_F(WindowOpenPanelDisabledTest,
244 DISABLED_WindowOpenPanelNotEnabled) {
[email protected]d5c14062011-10-27 00:02:13245 ASSERT_TRUE(RunExtensionTest("window_open/panel_not_enabled")) << message_;
246}
247
[email protected]af6b54512011-12-14 06:11:21248class WindowOpenPanelTest : public ExtensionApiTest {
[email protected]49aeab62013-02-07 02:53:11249 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
[email protected]af6b54512011-12-14 06:11:21250 ExtensionApiTest::SetUpCommandLine(command_line);
251 command_line->AppendSwitch(switches::kEnablePanels);
252 }
253};
254
[email protected]f1c102b2013-02-15 07:44:12255#if defined(USE_ASH_PANELS)
[email protected]87d722a2012-07-12 15:38:33256// On Ash, this currently fails because we're currently opening new panel
[email protected]d101b0c2012-03-16 00:30:57257// windows as popup windows instead.
[email protected]e00ccc92012-11-01 17:32:30258#define MAYBE_WindowOpenPanel DISABLED_WindowOpenPanel
[email protected]d101b0c2012-03-16 00:30:57259#else
260#define MAYBE_WindowOpenPanel WindowOpenPanel
261#endif
262IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenPanel) {
[email protected]08aa0c32011-04-11 22:18:37263 ASSERT_TRUE(RunExtensionTest("window_open/panel")) << message_;
264}
[email protected]54edcea2011-07-27 01:56:38265
[email protected]a60837b2014-03-11 03:49:20266#if defined(USE_ASH_PANELS) || defined(OS_LINUX)
[email protected]ca29ed12012-09-06 09:10:50267// On Ash, this currently fails because we're currently opening new panel
268// windows as popup windows instead.
[email protected]a60837b2014-03-11 03:49:20269// We're also failing on Linux-aura due to the panel is not opened in the
270// right origin.
[email protected]cb1849e2013-07-08 21:12:53271#define MAYBE_WindowOpenPanelDetached DISABLED_WindowOpenPanelDetached
272#else
273#define MAYBE_WindowOpenPanelDetached WindowOpenPanelDetached
274#endif
275IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenPanelDetached) {
[email protected]ca29ed12012-09-06 09:10:50276 ASSERT_TRUE(RunExtensionTest("window_open/panel_detached")) << message_;
277}
278
[email protected]15119302014-05-20 19:23:58279#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
280// TODO(erg): Bring up ash http://crbug.com/300084
281#define MAYBE_CloseNonExtensionPanelsOnUninstall \
282 DISABLED_CloseNonExtensionPanelsOnUninstall
283#else
284#define MAYBE_CloseNonExtensionPanelsOnUninstall \
285 CloseNonExtensionPanelsOnUninstall
286#endif
[email protected]af6b54512011-12-14 06:11:21287IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest,
[email protected]15119302014-05-20 19:23:58288 MAYBE_CloseNonExtensionPanelsOnUninstall) {
[email protected]45c6f6722013-07-23 03:02:19289#if defined(OS_WIN) && defined(USE_ASH)
290 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
[email protected]b65d4bdcc2013-07-31 00:37:33291 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
[email protected]45c6f6722013-07-23 03:02:19292 return;
293#endif
294
[email protected]f1c102b2013-02-15 07:44:12295#if defined(USE_ASH_PANELS)
[email protected]1dd66b72012-09-19 20:41:48296 // On Ash, new panel windows open as popup windows instead.
[email protected]f1c102b2013-02-15 07:44:12297 int num_popups, num_panels;
298 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePanels)) {
299 num_popups = 2;
300 num_panels = 2;
301 } else {
302 num_popups = 4;
303 num_panels = 0;
304 }
[email protected]1dd66b72012-09-19 20:41:48305#else
306 int num_popups = 2;
307 int num_panels = 2;
308#endif
[email protected]c1dffe82013-06-26 20:59:05309 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]1dd66b72012-09-19 20:41:48310
311 // Setup listeners to wait on strings we expect the extension pages to send.
312 std::vector<std::string> test_strings;
313 test_strings.push_back("content_tab");
314 if (num_panels)
315 test_strings.push_back("content_panel");
316 test_strings.push_back("content_popup");
317
318 ScopedVector<ExtensionTestMessageListener> listeners;
319 for (size_t i = 0; i < test_strings.size(); ++i) {
320 listeners.push_back(
321 new ExtensionTestMessageListener(test_strings[i], false));
322 }
323
324 const extensions::Extension* extension = LoadExtension(
325 test_data_dir_.AppendASCII("window_open").AppendASCII(
326 "close_panels_on_uninstall"));
327 ASSERT_TRUE(extension);
328
329 // Two tabs. One in extension domain and one in non-extension domain.
330 // Two popups - one in extension domain and one in non-extension domain.
331 // Two panels - one in extension domain and one in non-extension domain.
[email protected]f1c102b2013-02-15 07:44:12332 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, num_panels));
[email protected]4cdd8572013-02-15 00:33:25333
334 // Wait on test messages to make sure the pages loaded.
335 for (size_t i = 0; i < listeners.size(); ++i)
336 ASSERT_TRUE(listeners[i]->WaitUntilSatisfied());
337
338 UninstallExtension(extension->id());
339
340 // Wait for the tabs and popups in non-extension domain to stay open.
341 // Expect everything else, including panels, to close.
[email protected]4cdd8572013-02-15 00:33:25342 num_popups -= 1;
[email protected]f1c102b2013-02-15 07:44:12343#if defined(USE_ASH_PANELS)
344 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePanels)) {
345 // On Ash, new panel windows open as popup windows instead, so there are 2
346 // extension domain popups that will close (instead of 1 popup on non-Ash).
347 num_popups -= 1;
348 }
[email protected]4cdd8572013-02-15 00:33:25349#endif
[email protected]9111fff2013-06-12 18:01:55350#if defined(USE_ASH)
351#if !defined(OS_WIN)
352 // On linux ash we close all popup applications when closing its extension.
353 num_popups = 0;
354#endif
355#endif
[email protected]f1c102b2013-02-15 07:44:12356 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 1, num_popups, 0));
[email protected]4cdd8572013-02-15 00:33:25357}
358
[email protected]15119302014-05-20 19:23:58359// This test isn't applicable on Chrome OS, which automatically reloads crashed
360// pages.
[email protected]4ad85f42013-07-24 02:31:57361#if !defined(OS_CHROMEOS)
362IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, ClosePanelsOnExtensionCrash) {
[email protected]f1c102b2013-02-15 07:44:12363#if defined(USE_ASH_PANELS)
[email protected]4cdd8572013-02-15 00:33:25364 // On Ash, new panel windows open as popup windows instead.
365 int num_popups = 4;
366 int num_panels = 0;
367#else
368 int num_popups = 2;
369 int num_panels = 2;
370#endif
[email protected]c1dffe82013-06-26 20:59:05371 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]4cdd8572013-02-15 00:33:25372
373 // Setup listeners to wait on strings we expect the extension pages to send.
374 std::vector<std::string> test_strings;
375 test_strings.push_back("content_tab");
376 if (num_panels)
377 test_strings.push_back("content_panel");
378 test_strings.push_back("content_popup");
379
380 ScopedVector<ExtensionTestMessageListener> listeners;
381 for (size_t i = 0; i < test_strings.size(); ++i) {
382 listeners.push_back(
383 new ExtensionTestMessageListener(test_strings[i], false));
384 }
385
386 const extensions::Extension* extension = LoadExtension(
387 test_data_dir_.AppendASCII("window_open").AppendASCII(
388 "close_panels_on_uninstall"));
389 ASSERT_TRUE(extension);
390
391 // Two tabs. One in extension domain and one in non-extension domain.
392 // Two popups - one in extension domain and one in non-extension domain.
393 // Two panels - one in extension domain and one in non-extension domain.
[email protected]f1c102b2013-02-15 07:44:12394 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, num_panels));
[email protected]1dd66b72012-09-19 20:41:48395
396 // Wait on test messages to make sure the pages loaded.
397 for (size_t i = 0; i < listeners.size(); ++i)
398 ASSERT_TRUE(listeners[i]->WaitUntilSatisfied());
399
400 // Crash the extension.
401 extensions::ExtensionHost* extension_host =
[email protected]be93bba02012-10-24 16:44:03402 extensions::ExtensionSystem::Get(browser()->profile())->
403 process_manager()->GetBackgroundHostForExtension(extension->id());
[email protected]1dd66b72012-09-19 20:41:48404 ASSERT_TRUE(extension_host);
405 base::KillProcess(extension_host->render_process_host()->GetHandle(),
406 content::RESULT_CODE_KILLED, false);
407 WaitForExtensionCrash(extension->id());
408
409 // Only expect panels to close. The rest stay open to show a sad-tab.
[email protected]f1c102b2013-02-15 07:44:12410 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, 0));
[email protected]1dd66b72012-09-19 20:41:48411}
[email protected]4ad85f42013-07-24 02:31:57412#endif // !defined(OS_CHROMEOS)
[email protected]1dd66b72012-09-19 20:41:48413
[email protected]f1c102b2013-02-15 07:44:12414#if defined(USE_ASH_PANELS)
415// This test is not applicable on Ash. The modified window.open behavior only
416// applies to non-Ash panel windows.
[email protected]99f4fdb92012-08-30 23:13:51417#define MAYBE_WindowOpenFromPanel DISABLED_WindowOpenFromPanel
418#else
419#define MAYBE_WindowOpenFromPanel WindowOpenFromPanel
420#endif
421IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenFromPanel) {
[email protected]c1dffe82013-06-26 20:59:05422 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]6798c332012-08-29 02:16:51423
[email protected]99f4fdb92012-08-30 23:13:51424 // Load the extension that will open a panel which then calls window.open.
[email protected]6798c332012-08-29 02:16:51425 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("window_open").
426 AppendASCII("panel_window_open")));
[email protected]99f4fdb92012-08-30 23:13:51427
428 // Expect one panel (opened by extension) and one tab (from the panel calling
429 // window.open). Panels modify the WindowOpenDisposition in window.open
430 // to always open in a tab.
[email protected]f1c102b2013-02-15 07:44:12431 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 1, 0, 1));
[email protected]6798c332012-08-29 02:16:51432}
433
[email protected]24c6bcfc2012-02-29 21:06:36434IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpener) {
[email protected]54edcea2011-07-27 01:56:38435 ASSERT_TRUE(RunExtensionTest("window_open/opener")) << message_;
436}
[email protected]fad73672012-06-15 23:26:06437
[email protected]fa7c1602013-04-03 23:00:20438#if defined(OS_MACOSX)
439// Extension popup windows are incorrectly sized on OSX, crbug.com/225601
440#define MAYBE_WindowOpenSized DISABLED_WindowOpenSized
441#else
442#define MAYBE_WindowOpenSized WindowOpenSized
443#endif
444// Ensure that the width and height properties of a window opened with
445// chrome.windows.create match the creation parameters. See crbug.com/173831.
446IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_WindowOpenSized) {
447 ASSERT_TRUE(RunExtensionTest("window_open/window_size")) << message_;
448 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 1, 0));
449}
450
[email protected]fad73672012-06-15 23:26:06451// Tests that an extension page can call window.open to an extension URL and
452// the new window has extension privileges.
453IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenExtension) {
454 ASSERT_TRUE(LoadExtension(
455 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
456
[email protected]99bee642014-05-31 22:36:43457 GURL start_url(std::string(extensions::kExtensionScheme) +
[email protected]fb4fe0952014-06-05 09:44:24458 url::kStandardSchemeSeparator +
[email protected]99bee642014-05-31 22:36:43459 last_loaded_extension_id() + "/test.html");
[email protected]fad73672012-06-15 23:26:06460 ui_test_utils::NavigateToURL(browser(), start_url);
[email protected]f3e73f62012-10-20 05:35:16461 WebContents* newtab = NULL;
[email protected]e0448872013-01-11 19:35:02462 ASSERT_NO_FATAL_FAILURE(
463 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(),
464 start_url.Resolve("newtab.html"), true, &newtab));
[email protected]fad73672012-06-15 23:26:06465
466 bool result = false;
[email protected]b6987e02013-01-04 18:30:43467 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()",
468 &result));
[email protected]fad73672012-06-15 23:26:06469 EXPECT_TRUE(result);
470}
471
472// Tests that if an extension page calls window.open to an invalid extension
473// URL, the browser doesn't crash.
474IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) {
475 ASSERT_TRUE(LoadExtension(
476 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
477
[email protected]99bee642014-05-31 22:36:43478 GURL start_url(std::string(extensions::kExtensionScheme) +
[email protected]fb4fe0952014-06-05 09:44:24479 url::kStandardSchemeSeparator +
[email protected]99bee642014-05-31 22:36:43480 last_loaded_extension_id() + "/test.html");
[email protected]fad73672012-06-15 23:26:06481 ui_test_utils::NavigateToURL(browser(), start_url);
[email protected]e0448872013-01-11 19:35:02482 ASSERT_NO_FATAL_FAILURE(
483 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]fad73672012-06-15 23:26:06484 GURL("chrome-extension://thisissurelynotavalidextensionid/newtab.html"),
485 false, NULL));
486
487 // If we got to this point, we didn't crash, so we're good.
488}
489
490// Tests that calling window.open from the newtab page to an extension URL
491// gives the new window extension privileges - even though the opening page
492// does not have extension privileges, we break the script connection, so
493// there is no privilege leak.
494IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) {
495 ASSERT_TRUE(LoadExtension(
496 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
497
498 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
[email protected]f3e73f62012-10-20 05:35:16499 WebContents* newtab = NULL;
[email protected]e0448872013-01-11 19:35:02500 ASSERT_NO_FATAL_FAILURE(
501 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]99bee642014-05-31 22:36:43502 GURL(std::string(extensions::kExtensionScheme) +
[email protected]fb4fe0952014-06-05 09:44:24503 url::kStandardSchemeSeparator +
[email protected]99bee642014-05-31 22:36:43504 last_loaded_extension_id() + "/newtab.html"),
505 false,
506 &newtab));
[email protected]fad73672012-06-15 23:26:06507
508 // Extension API should succeed.
509 bool result = false;
[email protected]b6987e02013-01-04 18:30:43510 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()",
511 &result));
[email protected]fad73672012-06-15 23:26:06512 EXPECT_TRUE(result);
513}