blob: 80466511dd11a0de82740e30b8a7b7dd64871947 [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]1dd66b72012-09-19 20:41:4810#include "chrome/browser/extensions/extension_host.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]7c6ef352013-09-26 07:23:1419#include "chrome/common/chrome_paths.h"
[email protected]32b7c492010-09-01 04:15:0020#include "chrome/common/chrome_switches.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]98b6d942013-11-10 00:34:0727#include "extensions/browser/process_manager.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"
[email protected]f2cb3cf2013-03-21 01:40:5330#include "net/dns/mock_host_resolver.h"
[email protected]7c6ef352013-09-26 07:23:1431#include "net/test/embedded_test_server/embedded_test_server.h"
[email protected]bc44f4142013-02-12 06:15:5632#include "testing/gtest/include/gtest/gtest.h"
[email protected]32b7c492010-09-01 04:15:0033
[email protected]f1c102b2013-02-15 07:44:1234#if defined(USE_ASH)
[email protected]f6d9b282013-08-09 11:03:2035#include "apps/shell_window_registry.h"
[email protected]f1c102b2013-02-15 07:44:1236#endif
37
38#if defined(USE_ASH) && !defined(OS_WIN)
39// TODO(stevenjb): Figure out the correct behavior for Ash + Win
40#define USE_ASH_PANELS
41#endif
42
[email protected]e5d549d2011-12-28 01:29:2043using content::OpenURLParams;
44using content::Referrer;
[email protected]fad73672012-06-15 23:26:0645using content::WebContents;
[email protected]e5d549d2011-12-28 01:29:2046
[email protected]e78eb292010-12-22 08:35:3947// Disabled, http://crbug.com/64899.
48IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpen) {
[email protected]32b7c492010-09-01 04:15:0049 CommandLine::ForCurrentProcess()->AppendSwitch(
[email protected]c8d02992013-07-31 22:16:5150 extensions::switches::kEnableExperimentalExtensionApis);
[email protected]32b7c492010-09-01 04:15:0051
52 ResultCatcher catcher;
53 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_
54 .AppendASCII("window_open").AppendASCII("spanning")));
55 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
56}
[email protected]4026ce1e2010-09-14 19:35:0457
[email protected]f1c102b2013-02-15 07:44:1258int GetPanelCount(Browser* browser) {
59#if defined(USE_ASH_PANELS)
[email protected]f6d9b282013-08-09 11:03:2060 return static_cast<int>(apps::ShellWindowRegistry::Get(
[email protected]f1c102b2013-02-15 07:44:1261 browser->profile())->shell_windows().size());
62#else
63 return PanelManager::GetInstance()->num_panels();
64#endif
65}
66
67bool WaitForTabsAndPopups(Browser* browser,
[email protected]f9e82d92011-10-29 00:50:4568 int num_tabs,
69 int num_popups,
70 int num_panels) {
[email protected]58b349b2011-11-23 02:07:1571 SCOPED_TRACE(
[email protected]7d3cbc92013-03-18 22:33:0472 base::StringPrintf("WaitForTabsAndPopups tabs:%d, popups:%d, panels:%d",
73 num_tabs, num_popups, num_panels));
[email protected]4026ce1e2010-09-14 19:35:0474 // We start with one tab and one browser already open.
75 ++num_tabs;
[email protected]f6ffa7d2012-08-17 17:27:0876 size_t num_browsers = static_cast<size_t>(num_popups) + 1;
[email protected]4026ce1e2010-09-14 19:35:0477
[email protected]f1c102b2013-02-15 07:44:1278 const base::TimeDelta kWaitTime = base::TimeDelta::FromSeconds(10);
[email protected]0a5bdc6522011-06-08 19:04:4979 base::TimeTicks end_time = base::TimeTicks::Now() + kWaitTime;
80 while (base::TimeTicks::Now() < end_time) {
[email protected]c987a242013-02-28 01:17:4181 if (chrome::GetBrowserCount(browser->profile(),
82 browser->host_desktop_type()) == num_browsers &&
[email protected]e0448872013-01-11 19:35:0283 browser->tab_strip_model()->count() == num_tabs &&
[email protected]f1c102b2013-02-15 07:44:1284 GetPanelCount(browser) == num_panels)
[email protected]0a5bdc6522011-06-08 19:04:4985 break;
86
[email protected]b8deecd2012-07-30 21:09:4487 content::RunAllPendingInMessageLoop();
[email protected]0a5bdc6522011-06-08 19:04:4988 }
89
[email protected]c987a242013-02-28 01:17:4190 EXPECT_EQ(num_browsers,
91 chrome::GetBrowserCount(browser->profile(),
92 browser->host_desktop_type()));
[email protected]e0448872013-01-11 19:35:0293 EXPECT_EQ(num_tabs, browser->tab_strip_model()->count());
[email protected]f1c102b2013-02-15 07:44:1294 EXPECT_EQ(num_panels, GetPanelCount(browser));
[email protected]0a5bdc6522011-06-08 19:04:4995
[email protected]f9e82d92011-10-29 00:50:4596 int num_popups_seen = 0;
[email protected]bc44f4142013-02-12 06:15:5697 for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) {
[email protected]0a5bdc6522011-06-08 19:04:4998 if (*iter == browser)
[email protected]4026ce1e2010-09-14 19:35:0499 continue;
[email protected]4026ce1e2010-09-14 19:35:04100
[email protected]f6ffa7d2012-08-17 17:27:08101 EXPECT_TRUE((*iter)->is_type_popup());
102 ++num_popups_seen;
[email protected]4026ce1e2010-09-14 19:35:04103 }
[email protected]f9e82d92011-10-29 00:50:45104 EXPECT_EQ(num_popups, num_popups_seen);
[email protected]f1c102b2013-02-15 07:44:12105
[email protected]c987a242013-02-28 01:17:41106 return ((num_browsers ==
107 chrome::GetBrowserCount(browser->profile(),
108 browser->host_desktop_type())) &&
[email protected]f1c102b2013-02-15 07:44:12109 (num_tabs == browser->tab_strip_model()->count()) &&
110 (num_panels == GetPanelCount(browser)) &&
111 (num_popups == num_popups_seen));
[email protected]4026ce1e2010-09-14 19:35:04112}
113
[email protected]f112b0f2011-05-26 01:53:52114IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserIsApp) {
115 host_resolver()->AddRule("a.com", "127.0.0.1");
[email protected]c1dffe82013-06-26 20:59:05116 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]f112b0f2011-05-26 01:53:52117 ASSERT_TRUE(LoadExtension(
118 test_data_dir_.AppendASCII("window_open").AppendASCII("browser_is_app")));
119
[email protected]f1c102b2013-02-15 07:44:12120 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 2, 0));
[email protected]f112b0f2011-05-26 01:53:52121
[email protected]bc44f4142013-02-12 06:15:56122 for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) {
[email protected]f112b0f2011-05-26 01:53:52123 if (*iter == browser())
[email protected]bc44f4142013-02-12 06:15:56124 ASSERT_FALSE(iter->is_app());
[email protected]f112b0f2011-05-26 01:53:52125 else
[email protected]bc44f4142013-02-12 06:15:56126 ASSERT_TRUE(iter->is_app());
[email protected]f112b0f2011-05-26 01:53:52127 }
128}
129
[email protected]0a5bdc6522011-06-08 19:04:49130IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupDefault) {
[email protected]c1dffe82013-06-26 20:59:05131 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]0a5bdc6522011-06-08 19:04:49132 ASSERT_TRUE(LoadExtension(
133 test_data_dir_.AppendASCII("window_open").AppendASCII("popup")));
134
135 const int num_tabs = 1;
136 const int num_popups = 0;
[email protected]f1c102b2013-02-15 07:44:12137 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0));
[email protected]0a5bdc6522011-06-08 19:04:49138}
139
[email protected]7c6ef352013-09-26 07:23:14140IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupIframe) {
141 ASSERT_TRUE(StartEmbeddedTestServer());
142 base::FilePath test_data_dir;
143 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
144 embedded_test_server()->ServeFilesFromDirectory(test_data_dir);
145 ASSERT_TRUE(LoadExtension(
146 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_iframe")));
147
148 const int num_tabs = 0;
149 const int num_popups = 1;
150 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0));
151}
152
[email protected]0a5bdc6522011-06-08 19:04:49153IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupLarge) {
[email protected]c1dffe82013-06-26 20:59:05154 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]0a5bdc6522011-06-08 19:04:49155 ASSERT_TRUE(LoadExtension(
156 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_large")));
157
[email protected]0a5bdc6522011-06-08 19:04:49158 // On other systems this should open a new popup window.
159 const int num_tabs = 0;
160 const int num_popups = 1;
[email protected]f1c102b2013-02-15 07:44:12161 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0));
[email protected]0a5bdc6522011-06-08 19:04:49162}
163
164IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupSmall) {
[email protected]c1dffe82013-06-26 20:59:05165 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]0a5bdc6522011-06-08 19:04:49166 ASSERT_TRUE(LoadExtension(
167 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_small")));
168
169 // On ChromeOS this should open a new panel (acts like a new popup window).
170 // On other systems this should open a new popup window.
171 const int num_tabs = 0;
172 const int num_popups = 1;
[email protected]f1c102b2013-02-15 07:44:12173 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0));
[email protected]0a5bdc6522011-06-08 19:04:49174}
175
[email protected]73fa1fce2013-02-21 20:10:05176// Disabled on Windows. Often times out or fails: crbug.com/177530
177#if defined(OS_WIN)
178#define MAYBE_PopupBlockingExtension DISABLED_PopupBlockingExtension
179#else
180#define MAYBE_PopupBlockingExtension PopupBlockingExtension
181#endif
182IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_PopupBlockingExtension) {
[email protected]4026ce1e2010-09-14 19:35:04183 host_resolver()->AddRule("*", "127.0.0.1");
[email protected]c1dffe82013-06-26 20:59:05184 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]4026ce1e2010-09-14 19:35:04185
186 ASSERT_TRUE(LoadExtension(
187 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking")
188 .AppendASCII("extension")));
189
[email protected]f1c102b2013-02-15 07:44:12190 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 5, 3, 0));
[email protected]4026ce1e2010-09-14 19:35:04191}
192
193IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PopupBlockingHostedApp) {
194 host_resolver()->AddRule("*", "127.0.0.1");
195 ASSERT_TRUE(test_server()->Start());
196
197 ASSERT_TRUE(LoadExtension(
198 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking")
199 .AppendASCII("hosted_app")));
200
[email protected]fe3048872010-10-18 14:58:59201 // The app being tested owns the domain a.com . The test URLs we navigate
202 // to below must be within that domain, so that they fall within the app's
203 // web extent.
204 GURL::Replacements replace_host;
205 std::string a_dot_com = "a.com";
206 replace_host.SetHostStr(a_dot_com);
207
208 const std::string popup_app_contents_path(
209 "files/extensions/api_test/window_open/popup_blocking/hosted_app/");
210
211 GURL open_tab =
212 test_server()->GetURL(popup_app_contents_path + "open_tab.html")
213 .ReplaceComponents(replace_host);
214 GURL open_popup =
215 test_server()->GetURL(popup_app_contents_path + "open_popup.html")
216 .ReplaceComponents(replace_host);
217
[email protected]e5d549d2011-12-28 01:29:20218 browser()->OpenURL(OpenURLParams(
219 open_tab, Referrer(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED,
220 false));
221 browser()->OpenURL(OpenURLParams(
222 open_popup, Referrer(), NEW_FOREGROUND_TAB,
223 content::PAGE_TRANSITION_TYPED, false));
[email protected]4026ce1e2010-09-14 19:35:04224
[email protected]f1c102b2013-02-15 07:44:12225 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 3, 1, 0));
[email protected]4026ce1e2010-09-14 19:35:04226}
[email protected]d4db6c702011-03-28 21:49:14227
[email protected]e7f90562011-05-23 21:38:24228IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowArgumentsOverflow) {
229 ASSERT_TRUE(RunExtensionTest("window_open/argument_overflow")) << message_;
230}
231
[email protected]d5c14062011-10-27 00:02:13232class WindowOpenPanelDisabledTest : public ExtensionApiTest {
[email protected]49aeab62013-02-07 02:53:11233 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
[email protected]08aa0c32011-04-11 22:18:37234 ExtensionApiTest::SetUpCommandLine(command_line);
[email protected]7e7a28092011-12-09 22:24:55235 // TODO(jennb): Re-enable when panels are enabled by default.
236 // command_line->AppendSwitch(switches::kDisablePanels);
[email protected]08aa0c32011-04-11 22:18:37237 }
238};
239
[email protected]7e7a28092011-12-09 22:24:55240IN_PROC_BROWSER_TEST_F(WindowOpenPanelDisabledTest,
241 DISABLED_WindowOpenPanelNotEnabled) {
[email protected]d5c14062011-10-27 00:02:13242 ASSERT_TRUE(RunExtensionTest("window_open/panel_not_enabled")) << message_;
243}
244
[email protected]af6b54512011-12-14 06:11:21245class WindowOpenPanelTest : public ExtensionApiTest {
[email protected]49aeab62013-02-07 02:53:11246 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
[email protected]af6b54512011-12-14 06:11:21247 ExtensionApiTest::SetUpCommandLine(command_line);
248 command_line->AppendSwitch(switches::kEnablePanels);
249 }
250};
251
[email protected]f1c102b2013-02-15 07:44:12252#if defined(USE_ASH_PANELS)
[email protected]87d722a2012-07-12 15:38:33253// On Ash, this currently fails because we're currently opening new panel
[email protected]d101b0c2012-03-16 00:30:57254// windows as popup windows instead.
[email protected]e00ccc92012-11-01 17:32:30255#define MAYBE_WindowOpenPanel DISABLED_WindowOpenPanel
[email protected]d101b0c2012-03-16 00:30:57256#else
257#define MAYBE_WindowOpenPanel WindowOpenPanel
258#endif
259IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenPanel) {
[email protected]08aa0c32011-04-11 22:18:37260 ASSERT_TRUE(RunExtensionTest("window_open/panel")) << message_;
261}
[email protected]54edcea2011-07-27 01:56:38262
[email protected]cb1849e2013-07-08 21:12:53263#if defined(USE_ASH_PANELS)
[email protected]ca29ed12012-09-06 09:10:50264// On Ash, this currently fails because we're currently opening new panel
265// windows as popup windows instead.
[email protected]cb1849e2013-07-08 21:12:53266#define MAYBE_WindowOpenPanelDetached DISABLED_WindowOpenPanelDetached
267#else
268#define MAYBE_WindowOpenPanelDetached WindowOpenPanelDetached
269#endif
270IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenPanelDetached) {
[email protected]ca29ed12012-09-06 09:10:50271 ASSERT_TRUE(RunExtensionTest("window_open/panel_detached")) << message_;
272}
273
[email protected]af6b54512011-12-14 06:11:21274IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest,
[email protected]f9e82d92011-10-29 00:50:45275 CloseNonExtensionPanelsOnUninstall) {
[email protected]45c6f6722013-07-23 03:02:19276#if defined(OS_WIN) && defined(USE_ASH)
277 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
[email protected]b65d4bdcc2013-07-31 00:37:33278 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
[email protected]45c6f6722013-07-23 03:02:19279 return;
280#endif
281
[email protected]f1c102b2013-02-15 07:44:12282#if defined(USE_ASH_PANELS)
[email protected]1dd66b72012-09-19 20:41:48283 // On Ash, new panel windows open as popup windows instead.
[email protected]f1c102b2013-02-15 07:44:12284 int num_popups, num_panels;
285 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePanels)) {
286 num_popups = 2;
287 num_panels = 2;
288 } else {
289 num_popups = 4;
290 num_panels = 0;
291 }
[email protected]1dd66b72012-09-19 20:41:48292#else
293 int num_popups = 2;
294 int num_panels = 2;
295#endif
[email protected]c1dffe82013-06-26 20:59:05296 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]1dd66b72012-09-19 20:41:48297
298 // Setup listeners to wait on strings we expect the extension pages to send.
299 std::vector<std::string> test_strings;
300 test_strings.push_back("content_tab");
301 if (num_panels)
302 test_strings.push_back("content_panel");
303 test_strings.push_back("content_popup");
304
305 ScopedVector<ExtensionTestMessageListener> listeners;
306 for (size_t i = 0; i < test_strings.size(); ++i) {
307 listeners.push_back(
308 new ExtensionTestMessageListener(test_strings[i], false));
309 }
310
311 const extensions::Extension* extension = LoadExtension(
312 test_data_dir_.AppendASCII("window_open").AppendASCII(
313 "close_panels_on_uninstall"));
314 ASSERT_TRUE(extension);
315
316 // Two tabs. One in extension domain and one in non-extension domain.
317 // Two popups - one in extension domain and one in non-extension domain.
318 // Two panels - one in extension domain and one in non-extension domain.
[email protected]f1c102b2013-02-15 07:44:12319 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, num_panels));
[email protected]4cdd8572013-02-15 00:33:25320
321 // Wait on test messages to make sure the pages loaded.
322 for (size_t i = 0; i < listeners.size(); ++i)
323 ASSERT_TRUE(listeners[i]->WaitUntilSatisfied());
324
325 UninstallExtension(extension->id());
326
327 // Wait for the tabs and popups in non-extension domain to stay open.
328 // Expect everything else, including panels, to close.
[email protected]4cdd8572013-02-15 00:33:25329 num_popups -= 1;
[email protected]f1c102b2013-02-15 07:44:12330#if defined(USE_ASH_PANELS)
331 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePanels)) {
332 // On Ash, new panel windows open as popup windows instead, so there are 2
333 // extension domain popups that will close (instead of 1 popup on non-Ash).
334 num_popups -= 1;
335 }
[email protected]4cdd8572013-02-15 00:33:25336#endif
[email protected]9111fff2013-06-12 18:01:55337#if defined(USE_ASH)
338#if !defined(OS_WIN)
339 // On linux ash we close all popup applications when closing its extension.
340 num_popups = 0;
341#endif
342#endif
[email protected]f1c102b2013-02-15 07:44:12343 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 1, num_popups, 0));
[email protected]4cdd8572013-02-15 00:33:25344}
345
[email protected]4ad85f42013-07-24 02:31:57346// This test isn't applicable on Chrome OS, which automatically reloads
347// crashed pages.
348#if !defined(OS_CHROMEOS)
349IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, ClosePanelsOnExtensionCrash) {
[email protected]f1c102b2013-02-15 07:44:12350#if defined(USE_ASH_PANELS)
[email protected]4cdd8572013-02-15 00:33:25351 // On Ash, new panel windows open as popup windows instead.
352 int num_popups = 4;
353 int num_panels = 0;
354#else
355 int num_popups = 2;
356 int num_panels = 2;
357#endif
[email protected]c1dffe82013-06-26 20:59:05358 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]4cdd8572013-02-15 00:33:25359
360 // Setup listeners to wait on strings we expect the extension pages to send.
361 std::vector<std::string> test_strings;
362 test_strings.push_back("content_tab");
363 if (num_panels)
364 test_strings.push_back("content_panel");
365 test_strings.push_back("content_popup");
366
367 ScopedVector<ExtensionTestMessageListener> listeners;
368 for (size_t i = 0; i < test_strings.size(); ++i) {
369 listeners.push_back(
370 new ExtensionTestMessageListener(test_strings[i], false));
371 }
372
373 const extensions::Extension* extension = LoadExtension(
374 test_data_dir_.AppendASCII("window_open").AppendASCII(
375 "close_panels_on_uninstall"));
376 ASSERT_TRUE(extension);
377
378 // Two tabs. One in extension domain and one in non-extension domain.
379 // Two popups - one in extension domain and one in non-extension domain.
380 // Two panels - one in extension domain and one in non-extension domain.
[email protected]f1c102b2013-02-15 07:44:12381 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, num_panels));
[email protected]1dd66b72012-09-19 20:41:48382
383 // Wait on test messages to make sure the pages loaded.
384 for (size_t i = 0; i < listeners.size(); ++i)
385 ASSERT_TRUE(listeners[i]->WaitUntilSatisfied());
386
387 // Crash the extension.
388 extensions::ExtensionHost* extension_host =
[email protected]be93bba02012-10-24 16:44:03389 extensions::ExtensionSystem::Get(browser()->profile())->
390 process_manager()->GetBackgroundHostForExtension(extension->id());
[email protected]1dd66b72012-09-19 20:41:48391 ASSERT_TRUE(extension_host);
392 base::KillProcess(extension_host->render_process_host()->GetHandle(),
393 content::RESULT_CODE_KILLED, false);
394 WaitForExtensionCrash(extension->id());
395
396 // Only expect panels to close. The rest stay open to show a sad-tab.
[email protected]f1c102b2013-02-15 07:44:12397 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, 0));
[email protected]1dd66b72012-09-19 20:41:48398}
[email protected]4ad85f42013-07-24 02:31:57399#endif // !defined(OS_CHROMEOS)
[email protected]1dd66b72012-09-19 20:41:48400
[email protected]f1c102b2013-02-15 07:44:12401#if defined(USE_ASH_PANELS)
402// This test is not applicable on Ash. The modified window.open behavior only
403// applies to non-Ash panel windows.
[email protected]99f4fdb92012-08-30 23:13:51404#define MAYBE_WindowOpenFromPanel DISABLED_WindowOpenFromPanel
405#else
406#define MAYBE_WindowOpenFromPanel WindowOpenFromPanel
407#endif
408IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenFromPanel) {
[email protected]c1dffe82013-06-26 20:59:05409 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]6798c332012-08-29 02:16:51410
[email protected]99f4fdb92012-08-30 23:13:51411 // Load the extension that will open a panel which then calls window.open.
[email protected]6798c332012-08-29 02:16:51412 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("window_open").
413 AppendASCII("panel_window_open")));
[email protected]99f4fdb92012-08-30 23:13:51414
415 // Expect one panel (opened by extension) and one tab (from the panel calling
416 // window.open). Panels modify the WindowOpenDisposition in window.open
417 // to always open in a tab.
[email protected]f1c102b2013-02-15 07:44:12418 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 1, 0, 1));
[email protected]6798c332012-08-29 02:16:51419}
420
[email protected]24c6bcfc2012-02-29 21:06:36421IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpener) {
[email protected]54edcea2011-07-27 01:56:38422 ASSERT_TRUE(RunExtensionTest("window_open/opener")) << message_;
423}
[email protected]fad73672012-06-15 23:26:06424
[email protected]fa7c1602013-04-03 23:00:20425#if defined(OS_MACOSX)
426// Extension popup windows are incorrectly sized on OSX, crbug.com/225601
427#define MAYBE_WindowOpenSized DISABLED_WindowOpenSized
428#else
429#define MAYBE_WindowOpenSized WindowOpenSized
430#endif
431// Ensure that the width and height properties of a window opened with
432// chrome.windows.create match the creation parameters. See crbug.com/173831.
433IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_WindowOpenSized) {
434 ASSERT_TRUE(RunExtensionTest("window_open/window_size")) << message_;
435 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 1, 0));
436}
437
[email protected]fad73672012-06-15 23:26:06438// Tests that an extension page can call window.open to an extension URL and
439// the new window has extension privileges.
440IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenExtension) {
441 ASSERT_TRUE(LoadExtension(
442 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
443
444 GURL start_url(std::string("chrome-extension://") +
[email protected]918c2712013-10-21 23:59:56445 last_loaded_extension_id() + "/test.html");
[email protected]fad73672012-06-15 23:26:06446 ui_test_utils::NavigateToURL(browser(), start_url);
[email protected]f3e73f62012-10-20 05:35:16447 WebContents* newtab = NULL;
[email protected]e0448872013-01-11 19:35:02448 ASSERT_NO_FATAL_FAILURE(
449 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(),
450 start_url.Resolve("newtab.html"), true, &newtab));
[email protected]fad73672012-06-15 23:26:06451
452 bool result = false;
[email protected]b6987e02013-01-04 18:30:43453 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()",
454 &result));
[email protected]fad73672012-06-15 23:26:06455 EXPECT_TRUE(result);
456}
457
458// Tests that if an extension page calls window.open to an invalid extension
459// URL, the browser doesn't crash.
460IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) {
461 ASSERT_TRUE(LoadExtension(
462 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
463
464 GURL start_url(std::string("chrome-extension://") +
[email protected]918c2712013-10-21 23:59:56465 last_loaded_extension_id() + "/test.html");
[email protected]fad73672012-06-15 23:26:06466 ui_test_utils::NavigateToURL(browser(), start_url);
[email protected]e0448872013-01-11 19:35:02467 ASSERT_NO_FATAL_FAILURE(
468 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]fad73672012-06-15 23:26:06469 GURL("chrome-extension://thisissurelynotavalidextensionid/newtab.html"),
470 false, NULL));
471
472 // If we got to this point, we didn't crash, so we're good.
473}
474
475// Tests that calling window.open from the newtab page to an extension URL
476// gives the new window extension privileges - even though the opening page
477// does not have extension privileges, we break the script connection, so
478// there is no privilege leak.
479IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) {
480 ASSERT_TRUE(LoadExtension(
481 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
482
483 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
[email protected]f3e73f62012-10-20 05:35:16484 WebContents* newtab = NULL;
[email protected]e0448872013-01-11 19:35:02485 ASSERT_NO_FATAL_FAILURE(
486 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]918c2712013-10-21 23:59:56487 GURL(std::string("chrome-extension://") + last_loaded_extension_id() +
[email protected]fad73672012-06-15 23:26:06488 "/newtab.html"), false, &newtab));
489
490 // Extension API should succeed.
491 bool result = false;
[email protected]b6987e02013-01-04 18:30:43492 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()",
493 &result));
[email protected]fad73672012-06-15 23:26:06494 EXPECT_TRUE(result);
495}