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 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_SIGNIN_TOKEN_SERVICE_UNITTEST_H_ | 7 #ifndef CHROME_BROWSER_SIGNIN_TOKEN_SERVICE_UNITTEST_H_ |
8 #define CHROME_BROWSER_SIGNIN_TOKEN_SERVICE_UNITTEST_H_ | 8 #define CHROME_BROWSER_SIGNIN_TOKEN_SERVICE_UNITTEST_H_ |
9 | 9 |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
12 #include "chrome/browser/signin/token_service.h" | 12 #include "chrome/browser/signin/token_service.h" |
13 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
14 #include "content/public/browser/notification_details.h" | 14 #include "content/public/browser/notification_details.h" |
15 #include "content/public/browser/notification_source.h" | 15 #include "content/public/browser/notification_source.h" |
16 #include "content/public/test/test_browser_thread_bundle.h" | 16 #include "content/public/test/test_browser_thread_bundle.h" |
17 #include "content/public/test/test_notification_tracker.h" | 17 #include "content/public/test/test_notification_tracker.h" |
18 #include "google_apis/gaia/gaia_auth_consumer.h" | 18 #include "google_apis/gaia/gaia_auth_consumer.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 | 20 |
21 class FakeSigninManagerBase; | 21 class FakeSigninManagerBase; |
22 | 22 |
23 // TestNotificationTracker doesn't do a deep copy on the notification details. | |
24 // We have to in order to read it out, or we have a bad ptr, since the details | |
25 // are a reference on the stack. | |
26 class TokenAvailableTracker : public content::TestNotificationTracker { | |
27 public: | |
28 TokenAvailableTracker(); | |
29 virtual ~TokenAvailableTracker(); | |
30 | |
31 const TokenService::TokenAvailableDetails& details() { | |
32 return details_; | |
33 } | |
34 | |
35 private: | |
36 virtual void Observe(int type, | |
37 const content::NotificationSource& source, | |
38 const content::NotificationDetails& details) OVERRIDE; | |
39 | |
40 TokenService::TokenAvailableDetails details_; | |
41 }; | |
42 | |
43 class TokenFailedTracker : public content::TestNotificationTracker { | |
44 public: | |
45 TokenFailedTracker(); | |
46 virtual ~TokenFailedTracker(); | |
47 | |
48 const TokenService::TokenRequestFailedDetails& details() { | |
49 return details_; | |
50 } | |
51 | |
52 private: | |
53 virtual void Observe(int type, | |
54 const content::NotificationSource& source, | |
55 const content::NotificationDetails& details) OVERRIDE; | |
56 | |
57 TokenService::TokenRequestFailedDetails details_; | |
58 }; | |
59 | |
60 class TokenServiceTestHarness : public testing::Test { | 23 class TokenServiceTestHarness : public testing::Test { |
61 protected: | 24 protected: |
62 TokenServiceTestHarness(); | 25 TokenServiceTestHarness(); |
63 virtual ~TokenServiceTestHarness(); | 26 virtual ~TokenServiceTestHarness(); |
64 | 27 |
65 virtual void SetUp() OVERRIDE; | 28 virtual void SetUp() OVERRIDE; |
66 virtual void TearDown() OVERRIDE; | 29 virtual void TearDown() OVERRIDE; |
67 | 30 |
68 virtual scoped_ptr<TestingProfile> CreateProfile(); | 31 virtual scoped_ptr<TestingProfile> CreateProfile(); |
69 void UpdateCredentialsOnService(); | 32 void UpdateCredentialsOnService(); |
70 TestingProfile* profile() const { return profile_.get(); } | 33 TestingProfile* profile() const { return profile_.get(); } |
71 TokenService* service() const { return service_; } | 34 TokenService* service() const { return service_; } |
72 const GaiaAuthConsumer::ClientLoginResult& credentials() const { | 35 const GaiaAuthConsumer::ClientLoginResult& credentials() const { |
73 return credentials_; | 36 return credentials_; |
74 } | 37 } |
75 TokenAvailableTracker* success_tracker() { return &success_tracker_; } | |
76 TokenFailedTracker* failure_tracker() { return &failure_tracker_; } | |
77 | 38 |
78 void CreateSigninManager(const std::string& username); | 39 void CreateSigninManager(const std::string& username); |
79 | 40 |
80 private: | 41 private: |
81 content::TestBrowserThreadBundle thread_bundle_; | 42 content::TestBrowserThreadBundle thread_bundle_; |
82 | 43 |
83 FakeSigninManagerBase* signin_manager_; | 44 FakeSigninManagerBase* signin_manager_; |
84 TokenService* service_; | 45 TokenService* service_; |
85 TokenAvailableTracker success_tracker_; | |
86 TokenFailedTracker failure_tracker_; | |
87 GaiaAuthConsumer::ClientLoginResult credentials_; | 46 GaiaAuthConsumer::ClientLoginResult credentials_; |
88 std::string oauth_token_; | 47 std::string oauth_token_; |
89 std::string oauth_secret_; | 48 std::string oauth_secret_; |
90 scoped_ptr<TestingProfile> profile_; | 49 scoped_ptr<TestingProfile> profile_; |
91 }; | 50 }; |
92 | 51 |
93 #endif // CHROME_BROWSER_SIGNIN_TOKEN_SERVICE_UNITTEST_H_ | 52 #endif // CHROME_BROWSER_SIGNIN_TOKEN_SERVICE_UNITTEST_H_ |
OLD | NEW |