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

Side by Side Diff: chrome/renderer/safe_browsing/phishing_classifier_delegate_browsertest.cc

Issue 1585003002: Rewrite PhishingClassifierDelegateTest using ChromeRenderViewTest to run with multi-process (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/renderer/safe_browsing/threat_dom_details.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" 5 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h"
6 6
7 #include <stdint.h>
8 #include <utility>
9
10 #include "base/command_line.h"
11 #include "base/location.h"
12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
14 #include "base/run_loop.h"
15 #include "base/single_thread_task_runner.h"
16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
18 #include "build/build_config.h"
19 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_commands.h"
21 #include "chrome/browser/ui/tabs/tab_strip_model.h"
22 #include "chrome/common/chrome_switches.h"
23 #include "chrome/common/safe_browsing/csd.pb.h" 9 #include "chrome/common/safe_browsing/csd.pb.h"
24 #include "chrome/common/safe_browsing/safebrowsing_messages.h" 10 #include "chrome/common/safe_browsing/safebrowsing_messages.h"
25 #include "chrome/renderer/safe_browsing/features.h" 11 #include "chrome/renderer/safe_browsing/features.h"
26 #include "chrome/renderer/safe_browsing/phishing_classifier.h" 12 #include "chrome/renderer/safe_browsing/phishing_classifier.h"
27 #include "chrome/renderer/safe_browsing/scorer.h" 13 #include "chrome/renderer/safe_browsing/scorer.h"
28 #include "chrome/test/base/in_process_browser_test.h" 14 #include "chrome/test/base/chrome_render_view_test.h"
29 #include "chrome/test/base/ui_test_utils.h" 15 #include "chrome/test/base/chrome_unit_test_suite.h"
30 #include "content/public/browser/browser_message_filter.h"
31 #include "content/public/browser/browser_thread.h"
32 #include "content/public/browser/render_frame_host.h"
33 #include "content/public/browser/render_process_host.h"
34 #include "content/public/browser/web_contents.h"
35 #include "content/public/common/content_switches.h"
36 #include "content/public/renderer/render_frame.h" 16 #include "content/public/renderer/render_frame.h"
37 #include "content/public/test/browser_test_utils.h" 17 #include "content/public/renderer/render_view.h"
38 #include "content/public/test/test_navigation_observer.h"
39 #include "content/public/test/test_utils.h"
40 #include "net/dns/mock_host_resolver.h"
41 #include "net/test/embedded_test_server/embedded_test_server.h"
42 #include "net/test/embedded_test_server/http_request.h"
43 #include "net/test/embedded_test_server/http_response.h"
44 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
45 #include "third_party/WebKit/public/platform/WebURL.h" 19 #include "third_party/WebKit/public/platform/WebURL.h"
46 #include "third_party/WebKit/public/platform/WebURLRequest.h" 20 #include "third_party/WebKit/public/platform/WebURLRequest.h"
47 #include "url/gurl.h" 21 #include "url/gurl.h"
48 22
49 using base::ASCIIToUTF16; 23 using base::ASCIIToUTF16;
50 using ::testing::_; 24 using ::testing::_;
51 using ::testing::InSequence; 25 using ::testing::InSequence;
52 using ::testing::Mock; 26 using ::testing::Mock;
53 using ::testing::Pointee; 27 using ::testing::Pointee;
(...skipping 21 matching lines...) Expand all
75 class MockScorer : public Scorer { 49 class MockScorer : public Scorer {
76 public: 50 public:
77 MockScorer() : Scorer() {} 51 MockScorer() : Scorer() {}
78 virtual ~MockScorer() {} 52 virtual ~MockScorer() {}
79 53
80 MOCK_CONST_METHOD1(ComputeScore, double(const FeatureMap&)); 54 MOCK_CONST_METHOD1(ComputeScore, double(const FeatureMap&));
81 55
82 private: 56 private:
83 DISALLOW_COPY_AND_ASSIGN(MockScorer); 57 DISALLOW_COPY_AND_ASSIGN(MockScorer);
84 }; 58 };
59 } // namespace
85 60
86 class InterceptingMessageFilter : public content::BrowserMessageFilter { 61 class FakeRenderThread : public ChromeMockRenderThread {
87 public: 62 public:
88 InterceptingMessageFilter() 63 // Instead of sending this message, we verify its content here.
89 : BrowserMessageFilter(SafeBrowsingMsgStart), 64 bool Send(IPC::Message* msg) override {
90 waiting_message_loop_(NULL) { 65 // handle and verify message here.
66 IPC_BEGIN_MESSAGE_MAP(FakeRenderThread, *msg)
67 IPC_MESSAGE_HANDLER(SafeBrowsingHostMsg_PhishingDetectionDone,
68 VerifyMessageContent)
69 IPC_END_MESSAGE_MAP()
70 if (msg) { // Prevent memory leak.
71 delete msg;
72 msg = nullptr;
73 }
74 // Return true anyway, since we don't want to block other IPC.
75 return true;
91 } 76 }
92 77
93 const ClientPhishingRequest* verdict() const { return verdict_.get(); } 78 void VerifyMessageContent(const std::string& verdict_str) {
94 bool OnMessageReceived(const IPC::Message& message) override { 79 ClientPhishingRequest verdict;
95 bool handled = true; 80 if (verdict.ParseFromString(verdict_str)) {
96 IPC_BEGIN_MESSAGE_MAP(InterceptingMessageFilter, message) 81 EXPECT_EQ("http://host.com/", verdict.url());
97 IPC_MESSAGE_HANDLER(SafeBrowsingHostMsg_PhishingDetectionDone, 82 EXPECT_EQ(0.8f, verdict.client_score());
98 OnPhishingDetectionDone) 83 EXPECT_EQ(false, verdict.is_phishing());
99 IPC_MESSAGE_UNHANDLED(handled = false) 84 } else {
100 IPC_END_MESSAGE_MAP() 85 NOTREACHED() << "Cannot parse IPC content. Test failed.";
101 return handled; 86 }
87 }
88 };
89
90 class PhishingClassifierDelegateTest : public ChromeRenderViewTest {
91 protected:
92 void SetUp() override {
93 ChromeUnitTestSuite::InitializeProviders();
94 ChromeUnitTestSuite::InitializeResourceBundle();
95
96 // Plug-in FakeRenderThread.
97 chrome_render_thread_ = new FakeRenderThread();
98 render_thread_.reset(chrome_render_thread_);
99
100 content::RenderViewTest::SetUp();
101
102 content::RenderFrame* render_frame = view_->GetMainRenderFrame();
103 classifier_ = new StrictMock<MockPhishingClassifier>(render_frame);
104 delegate_ = PhishingClassifierDelegate::Create(render_frame, classifier_);
102 } 105 }
103 106
104 void Reset() { 107 // Runs the ClassificationDone callback, then verify if message sent
105 run_loop_.reset(new base::RunLoop()); 108 // by FakeRenderThread is correct.
106 waiting_message_loop_ = base::MessageLoop::current(); 109 void RunAndVerifyClassificationDone(const ClientPhishingRequest& verdict) {
107 quit_closure_ = run_loop_->QuitClosure(); 110 delegate_->ClassificationDone(verdict);
108 }
109
110 void RunUntilVerdictReceived() {
111 content::RunThisRunLoop(run_loop_.get());
112
113 // Clear out the synchronization state just in case.
114 waiting_message_loop_ = NULL;
115 quit_closure_.Reset();
116 run_loop_.reset();
117 }
118
119 void OnPhishingDetectionDone(const std::string& verdict_str) {
120 scoped_ptr<ClientPhishingRequest> verdict(new ClientPhishingRequest);
121 if (verdict->ParseFromString(verdict_str) &&
122 verdict->IsInitialized()) {
123 verdict_.swap(verdict);
124 }
125 waiting_message_loop_->task_runner()->PostTask(FROM_HERE, quit_closure_);
126 }
127
128 private:
129 ~InterceptingMessageFilter() override {}
130
131 scoped_ptr<ClientPhishingRequest> verdict_;
132 base::MessageLoop* waiting_message_loop_;
133 base::Closure quit_closure_;
134 scoped_ptr<base::RunLoop> run_loop_;
135 };
136 } // namespace
137
138 class PhishingClassifierDelegateTest : public InProcessBrowserTest {
139 public:
140 void CancelCalled() {
141 if (runner_.get()) {
142 content::BrowserThread::PostTask(
143 content::BrowserThread::UI, FROM_HERE, runner_->QuitClosure());
144 }
145 }
146
147 protected:
148 void SetUpCommandLine(base::CommandLine* command_line) override {
149 command_line->AppendSwitch(switches::kSingleProcess);
150 #if defined(OS_WIN)
151 // Don't want to try to create a GPU process.
152 command_line->AppendSwitch(switches::kDisableGpu);
153 #endif
154 }
155
156 void SetUpOnMainThread() override {
157 intercepting_filter_ = new InterceptingMessageFilter();
158
159 GetWebContents()->GetRenderProcessHost()->AddFilter(
160 intercepting_filter_.get());
161 content::RenderFrame* render_frame = GetRenderFrame();
162 classifier_ = new StrictMock<MockPhishingClassifier>(render_frame);
163 PostTaskToInProcessRendererAndWait(
164 base::Bind(&PhishingClassifierDelegateTest::SetUpOnRendererThread,
165 base::Unretained(this)));
166
167 embedded_test_server()->RegisterRequestHandler(
168 base::Bind(&PhishingClassifierDelegateTest::HandleRequest,
169 base::Unretained(this)));
170 ASSERT_TRUE(embedded_test_server()->Start());
171 host_resolver()->AddRule("*", "127.0.0.1");
172 }
173
174 // Runs the ClassificationDone callback, then waits for the
175 // PhishingDetectionDone IPC to arrive.
176 void RunClassificationDone(const ClientPhishingRequest& verdict) {
177 // Clear out any previous state.
178 intercepting_filter_->Reset();
179 PostTaskToInProcessRendererAndWait(
180 base::Bind(&PhishingClassifierDelegate::ClassificationDone,
181 base::Unretained(delegate_),
182 verdict));
183 intercepting_filter_->RunUntilVerdictReceived();
184 } 111 }
185 112
186 void OnStartPhishingDetection(const GURL& url) { 113 void OnStartPhishingDetection(const GURL& url) {
187 PostTaskToInProcessRendererAndWait( 114 delegate_->OnStartPhishingDetection(url);
188 base::Bind(&PhishingClassifierDelegate::OnStartPhishingDetection,
189 base::Unretained(delegate_), url));
190 } 115 }
191 116
192 void PageCaptured(base::string16* page_text, bool preliminary_capture) { 117 void PageCaptured(base::string16* page_text,
193 PostTaskToInProcessRendererAndWait( 118 bool preliminary_capture,
194 base::Bind(&PhishingClassifierDelegate::PageCaptured, 119 const GURL& page_url) {
195 base::Unretained(delegate_), page_text, 120 if (preliminary_capture)
196 preliminary_capture)); 121 return;
122
123 delegate_->CancelPendingClassification(
124 PhishingClassifierDelegate::PAGE_RECAPTURED);
125 delegate_->last_finished_load_url_ = page_url;
126 delegate_->classifier_page_text_.swap(*page_text);
127 delegate_->have_page_text_ = true;
128 delegate_->MaybeStartClassification();
197 } 129 }
198 130
199 scoped_ptr<net::test_server::HttpResponse> HandleRequest( 131 void SimulateRedirection(const GURL& redir_url) {
200 const net::test_server::HttpRequest& request) { 132 delegate_->last_url_received_from_browser_ = redir_url;
201 auto host_it = request.headers.find("Host");
202 if (host_it == request.headers.end())
203 return scoped_ptr<net::test_server::HttpResponse>();
204
205 std::string url =
206 std::string("http://") + host_it->second + request.relative_url;
207 if (response_url_.spec() != url)
208 return scoped_ptr<net::test_server::HttpResponse>();
209
210 scoped_ptr<net::test_server::BasicHttpResponse> http_response(
211 new net::test_server::BasicHttpResponse());
212 http_response->set_code(net::HTTP_OK);
213 http_response->set_content_type("text/html");
214 http_response->set_content(response_content_);
215 return std::move(http_response);
216 } 133 }
217 134
218 content::WebContents* GetWebContents() { 135 void SimulatePageTrantitionForwardOrBack(const char* html, const char* url) {
219 return browser()->tab_strip_model()->GetActiveWebContents(); 136 LoadHTMLWithUrlOverride(html, url);
137 delegate_->last_main_frame_transition_ = ui::PAGE_TRANSITION_FORWARD_BACK;
220 } 138 }
221 139
222 content::RenderFrame* GetRenderFrame() {
223 int render_frame_routing_id =
224 GetWebContents()->GetMainFrame()->GetRoutingID();
225 content::RenderFrame* render_frame =
226 content::RenderFrame::FromRoutingID(render_frame_routing_id);
227 return render_frame;
228 }
229
230 // Returns the URL that was loaded.
231 GURL LoadHtml(const std::string& host, const std::string& content) {
232 GURL::Replacements replace_host;
233 replace_host.SetHostStr(host);
234 response_content_ = content;
235 response_url_ =
236 embedded_test_server()->base_url().ReplaceComponents(replace_host);
237 ui_test_utils::NavigateToURL(browser(), response_url_);
238 return response_url_;
239 }
240
241 void GoBack() {
242 GetWebContents()->GetController().GoBack();
243 content::WaitForLoadStop(GetWebContents());
244 }
245
246 void GoForward() {
247 GetWebContents()->GetController().GoForward();
248 content::WaitForLoadStop(GetWebContents());
249 }
250
251 scoped_refptr<InterceptingMessageFilter> intercepting_filter_;
252 GURL response_url_;
253 std::string response_content_;
254 scoped_ptr<ClientPhishingRequest> verdict_;
255 StrictMock<MockPhishingClassifier>* classifier_; // Owned by |delegate_|. 140 StrictMock<MockPhishingClassifier>* classifier_; // Owned by |delegate_|.
256 PhishingClassifierDelegate* delegate_; // Owned by the RenderView. 141 PhishingClassifierDelegate* delegate_; // Owned by the RenderFrame.
257 scoped_refptr<content::MessageLoopRunner> runner_;
258
259 private:
260 void SetUpOnRendererThread() {
261 content::RenderFrame* render_frame = GetRenderFrame();
262 // PhishingClassifierDelegate is a RenderFrameObserver and therefore has to
263 // be created on the renderer thread, which is not the main thread in an
264 // in-process-browser-test.
265 delegate_ = PhishingClassifierDelegate::Create(render_frame, classifier_);
266 }
267
268 }; 142 };
269 143
270 IN_PROC_BROWSER_TEST_F(PhishingClassifierDelegateTest, Navigation) { 144 TEST_F(PhishingClassifierDelegateTest, Navigation) {
271 MockScorer scorer; 145 MockScorer scorer;
272 delegate_->SetPhishingScorer(&scorer); 146 delegate_->SetPhishingScorer(&scorer);
273 ASSERT_TRUE(classifier_->is_ready()); 147 ASSERT_TRUE(classifier_->is_ready());
274 148
275 // Test an initial load. We expect classification to happen normally. 149 // Test an initial load. We expect classification to happen normally.
276 EXPECT_CALL(*classifier_, CancelPendingClassification()); 150 EXPECT_CALL(*classifier_, CancelPendingClassification());
277 GURL iframe_url = embedded_test_server()->GetURL("/"); 151 std::string html = "<html><body>dummy</body></html>";
278 GURL::Replacements replace_host; 152 GURL url("http://host.com/index.html");
279 replace_host.SetHostStr("sub1.com"); 153 LoadHTMLWithUrlOverride(html.c_str(), url.spec().c_str());
280 std::string html = "<html><body><iframe src=\"";
281 html += iframe_url.ReplaceComponents(replace_host).spec();
282 html += "\"></iframe></body></html>";
283 GURL url = LoadHtml("host.com", html);
284 Mock::VerifyAndClearExpectations(classifier_); 154 Mock::VerifyAndClearExpectations(classifier_);
155
285 OnStartPhishingDetection(url); 156 OnStartPhishingDetection(url);
286 base::string16 page_text = ASCIIToUTF16("dummy"); 157 base::string16 page_text = ASCIIToUTF16("dummy");
287 { 158 {
288 InSequence s; 159 InSequence s;
289 EXPECT_CALL(*classifier_, CancelPendingClassification()); 160 EXPECT_CALL(*classifier_, CancelPendingClassification());
290 EXPECT_CALL(*classifier_, BeginClassification(Pointee(page_text), _)); 161 EXPECT_CALL(*classifier_, BeginClassification(Pointee(page_text), _));
291 PageCaptured(&page_text, false); 162 PageCaptured(&page_text, false, url);
292 Mock::VerifyAndClearExpectations(classifier_); 163 Mock::VerifyAndClearExpectations(classifier_);
293 } 164 }
294 165
295 // Reloading the same page should not trigger a reclassification. 166 // Reloading the same page should not trigger a reclassification.
296 // However, it will cancel any pending classification since the 167 // However, it will cancel any pending classification since the
297 // content is being replaced. 168 // content is being replaced.
298 EXPECT_CALL(*classifier_, CancelPendingClassification()); 169 EXPECT_CALL(*classifier_, CancelPendingClassification());
299 170 LoadHTMLWithUrlOverride(html.c_str(), url.spec().c_str());
300 content::TestNavigationObserver observer(GetWebContents());
301 chrome::Reload(browser(), CURRENT_TAB);
302 observer.Wait();
303
304 Mock::VerifyAndClearExpectations(classifier_);
305 OnStartPhishingDetection(url);
306 page_text = ASCIIToUTF16("dummy");
307 EXPECT_CALL(*classifier_, CancelPendingClassification());
308 PageCaptured(&page_text, false);
309 Mock::VerifyAndClearExpectations(classifier_); 171 Mock::VerifyAndClearExpectations(classifier_);
310 172
311 OnStartPhishingDetection(url); 173 OnStartPhishingDetection(url);
312 page_text = ASCIIToUTF16("dummy"); 174 page_text = ASCIIToUTF16("dummy");
313 EXPECT_CALL(*classifier_, CancelPendingClassification()); 175 EXPECT_CALL(*classifier_, CancelPendingClassification());
314 PageCaptured(&page_text, false); 176 PageCaptured(&page_text, false, url);
315 Mock::VerifyAndClearExpectations(classifier_); 177 Mock::VerifyAndClearExpectations(classifier_);
316 178
317 // Scrolling to an anchor works similarly to a subframe navigation, but
318 // see the TODO in PhishingClassifierDelegate::DidCommitProvisionalLoad.
319 EXPECT_CALL(*classifier_, CancelPendingClassification());
320 GURL foo_url = GURL(url.spec() + "#foo");
321 ui_test_utils::NavigateToURL(browser(), foo_url);
322 Mock::VerifyAndClearExpectations(classifier_);
323 OnStartPhishingDetection(url); 179 OnStartPhishingDetection(url);
324 page_text = ASCIIToUTF16("dummy"); 180 page_text = ASCIIToUTF16("dummy");
325 EXPECT_CALL(*classifier_, CancelPendingClassification()); 181 EXPECT_CALL(*classifier_, CancelPendingClassification());
326 PageCaptured(&page_text, false); 182 PageCaptured(&page_text, false, url);
183 Mock::VerifyAndClearExpectations(classifier_);
184
185 // Navigating within page works similarly to a subframe navigation, but
186 // see the TODO in PhishingClassifierDelegate::DidCommitProvisionalLoad.
187 EXPECT_CALL(*classifier_, CancelPendingClassification());
188 DidNavigateWithinPage(GetMainFrame(), true);
189 Mock::VerifyAndClearExpectations(classifier_);
190
191 OnStartPhishingDetection(url);
192 page_text = ASCIIToUTF16("dummy");
193 EXPECT_CALL(*classifier_, CancelPendingClassification());
194 PageCaptured(&page_text, false, url);
327 Mock::VerifyAndClearExpectations(classifier_); 195 Mock::VerifyAndClearExpectations(classifier_);
328 196
329 // Now load a new toplevel page, which should trigger another classification. 197 // Now load a new toplevel page, which should trigger another classification.
330 EXPECT_CALL(*classifier_, CancelPendingClassification()) 198 EXPECT_CALL(*classifier_, CancelPendingClassification());
331 .WillOnce(Invoke(this, &PhishingClassifierDelegateTest::CancelCalled)); 199 GURL new_url("http://host2.com");
200 LoadHTMLWithUrlOverride("dummy2", new_url.spec().c_str());
201 Mock::VerifyAndClearExpectations(classifier_);
332 202
333 runner_ = new content::MessageLoopRunner;
334 url = LoadHtml("host2.com", "dummy2");
335 runner_->Run();
336 runner_ = NULL;
337
338 Mock::VerifyAndClearExpectations(classifier_);
339 page_text = ASCIIToUTF16("dummy2"); 203 page_text = ASCIIToUTF16("dummy2");
340 OnStartPhishingDetection(url); 204 OnStartPhishingDetection(new_url);
341 { 205 {
342 InSequence s; 206 InSequence s;
343 EXPECT_CALL(*classifier_, CancelPendingClassification()); 207 EXPECT_CALL(*classifier_, CancelPendingClassification());
344 EXPECT_CALL(*classifier_, BeginClassification(Pointee(page_text), _)); 208 EXPECT_CALL(*classifier_, BeginClassification(Pointee(page_text), _));
345 PageCaptured(&page_text, false); 209 PageCaptured(&page_text, false, new_url);
346 Mock::VerifyAndClearExpectations(classifier_); 210 Mock::VerifyAndClearExpectations(classifier_);
347 } 211 }
348 212
349 // No classification should happen on back/forward navigation. 213 // No classification should happen on back/forward navigation.
350 // Note: in practice, the browser will not send a StartPhishingDetection IPC 214 // Note: in practice, the browser will not send a StartPhishingDetection IPC
351 // in this case. However, we want to make sure that the delegate behaves 215 // in this case. However, we want to make sure that the delegate behaves
352 // correctly regardless. 216 // correctly regardless.
353 EXPECT_CALL(*classifier_, CancelPendingClassification()).Times(1); 217 EXPECT_CALL(*classifier_, CancelPendingClassification()).Times(1);
354 GoBack(); 218 // Simulate a go back navigation, i.e. back to http://host.com/index.html.
219 SimulatePageTrantitionForwardOrBack(html.c_str(), url.spec().c_str());
220 Mock::VerifyAndClearExpectations(classifier_);
221 page_text = ASCIIToUTF16("dummy");
222 OnStartPhishingDetection(new_url);
223 EXPECT_CALL(*classifier_, CancelPendingClassification());
224 PageCaptured(&page_text, false, new_url);
225 Mock::VerifyAndClearExpectations(classifier_);
226
227 EXPECT_CALL(*classifier_, CancelPendingClassification());
228 // Simulate a go forward navigation, i.e. forward to http://host.com
229 SimulatePageTrantitionForwardOrBack("dummy2", new_url.spec().c_str());
230 Mock::VerifyAndClearExpectations(classifier_);
231
232 page_text = ASCIIToUTF16("dummy2");
233 OnStartPhishingDetection(url);
234 EXPECT_CALL(*classifier_, CancelPendingClassification());
235 PageCaptured(&page_text, false, url);
236 Mock::VerifyAndClearExpectations(classifier_);
237
238 // Now go back again and navigate to a different place within
239 // the same page. No classification should happen.
240 EXPECT_CALL(*classifier_, CancelPendingClassification());
241 // Simulate a go back again to http://host.com/index.html
242 SimulatePageTrantitionForwardOrBack(html.c_str(), url.spec().c_str());
355 Mock::VerifyAndClearExpectations(classifier_); 243 Mock::VerifyAndClearExpectations(classifier_);
356 244
357 page_text = ASCIIToUTF16("dummy"); 245 page_text = ASCIIToUTF16("dummy");
358 OnStartPhishingDetection(url); 246 OnStartPhishingDetection(url);
359 EXPECT_CALL(*classifier_, CancelPendingClassification()); 247 EXPECT_CALL(*classifier_, CancelPendingClassification());
360 PageCaptured(&page_text, false); 248 PageCaptured(&page_text, false, url);
361 Mock::VerifyAndClearExpectations(classifier_); 249 Mock::VerifyAndClearExpectations(classifier_);
362 250
363 EXPECT_CALL(*classifier_, CancelPendingClassification()); 251 EXPECT_CALL(*classifier_, CancelPendingClassification());
364 GoForward(); 252 // In-page navigation.
365 Mock::VerifyAndClearExpectations(classifier_); 253 DidNavigateWithinPage(GetMainFrame(), true);
366
367 page_text = ASCIIToUTF16("dummy2");
368 OnStartPhishingDetection(url);
369 EXPECT_CALL(*classifier_, CancelPendingClassification());
370 PageCaptured(&page_text, false);
371 Mock::VerifyAndClearExpectations(classifier_);
372
373 // Now go back again and scroll to a different anchor.
374 // No classification should happen.
375 EXPECT_CALL(*classifier_, CancelPendingClassification());
376 GoBack();
377 Mock::VerifyAndClearExpectations(classifier_);
378 page_text = ASCIIToUTF16("dummy");
379
380 OnStartPhishingDetection(url);
381 EXPECT_CALL(*classifier_, CancelPendingClassification());
382 PageCaptured(&page_text, false);
383 Mock::VerifyAndClearExpectations(classifier_);
384
385 EXPECT_CALL(*classifier_, CancelPendingClassification());
386 GURL foo2_url = GURL(foo_url.spec() + "2");
387 ui_test_utils::NavigateToURL(browser(), foo2_url);
388 Mock::VerifyAndClearExpectations(classifier_); 254 Mock::VerifyAndClearExpectations(classifier_);
389 255
390 OnStartPhishingDetection(url); 256 OnStartPhishingDetection(url);
391 page_text = ASCIIToUTF16("dummy"); 257 page_text = ASCIIToUTF16("dummy");
392 EXPECT_CALL(*classifier_, CancelPendingClassification()); 258 EXPECT_CALL(*classifier_, CancelPendingClassification());
393 PageCaptured(&page_text, false); 259 PageCaptured(&page_text, false, url);
394 Mock::VerifyAndClearExpectations(classifier_); 260 Mock::VerifyAndClearExpectations(classifier_);
395 261
396 // The delegate will cancel pending classification on destruction. 262 // The delegate will cancel pending classification on destruction.
397 EXPECT_CALL(*classifier_, CancelPendingClassification()); 263 EXPECT_CALL(*classifier_, CancelPendingClassification());
398 } 264 }
399 265
400 // Flaky: crbug.com/479757 266 TEST_F(PhishingClassifierDelegateTest, NoScorer) {
401 #if defined(LEAK_SANITIZER)
402 #define MAYBE_NoScorer DISABLED_NoScorer
403 #else
404 #define MAYBE_NoScorer NoScorer
405 #endif
406
407 IN_PROC_BROWSER_TEST_F(PhishingClassifierDelegateTest, MAYBE_NoScorer) {
408 // For this test, we'll create the delegate with no scorer available yet. 267 // For this test, we'll create the delegate with no scorer available yet.
409 ASSERT_FALSE(classifier_->is_ready()); 268 ASSERT_FALSE(classifier_->is_ready());
410 269
411 // Queue up a pending classification, cancel it, then queue up another one. 270 // Queue up a pending classification, cancel it, then queue up another one.
412 GURL url = LoadHtml("host.com", "dummy"); 271 GURL url("http://host.com");
413 base::string16 page_text = ASCIIToUTF16("dummy"); 272 base::string16 page_text = ASCIIToUTF16("dummy");
273 LoadHTMLWithUrlOverride("dummy", url.spec().c_str());
414 OnStartPhishingDetection(url); 274 OnStartPhishingDetection(url);
415 PageCaptured(&page_text, false); 275 PageCaptured(&page_text, false, url);
416 276
417 url = LoadHtml("host2.com", "dummy2"); 277 GURL url2("http://host2.com");
418 page_text = ASCIIToUTF16("dummy2"); 278 page_text = ASCIIToUTF16("dummy");
419 OnStartPhishingDetection(url); 279 LoadHTMLWithUrlOverride("dummy", url2.spec().c_str());
420 PageCaptured(&page_text, false); 280 OnStartPhishingDetection(url2);
281 PageCaptured(&page_text, false, url2);
421 282
422 // Now set a scorer, which should cause a classifier to be created and 283 // Now set a scorer, which should cause a classifier to be created and
423 // the classification to proceed. 284 // the classification to proceed.
424 page_text = ASCIIToUTF16("dummy2"); 285 page_text = ASCIIToUTF16("dummy");
425 EXPECT_CALL(*classifier_, BeginClassification(Pointee(page_text), _)); 286 EXPECT_CALL(*classifier_, BeginClassification(Pointee(page_text), _));
426 MockScorer scorer; 287 MockScorer scorer;
427 delegate_->SetPhishingScorer(&scorer); 288 delegate_->SetPhishingScorer(&scorer);
428 Mock::VerifyAndClearExpectations(classifier_); 289 Mock::VerifyAndClearExpectations(classifier_);
429 290
430 // If we set a new scorer while a classification is going on the 291 // If we set a new scorer while a classification is going on the
431 // classification should be cancelled. 292 // classification should be cancelled.
432 EXPECT_CALL(*classifier_, CancelPendingClassification()); 293 EXPECT_CALL(*classifier_, CancelPendingClassification());
433 delegate_->SetPhishingScorer(&scorer); 294 delegate_->SetPhishingScorer(&scorer);
434 Mock::VerifyAndClearExpectations(classifier_); 295 Mock::VerifyAndClearExpectations(classifier_);
435 296
436 // The delegate will cancel pending classification on destruction. 297 // The delegate will cancel pending classification on destruction.
437 EXPECT_CALL(*classifier_, CancelPendingClassification()); 298 EXPECT_CALL(*classifier_, CancelPendingClassification());
438 } 299 }
439 300
440 // Flaky: crbug.com/435719 301 TEST_F(PhishingClassifierDelegateTest, NoScorer_Ref) {
441 #if defined(LEAK_SANITIZER)
442 #define MAYBE_NoScorer_Ref DISABLED_NoScorer_Ref
443 #else
444 #define MAYBE_NoScorer_Ref NoScorer_Ref
445 #endif
446
447 IN_PROC_BROWSER_TEST_F(PhishingClassifierDelegateTest, MAYBE_NoScorer_Ref) {
448 // Similar to the last test, but navigates within the page before 302 // Similar to the last test, but navigates within the page before
449 // setting the scorer. 303 // setting the scorer.
450 ASSERT_FALSE(classifier_->is_ready()); 304 ASSERT_FALSE(classifier_->is_ready());
451 305
452 // Queue up a pending classification, cancel it, then queue up another one. 306 // Queue up a pending classification, cancel it, then queue up another one.
453 GURL url = LoadHtml("host.com", "dummy"); 307 GURL url("http://host.com");
454 base::string16 page_text = ASCIIToUTF16("dummy"); 308 base::string16 page_text = ASCIIToUTF16("dummy");
309 LoadHTMLWithUrlOverride("dummy", url.spec().c_str());
455 OnStartPhishingDetection(url); 310 OnStartPhishingDetection(url);
456 PageCaptured(&page_text, false); 311 PageCaptured(&page_text, false, url);
457 312
313 page_text = ASCIIToUTF16("dummy");
458 OnStartPhishingDetection(url); 314 OnStartPhishingDetection(url);
459 page_text = ASCIIToUTF16("dummy"); 315 PageCaptured(&page_text, false, url);
460 PageCaptured(&page_text, false);
461 316
462 // Now set a scorer, which should cause a classifier to be created and 317 // Now set a scorer, which should cause a classifier to be created and
463 // the classification to proceed. 318 // the classification to proceed.
464 page_text = ASCIIToUTF16("dummy"); 319 page_text = ASCIIToUTF16("dummy");
465 EXPECT_CALL(*classifier_, BeginClassification(Pointee(page_text), _)); 320 EXPECT_CALL(*classifier_, BeginClassification(Pointee(page_text), _));
466 MockScorer scorer; 321 MockScorer scorer;
467 delegate_->SetPhishingScorer(&scorer); 322 delegate_->SetPhishingScorer(&scorer);
468 Mock::VerifyAndClearExpectations(classifier_); 323 Mock::VerifyAndClearExpectations(classifier_);
469 324
325 // If we set a new scorer while a classification is going on the
326 // classification should be cancelled.
327 EXPECT_CALL(*classifier_, CancelPendingClassification());
328 delegate_->SetPhishingScorer(&scorer);
329 Mock::VerifyAndClearExpectations(classifier_);
330
470 // The delegate will cancel pending classification on destruction. 331 // The delegate will cancel pending classification on destruction.
471 EXPECT_CALL(*classifier_, CancelPendingClassification()); 332 EXPECT_CALL(*classifier_, CancelPendingClassification());
472 } 333 }
473 334
474 IN_PROC_BROWSER_TEST_F(PhishingClassifierDelegateTest, 335 TEST_F(PhishingClassifierDelegateTest, NoStartPhishingDetection) {
475 NoStartPhishingDetection) {
476 // Tests the behavior when OnStartPhishingDetection has not yet been called 336 // Tests the behavior when OnStartPhishingDetection has not yet been called
477 // when the page load finishes. 337 // when the page load finishes.
478 MockScorer scorer; 338 MockScorer scorer;
479 delegate_->SetPhishingScorer(&scorer); 339 delegate_->SetPhishingScorer(&scorer);
480 ASSERT_TRUE(classifier_->is_ready()); 340 ASSERT_TRUE(classifier_->is_ready());
481 341
482 EXPECT_CALL(*classifier_, CancelPendingClassification()); 342 EXPECT_CALL(*classifier_, CancelPendingClassification());
483 GURL url = LoadHtml("host.com", "<html><body>phish</body></html>"); 343 GURL url("http://host.com");
344 LoadHTMLWithUrlOverride("<html><body>phish</body></html>",
345 url.spec().c_str());
484 Mock::VerifyAndClearExpectations(classifier_); 346 Mock::VerifyAndClearExpectations(classifier_);
485 base::string16 page_text = ASCIIToUTF16("phish"); 347 base::string16 page_text = ASCIIToUTF16("phish");
486 EXPECT_CALL(*classifier_, CancelPendingClassification()); 348 EXPECT_CALL(*classifier_, CancelPendingClassification());
487 PageCaptured(&page_text, false); 349 PageCaptured(&page_text, false, url);
488 Mock::VerifyAndClearExpectations(classifier_); 350 Mock::VerifyAndClearExpectations(classifier_);
489 // Now simulate the StartPhishingDetection IPC. We expect classification 351 // Now simulate the StartPhishingDetection IPC. We expect classification
490 // to begin. 352 // to begin.
491 page_text = ASCIIToUTF16("phish"); 353 page_text = ASCIIToUTF16("phish");
492 EXPECT_CALL(*classifier_, BeginClassification(Pointee(page_text), _)); 354 EXPECT_CALL(*classifier_, BeginClassification(Pointee(page_text), _));
493 OnStartPhishingDetection(url); 355 OnStartPhishingDetection(url);
494 Mock::VerifyAndClearExpectations(classifier_); 356 Mock::VerifyAndClearExpectations(classifier_);
495 357
496 // Now try again, but this time we will navigate the page away before 358 // Now try again, but this time we will navigate the page away before
497 // the IPC is sent. 359 // the IPC is sent.
498 EXPECT_CALL(*classifier_, CancelPendingClassification()); 360 EXPECT_CALL(*classifier_, CancelPendingClassification());
499 LoadHtml("host2.com", "<html><body>phish</body></html>"); 361 GURL url2("http://host2.com");
362 LoadHTMLWithUrlOverride("<html><body>phish</body></html>",
363 url2.spec().c_str());
500 Mock::VerifyAndClearExpectations(classifier_); 364 Mock::VerifyAndClearExpectations(classifier_);
501 page_text = ASCIIToUTF16("phish"); 365 page_text = ASCIIToUTF16("phish");
502 EXPECT_CALL(*classifier_, CancelPendingClassification()); 366 EXPECT_CALL(*classifier_, CancelPendingClassification());
503 PageCaptured(&page_text, false); 367 PageCaptured(&page_text, false, url2);
504 Mock::VerifyAndClearExpectations(classifier_); 368 Mock::VerifyAndClearExpectations(classifier_);
505 369
506 EXPECT_CALL(*classifier_, CancelPendingClassification()); 370 EXPECT_CALL(*classifier_, CancelPendingClassification());
507 LoadHtml("host3.com", "<html><body>phish</body></html>"); 371 GURL url3("http://host3.com");
372 LoadHTMLWithUrlOverride("<html><body>phish</body></html>",
373 url3.spec().c_str());
508 Mock::VerifyAndClearExpectations(classifier_); 374 Mock::VerifyAndClearExpectations(classifier_);
509 OnStartPhishingDetection(url); 375 OnStartPhishingDetection(url);
510 376
511 // In this test, the original page is a redirect, which we do not get a 377 // In this test, the original page is a redirect, which we do not get a
512 // StartPhishingDetection IPC for. We use location.replace() to load a 378 // StartPhishingDetection IPC for. We simulate the redirection event to
513 // new page while reusing the original session history entry, and check that 379 // load a new page while reusing the original session history entry, and
514 // classification begins correctly for the landing page. 380 // check that classification begins correctly for the landing page.
515 EXPECT_CALL(*classifier_, CancelPendingClassification()); 381 EXPECT_CALL(*classifier_, CancelPendingClassification());
516 LoadHtml("host4.com", "<html><body>abc</body></html>"); 382 GURL url4("http://host4.com");
383 LoadHTMLWithUrlOverride("<html><body>phish</body></html>",
384 url4.spec().c_str());
517 Mock::VerifyAndClearExpectations(classifier_); 385 Mock::VerifyAndClearExpectations(classifier_);
518 page_text = ASCIIToUTF16("abc"); 386 page_text = ASCIIToUTF16("abc");
519 EXPECT_CALL(*classifier_, CancelPendingClassification()); 387 EXPECT_CALL(*classifier_, CancelPendingClassification());
520 PageCaptured(&page_text, false); 388 PageCaptured(&page_text, false, url4);
521 Mock::VerifyAndClearExpectations(classifier_); 389 Mock::VerifyAndClearExpectations(classifier_);
522 EXPECT_CALL(*classifier_, CancelPendingClassification()); 390 EXPECT_CALL(*classifier_, CancelPendingClassification());
523 391
524 ui_test_utils::NavigateToURL( 392 GURL redir_url("http://host4.com/redir");
525 browser(), GURL("javascript:location.replace(\'redir\');")); 393 LoadHTMLWithUrlOverride("123", redir_url.spec().c_str());
526
527 Mock::VerifyAndClearExpectations(classifier_); 394 Mock::VerifyAndClearExpectations(classifier_);
528 395 OnStartPhishingDetection(url4);
529 GURL redir_url = embedded_test_server()->GetURL("/redir");
530 GURL::Replacements replace_host;
531 replace_host.SetHostStr("host4.com");
532 OnStartPhishingDetection(redir_url.ReplaceComponents(replace_host));
533 page_text = ASCIIToUTF16("123"); 396 page_text = ASCIIToUTF16("123");
534 { 397 {
535 InSequence s; 398 InSequence s;
536 EXPECT_CALL(*classifier_, CancelPendingClassification()); 399 EXPECT_CALL(*classifier_, CancelPendingClassification());
537 EXPECT_CALL(*classifier_, BeginClassification(Pointee(page_text), _)); 400 EXPECT_CALL(*classifier_, BeginClassification(Pointee(page_text), _));
538 PageCaptured(&page_text, false); 401 SimulateRedirection(redir_url);
402 PageCaptured(&page_text, false, redir_url);
539 Mock::VerifyAndClearExpectations(classifier_); 403 Mock::VerifyAndClearExpectations(classifier_);
540 } 404 }
541 405
542 // The delegate will cancel pending classification on destruction. 406 // The delegate will cancel pending classification on destruction.
543 EXPECT_CALL(*classifier_, CancelPendingClassification()); 407 EXPECT_CALL(*classifier_, CancelPendingClassification());
544 } 408 }
545 409
546 // Test flakes with LSAN enabled. See http://crbug.com/373155. 410 TEST_F(PhishingClassifierDelegateTest, IgnorePreliminaryCapture) {
547 #if defined(LEAK_SANITIZER)
548 #define MAYBE_IgnorePreliminaryCapture DISABLED_IgnorePreliminaryCapture
549 #else
550 #define MAYBE_IgnorePreliminaryCapture IgnorePreliminaryCapture
551 #endif
552 IN_PROC_BROWSER_TEST_F(PhishingClassifierDelegateTest,
553 MAYBE_IgnorePreliminaryCapture) {
554 // Tests that preliminary PageCaptured notifications are ignored. 411 // Tests that preliminary PageCaptured notifications are ignored.
555 MockScorer scorer; 412 MockScorer scorer;
556 delegate_->SetPhishingScorer(&scorer); 413 delegate_->SetPhishingScorer(&scorer);
557 ASSERT_TRUE(classifier_->is_ready()); 414 ASSERT_TRUE(classifier_->is_ready());
558 415
559 EXPECT_CALL(*classifier_, CancelPendingClassification()); 416 EXPECT_CALL(*classifier_, CancelPendingClassification());
560 GURL url = LoadHtml("host.com", "<html><body>phish</body></html>"); 417 GURL url("http://host.com");
418 LoadHTMLWithUrlOverride("<html><body>phish</body></html>",
419 url.spec().c_str());
561 Mock::VerifyAndClearExpectations(classifier_); 420 Mock::VerifyAndClearExpectations(classifier_);
562 OnStartPhishingDetection(url); 421 OnStartPhishingDetection(url);
563 base::string16 page_text = ASCIIToUTF16("phish"); 422 base::string16 page_text = ASCIIToUTF16("phish");
564 PageCaptured(&page_text, true); 423 PageCaptured(&page_text, true, url);
565 424
566 // Once the non-preliminary capture happens, classification should begin. 425 // Once the non-preliminary capture happens, classification should begin.
567 page_text = ASCIIToUTF16("phish"); 426 page_text = ASCIIToUTF16("phish");
568 { 427 {
569 InSequence s; 428 InSequence s;
570 EXPECT_CALL(*classifier_, CancelPendingClassification()); 429 EXPECT_CALL(*classifier_, CancelPendingClassification());
571 EXPECT_CALL(*classifier_, BeginClassification(Pointee(page_text), _)); 430 EXPECT_CALL(*classifier_, BeginClassification(Pointee(page_text), _));
572 PageCaptured(&page_text, false); 431 PageCaptured(&page_text, false, url);
573 Mock::VerifyAndClearExpectations(classifier_); 432 Mock::VerifyAndClearExpectations(classifier_);
574 } 433 }
575 434
576 // The delegate will cancel pending classification on destruction. 435 // The delegate will cancel pending classification on destruction.
577 EXPECT_CALL(*classifier_, CancelPendingClassification()); 436 EXPECT_CALL(*classifier_, CancelPendingClassification());
578 } 437 }
579 438
580 #if defined(ADDRESS_SANITIZER) 439 TEST_F(PhishingClassifierDelegateTest, DuplicatePageCapture) {
581 #define Maybe_DuplicatePageCapture DISABLED_DuplicatePageCapture
582 #else
583 #define Maybe_DuplicatePageCapture DuplicatePageCapture
584 #endif
585 IN_PROC_BROWSER_TEST_F(PhishingClassifierDelegateTest,
586 Maybe_DuplicatePageCapture) {
587 // Tests that a second PageCaptured notification causes classification to 440 // Tests that a second PageCaptured notification causes classification to
588 // be cancelled. 441 // be cancelled.
589 MockScorer scorer; 442 MockScorer scorer;
590 delegate_->SetPhishingScorer(&scorer); 443 delegate_->SetPhishingScorer(&scorer);
591 ASSERT_TRUE(classifier_->is_ready()); 444 ASSERT_TRUE(classifier_->is_ready());
592 445
593 EXPECT_CALL(*classifier_, CancelPendingClassification()); 446 EXPECT_CALL(*classifier_, CancelPendingClassification());
594 GURL url = LoadHtml("host.com", "<html><body>phish</body></html>"); 447 GURL url("http://host.com");
448 LoadHTMLWithUrlOverride("<html><body>phish</body></html>",
449 url.spec().c_str());
595 Mock::VerifyAndClearExpectations(classifier_); 450 Mock::VerifyAndClearExpectations(classifier_);
596 OnStartPhishingDetection(url); 451 OnStartPhishingDetection(url);
597 base::string16 page_text = ASCIIToUTF16("phish"); 452 base::string16 page_text = ASCIIToUTF16("phish");
598 { 453 {
599 InSequence s; 454 InSequence s;
600 EXPECT_CALL(*classifier_, CancelPendingClassification()); 455 EXPECT_CALL(*classifier_, CancelPendingClassification());
601 EXPECT_CALL(*classifier_, BeginClassification(Pointee(page_text), _)); 456 EXPECT_CALL(*classifier_, BeginClassification(Pointee(page_text), _));
602 PageCaptured(&page_text, false); 457 PageCaptured(&page_text, false, url);
603 Mock::VerifyAndClearExpectations(classifier_); 458 Mock::VerifyAndClearExpectations(classifier_);
604 } 459 }
605 460
606 page_text = ASCIIToUTF16("phish"); 461 page_text = ASCIIToUTF16("phish");
607 EXPECT_CALL(*classifier_, CancelPendingClassification()); 462 EXPECT_CALL(*classifier_, CancelPendingClassification());
608 PageCaptured(&page_text, false); 463 PageCaptured(&page_text, false, url);
609 Mock::VerifyAndClearExpectations(classifier_); 464 Mock::VerifyAndClearExpectations(classifier_);
610 465
611 // The delegate will cancel pending classification on destruction. 466 // The delegate will cancel pending classification on destruction.
612 EXPECT_CALL(*classifier_, CancelPendingClassification()); 467 EXPECT_CALL(*classifier_, CancelPendingClassification());
613 } 468 }
614 469
615 // Test flakes with LSAN enabled. See http://crbug.com/373155. 470 TEST_F(PhishingClassifierDelegateTest, PhishingDetectionDone) {
616 #if defined(LEAK_SANITIZER) 471 // Tests that a SafeBrowsingHostMsg_PhishingDetectionDone IPC is
617 #define MAYBE_PhishingDetectionDone DISABLED_PhishingDetectionDone 472 // sent to the browser whenever we finish classification.
618 #else
619 #define MAYBE_PhishingDetectionDone PhishingDetectionDone
620 #endif
621 IN_PROC_BROWSER_TEST_F(PhishingClassifierDelegateTest,
622 MAYBE_PhishingDetectionDone) {
623 // Tests that a PhishingDetectionDone IPC is sent to the browser
624 // whenever we finish classification.
625 MockScorer scorer; 473 MockScorer scorer;
626 delegate_->SetPhishingScorer(&scorer); 474 delegate_->SetPhishingScorer(&scorer);
627 ASSERT_TRUE(classifier_->is_ready()); 475 ASSERT_TRUE(classifier_->is_ready());
628 476
629 // Start by loading a page to populate the delegate's state. 477 // Start by loading a page to populate the delegate's state.
630 EXPECT_CALL(*classifier_, CancelPendingClassification()); 478 EXPECT_CALL(*classifier_, CancelPendingClassification());
631 GURL url = LoadHtml("host.com", "<html><body>phish</body></html>"); 479 GURL url("http://host.com");
480 LoadHTMLWithUrlOverride("<html><body>phish</body></html>",
481 url.spec().c_str());
632 Mock::VerifyAndClearExpectations(classifier_); 482 Mock::VerifyAndClearExpectations(classifier_);
633 base::string16 page_text = ASCIIToUTF16("phish"); 483 base::string16 page_text = ASCIIToUTF16("phish");
634 OnStartPhishingDetection(url); 484 OnStartPhishingDetection(url);
635 { 485 {
636 InSequence s; 486 InSequence s;
637 EXPECT_CALL(*classifier_, CancelPendingClassification()); 487 EXPECT_CALL(*classifier_, CancelPendingClassification());
638 EXPECT_CALL(*classifier_, BeginClassification(Pointee(page_text), _)); 488 EXPECT_CALL(*classifier_, BeginClassification(Pointee(page_text), _));
639 PageCaptured(&page_text, false); 489 PageCaptured(&page_text, false, url);
640 Mock::VerifyAndClearExpectations(classifier_); 490 Mock::VerifyAndClearExpectations(classifier_);
641 } 491 }
642 492
643 // Now run the callback to simulate the classifier finishing. 493 // Now run the callback to simulate the classifier finishing.
644 ClientPhishingRequest verdict; 494 ClientPhishingRequest verdict;
645 verdict.set_url(url.spec()); 495 verdict.set_url(url.spec());
646 verdict.set_client_score(0.8f); 496 verdict.set_client_score(0.8f);
647 verdict.set_is_phishing(false); // Send IPC even if site is not phishing. 497 verdict.set_is_phishing(false); // Send IPC even if site is not phishing.
648 RunClassificationDone(verdict); 498 RunAndVerifyClassificationDone(verdict);
649 ASSERT_TRUE(intercepting_filter_->verdict());
650 EXPECT_EQ(verdict.SerializeAsString(),
651 intercepting_filter_->verdict()->SerializeAsString());
652 499
653 // The delegate will cancel pending classification on destruction. 500 // The delegate will cancel pending classification on destruction.
654 EXPECT_CALL(*classifier_, CancelPendingClassification()); 501 EXPECT_CALL(*classifier_, CancelPendingClassification());
655 } 502 }
656 503
657 } // namespace safe_browsing 504 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « no previous file | chrome/renderer/safe_browsing/threat_dom_details.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698