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

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

Issue 6523032: Even more test cleanup. Some fixes to non-test code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 10 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) 2010 The Chromium Authors. All rights reserved. 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 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 harness for the profile's token service. 5 // This file defines a unit test harness for the profile's token service.
6 6
7 #ifndef CHROME_BROWSER_NET_GAIA_TOKEN_SERVICE_UNITTEST_H_ 7 #ifndef CHROME_BROWSER_NET_GAIA_TOKEN_SERVICE_UNITTEST_H_
8 #define CHROME_BROWSER_NET_GAIA_TOKEN_SERVICE_UNITTEST_H_ 8 #define CHROME_BROWSER_NET_GAIA_TOKEN_SERVICE_UNITTEST_H_
9 #pragma once 9 #pragma once
10 10
11 #include "base/synchronization/waitable_event.h" 11 #include "base/synchronization/waitable_event.h"
12 #include "chrome/browser/net/gaia/token_service.h" 12 #include "chrome/browser/net/gaia/token_service.h"
13 #include "chrome/browser/webdata/web_data_service.h" 13 #include "chrome/browser/webdata/web_data_service.h"
14 #include "chrome/common/net/gaia/gaia_auth_consumer.h" 14 #include "chrome/common/net/gaia/gaia_auth_consumer.h"
15 #include "chrome/common/notification_details.h" 15 #include "chrome/common/notification_details.h"
16 #include "chrome/common/notification_source.h" 16 #include "chrome/common/notification_source.h"
17 #include "chrome/test/signaling_task.h" 17 #include "chrome/test/signaling_task.h"
18 #include "chrome/test/test_notification_tracker.h" 18 #include "chrome/test/test_notification_tracker.h"
19 #include "chrome/test/testing_profile.h" 19 #include "chrome/test/testing_profile.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 21
22 // TestNotificationTracker doesn't do a deep copy on the notification details. 22 // TestNotificationTracker doesn't do a deep copy on the notification details.
23 // We have to in order to read it out, or we have a bad ptr, since the details 23 // We have to in order to read it out, or we have a bad ptr, since the details
24 // are a reference on the stack. 24 // are a reference on the stack.
25 class TokenAvailableTracker : public TestNotificationTracker { 25 class TokenAvailableTracker : public TestNotificationTracker {
26 public: 26 public:
27 TokenAvailableTracker();
28 virtual ~TokenAvailableTracker();
29
27 const TokenService::TokenAvailableDetails& details() { 30 const TokenService::TokenAvailableDetails& details() {
28 return details_; 31 return details_;
29 } 32 }
30 33
31 private: 34 private:
32 virtual void Observe(NotificationType type, 35 virtual void Observe(NotificationType type,
33 const NotificationSource& source, 36 const NotificationSource& source,
34 const NotificationDetails& details) { 37 const NotificationDetails& details);
35 TestNotificationTracker::Observe(type, source, details);
36 if (type == NotificationType::TOKEN_AVAILABLE) {
37 Details<const TokenService::TokenAvailableDetails> full = details;
38 details_ = *full.ptr();
39 }
40 }
41 38
42 TokenService::TokenAvailableDetails details_; 39 TokenService::TokenAvailableDetails details_;
43 }; 40 };
44 41
45 class TokenFailedTracker : public TestNotificationTracker { 42 class TokenFailedTracker : public TestNotificationTracker {
46 public: 43 public:
44 TokenFailedTracker();
45 virtual ~TokenFailedTracker();
46
47 const TokenService::TokenRequestFailedDetails& details() { 47 const TokenService::TokenRequestFailedDetails& details() {
48 return details_; 48 return details_;
49 } 49 }
50 50
51 private: 51 private:
52 virtual void Observe(NotificationType type, 52 virtual void Observe(NotificationType type,
53 const NotificationSource& source, 53 const NotificationSource& source,
54 const NotificationDetails& details) { 54 const NotificationDetails& details);
55 TestNotificationTracker::Observe(type, source, details);
56 if (type == NotificationType::TOKEN_REQUEST_FAILED) {
57 Details<const TokenService::TokenRequestFailedDetails> full = details;
58 details_ = *full.ptr();
59 }
60 }
61 55
62 TokenService::TokenRequestFailedDetails details_; 56 TokenService::TokenRequestFailedDetails details_;
63 }; 57 };
64 58
65 class TokenServiceTestHarness : public testing::Test { 59 class TokenServiceTestHarness : public testing::Test {
66 public: 60 public:
67 TokenServiceTestHarness(); 61 TokenServiceTestHarness();
68 virtual ~TokenServiceTestHarness(); 62 virtual ~TokenServiceTestHarness();
69 63
70 virtual void SetUp(); 64 virtual void SetUp();
71 65
72 virtual void TearDown(); 66 virtual void TearDown();
73 67
74 void WaitForDBLoadCompletion(); 68 void WaitForDBLoadCompletion();
75 69
76 MessageLoopForUI message_loop_; 70 MessageLoopForUI message_loop_;
77 BrowserThread ui_thread_; // Mostly so DCHECKS pass. 71 BrowserThread ui_thread_; // Mostly so DCHECKS pass.
78 BrowserThread db_thread_; // WDS on here 72 BrowserThread db_thread_; // WDS on here
79 73
80 TokenService service_; 74 TokenService service_;
81 TokenAvailableTracker success_tracker_; 75 TokenAvailableTracker success_tracker_;
82 TokenFailedTracker failure_tracker_; 76 TokenFailedTracker failure_tracker_;
83 GaiaAuthConsumer::ClientLoginResult credentials_; 77 GaiaAuthConsumer::ClientLoginResult credentials_;
84 scoped_ptr<TestingProfile> profile_; 78 scoped_ptr<TestingProfile> profile_;
85 }; 79 };
86 80
87 #endif // CHROME_BROWSER_NET_GAIA_TOKEN_SERVICE_UNITTEST_H_ 81 #endif // CHROME_BROWSER_NET_GAIA_TOKEN_SERVICE_UNITTEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698