OLD | NEW |
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 // This test uses the safebrowsing test server published at | 5 // This test uses the safebrowsing test server published at |
6 // http://code.google.com/p/google-safe-browsing/ to test the safebrowsing | 6 // http://code.google.com/p/google-safe-browsing/ to test the safebrowsing |
7 // protocol implemetation. Details of the safebrowsing testing flow is | 7 // protocol implemetation. Details of the safebrowsing testing flow is |
8 // documented at | 8 // documented at |
9 // http://code.google.com/p/google-safe-browsing/wiki/ProtocolTesting | 9 // http://code.google.com/p/google-safe-browsing/wiki/ProtocolTesting |
10 // | 10 // |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 base::Time last_update() { | 196 base::Time last_update() { |
197 base::AutoLock l(update_status_mutex_); | 197 base::AutoLock l(update_status_mutex_); |
198 return last_update_; | 198 return last_update_; |
199 } | 199 } |
200 | 200 |
201 bool is_update_scheduled() { | 201 bool is_update_scheduled() { |
202 base::AutoLock l(update_status_mutex_); | 202 base::AutoLock l(update_status_mutex_); |
203 return is_update_scheduled_; | 203 return is_update_scheduled_; |
204 } | 204 } |
205 | 205 |
206 MessageLoop* SafeBrowsingMessageLoop() { | 206 base::MessageLoop* SafeBrowsingMessageLoop() { |
207 return database_manager()->safe_browsing_thread_->message_loop(); | 207 return database_manager()->safe_browsing_thread_->message_loop(); |
208 } | 208 } |
209 | 209 |
210 const net::SpawnedTestServer& test_server() const { | 210 const net::SpawnedTestServer& test_server() const { |
211 return *test_server_; | 211 return *test_server_; |
212 } | 212 } |
213 | 213 |
214 protected: | 214 protected: |
215 bool InitSafeBrowsingService() { | 215 bool InitSafeBrowsingService() { |
216 safe_browsing_service_ = g_browser_process->safe_browsing_service(); | 216 safe_browsing_service_ = g_browser_process->safe_browsing_service(); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 // Updates status from IO Thread. | 343 // Updates status from IO Thread. |
344 void CheckStatusOnIOThread() { | 344 void CheckStatusOnIOThread() { |
345 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 345 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
346 safe_browsing_test_->UpdateSafeBrowsingStatus(); | 346 safe_browsing_test_->UpdateSafeBrowsingStatus(); |
347 safe_browsing_test_->SafeBrowsingMessageLoop()->PostTask(FROM_HERE, | 347 safe_browsing_test_->SafeBrowsingMessageLoop()->PostTask(FROM_HERE, |
348 base::Bind(&SafeBrowsingServerTestHelper::CheckIsDatabaseReady, this)); | 348 base::Bind(&SafeBrowsingServerTestHelper::CheckIsDatabaseReady, this)); |
349 } | 349 } |
350 | 350 |
351 // Checks status in SafeBrowsing Thread. | 351 // Checks status in SafeBrowsing Thread. |
352 void CheckIsDatabaseReady() { | 352 void CheckIsDatabaseReady() { |
353 EXPECT_EQ(MessageLoop::current(), | 353 EXPECT_EQ(base::MessageLoop::current(), |
354 safe_browsing_test_->SafeBrowsingMessageLoop()); | 354 safe_browsing_test_->SafeBrowsingMessageLoop()); |
355 safe_browsing_test_->CheckIsDatabaseReady(); | 355 safe_browsing_test_->CheckIsDatabaseReady(); |
356 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 356 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
357 base::Bind(&SafeBrowsingServerTestHelper::OnWaitForStatusUpdateDone, | 357 base::Bind(&SafeBrowsingServerTestHelper::OnWaitForStatusUpdateDone, |
358 this)); | 358 this)); |
359 } | 359 } |
360 | 360 |
361 void OnWaitForStatusUpdateDone() { | 361 void OnWaitForStatusUpdateDone() { |
362 StopUILoop(); | 362 StopUILoop(); |
363 } | 363 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 return response_data_; | 415 return response_data_; |
416 } | 416 } |
417 | 417 |
418 private: | 418 private: |
419 friend class base::RefCountedThreadSafe<SafeBrowsingServerTestHelper>; | 419 friend class base::RefCountedThreadSafe<SafeBrowsingServerTestHelper>; |
420 virtual ~SafeBrowsingServerTestHelper() {} | 420 virtual ~SafeBrowsingServerTestHelper() {} |
421 | 421 |
422 // Stops UI loop after desired status is updated. | 422 // Stops UI loop after desired status is updated. |
423 void StopUILoop() { | 423 void StopUILoop() { |
424 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 424 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
425 MessageLoopForUI::current()->Quit(); | 425 base::MessageLoopForUI::current()->Quit(); |
426 } | 426 } |
427 | 427 |
428 // Fetch a URL. If message_loop_started is true, starts the message loop | 428 // Fetch a URL. If message_loop_started is true, starts the message loop |
429 // so the caller could wait till OnURLFetchComplete is called. | 429 // so the caller could wait till OnURLFetchComplete is called. |
430 net::URLRequestStatus::Status FetchUrl(const GURL& url) { | 430 net::URLRequestStatus::Status FetchUrl(const GURL& url) { |
431 url_fetcher_.reset(net::URLFetcher::Create( | 431 url_fetcher_.reset(net::URLFetcher::Create( |
432 url, net::URLFetcher::GET, this)); | 432 url, net::URLFetcher::GET, this)); |
433 url_fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE); | 433 url_fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
434 url_fetcher_->SetRequestContext(request_context_); | 434 url_fetcher_->SetRequestContext(request_context_); |
435 url_fetcher_->Start(); | 435 url_fetcher_->Start(); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 safe_browsing_helper->FetchDBToVerify(test_server(), step)); | 524 safe_browsing_helper->FetchDBToVerify(test_server(), step)); |
525 EXPECT_GT(safe_browsing_helper->response_data().size(), 0U); | 525 EXPECT_GT(safe_browsing_helper->response_data().size(), 0U); |
526 last_step = step; | 526 last_step = step; |
527 } | 527 } |
528 | 528 |
529 // Verifies with server if test is done and waits till server responses. | 529 // Verifies with server if test is done and waits till server responses. |
530 EXPECT_EQ(net::URLRequestStatus::SUCCESS, | 530 EXPECT_EQ(net::URLRequestStatus::SUCCESS, |
531 safe_browsing_helper->VerifyTestComplete(test_server(), last_step)); | 531 safe_browsing_helper->VerifyTestComplete(test_server(), last_step)); |
532 EXPECT_EQ("yes", safe_browsing_helper->response_data()); | 532 EXPECT_EQ("yes", safe_browsing_helper->response_data()); |
533 } | 533 } |
OLD | NEW |