Index: chrome/renderer/safe_browsing/phishing_classifier_delegate_browsertest.cc |
diff --git a/chrome/renderer/safe_browsing/phishing_classifier_delegate_browsertest.cc b/chrome/renderer/safe_browsing/phishing_classifier_delegate_browsertest.cc |
index f24d8f478a604deb8b4398feed409582eaf58bb1..b46e4063fecb36e21dcd5c26d62b40a28445b74c 100644 |
--- a/chrome/renderer/safe_browsing/phishing_classifier_delegate_browsertest.cc |
+++ b/chrome/renderer/safe_browsing/phishing_classifier_delegate_browsertest.cc |
@@ -112,6 +112,7 @@ TEST_F(PhishingClassifierDelegateTest, Navigation) { |
delegate.CommittedLoadInFrame(GetMainFrame()); |
delegate.CommittedLoadInFrame(child_frame); |
Mock::VerifyAndClearExpectations(classifier); |
+ delegate.OnStartPhishingDetection(GURL("http://host.com/")); |
EXPECT_CALL(*classifier, BeginClassification(Pointee(page_text), _)). |
WillOnce(DeleteArg<1>()); |
delegate.FinishedLoad(&page_text); |
@@ -123,6 +124,8 @@ TEST_F(PhishingClassifierDelegateTest, Navigation) { |
EXPECT_CALL(*classifier, CancelPendingClassification()); |
delegate.CommittedLoadInFrame(GetMainFrame()); |
Mock::VerifyAndClearExpectations(classifier); |
+ delegate.OnStartPhishingDetection(GURL("http://host.com/")); |
+ page_text = ASCIIToUTF16("dummy"); |
delegate.FinishedLoad(&page_text); |
// Navigating in a subframe will increment the page id, but not change |
@@ -133,6 +136,8 @@ TEST_F(PhishingClassifierDelegateTest, Navigation) { |
EXPECT_CALL(*classifier, CancelPendingClassification()); |
delegate.CommittedLoadInFrame(child_frame); |
Mock::VerifyAndClearExpectations(classifier); |
+ delegate.OnStartPhishingDetection(GURL("http://host.com/")); |
+ page_text = ASCIIToUTF16("dummy"); |
delegate.FinishedLoad(&page_text); |
// Scrolling to an anchor will increment the page id, but should not |
@@ -140,24 +145,39 @@ TEST_F(PhishingClassifierDelegateTest, Navigation) { |
// be cancelled, since the content is not changing. |
LoadURL("http://host.com/#foo"); |
delegate.CommittedLoadInFrame(GetMainFrame()); |
+ delegate.OnStartPhishingDetection(GURL("http://host.com/#foo")); |
+ page_text = ASCIIToUTF16("dummy"); |
delegate.FinishedLoad(&page_text); |
// Now load a new toplevel page, which should trigger another classification. |
LoadURL("http://host2.com/"); |
- page_text = ASCIIToUTF16("dummy2"); |
EXPECT_CALL(*classifier, CancelPendingClassification()); |
delegate.CommittedLoadInFrame(GetMainFrame()); |
Mock::VerifyAndClearExpectations(classifier); |
+ page_text = ASCIIToUTF16("dummy2"); |
EXPECT_CALL(*classifier, BeginClassification(Pointee(page_text), _)). |
WillOnce(DeleteArg<1>()); |
+ delegate.OnStartPhishingDetection(GURL("http://host2.com/")); |
delegate.FinishedLoad(&page_text); |
Mock::VerifyAndClearExpectations(classifier); |
+ // No classification should happen on back/forward navigation. |
+ // Note: in practice, the browser will not send a StartPhishingDetection IPC |
+ // in this case. However, we want to make sure that the delegate behaves |
+ // correctly regardless. |
+ GoBack(); |
+ EXPECT_CALL(*classifier, CancelPendingClassification()); |
+ delegate.CommittedLoadInFrame(GetMainFrame()); |
+ Mock::VerifyAndClearExpectations(classifier); |
+ page_text = ASCIIToUTF16("dummy"); |
+ delegate.OnStartPhishingDetection(GURL("http://host.com/#foo")); |
+ delegate.FinishedLoad(&page_text); |
+ |
// The delegate will cancel pending classification on destruction. |
EXPECT_CALL(*classifier, CancelPendingClassification()); |
} |
-TEST_F(PhishingClassifierDelegateTest, PendingClassification) { |
+TEST_F(PhishingClassifierDelegateTest, NoScorer) { |
// For this test, we'll create the delegate with no scorer available yet. |
MockPhishingClassifier* classifier = |
new StrictMock<MockPhishingClassifier>(view_); |
@@ -168,11 +188,13 @@ TEST_F(PhishingClassifierDelegateTest, PendingClassification) { |
LoadURL("http://host.com/"); |
string16 page_text = ASCIIToUTF16("dummy"); |
delegate.CommittedLoadInFrame(GetMainFrame()); |
+ delegate.OnStartPhishingDetection(GURL("http://host.com/")); |
delegate.FinishedLoad(&page_text); |
LoadURL("http://host2.com/"); |
delegate.CommittedLoadInFrame(GetMainFrame()); |
page_text = ASCIIToUTF16("dummy2"); |
+ delegate.OnStartPhishingDetection(GURL("http://host2.com/")); |
delegate.FinishedLoad(&page_text); |
// Now set a scorer, which should cause a classifier to be created and |
@@ -189,7 +211,7 @@ TEST_F(PhishingClassifierDelegateTest, PendingClassification) { |
EXPECT_CALL(*classifier, CancelPendingClassification()); |
} |
-TEST_F(PhishingClassifierDelegateTest, PendingClassification_Ref) { |
+TEST_F(PhishingClassifierDelegateTest, NoScorer_Ref) { |
// Similar to the last test, but navigates within the page before |
// setting the scorer. |
MockPhishingClassifier* classifier = |
@@ -202,11 +224,13 @@ TEST_F(PhishingClassifierDelegateTest, PendingClassification_Ref) { |
delegate.CommittedLoadInFrame(GetMainFrame()); |
string16 orig_page_text = ASCIIToUTF16("dummy"); |
string16 page_text = orig_page_text; |
+ delegate.OnStartPhishingDetection(GURL("http://host.com/")); |
delegate.FinishedLoad(&page_text); |
LoadURL("http://host.com/#foo"); |
page_text = orig_page_text; |
delegate.CommittedLoadInFrame(GetMainFrame()); |
+ delegate.OnStartPhishingDetection(GURL("http://host.com/#foo")); |
delegate.FinishedLoad(&page_text); |
// Now set a scorer, which should cause a classifier to be created and |
@@ -221,6 +245,49 @@ TEST_F(PhishingClassifierDelegateTest, PendingClassification_Ref) { |
EXPECT_CALL(*classifier, CancelPendingClassification()); |
} |
+TEST_F(PhishingClassifierDelegateTest, NoStartPhishingDetection) { |
+ // Tests the behavior when OnStartPhishingDetection has not yet been called |
+ // when the page load finishes. |
+ MockPhishingClassifier* classifier = |
+ new StrictMock<MockPhishingClassifier>(view_); |
+ PhishingClassifierDelegate delegate(view_, classifier); |
+ MockScorer scorer; |
+ delegate.SetPhishingScorer(&scorer); |
+ ASSERT_TRUE(classifier->is_ready()); |
+ |
+ responses_["http://host.com/"] = "<html><body>phish</body></html>"; |
+ LoadURL("http://host.com/"); |
+ string16 orig_page_text = ASCIIToUTF16("phish"); |
+ string16 page_text = orig_page_text; |
+ EXPECT_CALL(*classifier, CancelPendingClassification()); |
+ delegate.CommittedLoadInFrame(GetMainFrame()); |
+ Mock::VerifyAndClearExpectations(classifier); |
+ delegate.FinishedLoad(&page_text); |
+ |
+ // Now simulate the StartPhishingDetection IPC. We expect classification |
+ // to begin. |
+ EXPECT_CALL(*classifier, BeginClassification(Pointee(orig_page_text), _)). |
+ WillOnce(DeleteArg<1>()); |
+ delegate.OnStartPhishingDetection(GURL("http://host.com/")); |
+ Mock::VerifyAndClearExpectations(classifier); |
+ |
+ // Now try again, but this time we will navigate the page away before |
+ // the IPC is sent. |
+ responses_["http://host2.com/"] = "<html><body>phish</body></html>"; |
+ LoadURL("http://host2.com/"); |
+ EXPECT_CALL(*classifier, CancelPendingClassification()); |
+ delegate.CommittedLoadInFrame(GetMainFrame()); |
+ Mock::VerifyAndClearExpectations(classifier); |
+ delegate.FinishedLoad(&page_text); |
+ |
+ responses_["http://host3.com/"] = "<html><body>phish</body></html>"; |
+ LoadURL("http://host3.com/"); |
+ delegate.OnStartPhishingDetection(GURL("http://host2.com/")); |
+ |
+ // The delegate will cancel pending classification on destruction. |
+ EXPECT_CALL(*classifier, CancelPendingClassification()); |
+} |
+ |
TEST_F(PhishingClassifierDelegateTest, DetectedPhishingSite) { |
// Tests that a DetectedPhishingSite IPC is sent to the browser |
// if a site comes back as phishy. |
@@ -240,6 +307,7 @@ TEST_F(PhishingClassifierDelegateTest, DetectedPhishingSite) { |
Mock::VerifyAndClearExpectations(classifier); |
EXPECT_CALL(*classifier, BeginClassification(Pointee(page_text), _)). |
WillOnce(DeleteArg<1>()); |
+ delegate.OnStartPhishingDetection(GURL("http://host.com/")); |
delegate.FinishedLoad(&page_text); |
Mock::VerifyAndClearExpectations(classifier); |