| 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 "components/gcm_driver/gcm_driver_desktop.h" | 5 #include "components/gcm_driver/gcm_driver_desktop.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/metrics/field_trial.h" | |
| 15 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 16 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 17 #include "base/test/test_simple_task_runner.h" | 16 #include "base/test/test_simple_task_runner.h" |
| 18 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
| 19 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
| 20 #include "components/gcm_driver/crypto/gcm_encryption_provider.h" | 19 #include "components/gcm_driver/crypto/gcm_encryption_provider.h" |
| 21 #include "components/gcm_driver/fake_gcm_app_handler.h" | 20 #include "components/gcm_driver/fake_gcm_app_handler.h" |
| 22 #include "components/gcm_driver/fake_gcm_client.h" | 21 #include "components/gcm_driver/fake_gcm_client.h" |
| 23 #include "components/gcm_driver/fake_gcm_client_factory.h" | 22 #include "components/gcm_driver/fake_gcm_client_factory.h" |
| 24 #include "components/gcm_driver/gcm_app_handler.h" | 23 #include "components/gcm_driver/gcm_app_handler.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 } | 159 } |
| 161 void set_async_operation_completed_callback(const base::Closure& callback) { | 160 void set_async_operation_completed_callback(const base::Closure& callback) { |
| 162 async_operation_completed_callback_ = callback; | 161 async_operation_completed_callback_ = callback; |
| 163 } | 162 } |
| 164 | 163 |
| 165 private: | 164 private: |
| 166 base::ScopedTempDir temp_dir_; | 165 base::ScopedTempDir temp_dir_; |
| 167 TestingPrefServiceSimple prefs_; | 166 TestingPrefServiceSimple prefs_; |
| 168 base::MessageLoopForUI message_loop_; | 167 base::MessageLoopForUI message_loop_; |
| 169 base::Thread io_thread_; | 168 base::Thread io_thread_; |
| 170 base::FieldTrialList field_trial_list_; | |
| 171 scoped_ptr<GCMDriverDesktop> driver_; | 169 scoped_ptr<GCMDriverDesktop> driver_; |
| 172 scoped_ptr<FakeGCMAppHandler> gcm_app_handler_; | 170 scoped_ptr<FakeGCMAppHandler> gcm_app_handler_; |
| 173 scoped_ptr<FakeGCMConnectionObserver> gcm_connection_observer_; | 171 scoped_ptr<FakeGCMConnectionObserver> gcm_connection_observer_; |
| 174 | 172 |
| 175 base::Closure async_operation_completed_callback_; | 173 base::Closure async_operation_completed_callback_; |
| 176 | 174 |
| 177 std::string registration_id_; | 175 std::string registration_id_; |
| 178 GCMClient::Result registration_result_; | 176 GCMClient::Result registration_result_; |
| 179 std::string send_message_id_; | 177 std::string send_message_id_; |
| 180 GCMClient::Result send_result_; | 178 GCMClient::Result send_result_; |
| 181 GCMClient::Result unregistration_result_; | 179 GCMClient::Result unregistration_result_; |
| 182 std::string p256dh_; | 180 std::string p256dh_; |
| 183 std::string auth_secret_; | 181 std::string auth_secret_; |
| 184 | 182 |
| 185 DISALLOW_COPY_AND_ASSIGN(GCMDriverTest); | 183 DISALLOW_COPY_AND_ASSIGN(GCMDriverTest); |
| 186 }; | 184 }; |
| 187 | 185 |
| 188 GCMDriverTest::GCMDriverTest() | 186 GCMDriverTest::GCMDriverTest() |
| 189 : io_thread_("IOThread"), | 187 : io_thread_("IOThread"), |
| 190 field_trial_list_(NULL), | |
| 191 registration_result_(GCMClient::UNKNOWN_ERROR), | 188 registration_result_(GCMClient::UNKNOWN_ERROR), |
| 192 send_result_(GCMClient::UNKNOWN_ERROR), | 189 send_result_(GCMClient::UNKNOWN_ERROR), |
| 193 unregistration_result_(GCMClient::UNKNOWN_ERROR) { | 190 unregistration_result_(GCMClient::UNKNOWN_ERROR) { |
| 194 } | 191 } |
| 195 | 192 |
| 196 GCMDriverTest::~GCMDriverTest() { | 193 GCMDriverTest::~GCMDriverTest() { |
| 197 } | 194 } |
| 198 | 195 |
| 199 void GCMDriverTest::SetUp() { | 196 void GCMDriverTest::SetUp() { |
| 200 GCMChannelStatusSyncer::RegisterPrefs(prefs_.registry()); | 197 GCMChannelStatusSyncer::RegisterPrefs(prefs_.registry()); |
| (...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 943 GCMChannelStatusSyncerTest::GCMChannelStatusSyncerTest() { | 940 GCMChannelStatusSyncerTest::GCMChannelStatusSyncerTest() { |
| 944 } | 941 } |
| 945 | 942 |
| 946 GCMChannelStatusSyncerTest::~GCMChannelStatusSyncerTest() { | 943 GCMChannelStatusSyncerTest::~GCMChannelStatusSyncerTest() { |
| 947 } | 944 } |
| 948 | 945 |
| 949 void GCMChannelStatusSyncerTest::SetUp() { | 946 void GCMChannelStatusSyncerTest::SetUp() { |
| 950 GCMDriverTest::SetUp(); | 947 GCMDriverTest::SetUp(); |
| 951 | 948 |
| 952 url_fetcher_factory_.set_remove_fetcher_on_delete(true); | 949 url_fetcher_factory_.set_remove_fetcher_on_delete(true); |
| 953 | |
| 954 // Turn on all-user support. | |
| 955 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("GCM", "Enabled")); | |
| 956 } | 950 } |
| 957 | 951 |
| 958 void GCMChannelStatusSyncerTest::CompleteGCMChannelStatusRequest( | 952 void GCMChannelStatusSyncerTest::CompleteGCMChannelStatusRequest( |
| 959 bool enabled, int poll_interval_seconds) { | 953 bool enabled, int poll_interval_seconds) { |
| 960 sync_pb::ExperimentStatusResponse response_proto; | 954 sync_pb::ExperimentStatusResponse response_proto; |
| 961 sync_pb::ExperimentsSpecifics* experiment_specifics = | 955 sync_pb::ExperimentsSpecifics* experiment_specifics = |
| 962 response_proto.add_experiment(); | 956 response_proto.add_experiment(); |
| 963 experiment_specifics->mutable_gcm_channel()->set_enabled(enabled); | 957 experiment_specifics->mutable_gcm_channel()->set_enabled(enabled); |
| 964 | 958 |
| 965 if (poll_interval_seconds) | 959 if (poll_interval_seconds) |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1382 PumpUILoop(); | 1376 PumpUILoop(); |
| 1383 EXPECT_EQ(GCMClient::UNKNOWN_ERROR, unregistration_result()); | 1377 EXPECT_EQ(GCMClient::UNKNOWN_ERROR, unregistration_result()); |
| 1384 | 1378 |
| 1385 // DeleteToken operation will be invoked after GCMClient becomes ready. | 1379 // DeleteToken operation will be invoked after GCMClient becomes ready. |
| 1386 GetGCMClient()->PerformDelayedStart(); | 1380 GetGCMClient()->PerformDelayedStart(); |
| 1387 WaitForAsyncOperation(); | 1381 WaitForAsyncOperation(); |
| 1388 EXPECT_EQ(GCMClient::SUCCESS, unregistration_result()); | 1382 EXPECT_EQ(GCMClient::SUCCESS, unregistration_result()); |
| 1389 } | 1383 } |
| 1390 | 1384 |
| 1391 } // namespace gcm | 1385 } // namespace gcm |
| OLD | NEW |