blob: 151ce58c5024da14e6e71639002dd50c0e927a63 [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
32#if defined(USE_ASH) && !defined(OS_WIN)
33// TODO(stevenjb): Figure out the correct behavior for Ash + Win
34#define USE_ASH_PANELS
35#endif
36
[email protected]e5d549d2011-12-28 01:29:2037using content::OpenURLParams;
38using content::Referrer;
[email protected]fad73672012-06-15 23:26:0639using content::WebContents;
[email protected]e5d549d2011-12-28 01:29:2040
[email protected]e78eb292010-12-22 08:35:3941// Disabled, http://crbug.com/64899.
42IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpen) {
[email protected]32b7c492010-09-01 04:15:0043 CommandLine::ForCurrentProcess()->AppendSwitch(
44 switches::kEnableExperimentalExtensionApis);
45
46 ResultCatcher catcher;
47 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_
48 .AppendASCII("window_open").AppendASCII("spanning")));
49 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
50}
[email protected]4026ce1e2010-09-14 19:35:0451
[email protected]f1c102b2013-02-15 07:44:1252int GetPanelCount(Browser* browser) {
53#if defined(USE_ASH_PANELS)
54 return static_cast<int>(extensions::ShellWindowRegistry::Get(
55 browser->profile())->shell_windows().size());
56#else
57 return PanelManager::GetInstance()->num_panels();
58#endif
59}
60
61bool WaitForTabsAndPopups(Browser* browser,
[email protected]f9e82d92011-10-29 00:50:4562 int num_tabs,
63 int num_popups,
64 int num_panels) {
[email protected]58b349b2011-11-23 02:07:1565 SCOPED_TRACE(
[email protected]7d3cbc92013-03-18 22:33:0466 base::StringPrintf("WaitForTabsAndPopups tabs:%d, popups:%d, panels:%d",
67 num_tabs, num_popups, num_panels));
[email protected]4026ce1e2010-09-14 19:35:0468 // We start with one tab and one browser already open.
69 ++num_tabs;
[email protected]f6ffa7d2012-08-17 17:27:0870 size_t num_browsers = static_cast<size_t>(num_popups) + 1;
[email protected]4026ce1e2010-09-14 19:35:0471
[email protected]f1c102b2013-02-15 07:44:1272 const base::TimeDelta kWaitTime = base::TimeDelta::FromSeconds(10);
[email protected]0a5bdc6522011-06-08 19:04:4973 base::TimeTicks end_time = base::TimeTicks::Now() + kWaitTime;
74 while (base::TimeTicks::Now() < end_time) {
[email protected]c987a242013-02-28 01:17:4175 if (chrome::GetBrowserCount(browser->profile(),
76 browser->host_desktop_type()) == 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]c987a242013-02-28 01:17:4184 EXPECT_EQ(num_browsers,
85 chrome::GetBrowserCount(browser->profile(),
86 browser->host_desktop_type()));
[email protected]e0448872013-01-11 19:35:0287 EXPECT_EQ(num_tabs, browser->tab_strip_model()->count());
[email protected]f1c102b2013-02-15 07:44:1288 EXPECT_EQ(num_panels, GetPanelCount(browser));
[email protected]0a5bdc6522011-06-08 19:04:4989
[email protected]f9e82d92011-10-29 00:50:4590 int num_popups_seen = 0;
[email protected]bc44f4142013-02-12 06:15:5691 for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) {
[email protected]0a5bdc6522011-06-08 19:04:4992 if (*iter == browser)
[email protected]4026ce1e2010-09-14 19:35:0493 continue;
[email protected]4026ce1e2010-09-14 19:35:0494
[email protected]f6ffa7d2012-08-17 17:27:0895 EXPECT_TRUE((*iter)->is_type_popup());
[email protected]f6ffa7d2012-08-17 17:27:0896 ++num_popups_seen;
[email protected]4026ce1e2010-09-14 19:35:0497 }
[email protected]f9e82d92011-10-29 00:50:4598 EXPECT_EQ(num_popups, num_popups_seen);
[email protected]f1c102b2013-02-15 07:44:1299
[email protected]c987a242013-02-28 01:17:41100 return ((num_browsers ==
101 chrome::GetBrowserCount(browser->profile(),
102 browser->host_desktop_type())) &&
[email protected]f1c102b2013-02-15 07:44:12103 (num_tabs == browser->tab_strip_model()->count()) &&
104 (num_panels == GetPanelCount(browser)) &&
105 (num_popups == num_popups_seen));
[email protected]4026ce1e2010-09-14 19:35:04106}
107
[email protected]f112b0f2011-05-26 01:53:52108IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserIsApp) {
109 host_resolver()->AddRule("a.com", "127.0.0.1");
[email protected]c1dffe82013-06-26 20:59:05110 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]f112b0f2011-05-26 01:53:52111 ASSERT_TRUE(LoadExtension(
112 test_data_dir_.AppendASCII("window_open").AppendASCII("browser_is_app")));
113
[email protected]f1c102b2013-02-15 07:44:12114 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 2, 0));
[email protected]f112b0f2011-05-26 01:53:52115
[email protected]bc44f4142013-02-12 06:15:56116 for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) {
[email protected]f112b0f2011-05-26 01:53:52117 if (*iter == browser())
[email protected]bc44f4142013-02-12 06:15:56118 ASSERT_FALSE(iter->is_app());
[email protected]f112b0f2011-05-26 01:53:52119 else
[email protected]bc44f4142013-02-12 06:15:56120 ASSERT_TRUE(iter->is_app());
[email protected]f112b0f2011-05-26 01:53:52121 }
122}
123
[email protected]0a5bdc6522011-06-08 19:04:49124IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupDefault) {
[email protected]c1dffe82013-06-26 20:59:05125 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]0a5bdc6522011-06-08 19:04:49126 ASSERT_TRUE(LoadExtension(
127 test_data_dir_.AppendASCII("window_open").AppendASCII("popup")));
128
129 const int num_tabs = 1;
130 const int num_popups = 0;
[email protected]f1c102b2013-02-15 07:44:12131 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0));
[email protected]0a5bdc6522011-06-08 19:04:49132}
133
134IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupLarge) {
[email protected]c1dffe82013-06-26 20:59:05135 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]0a5bdc6522011-06-08 19:04:49136 ASSERT_TRUE(LoadExtension(
137 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_large")));
138
[email protected]0a5bdc6522011-06-08 19:04:49139 // On other systems this should open a new popup window.
140 const int num_tabs = 0;
141 const int num_popups = 1;
[email protected]f1c102b2013-02-15 07:44:12142 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0));
[email protected]0a5bdc6522011-06-08 19:04:49143}
144
145IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupSmall) {
[email protected]c1dffe82013-06-26 20:59:05146 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]0a5bdc6522011-06-08 19:04:49147 ASSERT_TRUE(LoadExtension(
148 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_small")));
149
150 // On ChromeOS this should open a new panel (acts like a new popup window).
151 // On other systems this should open a new popup window.
152 const int num_tabs = 0;
153 const int num_popups = 1;
[email protected]f1c102b2013-02-15 07:44:12154 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0));
[email protected]0a5bdc6522011-06-08 19:04:49155}
156
[email protected]73fa1fce2013-02-21 20:10:05157// Disabled on Windows. Often times out or fails: crbug.com/177530
158#if defined(OS_WIN)
159#define MAYBE_PopupBlockingExtension DISABLED_PopupBlockingExtension
160#else
161#define MAYBE_PopupBlockingExtension PopupBlockingExtension
162#endif
163IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_PopupBlockingExtension) {
[email protected]4026ce1e2010-09-14 19:35:04164 host_resolver()->AddRule("*", "127.0.0.1");
[email protected]c1dffe82013-06-26 20:59:05165 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]4026ce1e2010-09-14 19:35:04166
167 ASSERT_TRUE(LoadExtension(
168 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking")
169 .AppendASCII("extension")));
170
[email protected]f1c102b2013-02-15 07:44:12171 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 5, 3, 0));
[email protected]4026ce1e2010-09-14 19:35:04172}
173
174IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PopupBlockingHostedApp) {
175 host_resolver()->AddRule("*", "127.0.0.1");
176 ASSERT_TRUE(test_server()->Start());
177
178 ASSERT_TRUE(LoadExtension(
179 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking")
180 .AppendASCII("hosted_app")));
181
[email protected]fe3048872010-10-18 14:58:59182 // The app being tested owns the domain a.com . The test URLs we navigate
183 // to below must be within that domain, so that they fall within the app's
184 // web extent.
185 GURL::Replacements replace_host;
186 std::string a_dot_com = "a.com";
187 replace_host.SetHostStr(a_dot_com);
188
189 const std::string popup_app_contents_path(
190 "files/extensions/api_test/window_open/popup_blocking/hosted_app/");
191
192 GURL open_tab =
193 test_server()->GetURL(popup_app_contents_path + "open_tab.html")
194 .ReplaceComponents(replace_host);
195 GURL open_popup =
196 test_server()->GetURL(popup_app_contents_path + "open_popup.html")
197 .ReplaceComponents(replace_host);
198
[email protected]e5d549d2011-12-28 01:29:20199 browser()->OpenURL(OpenURLParams(
200 open_tab, Referrer(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED,
201 false));
202 browser()->OpenURL(OpenURLParams(
203 open_popup, Referrer(), NEW_FOREGROUND_TAB,
204 content::PAGE_TRANSITION_TYPED, false));
[email protected]4026ce1e2010-09-14 19:35:04205
[email protected]f1c102b2013-02-15 07:44:12206 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 3, 1, 0));
[email protected]4026ce1e2010-09-14 19:35:04207}
[email protected]d4db6c702011-03-28 21:49:14208
[email protected]e7f90562011-05-23 21:38:24209IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowArgumentsOverflow) {
210 ASSERT_TRUE(RunExtensionTest("window_open/argument_overflow")) << message_;
211}
212
[email protected]d5c14062011-10-27 00:02:13213class WindowOpenPanelDisabledTest : public ExtensionApiTest {
[email protected]49aeab62013-02-07 02:53:11214 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
[email protected]08aa0c32011-04-11 22:18:37215 ExtensionApiTest::SetUpCommandLine(command_line);
[email protected]7e7a28092011-12-09 22:24:55216 // TODO(jennb): Re-enable when panels are enabled by default.
217 // command_line->AppendSwitch(switches::kDisablePanels);
[email protected]08aa0c32011-04-11 22:18:37218 }
219};
220
[email protected]7e7a28092011-12-09 22:24:55221IN_PROC_BROWSER_TEST_F(WindowOpenPanelDisabledTest,
222 DISABLED_WindowOpenPanelNotEnabled) {
[email protected]d5c14062011-10-27 00:02:13223 ASSERT_TRUE(RunExtensionTest("window_open/panel_not_enabled")) << message_;
224}
225
[email protected]af6b54512011-12-14 06:11:21226class WindowOpenPanelTest : public ExtensionApiTest {
[email protected]49aeab62013-02-07 02:53:11227 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
[email protected]af6b54512011-12-14 06:11:21228 ExtensionApiTest::SetUpCommandLine(command_line);
229 command_line->AppendSwitch(switches::kEnablePanels);
230 }
231};
232
[email protected]f1c102b2013-02-15 07:44:12233#if defined(USE_ASH_PANELS)
[email protected]87d722a2012-07-12 15:38:33234// On Ash, this currently fails because we're currently opening new panel
[email protected]d101b0c2012-03-16 00:30:57235// windows as popup windows instead.
[email protected]e00ccc92012-11-01 17:32:30236#define MAYBE_WindowOpenPanel DISABLED_WindowOpenPanel
[email protected]d101b0c2012-03-16 00:30:57237#else
238#define MAYBE_WindowOpenPanel WindowOpenPanel
239#endif
240IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenPanel) {
[email protected]08aa0c32011-04-11 22:18:37241 ASSERT_TRUE(RunExtensionTest("window_open/panel")) << message_;
242}
[email protected]54edcea2011-07-27 01:56:38243
[email protected]ca29ed12012-09-06 09:10:50244// On Ash, this currently fails because we're currently opening new panel
245// windows as popup windows instead.
[email protected]09ee0df02013-04-30 22:59:28246// This is also flakey on Windows, ASan and Mac builds: crbug.com/179251
247IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, DISABLED_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
[email protected]c1dffe82013-06-26 20:59:05267 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]1dd66b72012-09-19 20:41:48268
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]9111fff2013-06-12 18:01:55308#if defined(USE_ASH)
309#if !defined(OS_WIN)
310 // On linux ash we close all popup applications when closing its extension.
311 num_popups = 0;
312#endif
313#endif
[email protected]f1c102b2013-02-15 07:44:12314 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 1, num_popups, 0));
[email protected]4cdd8572013-02-15 00:33:25315}
316
317#if defined(OS_CHROMEOS)
318// TODO(derat): See if there's some way to get this to work on Chrome OS. It
319// crashes there, apparently because we automatically reload crashed pages:
320// http:/crbug.com/161073
321#define MAYBE_ClosePanelsOnExtensionCrash DISABLED_ClosePanelsOnExtensionCrash
322#else
323#define MAYBE_ClosePanelsOnExtensionCrash ClosePanelsOnExtensionCrash
324#endif
325IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_ClosePanelsOnExtensionCrash) {
[email protected]f1c102b2013-02-15 07:44:12326#if defined(USE_ASH_PANELS)
[email protected]4cdd8572013-02-15 00:33:25327 // On Ash, new panel windows open as popup windows instead.
328 int num_popups = 4;
329 int num_panels = 0;
330#else
331 int num_popups = 2;
332 int num_panels = 2;
333#endif
[email protected]c1dffe82013-06-26 20:59:05334 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]4cdd8572013-02-15 00:33:25335
336 // Setup listeners to wait on strings we expect the extension pages to send.
337 std::vector<std::string> test_strings;
338 test_strings.push_back("content_tab");
339 if (num_panels)
340 test_strings.push_back("content_panel");
341 test_strings.push_back("content_popup");
342
343 ScopedVector<ExtensionTestMessageListener> listeners;
344 for (size_t i = 0; i < test_strings.size(); ++i) {
345 listeners.push_back(
346 new ExtensionTestMessageListener(test_strings[i], false));
347 }
348
349 const extensions::Extension* extension = LoadExtension(
350 test_data_dir_.AppendASCII("window_open").AppendASCII(
351 "close_panels_on_uninstall"));
352 ASSERT_TRUE(extension);
353
354 // Two tabs. One in extension domain and one in non-extension domain.
355 // Two popups - one in extension domain and one in non-extension domain.
356 // Two panels - one in extension domain and one in non-extension domain.
[email protected]f1c102b2013-02-15 07:44:12357 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, num_panels));
[email protected]1dd66b72012-09-19 20:41:48358
359 // Wait on test messages to make sure the pages loaded.
360 for (size_t i = 0; i < listeners.size(); ++i)
361 ASSERT_TRUE(listeners[i]->WaitUntilSatisfied());
362
363 // Crash the extension.
364 extensions::ExtensionHost* extension_host =
[email protected]be93bba02012-10-24 16:44:03365 extensions::ExtensionSystem::Get(browser()->profile())->
366 process_manager()->GetBackgroundHostForExtension(extension->id());
[email protected]1dd66b72012-09-19 20:41:48367 ASSERT_TRUE(extension_host);
368 base::KillProcess(extension_host->render_process_host()->GetHandle(),
369 content::RESULT_CODE_KILLED, false);
370 WaitForExtensionCrash(extension->id());
371
372 // Only expect panels to close. The rest stay open to show a sad-tab.
[email protected]f1c102b2013-02-15 07:44:12373 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, 0));
[email protected]1dd66b72012-09-19 20:41:48374}
375
[email protected]f1c102b2013-02-15 07:44:12376#if defined(USE_ASH_PANELS)
377// This test is not applicable on Ash. The modified window.open behavior only
378// applies to non-Ash panel windows.
[email protected]99f4fdb92012-08-30 23:13:51379#define MAYBE_WindowOpenFromPanel DISABLED_WindowOpenFromPanel
380#else
381#define MAYBE_WindowOpenFromPanel WindowOpenFromPanel
382#endif
383IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenFromPanel) {
[email protected]c1dffe82013-06-26 20:59:05384 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]6798c332012-08-29 02:16:51385
[email protected]99f4fdb92012-08-30 23:13:51386 // Load the extension that will open a panel which then calls window.open.
[email protected]6798c332012-08-29 02:16:51387 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("window_open").
388 AppendASCII("panel_window_open")));
[email protected]99f4fdb92012-08-30 23:13:51389
390 // Expect one panel (opened by extension) and one tab (from the panel calling
391 // window.open). Panels modify the WindowOpenDisposition in window.open
392 // to always open in a tab.
[email protected]f1c102b2013-02-15 07:44:12393 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 1, 0, 1));
[email protected]6798c332012-08-29 02:16:51394}
395
[email protected]24c6bcfc2012-02-29 21:06:36396IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpener) {
[email protected]54edcea2011-07-27 01:56:38397 ASSERT_TRUE(RunExtensionTest("window_open/opener")) << message_;
398}
[email protected]fad73672012-06-15 23:26:06399
[email protected]fa7c1602013-04-03 23:00:20400#if defined(OS_MACOSX)
401// Extension popup windows are incorrectly sized on OSX, crbug.com/225601
402#define MAYBE_WindowOpenSized DISABLED_WindowOpenSized
403#else
404#define MAYBE_WindowOpenSized WindowOpenSized
405#endif
406// Ensure that the width and height properties of a window opened with
407// chrome.windows.create match the creation parameters. See crbug.com/173831.
408IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_WindowOpenSized) {
409 ASSERT_TRUE(RunExtensionTest("window_open/window_size")) << message_;
410 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 1, 0));
411}
412
[email protected]fad73672012-06-15 23:26:06413// Tests that an extension page can call window.open to an extension URL and
414// the new window has extension privileges.
415IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenExtension) {
416 ASSERT_TRUE(LoadExtension(
417 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
418
419 GURL start_url(std::string("chrome-extension://") +
420 last_loaded_extension_id_ + "/test.html");
421 ui_test_utils::NavigateToURL(browser(), start_url);
[email protected]f3e73f62012-10-20 05:35:16422 WebContents* newtab = NULL;
[email protected]e0448872013-01-11 19:35:02423 ASSERT_NO_FATAL_FAILURE(
424 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(),
425 start_url.Resolve("newtab.html"), true, &newtab));
[email protected]fad73672012-06-15 23:26:06426
427 bool result = false;
[email protected]b6987e02013-01-04 18:30:43428 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()",
429 &result));
[email protected]fad73672012-06-15 23:26:06430 EXPECT_TRUE(result);
431}
432
433// Tests that if an extension page calls window.open to an invalid extension
434// URL, the browser doesn't crash.
435IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) {
436 ASSERT_TRUE(LoadExtension(
437 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
438
439 GURL start_url(std::string("chrome-extension://") +
440 last_loaded_extension_id_ + "/test.html");
441 ui_test_utils::NavigateToURL(browser(), start_url);
[email protected]e0448872013-01-11 19:35:02442 ASSERT_NO_FATAL_FAILURE(
443 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]fad73672012-06-15 23:26:06444 GURL("chrome-extension://thisissurelynotavalidextensionid/newtab.html"),
445 false, NULL));
446
447 // If we got to this point, we didn't crash, so we're good.
448}
449
450// Tests that calling window.open from the newtab page to an extension URL
451// gives the new window extension privileges - even though the opening page
452// does not have extension privileges, we break the script connection, so
453// there is no privilege leak.
454IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) {
455 ASSERT_TRUE(LoadExtension(
456 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
457
458 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
[email protected]f3e73f62012-10-20 05:35:16459 WebContents* newtab = NULL;
[email protected]e0448872013-01-11 19:35:02460 ASSERT_NO_FATAL_FAILURE(
461 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]fad73672012-06-15 23:26:06462 GURL(std::string("chrome-extension://") + last_loaded_extension_id_ +
463 "/newtab.html"), false, &newtab));
464
465 // Extension API should succeed.
466 bool result = false;
[email protected]b6987e02013-01-04 18:30:43467 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()",
468 &result));
[email protected]fad73672012-06-15 23:26:06469 EXPECT_TRUE(result);
470}