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

Side by Side Diff: chrome/browser/net/gaia/token_service_unittest.h

Issue 3305003: New authorization framework for sync. ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 3 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
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // This file defines a unit test harness for the profile's token service.
6
7 #ifndef CHROME_BROWSER_NET_GAIA_TOKEN_SERVICE_UNITTEST_H_
8 #define CHROME_BROWSER_NET_GAIA_TOKEN_SERVICE_UNITTEST_H_
9 #pragma once
10
11 #include "chrome/browser/net/gaia/token_service.h"
12 #include "chrome/browser/password_manager/encryptor.h"
13 #include "chrome/browser/webdata/web_data_service.h"
14 #include "chrome/common/net/gaia/gaia_auth_consumer.h"
15 #include "chrome/test/signaling_task.h"
16 #include "chrome/test/test_notification_tracker.h"
17 #include "chrome/test/testing_profile.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19
20 // TestNotificationTracker doesn't do a deep copy on the notification details.
21 // We have to in order to read it out, or we have a bad ptr, since the details
22 // are a reference on the stack.
23 class TokenAvailableTracker : public TestNotificationTracker {
24 public:
25 const TokenService::TokenAvailableDetails& details() {
26 return details_;
27 }
28
29 private:
30 virtual void Observe(NotificationType type,
31 const NotificationSource& source,
32 const NotificationDetails& details) {
33 TestNotificationTracker::Observe(type, source, details);
34 if (type == NotificationType::TOKEN_AVAILABLE) {
35 Details<const TokenService::TokenAvailableDetails> full = details;
36 details_ = *full.ptr();
37 }
38 }
39
40 TokenService::TokenAvailableDetails details_;
41 };
42
43 class TokenFailedTracker : public TestNotificationTracker {
44 public:
45 const TokenService::TokenRequestFailedDetails& details() {
46 return details_;
47 }
48
49 private:
50 virtual void Observe(NotificationType type,
51 const NotificationSource& source,
52 const NotificationDetails& details) {
53 TestNotificationTracker::Observe(type, source, details);
54 if (type == NotificationType::TOKEN_REQUEST_FAILED) {
55 Details<const TokenService::TokenRequestFailedDetails> full = details;
56 details_ = *full.ptr();
57 }
58 }
59
60 TokenService::TokenRequestFailedDetails details_;
61 };
62
63 class TokenServiceTestHarness : public testing::Test {
64 public:
65 TokenServiceTestHarness()
66 : ui_thread_(ChromeThread::UI, &message_loop_),
67 db_thread_(ChromeThread::DB) {
68 }
69
70 virtual void SetUp() {
71 #if defined(OS_MACOSX)
72 Encryptor::UseMockKeychain(true);
73 #endif
74 credentials_.sid = "sid";
75 credentials_.lsid = "lsid";
76 credentials_.token = "token";
77 credentials_.data = "data";
78
79 ASSERT_TRUE(db_thread_.Start());
80
81 profile_.reset(new TestingProfile());
82 profile_->CreateWebDataService(false);
83 WaitForDBLoadCompletion();
84
85 success_tracker_.ListenFor(NotificationType::TOKEN_AVAILABLE,
86 Source<TokenService>(&service_));
87 failure_tracker_.ListenFor(NotificationType::TOKEN_REQUEST_FAILED,
88 Source<TokenService>(&service_));
89
90 service_.Initialize("test", profile_.get());
91
92 URLFetcher::set_factory(NULL);
93 }
94
95 virtual void TearDown() {
96 // You have to destroy the profile before the db_thread_ stops.
97 if (profile_.get()) {
98 profile_.reset(NULL);
99 }
100
101 db_thread_.Stop();
102 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask);
103 MessageLoop::current()->Run();
104 }
105
106 void WaitForDBLoadCompletion() {
107 // The WebDB does all work on the DB thread. This will add an event
108 // to the end of the DB thread, so when we reach this task, all DB
109 // operations should be complete.
110 WaitableEvent done(false, false);
111 ChromeThread::PostTask(
112 ChromeThread::DB, FROM_HERE, new SignalingTask(&done));
113 done.Wait();
114
115 // Notifications should be returned from the DB thread onto the UI thread.
116 message_loop_.RunAllPending();
117 }
118
119 MessageLoopForUI message_loop_;
120 ChromeThread ui_thread_; // Mostly so DCHECKS pass.
121 ChromeThread db_thread_; // WDS on here
122
123 TokenService service_;
124 TokenAvailableTracker success_tracker_;
125 TokenFailedTracker failure_tracker_;
126 GaiaAuthConsumer::ClientLoginResult credentials_;
127 scoped_ptr<TestingProfile> profile_;
128 };
129
130 #endif // CHROME_BROWSER_NET_GAIA_TOKEN_SERVICE_UNITTEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698