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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc

Issue 10690102: Relanding https://chromiumcodereview.appspot.com/10694037 after a revert. The original CL failed on… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed the test Created 8 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_blocking_page.cc ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // This test creates a fake safebrowsing service, where we can inject 5 // This test creates a fake safebrowsing service, where we can inject
6 // malware and phishing urls. It then uses a real browser to go to 6 // malware and phishing urls. It then uses a real browser to go to
7 // these urls, and sends "goback" or "proceed" commands and verifies 7 // these urls, and sends "goback" or "proceed" commands and verifies
8 // they work. 8 // they work.
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/utf_string_conversions.h"
12 #include "base/values.h"
11 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/prefs/pref_service.h" 14 #include "chrome/browser/prefs/pref_service.h"
13 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/safe_browsing/malware_details.h" 16 #include "chrome/browser/safe_browsing/malware_details.h"
15 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" 17 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
16 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 18 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
17 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/browser_tabstrip.h" 20 #include "chrome/browser/ui/browser_tabstrip.h"
19 #include "chrome/browser/ui/tab_contents/tab_contents.h" 21 #include "chrome/browser/ui/tab_contents/tab_contents.h"
20 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
21 #include "chrome/common/url_constants.h" 23 #include "chrome/common/url_constants.h"
22 #include "chrome/test/base/in_process_browser_test.h" 24 #include "chrome/test/base/in_process_browser_test.h"
23 #include "chrome/test/base/ui_test_utils.h" 25 #include "chrome/test/base/ui_test_utils.h"
24 #include "content/public/browser/interstitial_page.h" 26 #include "content/public/browser/interstitial_page.h"
25 #include "content/public/browser/navigation_controller.h" 27 #include "content/public/browser/navigation_controller.h"
26 #include "content/public/browser/notification_types.h" 28 #include "content/public/browser/notification_types.h"
29 #include "content/public/browser/render_view_host.h"
27 #include "content/public/browser/web_contents.h" 30 #include "content/public/browser/web_contents.h"
28 #include "content/public/browser/web_contents_view.h" 31 #include "content/public/browser/web_contents_view.h"
29 #include "content/public/test/test_browser_thread.h" 32 #include "content/public/test/test_browser_thread.h"
30 33
31 using content::BrowserThread; 34 using content::BrowserThread;
32 using content::InterstitialPage; 35 using content::InterstitialPage;
33 using content::NavigationController; 36 using content::NavigationController;
34 using content::WebContents; 37 using content::WebContents;
35 38
36 namespace { 39 namespace {
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 ui_test_utils::NavigateToURLWithDisposition( 365 ui_test_utils::NavigateToURLWithDisposition(
363 browser(), 366 browser(),
364 GURL("javascript:stopWin()"), 367 GURL("javascript:stopWin()"),
365 CURRENT_TAB, 368 CURRENT_TAB,
366 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 369 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
367 chrome::ActivateTabAt(browser(), 1, true); 370 chrome::ActivateTabAt(browser(), 1, true);
368 // Simulate the user clicking "proceed", there should be no crash. 371 // Simulate the user clicking "proceed", there should be no crash.
369 SendCommand("\"proceed\""); 372 SendCommand("\"proceed\"");
370 } 373 }
371 374
375 bool GetProceedLinkIsHidden(bool* result) {
376 InterstitialPage* interstitial = InterstitialPage::GetInterstitialPage(
377 chrome::GetActiveWebContents(browser()));
378 if (!interstitial)
379 return false;
380 content::RenderViewHost* rvh = interstitial->GetRenderViewHostForTesting();
381 if (!rvh)
382 return false;
383 // Wait until jstemplate is finished.
384 std::string ready_state;
385 do {
386 ready_state.clear();
387 scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue(
388 string16(),
389 ASCIIToUTF16("document.readyState;")));
390 if (!value.get() || !value->GetAsString(&ready_state))
391 return false;
392 } while (ready_state == "loading");
Mattias Nissler (ping if slow) 2012/07/09 08:32:26 I guess this loop spins pretty fast and thus eats
Joao da Silva 2012/07/10 09:52:20 I've had a deeper look into this. document.readySt
393 // Now get the display style for the "proceed anyway" div.
394 scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue(
395 string16(),
396 ASCIIToUTF16("var list = document.querySelectorAll("
397 "'div[jsdisplay=\"!proceedDisabled\"]');"
398 "if (list.length == 1)\n"
399 " list[0].style.display === 'none';\n"
400 "else\n"
401 " 'Fail with non-boolean result value';\n")));
402 if (!value.get())
403 return false;
404 return value->GetAsBoolean(result);
405 }
406
372 protected: 407 protected:
373 TestMalwareDetailsFactory details_factory_; 408 TestMalwareDetailsFactory details_factory_;
374 409
375 private: 410 private:
376 TestSafeBrowsingServiceFactory factory_; 411 TestSafeBrowsingServiceFactory factory_;
377 TestSafeBrowsingBlockingPageFactory blocking_page_factory_; 412 TestSafeBrowsingBlockingPageFactory blocking_page_factory_;
378 413
379 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageTest); 414 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageTest);
380 }; 415 };
381 416
(...skipping 17 matching lines...) Expand all
399 // already. See crbug.com/76460. 434 // already. See crbug.com/76460.
400 EXPECT_TRUE(YesInterstitial()); 435 EXPECT_TRUE(YesInterstitial());
401 } 436 }
402 437
403 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareDontProceed) { 438 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareDontProceed) {
404 GURL url = test_server()->GetURL(kEmptyPage); 439 GURL url = test_server()->GetURL(kEmptyPage);
405 AddURLResult(url, SafeBrowsingService::URL_MALWARE); 440 AddURLResult(url, SafeBrowsingService::URL_MALWARE);
406 441
407 ui_test_utils::NavigateToURL(browser(), url); 442 ui_test_utils::NavigateToURL(browser(), url);
408 443
444 bool hidden = false;
445 EXPECT_TRUE(GetProceedLinkIsHidden(&hidden));
446 EXPECT_FALSE(hidden);
447
409 SendCommand("\"takeMeBack\""); // Simulate the user clicking "back" 448 SendCommand("\"takeMeBack\""); // Simulate the user clicking "back"
410 AssertNoInterstitial(false); // Assert the interstitial is gone 449 AssertNoInterstitial(false); // Assert the interstitial is gone
411 EXPECT_EQ( 450 EXPECT_EQ(
412 GURL(chrome::kAboutBlankURL), // Back to "about:blank" 451 GURL(chrome::kAboutBlankURL), // Back to "about:blank"
413 chrome::GetActiveWebContents(browser())->GetURL()); 452 chrome::GetActiveWebContents(browser())->GetURL());
414 } 453 }
415 454
416 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareProceed) { 455 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareProceed) {
417 GURL url = test_server()->GetURL(kEmptyPage); 456 GURL url = test_server()->GetURL(kEmptyPage);
418 AddURLResult(url, SafeBrowsingService::URL_MALWARE); 457 AddURLResult(url, SafeBrowsingService::URL_MALWARE);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 SendCommand("\"doReport\""); // Simulate the user checking the checkbox. 594 SendCommand("\"doReport\""); // Simulate the user checking the checkbox.
556 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( 595 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean(
557 prefs::kSafeBrowsingReportingEnabled)); 596 prefs::kSafeBrowsingReportingEnabled));
558 597
559 SendCommand("\"proceed\""); // Simulate the user clicking "back" 598 SendCommand("\"proceed\""); // Simulate the user clicking "back"
560 AssertNoInterstitial(true); // Assert the interstitial is gone 599 AssertNoInterstitial(true); // Assert the interstitial is gone
561 600
562 EXPECT_EQ(url, chrome::GetActiveWebContents(browser())->GetURL()); 601 EXPECT_EQ(url, chrome::GetActiveWebContents(browser())->GetURL());
563 AssertReportSent(); 602 AssertReportSent();
564 } 603 }
604
605 // Verifies that the "proceed anyway" link isn't available when it is disabled
606 // by the corresponding policy. Also verifies that sending the "proceed"
607 // command anyway doesn't advance to the malware site.
608 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, ProceedDisabled) {
609 // Simulate a policy disabling the "proceed anyway" link.
610 browser()->profile()->GetPrefs()->SetBoolean(
611 prefs::kSafeBrowsingProceedAnywayDisabled, true);
612
613 GURL url = test_server()->GetURL(kEmptyPage);
614 AddURLResult(url, SafeBrowsingService::URL_MALWARE);
615 ui_test_utils::NavigateToURL(browser(), url);
616
617 // The "proceed anyway" link should be hidden.
618 bool hidden = false;
619 EXPECT_TRUE(GetProceedLinkIsHidden(&hidden));
620 EXPECT_TRUE(hidden);
621
622 // The "proceed" command should go back instead, if proceeding is disabled.
623 SendCommand("\"proceed\"");
624 AssertNoInterstitial(true);
625 EXPECT_EQ(
626 GURL(chrome::kAboutBlankURL), // Back to "about:blank"
627 chrome::GetActiveWebContents(browser())->GetURL());
628 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_blocking_page.cc ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698