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 | 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" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 133 |
134 void WaitForDOM() { | 134 void WaitForDOM() { |
135 if (got_dom_) { | 135 if (got_dom_) { |
136 LOG(INFO) << "Already got the dom details."; | 136 LOG(INFO) << "Already got the dom details."; |
137 return; | 137 return; |
138 } | 138 } |
139 // This condition might not trigger normally, but if you add a | 139 // This condition might not trigger normally, but if you add a |
140 // sleep(1) in malware_dom_details it triggers :). | 140 // sleep(1) in malware_dom_details it triggers :). |
141 waiting_ = true; | 141 waiting_ = true; |
142 LOG(INFO) << "Waiting for dom details."; | 142 LOG(INFO) << "Waiting for dom details."; |
143 ui_test_utils::RunMessageLoop(); | 143 content::RunMessageLoop(); |
144 EXPECT_TRUE(got_dom_); | 144 EXPECT_TRUE(got_dom_); |
145 } | 145 } |
146 | 146 |
147 private: | 147 private: |
148 virtual ~FakeMalwareDetails() {} | 148 virtual ~FakeMalwareDetails() {} |
149 | 149 |
150 void OnDOMDetailsDone() { | 150 void OnDOMDetailsDone() { |
151 got_dom_ = true; | 151 got_dom_ = true; |
152 if (waiting_) { | 152 if (waiting_) { |
153 MessageLoopForUI::current()->Quit(); | 153 MessageLoopForUI::current()->Quit(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 if (!wait_for_delete_) | 198 if (!wait_for_delete_) |
199 return; | 199 return; |
200 | 200 |
201 // Notify that we are gone | 201 // Notify that we are gone |
202 MessageLoopForUI::current()->Quit(); | 202 MessageLoopForUI::current()->Quit(); |
203 wait_for_delete_ = false; | 203 wait_for_delete_ = false; |
204 } | 204 } |
205 | 205 |
206 void WaitForDelete() { | 206 void WaitForDelete() { |
207 wait_for_delete_ = true; | 207 wait_for_delete_ = true; |
208 ui_test_utils::RunMessageLoop(); | 208 content::RunMessageLoop(); |
209 } | 209 } |
210 | 210 |
211 private: | 211 private: |
212 bool wait_for_delete_; | 212 bool wait_for_delete_; |
213 }; | 213 }; |
214 | 214 |
215 class TestSafeBrowsingBlockingPageFactory | 215 class TestSafeBrowsingBlockingPageFactory |
216 : public SafeBrowsingBlockingPageFactory { | 216 : public SafeBrowsingBlockingPageFactory { |
217 public: | 217 public: |
218 TestSafeBrowsingBlockingPageFactory() { } | 218 TestSafeBrowsingBlockingPageFactory() { } |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 WebContents* contents = chrome::GetActiveWebContents(browser()); | 322 WebContents* contents = chrome::GetActiveWebContents(browser()); |
323 content::WindowedNotificationObserver interstitial_observer( | 323 content::WindowedNotificationObserver interstitial_observer( |
324 content::NOTIFICATION_INTERSTITIAL_ATTACHED, | 324 content::NOTIFICATION_INTERSTITIAL_ATTACHED, |
325 content::Source<WebContents>(contents)); | 325 content::Source<WebContents>(contents)); |
326 if (!InterstitialPage::GetInterstitialPage(contents)) | 326 if (!InterstitialPage::GetInterstitialPage(contents)) |
327 interstitial_observer.Wait(); | 327 interstitial_observer.Wait(); |
328 } | 328 } |
329 | 329 |
330 void AssertReportSent() { | 330 void AssertReportSent() { |
331 // When a report is scheduled in the IO thread we should get notified. | 331 // When a report is scheduled in the IO thread we should get notified. |
332 ui_test_utils::RunMessageLoop(); | 332 content::RunMessageLoop(); |
333 | 333 |
334 FakeSafeBrowsingService* service = | 334 FakeSafeBrowsingService* service = |
335 static_cast<FakeSafeBrowsingService*>( | 335 static_cast<FakeSafeBrowsingService*>( |
336 g_browser_process->safe_browsing_service()); | 336 g_browser_process->safe_browsing_service()); |
337 | 337 |
338 std::string serialized = service->GetReport(); | 338 std::string serialized = service->GetReport(); |
339 | 339 |
340 safe_browsing::ClientMalwareReportRequest report; | 340 safe_browsing::ClientMalwareReportRequest report; |
341 ASSERT_TRUE(report.ParseFromString(serialized)); | 341 ASSERT_TRUE(report.ParseFromString(serialized)); |
342 | 342 |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 EXPECT_TRUE(GetProceedLinkIsHidden(&hidden)); | 615 EXPECT_TRUE(GetProceedLinkIsHidden(&hidden)); |
616 EXPECT_TRUE(hidden); | 616 EXPECT_TRUE(hidden); |
617 | 617 |
618 // The "proceed" command should go back instead, if proceeding is disabled. | 618 // The "proceed" command should go back instead, if proceeding is disabled. |
619 SendCommand("\"proceed\""); | 619 SendCommand("\"proceed\""); |
620 AssertNoInterstitial(true); | 620 AssertNoInterstitial(true); |
621 EXPECT_EQ( | 621 EXPECT_EQ( |
622 GURL(chrome::kAboutBlankURL), // Back to "about:blank" | 622 GURL(chrome::kAboutBlankURL), // Back to "about:blank" |
623 chrome::GetActiveWebContents(browser())->GetURL()); | 623 chrome::GetActiveWebContents(browser())->GetURL()); |
624 } | 624 } |
OLD | NEW |