blob: 7ebb814d5e6163d3440307e290e8cb41199edb1d [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]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]f6ffa7d2012-08-17 17:27:0816#include "chrome/browser/ui/panels/panel_manager.h"
[email protected]e0448872013-01-11 19:35:0217#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]32b7c492010-09-01 04:15:0018#include "chrome/common/chrome_switches.h"
[email protected]f9e82d92011-10-29 00:50:4519#include "chrome/common/extensions/extension.h"
[email protected]af44e7fb2011-07-29 18:32:3220#include "chrome/test/base/ui_test_utils.h"
[email protected]1dd66b72012-09-19 20:41:4821#include "content/public/browser/render_process_host.h"
[email protected]fad73672012-06-15 23:26:0622#include "content/public/browser/web_contents.h"
[email protected]1dd66b72012-09-19 20:41:4823#include "content/public/common/result_codes.h"
[email protected]7d478cb2012-07-24 17:19:4224#include "content/public/test/browser_test_utils.h"
[email protected]f2cb3cf2013-03-21 01:40:5325#include "net/dns/mock_host_resolver.h"
[email protected]bc44f4142013-02-12 06:15:5626#include "testing/gtest/include/gtest/gtest.h"
[email protected]32b7c492010-09-01 04:15:0027
[email protected]f1c102b2013-02-15 07:44:1228#if defined(USE_ASH)
29#include "chrome/browser/extensions/shell_window_registry.h"
30#endif
31
[email protected]45c6f6722013-07-23 03:02:1932#if defined(OS_WIN) && defined(USE_ASH)
33#include "base/win/windows_version.h"
34#endif
35
[email protected]f1c102b2013-02-15 07:44:1236#if defined(USE_ASH) && !defined(OS_WIN)
37// TODO(stevenjb): Figure out the correct behavior for Ash + Win
38#define USE_ASH_PANELS
39#endif
40
[email protected]e5d549d2011-12-28 01:29:2041using content::OpenURLParams;
42using content::Referrer;
[email protected]fad73672012-06-15 23:26:0643using content::WebContents;
[email protected]e5d549d2011-12-28 01:29:2044
[email protected]e78eb292010-12-22 08:35:3945// Disabled, http://crbug.com/64899.
46IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpen) {
[email protected]32b7c492010-09-01 04:15:0047 CommandLine::ForCurrentProcess()->AppendSwitch(
48 switches::kEnableExperimentalExtensionApis);
49
50 ResultCatcher catcher;
51 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_
52 .AppendASCII("window_open").AppendASCII("spanning")));
53 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
54}
[email protected]4026ce1e2010-09-14 19:35:0455
[email protected]f1c102b2013-02-15 07:44:1256int GetPanelCount(Browser* browser) {
57#if defined(USE_ASH_PANELS)
58 return static_cast<int>(extensions::ShellWindowRegistry::Get(
59 browser->profile())->shell_windows().size());
60#else
61 return PanelManager::GetInstance()->num_panels();
62#endif
63}
64
65bool WaitForTabsAndPopups(Browser* browser,
[email protected]f9e82d92011-10-29 00:50:4566 int num_tabs,
67 int num_popups,
68 int num_panels) {
[email protected]58b349b2011-11-23 02:07:1569 SCOPED_TRACE(
[email protected]7d3cbc92013-03-18 22:33:0470 base::StringPrintf("WaitForTabsAndPopups tabs:%d, popups:%d, panels:%d",
71 num_tabs, num_popups, num_panels));
[email protected]4026ce1e2010-09-14 19:35:0472 // We start with one tab and one browser already open.
73 ++num_tabs;
[email protected]f6ffa7d2012-08-17 17:27:0874 size_t num_browsers = static_cast<size_t>(num_popups) + 1;
[email protected]4026ce1e2010-09-14 19:35:0475
[email protected]f1c102b2013-02-15 07:44:1276 const base::TimeDelta kWaitTime = base::TimeDelta::FromSeconds(10);
[email protected]0a5bdc6522011-06-08 19:04:4977 base::TimeTicks end_time = base::TimeTicks::Now() + kWaitTime;
78 while (base::TimeTicks::Now() < end_time) {
[email protected]c987a242013-02-28 01:17:4179 if (chrome::GetBrowserCount(browser->profile(),
80 browser->host_desktop_type()) == num_browsers &&
[email protected]e0448872013-01-11 19:35:0281 browser->tab_strip_model()->count() == num_tabs &&
[email protected]f1c102b2013-02-15 07:44:1282 GetPanelCount(browser) == num_panels)
[email protected]0a5bdc6522011-06-08 19:04:4983 break;
84
[email protected]b8deecd2012-07-30 21:09:4485 content::RunAllPendingInMessageLoop();
[email protected]0a5bdc6522011-06-08 19:04:4986 }
87
[email protected]c987a242013-02-28 01:17:4188 EXPECT_EQ(num_browsers,
89 chrome::GetBrowserCount(browser->profile(),
90 browser->host_desktop_type()));
[email protected]e0448872013-01-11 19:35:0291 EXPECT_EQ(num_tabs, browser->tab_strip_model()->count());
[email protected]f1c102b2013-02-15 07:44:1292 EXPECT_EQ(num_panels, GetPanelCount(browser));
[email protected]0a5bdc6522011-06-08 19:04:4993
[email protected]f9e82d92011-10-29 00:50:4594 int num_popups_seen = 0;
[email protected]bc44f4142013-02-12 06:15:5695 for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) {
[email protected]0a5bdc6522011-06-08 19:04:4996 if (*iter == browser)
[email protected]4026ce1e2010-09-14 19:35:0497 continue;
[email protected]4026ce1e2010-09-14 19:35:0498
[email protected]f6ffa7d2012-08-17 17:27:0899 EXPECT_TRUE((*iter)->is_type_popup());
[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
[email protected]c987a242013-02-28 01:17:41104 return ((num_browsers ==
105 chrome::GetBrowserCount(browser->profile(),
106 browser->host_desktop_type())) &&
[email protected]f1c102b2013-02-15 07:44:12107 (num_tabs == browser->tab_strip_model()->count()) &&
108 (num_panels == GetPanelCount(browser)) &&
109 (num_popups == num_popups_seen));
[email protected]4026ce1e2010-09-14 19:35:04110}
111
[email protected]f112b0f2011-05-26 01:53:52112IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserIsApp) {
113 host_resolver()->AddRule("a.com", "127.0.0.1");
[email protected]c1dffe82013-06-26 20:59:05114 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]f112b0f2011-05-26 01:53:52115 ASSERT_TRUE(LoadExtension(
116 test_data_dir_.AppendASCII("window_open").AppendASCII("browser_is_app")));
117
[email protected]f1c102b2013-02-15 07:44:12118 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 2, 0));
[email protected]f112b0f2011-05-26 01:53:52119
[email protected]bc44f4142013-02-12 06:15:56120 for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) {
[email protected]f112b0f2011-05-26 01:53:52121 if (*iter == browser())
[email protected]bc44f4142013-02-12 06:15:56122 ASSERT_FALSE(iter->is_app());
[email protected]f112b0f2011-05-26 01:53:52123 else
[email protected]bc44f4142013-02-12 06:15:56124 ASSERT_TRUE(iter->is_app());
[email protected]f112b0f2011-05-26 01:53:52125 }
126}
127
[email protected]0a5bdc6522011-06-08 19:04:49128IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupDefault) {
[email protected]c1dffe82013-06-26 20:59:05129 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]0a5bdc6522011-06-08 19:04:49130 ASSERT_TRUE(LoadExtension(
131 test_data_dir_.AppendASCII("window_open").AppendASCII("popup")));
132
133 const int num_tabs = 1;
134 const int num_popups = 0;
[email protected]f1c102b2013-02-15 07:44:12135 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0));
[email protected]0a5bdc6522011-06-08 19:04:49136}
137
138IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupLarge) {
[email protected]c1dffe82013-06-26 20:59:05139 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]0a5bdc6522011-06-08 19:04:49140 ASSERT_TRUE(LoadExtension(
141 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_large")));
142
[email protected]0a5bdc6522011-06-08 19:04:49143 // On other systems this should open a new popup window.
144 const int num_tabs = 0;
145 const int num_popups = 1;
[email protected]f1c102b2013-02-15 07:44:12146 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0));
[email protected]0a5bdc6522011-06-08 19:04:49147}
148
149IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupSmall) {
[email protected]c1dffe82013-06-26 20:59:05150 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]0a5bdc6522011-06-08 19:04:49151 ASSERT_TRUE(LoadExtension(
152 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_small")));
153
154 // On ChromeOS this should open a new panel (acts like a new popup window).
155 // On other systems this should open a new popup window.
156 const int num_tabs = 0;
157 const int num_popups = 1;
[email protected]f1c102b2013-02-15 07:44:12158 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0));
[email protected]0a5bdc6522011-06-08 19:04:49159}
160
[email protected]73fa1fce2013-02-21 20:10:05161// Disabled on Windows. Often times out or fails: crbug.com/177530
162#if defined(OS_WIN)
163#define MAYBE_PopupBlockingExtension DISABLED_PopupBlockingExtension
164#else
165#define MAYBE_PopupBlockingExtension PopupBlockingExtension
166#endif
167IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_PopupBlockingExtension) {
[email protected]4026ce1e2010-09-14 19:35:04168 host_resolver()->AddRule("*", "127.0.0.1");
[email protected]c1dffe82013-06-26 20:59:05169 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]4026ce1e2010-09-14 19:35:04170
171 ASSERT_TRUE(LoadExtension(
172 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking")
173 .AppendASCII("extension")));
174
[email protected]f1c102b2013-02-15 07:44:12175 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 5, 3, 0));
[email protected]4026ce1e2010-09-14 19:35:04176}
177
178IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PopupBlockingHostedApp) {
179 host_resolver()->AddRule("*", "127.0.0.1");
180 ASSERT_TRUE(test_server()->Start());
181
182 ASSERT_TRUE(LoadExtension(
183 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking")
184 .AppendASCII("hosted_app")));
185
[email protected]fe3048872010-10-18 14:58:59186 // The app being tested owns the domain a.com . The test URLs we navigate
187 // to below must be within that domain, so that they fall within the app's
188 // web extent.
189 GURL::Replacements replace_host;
190 std::string a_dot_com = "a.com";
191 replace_host.SetHostStr(a_dot_com);
192
193 const std::string popup_app_contents_path(
194 "files/extensions/api_test/window_open/popup_blocking/hosted_app/");
195
196 GURL open_tab =
197 test_server()->GetURL(popup_app_contents_path + "open_tab.html")
198 .ReplaceComponents(replace_host);
199 GURL open_popup =
200 test_server()->GetURL(popup_app_contents_path + "open_popup.html")
201 .ReplaceComponents(replace_host);
202
[email protected]e5d549d2011-12-28 01:29:20203 browser()->OpenURL(OpenURLParams(
204 open_tab, Referrer(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED,
205 false));
206 browser()->OpenURL(OpenURLParams(
207 open_popup, Referrer(), NEW_FOREGROUND_TAB,
208 content::PAGE_TRANSITION_TYPED, false));
[email protected]4026ce1e2010-09-14 19:35:04209
[email protected]f1c102b2013-02-15 07:44:12210 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 3, 1, 0));
[email protected]4026ce1e2010-09-14 19:35:04211}
[email protected]d4db6c702011-03-28 21:49:14212
[email protected]e7f90562011-05-23 21:38:24213IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowArgumentsOverflow) {
214 ASSERT_TRUE(RunExtensionTest("window_open/argument_overflow")) << message_;
215}
216
[email protected]d5c14062011-10-27 00:02:13217class WindowOpenPanelDisabledTest : public ExtensionApiTest {
[email protected]49aeab62013-02-07 02:53:11218 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
[email protected]08aa0c32011-04-11 22:18:37219 ExtensionApiTest::SetUpCommandLine(command_line);
[email protected]7e7a28092011-12-09 22:24:55220 // TODO(jennb): Re-enable when panels are enabled by default.
221 // command_line->AppendSwitch(switches::kDisablePanels);
[email protected]08aa0c32011-04-11 22:18:37222 }
223};
224
[email protected]7e7a28092011-12-09 22:24:55225IN_PROC_BROWSER_TEST_F(WindowOpenPanelDisabledTest,
226 DISABLED_WindowOpenPanelNotEnabled) {
[email protected]d5c14062011-10-27 00:02:13227 ASSERT_TRUE(RunExtensionTest("window_open/panel_not_enabled")) << message_;
228}
229
[email protected]af6b54512011-12-14 06:11:21230class WindowOpenPanelTest : public ExtensionApiTest {
[email protected]49aeab62013-02-07 02:53:11231 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
[email protected]af6b54512011-12-14 06:11:21232 ExtensionApiTest::SetUpCommandLine(command_line);
233 command_line->AppendSwitch(switches::kEnablePanels);
234 }
235};
236
[email protected]f1c102b2013-02-15 07:44:12237#if defined(USE_ASH_PANELS)
[email protected]87d722a2012-07-12 15:38:33238// On Ash, this currently fails because we're currently opening new panel
[email protected]d101b0c2012-03-16 00:30:57239// windows as popup windows instead.
[email protected]e00ccc92012-11-01 17:32:30240#define MAYBE_WindowOpenPanel DISABLED_WindowOpenPanel
[email protected]d101b0c2012-03-16 00:30:57241#else
242#define MAYBE_WindowOpenPanel WindowOpenPanel
243#endif
244IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenPanel) {
[email protected]08aa0c32011-04-11 22:18:37245 ASSERT_TRUE(RunExtensionTest("window_open/panel")) << message_;
246}
[email protected]54edcea2011-07-27 01:56:38247
[email protected]cb1849e2013-07-08 21:12:53248#if defined(USE_ASH_PANELS)
[email protected]ca29ed12012-09-06 09:10:50249// On Ash, this currently fails because we're currently opening new panel
250// windows as popup windows instead.
[email protected]cb1849e2013-07-08 21:12:53251#define MAYBE_WindowOpenPanelDetached DISABLED_WindowOpenPanelDetached
252#else
253#define MAYBE_WindowOpenPanelDetached WindowOpenPanelDetached
254#endif
255IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenPanelDetached) {
[email protected]ca29ed12012-09-06 09:10:50256 ASSERT_TRUE(RunExtensionTest("window_open/panel_detached")) << message_;
257}
258
[email protected]af6b54512011-12-14 06:11:21259IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest,
[email protected]f9e82d92011-10-29 00:50:45260 CloseNonExtensionPanelsOnUninstall) {
[email protected]45c6f6722013-07-23 03:02:19261#if defined(OS_WIN) && defined(USE_ASH)
262 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
263 if (base::win::GetVersion() >= base::win::VERSION_WIN8)
264 return;
265#endif
266
[email protected]f1c102b2013-02-15 07:44:12267#if defined(USE_ASH_PANELS)
[email protected]1dd66b72012-09-19 20:41:48268 // On Ash, new panel windows open as popup windows instead.
[email protected]f1c102b2013-02-15 07:44:12269 int num_popups, num_panels;
270 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePanels)) {
271 num_popups = 2;
272 num_panels = 2;
273 } else {
274 num_popups = 4;
275 num_panels = 0;
276 }
[email protected]1dd66b72012-09-19 20:41:48277#else
278 int num_popups = 2;
279 int num_panels = 2;
280#endif
[email protected]c1dffe82013-06-26 20:59:05281 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]1dd66b72012-09-19 20:41:48282
283 // Setup listeners to wait on strings we expect the extension pages to send.
284 std::vector<std::string> test_strings;
285 test_strings.push_back("content_tab");
286 if (num_panels)
287 test_strings.push_back("content_panel");
288 test_strings.push_back("content_popup");
289
290 ScopedVector<ExtensionTestMessageListener> listeners;
291 for (size_t i = 0; i < test_strings.size(); ++i) {
292 listeners.push_back(
293 new ExtensionTestMessageListener(test_strings[i], false));
294 }
295
296 const extensions::Extension* extension = LoadExtension(
297 test_data_dir_.AppendASCII("window_open").AppendASCII(
298 "close_panels_on_uninstall"));
299 ASSERT_TRUE(extension);
300
301 // Two tabs. One in extension domain and one in non-extension domain.
302 // Two popups - one in extension domain and one in non-extension domain.
303 // Two panels - one in extension domain and one in non-extension domain.
[email protected]f1c102b2013-02-15 07:44:12304 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, num_panels));
[email protected]4cdd8572013-02-15 00:33:25305
306 // Wait on test messages to make sure the pages loaded.
307 for (size_t i = 0; i < listeners.size(); ++i)
308 ASSERT_TRUE(listeners[i]->WaitUntilSatisfied());
309
310 UninstallExtension(extension->id());
311
312 // Wait for the tabs and popups in non-extension domain to stay open.
313 // Expect everything else, including panels, to close.
[email protected]4cdd8572013-02-15 00:33:25314 num_popups -= 1;
[email protected]f1c102b2013-02-15 07:44:12315#if defined(USE_ASH_PANELS)
316 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePanels)) {
317 // On Ash, new panel windows open as popup windows instead, so there are 2
318 // extension domain popups that will close (instead of 1 popup on non-Ash).
319 num_popups -= 1;
320 }
[email protected]4cdd8572013-02-15 00:33:25321#endif
[email protected]9111fff2013-06-12 18:01:55322#if defined(USE_ASH)
323#if !defined(OS_WIN)
324 // On linux ash we close all popup applications when closing its extension.
325 num_popups = 0;
326#endif
327#endif
[email protected]f1c102b2013-02-15 07:44:12328 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 1, num_popups, 0));
[email protected]4cdd8572013-02-15 00:33:25329}
330
[email protected]4ad85f42013-07-24 02:31:57331// This test isn't applicable on Chrome OS, which automatically reloads
332// crashed pages.
333#if !defined(OS_CHROMEOS)
334IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, ClosePanelsOnExtensionCrash) {
[email protected]f1c102b2013-02-15 07:44:12335#if defined(USE_ASH_PANELS)
[email protected]4cdd8572013-02-15 00:33:25336 // On Ash, new panel windows open as popup windows instead.
337 int num_popups = 4;
338 int num_panels = 0;
339#else
340 int num_popups = 2;
341 int num_panels = 2;
342#endif
[email protected]c1dffe82013-06-26 20:59:05343 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]4cdd8572013-02-15 00:33:25344
345 // Setup listeners to wait on strings we expect the extension pages to send.
346 std::vector<std::string> test_strings;
347 test_strings.push_back("content_tab");
348 if (num_panels)
349 test_strings.push_back("content_panel");
350 test_strings.push_back("content_popup");
351
352 ScopedVector<ExtensionTestMessageListener> listeners;
353 for (size_t i = 0; i < test_strings.size(); ++i) {
354 listeners.push_back(
355 new ExtensionTestMessageListener(test_strings[i], false));
356 }
357
358 const extensions::Extension* extension = LoadExtension(
359 test_data_dir_.AppendASCII("window_open").AppendASCII(
360 "close_panels_on_uninstall"));
361 ASSERT_TRUE(extension);
362
363 // Two tabs. One in extension domain and one in non-extension domain.
364 // Two popups - one in extension domain and one in non-extension domain.
365 // Two panels - one in extension domain and one in non-extension domain.
[email protected]f1c102b2013-02-15 07:44:12366 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, num_panels));
[email protected]1dd66b72012-09-19 20:41:48367
368 // Wait on test messages to make sure the pages loaded.
369 for (size_t i = 0; i < listeners.size(); ++i)
370 ASSERT_TRUE(listeners[i]->WaitUntilSatisfied());
371
372 // Crash the extension.
373 extensions::ExtensionHost* extension_host =
[email protected]be93bba02012-10-24 16:44:03374 extensions::ExtensionSystem::Get(browser()->profile())->
375 process_manager()->GetBackgroundHostForExtension(extension->id());
[email protected]1dd66b72012-09-19 20:41:48376 ASSERT_TRUE(extension_host);
377 base::KillProcess(extension_host->render_process_host()->GetHandle(),
378 content::RESULT_CODE_KILLED, false);
379 WaitForExtensionCrash(extension->id());
380
381 // Only expect panels to close. The rest stay open to show a sad-tab.
[email protected]f1c102b2013-02-15 07:44:12382 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, 0));
[email protected]1dd66b72012-09-19 20:41:48383}
[email protected]4ad85f42013-07-24 02:31:57384#endif // !defined(OS_CHROMEOS)
[email protected]1dd66b72012-09-19 20:41:48385
[email protected]f1c102b2013-02-15 07:44:12386#if defined(USE_ASH_PANELS)
387// This test is not applicable on Ash. The modified window.open behavior only
388// applies to non-Ash panel windows.
[email protected]99f4fdb92012-08-30 23:13:51389#define MAYBE_WindowOpenFromPanel DISABLED_WindowOpenFromPanel
390#else
391#define MAYBE_WindowOpenFromPanel WindowOpenFromPanel
392#endif
393IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenFromPanel) {
[email protected]c1dffe82013-06-26 20:59:05394 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]6798c332012-08-29 02:16:51395
[email protected]99f4fdb92012-08-30 23:13:51396 // Load the extension that will open a panel which then calls window.open.
[email protected]6798c332012-08-29 02:16:51397 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("window_open").
398 AppendASCII("panel_window_open")));
[email protected]99f4fdb92012-08-30 23:13:51399
400 // Expect one panel (opened by extension) and one tab (from the panel calling
401 // window.open). Panels modify the WindowOpenDisposition in window.open
402 // to always open in a tab.
[email protected]f1c102b2013-02-15 07:44:12403 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 1, 0, 1));
[email protected]6798c332012-08-29 02:16:51404}
405
[email protected]24c6bcfc2012-02-29 21:06:36406IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpener) {
[email protected]54edcea2011-07-27 01:56:38407 ASSERT_TRUE(RunExtensionTest("window_open/opener")) << message_;
408}
[email protected]fad73672012-06-15 23:26:06409
[email protected]fa7c1602013-04-03 23:00:20410#if defined(OS_MACOSX)
411// Extension popup windows are incorrectly sized on OSX, crbug.com/225601
412#define MAYBE_WindowOpenSized DISABLED_WindowOpenSized
413#else
414#define MAYBE_WindowOpenSized WindowOpenSized
415#endif
416// Ensure that the width and height properties of a window opened with
417// chrome.windows.create match the creation parameters. See crbug.com/173831.
418IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_WindowOpenSized) {
419 ASSERT_TRUE(RunExtensionTest("window_open/window_size")) << message_;
420 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 1, 0));
421}
422
[email protected]fad73672012-06-15 23:26:06423// Tests that an extension page can call window.open to an extension URL and
424// the new window has extension privileges.
425IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenExtension) {
426 ASSERT_TRUE(LoadExtension(
427 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
428
429 GURL start_url(std::string("chrome-extension://") +
430 last_loaded_extension_id_ + "/test.html");
431 ui_test_utils::NavigateToURL(browser(), start_url);
[email protected]f3e73f62012-10-20 05:35:16432 WebContents* newtab = NULL;
[email protected]e0448872013-01-11 19:35:02433 ASSERT_NO_FATAL_FAILURE(
434 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(),
435 start_url.Resolve("newtab.html"), true, &newtab));
[email protected]fad73672012-06-15 23:26:06436
437 bool result = false;
[email protected]b6987e02013-01-04 18:30:43438 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()",
439 &result));
[email protected]fad73672012-06-15 23:26:06440 EXPECT_TRUE(result);
441}
442
443// Tests that if an extension page calls window.open to an invalid extension
444// URL, the browser doesn't crash.
445IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) {
446 ASSERT_TRUE(LoadExtension(
447 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
448
449 GURL start_url(std::string("chrome-extension://") +
450 last_loaded_extension_id_ + "/test.html");
451 ui_test_utils::NavigateToURL(browser(), start_url);
[email protected]e0448872013-01-11 19:35:02452 ASSERT_NO_FATAL_FAILURE(
453 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]fad73672012-06-15 23:26:06454 GURL("chrome-extension://thisissurelynotavalidextensionid/newtab.html"),
455 false, NULL));
456
457 // If we got to this point, we didn't crash, so we're good.
458}
459
460// Tests that calling window.open from the newtab page to an extension URL
461// gives the new window extension privileges - even though the opening page
462// does not have extension privileges, we break the script connection, so
463// there is no privilege leak.
464IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) {
465 ASSERT_TRUE(LoadExtension(
466 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
467
468 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
[email protected]f3e73f62012-10-20 05:35:16469 WebContents* newtab = NULL;
[email protected]e0448872013-01-11 19:35:02470 ASSERT_NO_FATAL_FAILURE(
471 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]fad73672012-06-15 23:26:06472 GURL(std::string("chrome-extension://") + last_loaded_extension_id_ +
473 "/newtab.html"), false, &newtab));
474
475 // Extension API should succeed.
476 bool result = false;
[email protected]b6987e02013-01-04 18:30:43477 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()",
478 &result));
[email protected]fad73672012-06-15 23:26:06479 EXPECT_TRUE(result);
480}