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

Side by Side Diff: chrome/browser/invalidation/gcm_invalidation_bridge_unittest.cc

Issue 348503002: Report InvalidatorState correctly from GCMNetworkChannel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@GCM.ConnectionState
Patch Set: Fix SyncNetworkChannelTest Created 6 years, 6 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
« no previous file with comments | « no previous file | components/invalidation/gcm_invalidation_bridge.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/run_loop.h" 5 #include "base/run_loop.h"
6 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" 6 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
7 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" 7 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
8 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 8 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
9 #include "chrome/test/base/testing_profile.h" 9 #include "chrome/test/base/testing_profile.h"
10 #include "components/gcm_driver/fake_gcm_driver.h" 10 #include "components/gcm_driver/fake_gcm_driver.h"
(...skipping 29 matching lines...) Expand all
40 gcm::GCMClient::SUCCESS)); 40 gcm::GCMClient::SUCCESS));
41 } 41 }
42 42
43 private: 43 private:
44 DISALLOW_COPY_AND_ASSIGN(CustomFakeGCMDriver); 44 DISALLOW_COPY_AND_ASSIGN(CustomFakeGCMDriver);
45 }; 45 };
46 46
47 class GCMInvalidationBridgeTest : public ::testing::Test { 47 class GCMInvalidationBridgeTest : public ::testing::Test {
48 protected: 48 protected:
49 GCMInvalidationBridgeTest() 49 GCMInvalidationBridgeTest()
50 : connection_state_( 50 : connection_online_(false) {}
51 syncer::GCMNetworkChannelDelegate::CONNECTION_STATE_OFFLINE) {}
52 51
53 virtual ~GCMInvalidationBridgeTest() {} 52 virtual ~GCMInvalidationBridgeTest() {}
54 53
55 virtual void SetUp() OVERRIDE { 54 virtual void SetUp() OVERRIDE {
56 TestingProfile::Builder builder; 55 TestingProfile::Builder builder;
57 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(), 56 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(),
58 &BuildAutoIssuingFakeProfileOAuth2TokenService); 57 &BuildAutoIssuingFakeProfileOAuth2TokenService);
59 profile_ = builder.Build(); 58 profile_ = builder.Build();
60 59
61 FakeProfileOAuth2TokenService* token_service = 60 FakeProfileOAuth2TokenService* token_service =
(...skipping 23 matching lines...) Expand all
85 gcm::GCMClient::Result result) { 84 gcm::GCMClient::Result result) {
86 registration_id_ = registration_id; 85 registration_id_ = registration_id;
87 } 86 }
88 87
89 void RequestTokenFinished(const GoogleServiceAuthError& error, 88 void RequestTokenFinished(const GoogleServiceAuthError& error,
90 const std::string& token) { 89 const std::string& token) {
91 issued_tokens_.push_back(token); 90 issued_tokens_.push_back(token);
92 request_token_errors_.push_back(error); 91 request_token_errors_.push_back(error);
93 } 92 }
94 93
95 void ConnectionStateChanged( 94 void ConnectionStateChanged(bool online) {
96 syncer::GCMNetworkChannelDelegate::ConnectionState connection_state) { 95 connection_online_ = online;
97 connection_state_ = connection_state;
98 } 96 }
99 97
100 content::TestBrowserThreadBundle thread_bundle_; 98 content::TestBrowserThreadBundle thread_bundle_;
101 scoped_ptr<Profile> profile_; 99 scoped_ptr<Profile> profile_;
102 scoped_ptr<gcm::GCMDriver> gcm_driver_; 100 scoped_ptr<gcm::GCMDriver> gcm_driver_;
103 scoped_ptr<FakeIdentityProvider> identity_provider_; 101 scoped_ptr<FakeIdentityProvider> identity_provider_;
104 102
105 std::vector<std::string> issued_tokens_; 103 std::vector<std::string> issued_tokens_;
106 std::vector<GoogleServiceAuthError> request_token_errors_; 104 std::vector<GoogleServiceAuthError> request_token_errors_;
107 std::string registration_id_; 105 std::string registration_id_;
108 syncer::GCMNetworkChannelDelegate::ConnectionState connection_state_; 106 bool connection_online_;
109 107
110 scoped_ptr<GCMInvalidationBridge> bridge_; 108 scoped_ptr<GCMInvalidationBridge> bridge_;
111 scoped_ptr<syncer::GCMNetworkChannelDelegate> delegate_; 109 scoped_ptr<syncer::GCMNetworkChannelDelegate> delegate_;
112 }; 110 };
113 111
114 TEST_F(GCMInvalidationBridgeTest, RequestToken) { 112 TEST_F(GCMInvalidationBridgeTest, RequestToken) {
115 // Make sure that call to RequestToken reaches OAuth2TokenService and gets 113 // Make sure that call to RequestToken reaches OAuth2TokenService and gets
116 // back to callback. 114 // back to callback.
117 delegate_->RequestToken( 115 delegate_->RequestToken(
118 base::Bind(&GCMInvalidationBridgeTest::RequestTokenFinished, 116 base::Bind(&GCMInvalidationBridgeTest::RequestTokenFinished,
(...skipping 28 matching lines...) Expand all
147 TEST_F(GCMInvalidationBridgeTest, Register) { 145 TEST_F(GCMInvalidationBridgeTest, Register) {
148 EXPECT_TRUE(registration_id_.empty()); 146 EXPECT_TRUE(registration_id_.empty());
149 delegate_->Register(base::Bind(&GCMInvalidationBridgeTest::RegisterFinished, 147 delegate_->Register(base::Bind(&GCMInvalidationBridgeTest::RegisterFinished,
150 base::Unretained(this))); 148 base::Unretained(this)));
151 RunLoop(); 149 RunLoop();
152 150
153 EXPECT_FALSE(registration_id_.empty()); 151 EXPECT_FALSE(registration_id_.empty());
154 } 152 }
155 153
156 TEST_F(GCMInvalidationBridgeTest, ConnectionState) { 154 TEST_F(GCMInvalidationBridgeTest, ConnectionState) {
157 EXPECT_EQ(syncer::GCMNetworkChannelDelegate::CONNECTION_STATE_OFFLINE, 155 EXPECT_FALSE(connection_online_);
158 connection_state_);
159 bridge_->OnConnected(net::IPEndPoint()); 156 bridge_->OnConnected(net::IPEndPoint());
160 RunLoop(); 157 RunLoop();
161 EXPECT_EQ(syncer::GCMNetworkChannelDelegate::CONNECTION_STATE_ONLINE, 158 EXPECT_TRUE(connection_online_);
162 connection_state_);
163 bridge_->OnDisconnected(); 159 bridge_->OnDisconnected();
164 RunLoop(); 160 RunLoop();
165 EXPECT_EQ(syncer::GCMNetworkChannelDelegate::CONNECTION_STATE_OFFLINE, 161 EXPECT_FALSE(connection_online_);
166 connection_state_);
167 } 162 }
168 163
169 } // namespace 164 } // namespace
170 } // namespace invalidation 165 } // namespace invalidation
OLDNEW
« no previous file with comments | « no previous file | components/invalidation/gcm_invalidation_bridge.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698