| 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/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 #include "components/gcm_driver/gcm_channel_status_request.h" | 6 #include "components/gcm_driver/gcm_channel_status_request.h" |
| 7 #include "components/gcm_driver/proto/gcm_channel_status.pb.h" | |
| 8 #include "net/url_request/test_url_fetcher_factory.h" | 7 #include "net/url_request/test_url_fetcher_factory.h" |
| 9 #include "net/url_request/url_request_test_util.h" | 8 #include "net/url_request/url_request_test_util.h" |
| 9 #include "sync/protocol/experiment_status.pb.h" |
| 10 #include "sync/protocol/experiments_specifics.pb.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 12 |
| 12 namespace gcm { | 13 namespace gcm { |
| 13 | 14 |
| 14 class GCMChannelStatusRequestTest : public testing::Test { | 15 class GCMChannelStatusRequestTest : public testing::Test { |
| 15 public: | 16 public: |
| 16 GCMChannelStatusRequestTest(); | 17 GCMChannelStatusRequestTest(); |
| 17 virtual ~GCMChannelStatusRequestTest(); | 18 virtual ~GCMChannelStatusRequestTest(); |
| 18 | 19 |
| 19 protected: | 20 protected: |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 net::HttpStatusCode status_code, | 65 net::HttpStatusCode status_code, |
| 65 const std::string& response_body) { | 66 const std::string& response_body) { |
| 66 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); | 67 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
| 67 ASSERT_TRUE(fetcher); | 68 ASSERT_TRUE(fetcher); |
| 68 fetcher->set_response_code(status_code); | 69 fetcher->set_response_code(status_code); |
| 69 fetcher->SetResponseString(response_body); | 70 fetcher->SetResponseString(response_body); |
| 70 } | 71 } |
| 71 | 72 |
| 72 void GCMChannelStatusRequestTest::SetResponseProtoData( | 73 void GCMChannelStatusRequestTest::SetResponseProtoData( |
| 73 GCMStatus status, int poll_interval_seconds) { | 74 GCMStatus status, int poll_interval_seconds) { |
| 74 gcm_proto::ExperimentStatusResponse response_proto; | 75 sync_pb::ExperimentStatusResponse response_proto; |
| 75 if (status != NOT_SPECIFIED) | 76 if (status != NOT_SPECIFIED) { |
| 76 response_proto.mutable_gcm_channel()->set_enabled(status == GCM_ENABLED); | 77 sync_pb::ExperimentsSpecifics* experiment_specifics = |
| 78 response_proto.add_experiment(); |
| 79 experiment_specifics->mutable_gcm_channel()->set_enabled(status == |
| 80 GCM_ENABLED); |
| 81 } |
| 77 | 82 |
| 78 // Zero |poll_interval_seconds| means the optional field is not set. | 83 // Zero |poll_interval_seconds| means the optional field is not set. |
| 79 if (poll_interval_seconds) | 84 if (poll_interval_seconds) |
| 80 response_proto.set_poll_interval_seconds(poll_interval_seconds); | 85 response_proto.set_poll_interval_seconds(poll_interval_seconds); |
| 81 | 86 |
| 82 std::string response_string; | 87 std::string response_string; |
| 83 response_proto.SerializeToString(&response_string); | 88 response_proto.SerializeToString(&response_string); |
| 84 SetResponseStatusAndString(net::HTTP_OK, response_string); | 89 SetResponseStatusAndString(net::HTTP_OK, response_string); |
| 85 } | 90 } |
| 86 | 91 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 StartRequest(); | 194 StartRequest(); |
| 190 SetResponseProtoData(GCM_DISABLED, poll_interval_seconds); | 195 SetResponseProtoData(GCM_DISABLED, poll_interval_seconds); |
| 191 CompleteFetch(); | 196 CompleteFetch(); |
| 192 | 197 |
| 193 EXPECT_TRUE(request_callback_invoked_); | 198 EXPECT_TRUE(request_callback_invoked_); |
| 194 EXPECT_FALSE(enabled_); | 199 EXPECT_FALSE(enabled_); |
| 195 EXPECT_EQ(poll_interval_seconds, poll_interval_seconds_); | 200 EXPECT_EQ(poll_interval_seconds, poll_interval_seconds_); |
| 196 } | 201 } |
| 197 | 202 |
| 198 } // namespace gcm | 203 } // namespace gcm |
| OLD | NEW |