| 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 76a706ee09d8a58b89f33a418210da1c2f86d73c..8131bf8ad222f5faa2e3d0d57759e677e35d0b2d 100644
|
| --- a/chrome/renderer/safe_browsing/phishing_classifier_delegate_browsertest.cc
|
| +++ b/chrome/renderer/safe_browsing/phishing_classifier_delegate_browsertest.cc
|
| @@ -89,6 +89,11 @@ class PhishingClassifierDelegateTest : public RenderViewFakeResourcesTest {
|
| message_loop_.Run();
|
| }
|
|
|
| + void OnStartPhishingDetection(PhishingClassifierDelegate* delegate,
|
| + const GURL& url) {
|
| + delegate->OnStartPhishingDetection(url);
|
| + }
|
| +
|
| bool detected_phishing_site_;
|
| GURL detected_url_;
|
| double detected_score_;
|
| @@ -109,6 +114,7 @@ TEST_F(PhishingClassifierDelegateTest, Navigation) {
|
| "<html><body><iframe src=\"http://sub1.com/\"></iframe></body></html>";
|
| LoadURL("http://host.com/");
|
| Mock::VerifyAndClearExpectations(classifier);
|
| + OnStartPhishingDetection(delegate, GURL("http://host.com/"));
|
| string16 page_text = ASCIIToUTF16("dummy");
|
| EXPECT_CALL(*classifier, BeginClassification(Pointee(page_text), _)).
|
| WillOnce(DeleteArg<1>());
|
| @@ -122,6 +128,7 @@ TEST_F(PhishingClassifierDelegateTest, Navigation) {
|
| GetMainFrame()->reload();
|
| message_loop_.Run();
|
| Mock::VerifyAndClearExpectations(classifier);
|
| + OnStartPhishingDetection(delegate, GURL("http://host.com/"));
|
| delegate->PageCaptured(page_text);
|
|
|
| // Navigating in a subframe will increment the page id, but not change
|
| @@ -132,12 +139,14 @@ TEST_F(PhishingClassifierDelegateTest, Navigation) {
|
| WebKit::WebURLRequest(GURL("http://sub2.com/")));
|
| message_loop_.Run();
|
| Mock::VerifyAndClearExpectations(classifier);
|
| + OnStartPhishingDetection(delegate, GURL("http://host.com/"));
|
| delegate->PageCaptured(page_text);
|
|
|
| // Scrolling to an anchor will increment the page id, but should not
|
| // not trigger a reclassification. A pending classification should not
|
| // be cancelled, since the content is not changing.
|
| LoadURL("http://host.com/#foo");
|
| + OnStartPhishingDetection(delegate, GURL("http://host.com/#foo"));
|
| delegate->PageCaptured(page_text);
|
|
|
| // Now load a new toplevel page, which should trigger another classification.
|
| @@ -147,14 +156,26 @@ TEST_F(PhishingClassifierDelegateTest, Navigation) {
|
| page_text = ASCIIToUTF16("dummy2");
|
| EXPECT_CALL(*classifier, BeginClassification(Pointee(page_text), _)).
|
| WillOnce(DeleteArg<1>());
|
| + OnStartPhishingDetection(delegate, GURL("http://host2.com/"));
|
| delegate->PageCaptured(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.
|
| + EXPECT_CALL(*classifier, CancelPendingClassification());
|
| + GoBack();
|
| + Mock::VerifyAndClearExpectations(classifier);
|
| + page_text = ASCIIToUTF16("dummy");
|
| + OnStartPhishingDetection(delegate, GURL("http://host.com/#foo"));
|
| + delegate->PageCaptured(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_);
|
| @@ -165,10 +186,12 @@ TEST_F(PhishingClassifierDelegateTest, PendingClassification) {
|
| // Queue up a pending classification, cancel it, then queue up another one.
|
| LoadURL("http://host.com/");
|
| string16 page_text = ASCIIToUTF16("dummy");
|
| + OnStartPhishingDetection(delegate, GURL("http://host.com/"));
|
| delegate->PageCaptured(page_text);
|
|
|
| LoadURL("http://host2.com/");
|
| page_text = ASCIIToUTF16("dummy2");
|
| + OnStartPhishingDetection(delegate, GURL("http://host2.com/"));
|
| delegate->PageCaptured(page_text);
|
|
|
| // Now set a scorer, which should cause a classifier to be created and
|
| @@ -185,7 +208,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 =
|
| @@ -196,17 +219,17 @@ TEST_F(PhishingClassifierDelegateTest, PendingClassification_Ref) {
|
|
|
| // Queue up a pending classification, cancel it, then queue up another one.
|
| LoadURL("http://host.com/");
|
| - string16 orig_page_text = ASCIIToUTF16("dummy");
|
| - string16 page_text = orig_page_text;
|
| + string16 page_text = ASCIIToUTF16("dummy");
|
| + OnStartPhishingDetection(delegate, GURL("http://host.com/"));
|
| delegate->PageCaptured(page_text);
|
|
|
| LoadURL("http://host.com/#foo");
|
| - page_text = orig_page_text;
|
| + OnStartPhishingDetection(delegate, GURL("http://host.com/#foo"));
|
| delegate->PageCaptured(page_text);
|
|
|
| // Now set a scorer, which should cause a classifier to be created and
|
| // the classification to proceed.
|
| - EXPECT_CALL(*classifier, BeginClassification(Pointee(orig_page_text), _)).
|
| + EXPECT_CALL(*classifier, BeginClassification(Pointee(page_text), _)).
|
| WillOnce(DeleteArg<1>());
|
| MockScorer scorer;
|
| delegate->SetPhishingScorer(&scorer);
|
| @@ -216,6 +239,47 @@ 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 =
|
| + new PhishingClassifierDelegate(view_, classifier);
|
| + MockScorer scorer;
|
| + delegate->SetPhishingScorer(&scorer);
|
| + ASSERT_TRUE(classifier->is_ready());
|
| +
|
| + EXPECT_CALL(*classifier, CancelPendingClassification());
|
| + responses_["http://host.com/"] = "<html><body>phish</body></html>";
|
| + LoadURL("http://host.com/");
|
| + Mock::VerifyAndClearExpectations(classifier);
|
| + string16 page_text = ASCIIToUTF16("phish");
|
| + delegate->PageCaptured(page_text);
|
| + // Now simulate the StartPhishingDetection IPC. We expect classification
|
| + // to begin.
|
| + EXPECT_CALL(*classifier, BeginClassification(Pointee(page_text), _)).
|
| + WillOnce(DeleteArg<1>());
|
| + OnStartPhishingDetection(delegate, GURL("http://host.com/"));
|
| + Mock::VerifyAndClearExpectations(classifier);
|
| +
|
| + // Now try again, but this time we will navigate the page away before
|
| + // the IPC is sent.
|
| + EXPECT_CALL(*classifier, CancelPendingClassification());
|
| + responses_["http://host2.com/"] = "<html><body>phish</body></html>";
|
| + LoadURL("http://host2.com/");
|
| + delegate->PageCaptured(page_text);
|
| +
|
| + EXPECT_CALL(*classifier, CancelPendingClassification());
|
| + responses_["http://host3.com/"] = "<html><body>phish</body></html>";
|
| + LoadURL("http://host3.com/");
|
| + Mock::VerifyAndClearExpectations(classifier);
|
| + OnStartPhishingDetection(delegate, 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.
|
| @@ -235,6 +299,7 @@ TEST_F(PhishingClassifierDelegateTest, DetectedPhishingSite) {
|
| string16 page_text = ASCIIToUTF16("phish");
|
| EXPECT_CALL(*classifier, BeginClassification(Pointee(page_text), _)).
|
| WillOnce(DeleteArg<1>());
|
| + OnStartPhishingDetection(delegate, GURL("http://host.com/"));
|
| delegate->PageCaptured(page_text);
|
| Mock::VerifyAndClearExpectations(classifier);
|
|
|
|
|