blob: 531f65dff9b3205e7b164e102ab23b81f3d81d1a [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]46acbf12013-06-10 18:43:427#include "base/strings/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]01996a592013-09-13 06:55:0413#include "chrome/browser/profiles/profile.h"
[email protected]2ad4a902010-11-17 06:05:1314#include "chrome/browser/ui/browser.h"
[email protected]d8748142012-05-16 21:13:4315#include "chrome/browser/ui/browser_finder.h"
[email protected]bc44f4142013-02-12 06:15:5616#include "chrome/browser/ui/browser_iterator.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]b65d4bdcc2013-07-31 00:37:3321#include "chrome/test/base/test_switches.h"
[email protected]af44e7fb2011-07-29 18:32:3222#include "chrome/test/base/ui_test_utils.h"
[email protected]1dd66b72012-09-19 20:41:4823#include "content/public/browser/render_process_host.h"
[email protected]fad73672012-06-15 23:26:0624#include "content/public/browser/web_contents.h"
[email protected]1dd66b72012-09-19 20:41:4825#include "content/public/common/result_codes.h"
[email protected]7d478cb2012-07-24 17:19:4226#include "content/public/test/browser_test_utils.h"
[email protected]c8d02992013-07-31 22:16:5127#include "extensions/common/switches.h"
[email protected]f2cb3cf2013-03-21 01:40:5328#include "net/dns/mock_host_resolver.h"
[email protected]bc44f4142013-02-12 06:15:5629#include "testing/gtest/include/gtest/gtest.h"
[email protected]32b7c492010-09-01 04:15:0030
[email protected]f1c102b2013-02-15 07:44:1231#if defined(USE_ASH)
[email protected]f6d9b282013-08-09 11:03:2032#include "apps/shell_window_registry.h"
[email protected]f1c102b2013-02-15 07:44:1233#endif
34
35#if defined(USE_ASH) && !defined(OS_WIN)
36// TODO(stevenjb): Figure out the correct behavior for Ash + Win
37#define USE_ASH_PANELS
38#endif
39
[email protected]e5d549d2011-12-28 01:29:2040using content::OpenURLParams;
41using content::Referrer;
[email protected]fad73672012-06-15 23:26:0642using content::WebContents;
[email protected]e5d549d2011-12-28 01:29:2043
[email protected]e78eb292010-12-22 08:35:3944// Disabled, http://crbug.com/64899.
45IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpen) {
[email protected]32b7c492010-09-01 04:15:0046 CommandLine::ForCurrentProcess()->AppendSwitch(
[email protected]c8d02992013-07-31 22:16:5147 extensions::switches::kEnableExperimentalExtensionApis);
[email protected]32b7c492010-09-01 04:15:0048
49 ResultCatcher catcher;
50 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_
51 .AppendASCII("window_open").AppendASCII("spanning")));
52 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
53}
[email protected]4026ce1e2010-09-14 19:35:0454
[email protected]f1c102b2013-02-15 07:44:1255int GetPanelCount(Browser* browser) {
56#if defined(USE_ASH_PANELS)
[email protected]f6d9b282013-08-09 11:03:2057 return static_cast<int>(apps::ShellWindowRegistry::Get(
[email protected]f1c102b2013-02-15 07:44:1258 browser->profile())->shell_windows().size());
59#else
60 return PanelManager::GetInstance()->num_panels();
61#endif
62}
63
64bool WaitForTabsAndPopups(Browser* browser,
[email protected]f9e82d92011-10-29 00:50:4565 int num_tabs,
66 int num_popups,
67 int num_panels) {
[email protected]58b349b2011-11-23 02:07:1568 SCOPED_TRACE(
[email protected]7d3cbc92013-03-18 22:33:0469 base::StringPrintf("WaitForTabsAndPopups tabs:%d, popups:%d, panels:%d",
70 num_tabs, num_popups, num_panels));
[email protected]4026ce1e2010-09-14 19:35:0471 // We start with one tab and one browser already open.
72 ++num_tabs;
[email protected]f6ffa7d2012-08-17 17:27:0873 size_t num_browsers = static_cast<size_t>(num_popups) + 1;
[email protected]4026ce1e2010-09-14 19:35:0474
[email protected]f1c102b2013-02-15 07:44:1275 const base::TimeDelta kWaitTime = base::TimeDelta::FromSeconds(10);
[email protected]0a5bdc6522011-06-08 19:04:4976 base::TimeTicks end_time = base::TimeTicks::Now() + kWaitTime;
77 while (base::TimeTicks::Now() < end_time) {
[email protected]c987a242013-02-28 01:17:4178 if (chrome::GetBrowserCount(browser->profile(),
79 browser->host_desktop_type()) == num_browsers &&
[email protected]e0448872013-01-11 19:35:0280 browser->tab_strip_model()->count() == num_tabs &&
[email protected]f1c102b2013-02-15 07:44:1281 GetPanelCount(browser) == num_panels)
[email protected]0a5bdc6522011-06-08 19:04:4982 break;
83
[email protected]b8deecd2012-07-30 21:09:4484 content::RunAllPendingInMessageLoop();
[email protected]0a5bdc6522011-06-08 19:04:4985 }
86
[email protected]c987a242013-02-28 01:17:4187 EXPECT_EQ(num_browsers,
88 chrome::GetBrowserCount(browser->profile(),
89 browser->host_desktop_type()));
[email protected]e0448872013-01-11 19:35:0290 EXPECT_EQ(num_tabs, browser->tab_strip_model()->count());
[email protected]f1c102b2013-02-15 07:44:1291 EXPECT_EQ(num_panels, GetPanelCount(browser));
[email protected]0a5bdc6522011-06-08 19:04:4992
[email protected]f9e82d92011-10-29 00:50:4593 int num_popups_seen = 0;
[email protected]bc44f4142013-02-12 06:15:5694 for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) {
[email protected]0a5bdc6522011-06-08 19:04:4995 if (*iter == browser)
[email protected]4026ce1e2010-09-14 19:35:0496 continue;
[email protected]4026ce1e2010-09-14 19:35:0497
[email protected]f6ffa7d2012-08-17 17:27:0898 EXPECT_TRUE((*iter)->is_type_popup());
99 ++num_popups_seen;
[email protected]4026ce1e2010-09-14 19:35:04100 }
[email protected]f9e82d92011-10-29 00:50:45101 EXPECT_EQ(num_popups, num_popups_seen);
[email protected]f1c102b2013-02-15 07:44:12102
[email protected]c987a242013-02-28 01:17:41103 return ((num_browsers ==
104 chrome::GetBrowserCount(browser->profile(),
105 browser->host_desktop_type())) &&
[email protected]f1c102b2013-02-15 07:44:12106 (num_tabs == browser->tab_strip_model()->count()) &&
107 (num_panels == GetPanelCount(browser)) &&
108 (num_popups == num_popups_seen));
[email protected]4026ce1e2010-09-14 19:35:04109}
110
[email protected]f112b0f2011-05-26 01:53:52111IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserIsApp) {
112 host_resolver()->AddRule("a.com", "127.0.0.1");
[email protected]c1dffe82013-06-26 20:59:05113 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]f112b0f2011-05-26 01:53:52114 ASSERT_TRUE(LoadExtension(
115 test_data_dir_.AppendASCII("window_open").AppendASCII("browser_is_app")));
116
[email protected]f1c102b2013-02-15 07:44:12117 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 2, 0));
[email protected]f112b0f2011-05-26 01:53:52118
[email protected]bc44f4142013-02-12 06:15:56119 for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) {
[email protected]f112b0f2011-05-26 01:53:52120 if (*iter == browser())
[email protected]bc44f4142013-02-12 06:15:56121 ASSERT_FALSE(iter->is_app());
[email protected]f112b0f2011-05-26 01:53:52122 else
[email protected]bc44f4142013-02-12 06:15:56123 ASSERT_TRUE(iter->is_app());
[email protected]f112b0f2011-05-26 01:53:52124 }
125}
126
[email protected]0a5bdc6522011-06-08 19:04:49127IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupDefault) {
[email protected]c1dffe82013-06-26 20:59:05128 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]0a5bdc6522011-06-08 19:04:49129 ASSERT_TRUE(LoadExtension(
130 test_data_dir_.AppendASCII("window_open").AppendASCII("popup")));
131
132 const int num_tabs = 1;
133 const int num_popups = 0;
[email protected]f1c102b2013-02-15 07:44:12134 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0));
[email protected]0a5bdc6522011-06-08 19:04:49135}
136
137IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupLarge) {
[email protected]c1dffe82013-06-26 20:59:05138 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]0a5bdc6522011-06-08 19:04:49139 ASSERT_TRUE(LoadExtension(
140 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_large")));
141
[email protected]0a5bdc6522011-06-08 19:04:49142 // On other systems this should open a new popup window.
143 const int num_tabs = 0;
144 const int num_popups = 1;
[email protected]f1c102b2013-02-15 07:44:12145 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0));
[email protected]0a5bdc6522011-06-08 19:04:49146}
147
148IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupSmall) {
[email protected]c1dffe82013-06-26 20:59:05149 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]0a5bdc6522011-06-08 19:04:49150 ASSERT_TRUE(LoadExtension(
151 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_small")));
152
153 // On ChromeOS this should open a new panel (acts like a new popup window).
154 // On other systems this should open a new popup window.
155 const int num_tabs = 0;
156 const int num_popups = 1;
[email protected]f1c102b2013-02-15 07:44:12157 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0));
[email protected]0a5bdc6522011-06-08 19:04:49158}
159
[email protected]73fa1fce2013-02-21 20:10:05160// Disabled on Windows. Often times out or fails: crbug.com/177530
161#if defined(OS_WIN)
162#define MAYBE_PopupBlockingExtension DISABLED_PopupBlockingExtension
163#else
164#define MAYBE_PopupBlockingExtension PopupBlockingExtension
165#endif
166IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_PopupBlockingExtension) {
[email protected]4026ce1e2010-09-14 19:35:04167 host_resolver()->AddRule("*", "127.0.0.1");
[email protected]c1dffe82013-06-26 20:59:05168 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]4026ce1e2010-09-14 19:35:04169
170 ASSERT_TRUE(LoadExtension(
171 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking")
172 .AppendASCII("extension")));
173
[email protected]f1c102b2013-02-15 07:44:12174 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 5, 3, 0));
[email protected]4026ce1e2010-09-14 19:35:04175}
176
177IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PopupBlockingHostedApp) {
178 host_resolver()->AddRule("*", "127.0.0.1");
179 ASSERT_TRUE(test_server()->Start());
180
181 ASSERT_TRUE(LoadExtension(
182 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking")
183 .AppendASCII("hosted_app")));
184
[email protected]fe3048872010-10-18 14:58:59185 // The app being tested owns the domain a.com . The test URLs we navigate
186 // to below must be within that domain, so that they fall within the app's
187 // web extent.
188 GURL::Replacements replace_host;
189 std::string a_dot_com = "a.com";
190 replace_host.SetHostStr(a_dot_com);
191
192 const std::string popup_app_contents_path(
193 "files/extensions/api_test/window_open/popup_blocking/hosted_app/");
194
195 GURL open_tab =
196 test_server()->GetURL(popup_app_contents_path + "open_tab.html")
197 .ReplaceComponents(replace_host);
198 GURL open_popup =
199 test_server()->GetURL(popup_app_contents_path + "open_popup.html")
200 .ReplaceComponents(replace_host);
201
[email protected]e5d549d2011-12-28 01:29:20202 browser()->OpenURL(OpenURLParams(
203 open_tab, Referrer(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED,
204 false));
205 browser()->OpenURL(OpenURLParams(
206 open_popup, Referrer(), NEW_FOREGROUND_TAB,
207 content::PAGE_TRANSITION_TYPED, false));
[email protected]4026ce1e2010-09-14 19:35:04208
[email protected]f1c102b2013-02-15 07:44:12209 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 3, 1, 0));
[email protected]4026ce1e2010-09-14 19:35:04210}
[email protected]d4db6c702011-03-28 21:49:14211
[email protected]e7f90562011-05-23 21:38:24212IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowArgumentsOverflow) {
213 ASSERT_TRUE(RunExtensionTest("window_open/argument_overflow")) << message_;
214}
215
[email protected]d5c14062011-10-27 00:02:13216class WindowOpenPanelDisabledTest : public ExtensionApiTest {
[email protected]49aeab62013-02-07 02:53:11217 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
[email protected]08aa0c32011-04-11 22:18:37218 ExtensionApiTest::SetUpCommandLine(command_line);
[email protected]7e7a28092011-12-09 22:24:55219 // TODO(jennb): Re-enable when panels are enabled by default.
220 // command_line->AppendSwitch(switches::kDisablePanels);
[email protected]08aa0c32011-04-11 22:18:37221 }
222};
223
[email protected]7e7a28092011-12-09 22:24:55224IN_PROC_BROWSER_TEST_F(WindowOpenPanelDisabledTest,
225 DISABLED_WindowOpenPanelNotEnabled) {
[email protected]d5c14062011-10-27 00:02:13226 ASSERT_TRUE(RunExtensionTest("window_open/panel_not_enabled")) << message_;
227}
228
[email protected]af6b54512011-12-14 06:11:21229class WindowOpenPanelTest : public ExtensionApiTest {
[email protected]49aeab62013-02-07 02:53:11230 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
[email protected]af6b54512011-12-14 06:11:21231 ExtensionApiTest::SetUpCommandLine(command_line);
232 command_line->AppendSwitch(switches::kEnablePanels);
233 }
234};
235
[email protected]f1c102b2013-02-15 07:44:12236#if defined(USE_ASH_PANELS)
[email protected]87d722a2012-07-12 15:38:33237// On Ash, this currently fails because we're currently opening new panel
[email protected]d101b0c2012-03-16 00:30:57238// windows as popup windows instead.
[email protected]e00ccc92012-11-01 17:32:30239#define MAYBE_WindowOpenPanel DISABLED_WindowOpenPanel
[email protected]d101b0c2012-03-16 00:30:57240#else
241#define MAYBE_WindowOpenPanel WindowOpenPanel
242#endif
243IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenPanel) {
[email protected]08aa0c32011-04-11 22:18:37244 ASSERT_TRUE(RunExtensionTest("window_open/panel")) << message_;
245}
[email protected]54edcea2011-07-27 01:56:38246
[email protected]cb1849e2013-07-08 21:12:53247#if defined(USE_ASH_PANELS)
[email protected]ca29ed12012-09-06 09:10:50248// On Ash, this currently fails because we're currently opening new panel
249// windows as popup windows instead.
[email protected]cb1849e2013-07-08 21:12:53250#define MAYBE_WindowOpenPanelDetached DISABLED_WindowOpenPanelDetached
251#else
252#define MAYBE_WindowOpenPanelDetached WindowOpenPanelDetached
253#endif
254IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenPanelDetached) {
[email protected]ca29ed12012-09-06 09:10:50255 ASSERT_TRUE(RunExtensionTest("window_open/panel_detached")) << message_;
256}
257
[email protected]af6b54512011-12-14 06:11:21258IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest,
[email protected]f9e82d92011-10-29 00:50:45259 CloseNonExtensionPanelsOnUninstall) {
[email protected]45c6f6722013-07-23 03:02:19260#if defined(OS_WIN) && defined(USE_ASH)
261 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
[email protected]b65d4bdcc2013-07-31 00:37:33262 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
[email protected]45c6f6722013-07-23 03:02:19263 return;
264#endif
265
[email protected]f1c102b2013-02-15 07:44:12266#if defined(USE_ASH_PANELS)
[email protected]1dd66b72012-09-19 20:41:48267 // On Ash, new panel windows open as popup windows instead.
[email protected]f1c102b2013-02-15 07:44:12268 int num_popups, num_panels;
269 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePanels)) {
270 num_popups = 2;
271 num_panels = 2;
272 } else {
273 num_popups = 4;
274 num_panels = 0;
275 }
[email protected]1dd66b72012-09-19 20:41:48276#else
277 int num_popups = 2;
278 int num_panels = 2;
279#endif
[email protected]c1dffe82013-06-26 20:59:05280 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]1dd66b72012-09-19 20:41:48281
282 // Setup listeners to wait on strings we expect the extension pages to send.
283 std::vector<std::string> test_strings;
284 test_strings.push_back("content_tab");
285 if (num_panels)
286 test_strings.push_back("content_panel");
287 test_strings.push_back("content_popup");
288
289 ScopedVector<ExtensionTestMessageListener> listeners;
290 for (size_t i = 0; i < test_strings.size(); ++i) {
291 listeners.push_back(
292 new ExtensionTestMessageListener(test_strings[i], false));
293 }
294
295 const extensions::Extension* extension = LoadExtension(
296 test_data_dir_.AppendASCII("window_open").AppendASCII(
297 "close_panels_on_uninstall"));
298 ASSERT_TRUE(extension);
299
300 // Two tabs. One in extension domain and one in non-extension domain.
301 // Two popups - one in extension domain and one in non-extension domain.
302 // Two panels - one in extension domain and one in non-extension domain.
[email protected]f1c102b2013-02-15 07:44:12303 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, num_panels));
[email protected]4cdd8572013-02-15 00:33:25304
305 // Wait on test messages to make sure the pages loaded.
306 for (size_t i = 0; i < listeners.size(); ++i)
307 ASSERT_TRUE(listeners[i]->WaitUntilSatisfied());
308
309 UninstallExtension(extension->id());
310
311 // Wait for the tabs and popups in non-extension domain to stay open.
312 // Expect everything else, including panels, to close.
[email protected]4cdd8572013-02-15 00:33:25313 num_popups -= 1;
[email protected]f1c102b2013-02-15 07:44:12314#if defined(USE_ASH_PANELS)
315 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePanels)) {
316 // On Ash, new panel windows open as popup windows instead, so there are 2
317 // extension domain popups that will close (instead of 1 popup on non-Ash).
318 num_popups -= 1;
319 }
[email protected]4cdd8572013-02-15 00:33:25320#endif
[email protected]9111fff2013-06-12 18:01:55321#if defined(USE_ASH)
322#if !defined(OS_WIN)
323 // On linux ash we close all popup applications when closing its extension.
324 num_popups = 0;
325#endif
326#endif
[email protected]f1c102b2013-02-15 07:44:12327 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 1, num_popups, 0));
[email protected]4cdd8572013-02-15 00:33:25328}
329
[email protected]4ad85f42013-07-24 02:31:57330// This test isn't applicable on Chrome OS, which automatically reloads
331// crashed pages.
332#if !defined(OS_CHROMEOS)
333IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, ClosePanelsOnExtensionCrash) {
[email protected]f1c102b2013-02-15 07:44:12334#if defined(USE_ASH_PANELS)
[email protected]4cdd8572013-02-15 00:33:25335 // On Ash, new panel windows open as popup windows instead.
336 int num_popups = 4;
337 int num_panels = 0;
338#else
339 int num_popups = 2;
340 int num_panels = 2;
341#endif
[email protected]c1dffe82013-06-26 20:59:05342 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]4cdd8572013-02-15 00:33:25343
344 // Setup listeners to wait on strings we expect the extension pages to send.
345 std::vector<std::string> test_strings;
346 test_strings.push_back("content_tab");
347 if (num_panels)
348 test_strings.push_back("content_panel");
349 test_strings.push_back("content_popup");
350
351 ScopedVector<ExtensionTestMessageListener> listeners;
352 for (size_t i = 0; i < test_strings.size(); ++i) {
353 listeners.push_back(
354 new ExtensionTestMessageListener(test_strings[i], false));
355 }
356
357 const extensions::Extension* extension = LoadExtension(
358 test_data_dir_.AppendASCII("window_open").AppendASCII(
359 "close_panels_on_uninstall"));
360 ASSERT_TRUE(extension);
361
362 // Two tabs. One in extension domain and one in non-extension domain.
363 // Two popups - one in extension domain and one in non-extension domain.
364 // Two panels - one in extension domain and one in non-extension domain.
[email protected]f1c102b2013-02-15 07:44:12365 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, num_panels));
[email protected]1dd66b72012-09-19 20:41:48366
367 // Wait on test messages to make sure the pages loaded.
368 for (size_t i = 0; i < listeners.size(); ++i)
369 ASSERT_TRUE(listeners[i]->WaitUntilSatisfied());
370
371 // Crash the extension.
372 extensions::ExtensionHost* extension_host =
[email protected]be93bba02012-10-24 16:44:03373 extensions::ExtensionSystem::Get(browser()->profile())->
374 process_manager()->GetBackgroundHostForExtension(extension->id());
[email protected]1dd66b72012-09-19 20:41:48375 ASSERT_TRUE(extension_host);
376 base::KillProcess(extension_host->render_process_host()->GetHandle(),
377 content::RESULT_CODE_KILLED, false);
378 WaitForExtensionCrash(extension->id());
379
380 // Only expect panels to close. The rest stay open to show a sad-tab.
[email protected]f1c102b2013-02-15 07:44:12381 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, 0));
[email protected]1dd66b72012-09-19 20:41:48382}
[email protected]4ad85f42013-07-24 02:31:57383#endif // !defined(OS_CHROMEOS)
[email protected]1dd66b72012-09-19 20:41:48384
[email protected]f1c102b2013-02-15 07:44:12385#if defined(USE_ASH_PANELS)
386// This test is not applicable on Ash. The modified window.open behavior only
387// applies to non-Ash panel windows.
[email protected]99f4fdb92012-08-30 23:13:51388#define MAYBE_WindowOpenFromPanel DISABLED_WindowOpenFromPanel
389#else
390#define MAYBE_WindowOpenFromPanel WindowOpenFromPanel
391#endif
392IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenFromPanel) {
[email protected]c1dffe82013-06-26 20:59:05393 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]6798c332012-08-29 02:16:51394
[email protected]99f4fdb92012-08-30 23:13:51395 // Load the extension that will open a panel which then calls window.open.
[email protected]6798c332012-08-29 02:16:51396 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("window_open").
397 AppendASCII("panel_window_open")));
[email protected]99f4fdb92012-08-30 23:13:51398
399 // Expect one panel (opened by extension) and one tab (from the panel calling
400 // window.open). Panels modify the WindowOpenDisposition in window.open
401 // to always open in a tab.
[email protected]f1c102b2013-02-15 07:44:12402 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 1, 0, 1));
[email protected]6798c332012-08-29 02:16:51403}
404
[email protected]24c6bcfc2012-02-29 21:06:36405IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpener) {
[email protected]54edcea2011-07-27 01:56:38406 ASSERT_TRUE(RunExtensionTest("window_open/opener")) << message_;
407}
[email protected]fad73672012-06-15 23:26:06408
[email protected]fa7c1602013-04-03 23:00:20409#if defined(OS_MACOSX)
410// Extension popup windows are incorrectly sized on OSX, crbug.com/225601
411#define MAYBE_WindowOpenSized DISABLED_WindowOpenSized
412#else
413#define MAYBE_WindowOpenSized WindowOpenSized
414#endif
415// Ensure that the width and height properties of a window opened with
416// chrome.windows.create match the creation parameters. See crbug.com/173831.
417IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_WindowOpenSized) {
418 ASSERT_TRUE(RunExtensionTest("window_open/window_size")) << message_;
419 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 1, 0));
420}
421
[email protected]fad73672012-06-15 23:26:06422// Tests that an extension page can call window.open to an extension URL and
423// the new window has extension privileges.
424IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenExtension) {
425 ASSERT_TRUE(LoadExtension(
426 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
427
428 GURL start_url(std::string("chrome-extension://") +
429 last_loaded_extension_id_ + "/test.html");
430 ui_test_utils::NavigateToURL(browser(), start_url);
[email protected]f3e73f62012-10-20 05:35:16431 WebContents* newtab = NULL;
[email protected]e0448872013-01-11 19:35:02432 ASSERT_NO_FATAL_FAILURE(
433 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(),
434 start_url.Resolve("newtab.html"), true, &newtab));
[email protected]fad73672012-06-15 23:26:06435
436 bool result = false;
[email protected]b6987e02013-01-04 18:30:43437 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()",
438 &result));
[email protected]fad73672012-06-15 23:26:06439 EXPECT_TRUE(result);
440}
441
442// Tests that if an extension page calls window.open to an invalid extension
443// URL, the browser doesn't crash.
444IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) {
445 ASSERT_TRUE(LoadExtension(
446 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
447
448 GURL start_url(std::string("chrome-extension://") +
449 last_loaded_extension_id_ + "/test.html");
450 ui_test_utils::NavigateToURL(browser(), start_url);
[email protected]e0448872013-01-11 19:35:02451 ASSERT_NO_FATAL_FAILURE(
452 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]fad73672012-06-15 23:26:06453 GURL("chrome-extension://thisissurelynotavalidextensionid/newtab.html"),
454 false, NULL));
455
456 // If we got to this point, we didn't crash, so we're good.
457}
458
459// Tests that calling window.open from the newtab page to an extension URL
460// gives the new window extension privileges - even though the opening page
461// does not have extension privileges, we break the script connection, so
462// there is no privilege leak.
463IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) {
464 ASSERT_TRUE(LoadExtension(
465 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
466
467 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
[email protected]f3e73f62012-10-20 05:35:16468 WebContents* newtab = NULL;
[email protected]e0448872013-01-11 19:35:02469 ASSERT_NO_FATAL_FAILURE(
470 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]fad73672012-06-15 23:26:06471 GURL(std::string("chrome-extension://") + last_loaded_extension_id_ +
472 "/newtab.html"), false, &newtab));
473
474 // Extension API should succeed.
475 bool result = false;
[email protected]b6987e02013-01-04 18:30:43476 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()",
477 &result));
[email protected]fad73672012-06-15 23:26:06478 EXPECT_TRUE(result);
479}