Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: chrome/browser/chrome_to_mobile_service_unittest.cc

Issue 10861038: Revert 152609 - Integrate invalidation API into ChromeToMobileService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 RequestAccessToken method.
20 class MockChromeToMobileService : public ChromeToMobileService { 21 class MockChromeToMobileService : public ChromeToMobileService {
21 public: 22 public:
22 MockChromeToMobileService(); 23 MockChromeToMobileService();
23 ~MockChromeToMobileService(); 24 ~MockChromeToMobileService();
24 25
25 MOCK_METHOD0(RequestAccessToken, void()); 26 MOCK_METHOD0(RequestAccessToken, void());
26 27
27 private: 28 private:
28 DISALLOW_COPY_AND_ASSIGN(MockChromeToMobileService); 29 DISALLOW_COPY_AND_ASSIGN(MockChromeToMobileService);
29 }; 30 };
(...skipping 12 matching lines...) Expand all
42 MockChromeToMobileService service_; 43 MockChromeToMobileService service_;
43 44
44 private: 45 private:
45 DISALLOW_COPY_AND_ASSIGN(ChromeToMobileServiceTest); 46 DISALLOW_COPY_AND_ASSIGN(ChromeToMobileServiceTest);
46 }; 47 };
47 48
48 ChromeToMobileServiceTest::ChromeToMobileServiceTest() {} 49 ChromeToMobileServiceTest::ChromeToMobileServiceTest() {}
49 50
50 ChromeToMobileServiceTest::~ChromeToMobileServiceTest() {} 51 ChromeToMobileServiceTest::~ChromeToMobileServiceTest() {}
51 52
52 // Ensure that irrelevant notifications do not invalidate the access token. 53 // Ensure that RequestAccessToken is not called for irrelevant notifications.
53 TEST_F(ChromeToMobileServiceTest, IgnoreIrrelevantNotifications) { 54 TEST_F(ChromeToMobileServiceTest, IgnoreIrrelevantNotifications) {
54 EXPECT_CALL(service_, RequestAccessToken()).Times(0); 55 EXPECT_CALL(service_, RequestAccessToken()).Times(0);
55 56
56 service_.SetAccessTokenForTest(kDummyString); 57 // Send dummy service/token details (should not refresh token).
57 ASSERT_FALSE(service_.GetAccessTokenForTest().empty());
58
59 // Send dummy service/token details (should not request token).
60 DummyNotificationSource dummy_source; 58 DummyNotificationSource dummy_source;
61 TokenService::TokenAvailableDetails dummy_details(kDummyString, kDummyString); 59 TokenService::TokenAvailableDetails dummy_details(kDummyString, kDummyString);
62 service_.Observe(chrome::NOTIFICATION_TOKEN_AVAILABLE, 60 service_.Observe(chrome::NOTIFICATION_TOKEN_AVAILABLE,
63 content::Source<DummyNotificationSource>(&dummy_source), 61 content::Source<DummyNotificationSource>(&dummy_source),
64 content::Details<TokenService::TokenAvailableDetails>(&dummy_details)); 62 content::Details<TokenService::TokenAvailableDetails>(&dummy_details));
65 EXPECT_FALSE(service_.GetAccessTokenForTest().empty());
66 } 63 }
67 64
68 // Ensure that proper notifications invalidate the access token. 65 // Ensure that RequestAccessToken is called on the proper notification.
69 TEST_F(ChromeToMobileServiceTest, AuthenticateOnTokenAvailable) { 66 TEST_F(ChromeToMobileServiceTest, AuthenticateOnTokenAvailable) {
70 EXPECT_CALL(service_, RequestAccessToken()).Times(0); 67 EXPECT_CALL(service_, RequestAccessToken()).Times(1);
71 68
72 service_.SetAccessTokenForTest(kDummyString); 69 // Send a Gaia OAuth2 Login service dummy token (should refresh token).
73 ASSERT_FALSE(service_.GetAccessTokenForTest().empty());
74
75 // Send a Gaia OAuth2 Login service dummy token (should request token).
76 DummyNotificationSource dummy_source; 70 DummyNotificationSource dummy_source;
77 TokenService::TokenAvailableDetails login_details( 71 TokenService::TokenAvailableDetails login_details(
78 GaiaConstants::kGaiaOAuth2LoginRefreshToken, kDummyString); 72 GaiaConstants::kGaiaOAuth2LoginRefreshToken, kDummyString);
79 service_.Observe(chrome::NOTIFICATION_TOKEN_AVAILABLE, 73 service_.Observe(chrome::NOTIFICATION_TOKEN_AVAILABLE,
80 content::Source<DummyNotificationSource>(&dummy_source), 74 content::Source<DummyNotificationSource>(&dummy_source),
81 content::Details<TokenService::TokenAvailableDetails>(&login_details)); 75 content::Details<TokenService::TokenAvailableDetails>(&login_details));
82 EXPECT_TRUE(service_.GetAccessTokenForTest().empty());
83 } 76 }
84 77
85 } // namespace 78 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/chrome_to_mobile_service_factory.cc ('k') | chrome/browser/ui/cocoa/chrome_to_mobile_bubble_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698