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

Side by Side Diff: chrome/browser/signin/token_service_unittest.cc

Issue 10006037: Moved WebDataService to ProfileKeyedService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed compile Created 8 years, 8 months 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 // 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
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 WaitForDBLoadCompletion(); 76 WaitForDBLoadCompletion();
77 service_ = TokenServiceFactory::GetForProfile(profile_.get()); 77 service_ = TokenServiceFactory::GetForProfile(profile_.get());
78 78
79 success_tracker_.ListenFor(chrome::NOTIFICATION_TOKEN_AVAILABLE, 79 success_tracker_.ListenFor(chrome::NOTIFICATION_TOKEN_AVAILABLE,
80 content::Source<TokenService>(service_)); 80 content::Source<TokenService>(service_));
81 failure_tracker_.ListenFor(chrome::NOTIFICATION_TOKEN_REQUEST_FAILED, 81 failure_tracker_.ListenFor(chrome::NOTIFICATION_TOKEN_REQUEST_FAILED,
82 content::Source<TokenService>(service_)); 82 content::Source<TokenService>(service_));
83 83
84 service_->Initialize("test", profile_.get()); 84 service_->Initialize("test", profile_.get());
85 } 85 }
86 86
87 void TokenServiceTestHarness::TearDown() { 87 void TokenServiceTestHarness::TearDown() {
88 // You have to destroy the profile before the db_thread_ stops. 88 // You have to destroy the profile before the db_thread_ stops.
89 if (profile_.get()) { 89 if (profile_.get()) {
90 profile_.reset(NULL); 90 profile_.reset(NULL);
91 } 91 }
92 92
93 BrowserThread::UnsafeGetMessageLoopForThread(
94 BrowserThread::DB)->RunAllPending();
95
93 db_thread_.Stop(); 96 db_thread_.Stop();
94 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 97 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
95 MessageLoop::current()->Run(); 98 MessageLoop::current()->Run();
96 } 99 }
97 100
98 void TokenServiceTestHarness::WaitForDBLoadCompletion() { 101 void TokenServiceTestHarness::WaitForDBLoadCompletion() {
99 // The WebDB does all work on the DB thread. This will add an event 102 // 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 103 // to the end of the DB thread, so when we reach this task, all DB
101 // operations should be complete. 104 // operations should be complete.
102 base::WaitableEvent done(false, false); 105 base::WaitableEvent done(false, false);
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 408
406 *CommandLine::ForCurrentProcess() = original_cl; 409 *CommandLine::ForCurrentProcess() = original_cl;
407 } 410 }
408 }; 411 };
409 412
410 TEST_F(TokenServiceCommandLineTest, TestValueOverride) { 413 TEST_F(TokenServiceCommandLineTest, TestValueOverride) {
411 EXPECT_TRUE(service_->HasTokenForService("my_service")); 414 EXPECT_TRUE(service_->HasTokenForService("my_service"));
412 EXPECT_EQ("my_value", service_->GetTokenForService("my_service")); 415 EXPECT_EQ("my_value", service_->GetTokenForService("my_service"));
413 } 416 }
414 #endif // ifndef NDEBUG 417 #endif // ifndef NDEBUG
OLDNEW
« no previous file with comments | « chrome/browser/signin/token_service_factory.cc ('k') | chrome/browser/sync/glue/autofill_data_type_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698