- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / signin / token_service_unittest.h
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.
4 //
5 // This file defines a unit test harness for the profile's token service.
6
7 #ifndef CHROME_BROWSER_SIGNIN_TOKEN_SERVICE_UNITTEST_H_
8 #define CHROME_BROWSER_SIGNIN_TOKEN_SERVICE_UNITTEST_H_
9
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"
20
21 class FakeSigninManagerBase;
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 {
61  protected:
62   TokenServiceTestHarness();
63   virtual ~TokenServiceTestHarness();
64
65   virtual void SetUp() OVERRIDE;
66   virtual void TearDown() OVERRIDE;
67
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 {
73     return credentials_;
74   }
75   TokenAvailableTracker* success_tracker() { return &success_tracker_; }
76   TokenFailedTracker* failure_tracker() { return &failure_tracker_; }
77
78   void CreateSigninManager(const std::string& username);
79
80  private:
81   content::TestBrowserThreadBundle thread_bundle_;
82
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_;
91 };
92
93 #endif  // CHROME_BROWSER_SIGNIN_TOKEN_SERVICE_UNITTEST_H_