| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/message_loop/message_loop_proxy.h" | 12 #include "base/message_loop/message_loop_proxy.h" |
| 13 #include "base/metrics/field_trial.h" | 13 #include "base/metrics/field_trial.h" |
| 14 #include "base/prefs/pref_registry_simple.h" | 14 #include "base/prefs/pref_registry_simple.h" |
| 15 #include "base/prefs/testing_pref_service.h" | 15 #include "base/prefs/testing_pref_service.h" |
| 16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/test/test_simple_task_runner.h" | 18 #include "base/test/test_simple_task_runner.h" |
| 19 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
| 20 #include "components/gcm_driver/fake_gcm_app_handler.h" | 20 #include "components/gcm_driver/fake_gcm_app_handler.h" |
| 21 #include "components/gcm_driver/fake_gcm_client.h" | 21 #include "components/gcm_driver/fake_gcm_client.h" |
| 22 #include "components/gcm_driver/fake_gcm_client_factory.h" | 22 #include "components/gcm_driver/fake_gcm_client_factory.h" |
| 23 #include "components/gcm_driver/gcm_app_handler.h" | 23 #include "components/gcm_driver/gcm_app_handler.h" |
| 24 #include "components/gcm_driver/gcm_channel_status_request.h" | 24 #include "components/gcm_driver/gcm_channel_status_request.h" |
| 25 #include "components/gcm_driver/gcm_channel_status_syncer.h" | 25 #include "components/gcm_driver/gcm_channel_status_syncer.h" |
| 26 #include "components/gcm_driver/gcm_client_factory.h" | 26 #include "components/gcm_driver/gcm_client_factory.h" |
| 27 #include "components/gcm_driver/gcm_connection_observer.h" | 27 #include "components/gcm_driver/gcm_connection_observer.h" |
| 28 #include "components/gcm_driver/proto/gcm_channel_status.pb.h" | |
| 29 #include "net/url_request/test_url_fetcher_factory.h" | 28 #include "net/url_request/test_url_fetcher_factory.h" |
| 30 #include "net/url_request/url_fetcher_delegate.h" | 29 #include "net/url_request/url_fetcher_delegate.h" |
| 31 #include "net/url_request/url_request_context_getter.h" | 30 #include "net/url_request/url_request_context_getter.h" |
| 32 #include "net/url_request/url_request_test_util.h" | 31 #include "net/url_request/url_request_test_util.h" |
| 32 #include "sync/protocol/experiment_status.pb.h" |
| 33 #include "sync/protocol/experiments_specifics.pb.h" |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 34 | 35 |
| 35 namespace gcm { | 36 namespace gcm { |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| 39 const char kTestAccountID1[] = "user1@example.com"; | 40 const char kTestAccountID1[] = "user1@example.com"; |
| 40 const char kTestAccountID2[] = "user2@example.com"; | 41 const char kTestAccountID2[] = "user2@example.com"; |
| 41 const char kTestAppID1[] = "TestApp1"; | 42 const char kTestAppID1[] = "TestApp1"; |
| 42 const char kTestAppID2[] = "TestApp2"; | 43 const char kTestAppID2[] = "TestApp2"; |
| (...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 | 1016 |
| 1016 void GCMChannelStatusSyncerTest::SetUp() { | 1017 void GCMChannelStatusSyncerTest::SetUp() { |
| 1017 GCMDriverTest::SetUp(); | 1018 GCMDriverTest::SetUp(); |
| 1018 | 1019 |
| 1019 // Turn on all-user support. | 1020 // Turn on all-user support. |
| 1020 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("GCM", "Enabled")); | 1021 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("GCM", "Enabled")); |
| 1021 } | 1022 } |
| 1022 | 1023 |
| 1023 void GCMChannelStatusSyncerTest::CompleteGCMChannelStatusRequest( | 1024 void GCMChannelStatusSyncerTest::CompleteGCMChannelStatusRequest( |
| 1024 bool enabled, int poll_interval_seconds) { | 1025 bool enabled, int poll_interval_seconds) { |
| 1025 gcm_proto::ExperimentStatusResponse response_proto; | 1026 sync_pb::ExperimentStatusResponse response_proto; |
| 1026 response_proto.mutable_gcm_channel()->set_enabled(enabled); | 1027 sync_pb::ExperimentsSpecifics* experiment_specifics = |
| 1028 response_proto.add_experiment(); |
| 1029 experiment_specifics->mutable_gcm_channel()->set_enabled(enabled); |
| 1027 | 1030 |
| 1028 if (poll_interval_seconds) | 1031 if (poll_interval_seconds) |
| 1029 response_proto.set_poll_interval_seconds(poll_interval_seconds); | 1032 response_proto.set_poll_interval_seconds(poll_interval_seconds); |
| 1030 | 1033 |
| 1031 std::string response_string; | 1034 std::string response_string; |
| 1032 response_proto.SerializeToString(&response_string); | 1035 response_proto.SerializeToString(&response_string); |
| 1033 | 1036 |
| 1034 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); | 1037 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
| 1035 ASSERT_TRUE(fetcher); | 1038 ASSERT_TRUE(fetcher); |
| 1036 fetcher->set_response_code(net::HTTP_OK); | 1039 fetcher->set_response_code(net::HTTP_OK); |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1221 // After start-up, the request should still be scheduled at the expected | 1224 // After start-up, the request should still be scheduled at the expected |
| 1222 // updated interval. | 1225 // updated interval. |
| 1223 actual_delay_seconds = | 1226 actual_delay_seconds = |
| 1224 syncer()->current_request_delay_interval().InSeconds(); | 1227 syncer()->current_request_delay_interval().InSeconds(); |
| 1225 EXPECT_TRUE(CompareDelaySeconds(expected_delay_seconds, actual_delay_seconds)) | 1228 EXPECT_TRUE(CompareDelaySeconds(expected_delay_seconds, actual_delay_seconds)) |
| 1226 << "expected delay: " << expected_delay_seconds | 1229 << "expected delay: " << expected_delay_seconds |
| 1227 << " actual delay: " << actual_delay_seconds; | 1230 << " actual delay: " << actual_delay_seconds; |
| 1228 } | 1231 } |
| 1229 | 1232 |
| 1230 } // namespace gcm | 1233 } // namespace gcm |
| OLD | NEW |