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 #include "chrome/browser/chrome_to_mobile_service.h" | 5 #include "chrome/browser/chrome_to_mobile_service.h" |
6 | 6 |
7 #include "chrome/browser/signin/token_service.h" | 7 #include "chrome/browser/signin/token_service.h" |
8 #include "chrome/common/chrome_notification_types.h" | 8 #include "chrome/common/chrome_notification_types.h" |
9 #include "chrome/common/net/gaia/gaia_constants.h" | 9 #include "chrome/common/net/gaia/gaia_constants.h" |
10 #include "content/public/browser/notification_details.h" | 10 #include "content/public/browser/notification_details.h" |
11 #include "content/public/browser/notification_source.h" | 11 #include "content/public/browser/notification_source.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 const char kDummyString[] = "dummy"; | 16 const char kDummyString[] = "dummy"; |
17 | 17 |
18 class DummyNotificationSource {}; | 18 class DummyNotificationSource {}; |
19 | 19 |
20 // A mock ChromeToMobileService with a mocked out RefreshAccessToken method. | 20 // A mock ChromeToMobileService with a mocked out RequestAccessToken method. |
21 class MockChromeToMobileService : public ChromeToMobileService { | 21 class MockChromeToMobileService : public ChromeToMobileService { |
22 public: | 22 public: |
23 MockChromeToMobileService(); | 23 MockChromeToMobileService(); |
24 ~MockChromeToMobileService(); | 24 ~MockChromeToMobileService(); |
25 | 25 |
26 MOCK_METHOD0(RefreshAccessToken, void()); | 26 MOCK_METHOD0(RequestAccessToken, void()); |
27 | 27 |
28 private: | 28 private: |
29 DISALLOW_COPY_AND_ASSIGN(MockChromeToMobileService); | 29 DISALLOW_COPY_AND_ASSIGN(MockChromeToMobileService); |
30 }; | 30 }; |
31 | 31 |
32 MockChromeToMobileService::MockChromeToMobileService() | 32 MockChromeToMobileService::MockChromeToMobileService() |
33 : ChromeToMobileService(NULL) {} | 33 : ChromeToMobileService(NULL) {} |
34 | 34 |
35 MockChromeToMobileService::~MockChromeToMobileService() {} | 35 MockChromeToMobileService::~MockChromeToMobileService() {} |
36 | 36 |
37 class ChromeToMobileServiceTest : public testing::Test { | 37 class ChromeToMobileServiceTest : public testing::Test { |
38 public: | 38 public: |
39 ChromeToMobileServiceTest(); | 39 ChromeToMobileServiceTest(); |
40 virtual ~ChromeToMobileServiceTest(); | 40 virtual ~ChromeToMobileServiceTest(); |
41 | 41 |
42 protected: | 42 protected: |
43 MockChromeToMobileService service_; | 43 MockChromeToMobileService service_; |
44 | 44 |
45 private: | 45 private: |
46 DISALLOW_COPY_AND_ASSIGN(ChromeToMobileServiceTest); | 46 DISALLOW_COPY_AND_ASSIGN(ChromeToMobileServiceTest); |
47 }; | 47 }; |
48 | 48 |
49 ChromeToMobileServiceTest::ChromeToMobileServiceTest() {} | 49 ChromeToMobileServiceTest::ChromeToMobileServiceTest() {} |
50 | 50 |
51 ChromeToMobileServiceTest::~ChromeToMobileServiceTest() {} | 51 ChromeToMobileServiceTest::~ChromeToMobileServiceTest() {} |
52 | 52 |
53 // Ensure that RefreshAccessToken is not called for irrelevant notifications. | 53 // Ensure that RequestAccessToken is not called for irrelevant notifications. |
54 TEST_F(ChromeToMobileServiceTest, IgnoreIrrelevantNotifications) { | 54 TEST_F(ChromeToMobileServiceTest, IgnoreIrrelevantNotifications) { |
55 EXPECT_CALL(service_, RefreshAccessToken()).Times(0); | 55 EXPECT_CALL(service_, RequestAccessToken()).Times(0); |
56 | 56 |
57 // Send dummy service/token details (should not refresh token). | 57 // Send dummy service/token details (should not refresh token). |
58 DummyNotificationSource dummy_source; | 58 DummyNotificationSource dummy_source; |
59 TokenService::TokenAvailableDetails dummy_details(kDummyString, kDummyString); | 59 TokenService::TokenAvailableDetails dummy_details(kDummyString, kDummyString); |
60 service_.Observe(chrome::NOTIFICATION_TOKEN_AVAILABLE, | 60 service_.Observe(chrome::NOTIFICATION_TOKEN_AVAILABLE, |
61 content::Source<DummyNotificationSource>(&dummy_source), | 61 content::Source<DummyNotificationSource>(&dummy_source), |
62 content::Details<TokenService::TokenAvailableDetails>(&dummy_details)); | 62 content::Details<TokenService::TokenAvailableDetails>(&dummy_details)); |
63 } | 63 } |
64 | 64 |
65 // Ensure that RefreshAccessToken is called on the proper notification. | 65 // Ensure that RequestAccessToken is called on the proper notification. |
66 TEST_F(ChromeToMobileServiceTest, AuthenticateOnTokenAvailable) { | 66 TEST_F(ChromeToMobileServiceTest, AuthenticateOnTokenAvailable) { |
67 EXPECT_CALL(service_, RefreshAccessToken()).Times(1); | 67 EXPECT_CALL(service_, RequestAccessToken()).Times(1); |
68 | 68 |
69 // Send a Gaia OAuth2 Login service dummy token (should refresh token). | 69 // Send a Gaia OAuth2 Login service dummy token (should refresh token). |
70 DummyNotificationSource dummy_source; | 70 DummyNotificationSource dummy_source; |
71 TokenService::TokenAvailableDetails login_details( | 71 TokenService::TokenAvailableDetails login_details( |
72 GaiaConstants::kGaiaOAuth2LoginRefreshToken, kDummyString); | 72 GaiaConstants::kGaiaOAuth2LoginRefreshToken, kDummyString); |
73 service_.Observe(chrome::NOTIFICATION_TOKEN_AVAILABLE, | 73 service_.Observe(chrome::NOTIFICATION_TOKEN_AVAILABLE, |
74 content::Source<DummyNotificationSource>(&dummy_source), | 74 content::Source<DummyNotificationSource>(&dummy_source), |
75 content::Details<TokenService::TokenAvailableDetails>(&login_details)); | 75 content::Details<TokenService::TokenAvailableDetails>(&login_details)); |
76 } | 76 } |
77 | 77 |
78 } // namespace | 78 } // namespace |
OLD | NEW |