| OLD | NEW |
| 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 "base/strings/string_util.h" | 6 #include "base/strings/string_util.h" |
| 7 #include "components/invalidation/gcm_network_channel.h" | 7 #include "components/invalidation/gcm_network_channel.h" |
| 8 #include "google_apis/gaia/google_service_auth_error.h" | 8 #include "google_apis/gaia/google_service_auth_error.h" |
| 9 #include "net/url_request/test_url_fetcher_factory.h" | 9 #include "net/url_request/test_url_fetcher_factory.h" |
| 10 #include "net/url_request/url_request_test_util.h" | 10 #include "net/url_request/url_request_test_util.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 118 |
| 119 class GCMNetworkChannelTest | 119 class GCMNetworkChannelTest |
| 120 : public ::testing::Test, | 120 : public ::testing::Test, |
| 121 public SyncNetworkChannel::Observer { | 121 public SyncNetworkChannel::Observer { |
| 122 public: | 122 public: |
| 123 GCMNetworkChannelTest() | 123 GCMNetworkChannelTest() |
| 124 : delegate_(NULL), | 124 : delegate_(NULL), |
| 125 url_fetchers_created_count_(0), | 125 url_fetchers_created_count_(0), |
| 126 last_invalidator_state_(TRANSIENT_INVALIDATION_ERROR) {} | 126 last_invalidator_state_(TRANSIENT_INVALIDATION_ERROR) {} |
| 127 | 127 |
| 128 virtual ~GCMNetworkChannelTest() { | 128 ~GCMNetworkChannelTest() override {} |
| 129 } | |
| 130 | 129 |
| 131 virtual void SetUp() { | 130 void SetUp() override { |
| 132 request_context_getter_ = new net::TestURLRequestContextGetter( | 131 request_context_getter_ = new net::TestURLRequestContextGetter( |
| 133 base::MessageLoopProxy::current()); | 132 base::MessageLoopProxy::current()); |
| 134 // Ownership of delegate goes to GCNMentworkChannel but test needs pointer | 133 // Ownership of delegate goes to GCNMentworkChannel but test needs pointer |
| 135 // to it. | 134 // to it. |
| 136 delegate_ = new TestGCMNetworkChannelDelegate(); | 135 delegate_ = new TestGCMNetworkChannelDelegate(); |
| 137 scoped_ptr<GCMNetworkChannelDelegate> delegate(delegate_); | 136 scoped_ptr<GCMNetworkChannelDelegate> delegate(delegate_); |
| 138 gcm_network_channel_.reset(new TestGCMNetworkChannel( | 137 gcm_network_channel_.reset(new TestGCMNetworkChannel( |
| 139 request_context_getter_, | 138 request_context_getter_, |
| 140 delegate.Pass())); | 139 delegate.Pass())); |
| 141 gcm_network_channel_->AddObserver(this); | 140 gcm_network_channel_->AddObserver(this); |
| 142 gcm_network_channel_->SetMessageReceiver( | 141 gcm_network_channel_->SetMessageReceiver( |
| 143 invalidation::NewPermanentCallback( | 142 invalidation::NewPermanentCallback( |
| 144 this, &GCMNetworkChannelTest::OnIncomingMessage)); | 143 this, &GCMNetworkChannelTest::OnIncomingMessage)); |
| 145 url_fetcher_factory_.reset(new net::FakeURLFetcherFactory(NULL, | 144 url_fetcher_factory_.reset(new net::FakeURLFetcherFactory(NULL, |
| 146 base::Bind(&GCMNetworkChannelTest::CreateURLFetcher, | 145 base::Bind(&GCMNetworkChannelTest::CreateURLFetcher, |
| 147 base::Unretained(this)))); | 146 base::Unretained(this)))); |
| 148 } | 147 } |
| 149 | 148 |
| 150 virtual void TearDown() { | 149 void TearDown() override { gcm_network_channel_->RemoveObserver(this); } |
| 151 gcm_network_channel_->RemoveObserver(this); | |
| 152 } | |
| 153 | 150 |
| 154 // Helper functions to call private methods from test | 151 // Helper functions to call private methods from test |
| 155 GURL BuildUrl(const std::string& registration_id) { | 152 GURL BuildUrl(const std::string& registration_id) { |
| 156 return gcm_network_channel_->GCMNetworkChannel::BuildUrl(registration_id); | 153 return gcm_network_channel_->GCMNetworkChannel::BuildUrl(registration_id); |
| 157 } | 154 } |
| 158 | 155 |
| 159 static void Base64EncodeURLSafe(const std::string& input, | 156 static void Base64EncodeURLSafe(const std::string& input, |
| 160 std::string* output) { | 157 std::string* output) { |
| 161 GCMNetworkChannel::Base64EncodeURLSafe(input, output); | 158 GCMNetworkChannel::Base64EncodeURLSafe(input, output); |
| 162 } | 159 } |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 delegate()->request_token_callback.Run( | 502 delegate()->request_token_callback.Run( |
| 506 GoogleServiceAuthError::AuthErrorNone(), "access.token"); | 503 GoogleServiceAuthError::AuthErrorNone(), "access.token"); |
| 507 RunLoopUntilIdle(); | 504 RunLoopUntilIdle(); |
| 508 EXPECT_EQ(url_fetchers_created_count(), 3); | 505 EXPECT_EQ(url_fetchers_created_count(), 3); |
| 509 // Echo_token should be from second message. | 506 // Echo_token should be from second message. |
| 510 EXPECT_EQ("echo.token", get_last_echo_token()); | 507 EXPECT_EQ("echo.token", get_last_echo_token()); |
| 511 } | 508 } |
| 512 #endif | 509 #endif |
| 513 | 510 |
| 514 } // namespace syncer | 511 } // namespace syncer |
| OLD | NEW |