blob: aa34d26972a45b89647a70403cc5eb33d91e7181 [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]01996a592013-09-13 06:55:0410#include "chrome/browser/profiles/profile.h"
[email protected]2ad4a902010-11-17 06:05:1311#include "chrome/browser/ui/browser.h"
[email protected]d8748142012-05-16 21:13:4312#include "chrome/browser/ui/browser_finder.h"
[email protected]bc44f4142013-02-12 06:15:5613#include "chrome/browser/ui/browser_iterator.h"
[email protected]f6ffa7d2012-08-17 17:27:0814#include "chrome/browser/ui/panels/panel_manager.h"
[email protected]e0448872013-01-11 19:35:0215#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]7c6ef352013-09-26 07:23:1416#include "chrome/common/chrome_paths.h"
[email protected]32b7c492010-09-01 04:15:0017#include "chrome/common/chrome_switches.h"
[email protected]b65d4bdcc2013-07-31 00:37:3318#include "chrome/test/base/test_switches.h"
[email protected]af44e7fb2011-07-29 18:32:3219#include "chrome/test/base/ui_test_utils.h"
[email protected]1dd66b72012-09-19 20:41:4820#include "content/public/browser/render_process_host.h"
[email protected]fad73672012-06-15 23:26:0621#include "content/public/browser/web_contents.h"
[email protected]1dd66b72012-09-19 20:41:4822#include "content/public/common/result_codes.h"
[email protected]99bee642014-05-31 22:36:4323#include "content/public/common/url_constants.h"
[email protected]7d478cb2012-07-24 17:19:4224#include "content/public/test/browser_test_utils.h"
[email protected]22401dc2014-03-21 01:38:5725#include "extensions/browser/extension_host.h"
[email protected]98b6d942013-11-10 00:34:0726#include "extensions/browser/process_manager.h"
[email protected]99bee642014-05-31 22:36:4327#include "extensions/common/constants.h"
[email protected]e4452d32013-11-15 23:07:4128#include "extensions/common/extension.h"
[email protected]c8d02992013-07-31 22:16:5129#include "extensions/common/switches.h"
lfg910f2f92014-09-19 05:31:0930#include "extensions/test/extension_test_message_listener.h"
yoze8dc2f12014-09-09 23:16:3231#include "extensions/test/result_catcher.h"
[email protected]f2cb3cf2013-03-21 01:40:5332#include "net/dns/mock_host_resolver.h"
[email protected]7c6ef352013-09-26 07:23:1433#include "net/test/embedded_test_server/embedded_test_server.h"
[email protected]bc44f4142013-02-12 06:15:5634#include "testing/gtest/include/gtest/gtest.h"
[email protected]32b7c492010-09-01 04:15:0035
[email protected]f1c102b2013-02-15 07:44:1236#if defined(USE_ASH)
hashimotoad3c6872014-08-29 09:46:5737#include "extensions/browser/app_window/app_window_registry.h"
[email protected]f1c102b2013-02-15 07:44:1238#endif
39
[email protected]15119302014-05-20 19:23:5840#if defined(USE_ASH) && defined(OS_CHROMEOS)
[email protected]f1c102b2013-02-15 07:44:1241// TODO(stevenjb): Figure out the correct behavior for Ash + Win
42#define USE_ASH_PANELS
43#endif
44
[email protected]e5d549d2011-12-28 01:29:2045using content::OpenURLParams;
46using content::Referrer;
[email protected]fad73672012-06-15 23:26:0647using content::WebContents;
[email protected]e5d549d2011-12-28 01:29:2048
[email protected]e78eb292010-12-22 08:35:3949// Disabled, http://crbug.com/64899.
50IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpen) {
[email protected]32b7c492010-09-01 04:15:0051 CommandLine::ForCurrentProcess()->AppendSwitch(
[email protected]c8d02992013-07-31 22:16:5152 extensions::switches::kEnableExperimentalExtensionApis);
[email protected]32b7c492010-09-01 04:15:0053
yoze8dc2f12014-09-09 23:16:3254 extensions::ResultCatcher catcher;
[email protected]32b7c492010-09-01 04:15:0055 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_
56 .AppendASCII("window_open").AppendASCII("spanning")));
57 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
58}
[email protected]4026ce1e2010-09-14 19:35:0459
[email protected]f1c102b2013-02-15 07:44:1260int GetPanelCount(Browser* browser) {
61#if defined(USE_ASH_PANELS)
hashimotoad3c6872014-08-29 09:46:5762 return static_cast<int>(extensions::AppWindowRegistry::Get(
63 browser->profile())->app_windows().size());
[email protected]f1c102b2013-02-15 07:44:1264#else
65 return PanelManager::GetInstance()->num_panels();
66#endif
67}
68
69bool WaitForTabsAndPopups(Browser* browser,
[email protected]f9e82d92011-10-29 00:50:4570 int num_tabs,
71 int num_popups,
72 int num_panels) {
[email protected]58b349b2011-11-23 02:07:1573 SCOPED_TRACE(
[email protected]7d3cbc92013-03-18 22:33:0474 base::StringPrintf("WaitForTabsAndPopups tabs:%d, popups:%d, panels:%d",
75 num_tabs, num_popups, num_panels));
[email protected]4026ce1e2010-09-14 19:35:0476 // We start with one tab and one browser already open.
77 ++num_tabs;
[email protected]f6ffa7d2012-08-17 17:27:0878 size_t num_browsers = static_cast<size_t>(num_popups) + 1;
[email protected]4026ce1e2010-09-14 19:35:0479
[email protected]f1c102b2013-02-15 07:44:1280 const base::TimeDelta kWaitTime = base::TimeDelta::FromSeconds(10);
[email protected]0a5bdc6522011-06-08 19:04:4981 base::TimeTicks end_time = base::TimeTicks::Now() + kWaitTime;
82 while (base::TimeTicks::Now() < end_time) {
[email protected]c987a242013-02-28 01:17:4183 if (chrome::GetBrowserCount(browser->profile(),
84 browser->host_desktop_type()) == num_browsers &&
[email protected]e0448872013-01-11 19:35:0285 browser->tab_strip_model()->count() == num_tabs &&
[email protected]f1c102b2013-02-15 07:44:1286 GetPanelCount(browser) == num_panels)
[email protected]0a5bdc6522011-06-08 19:04:4987 break;
88
[email protected]b8deecd2012-07-30 21:09:4489 content::RunAllPendingInMessageLoop();
[email protected]0a5bdc6522011-06-08 19:04:4990 }
91
[email protected]c987a242013-02-28 01:17:4192 EXPECT_EQ(num_browsers,
93 chrome::GetBrowserCount(browser->profile(),
94 browser->host_desktop_type()));
[email protected]e0448872013-01-11 19:35:0295 EXPECT_EQ(num_tabs, browser->tab_strip_model()->count());
[email protected]f1c102b2013-02-15 07:44:1296 EXPECT_EQ(num_panels, GetPanelCount(browser));
[email protected]0a5bdc6522011-06-08 19:04:4997
[email protected]f9e82d92011-10-29 00:50:4598 int num_popups_seen = 0;
[email protected]bc44f4142013-02-12 06:15:5699 for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) {
[email protected]0a5bdc6522011-06-08 19:04:49100 if (*iter == browser)
[email protected]4026ce1e2010-09-14 19:35:04101 continue;
[email protected]4026ce1e2010-09-14 19:35:04102
[email protected]f6ffa7d2012-08-17 17:27:08103 EXPECT_TRUE((*iter)->is_type_popup());
104 ++num_popups_seen;
[email protected]4026ce1e2010-09-14 19:35:04105 }
[email protected]f9e82d92011-10-29 00:50:45106 EXPECT_EQ(num_popups, num_popups_seen);
[email protected]f1c102b2013-02-15 07:44:12107
[email protected]c987a242013-02-28 01:17:41108 return ((num_browsers ==
109 chrome::GetBrowserCount(browser->profile(),
110 browser->host_desktop_type())) &&
[email protected]f1c102b2013-02-15 07:44:12111 (num_tabs == browser->tab_strip_model()->count()) &&
112 (num_panels == GetPanelCount(browser)) &&
113 (num_popups == num_popups_seen));
[email protected]4026ce1e2010-09-14 19:35:04114}
115
[email protected]f112b0f2011-05-26 01:53:52116IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserIsApp) {
117 host_resolver()->AddRule("a.com", "127.0.0.1");
[email protected]c1dffe82013-06-26 20:59:05118 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]f112b0f2011-05-26 01:53:52119 ASSERT_TRUE(LoadExtension(
120 test_data_dir_.AppendASCII("window_open").AppendASCII("browser_is_app")));
121
[email protected]f1c102b2013-02-15 07:44:12122 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 2, 0));
[email protected]f112b0f2011-05-26 01:53:52123
[email protected]bc44f4142013-02-12 06:15:56124 for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) {
[email protected]f112b0f2011-05-26 01:53:52125 if (*iter == browser())
[email protected]bc44f4142013-02-12 06:15:56126 ASSERT_FALSE(iter->is_app());
[email protected]f112b0f2011-05-26 01:53:52127 else
[email protected]bc44f4142013-02-12 06:15:56128 ASSERT_TRUE(iter->is_app());
[email protected]f112b0f2011-05-26 01:53:52129 }
130}
131
[email protected]0a5bdc6522011-06-08 19:04:49132IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupDefault) {
[email protected]c1dffe82013-06-26 20:59:05133 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]0a5bdc6522011-06-08 19:04:49134 ASSERT_TRUE(LoadExtension(
135 test_data_dir_.AppendASCII("window_open").AppendASCII("popup")));
136
137 const int num_tabs = 1;
138 const int num_popups = 0;
[email protected]f1c102b2013-02-15 07:44:12139 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0));
[email protected]0a5bdc6522011-06-08 19:04:49140}
141
[email protected]7c6ef352013-09-26 07:23:14142IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupIframe) {
143 ASSERT_TRUE(StartEmbeddedTestServer());
144 base::FilePath test_data_dir;
145 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
146 embedded_test_server()->ServeFilesFromDirectory(test_data_dir);
147 ASSERT_TRUE(LoadExtension(
148 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_iframe")));
149
jochenc5cfa642014-09-02 15:30:03150 const int num_tabs = 1;
151 const int num_popups = 0;
[email protected]7c6ef352013-09-26 07:23:14152 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0));
153}
154
[email protected]0a5bdc6522011-06-08 19:04:49155IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupLarge) {
[email protected]c1dffe82013-06-26 20:59:05156 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]0a5bdc6522011-06-08 19:04:49157 ASSERT_TRUE(LoadExtension(
158 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_large")));
159
[email protected]0a5bdc6522011-06-08 19:04:49160 // On other systems this should open a new popup window.
161 const int num_tabs = 0;
162 const int num_popups = 1;
[email protected]f1c102b2013-02-15 07:44:12163 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0));
[email protected]0a5bdc6522011-06-08 19:04:49164}
165
166IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupSmall) {
[email protected]c1dffe82013-06-26 20:59:05167 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]0a5bdc6522011-06-08 19:04:49168 ASSERT_TRUE(LoadExtension(
169 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_small")));
170
171 // On ChromeOS this should open a new panel (acts like a new popup window).
172 // On other systems this should open a new popup window.
173 const int num_tabs = 0;
174 const int num_popups = 1;
[email protected]f1c102b2013-02-15 07:44:12175 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0));
[email protected]0a5bdc6522011-06-08 19:04:49176}
177
[email protected]73fa1fce2013-02-21 20:10:05178// Disabled on Windows. Often times out or fails: crbug.com/177530
179#if defined(OS_WIN)
180#define MAYBE_PopupBlockingExtension DISABLED_PopupBlockingExtension
181#else
182#define MAYBE_PopupBlockingExtension PopupBlockingExtension
183#endif
184IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_PopupBlockingExtension) {
[email protected]4026ce1e2010-09-14 19:35:04185 host_resolver()->AddRule("*", "127.0.0.1");
[email protected]c1dffe82013-06-26 20:59:05186 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]4026ce1e2010-09-14 19:35:04187
188 ASSERT_TRUE(LoadExtension(
189 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking")
190 .AppendASCII("extension")));
191
[email protected]f1c102b2013-02-15 07:44:12192 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 5, 3, 0));
[email protected]4026ce1e2010-09-14 19:35:04193}
194
195IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PopupBlockingHostedApp) {
196 host_resolver()->AddRule("*", "127.0.0.1");
197 ASSERT_TRUE(test_server()->Start());
198
199 ASSERT_TRUE(LoadExtension(
200 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking")
201 .AppendASCII("hosted_app")));
202
[email protected]fe3048872010-10-18 14:58:59203 // The app being tested owns the domain a.com . The test URLs we navigate
204 // to below must be within that domain, so that they fall within the app's
205 // web extent.
206 GURL::Replacements replace_host;
207 std::string a_dot_com = "a.com";
208 replace_host.SetHostStr(a_dot_com);
209
210 const std::string popup_app_contents_path(
211 "files/extensions/api_test/window_open/popup_blocking/hosted_app/");
212
213 GURL open_tab =
214 test_server()->GetURL(popup_app_contents_path + "open_tab.html")
215 .ReplaceComponents(replace_host);
216 GURL open_popup =
217 test_server()->GetURL(popup_app_contents_path + "open_popup.html")
218 .ReplaceComponents(replace_host);
219
[email protected]e5d549d2011-12-28 01:29:20220 browser()->OpenURL(OpenURLParams(
Sylvain Defresnec6ccc77d2014-09-19 10:19:35221 open_tab, Referrer(), NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_TYPED,
[email protected]e5d549d2011-12-28 01:29:20222 false));
223 browser()->OpenURL(OpenURLParams(
224 open_popup, Referrer(), NEW_FOREGROUND_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35225 ui::PAGE_TRANSITION_TYPED, false));
[email protected]4026ce1e2010-09-14 19:35:04226
[email protected]f1c102b2013-02-15 07:44:12227 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 3, 1, 0));
[email protected]4026ce1e2010-09-14 19:35:04228}
[email protected]d4db6c702011-03-28 21:49:14229
[email protected]e7f90562011-05-23 21:38:24230IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowArgumentsOverflow) {
231 ASSERT_TRUE(RunExtensionTest("window_open/argument_overflow")) << message_;
232}
233
[email protected]d5c14062011-10-27 00:02:13234class WindowOpenPanelDisabledTest : public ExtensionApiTest {
dchengae36a4a2014-10-21 12:36:36235 void SetUpCommandLine(CommandLine* command_line) override {
[email protected]08aa0c32011-04-11 22:18:37236 ExtensionApiTest::SetUpCommandLine(command_line);
[email protected]7e7a28092011-12-09 22:24:55237 // TODO(jennb): Re-enable when panels are enabled by default.
238 // command_line->AppendSwitch(switches::kDisablePanels);
[email protected]08aa0c32011-04-11 22:18:37239 }
240};
241
[email protected]7e7a28092011-12-09 22:24:55242IN_PROC_BROWSER_TEST_F(WindowOpenPanelDisabledTest,
243 DISABLED_WindowOpenPanelNotEnabled) {
[email protected]d5c14062011-10-27 00:02:13244 ASSERT_TRUE(RunExtensionTest("window_open/panel_not_enabled")) << message_;
245}
246
[email protected]af6b54512011-12-14 06:11:21247class WindowOpenPanelTest : public ExtensionApiTest {
dchengae36a4a2014-10-21 12:36:36248 void SetUpCommandLine(CommandLine* command_line) override {
[email protected]af6b54512011-12-14 06:11:21249 ExtensionApiTest::SetUpCommandLine(command_line);
250 command_line->AppendSwitch(switches::kEnablePanels);
251 }
252};
253
[email protected]f1c102b2013-02-15 07:44:12254#if defined(USE_ASH_PANELS)
[email protected]87d722a2012-07-12 15:38:33255// On Ash, this currently fails because we're currently opening new panel
[email protected]d101b0c2012-03-16 00:30:57256// windows as popup windows instead.
[email protected]e00ccc92012-11-01 17:32:30257#define MAYBE_WindowOpenPanel DISABLED_WindowOpenPanel
[email protected]d101b0c2012-03-16 00:30:57258#else
259#define MAYBE_WindowOpenPanel WindowOpenPanel
260#endif
261IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenPanel) {
[email protected]08aa0c32011-04-11 22:18:37262 ASSERT_TRUE(RunExtensionTest("window_open/panel")) << message_;
263}
[email protected]54edcea2011-07-27 01:56:38264
[email protected]a60837b2014-03-11 03:49:20265#if defined(USE_ASH_PANELS) || defined(OS_LINUX)
[email protected]ca29ed12012-09-06 09:10:50266// On Ash, this currently fails because we're currently opening new panel
267// windows as popup windows instead.
[email protected]a60837b2014-03-11 03:49:20268// We're also failing on Linux-aura due to the panel is not opened in the
269// right origin.
[email protected]cb1849e2013-07-08 21:12:53270#define MAYBE_WindowOpenPanelDetached DISABLED_WindowOpenPanelDetached
271#else
272#define MAYBE_WindowOpenPanelDetached WindowOpenPanelDetached
273#endif
274IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenPanelDetached) {
[email protected]ca29ed12012-09-06 09:10:50275 ASSERT_TRUE(RunExtensionTest("window_open/panel_detached")) << message_;
276}
277
[email protected]15119302014-05-20 19:23:58278#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
279// TODO(erg): Bring up ash http://crbug.com/300084
280#define MAYBE_CloseNonExtensionPanelsOnUninstall \
281 DISABLED_CloseNonExtensionPanelsOnUninstall
282#else
283#define MAYBE_CloseNonExtensionPanelsOnUninstall \
284 CloseNonExtensionPanelsOnUninstall
285#endif
[email protected]af6b54512011-12-14 06:11:21286IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest,
[email protected]15119302014-05-20 19:23:58287 MAYBE_CloseNonExtensionPanelsOnUninstall) {
[email protected]45c6f6722013-07-23 03:02:19288#if defined(OS_WIN) && defined(USE_ASH)
289 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
[email protected]b65d4bdcc2013-07-31 00:37:33290 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
[email protected]45c6f6722013-07-23 03:02:19291 return;
292#endif
293
[email protected]f1c102b2013-02-15 07:44:12294#if defined(USE_ASH_PANELS)
[email protected]1dd66b72012-09-19 20:41:48295 // On Ash, new panel windows open as popup windows instead.
[email protected]f1c102b2013-02-15 07:44:12296 int num_popups, num_panels;
297 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePanels)) {
298 num_popups = 2;
299 num_panels = 2;
300 } else {
301 num_popups = 4;
302 num_panels = 0;
303 }
[email protected]1dd66b72012-09-19 20:41:48304#else
305 int num_popups = 2;
306 int num_panels = 2;
307#endif
[email protected]c1dffe82013-06-26 20:59:05308 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]1dd66b72012-09-19 20:41:48309
310 // Setup listeners to wait on strings we expect the extension pages to send.
311 std::vector<std::string> test_strings;
312 test_strings.push_back("content_tab");
313 if (num_panels)
314 test_strings.push_back("content_panel");
315 test_strings.push_back("content_popup");
316
317 ScopedVector<ExtensionTestMessageListener> listeners;
318 for (size_t i = 0; i < test_strings.size(); ++i) {
319 listeners.push_back(
320 new ExtensionTestMessageListener(test_strings[i], false));
321 }
322
323 const extensions::Extension* extension = LoadExtension(
324 test_data_dir_.AppendASCII("window_open").AppendASCII(
325 "close_panels_on_uninstall"));
326 ASSERT_TRUE(extension);
327
328 // Two tabs. One in extension domain and one in non-extension domain.
329 // Two popups - one in extension domain and one in non-extension domain.
330 // Two panels - one in extension domain and one in non-extension domain.
[email protected]f1c102b2013-02-15 07:44:12331 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, num_panels));
[email protected]4cdd8572013-02-15 00:33:25332
333 // Wait on test messages to make sure the pages loaded.
334 for (size_t i = 0; i < listeners.size(); ++i)
335 ASSERT_TRUE(listeners[i]->WaitUntilSatisfied());
336
337 UninstallExtension(extension->id());
338
339 // Wait for the tabs and popups in non-extension domain to stay open.
340 // Expect everything else, including panels, to close.
[email protected]4cdd8572013-02-15 00:33:25341 num_popups -= 1;
[email protected]f1c102b2013-02-15 07:44:12342#if defined(USE_ASH_PANELS)
343 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePanels)) {
344 // On Ash, new panel windows open as popup windows instead, so there are 2
345 // extension domain popups that will close (instead of 1 popup on non-Ash).
346 num_popups -= 1;
347 }
[email protected]4cdd8572013-02-15 00:33:25348#endif
[email protected]9111fff2013-06-12 18:01:55349#if defined(USE_ASH)
350#if !defined(OS_WIN)
351 // On linux ash we close all popup applications when closing its extension.
352 num_popups = 0;
353#endif
354#endif
[email protected]f1c102b2013-02-15 07:44:12355 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 1, num_popups, 0));
[email protected]4cdd8572013-02-15 00:33:25356}
357
[email protected]15119302014-05-20 19:23:58358// This test isn't applicable on Chrome OS, which automatically reloads crashed
359// pages.
[email protected]4ad85f42013-07-24 02:31:57360#if !defined(OS_CHROMEOS)
361IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, ClosePanelsOnExtensionCrash) {
[email protected]f1c102b2013-02-15 07:44:12362#if defined(USE_ASH_PANELS)
[email protected]4cdd8572013-02-15 00:33:25363 // On Ash, new panel windows open as popup windows instead.
364 int num_popups = 4;
365 int num_panels = 0;
366#else
367 int num_popups = 2;
368 int num_panels = 2;
369#endif
[email protected]c1dffe82013-06-26 20:59:05370 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]4cdd8572013-02-15 00:33:25371
372 // Setup listeners to wait on strings we expect the extension pages to send.
373 std::vector<std::string> test_strings;
374 test_strings.push_back("content_tab");
375 if (num_panels)
376 test_strings.push_back("content_panel");
377 test_strings.push_back("content_popup");
378
379 ScopedVector<ExtensionTestMessageListener> listeners;
380 for (size_t i = 0; i < test_strings.size(); ++i) {
381 listeners.push_back(
382 new ExtensionTestMessageListener(test_strings[i], false));
383 }
384
385 const extensions::Extension* extension = LoadExtension(
386 test_data_dir_.AppendASCII("window_open").AppendASCII(
387 "close_panels_on_uninstall"));
388 ASSERT_TRUE(extension);
389
390 // Two tabs. One in extension domain and one in non-extension domain.
391 // Two popups - one in extension domain and one in non-extension domain.
392 // Two panels - one in extension domain and one in non-extension domain.
[email protected]f1c102b2013-02-15 07:44:12393 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, num_panels));
[email protected]1dd66b72012-09-19 20:41:48394
395 // Wait on test messages to make sure the pages loaded.
396 for (size_t i = 0; i < listeners.size(); ++i)
397 ASSERT_TRUE(listeners[i]->WaitUntilSatisfied());
398
399 // Crash the extension.
400 extensions::ExtensionHost* extension_host =
reillyg0ea3fa902014-10-28 15:30:23401 extensions::ProcessManager::Get(browser()->profile())
402 ->GetBackgroundHostForExtension(extension->id());
[email protected]1dd66b72012-09-19 20:41:48403 ASSERT_TRUE(extension_host);
jaekyun37e572a32014-12-04 23:33:35404 extension_host->render_process_host()->Shutdown(content::RESULT_CODE_KILLED,
405 false);
[email protected]1dd66b72012-09-19 20:41:48406 WaitForExtensionCrash(extension->id());
407
408 // Only expect panels to close. The rest stay open to show a sad-tab.
[email protected]f1c102b2013-02-15 07:44:12409 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, 0));
[email protected]1dd66b72012-09-19 20:41:48410}
[email protected]4ad85f42013-07-24 02:31:57411#endif // !defined(OS_CHROMEOS)
[email protected]1dd66b72012-09-19 20:41:48412
[email protected]f1c102b2013-02-15 07:44:12413#if defined(USE_ASH_PANELS)
414// This test is not applicable on Ash. The modified window.open behavior only
415// applies to non-Ash panel windows.
[email protected]99f4fdb92012-08-30 23:13:51416#define MAYBE_WindowOpenFromPanel DISABLED_WindowOpenFromPanel
417#else
418#define MAYBE_WindowOpenFromPanel WindowOpenFromPanel
419#endif
420IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenFromPanel) {
[email protected]c1dffe82013-06-26 20:59:05421 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]6798c332012-08-29 02:16:51422
[email protected]99f4fdb92012-08-30 23:13:51423 // Load the extension that will open a panel which then calls window.open.
[email protected]6798c332012-08-29 02:16:51424 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("window_open").
425 AppendASCII("panel_window_open")));
[email protected]99f4fdb92012-08-30 23:13:51426
427 // Expect one panel (opened by extension) and one tab (from the panel calling
428 // window.open). Panels modify the WindowOpenDisposition in window.open
429 // to always open in a tab.
[email protected]f1c102b2013-02-15 07:44:12430 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 1, 0, 1));
[email protected]6798c332012-08-29 02:16:51431}
432
[email protected]24c6bcfc2012-02-29 21:06:36433IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpener) {
[email protected]54edcea2011-07-27 01:56:38434 ASSERT_TRUE(RunExtensionTest("window_open/opener")) << message_;
435}
[email protected]fad73672012-06-15 23:26:06436
[email protected]fa7c1602013-04-03 23:00:20437#if defined(OS_MACOSX)
438// Extension popup windows are incorrectly sized on OSX, crbug.com/225601
439#define MAYBE_WindowOpenSized DISABLED_WindowOpenSized
440#else
441#define MAYBE_WindowOpenSized WindowOpenSized
442#endif
443// Ensure that the width and height properties of a window opened with
444// chrome.windows.create match the creation parameters. See crbug.com/173831.
445IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_WindowOpenSized) {
446 ASSERT_TRUE(RunExtensionTest("window_open/window_size")) << message_;
447 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 1, 0));
448}
449
[email protected]fad73672012-06-15 23:26:06450// Tests that an extension page can call window.open to an extension URL and
451// the new window has extension privileges.
452IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenExtension) {
453 ASSERT_TRUE(LoadExtension(
454 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
455
[email protected]99bee642014-05-31 22:36:43456 GURL start_url(std::string(extensions::kExtensionScheme) +
[email protected]fb4fe0952014-06-05 09:44:24457 url::kStandardSchemeSeparator +
[email protected]99bee642014-05-31 22:36:43458 last_loaded_extension_id() + "/test.html");
[email protected]fad73672012-06-15 23:26:06459 ui_test_utils::NavigateToURL(browser(), start_url);
[email protected]f3e73f62012-10-20 05:35:16460 WebContents* newtab = NULL;
[email protected]e0448872013-01-11 19:35:02461 ASSERT_NO_FATAL_FAILURE(
462 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(),
463 start_url.Resolve("newtab.html"), true, &newtab));
[email protected]fad73672012-06-15 23:26:06464
465 bool result = false;
[email protected]b6987e02013-01-04 18:30:43466 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()",
467 &result));
[email protected]fad73672012-06-15 23:26:06468 EXPECT_TRUE(result);
469}
470
471// Tests that if an extension page calls window.open to an invalid extension
472// URL, the browser doesn't crash.
473IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) {
474 ASSERT_TRUE(LoadExtension(
475 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
476
[email protected]99bee642014-05-31 22:36:43477 GURL start_url(std::string(extensions::kExtensionScheme) +
[email protected]fb4fe0952014-06-05 09:44:24478 url::kStandardSchemeSeparator +
[email protected]99bee642014-05-31 22:36:43479 last_loaded_extension_id() + "/test.html");
[email protected]fad73672012-06-15 23:26:06480 ui_test_utils::NavigateToURL(browser(), start_url);
[email protected]e0448872013-01-11 19:35:02481 ASSERT_NO_FATAL_FAILURE(
482 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]fad73672012-06-15 23:26:06483 GURL("chrome-extension://thisissurelynotavalidextensionid/newtab.html"),
484 false, NULL));
485
486 // If we got to this point, we didn't crash, so we're good.
487}
488
489// Tests that calling window.open from the newtab page to an extension URL
490// gives the new window extension privileges - even though the opening page
491// does not have extension privileges, we break the script connection, so
492// there is no privilege leak.
493IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) {
494 ASSERT_TRUE(LoadExtension(
495 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
496
497 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
[email protected]f3e73f62012-10-20 05:35:16498 WebContents* newtab = NULL;
[email protected]e0448872013-01-11 19:35:02499 ASSERT_NO_FATAL_FAILURE(
500 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]99bee642014-05-31 22:36:43501 GURL(std::string(extensions::kExtensionScheme) +
[email protected]fb4fe0952014-06-05 09:44:24502 url::kStandardSchemeSeparator +
[email protected]99bee642014-05-31 22:36:43503 last_loaded_extension_id() + "/newtab.html"),
504 false,
505 &newtab));
[email protected]fad73672012-06-15 23:26:06506
507 // Extension API should succeed.
508 bool result = false;
[email protected]b6987e02013-01-04 18:30:43509 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()",
510 &result));
[email protected]fad73672012-06-15 23:26:06511 EXPECT_TRUE(result);
512}