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

Side by Side Diff: chrome/browser/ui/blocked_content/popup_blocker_browsertest.cc

Issue 731083002: Update popup blocker behavior and tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updates Created 6 years, 1 month 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
« no previous file with comments | « chrome/browser/ui/blocked_content/blocked_window_params.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 131
132 if (what_to_expect == ExpectPopup) { 132 if (what_to_expect == ExpectPopup) {
133 ASSERT_EQ(2u, 133 ASSERT_EQ(2u,
134 chrome::GetBrowserCount(browser()->profile(), 134 chrome::GetBrowserCount(browser()->profile(),
135 browser()->host_desktop_type())); 135 browser()->host_desktop_type()));
136 } else { 136 } else {
137 ASSERT_EQ(1u, 137 ASSERT_EQ(1u,
138 chrome::GetBrowserCount(browser()->profile(), 138 chrome::GetBrowserCount(browser()->profile(),
139 browser()->host_desktop_type())); 139 browser()->host_desktop_type()));
140 ASSERT_EQ(2, browser()->tab_strip_model()->count()); 140 ASSERT_EQ(2, browser()->tab_strip_model()->count());
141
142 // Check that we always create foreground tabs.
143 ASSERT_EQ(1, browser()->tab_strip_model()->active_index());
141 } 144 }
142 145
143 ASSERT_EQ(0, GetBlockedContentsCount()); 146 ASSERT_EQ(0, GetBlockedContentsCount());
144 } 147 }
145 148
146 // Navigates to the test indicated by |test_name| using |browser| which is 149 // Navigates to the test indicated by |test_name| using |browser| which is
147 // expected to try to open a popup. Verifies that the popup was blocked and 150 // expected to try to open a popup. Verifies that the popup was blocked and
148 // then opens the blocked popup. Once the popup stopped loading, verifies 151 // then opens the blocked popup. Once the popup stopped loading, verifies
149 // that the title of the page is "PASS" if |check_title| is set. 152 // that the title of the page is "PASS" if |check_title| is set.
150 // 153 //
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 popup_blocker_helper->ShowBlockedPopup(iter->first); 198 popup_blocker_helper->ShowBlockedPopup(iter->first);
196 199
197 observer.Wait(); 200 observer.Wait();
198 Browser* new_browser; 201 Browser* new_browser;
199 if (what_to_expect == ExpectPopup) { 202 if (what_to_expect == ExpectPopup) {
200 new_browser = browser_observer.WaitForSingleNewBrowser(); 203 new_browser = browser_observer.WaitForSingleNewBrowser();
201 web_contents = new_browser->tab_strip_model()->GetActiveWebContents(); 204 web_contents = new_browser->tab_strip_model()->GetActiveWebContents();
202 } else { 205 } else {
203 new_browser = browser; 206 new_browser = browser;
204 EXPECT_EQ(2, browser->tab_strip_model()->count()); 207 EXPECT_EQ(2, browser->tab_strip_model()->count());
208 // Check that we always create foreground tabs.
209 EXPECT_EQ(1, browser->tab_strip_model()->active_index());
205 web_contents = browser->tab_strip_model()->GetWebContentsAt(1); 210 web_contents = browser->tab_strip_model()->GetWebContentsAt(1);
206 } 211 }
207 212
208 if (check_title == CheckTitle) { 213 if (check_title == CheckTitle) {
209 // Check that the check passed. 214 // Check that the check passed.
210 base::string16 expected_title(base::ASCIIToUTF16("PASS")); 215 base::string16 expected_title(base::ASCIIToUTF16("PASS"));
211 content::TitleWatcher title_watcher(web_contents, expected_title); 216 content::TitleWatcher title_watcher(web_contents, expected_title);
212 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 217 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
213 } 218 }
214 219
215 return web_contents; 220 return web_contents;
216 } 221 }
217 222
218 private: 223 private:
219 DISALLOW_COPY_AND_ASSIGN(PopupBlockerBrowserTest); 224 DISALLOW_COPY_AND_ASSIGN(PopupBlockerBrowserTest);
220 }; 225 };
221 226
222 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, 227 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest,
223 BlockWebContentsCreation) { 228 BlockWebContentsCreation) {
224 #if defined(OS_WIN) && defined(USE_ASH) 229 #if defined(OS_WIN) && defined(USE_ASH)
225 // Disable this test in Metro+Ash for now (http://crbug.com/262796). 230 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
226 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) 231 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
227 return; 232 return;
228 #endif 233 #endif
229 234
230 RunCheckTest( 235 RunCheckTest(
231 browser(), 236 browser(),
232 "/popup_blocker/popup-blocked-to-post-blank.html", 237 "/popup_blocker/popup-blocked-to-post-blank.html",
233 ExpectPopup, 238 ExpectTab,
234 DontCheckTitle); 239 DontCheckTitle);
235 } 240 }
236 241
237 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, 242 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest,
238 BlockWebContentsCreationIncognito) { 243 BlockWebContentsCreationIncognito) {
239 #if defined(OS_WIN) && defined(USE_ASH) 244 #if defined(OS_WIN) && defined(USE_ASH)
240 // Disable this test in Metro+Ash for now (http://crbug.com/262796). 245 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
241 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) 246 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
242 return; 247 return;
243 #endif 248 #endif
244 249
245 RunCheckTest( 250 RunCheckTest(
246 CreateIncognitoBrowser(), 251 CreateIncognitoBrowser(),
247 "/popup_blocker/popup-blocked-to-post-blank.html", 252 "/popup_blocker/popup-blocked-to-post-blank.html",
248 ExpectPopup, 253 ExpectTab,
249 DontCheckTitle); 254 DontCheckTitle);
250 } 255 }
251 256
252 // Temporary. http://crbug.com/431335
253 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, 257 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest,
254 DISABLED_PopupBlockedFakeClickOnAnchor) { 258 PopupBlockedFakeClickOnAnchor) {
255 #if defined(OS_WIN) && defined(USE_ASH) 259 #if defined(OS_WIN) && defined(USE_ASH)
256 // Disable this test in Metro+Ash for now (http://crbug.com/262796). 260 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
257 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) 261 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
258 return; 262 return;
259 #endif 263 #endif
260 264
261 RunCheckTest( 265 RunCheckTest(
262 browser(), 266 browser(),
263 "/popup_blocker/popup-fake-click-on-anchor.html", 267 "/popup_blocker/popup-fake-click-on-anchor.html",
264 ExpectTab, 268 ExpectTab,
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 model->CurrentMatch(NULL).contents); 383 model->CurrentMatch(NULL).contents);
380 } 384 }
381 385
382 // This test fails on linux AURA with this change 386 // This test fails on linux AURA with this change
383 // https://codereview.chromium.org/23903056 387 // https://codereview.chromium.org/23903056
384 // BUG=https://code.google.com/p/chromium/issues/detail?id=295299 388 // BUG=https://code.google.com/p/chromium/issues/detail?id=295299
385 // TODO(ananta). Debug and fix this test. 389 // TODO(ananta). Debug and fix this test.
386 #if defined(USE_AURA) && defined(OS_LINUX) 390 #if defined(USE_AURA) && defined(OS_LINUX)
387 #define MAYBE_WindowFeatures DISABLED_WindowFeatures 391 #define MAYBE_WindowFeatures DISABLED_WindowFeatures
388 #else 392 #else
389 #define MAYBE_WindowFeatures WindowFeatures 393 // TODO(jochen): Temporarily disabled, renable again after next blink roll.
394 #define MAYBE_WindowFeatures DISABLED_WindowFeatures
390 #endif 395 #endif
391 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, MAYBE_WindowFeatures) { 396 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, MAYBE_WindowFeatures) {
392 WebContents* popup = 397 WebContents* popup =
393 RunCheckTest(browser(), 398 RunCheckTest(browser(),
394 "/popup_blocker/popup-window-open.html", 399 "/popup_blocker/popup-window-open.html",
395 ExpectPopup, 400 ExpectPopup,
396 DontCheckTitle); 401 DontCheckTitle);
397 402
398 // Check that the new popup has (roughly) the requested size. 403 // Check that the new popup has (roughly) the requested size.
399 gfx::Size window_size = popup->GetContainerBounds().size(); 404 gfx::Size window_size = popup->GetContainerBounds().size();
400 EXPECT_TRUE(349 <= window_size.width() && window_size.width() <= 351); 405 EXPECT_TRUE(349 <= window_size.width() && window_size.width() <= 351);
401 EXPECT_TRUE(249 <= window_size.height() && window_size.height() <= 251); 406 EXPECT_TRUE(249 <= window_size.height() && window_size.height() <= 251);
402 } 407 }
403 408
404 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, CorrectReferrer) { 409 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, CorrectReferrer) {
405 RunCheckTest(browser(), 410 RunCheckTest(browser(),
406 "/popup_blocker/popup-referrer.html", 411 "/popup_blocker/popup-referrer.html",
407 ExpectPopup, 412 ExpectTab,
408 CheckTitle); 413 CheckTitle);
409 } 414 }
410 415
411 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, WindowFeaturesBarProps) { 416 // TODO(jochen): Temporarily disabled, renable again after next blink roll.
417 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest,
418 DISABLED_WindowFeaturesBarProps) {
412 RunCheckTest(browser(), 419 RunCheckTest(browser(),
413 "/popup_blocker/popup-windowfeatures.html", 420 "/popup_blocker/popup-windowfeatures.html",
414 ExpectPopup, 421 ExpectTab,
415 CheckTitle); 422 CheckTitle);
416 } 423 }
417 424
418 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, SessionStorage) { 425 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, SessionStorage) {
419 RunCheckTest(browser(), 426 RunCheckTest(browser(),
420 "/popup_blocker/popup-sessionstorage.html", 427 "/popup_blocker/popup-sessionstorage.html",
421 ExpectPopup, 428 ExpectTab,
422 CheckTitle); 429 CheckTitle);
423 } 430 }
424 431
425 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, Opener) { 432 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, Opener) {
426 RunCheckTest(browser(), 433 RunCheckTest(browser(),
427 "/popup_blocker/popup-opener.html", 434 "/popup_blocker/popup-opener.html",
428 ExpectPopup, 435 ExpectTab,
429 CheckTitle); 436 CheckTitle);
430 } 437 }
431 438
432 // Tests that the popup can still close itself after navigating. This tests that 439 // Tests that the popup can still close itself after navigating. This tests that
433 // the openedByDOM bit is preserved across blocked popups. 440 // the openedByDOM bit is preserved across blocked popups.
434 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ClosableAfterNavigation) { 441 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ClosableAfterNavigation) {
435 // Open a popup. 442 // Open a popup.
436 WebContents* popup = 443 WebContents* popup =
437 RunCheckTest(browser(), 444 RunCheckTest(browser(),
438 "/popup_blocker/popup-opener.html", 445 "/popup_blocker/popup-opener.html",
439 ExpectPopup, 446 ExpectTab,
440 CheckTitle); 447 CheckTitle);
441 448
442 // Navigate it elsewhere. 449 // Navigate it elsewhere.
443 content::TestNavigationObserver nav_observer(popup); 450 content::TestNavigationObserver nav_observer(popup);
444 popup->GetMainFrame()->ExecuteJavaScript( 451 popup->GetMainFrame()->ExecuteJavaScript(
445 base::UTF8ToUTF16("location.href = '/empty.html'")); 452 base::UTF8ToUTF16("location.href = '/empty.html'"));
446 nav_observer.Wait(); 453 nav_observer.Wait();
447 454
448 // Have it close itself. 455 // Have it close itself.
449 CloseObserver close_observer(popup); 456 CloseObserver close_observer(popup);
450 popup->GetMainFrame()->ExecuteJavaScript( 457 popup->GetMainFrame()->ExecuteJavaScript(
451 base::UTF8ToUTF16("window.close()")); 458 base::UTF8ToUTF16("window.close()"));
452 close_observer.Wait(); 459 close_observer.Wait();
453 } 460 }
454 461
455 // Temporary. http://crbug.com/431335 462 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, OpenerSuppressed) {
456 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, DISABLED_OpenerSuppressed) {
457 RunCheckTest(browser(), 463 RunCheckTest(browser(),
458 "/popup_blocker/popup-openersuppressed.html", 464 "/popup_blocker/popup-openersuppressed.html",
459 ExpectTab, 465 ExpectTab,
460 CheckTitle); 466 CheckTitle);
461 } 467 }
462 468
463 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ShiftClick) { 469 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ShiftClick) {
464 RunCheckTest( 470 RunCheckTest(
465 browser(), 471 browser(),
466 "/popup_blocker/popup-fake-click-on-anchor3.html", 472 "/popup_blocker/popup-fake-click-on-anchor3.html",
467 ExpectPopup, 473 ExpectPopup,
468 CheckTitle); 474 CheckTitle);
469 } 475 }
470 476
471 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, WebUI) { 477 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, WebUI) {
472 WebContents* popup = 478 WebContents* popup =
473 RunCheckTest(browser(), 479 RunCheckTest(browser(),
474 "/popup_blocker/popup-webui.html", 480 "/popup_blocker/popup-webui.html",
475 ExpectPopup, 481 ExpectTab,
476 DontCheckTitle); 482 DontCheckTitle);
477 483
478 // Check that the new popup displays about:blank. 484 // Check that the new popup displays about:blank.
479 EXPECT_EQ(GURL(url::kAboutBlankURL), popup->GetURL()); 485 EXPECT_EQ(GURL(url::kAboutBlankURL), popup->GetURL());
480 } 486 }
481 487
482 // Verify that the renderer can't DOS the browser by creating arbitrarily many 488 // Verify that the renderer can't DOS the browser by creating arbitrarily many
483 // popups. 489 // popups.
484 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, DenialOfService) { 490 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, DenialOfService) {
485 GURL url(embedded_test_server()->GetURL("/popup_blocker/popup-dos.html")); 491 GURL url(embedded_test_server()->GetURL("/popup_blocker/popup-dos.html"));
(...skipping 17 matching lines...) Expand all
503 509
504 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), 510 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(),
505 browser()->host_desktop_type())); 511 browser()->host_desktop_type()));
506 ASSERT_EQ(1, browser()->tab_strip_model()->count()); 512 ASSERT_EQ(1, browser()->tab_strip_model()->count());
507 513
508 // The popup from the unload event handler should not show up for about:blank. 514 // The popup from the unload event handler should not show up for about:blank.
509 ASSERT_EQ(0, GetBlockedContentsCount()); 515 ASSERT_EQ(0, GetBlockedContentsCount());
510 } 516 }
511 517
512 } // namespace 518 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/ui/blocked_content/blocked_window_params.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698