| 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::TestServer& test_server() const { | 210 const net::TestServer& 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 // Updates status from IO Thread. | 339 // Updates status from IO Thread. |
| 340 void CheckStatusOnIOThread() { | 340 void CheckStatusOnIOThread() { |
| 341 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 341 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 342 safe_browsing_test_->UpdateSafeBrowsingStatus(); | 342 safe_browsing_test_->UpdateSafeBrowsingStatus(); |
| 343 safe_browsing_test_->SafeBrowsingMessageLoop()->PostTask(FROM_HERE, | 343 safe_browsing_test_->SafeBrowsingMessageLoop()->PostTask(FROM_HERE, |
| 344 base::Bind(&SafeBrowsingServerTestHelper::CheckIsDatabaseReady, this)); | 344 base::Bind(&SafeBrowsingServerTestHelper::CheckIsDatabaseReady, this)); |
| 345 } | 345 } |
| 346 | 346 |
| 347 // Checks status in SafeBrowsing Thread. | 347 // Checks status in SafeBrowsing Thread. |
| 348 void CheckIsDatabaseReady() { | 348 void CheckIsDatabaseReady() { |
| 349 EXPECT_EQ(MessageLoop::current(), | 349 EXPECT_EQ(base::MessageLoop::current(), |
| 350 safe_browsing_test_->SafeBrowsingMessageLoop()); | 350 safe_browsing_test_->SafeBrowsingMessageLoop()); |
| 351 safe_browsing_test_->CheckIsDatabaseReady(); | 351 safe_browsing_test_->CheckIsDatabaseReady(); |
| 352 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 352 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 353 base::Bind(&SafeBrowsingServerTestHelper::OnWaitForStatusUpdateDone, | 353 base::Bind(&SafeBrowsingServerTestHelper::OnWaitForStatusUpdateDone, |
| 354 this)); | 354 this)); |
| 355 } | 355 } |
| 356 | 356 |
| 357 void OnWaitForStatusUpdateDone() { | 357 void OnWaitForStatusUpdateDone() { |
| 358 StopUILoop(); | 358 StopUILoop(); |
| 359 } | 359 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 return response_data_; | 411 return response_data_; |
| 412 } | 412 } |
| 413 | 413 |
| 414 private: | 414 private: |
| 415 friend class base::RefCountedThreadSafe<SafeBrowsingServerTestHelper>; | 415 friend class base::RefCountedThreadSafe<SafeBrowsingServerTestHelper>; |
| 416 virtual ~SafeBrowsingServerTestHelper() {} | 416 virtual ~SafeBrowsingServerTestHelper() {} |
| 417 | 417 |
| 418 // Stops UI loop after desired status is updated. | 418 // Stops UI loop after desired status is updated. |
| 419 void StopUILoop() { | 419 void StopUILoop() { |
| 420 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 420 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 421 MessageLoopForUI::current()->Quit(); | 421 base::MessageLoopForUI::current()->Quit(); |
| 422 } | 422 } |
| 423 | 423 |
| 424 // Fetch a URL. If message_loop_started is true, starts the message loop | 424 // Fetch a URL. If message_loop_started is true, starts the message loop |
| 425 // so the caller could wait till OnURLFetchComplete is called. | 425 // so the caller could wait till OnURLFetchComplete is called. |
| 426 net::URLRequestStatus::Status FetchUrl(const GURL& url) { | 426 net::URLRequestStatus::Status FetchUrl(const GURL& url) { |
| 427 url_fetcher_.reset(net::URLFetcher::Create( | 427 url_fetcher_.reset(net::URLFetcher::Create( |
| 428 url, net::URLFetcher::GET, this)); | 428 url, net::URLFetcher::GET, this)); |
| 429 url_fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE); | 429 url_fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
| 430 url_fetcher_->SetRequestContext(request_context_); | 430 url_fetcher_->SetRequestContext(request_context_); |
| 431 url_fetcher_->Start(); | 431 url_fetcher_->Start(); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 safe_browsing_helper->FetchDBToVerify(test_server(), step)); | 520 safe_browsing_helper->FetchDBToVerify(test_server(), step)); |
| 521 EXPECT_GT(safe_browsing_helper->response_data().size(), 0U); | 521 EXPECT_GT(safe_browsing_helper->response_data().size(), 0U); |
| 522 last_step = step; | 522 last_step = step; |
| 523 } | 523 } |
| 524 | 524 |
| 525 // Verifies with server if test is done and waits till server responses. | 525 // Verifies with server if test is done and waits till server responses. |
| 526 EXPECT_EQ(net::URLRequestStatus::SUCCESS, | 526 EXPECT_EQ(net::URLRequestStatus::SUCCESS, |
| 527 safe_browsing_helper->VerifyTestComplete(test_server(), last_step)); | 527 safe_browsing_helper->VerifyTestComplete(test_server(), last_step)); |
| 528 EXPECT_EQ("yes", safe_browsing_helper->response_data()); | 528 EXPECT_EQ("yes", safe_browsing_helper->response_data()); |
| 529 } | 529 } |
| OLD | NEW |