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

Unified Diff: chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc

Issue 6611023: The optional Malware Details also collects HTTP cache information. See design... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc
===================================================================
--- chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc (revision 76771)
+++ chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc (working copy)
@@ -59,12 +59,13 @@
badurls[url.spec()] = checkresult;
}
- virtual void ReportMalwareDetails(scoped_refptr<MalwareDetails> details) {
- details_.push_back(details);
- // Notify the UI thread, that we got a report.
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- NewRunnableMethod(this,
- &FakeSafeBrowsingService::OnMalwareDetailsDone));
+ virtual void OnReportReady(scoped_refptr<MalwareDetails> report) {
+ details_.push_back(report);
+ // Notify the UI thread that we got a report.
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ NewRunnableMethod(this,
+ &FakeSafeBrowsingService::OnMalwareDetailsDone));
}
void OnMalwareDetailsDone() {
@@ -72,11 +73,11 @@
MessageLoopForUI::current()->Quit();
}
- std::list<scoped_refptr<MalwareDetails> >* GetDetails() {
+ std::vector<scoped_refptr<MalwareDetails> >* GetDetails() {
return &details_;
}
- std::list<scoped_refptr<MalwareDetails> > details_;
+ std::vector<scoped_refptr<MalwareDetails> > details_;
private:
base::hash_map<std::string, UrlCheckResult> badurls;
@@ -136,6 +137,10 @@
waiting_ = waiting;
}
+ safe_browsing::ClientMalwareReportRequest* get_report() {
+ return report_.get();
+ }
+
private:
// Some logic to figure out if we should wait for the dom details or not.
// These variables should only be accessed in the UI thread.
@@ -164,6 +169,46 @@
FakeMalwareDetails* details_;
};
+// A SafeBrowingBlockingPage class that lets us wait until it's hidden.
+class TestSafeBrowsingBlockingPage : public SafeBrowsingBlockingPage {
+ public:
+ TestSafeBrowsingBlockingPage(SafeBrowsingService* service,
+ TabContents* tab_contents,
+ const UnsafeResourceList& unsafe_resources)
+ : SafeBrowsingBlockingPage(service, tab_contents, unsafe_resources) {
+ wait_for_delete_ = false;
+ }
+
+ ~TestSafeBrowsingBlockingPage() {
+ if (wait_for_delete_) {
+ // Notify that we are gone
+ MessageLoopForUI::current()->Quit();
+ }
+ }
+
+ void set_wait_for_delete() {
+ wait_for_delete_ = true;
+ }
+
+ private:
+ bool wait_for_delete_;
+};
+
+class TestSafeBrowsingBlockingPageFactory
+ : public SafeBrowsingBlockingPageFactory {
+ public:
+ TestSafeBrowsingBlockingPageFactory() { }
+ ~TestSafeBrowsingBlockingPageFactory() { }
+
+ virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage(
+ SafeBrowsingService* service,
+ TabContents* tab_contents,
+ const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) {
+ return new TestSafeBrowsingBlockingPage(service, tab_contents,
+ unsafe_resources);
+ }
+};
+
// Tests the safe browsing blocking page in a browser.
class SafeBrowsingBlockingPageTest : public InProcessBrowserTest,
public SafeBrowsingService::Client {
@@ -173,12 +218,14 @@
virtual void SetUp() {
SafeBrowsingService::RegisterFactory(&factory_);
+ SafeBrowsingBlockingPage::RegisterFactory(&blocking_page_factory_);
MalwareDetails::RegisterFactory(&details_factory_);
InProcessBrowserTest::SetUp();
}
virtual void TearDown() {
InProcessBrowserTest::TearDown();
+ SafeBrowsingBlockingPage::RegisterFactory(NULL);
SafeBrowsingService::RegisterFactory(NULL);
MalwareDetails::RegisterFactory(NULL);
}
@@ -236,12 +283,19 @@
interstitial_page->Proceed();
}
- void AssertNoInterstitial() {
- // ui_test_utils::RunAllPendingInMessageLoop();
+ void AssertNoInterstitial(bool wait_for_delete) {
TabContents* contents = browser()->GetSelectedTabContents();
- InterstitialPage* interstitial_page = InterstitialPage::GetInterstitialPage(
- contents);
- ASSERT_FALSE(interstitial_page);
+
+ if (contents->showing_interstitial_page() && wait_for_delete) {
+ // We'll get notified when the interstitial is deleted.
+ static_cast<TestSafeBrowsingBlockingPage*>(
+ contents->interstitial_page())->set_wait_for_delete();
+ ui_test_utils::RunMessageLoop();
+ }
+
+ // Can't use InterstitialPage::GetInterstitialPage() because that
+ // gets updated after the TestSafeBrowsingBlockingPage destructor
+ ASSERT_FALSE(contents->showing_interstitial_page());
}
void WaitForNavigation() {
@@ -259,6 +313,11 @@
g_browser_process->resource_dispatcher_host()->
safe_browsing_service());
ASSERT_EQ(1u, service->GetDetails()->size());
+
+ // Verify the report is complete.
+ FakeMalwareDetails* details =
+ static_cast<FakeMalwareDetails*>(service->GetDetails()->at(0).get());
+ EXPECT_TRUE(details->get_report()->complete());
}
protected:
@@ -266,6 +325,7 @@
private:
TestSafeBrowsingServiceFactory factory_;
+ TestSafeBrowsingBlockingPageFactory blocking_page_factory_;
DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageTest);
};
@@ -283,7 +343,7 @@
ui_test_utils::NavigateToURL(browser(), url);
SendCommand("\"takeMeBack\""); // Simulate the user clicking "back"
- AssertNoInterstitial(); // Assert the interstitial is gone
+ AssertNoInterstitial(false); // Assert the interstitial is gone
EXPECT_EQ(GURL(chrome::kAboutBlankURL), // Back to "about:blank"
browser()->GetSelectedTabContents()->GetURL());
}
@@ -296,7 +356,7 @@
SendCommand("\"proceed\""); // Simulate the user clicking "proceed"
WaitForNavigation(); // Wait until we finish the navigation.
- AssertNoInterstitial(); // Assert the interstitial is gone.
+ AssertNoInterstitial(true); // Assert the interstitial is gone.
EXPECT_EQ(url, browser()->GetSelectedTabContents()->GetURL());
}
@@ -307,7 +367,7 @@
ui_test_utils::NavigateToURL(browser(), url);
SendCommand("\"takeMeBack\""); // Simulate the user clicking "proceed"
- AssertNoInterstitial(); // Assert the interstitial is gone
+ AssertNoInterstitial(false); // Assert the interstitial is gone
EXPECT_EQ(GURL(chrome::kAboutBlankURL), // We are back to "about:blank".
browser()->GetSelectedTabContents()->GetURL());
}
@@ -320,7 +380,7 @@
SendCommand("\"proceed\""); // Simulate the user clicking "proceed".
WaitForNavigation(); // Wait until we finish the navigation.
- AssertNoInterstitial(); // Assert the interstitial is gone
+ AssertNoInterstitial(true); // Assert the interstitial is gone
EXPECT_EQ(url, browser()->GetSelectedTabContents()->GetURL());
}
@@ -332,7 +392,7 @@
SendCommand("\"reportError\""); // Simulate the user clicking "report error"
WaitForNavigation(); // Wait until we finish the navigation.
- AssertNoInterstitial(); // Assert the interstitial is gone
+ AssertNoInterstitial(false); // Assert the interstitial is gone
// We are in the error reporting page.
EXPECT_EQ("/safebrowsing/report_error/",
@@ -347,7 +407,7 @@
SendCommand("\"learnMore\""); // Simulate the user clicking "learn more"
WaitForNavigation(); // Wait until we finish the navigation.
- AssertNoInterstitial(); // Assert the interstitial is gone
+ AssertNoInterstitial(false); // Assert the interstitial is gone
// We are in the help page.
EXPECT_EQ("/support/bin/answer.py",
@@ -362,7 +422,7 @@
ui_test_utils::NavigateToURL(browser(), url);
SendCommand("\"takeMeBack\""); // Simulate the user clicking "back"
- AssertNoInterstitial(); // Assert the interstitial is gone
+ AssertNoInterstitial(false); // Assert the interstitial is gone
EXPECT_EQ(GURL(chrome::kAboutBlankURL), // Back to "about:blank"
browser()->GetSelectedTabContents()->GetURL());
@@ -378,7 +438,7 @@
ui_test_utils::NavigateToURL(browser(), url);
SendCommand("\"proceed\""); // Simulate the user clicking "proceed"
- AssertNoInterstitial(); // Assert the interstitial is gone
+ AssertNoInterstitial(true); // Assert the interstitial is gone
EXPECT_EQ(url, browser()->GetSelectedTabContents()->GetURL());
}
@@ -407,7 +467,7 @@
prefs::kSafeBrowsingReportingEnabled));
SendCommand("\"proceed\""); // Simulate the user clicking "back"
- AssertNoInterstitial(); // Assert the interstitial is gone
+ AssertNoInterstitial(true); // Assert the interstitial is gone
EXPECT_EQ(url, browser()->GetSelectedTabContents()->GetURL());
AssertReportSent();

Powered by Google App Engine
This is Rietveld 408576698