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

Unified Diff: chrome/browser/invalidation/gcm_invalidation_bridge_unittest.cc

Issue 334253006: Notify SyncNetworkChannel about GCM connection state (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed typo 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/invalidation/gcm_invalidation_bridge.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/invalidation/gcm_invalidation_bridge_unittest.cc
diff --git a/chrome/browser/invalidation/gcm_invalidation_bridge_unittest.cc b/chrome/browser/invalidation/gcm_invalidation_bridge_unittest.cc
index b484a4a0fbdfb37c7a8479358e16f2e90289c967..b263baa768aedfbbe148f15ca9f715550cd33cfc 100644
--- a/chrome/browser/invalidation/gcm_invalidation_bridge_unittest.cc
+++ b/chrome/browser/invalidation/gcm_invalidation_bridge_unittest.cc
@@ -13,6 +13,7 @@
#include "content/public/test/test_browser_thread_bundle.h"
#include "google_apis/gaia/fake_identity_provider.h"
#include "google_apis/gaia/google_service_auth_error.h"
+#include "net/base/ip_endpoint.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace invalidation {
@@ -45,7 +46,9 @@ class CustomFakeGCMDriver : public gcm::FakeGCMDriver {
class GCMInvalidationBridgeTest : public ::testing::Test {
protected:
- GCMInvalidationBridgeTest() {}
+ GCMInvalidationBridgeTest()
+ : connection_state_(
+ syncer::GCMNetworkChannelDelegate::CONNECTION_STATE_OFFLINE) {}
virtual ~GCMInvalidationBridgeTest() {}
@@ -66,7 +69,13 @@ class GCMInvalidationBridgeTest : public ::testing::Test {
identity_provider_.get()));
delegate_ = bridge_->CreateDelegate();
- delegate_->Initialize();
+ delegate_->Initialize(
+ base::Bind(&GCMInvalidationBridgeTest::ConnectionStateChanged,
+ base::Unretained(this)));
+ RunLoop();
+ }
+
+ void RunLoop() {
base::RunLoop run_loop;
run_loop.RunUntilIdle();
}
@@ -83,6 +92,11 @@ class GCMInvalidationBridgeTest : public ::testing::Test {
request_token_errors_.push_back(error);
}
+ void ConnectionStateChanged(
+ syncer::GCMNetworkChannelDelegate::ConnectionState connection_state) {
+ connection_state_ = connection_state;
+ }
+
content::TestBrowserThreadBundle thread_bundle_;
scoped_ptr<Profile> profile_;
scoped_ptr<gcm::GCMDriver> gcm_driver_;
@@ -91,6 +105,7 @@ class GCMInvalidationBridgeTest : public ::testing::Test {
std::vector<std::string> issued_tokens_;
std::vector<GoogleServiceAuthError> request_token_errors_;
std::string registration_id_;
+ syncer::GCMNetworkChannelDelegate::ConnectionState connection_state_;
scoped_ptr<GCMInvalidationBridge> bridge_;
scoped_ptr<syncer::GCMNetworkChannelDelegate> delegate_;
@@ -102,8 +117,7 @@ TEST_F(GCMInvalidationBridgeTest, RequestToken) {
delegate_->RequestToken(
base::Bind(&GCMInvalidationBridgeTest::RequestTokenFinished,
base::Unretained(this)));
- base::RunLoop run_loop;
- run_loop.RunUntilIdle();
+ RunLoop();
EXPECT_EQ(1U, issued_tokens_.size());
EXPECT_NE("", issued_tokens_[0]);
EXPECT_EQ(GoogleServiceAuthError::AuthErrorNone(), request_token_errors_[0]);
@@ -118,8 +132,7 @@ TEST_F(GCMInvalidationBridgeTest, RequestTokenTwoConcurrentRequests) {
delegate_->RequestToken(
base::Bind(&GCMInvalidationBridgeTest::RequestTokenFinished,
base::Unretained(this)));
- base::RunLoop run_loop;
- run_loop.RunUntilIdle();
+ RunLoop();
EXPECT_EQ(2U, issued_tokens_.size());
@@ -135,11 +148,23 @@ TEST_F(GCMInvalidationBridgeTest, Register) {
EXPECT_TRUE(registration_id_.empty());
delegate_->Register(base::Bind(&GCMInvalidationBridgeTest::RegisterFinished,
base::Unretained(this)));
- base::RunLoop run_loop;
- run_loop.RunUntilIdle();
+ RunLoop();
EXPECT_FALSE(registration_id_.empty());
}
+TEST_F(GCMInvalidationBridgeTest, ConnectionState) {
+ EXPECT_EQ(syncer::GCMNetworkChannelDelegate::CONNECTION_STATE_OFFLINE,
+ connection_state_);
+ bridge_->OnConnected(net::IPEndPoint());
+ RunLoop();
+ EXPECT_EQ(syncer::GCMNetworkChannelDelegate::CONNECTION_STATE_ONLINE,
+ connection_state_);
+ bridge_->OnDisconnected();
+ RunLoop();
+ EXPECT_EQ(syncer::GCMNetworkChannelDelegate::CONNECTION_STATE_OFFLINE,
+ connection_state_);
+}
+
} // namespace
} // namespace invalidation
« 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