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
3 // found in the LICENSE file.
5 // This file defines a unit test harness for the profile's token service.
7 #ifndef CHROME_BROWSER_SIGNIN_TOKEN_SERVICE_UNITTEST_H_
8 #define CHROME_BROWSER_SIGNIN_TOKEN_SERVICE_UNITTEST_H_
10 #include "base/message_loop/message_loop.h"
11 #include "base/synchronization/waitable_event.h"
12 #include "chrome/browser/signin/token_service.h"
13 #include "chrome/test/base/testing_profile.h"
14 #include "content/public/browser/notification_details.h"
15 #include "content/public/browser/notification_source.h"
16 #include "content/public/test/test_browser_thread_bundle.h"
17 #include "content/public/test/test_notification_tracker.h"
18 #include "google_apis/gaia/gaia_auth_consumer.h"
19 #include "testing/gtest/include/gtest/gtest.h"
21 class FakeSigninManagerBase;
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 {
28 TokenAvailableTracker();
29 virtual ~TokenAvailableTracker();
31 const TokenService::TokenAvailableDetails& details() {
36 virtual void Observe(int type,
37 const content::NotificationSource& source,
38 const content::NotificationDetails& details) OVERRIDE;
40 TokenService::TokenAvailableDetails details_;
43 class TokenFailedTracker : public content::TestNotificationTracker {
46 virtual ~TokenFailedTracker();
48 const TokenService::TokenRequestFailedDetails& details() {
53 virtual void Observe(int type,
54 const content::NotificationSource& source,
55 const content::NotificationDetails& details) OVERRIDE;
57 TokenService::TokenRequestFailedDetails details_;
60 class TokenServiceTestHarness : public testing::Test {
62 TokenServiceTestHarness();
63 virtual ~TokenServiceTestHarness();
65 virtual void SetUp() OVERRIDE;
66 virtual void TearDown() OVERRIDE;
68 virtual scoped_ptr<TestingProfile> CreateProfile();
69 void UpdateCredentialsOnService();
70 TestingProfile* profile() const { return profile_.get(); }
71 TokenService* service() const { return service_; }
72 const GaiaAuthConsumer::ClientLoginResult& credentials() const {
75 TokenAvailableTracker* success_tracker() { return &success_tracker_; }
76 TokenFailedTracker* failure_tracker() { return &failure_tracker_; }
78 void CreateSigninManager(const std::string& username);
81 content::TestBrowserThreadBundle thread_bundle_;
83 FakeSigninManagerBase* signin_manager_;
84 TokenService* service_;
85 TokenAvailableTracker success_tracker_;
86 TokenFailedTracker failure_tracker_;
87 GaiaAuthConsumer::ClientLoginResult credentials_;
88 std::string oauth_token_;
89 std::string oauth_secret_;
90 scoped_ptr<TestingProfile> profile_;
93 #endif // CHROME_BROWSER_SIGNIN_TOKEN_SERVICE_UNITTEST_H_