Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Side by Side Diff: chrome/browser/extensions/window_open_apitest.cc

Issue 2263863002: Remove implementation of Panels on OSes other than ChromeOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR feedback Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/command_line.h"
8 #include "base/memory/scoped_vector.h" 7 #include "base/memory/scoped_vector.h"
9 #include "base/path_service.h" 8 #include "base/path_service.h"
10 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
11 #include "build/build_config.h" 10 #include "build/build_config.h"
12 #include "chrome/browser/extensions/extension_apitest.h" 11 #include "chrome/browser/extensions/extension_apitest.h"
13 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_finder.h" 14 #include "chrome/browser/ui/browser_finder.h"
16 #include "chrome/browser/ui/browser_list.h" 15 #include "chrome/browser/ui/browser_list.h"
17 #include "chrome/browser/ui/panels/panel_manager.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" 16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/common/chrome_paths.h" 17 #include "chrome/common/chrome_paths.h"
20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/test/base/ui_test_utils.h" 18 #include "chrome/test/base/ui_test_utils.h"
22 #include "content/public/browser/render_process_host.h" 19 #include "content/public/browser/render_process_host.h"
23 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
24 #include "content/public/common/result_codes.h" 21 #include "content/public/common/result_codes.h"
25 #include "content/public/common/url_constants.h" 22 #include "content/public/common/url_constants.h"
26 #include "content/public/test/browser_test_utils.h" 23 #include "content/public/test/browser_test_utils.h"
27 #include "extensions/browser/extension_host.h" 24 #include "extensions/browser/extension_host.h"
28 #include "extensions/browser/process_manager.h" 25 #include "extensions/browser/process_manager.h"
29 #include "extensions/common/constants.h" 26 #include "extensions/common/constants.h"
30 #include "extensions/common/extension.h" 27 #include "extensions/common/extension.h"
31 #include "extensions/common/switches.h"
32 #include "extensions/test/extension_test_message_listener.h" 28 #include "extensions/test/extension_test_message_listener.h"
33 #include "extensions/test/result_catcher.h" 29 #include "extensions/test/result_catcher.h"
34 #include "net/dns/mock_host_resolver.h" 30 #include "net/dns/mock_host_resolver.h"
35 #include "net/test/embedded_test_server/embedded_test_server.h" 31 #include "net/test/embedded_test_server/embedded_test_server.h"
36 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
37 33
38 #if defined(USE_ASH) 34 #if defined(USE_ASH)
39 #include "extensions/browser/app_window/app_window_registry.h" 35 #include "extensions/browser/app_window/app_window_registry.h"
40 #endif 36 #endif
41 37
42 #if defined(USE_ASH) && defined(OS_CHROMEOS)
43 // TODO(stevenjb): Figure out the correct behavior for Ash + Win
44 #define USE_ASH_PANELS
45 #endif
46
47 using content::OpenURLParams; 38 using content::OpenURLParams;
48 using content::Referrer; 39 using content::Referrer;
49 using content::WebContents; 40 using content::WebContents;
50 41
51 // The test uses the chrome.browserAction.openPopup API, which requires that the 42 // The test uses the chrome.browserAction.openPopup API, which requires that the
52 // window can automatically be activated. 43 // window can automatically be activated.
53 // See comments at BrowserActionInteractiveTest::ShouldRunPopupTest 44 // See comments at BrowserActionInteractiveTest::ShouldRunPopupTest
54 // Fails flakily on all platforms. https://crbug.com/477691 45 // Fails flakily on all platforms. https://crbug.com/477691
55 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpen) { 46 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpen) {
56 extensions::ResultCatcher catcher; 47 extensions::ResultCatcher catcher;
57 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ 48 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_
58 .AppendASCII("window_open").AppendASCII("spanning"))); 49 .AppendASCII("window_open").AppendASCII("spanning")));
59 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 50 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
60 } 51 }
61 52
62 int GetPanelCount(Browser* browser) {
63 #if defined(USE_ASH_PANELS)
64 return static_cast<int>(extensions::AppWindowRegistry::Get(
65 browser->profile())->app_windows().size());
66 #else
67 return PanelManager::GetInstance()->num_panels();
68 #endif
69 }
70
71 bool WaitForTabsAndPopups(Browser* browser, 53 bool WaitForTabsAndPopups(Browser* browser,
72 int num_tabs, 54 int num_tabs,
73 int num_popups, 55 int num_popups) {
74 int num_panels) {
75 SCOPED_TRACE( 56 SCOPED_TRACE(
76 base::StringPrintf("WaitForTabsAndPopups tabs:%d, popups:%d, panels:%d", 57 base::StringPrintf("WaitForTabsAndPopups tabs:%d, popups:%d",
77 num_tabs, num_popups, num_panels)); 58 num_tabs, num_popups));
78 // We start with one tab and one browser already open. 59 // We start with one tab and one browser already open.
79 ++num_tabs; 60 ++num_tabs;
80 size_t num_browsers = static_cast<size_t>(num_popups) + 1; 61 size_t num_browsers = static_cast<size_t>(num_popups) + 1;
81 62
82 const base::TimeDelta kWaitTime = base::TimeDelta::FromSeconds(10); 63 const base::TimeDelta kWaitTime = base::TimeDelta::FromSeconds(10);
83 base::TimeTicks end_time = base::TimeTicks::Now() + kWaitTime; 64 base::TimeTicks end_time = base::TimeTicks::Now() + kWaitTime;
84 while (base::TimeTicks::Now() < end_time) { 65 while (base::TimeTicks::Now() < end_time) {
85 if (chrome::GetBrowserCount(browser->profile()) == num_browsers && 66 if (chrome::GetBrowserCount(browser->profile()) == num_browsers &&
86 browser->tab_strip_model()->count() == num_tabs && 67 browser->tab_strip_model()->count() == num_tabs)
87 GetPanelCount(browser) == num_panels)
88 break; 68 break;
89 69
90 content::RunAllPendingInMessageLoop(); 70 content::RunAllPendingInMessageLoop();
91 } 71 }
92 72
93 EXPECT_EQ(num_browsers, chrome::GetBrowserCount(browser->profile())); 73 EXPECT_EQ(num_browsers, chrome::GetBrowserCount(browser->profile()));
94 EXPECT_EQ(num_tabs, browser->tab_strip_model()->count()); 74 EXPECT_EQ(num_tabs, browser->tab_strip_model()->count());
95 EXPECT_EQ(num_panels, GetPanelCount(browser));
96 75
97 int num_popups_seen = 0; 76 int num_popups_seen = 0;
98 for (auto* b : *BrowserList::GetInstance()) { 77 for (auto* b : *BrowserList::GetInstance()) {
99 if (b == browser) 78 if (b == browser)
100 continue; 79 continue;
101 80
102 EXPECT_TRUE(b->is_type_popup()); 81 EXPECT_TRUE(b->is_type_popup());
103 ++num_popups_seen; 82 ++num_popups_seen;
104 } 83 }
105 EXPECT_EQ(num_popups, num_popups_seen); 84 EXPECT_EQ(num_popups, num_popups_seen);
106 85
107 return ((num_browsers == chrome::GetBrowserCount(browser->profile())) && 86 return ((num_browsers == chrome::GetBrowserCount(browser->profile())) &&
108 (num_tabs == browser->tab_strip_model()->count()) && 87 (num_tabs == browser->tab_strip_model()->count()) &&
109 (num_panels == GetPanelCount(browser)) &&
110 (num_popups == num_popups_seen)); 88 (num_popups == num_popups_seen));
111 } 89 }
112 90
113 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserIsApp) { 91 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserIsApp) {
114 host_resolver()->AddRule("a.com", "127.0.0.1"); 92 host_resolver()->AddRule("a.com", "127.0.0.1");
115 ASSERT_TRUE(StartEmbeddedTestServer()); 93 ASSERT_TRUE(StartEmbeddedTestServer());
116 ASSERT_TRUE(LoadExtension( 94 ASSERT_TRUE(LoadExtension(
117 test_data_dir_.AppendASCII("window_open").AppendASCII("browser_is_app"))); 95 test_data_dir_.AppendASCII("window_open").AppendASCII("browser_is_app")));
118 96
119 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 2, 0)); 97 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 2));
120 98
121 for (auto* b : *BrowserList::GetInstance()) { 99 for (auto* b : *BrowserList::GetInstance()) {
122 if (b == browser()) 100 if (b == browser())
123 ASSERT_FALSE(b->is_app()); 101 ASSERT_FALSE(b->is_app());
124 else 102 else
125 ASSERT_TRUE(b->is_app()); 103 ASSERT_TRUE(b->is_app());
126 } 104 }
127 } 105 }
128 106
129 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupDefault) { 107 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupDefault) {
130 ASSERT_TRUE(StartEmbeddedTestServer()); 108 ASSERT_TRUE(StartEmbeddedTestServer());
131 ASSERT_TRUE(LoadExtension( 109 ASSERT_TRUE(LoadExtension(
132 test_data_dir_.AppendASCII("window_open").AppendASCII("popup"))); 110 test_data_dir_.AppendASCII("window_open").AppendASCII("popup")));
133 111
134 const int num_tabs = 1; 112 const int num_tabs = 1;
135 const int num_popups = 0; 113 const int num_popups = 0;
136 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0)); 114 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups));
137 } 115 }
138 116
139 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupIframe) { 117 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupIframe) {
140 ASSERT_TRUE(StartEmbeddedTestServer()); 118 ASSERT_TRUE(StartEmbeddedTestServer());
141 base::FilePath test_data_dir; 119 base::FilePath test_data_dir;
142 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); 120 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
143 embedded_test_server()->ServeFilesFromDirectory(test_data_dir); 121 embedded_test_server()->ServeFilesFromDirectory(test_data_dir);
144 ASSERT_TRUE(LoadExtension( 122 ASSERT_TRUE(LoadExtension(
145 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_iframe"))); 123 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_iframe")));
146 124
147 const int num_tabs = 1; 125 const int num_tabs = 1;
148 const int num_popups = 0; 126 const int num_popups = 0;
149 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0)); 127 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups));
150 } 128 }
151 129
152 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupLarge) { 130 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupLarge) {
153 ASSERT_TRUE(StartEmbeddedTestServer()); 131 ASSERT_TRUE(StartEmbeddedTestServer());
154 ASSERT_TRUE(LoadExtension( 132 ASSERT_TRUE(LoadExtension(
155 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_large"))); 133 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_large")));
156 134
157 // On other systems this should open a new popup window. 135 // On other systems this should open a new popup window.
158 const int num_tabs = 0; 136 const int num_tabs = 0;
159 const int num_popups = 1; 137 const int num_popups = 1;
160 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0)); 138 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups));
161 } 139 }
162 140
163 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupSmall) { 141 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupSmall) {
164 ASSERT_TRUE(StartEmbeddedTestServer()); 142 ASSERT_TRUE(StartEmbeddedTestServer());
165 ASSERT_TRUE(LoadExtension( 143 ASSERT_TRUE(LoadExtension(
166 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_small"))); 144 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_small")));
167 145
168 // On ChromeOS this should open a new panel (acts like a new popup window). 146 // On ChromeOS this should open a new panel (acts like a new popup window).
169 // On other systems this should open a new popup window. 147 // On other systems this should open a new popup window.
170 const int num_tabs = 0; 148 const int num_tabs = 0;
171 const int num_popups = 1; 149 const int num_popups = 1;
172 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0)); 150 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups));
173 } 151 }
174 152
175 // Disabled on Windows. Often times out or fails: crbug.com/177530 153 // Disabled on Windows. Often times out or fails: crbug.com/177530
176 #if defined(OS_WIN) 154 #if defined(OS_WIN)
177 #define MAYBE_PopupBlockingExtension DISABLED_PopupBlockingExtension 155 #define MAYBE_PopupBlockingExtension DISABLED_PopupBlockingExtension
178 #else 156 #else
179 #define MAYBE_PopupBlockingExtension PopupBlockingExtension 157 #define MAYBE_PopupBlockingExtension PopupBlockingExtension
180 #endif 158 #endif
181 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_PopupBlockingExtension) { 159 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_PopupBlockingExtension) {
182 host_resolver()->AddRule("*", "127.0.0.1"); 160 host_resolver()->AddRule("*", "127.0.0.1");
183 ASSERT_TRUE(StartEmbeddedTestServer()); 161 ASSERT_TRUE(StartEmbeddedTestServer());
184 162
185 ASSERT_TRUE(LoadExtension( 163 ASSERT_TRUE(LoadExtension(
186 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking") 164 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking")
187 .AppendASCII("extension"))); 165 .AppendASCII("extension")));
188 166
189 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 5, 3, 0)); 167 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 5, 3));
190 } 168 }
191 169
192 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PopupBlockingHostedApp) { 170 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PopupBlockingHostedApp) {
193 host_resolver()->AddRule("*", "127.0.0.1"); 171 host_resolver()->AddRule("*", "127.0.0.1");
194 ASSERT_TRUE(embedded_test_server()->Start()); 172 ASSERT_TRUE(embedded_test_server()->Start());
195 173
196 ASSERT_TRUE(LoadExtension( 174 ASSERT_TRUE(LoadExtension(
197 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking") 175 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking")
198 .AppendASCII("hosted_app"))); 176 .AppendASCII("hosted_app")));
199 177
(...skipping 13 matching lines...) Expand all
213 ->GetURL(popup_app_contents_path + "open_popup.html") 191 ->GetURL(popup_app_contents_path + "open_popup.html")
214 .ReplaceComponents(replace_host); 192 .ReplaceComponents(replace_host);
215 193
216 browser()->OpenURL(OpenURLParams( 194 browser()->OpenURL(OpenURLParams(
217 open_tab, Referrer(), NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_TYPED, 195 open_tab, Referrer(), NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_TYPED,
218 false)); 196 false));
219 browser()->OpenURL(OpenURLParams( 197 browser()->OpenURL(OpenURLParams(
220 open_popup, Referrer(), NEW_FOREGROUND_TAB, 198 open_popup, Referrer(), NEW_FOREGROUND_TAB,
221 ui::PAGE_TRANSITION_TYPED, false)); 199 ui::PAGE_TRANSITION_TYPED, false));
222 200
223 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 3, 1, 0)); 201 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 3, 1));
224 } 202 }
225 203
226 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowArgumentsOverflow) { 204 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowArgumentsOverflow) {
227 ASSERT_TRUE(RunExtensionTest("window_open/argument_overflow")) << message_; 205 ASSERT_TRUE(RunExtensionTest("window_open/argument_overflow")) << message_;
228 } 206 }
229 207
230 class WindowOpenPanelDisabledTest : public ExtensionApiTest {
231 void SetUpCommandLine(base::CommandLine* command_line) override {
232 ExtensionApiTest::SetUpCommandLine(command_line);
233 command_line->AppendSwitch(switches::kDisablePanels);
234 }
235 };
236
237 IN_PROC_BROWSER_TEST_F(WindowOpenPanelDisabledTest, WindowOpenPanelNotEnabled) {
238 ASSERT_TRUE(RunExtensionTest("window_open/panel_not_enabled")) << message_;
239 }
240
241 class WindowOpenPanelTest : public ExtensionApiTest {
242 void SetUpCommandLine(base::CommandLine* command_line) override {
243 ExtensionApiTest::SetUpCommandLine(command_line);
244 command_line->AppendSwitch(switches::kEnablePanels);
245 }
246 };
247
248 #if defined(USE_ASH_PANELS)
249 // On Ash, this currently fails because we're currently opening new panel
250 // windows as popup windows instead.
251 #define MAYBE_WindowOpenPanel DISABLED_WindowOpenPanel
252 #else
253 #define MAYBE_WindowOpenPanel WindowOpenPanel
254 #endif
255 IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenPanel) {
256 ASSERT_TRUE(RunExtensionTest("window_open/panel")) << message_;
257 }
258
259 // Test verifying that panel-subframe can use window.open to find
260 // background-subframe (see the picture below). In other words, the test
261 // verifies that the everything on the picture below stays in the same
262 // BrowsingInstance.
263 //
264 // +-extension background page---+ +-panel-----------------------------+
265 // | | | |
266 // | chrome.windows.create( | | +-panel-subframe----------------+ |
267 // | 'type':'panel') -------------> | | (foo.com) | |
268 // | | | | | |
269 // | +-background-subframe-+ | | | w = window.open(..., | |
270 // | | (foo.com) | | | | "background-subframe-name") | |
271 // | | | <--------------/ | |
272 // | +---------------------+ | | +-------------------------------+ |
273 // | | | |
274 // +-----------------------------+ +-----------------------------------+
275 //
276 // See also crbug.com/568357 for more info / context.
277 IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, BrowsingInstanceTest) {
278 host_resolver()->AddRule("*", "127.0.0.1");
279 ASSERT_TRUE(StartEmbeddedTestServer());
280
281 ASSERT_TRUE(
282 RunExtensionTestWithArg("window_open/panel_browsing_instance", "panel"))
283 << message_;
284 }
285
286 // Similar to the previous test, but for when panels are disabled.
287 IN_PROC_BROWSER_TEST_F(WindowOpenPanelDisabledTest, BrowsingInstanceTest) {
288 host_resolver()->AddRule("*", "127.0.0.1");
289 ASSERT_TRUE(StartEmbeddedTestServer());
290
291 ASSERT_TRUE(
292 RunExtensionTestWithArg("window_open/panel_browsing_instance", "popup"))
293 << message_;
294 }
295
296 #if defined(USE_ASH_PANELS) || defined(OS_LINUX)
297 // On Ash, this currently fails because we're currently opening new panel
298 // windows as popup windows instead.
299 // We're also failing on Linux-aura due to the panel is not opened in the
300 // right origin.
301 #define MAYBE_WindowOpenPanelDetached DISABLED_WindowOpenPanelDetached
302 #else
303 #define MAYBE_WindowOpenPanelDetached WindowOpenPanelDetached
304 #endif
305 IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenPanelDetached) {
306 ASSERT_TRUE(RunExtensionTest("window_open/panel_detached")) << message_;
307 }
308
309 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
310 // TODO(erg): Bring up ash http://crbug.com/300084
311 #define MAYBE_CloseNonExtensionPanelsOnUninstall \
312 DISABLED_CloseNonExtensionPanelsOnUninstall
313 #else
314 #define MAYBE_CloseNonExtensionPanelsOnUninstall \
315 CloseNonExtensionPanelsOnUninstall
316 #endif
317 IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest,
318 MAYBE_CloseNonExtensionPanelsOnUninstall) {
319 #if defined(USE_ASH_PANELS)
320 // On Ash, new panel windows open as popup windows instead.
321 int num_popups, num_panels;
322 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
323 switches::kEnablePanels)) {
324 num_popups = 2;
325 num_panels = 2;
326 } else {
327 num_popups = 4;
328 num_panels = 0;
329 }
330 #else
331 int num_popups = 2;
332 int num_panels = 2;
333 #endif
334 ASSERT_TRUE(StartEmbeddedTestServer());
335
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.
357 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, num_panels));
358
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 UninstallExtension(extension->id());
364
365 // Wait for the tabs and popups in non-extension domain to stay open.
366 // Expect everything else, including panels, to close.
367 num_popups -= 1;
368 #if defined(USE_ASH_PANELS)
369 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
370 switches::kEnablePanels)) {
371 // On Ash, new panel windows open as popup windows instead, so there are 2
372 // extension domain popups that will close (instead of 1 popup on non-Ash).
373 num_popups -= 1;
374 }
375 #endif
376 #if defined(USE_ASH)
377 #if !defined(OS_WIN)
378 // On linux ash we close all popup applications when closing its extension.
379 num_popups = 0;
380 #endif
381 #endif
382 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 1, num_popups, 0));
383 }
384
385 // This test isn't applicable on Chrome OS, which automatically reloads crashed
386 // pages.
387 #if !defined(OS_CHROMEOS)
388 IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, ClosePanelsOnExtensionCrash) {
389 #if defined(USE_ASH_PANELS)
390 // On Ash, new panel windows open as popup windows instead.
391 int num_popups = 4;
392 int num_panels = 0;
393 #else
394 int num_popups = 2;
395 int num_panels = 2;
396 #endif
397 ASSERT_TRUE(StartEmbeddedTestServer());
398
399 // Setup listeners to wait on strings we expect the extension pages to send.
400 std::vector<std::string> test_strings;
401 test_strings.push_back("content_tab");
402 if (num_panels)
403 test_strings.push_back("content_panel");
404 test_strings.push_back("content_popup");
405
406 ScopedVector<ExtensionTestMessageListener> listeners;
407 for (size_t i = 0; i < test_strings.size(); ++i) {
408 listeners.push_back(
409 new ExtensionTestMessageListener(test_strings[i], false));
410 }
411
412 const extensions::Extension* extension = LoadExtension(
413 test_data_dir_.AppendASCII("window_open").AppendASCII(
414 "close_panels_on_uninstall"));
415 ASSERT_TRUE(extension);
416
417 // Two tabs. One in extension domain and one in non-extension domain.
418 // Two popups - one in extension domain and one in non-extension domain.
419 // Two panels - one in extension domain and one in non-extension domain.
420 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, num_panels));
421
422 // Wait on test messages to make sure the pages loaded.
423 for (size_t i = 0; i < listeners.size(); ++i)
424 ASSERT_TRUE(listeners[i]->WaitUntilSatisfied());
425
426 // Crash the extension.
427 extensions::ExtensionHost* extension_host =
428 extensions::ProcessManager::Get(browser()->profile())
429 ->GetBackgroundHostForExtension(extension->id());
430 ASSERT_TRUE(extension_host);
431 extension_host->render_process_host()->Shutdown(content::RESULT_CODE_KILLED,
432 false);
433 WaitForExtensionCrash(extension->id());
434
435 // Only expect panels to close. The rest stay open to show a sad-tab.
436 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 2, num_popups, 0));
437 }
438 #endif // !defined(OS_CHROMEOS)
439
440 #if defined(USE_ASH_PANELS)
441 // This test is not applicable on Ash. The modified window.open behavior only
442 // applies to non-Ash panel windows.
443 #define MAYBE_WindowOpenFromPanel DISABLED_WindowOpenFromPanel
444 #else
445 #define MAYBE_WindowOpenFromPanel WindowOpenFromPanel
446 #endif
447 IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenFromPanel) {
448 ASSERT_TRUE(StartEmbeddedTestServer());
449
450 // Load the extension that will open a panel which then calls window.open.
451 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("window_open").
452 AppendASCII("panel_window_open")));
453
454 // Expect one panel (opened by extension) and one tab (from the panel calling
455 // window.open). Panels modify the WindowOpenDisposition in window.open
456 // to always open in a tab.
457 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 1, 0, 1));
458 }
459
460 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpener) { 208 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpener) {
461 ASSERT_TRUE(RunExtensionTest("window_open/opener")) << message_; 209 ASSERT_TRUE(RunExtensionTest("window_open/opener")) << message_;
462 } 210 }
463 211
464 #if defined(OS_MACOSX) 212 #if defined(OS_MACOSX)
465 // Extension popup windows are incorrectly sized on OSX, crbug.com/225601 213 // Extension popup windows are incorrectly sized on OSX, crbug.com/225601
466 #define MAYBE_WindowOpenSized DISABLED_WindowOpenSized 214 #define MAYBE_WindowOpenSized DISABLED_WindowOpenSized
467 #else 215 #else
468 #define MAYBE_WindowOpenSized WindowOpenSized 216 #define MAYBE_WindowOpenSized WindowOpenSized
469 #endif 217 #endif
470 // Ensure that the width and height properties of a window opened with 218 // Ensure that the width and height properties of a window opened with
471 // chrome.windows.create match the creation parameters. See crbug.com/173831. 219 // chrome.windows.create match the creation parameters. See crbug.com/173831.
472 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_WindowOpenSized) { 220 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_WindowOpenSized) {
473 ASSERT_TRUE(RunExtensionTest("window_open/window_size")) << message_; 221 ASSERT_TRUE(RunExtensionTest("window_open/window_size")) << message_;
474 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 1, 0)); 222 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 1));
475 } 223 }
476 224
477 // Tests that an extension page can call window.open to an extension URL and 225 // Tests that an extension page can call window.open to an extension URL and
478 // the new window has extension privileges. 226 // the new window has extension privileges.
479 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenExtension) { 227 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenExtension) {
480 ASSERT_TRUE(LoadExtension( 228 ASSERT_TRUE(LoadExtension(
481 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); 229 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
482 230
483 GURL start_url(std::string(extensions::kExtensionScheme) + 231 GURL start_url(std::string(extensions::kExtensionScheme) +
484 url::kStandardSchemeSeparator + 232 url::kStandardSchemeSeparator +
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 last_loaded_extension_id() + "/newtab.html"), 278 last_loaded_extension_id() + "/newtab.html"),
531 false, 279 false,
532 &newtab)); 280 &newtab));
533 281
534 // Extension API should succeed. 282 // Extension API should succeed.
535 bool result = false; 283 bool result = false;
536 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()", 284 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()",
537 &result)); 285 &result));
538 EXPECT_TRUE(result); 286 EXPECT_TRUE(result);
539 } 287 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_messages_apitest.cc ('k') | chrome/browser/extensions/window_open_interactive_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698