blob: b448aee28b47b34b74b12ca554c6ea4bf33beb7a [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]58b349b2011-11-23 02:07:157#include "base/stringprintf.h"
[email protected]32b7c492010-09-01 04:15:008#include "chrome/browser/extensions/extension_apitest.h"
[email protected]1dd66b72012-09-19 20:41:489#include "chrome/browser/extensions/extension_host.h"
10#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]be93bba02012-10-24 16:44:0311#include "chrome/browser/extensions/extension_system.h"
[email protected]f9e82d92011-10-29 00:50:4512#include "chrome/browser/extensions/extension_test_message_listener.h"
[email protected]2ad4a902010-11-17 06:05:1313#include "chrome/browser/ui/browser.h"
[email protected]d8748142012-05-16 21:13:4314#include "chrome/browser/ui/browser_finder.h"
[email protected]bc44f4142013-02-12 06:15:5615#include "chrome/browser/ui/browser_iterator.h"
[email protected]52877dbc62012-06-29 22:22:0316#include "chrome/browser/ui/browser_tabstrip.h"
[email protected]f6ffa7d2012-08-17 17:27:0817#include "chrome/browser/ui/panels/panel_manager.h"
[email protected]e0448872013-01-11 19:35:0218#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]32b7c492010-09-01 04:15:0019#include "chrome/common/chrome_switches.h"
[email protected]f9e82d92011-10-29 00:50:4520#include "chrome/common/extensions/extension.h"
[email protected]af44e7fb2011-07-29 18:32:3221#include "chrome/test/base/ui_test_utils.h"
[email protected]1dd66b72012-09-19 20:41:4822#include "content/public/browser/render_process_host.h"
[email protected]fad73672012-06-15 23:26:0623#include "content/public/browser/web_contents.h"
[email protected]1dd66b72012-09-19 20:41:4824#include "content/public/common/result_codes.h"
[email protected]7d478cb2012-07-24 17:19:4225#include "content/public/test/browser_test_utils.h"
[email protected]4026ce1e2010-09-14 19:35:0426#include "net/base/mock_host_resolver.h"
[email protected]bc44f4142013-02-12 06:15:5627#include "testing/gtest/include/gtest/gtest.h"
[email protected]32b7c492010-09-01 04:15:0028
[email protected]f1c102b2013-02-15 07:44:1229#if defined(USE_ASH)
30#include "chrome/browser/extensions/shell_window_registry.h"
31#endif
32
33#if defined(USE_ASH) && !defined(OS_WIN)
34// TODO(stevenjb): Figure out the correct behavior for Ash + Win
35#define USE_ASH_PANELS
36#endif
37
[email protected]e5d549d2011-12-28 01:29:2038using content::OpenURLParams;
39using content::Referrer;
[email protected]fad73672012-06-15 23:26:0640using content::WebContents;
[email protected]e5d549d2011-12-28 01:29:2041
[email protected]e78eb292010-12-22 08:35:3942// Disabled, http://crbug.com/64899.
43IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpen) {
[email protected]32b7c492010-09-01 04:15:0044 CommandLine::ForCurrentProcess()->AppendSwitch(
45 switches::kEnableExperimentalExtensionApis);
46
47 ResultCatcher catcher;
48 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_
49 .AppendASCII("window_open").AppendASCII("spanning")));
50 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
51}
[email protected]4026ce1e2010-09-14 19:35:0452
[email protected]f1c102b2013-02-15 07:44:1253int GetPanelCount(Browser* browser) {
54#if defined(USE_ASH_PANELS)
55 return static_cast<int>(extensions::ShellWindowRegistry::Get(
56 browser->profile())->shell_windows().size());
57#else
58 return PanelManager::GetInstance()->num_panels();
59#endif
60}
61
62bool WaitForTabsAndPopups(Browser* browser,
[email protected]f9e82d92011-10-29 00:50:4563 int num_tabs,
64 int num_popups,
65 int num_panels) {
[email protected]58b349b2011-11-23 02:07:1566 SCOPED_TRACE(
67 StringPrintf("WaitForTabsAndPopups tabs:%d, popups:%d, panels:%d",
68 num_tabs, num_popups, num_panels));
[email protected]4026ce1e2010-09-14 19:35:0469 // We start with one tab and one browser already open.
70 ++num_tabs;
[email protected]f6ffa7d2012-08-17 17:27:0871 size_t num_browsers = static_cast<size_t>(num_popups) + 1;
[email protected]4026ce1e2010-09-14 19:35:0472
[email protected]f1c102b2013-02-15 07:44:1273 const base::TimeDelta kWaitTime = base::TimeDelta::FromSeconds(10);
[email protected]0a5bdc6522011-06-08 19:04:4974 base::TimeTicks end_time = base::TimeTicks::Now() + kWaitTime;
75 while (base::TimeTicks::Now() < end_time) {
[email protected]52ff7d932012-10-28 19:46:4676 if (chrome::GetBrowserCount(browser->profile()) == num_browsers &&
[email protected]e0448872013-01-11 19:35:0277 browser->tab_strip_model()->count() == num_tabs &&
[email protected]f1c102b2013-02-15 07:44:1278 GetPanelCount(browser) == num_panels)
[email protected]0a5bdc6522011-06-08 19:04:4979 break;
80
[email protected]b8deecd2012-07-30 21:09:4481 content::RunAllPendingInMessageLoop();
[email protected]0a5bdc6522011-06-08 19:04:4982 }
83
[email protected]52ff7d932012-10-28 19:46:4684 EXPECT_EQ(num_browsers, chrome::GetBrowserCount(browser->profile()));
[email protected]e0448872013-01-11 19:35:0285 EXPECT_EQ(num_tabs, browser->tab_strip_model()->count());
[email protected]f1c102b2013-02-15 07:44:1286 EXPECT_EQ(num_panels, GetPanelCount(browser));
[email protected]0a5bdc6522011-06-08 19:04:4987
[email protected]f9e82d92011-10-29 00:50:4588 int num_popups_seen = 0;
[email protected]bc44f4142013-02-12 06:15:5689 for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) {
[email protected]0a5bdc6522011-06-08 19:04:4990 if (*iter == browser)
[email protected]4026ce1e2010-09-14 19:35:0491 continue;
[email protected]4026ce1e2010-09-14 19:35:0492
[email protected]f6ffa7d2012-08-17 17:27:0893 // Check for TYPE_POPUP.
[email protected]f1c102b2013-02-15 07:44:1294#if defined(USE_ASH_PANELS)
95 // On Ash, panel windows may open as popup windows.
[email protected]99f4fdb92012-08-30 23:13:5196 EXPECT_TRUE((*iter)->is_type_popup() || (*iter)->is_type_panel());
97#else
[email protected]f6ffa7d2012-08-17 17:27:0898 EXPECT_TRUE((*iter)->is_type_popup());
[email protected]99f4fdb92012-08-30 23:13:5199#endif
[email protected]f6ffa7d2012-08-17 17:27:08100 ++num_popups_seen;
[email protected]4026ce1e2010-09-14 19:35:04101 }
[email protected]f9e82d92011-10-29 00:50:45102 EXPECT_EQ(num_popups, num_popups_seen);
[email protected]f1c102b2013-02-15 07:44:12103
104 return ((num_browsers == chrome::GetBrowserCount(browser->profile())) &&
105 (num_tabs == browser->tab_strip_model()->count()) &&
106 (num_panels == GetPanelCount(browser)) &&
107 (num_popups == num_popups_seen));
[email protected]4026ce1e2010-09-14 19:35:04108}
109
[email protected]f112b0f2011-05-26 01:53:52110IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserIsApp) {
111 host_resolver()->AddRule("a.com", "127.0.0.1");
112 ASSERT_TRUE(StartTestServer());
113 ASSERT_TRUE(LoadExtension(
114 test_data_dir_.AppendASCII("window_open").AppendASCII("browser_is_app")));
115
[email protected]f1c102b2013-02-15 07:44:12116 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 2, 0));
[email protected]f112b0f2011-05-26 01:53:52117
[email protected]bc44f4142013-02-12 06:15:56118 for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) {
[email protected]f112b0f2011-05-26 01:53:52119 if (*iter == browser())
[email protected]bc44f4142013-02-12 06:15:56120 ASSERT_FALSE(iter->is_app());
[email protected]f112b0f2011-05-26 01:53:52121 else
[email protected]bc44f4142013-02-12 06:15:56122 ASSERT_TRUE(iter->is_app());
[email protected]f112b0f2011-05-26 01:53:52123 }
124}
125
[email protected]0a5bdc6522011-06-08 19:04:49126IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupDefault) {
127 ASSERT_TRUE(StartTestServer());
128 ASSERT_TRUE(LoadExtension(
129 test_data_dir_.AppendASCII("window_open").AppendASCII("popup")));
130
131 const int num_tabs = 1;
132 const int num_popups = 0;
[email protected]f1c102b2013-02-15 07:44:12133 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0));
[email protected]0a5bdc6522011-06-08 19:04:49134}
135
136IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupLarge) {
137 ASSERT_TRUE(StartTestServer());
138 ASSERT_TRUE(LoadExtension(
139 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_large")));
140
[email protected]0a5bdc6522011-06-08 19:04:49141 // On other systems this should open a new popup window.
142 const int num_tabs = 0;
143 const int num_popups = 1;
[email protected]f1c102b2013-02-15 07:44:12144 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0));
[email protected]0a5bdc6522011-06-08 19:04:49145}
146
147IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupSmall) {
148 ASSERT_TRUE(StartTestServer());
149 ASSERT_TRUE(LoadExtension(
150 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_small")));
151
152 // On ChromeOS this should open a new panel (acts like a new popup window).
153 // On other systems this should open a new popup window.
154 const int num_tabs = 0;
155 const int num_popups = 1;
[email protected]f1c102b2013-02-15 07:44:12156 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0));
[email protected]0a5bdc6522011-06-08 19:04:49157}
158
[email protected]4026ce1e2010-09-14 19:35:04159IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PopupBlockingExtension) {
160 host_resolver()->AddRule("*", "127.0.0.1");
[email protected]e18a19b2010-10-19 20:32:30161 ASSERT_TRUE(StartTestServer());
[email protected]4026ce1e2010-09-14 19:35:04162
163 ASSERT_TRUE(LoadExtension(
164 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking")
165 .AppendASCII("extension")));
166
[email protected]f1c102b2013-02-15 07:44:12167 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 5, 3, 0));
[email protected]4026ce1e2010-09-14 19:35:04168}
169
170IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PopupBlockingHostedApp) {
171 host_resolver()->AddRule("*", "127.0.0.1");
172 ASSERT_TRUE(test_server()->Start());
173
174 ASSERT_TRUE(LoadExtension(
175 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking")
176 .AppendASCII("hosted_app")));
177
[email protected]fe3048872010-10-18 14:58:59178 // The app being tested owns the domain a.com . The test URLs we navigate
179 // to below must be within that domain, so that they fall within the app's
180 // web extent.
181 GURL::Replacements replace_host;
182 std::string a_dot_com = "a.com";
183 replace_host.SetHostStr(a_dot_com);
184
185 const std::string popup_app_contents_path(
186 "files/extensions/api_test/window_open/popup_blocking/hosted_app/");
187
188 GURL open_tab =
189 test_server()->GetURL(popup_app_contents_path + "open_tab.html")
190 .ReplaceComponents(replace_host);
191 GURL open_popup =
192 test_server()->GetURL(popup_app_contents_path + "open_popup.html")
193 .ReplaceComponents(replace_host);
194
[email protected]e5d549d2011-12-28 01:29:20195 browser()->OpenURL(OpenURLParams(
196 open_tab, Referrer(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED,
197 false));
198 browser()->OpenURL(OpenURLParams(
199 open_popup, Referrer(), NEW_FOREGROUND_TAB,
200 content::PAGE_TRANSITION_TYPED, false));
[email protected]4026ce1e2010-09-14 19:35:04201
[email protected]f1c102b2013-02-15 07:44:12202 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 3, 1, 0));
[email protected]4026ce1e2010-09-14 19:35:04203}
[email protected]d4db6c702011-03-28 21:49:14204
[email protected]e7f90562011-05-23 21:38:24205IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowArgumentsOverflow) {
206 ASSERT_TRUE(RunExtensionTest("window_open/argument_overflow")) << message_;
207}
208
[email protected]d5c14062011-10-27 00:02:13209class WindowOpenPanelDisabledTest : public ExtensionApiTest {
[email protected]49aeab62013-02-07 02:53:11210 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
[email protected]08aa0c32011-04-11 22:18:37211 ExtensionApiTest::SetUpCommandLine(command_line);
[email protected]7e7a28092011-12-09 22:24:55212 // TODO(jennb): Re-enable when panels are enabled by default.
213 // command_line->AppendSwitch(switches::kDisablePanels);
[email protected]08aa0c32011-04-11 22:18:37214 }
215};
216
[email protected]7e7a28092011-12-09 22:24:55217IN_PROC_BROWSER_TEST_F(WindowOpenPanelDisabledTest,
218 DISABLED_WindowOpenPanelNotEnabled) {
[email protected]d5c14062011-10-27 00:02:13219 ASSERT_TRUE(RunExtensionTest("window_open/panel_not_enabled")) << message_;
220}
221
[email protected]af6b54512011-12-14 06:11:21222class WindowOpenPanelTest : public ExtensionApiTest {
[email protected]49aeab62013-02-07 02:53:11223 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
[email protected]af6b54512011-12-14 06:11:21224 ExtensionApiTest::SetUpCommandLine(command_line);
225 command_line->AppendSwitch(switches::kEnablePanels);
226 }
227};
228
[email protected]f1c102b2013-02-15 07:44:12229#if defined(USE_ASH_PANELS)
[email protected]87d722a2012-07-12 15:38:33230// On Ash, this currently fails because we're currently opening new panel
[email protected]d101b0c2012-03-16 00:30:57231// windows as popup windows instead.
[email protected]e00ccc92012-11-01 17:32:30232#define MAYBE_WindowOpenPanel DISABLED_WindowOpenPanel
[email protected]d101b0c2012-03-16 00:30:57233#else
234#define MAYBE_WindowOpenPanel WindowOpenPanel
235#endif
236IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenPanel) {
[email protected]08aa0c32011-04-11 22:18:37237 ASSERT_TRUE(RunExtensionTest("window_open/panel")) << message_;
238}
[email protected]54edcea2011-07-27 01:56:38239
[email protected]f1c102b2013-02-15 07:44:12240#if defined(USE_ASH_PANELS)
[email protected]ca29ed12012-09-06 09:10:50241// On Ash, this currently fails because we're currently opening new panel
242// windows as popup windows instead.
[email protected]e00ccc92012-11-01 17:32:30243#define MAYBE_WindowOpenPanelDetached DISABLED_WindowOpenPanelDetached
[email protected]ca29ed12012-09-06 09:10:50244#else
245#define MAYBE_WindowOpenPanelDetached WindowOpenPanelDetached
246#endif
247IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenPanelDetached) {
[email protected]ca29ed12012-09-06 09:10:50248 ASSERT_TRUE(RunExtensionTest("window_open/panel_detached")) << message_;
249}
250
[email protected]af6b54512011-12-14 06:11:21251IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest,
[email protected]f9e82d92011-10-29 00:50:45252 CloseNonExtensionPanelsOnUninstall) {
[email protected]f1c102b2013-02-15 07:44:12253#if defined(USE_ASH_PANELS)
[email protected]1dd66b72012-09-19 20:41:48254 // On Ash, new panel windows open as popup windows instead.
[email protected]f1c102b2013-02-15 07:44:12255 int num_popups, num_panels;
256 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePanels)) {
257 num_popups = 2;
258 num_panels = 2;
259 } else {
260 num_popups = 4;
261 num_panels = 0;
262 }
[email protected]1dd66b72012-09-19 20:41:48263#else
264 int num_popups = 2;
265 int num_panels = 2;
266#endif
267 ASSERT_TRUE(StartTestServer());
268
269 // Setup listeners to wait on strings we expect the extension pages to send.
270 std::vector<std::string> test_strings;
271 test_strings.push_back("content_tab");
272 if (num_panels)
273 test_strings.push_back("content_panel");
274 test_strings.push_back("content_popup");
275
276 ScopedVector<ExtensionTestMessageListener> listeners;
277 for (size_t i = 0; i < test_strings.size(); ++i) {
278 listeners.push_back(
279 new ExtensionTestMessageListener(test_strings[i], false));
280 }
281
282 const extensions::Extension* extension = LoadExtension(
283 test_data_dir_.AppendASCII("window_open").AppendASCII(
284 "close_panels_on_uninstall"));
285 ASSERT_TRUE(extension);
286
287 // Two tabs. One in extension domain and one in non-extension domain.
288 // Two popups - one in extension domain and one in non-extension domain.
289 // Two panels - one in extension domain and one in non-extension domain.
[email protected]f1c102b2013-02-15 07:44:12290 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, num_panels));
[email protected]4cdd8572013-02-15 00:33:25291
292 // Wait on test messages to make sure the pages loaded.
293 for (size_t i = 0; i < listeners.size(); ++i)
294 ASSERT_TRUE(listeners[i]->WaitUntilSatisfied());
295
296 UninstallExtension(extension->id());
297
298 // Wait for the tabs and popups in non-extension domain to stay open.
299 // Expect everything else, including panels, to close.
[email protected]4cdd8572013-02-15 00:33:25300 num_popups -= 1;
[email protected]f1c102b2013-02-15 07:44:12301#if defined(USE_ASH_PANELS)
302 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePanels)) {
303 // On Ash, new panel windows open as popup windows instead, so there are 2
304 // extension domain popups that will close (instead of 1 popup on non-Ash).
305 num_popups -= 1;
306 }
[email protected]4cdd8572013-02-15 00:33:25307#endif
[email protected]f1c102b2013-02-15 07:44:12308 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 1, num_popups, 0));
[email protected]4cdd8572013-02-15 00:33:25309}
310
311#if defined(OS_CHROMEOS)
312// TODO(derat): See if there's some way to get this to work on Chrome OS. It
313// crashes there, apparently because we automatically reload crashed pages:
314// http:/crbug.com/161073
315#define MAYBE_ClosePanelsOnExtensionCrash DISABLED_ClosePanelsOnExtensionCrash
316#else
317#define MAYBE_ClosePanelsOnExtensionCrash ClosePanelsOnExtensionCrash
318#endif
319IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_ClosePanelsOnExtensionCrash) {
[email protected]f1c102b2013-02-15 07:44:12320#if defined(USE_ASH_PANELS)
[email protected]4cdd8572013-02-15 00:33:25321 // On Ash, new panel windows open as popup windows instead.
322 int num_popups = 4;
323 int num_panels = 0;
324#else
325 int num_popups = 2;
326 int num_panels = 2;
327#endif
328 ASSERT_TRUE(StartTestServer());
329
330 // Setup listeners to wait on strings we expect the extension pages to send.
331 std::vector<std::string> test_strings;
332 test_strings.push_back("content_tab");
333 if (num_panels)
334 test_strings.push_back("content_panel");
335 test_strings.push_back("content_popup");
336
337 ScopedVector<ExtensionTestMessageListener> listeners;
338 for (size_t i = 0; i < test_strings.size(); ++i) {
339 listeners.push_back(
340 new ExtensionTestMessageListener(test_strings[i], false));
341 }
342
343 const extensions::Extension* extension = LoadExtension(
344 test_data_dir_.AppendASCII("window_open").AppendASCII(
345 "close_panels_on_uninstall"));
346 ASSERT_TRUE(extension);
347
348 // Two tabs. One in extension domain and one in non-extension domain.
349 // Two popups - one in extension domain and one in non-extension domain.
350 // Two panels - one in extension domain and one in non-extension domain.
[email protected]f1c102b2013-02-15 07:44:12351 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, num_panels));
[email protected]1dd66b72012-09-19 20:41:48352
353 // Wait on test messages to make sure the pages loaded.
354 for (size_t i = 0; i < listeners.size(); ++i)
355 ASSERT_TRUE(listeners[i]->WaitUntilSatisfied());
356
357 // Crash the extension.
358 extensions::ExtensionHost* extension_host =
[email protected]be93bba02012-10-24 16:44:03359 extensions::ExtensionSystem::Get(browser()->profile())->
360 process_manager()->GetBackgroundHostForExtension(extension->id());
[email protected]1dd66b72012-09-19 20:41:48361 ASSERT_TRUE(extension_host);
362 base::KillProcess(extension_host->render_process_host()->GetHandle(),
363 content::RESULT_CODE_KILLED, false);
364 WaitForExtensionCrash(extension->id());
365
366 // Only expect panels to close. The rest stay open to show a sad-tab.
[email protected]f1c102b2013-02-15 07:44:12367 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, 0));
[email protected]1dd66b72012-09-19 20:41:48368}
369
[email protected]f1c102b2013-02-15 07:44:12370#if defined(USE_ASH_PANELS)
371// This test is not applicable on Ash. The modified window.open behavior only
372// applies to non-Ash panel windows.
[email protected]99f4fdb92012-08-30 23:13:51373#define MAYBE_WindowOpenFromPanel DISABLED_WindowOpenFromPanel
374#else
375#define MAYBE_WindowOpenFromPanel WindowOpenFromPanel
376#endif
377IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenFromPanel) {
[email protected]6798c332012-08-29 02:16:51378 ASSERT_TRUE(StartTestServer());
379
[email protected]99f4fdb92012-08-30 23:13:51380 // Load the extension that will open a panel which then calls window.open.
[email protected]6798c332012-08-29 02:16:51381 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("window_open").
382 AppendASCII("panel_window_open")));
[email protected]99f4fdb92012-08-30 23:13:51383
384 // Expect one panel (opened by extension) and one tab (from the panel calling
385 // window.open). Panels modify the WindowOpenDisposition in window.open
386 // to always open in a tab.
[email protected]f1c102b2013-02-15 07:44:12387 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 1, 0, 1));
[email protected]6798c332012-08-29 02:16:51388}
389
[email protected]24c6bcfc2012-02-29 21:06:36390IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpener) {
[email protected]54edcea2011-07-27 01:56:38391 ASSERT_TRUE(RunExtensionTest("window_open/opener")) << message_;
392}
[email protected]fad73672012-06-15 23:26:06393
394// Tests that an extension page can call window.open to an extension URL and
395// the new window has extension privileges.
396IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenExtension) {
397 ASSERT_TRUE(LoadExtension(
398 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
399
400 GURL start_url(std::string("chrome-extension://") +
401 last_loaded_extension_id_ + "/test.html");
402 ui_test_utils::NavigateToURL(browser(), start_url);
[email protected]f3e73f62012-10-20 05:35:16403 WebContents* newtab = NULL;
[email protected]e0448872013-01-11 19:35:02404 ASSERT_NO_FATAL_FAILURE(
405 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(),
406 start_url.Resolve("newtab.html"), true, &newtab));
[email protected]fad73672012-06-15 23:26:06407
408 bool result = false;
[email protected]b6987e02013-01-04 18:30:43409 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()",
410 &result));
[email protected]fad73672012-06-15 23:26:06411 EXPECT_TRUE(result);
412}
413
414// Tests that if an extension page calls window.open to an invalid extension
415// URL, the browser doesn't crash.
416IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) {
417 ASSERT_TRUE(LoadExtension(
418 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
419
420 GURL start_url(std::string("chrome-extension://") +
421 last_loaded_extension_id_ + "/test.html");
422 ui_test_utils::NavigateToURL(browser(), start_url);
[email protected]e0448872013-01-11 19:35:02423 ASSERT_NO_FATAL_FAILURE(
424 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]fad73672012-06-15 23:26:06425 GURL("chrome-extension://thisissurelynotavalidextensionid/newtab.html"),
426 false, NULL));
427
428 // If we got to this point, we didn't crash, so we're good.
429}
430
431// Tests that calling window.open from the newtab page to an extension URL
432// gives the new window extension privileges - even though the opening page
433// does not have extension privileges, we break the script connection, so
434// there is no privilege leak.
435IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) {
436 ASSERT_TRUE(LoadExtension(
437 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
438
439 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
[email protected]f3e73f62012-10-20 05:35:16440 WebContents* newtab = NULL;
[email protected]e0448872013-01-11 19:35:02441 ASSERT_NO_FATAL_FAILURE(
442 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]fad73672012-06-15 23:26:06443 GURL(std::string("chrome-extension://") + last_loaded_extension_id_ +
444 "/newtab.html"), false, &newtab));
445
446 // Extension API should succeed.
447 bool result = false;
[email protected]b6987e02013-01-04 18:30:43448 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()",
449 &result));
[email protected]fad73672012-06-15 23:26:06450 EXPECT_TRUE(result);
451}