Chromium Code Reviews| 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()); |
|
mattm
2015/01/22 02:28:32
I think there should be a "if (!interstitial) retu
meacer
2015/01/22 03:17:50
Done.
| |
| 517 return false; | 517 return content::WaitForInterstitialReady(interstitial); |
| 518 // Wait until all <script> tags have executed, including jstemplate. | |
| 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 } | 518 } |
| 530 | 519 |
| 531 Visibility GetVisibility(const std::string& node_id) { | 520 Visibility GetVisibility(const std::string& node_id) { |
| 532 content::RenderViewHost* rvh = GetRenderViewHost(); | 521 content::RenderViewHost* rvh = GetRenderViewHost(); |
| 533 if (!rvh) | 522 if (!rvh) |
| 534 return VISIBILITY_ERROR; | 523 return VISIBILITY_ERROR; |
| 535 scoped_ptr<base::Value> value = content::ExecuteScriptAndGetValue( | 524 scoped_ptr<base::Value> value = content::ExecuteScriptAndGetValue( |
| 536 rvh->GetMainFrame(), | 525 rvh->GetMainFrame(), |
| 537 "var node = document.getElementById('" + node_id + "');\n" | 526 "var node = document.getElementById('" + node_id + "');\n" |
| 538 "if (node)\n" | 527 "if (node)\n" |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 796 ? "/transparencyreport/safebrowsing/" | 785 ? "/transparencyreport/safebrowsing/" |
| 797 : "/safebrowsing/diagnostic", | 786 : "/safebrowsing/diagnostic", |
| 798 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().path()); | 787 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().path()); |
| 799 } | 788 } |
| 800 | 789 |
| 801 INSTANTIATE_TEST_CASE_P(SafeBrowsingBlockingPageBrowserTestWithThreatType, | 790 INSTANTIATE_TEST_CASE_P(SafeBrowsingBlockingPageBrowserTestWithThreatType, |
| 802 SafeBrowsingBlockingPageBrowserTest, | 791 SafeBrowsingBlockingPageBrowserTest, |
| 803 testing::Values(SB_THREAT_TYPE_URL_MALWARE, | 792 testing::Values(SB_THREAT_TYPE_URL_MALWARE, |
| 804 SB_THREAT_TYPE_URL_PHISHING, | 793 SB_THREAT_TYPE_URL_PHISHING, |
| 805 SB_THREAT_TYPE_URL_UNWANTED)); | 794 SB_THREAT_TYPE_URL_UNWANTED)); |
| OLD | NEW |