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.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 // TestNotificationTracker doesn't do a deep copy on the notification details. | 21 // TestNotificationTracker doesn't do a deep copy on the notification details. |
22 // We have to in order to read it out, or we have a bad ptr, since the details | 22 // We have to in order to read it out, or we have a bad ptr, since the details |
23 // are a reference on the stack. | 23 // are a reference on the stack. |
24 class TokenAvailableTracker : public content::TestNotificationTracker { | 24 class TokenAvailableTracker : public content::TestNotificationTracker { |
25 public: | 25 public: |
26 TokenAvailableTracker(); | 26 TokenAvailableTracker(); |
(...skipping 22 matching lines...) Expand all Loading... |
49 | 49 |
50 private: | 50 private: |
51 virtual void Observe(int type, | 51 virtual void Observe(int type, |
52 const content::NotificationSource& source, | 52 const content::NotificationSource& source, |
53 const content::NotificationDetails& details) OVERRIDE; | 53 const content::NotificationDetails& details) OVERRIDE; |
54 | 54 |
55 TokenService::TokenRequestFailedDetails details_; | 55 TokenService::TokenRequestFailedDetails details_; |
56 }; | 56 }; |
57 | 57 |
58 class TokenServiceTestHarness : public testing::Test { | 58 class TokenServiceTestHarness : public testing::Test { |
59 public: | 59 protected: |
60 TokenServiceTestHarness(); | 60 TokenServiceTestHarness(); |
61 virtual ~TokenServiceTestHarness(); | 61 virtual ~TokenServiceTestHarness(); |
62 | 62 |
63 virtual void SetUp() OVERRIDE; | 63 virtual void SetUp() OVERRIDE; |
64 | |
65 virtual void TearDown() OVERRIDE; | 64 virtual void TearDown() OVERRIDE; |
66 | 65 |
67 void WaitForDBLoadCompletion(); | 66 void UpdateCredentialsOnService(); |
| 67 TestingProfile* profile() const { return profile_.get(); } |
| 68 TokenService* service() const { return service_; } |
| 69 const GaiaAuthConsumer::ClientLoginResult& credentials() const { |
| 70 return credentials_; |
| 71 } |
| 72 TokenAvailableTracker* success_tracker() { return &success_tracker_; } |
| 73 TokenFailedTracker* failure_tracker() { return &failure_tracker_; } |
68 | 74 |
69 base::MessageLoopForUI message_loop_; | 75 private: |
70 content::TestBrowserThread ui_thread_; // Mostly so DCHECKS pass. | 76 content::TestBrowserThreadBundle thread_bundle_; |
71 content::TestBrowserThread db_thread_; // WDS on here | |
72 | 77 |
73 TokenService* service_; | 78 TokenService* service_; |
74 TokenAvailableTracker success_tracker_; | 79 TokenAvailableTracker success_tracker_; |
75 TokenFailedTracker failure_tracker_; | 80 TokenFailedTracker failure_tracker_; |
76 GaiaAuthConsumer::ClientLoginResult credentials_; | 81 GaiaAuthConsumer::ClientLoginResult credentials_; |
77 std::string oauth_token_; | 82 std::string oauth_token_; |
78 std::string oauth_secret_; | 83 std::string oauth_secret_; |
79 scoped_ptr<TestingProfile> profile_; | 84 scoped_ptr<TestingProfile> profile_; |
80 }; | 85 }; |
81 | 86 |
82 #endif // CHROME_BROWSER_SIGNIN_TOKEN_SERVICE_UNITTEST_H_ | 87 #endif // CHROME_BROWSER_SIGNIN_TOKEN_SERVICE_UNITTEST_H_ |
OLD | NEW |