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

Side by Side Diff: chrome/browser/safe_browsing/client_side_detection_service_unittest.cc

Issue 11413050: chrome/browser: Update calls from RunAllPending() to RunUntilIdle(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 | Annotate | Revision Log
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 <map> 5 #include <map>
6 #include <queue> 6 #include <queue>
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 file_thread_.reset(new content::TestBrowserThread(BrowserThread::FILE, 65 file_thread_.reset(new content::TestBrowserThread(BrowserThread::FILE,
66 &msg_loop_)); 66 &msg_loop_));
67 67
68 factory_.reset(new net::FakeURLFetcherFactory()); 68 factory_.reset(new net::FakeURLFetcherFactory());
69 69
70 browser_thread_.reset(new content::TestBrowserThread(BrowserThread::UI, 70 browser_thread_.reset(new content::TestBrowserThread(BrowserThread::UI,
71 &msg_loop_)); 71 &msg_loop_));
72 } 72 }
73 73
74 virtual void TearDown() { 74 virtual void TearDown() {
75 msg_loop_.RunAllPending(); 75 msg_loop_.RunUntilIdle();
76 csd_service_.reset(); 76 csd_service_.reset();
77 file_thread_.reset(); 77 file_thread_.reset();
78 browser_thread_.reset(); 78 browser_thread_.reset();
79 } 79 }
80 80
81 bool SendClientReportPhishingRequest(const GURL& phishing_url, 81 bool SendClientReportPhishingRequest(const GURL& phishing_url,
82 float score) { 82 float score) {
83 ClientPhishingRequest* request = new ClientPhishingRequest(); 83 ClientPhishingRequest* request = new ClientPhishingRequest();
84 request->set_url(phishing_url.spec()); 84 request->set_url(phishing_url.spec());
85 request->set_client_score(score); 85 request->set_client_score(score);
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 TEST_F(ClientSideDetectionServiceTest, ServiceObjectDeletedBeforeCallbackDone) { 323 TEST_F(ClientSideDetectionServiceTest, ServiceObjectDeletedBeforeCallbackDone) {
324 SetModelFetchResponse("bogus model", true /* success */); 324 SetModelFetchResponse("bogus model", true /* success */);
325 csd_service_.reset(ClientSideDetectionService::Create(NULL)); 325 csd_service_.reset(ClientSideDetectionService::Create(NULL));
326 csd_service_->SetEnabledAndRefreshState(true); 326 csd_service_->SetEnabledAndRefreshState(true);
327 EXPECT_TRUE(csd_service_.get() != NULL); 327 EXPECT_TRUE(csd_service_.get() != NULL);
328 // We delete the client-side detection service class even though the callbacks 328 // We delete the client-side detection service class even though the callbacks
329 // haven't run yet. 329 // haven't run yet.
330 csd_service_.reset(); 330 csd_service_.reset();
331 // Waiting for the callbacks to run should not crash even if the service 331 // Waiting for the callbacks to run should not crash even if the service
332 // object is gone. 332 // object is gone.
333 msg_loop_.RunAllPending(); 333 msg_loop_.RunUntilIdle();
334 } 334 }
335 335
336 TEST_F(ClientSideDetectionServiceTest, SendClientReportPhishingRequest) { 336 TEST_F(ClientSideDetectionServiceTest, SendClientReportPhishingRequest) {
337 SetModelFetchResponse("bogus model", true /* success */); 337 SetModelFetchResponse("bogus model", true /* success */);
338 csd_service_.reset(ClientSideDetectionService::Create(NULL)); 338 csd_service_.reset(ClientSideDetectionService::Create(NULL));
339 csd_service_->SetEnabledAndRefreshState(true); 339 csd_service_->SetEnabledAndRefreshState(true);
340 340
341 GURL url("http://a.com/"); 341 GURL url("http://a.com/");
342 float score = 0.4f; // Some random client score. 342 float score = 0.4f; // Some random client score.
343 343
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 633
634 // Check that disabling the service cancels pending requests. 634 // Check that disabling the service cancels pending requests.
635 EXPECT_CALL(*service, ScheduleFetchModel(_)) 635 EXPECT_CALL(*service, ScheduleFetchModel(_))
636 .WillOnce(Invoke(service, &MockClientSideDetectionService::Schedule)); 636 .WillOnce(Invoke(service, &MockClientSideDetectionService::Schedule));
637 csd_service_->SetEnabledAndRefreshState(false); 637 csd_service_->SetEnabledAndRefreshState(false);
638 csd_service_->SetEnabledAndRefreshState(true); 638 csd_service_->SetEnabledAndRefreshState(true);
639 Mock::VerifyAndClearExpectations(service); 639 Mock::VerifyAndClearExpectations(service);
640 EXPECT_TRUE(csd_service_->model_fetcher_.get() != NULL); 640 EXPECT_TRUE(csd_service_->model_fetcher_.get() != NULL);
641 csd_service_->SetEnabledAndRefreshState(false); 641 csd_service_->SetEnabledAndRefreshState(false);
642 EXPECT_TRUE(csd_service_->model_fetcher_.get() == NULL); 642 EXPECT_TRUE(csd_service_->model_fetcher_.get() == NULL);
643 msg_loop_.RunAllPending(); 643 msg_loop_.RunUntilIdle();
644 // No calls expected. 644 // No calls expected.
645 Mock::VerifyAndClearExpectations(service); 645 Mock::VerifyAndClearExpectations(service);
646 646
647 // Requests always return false when the service is disabled. 647 // Requests always return false when the service is disabled.
648 ClientPhishingResponse response; 648 ClientPhishingResponse response;
649 response.set_phishy(true); 649 response.set_phishy(true);
650 SetClientReportPhishingResponse(response.SerializeAsString(), 650 SetClientReportPhishingResponse(response.SerializeAsString(),
651 true /* success */); 651 true /* success */);
652 EXPECT_FALSE(SendClientReportPhishingRequest(GURL("http://a.com/"), 0.4f)); 652 EXPECT_FALSE(SendClientReportPhishingRequest(GURL("http://a.com/"), 0.4f));
653 653
654 // Pending requests also return false if the service is disabled before they 654 // Pending requests also return false if the service is disabled before they
655 // report back. 655 // report back.
656 EXPECT_CALL(*service, ScheduleFetchModel(_)) 656 EXPECT_CALL(*service, ScheduleFetchModel(_))
657 .WillOnce(Invoke(service, &MockClientSideDetectionService::Schedule)); 657 .WillOnce(Invoke(service, &MockClientSideDetectionService::Schedule));
658 EXPECT_CALL(*service, EndFetchModel( 658 EXPECT_CALL(*service, EndFetchModel(
659 ClientSideDetectionService::MODEL_NOT_CHANGED)) 659 ClientSideDetectionService::MODEL_NOT_CHANGED))
660 .WillOnce(Invoke(service, &MockClientSideDetectionService::Disable)); 660 .WillOnce(Invoke(service, &MockClientSideDetectionService::Disable));
661 csd_service_->SetEnabledAndRefreshState(true); 661 csd_service_->SetEnabledAndRefreshState(true);
662 EXPECT_FALSE(SendClientReportPhishingRequest(GURL("http://a.com/"), 0.4f)); 662 EXPECT_FALSE(SendClientReportPhishingRequest(GURL("http://a.com/"), 0.4f));
663 Mock::VerifyAndClearExpectations(service); 663 Mock::VerifyAndClearExpectations(service);
664 } 664 }
665 } // namespace safe_browsing 665 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698