| 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 file defines a unit test for the profile's token service. | 5 // This file defines a unit test for the profile's token service. |
| 6 | 6 |
| 7 #include "chrome/browser/signin/token_service_unittest.h" | 7 #include "chrome/browser/signin/token_service_unittest.h" |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
| 14 #include "chrome/browser/password_manager/encryptor.h" | 14 #include "chrome/browser/password_manager/encryptor.h" |
| 15 #include "chrome/browser/signin/token_service_factory.h" | 15 #include "chrome/browser/signin/token_service_factory.h" |
| 16 #include "chrome/browser/webdata/web_data_service_factory.h" |
| 16 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
| 17 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/common/net/gaia/mock_url_fetcher_factory.h" | 19 #include "chrome/common/net/gaia/mock_url_fetcher_factory.h" |
| 19 #include "chrome/common/net/gaia/gaia_constants.h" | 20 #include "chrome/common/net/gaia/gaia_constants.h" |
| 20 #include "content/test/test_url_fetcher_factory.h" | 21 #include "content/test/test_url_fetcher_factory.h" |
| 21 | 22 |
| 22 using content::BrowserThread; | 23 using content::BrowserThread; |
| 23 | 24 |
| 24 TokenAvailableTracker::TokenAvailableTracker() {} | 25 TokenAvailableTracker::TokenAvailableTracker() {} |
| 25 | 26 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 credentials_.sid = "sid"; | 66 credentials_.sid = "sid"; |
| 66 credentials_.lsid = "lsid"; | 67 credentials_.lsid = "lsid"; |
| 67 credentials_.token = "token"; | 68 credentials_.token = "token"; |
| 68 credentials_.data = "data"; | 69 credentials_.data = "data"; |
| 69 oauth_token_ = "oauth"; | 70 oauth_token_ = "oauth"; |
| 70 oauth_secret_ = "secret"; | 71 oauth_secret_ = "secret"; |
| 71 | 72 |
| 72 ASSERT_TRUE(db_thread_.Start()); | 73 ASSERT_TRUE(db_thread_.Start()); |
| 73 | 74 |
| 74 profile_.reset(new TestingProfile()); | 75 profile_.reset(new TestingProfile()); |
| 75 profile_->CreateWebDataService(false); | 76 profile_->CreateWebDataService(); |
| 77 |
| 76 WaitForDBLoadCompletion(); | 78 WaitForDBLoadCompletion(); |
| 77 service_ = TokenServiceFactory::GetForProfile(profile_.get()); | 79 service_ = TokenServiceFactory::GetForProfile(profile_.get()); |
| 78 | 80 |
| 79 success_tracker_.ListenFor(chrome::NOTIFICATION_TOKEN_AVAILABLE, | 81 success_tracker_.ListenFor(chrome::NOTIFICATION_TOKEN_AVAILABLE, |
| 80 content::Source<TokenService>(service_)); | 82 content::Source<TokenService>(service_)); |
| 81 failure_tracker_.ListenFor(chrome::NOTIFICATION_TOKEN_REQUEST_FAILED, | 83 failure_tracker_.ListenFor(chrome::NOTIFICATION_TOKEN_REQUEST_FAILED, |
| 82 content::Source<TokenService>(service_)); | 84 content::Source<TokenService>(service_)); |
| 83 | 85 |
| 84 service_->Initialize("test", profile_.get()); | 86 service_->Initialize("test", profile_.get()); |
| 85 } | 87 } |
| 86 | 88 |
| 87 void TokenServiceTestHarness::TearDown() { | 89 void TokenServiceTestHarness::TearDown() { |
| 88 // You have to destroy the profile before the db_thread_ stops. | 90 // You have to destroy the profile before the db_thread_ stops. |
| 89 if (profile_.get()) { | 91 if (profile_.get()) { |
| 90 profile_.reset(NULL); | 92 profile_.reset(NULL); |
| 91 } | 93 } |
| 94 // Schedule another task on the DB thread to notify us that it's safe to |
| 95 // carry on with the test. |
| 96 base::WaitableEvent done(false, false); |
| 97 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 98 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); |
| 99 done.Wait(); |
| 92 | 100 |
| 93 db_thread_.Stop(); | 101 db_thread_.Stop(); |
| 94 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 102 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 95 MessageLoop::current()->Run(); | 103 MessageLoop::current()->Run(); |
| 96 } | 104 } |
| 97 | 105 |
| 98 void TokenServiceTestHarness::WaitForDBLoadCompletion() { | 106 void TokenServiceTestHarness::WaitForDBLoadCompletion() { |
| 107 // Force the loading of the WebDataService. |
| 108 WebDataServiceFactory::GetForProfile(profile_.get(), |
| 109 Profile::IMPLICIT_ACCESS); |
| 110 |
| 99 // The WebDB does all work on the DB thread. This will add an event | 111 // The WebDB does all work on the DB thread. This will add an event |
| 100 // to the end of the DB thread, so when we reach this task, all DB | 112 // to the end of the DB thread, so when we reach this task, all DB |
| 101 // operations should be complete. | 113 // operations should be complete. |
| 102 base::WaitableEvent done(false, false); | 114 base::WaitableEvent done(false, false); |
| 103 BrowserThread::PostTask( | 115 BrowserThread::PostTask( |
| 104 BrowserThread::DB, | 116 BrowserThread::DB, |
| 105 FROM_HERE, | 117 FROM_HERE, |
| 106 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); | 118 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); |
| 107 done.Wait(); | 119 done.Wait(); |
| 108 | 120 |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 | 421 |
| 410 *CommandLine::ForCurrentProcess() = original_cl; | 422 *CommandLine::ForCurrentProcess() = original_cl; |
| 411 } | 423 } |
| 412 }; | 424 }; |
| 413 | 425 |
| 414 TEST_F(TokenServiceCommandLineTest, TestValueOverride) { | 426 TEST_F(TokenServiceCommandLineTest, TestValueOverride) { |
| 415 EXPECT_TRUE(service_->HasTokenForService("my_service")); | 427 EXPECT_TRUE(service_->HasTokenForService("my_service")); |
| 416 EXPECT_EQ("my_value", service_->GetTokenForService("my_service")); | 428 EXPECT_EQ("my_value", service_->GetTokenForService("my_service")); |
| 417 } | 429 } |
| 418 #endif // ifndef NDEBUG | 430 #endif // ifndef NDEBUG |
| OLD | NEW |