OLD | NEW |
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 known- | 5 // This test creates a fake safebrowsing service, where we can inject known- |
6 // threat urls. It then uses a real browser to go to these urls, and sends | 6 // threat urls. It then uses a real browser to go to these urls, and sends |
7 // "goback" or "proceed" commands and verifies they work. | 7 // "goback" or "proceed" commands and verifies they work. |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 | 505 |
506 content::RenderViewHost* GetRenderViewHost() { | 506 content::RenderViewHost* GetRenderViewHost() { |
507 InterstitialPage* interstitial = InterstitialPage::GetInterstitialPage( | 507 InterstitialPage* interstitial = InterstitialPage::GetInterstitialPage( |
508 browser()->tab_strip_model()->GetActiveWebContents()); | 508 browser()->tab_strip_model()->GetActiveWebContents()); |
509 if (!interstitial) | 509 if (!interstitial) |
510 return NULL; | 510 return NULL; |
511 return interstitial->GetMainFrame()->GetRenderViewHost(); | 511 return interstitial->GetMainFrame()->GetRenderViewHost(); |
512 } | 512 } |
513 | 513 |
514 bool WaitForReady() { | 514 bool WaitForReady() { |
515 content::RenderViewHost* rvh = GetRenderViewHost(); | 515 InterstitialPage* interstitial = InterstitialPage::GetInterstitialPage( |
516 if (!rvh) | 516 browser()->tab_strip_model()->GetActiveWebContents()); |
| 517 if (!interstitial) |
517 return false; | 518 return false; |
518 // Wait until all <script> tags have executed, including jstemplate. | 519 return content::WaitForRenderFrameReady(interstitial->GetMainFrame()); |
519 // TODO(joaodasilva): it would be nice to avoid the busy loop, though in | |
520 // practice it spins at most once or twice. | |
521 std::string ready_state; | |
522 do { | |
523 scoped_ptr<base::Value> value = content::ExecuteScriptAndGetValue( | |
524 rvh->GetMainFrame(), "document.readyState"); | |
525 if (!value.get() || !value->GetAsString(&ready_state)) | |
526 return false; | |
527 } while (ready_state != "complete"); | |
528 return true; | |
529 } | 520 } |
530 | 521 |
531 Visibility GetVisibility(const std::string& node_id) { | 522 Visibility GetVisibility(const std::string& node_id) { |
532 content::RenderViewHost* rvh = GetRenderViewHost(); | 523 content::RenderViewHost* rvh = GetRenderViewHost(); |
533 if (!rvh) | 524 if (!rvh) |
534 return VISIBILITY_ERROR; | 525 return VISIBILITY_ERROR; |
535 scoped_ptr<base::Value> value = content::ExecuteScriptAndGetValue( | 526 scoped_ptr<base::Value> value = content::ExecuteScriptAndGetValue( |
536 rvh->GetMainFrame(), | 527 rvh->GetMainFrame(), |
537 "var node = document.getElementById('" + node_id + "');\n" | 528 "var node = document.getElementById('" + node_id + "');\n" |
538 "if (node)\n" | 529 "if (node)\n" |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 ? "/transparencyreport/safebrowsing/" | 787 ? "/transparencyreport/safebrowsing/" |
797 : "/safebrowsing/diagnostic", | 788 : "/safebrowsing/diagnostic", |
798 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().path()); | 789 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().path()); |
799 } | 790 } |
800 | 791 |
801 INSTANTIATE_TEST_CASE_P(SafeBrowsingBlockingPageBrowserTestWithThreatType, | 792 INSTANTIATE_TEST_CASE_P(SafeBrowsingBlockingPageBrowserTestWithThreatType, |
802 SafeBrowsingBlockingPageBrowserTest, | 793 SafeBrowsingBlockingPageBrowserTest, |
803 testing::Values(SB_THREAT_TYPE_URL_MALWARE, | 794 testing::Values(SB_THREAT_TYPE_URL_MALWARE, |
804 SB_THREAT_TYPE_URL_PHISHING, | 795 SB_THREAT_TYPE_URL_PHISHING, |
805 SB_THREAT_TYPE_URL_UNWANTED)); | 796 SB_THREAT_TYPE_URL_UNWANTED)); |
OLD | NEW |