Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/file_path.h" | 5 #include "base/file_path.h" |
| 6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/task.h" | 8 #include "base/task.h" |
| 9 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" | 9 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" |
| 10 #include "chrome/browser/safe_browsing/client_side_detection_host.h" | 10 #include "chrome/browser/safe_browsing/client_side_detection_host.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 #include "content/browser/tab_contents/test_tab_contents.h" | 22 #include "content/browser/tab_contents/test_tab_contents.h" |
| 23 #include "googleurl/src/gurl.h" | 23 #include "googleurl/src/gurl.h" |
| 24 #include "ipc/ipc_test_sink.h" | 24 #include "ipc/ipc_test_sink.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 27 |
| 28 using ::testing::_; | 28 using ::testing::_; |
| 29 using ::testing::DeleteArg; | 29 using ::testing::DeleteArg; |
| 30 using ::testing::DoAll; | 30 using ::testing::DoAll; |
| 31 using ::testing::Eq; | 31 using ::testing::Eq; |
| 32 using ::testing::IsNull; | |
| 32 using ::testing::Mock; | 33 using ::testing::Mock; |
| 33 using ::testing::NiceMock; | 34 using ::testing::NiceMock; |
| 34 using ::testing::NotNull; | 35 using ::testing::NotNull; |
| 35 using ::testing::Pointee; | 36 using ::testing::Pointee; |
| 36 using ::testing::Return; | 37 using ::testing::Return; |
| 37 using ::testing::SaveArg; | 38 using ::testing::SaveArg; |
| 38 using ::testing::SetArgumentPointee; | 39 using ::testing::SetArgumentPointee; |
| 39 using ::testing::StrictMock; | 40 using ::testing::StrictMock; |
| 40 | 41 |
| 41 namespace { | 42 namespace { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 csd_host_->set_client_side_detection_service(csd_service_.get()); | 155 csd_host_->set_client_side_detection_service(csd_service_.get()); |
| 155 csd_host_->set_safe_browsing_service(sb_service_.get()); | 156 csd_host_->set_safe_browsing_service(sb_service_.get()); |
| 156 } | 157 } |
| 157 | 158 |
| 158 virtual void TearDown() { | 159 virtual void TearDown() { |
| 159 TabContentsWrapperTestHarness::TearDown(); | 160 TabContentsWrapperTestHarness::TearDown(); |
| 160 io_thread_.reset(); | 161 io_thread_.reset(); |
| 161 ui_thread_.reset(); | 162 ui_thread_.reset(); |
| 162 } | 163 } |
| 163 | 164 |
| 164 void OnDetectedPhishingSite(const std::string& verdict_str) { | 165 void OnPhishingDetectionDone(const std::string& verdict_str) { |
| 165 // Make sure we have a valid BrowseInfo object set before we call this | 166 // Make sure we have a valid BrowseInfo object set before we call this |
| 166 // method. | 167 // method. |
| 167 csd_host_->browse_info_.reset(new BrowseInfo); | 168 csd_host_->browse_info_.reset(new BrowseInfo); |
| 168 csd_host_->OnDetectedPhishingSite(verdict_str); | 169 csd_host_->OnPhishingDetectionDone(verdict_str); |
| 169 } | 170 } |
| 170 | 171 |
| 171 void FlushIOMessageLoop() { | 172 void FlushIOMessageLoop() { |
| 172 // If there was a message posted on the IO thread to display the | 173 // If there was a message posted on the IO thread to display the |
| 173 // interstitial page we know that it would have been posted before | 174 // interstitial page we know that it would have been posted before |
| 174 // we put the quit message there. | 175 // we put the quit message there. |
| 175 BrowserThread::PostTask(BrowserThread::IO, | 176 BrowserThread::PostTask(BrowserThread::IO, |
| 176 FROM_HERE, | 177 FROM_HERE, |
| 177 NewRunnableFunction(&QuitUIMessageLoopFromIO)); | 178 NewRunnableFunction(&QuitUIMessageLoopFromIO)); |
| 178 MessageLoop::current()->Run(); | 179 MessageLoop::current()->Run(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 MessageLoop::current()->RunAllPending(); | 219 MessageLoop::current()->RunAllPending(); |
| 219 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 220 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
| 220 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); | 221 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); |
| 221 EXPECT_TRUE(Mock::VerifyAndClear(mock_profile_)); | 222 EXPECT_TRUE(Mock::VerifyAndClear(mock_profile_)); |
| 222 } | 223 } |
| 223 | 224 |
| 224 void SetFeatureExtractor(BrowserFeatureExtractor* extractor) { | 225 void SetFeatureExtractor(BrowserFeatureExtractor* extractor) { |
| 225 csd_host_->feature_extractor_.reset(extractor); | 226 csd_host_->feature_extractor_.reset(extractor); |
| 226 } | 227 } |
| 227 | 228 |
| 229 void SetUnsafeUniquePageIdToCurrent() { | |
| 230 csd_host_->unsafe_unique_page_id_ = | |
| 231 contents()->controller().GetActiveEntry()->unique_id(); | |
| 232 ASSERT_TRUE(csd_host_->DidShowSBInterstitial()); | |
| 233 } | |
| 234 | |
| 228 protected: | 235 protected: |
| 229 scoped_ptr<ClientSideDetectionHost> csd_host_; | 236 scoped_ptr<ClientSideDetectionHost> csd_host_; |
| 230 scoped_ptr<StrictMock<MockClientSideDetectionService> > csd_service_; | 237 scoped_ptr<StrictMock<MockClientSideDetectionService> > csd_service_; |
| 231 scoped_refptr<StrictMock<MockSafeBrowsingService> > sb_service_; | 238 scoped_refptr<StrictMock<MockSafeBrowsingService> > sb_service_; |
| 232 MockTestingProfile* mock_profile_; // We don't own this object | 239 MockTestingProfile* mock_profile_; // We don't own this object |
| 233 | 240 |
| 234 private: | 241 private: |
| 235 scoped_ptr<BrowserThread> ui_thread_; | 242 scoped_ptr<BrowserThread> ui_thread_; |
| 236 scoped_ptr<BrowserThread> io_thread_; | 243 scoped_ptr<BrowserThread> io_thread_; |
| 237 }; | 244 }; |
| 238 | 245 |
| 239 TEST_F(ClientSideDetectionHostTest, OnDetectedPhishingSiteInvalidVerdict) { | 246 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneInvalidVerdict) { |
| 240 // Case 0: renderer sends an invalid verdict string that we're unable to | 247 // Case 0: renderer sends an invalid verdict string that we're unable to |
| 241 // parse. | 248 // parse. |
| 242 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 249 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( |
| 243 contents(), | 250 contents(), |
| 244 csd_service_.get()); | 251 csd_service_.get()); |
| 245 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 252 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
| 246 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0); | 253 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0); |
| 247 OnDetectedPhishingSite("Invalid Protocol Buffer"); | 254 OnPhishingDetectionDone("Invalid Protocol Buffer"); |
| 248 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); | 255 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); |
| 249 } | 256 } |
| 250 | 257 |
| 251 TEST_F(ClientSideDetectionHostTest, OnDetectedPhishingSiteNotPhishing) { | 258 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneNotPhishing) { |
| 252 // Case 1: client thinks the page is phishing. The server does not agree. | 259 // Case 1: client thinks the page is phishing. The server does not agree. |
| 253 // No interstitial is shown. | 260 // No interstitial is shown. |
| 254 ClientSideDetectionService::ClientReportPhishingRequestCallback* cb; | 261 ClientSideDetectionService::ClientReportPhishingRequestCallback* cb; |
| 255 ClientPhishingRequest verdict; | 262 ClientPhishingRequest verdict; |
| 256 verdict.set_url("http://phishingurl.com/"); | 263 verdict.set_url("http://phishingurl.com/"); |
| 257 verdict.set_client_score(1.0f); | 264 verdict.set_client_score(1.0f); |
| 258 verdict.set_is_phishing(true); | 265 verdict.set_is_phishing(true); |
| 259 | 266 |
| 260 EXPECT_CALL(*csd_service_, | 267 EXPECT_CALL(*csd_service_, |
| 261 SendClientReportPhishingRequest( | 268 SendClientReportPhishingRequest( |
| 262 Pointee(PartiallyEqualVerdict(verdict)), _)) | 269 Pointee(PartiallyEqualVerdict(verdict)), _)) |
| 263 .WillOnce(DoAll(DeleteArg<0>(), SaveArg<1>(&cb), QuitUIMessageLoop())); | 270 .WillOnce(DoAll(DeleteArg<0>(), SaveArg<1>(&cb), QuitUIMessageLoop())); |
| 264 OnDetectedPhishingSite(verdict.SerializeAsString()); | 271 OnPhishingDetectionDone(verdict.SerializeAsString()); |
| 265 MessageLoop::current()->Run(); | 272 MessageLoop::current()->Run(); |
| 266 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 273 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
| 267 ASSERT_TRUE(cb); | 274 ASSERT_TRUE(cb); |
| 268 | 275 |
| 269 // Make sure DoDisplayBlockingPage is not going to be called. | 276 // Make sure DoDisplayBlockingPage is not going to be called. |
| 270 EXPECT_CALL(*sb_service_, DoDisplayBlockingPage(_)).Times(0); | 277 EXPECT_CALL(*sb_service_, DoDisplayBlockingPage(_)).Times(0); |
| 271 cb->Run(GURL(verdict.url()), false); | 278 cb->Run(GURL(verdict.url()), false); |
| 272 delete cb; | 279 delete cb; |
| 273 MessageLoop::current()->RunAllPending(); | 280 MessageLoop::current()->RunAllPending(); |
| 274 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); | 281 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); |
| 275 } | 282 } |
| 276 | 283 |
| 277 TEST_F(ClientSideDetectionHostTest, OnDetectedPhishingSiteDisabled) { | 284 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneDisabled) { |
| 278 // Case 2: client thinks the page is phishing and so does the server but | 285 // Case 2: client thinks the page is phishing and so does the server but |
| 279 // showing the interstitial is disabled => no interstitial is shown. | 286 // showing the interstitial is disabled => no interstitial is shown. |
| 280 ClientSideDetectionService::ClientReportPhishingRequestCallback* cb; | 287 ClientSideDetectionService::ClientReportPhishingRequestCallback* cb; |
| 281 ClientPhishingRequest verdict; | 288 ClientPhishingRequest verdict; |
| 282 verdict.set_url("http://phishingurl.com/"); | 289 verdict.set_url("http://phishingurl.com/"); |
| 283 verdict.set_client_score(1.0f); | 290 verdict.set_client_score(1.0f); |
| 284 verdict.set_is_phishing(true); | 291 verdict.set_is_phishing(true); |
| 285 | 292 |
| 286 EXPECT_CALL(*csd_service_, | 293 EXPECT_CALL(*csd_service_, |
| 287 SendClientReportPhishingRequest( | 294 SendClientReportPhishingRequest( |
| 288 Pointee(PartiallyEqualVerdict(verdict)), _)) | 295 Pointee(PartiallyEqualVerdict(verdict)), _)) |
| 289 .WillOnce(DoAll(DeleteArg<0>(), SaveArg<1>(&cb), QuitUIMessageLoop())); | 296 .WillOnce(DoAll(DeleteArg<0>(), SaveArg<1>(&cb), QuitUIMessageLoop())); |
| 290 OnDetectedPhishingSite(verdict.SerializeAsString()); | 297 OnPhishingDetectionDone(verdict.SerializeAsString()); |
| 291 MessageLoop::current()->Run(); | 298 MessageLoop::current()->Run(); |
| 292 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 299 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
| 293 ASSERT_TRUE(cb); | 300 ASSERT_TRUE(cb); |
| 294 | 301 |
| 295 // Make sure DoDisplayBlockingPage is not going to be called. | 302 // Make sure DoDisplayBlockingPage is not going to be called. |
| 296 EXPECT_CALL(*sb_service_, DoDisplayBlockingPage(_)).Times(0); | 303 EXPECT_CALL(*sb_service_, DoDisplayBlockingPage(_)).Times(0); |
| 297 cb->Run(GURL(verdict.url()), false); | 304 cb->Run(GURL(verdict.url()), false); |
| 298 delete cb; | 305 delete cb; |
| 299 MessageLoop::current()->RunAllPending(); | 306 MessageLoop::current()->RunAllPending(); |
| 300 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); | 307 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); |
| 301 } | 308 } |
| 302 | 309 |
| 303 TEST_F(ClientSideDetectionHostTest, OnDetectedPhishingSiteShowInterstitial) { | 310 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneShowInterstitial) { |
| 304 // Case 3: client thinks the page is phishing and so does the server. | 311 // Case 3: client thinks the page is phishing and so does the server. |
| 305 // We show an interstitial. | 312 // We show an interstitial. |
| 306 ClientSideDetectionService::ClientReportPhishingRequestCallback* cb; | 313 ClientSideDetectionService::ClientReportPhishingRequestCallback* cb; |
| 307 GURL phishing_url("http://phishingurl.com/"); | 314 GURL phishing_url("http://phishingurl.com/"); |
| 308 ClientPhishingRequest verdict; | 315 ClientPhishingRequest verdict; |
| 309 verdict.set_url(phishing_url.spec()); | 316 verdict.set_url(phishing_url.spec()); |
| 310 verdict.set_client_score(1.0f); | 317 verdict.set_client_score(1.0f); |
| 311 verdict.set_is_phishing(true); | 318 verdict.set_is_phishing(true); |
| 312 | 319 |
| 313 EXPECT_CALL(*csd_service_, | 320 EXPECT_CALL(*csd_service_, |
| 314 SendClientReportPhishingRequest( | 321 SendClientReportPhishingRequest( |
| 315 Pointee(PartiallyEqualVerdict(verdict)), _)) | 322 Pointee(PartiallyEqualVerdict(verdict)), _)) |
| 316 .WillOnce(DoAll(DeleteArg<0>(), SaveArg<1>(&cb), QuitUIMessageLoop())); | 323 .WillOnce(DoAll(DeleteArg<0>(), SaveArg<1>(&cb), QuitUIMessageLoop())); |
| 317 OnDetectedPhishingSite(verdict.SerializeAsString()); | 324 OnPhishingDetectionDone(verdict.SerializeAsString()); |
| 318 MessageLoop::current()->Run(); | 325 MessageLoop::current()->Run(); |
| 319 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 326 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
| 320 ASSERT_TRUE(cb); | 327 ASSERT_TRUE(cb); |
| 321 | 328 |
| 322 SafeBrowsingService::UnsafeResource resource; | 329 SafeBrowsingService::UnsafeResource resource; |
| 323 EXPECT_CALL(*sb_service_, DoDisplayBlockingPage(_)) | 330 EXPECT_CALL(*sb_service_, DoDisplayBlockingPage(_)) |
| 324 .WillOnce(SaveArg<0>(&resource)); | 331 .WillOnce(SaveArg<0>(&resource)); |
| 325 cb->Run(phishing_url, true); | 332 cb->Run(phishing_url, true); |
| 326 delete cb; | 333 delete cb; |
| 327 | 334 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 344 NewRunnableMethod( | 351 NewRunnableMethod( |
| 345 sb_service_.get(), | 352 sb_service_.get(), |
| 346 &MockSafeBrowsingService::InvokeOnBlockingPageComplete, | 353 &MockSafeBrowsingService::InvokeOnBlockingPageComplete, |
| 347 resource.client)); | 354 resource.client)); |
| 348 // Since the CsdClient object will be deleted on the UI thread I need | 355 // Since the CsdClient object will be deleted on the UI thread I need |
| 349 // to run the UI message loop. Post a task to stop the UI message loop | 356 // to run the UI message loop. Post a task to stop the UI message loop |
| 350 // after the client object destructor is called. | 357 // after the client object destructor is called. |
| 351 FlushIOMessageLoop(); | 358 FlushIOMessageLoop(); |
| 352 } | 359 } |
| 353 | 360 |
| 354 TEST_F(ClientSideDetectionHostTest, OnDetectedPhishingSiteMultiplePings) { | 361 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneMultiplePings) { |
| 355 // Case 4 & 5: client thinks a page is phishing then navigates to | 362 // Case 4 & 5: client thinks a page is phishing then navigates to |
| 356 // another page which is also considered phishing by the client | 363 // another page which is also considered phishing by the client |
| 357 // before the server responds with a verdict. After a while the | 364 // before the server responds with a verdict. After a while the |
| 358 // server responds for both requests with a phishing verdict. Only | 365 // server responds for both requests with a phishing verdict. Only |
| 359 // a single interstitial is shown for the second URL. | 366 // a single interstitial is shown for the second URL. |
| 360 ClientSideDetectionService::ClientReportPhishingRequestCallback* cb; | 367 ClientSideDetectionService::ClientReportPhishingRequestCallback* cb; |
| 361 GURL phishing_url("http://phishingurl.com/"); | 368 GURL phishing_url("http://phishingurl.com/"); |
| 362 ClientPhishingRequest verdict; | 369 ClientPhishingRequest verdict; |
| 363 verdict.set_url(phishing_url.spec()); | 370 verdict.set_url(phishing_url.spec()); |
| 364 verdict.set_client_score(1.0f); | 371 verdict.set_client_score(1.0f); |
| 365 verdict.set_is_phishing(true); | 372 verdict.set_is_phishing(true); |
| 366 | 373 |
| 367 EXPECT_CALL(*csd_service_, | 374 EXPECT_CALL(*csd_service_, |
| 368 SendClientReportPhishingRequest( | 375 SendClientReportPhishingRequest( |
| 369 Pointee(PartiallyEqualVerdict(verdict)), _)) | 376 Pointee(PartiallyEqualVerdict(verdict)), _)) |
| 370 .WillOnce(DoAll(DeleteArg<0>(), SaveArg<1>(&cb), QuitUIMessageLoop())); | 377 .WillOnce(DoAll(DeleteArg<0>(), SaveArg<1>(&cb), QuitUIMessageLoop())); |
| 371 OnDetectedPhishingSite(verdict.SerializeAsString()); | 378 OnPhishingDetectionDone(verdict.SerializeAsString()); |
| 372 MessageLoop::current()->Run(); | 379 MessageLoop::current()->Run(); |
| 373 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 380 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
| 374 ASSERT_TRUE(cb); | 381 ASSERT_TRUE(cb); |
| 375 GURL other_phishing_url("http://other_phishing_url.com/bla"); | 382 GURL other_phishing_url("http://other_phishing_url.com/bla"); |
| 376 ExpectPreClassificationChecks(other_phishing_url, &kFalse, &kFalse, &kFalse, | 383 ExpectPreClassificationChecks(other_phishing_url, &kFalse, &kFalse, &kFalse, |
| 377 &kFalse, &kFalse, &kFalse); | 384 &kFalse, &kFalse, &kFalse); |
| 378 // We navigate away. The callback cb should be revoked. | 385 // We navigate away. The callback cb should be revoked. |
| 379 NavigateAndCommit(other_phishing_url); | 386 NavigateAndCommit(other_phishing_url); |
| 380 // Wait for the pre-classification checks to finish for other_phishing_url. | 387 // Wait for the pre-classification checks to finish for other_phishing_url. |
| 381 WaitAndCheckPreClassificationChecks(); | 388 WaitAndCheckPreClassificationChecks(); |
| 382 | 389 |
| 383 ClientSideDetectionService::ClientReportPhishingRequestCallback* cb_other; | 390 ClientSideDetectionService::ClientReportPhishingRequestCallback* cb_other; |
| 384 verdict.set_url(other_phishing_url.spec()); | 391 verdict.set_url(other_phishing_url.spec()); |
| 385 verdict.set_client_score(0.8f); | 392 verdict.set_client_score(0.8f); |
| 386 EXPECT_CALL(*csd_service_, | 393 EXPECT_CALL(*csd_service_, |
| 387 SendClientReportPhishingRequest( | 394 SendClientReportPhishingRequest( |
| 388 Pointee(PartiallyEqualVerdict(verdict)), _)) | 395 Pointee(PartiallyEqualVerdict(verdict)), _)) |
| 389 .WillOnce(DoAll(DeleteArg<0>(), | 396 .WillOnce(DoAll(DeleteArg<0>(), |
| 390 SaveArg<1>(&cb_other), | 397 SaveArg<1>(&cb_other), |
| 391 QuitUIMessageLoop())); | 398 QuitUIMessageLoop())); |
| 392 OnDetectedPhishingSite(verdict.SerializeAsString()); | 399 OnPhishingDetectionDone(verdict.SerializeAsString()); |
| 393 MessageLoop::current()->Run(); | 400 MessageLoop::current()->Run(); |
| 394 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 401 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
| 395 ASSERT_TRUE(cb_other); | 402 ASSERT_TRUE(cb_other); |
| 396 | 403 |
| 397 // We expect that the interstitial is shown for the second phishing URL and | 404 // We expect that the interstitial is shown for the second phishing URL and |
| 398 // not for the first phishing URL. | 405 // not for the first phishing URL. |
| 399 SafeBrowsingService::UnsafeResource resource; | 406 SafeBrowsingService::UnsafeResource resource; |
| 400 EXPECT_CALL(*sb_service_, DoDisplayBlockingPage(_)) | 407 EXPECT_CALL(*sb_service_, DoDisplayBlockingPage(_)) |
| 401 .WillOnce(SaveArg<0>(&resource)); | 408 .WillOnce(SaveArg<0>(&resource)); |
| 402 | 409 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 424 NewRunnableMethod( | 431 NewRunnableMethod( |
| 425 sb_service_.get(), | 432 sb_service_.get(), |
| 426 &MockSafeBrowsingService::InvokeOnBlockingPageComplete, | 433 &MockSafeBrowsingService::InvokeOnBlockingPageComplete, |
| 427 resource.client)); | 434 resource.client)); |
| 428 // Since the CsdClient object will be deleted on the UI thread I need | 435 // Since the CsdClient object will be deleted on the UI thread I need |
| 429 // to run the UI message loop. Post a task to stop the UI message loop | 436 // to run the UI message loop. Post a task to stop the UI message loop |
| 430 // after the client object destructor is called. | 437 // after the client object destructor is called. |
| 431 FlushIOMessageLoop(); | 438 FlushIOMessageLoop(); |
| 432 } | 439 } |
| 433 | 440 |
| 441 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneVerdictNotPhishing) { | |
| 442 // Case 6: renderer sends a verdict string that isn't phishing. | |
| 443 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | |
| 444 contents(), | |
| 445 csd_service_.get()); | |
| 446 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | |
| 447 | |
| 448 ClientPhishingRequest verdict; | |
| 449 verdict.set_url("http://not-phishing.com/"); | |
| 450 verdict.set_client_score(0.1f); | |
| 451 verdict.set_is_phishing(false); | |
| 452 | |
| 453 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0); | |
| 454 OnPhishingDetectionDone(verdict.SerializeAsString()); | |
| 455 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); | |
| 456 } | |
| 457 | |
| 458 TEST_F(ClientSideDetectionHostTest, | |
| 459 OnPhishingDetectionDoneVerdictNotPhishingButSBMatch) { | |
| 460 // Case 7: renderer sends a verdict string that isn't phishing but the URL | |
| 461 // was on the regular phishing or malware lists. | |
| 462 GURL url("http://not-phishing.com/"); | |
| 463 ClientPhishingRequest verdict; | |
| 464 verdict.set_url(url.spec()); | |
| 465 verdict.set_client_score(0.1f); | |
| 466 verdict.set_is_phishing(false); | |
| 467 | |
| 468 // First we have to navigate to the URL to set the unique page ID. | |
| 469 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, | |
| 470 &kFalse, &kFalse); | |
| 471 NavigateAndCommit(url); | |
| 472 WaitAndCheckPreClassificationChecks(); | |
| 473 SetUnsafeUniquePageIdToCurrent(); | |
| 474 | |
| 475 EXPECT_CALL(*csd_service_, | |
| 476 SendClientReportPhishingRequest( | |
| 477 Pointee(PartiallyEqualVerdict(verdict)), IsNull())) | |
| 478 .WillOnce(DoAll(DeleteArg<0>(), QuitUIMessageLoop())); | |
|
Brian Ryner
2011/07/19 21:27:10
Is there an easy way to check that this situation
noelutz
2011/07/19 22:28:08
Well, I do check that NULL is passed for the callb
Brian Ryner
2011/07/19 22:35:24
Ah, I missed that. Seems reasonable.
| |
| 479 OnPhishingDetectionDone(verdict.SerializeAsString()); | |
| 480 MessageLoop::current()->Run(); | |
| 481 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | |
| 482 } | |
| 483 | |
| 434 TEST_F(ClientSideDetectionHostTest, NavigationCancelsShouldClassifyUrl) { | 484 TEST_F(ClientSideDetectionHostTest, NavigationCancelsShouldClassifyUrl) { |
| 435 // Test that canceling pending should classify requests works as expected. | 485 // Test that canceling pending should classify requests works as expected. |
| 436 | 486 |
| 437 GURL first_url("http://first.phishy.url.com"); | 487 GURL first_url("http://first.phishy.url.com"); |
| 438 // The proxy checks is done synchronously so check that it has been done | 488 // The proxy checks is done synchronously so check that it has been done |
| 439 // for the first URL. | 489 // for the first URL. |
| 440 ExpectPreClassificationChecks(first_url, &kFalse, &kFalse, &kFalse, NULL, | 490 ExpectPreClassificationChecks(first_url, &kFalse, &kFalse, &kFalse, NULL, |
| 441 NULL, NULL); | 491 NULL, NULL); |
| 442 NavigateAndCommit(first_url); | 492 NavigateAndCommit(first_url); |
| 443 | 493 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 612 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); | 662 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); |
| 613 EXPECT_EQ(url, resource.url); | 663 EXPECT_EQ(url, resource.url); |
| 614 EXPECT_EQ(url, resource.original_url); | 664 EXPECT_EQ(url, resource.original_url); |
| 615 delete resource.client; | 665 delete resource.client; |
| 616 msg = process()->sink().GetFirstMessageMatching( | 666 msg = process()->sink().GetFirstMessageMatching( |
| 617 SafeBrowsingMsg_StartPhishingDetection::ID); | 667 SafeBrowsingMsg_StartPhishingDetection::ID); |
| 618 ASSERT_FALSE(msg); | 668 ASSERT_FALSE(msg); |
| 619 } | 669 } |
| 620 | 670 |
| 621 } // namespace safe_browsing | 671 } // namespace safe_browsing |
| OLD | NEW |