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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 net::HttpStatusCode status_code, | 63 net::HttpStatusCode status_code, |
63 const std::string& response_body) { | 64 const std::string& response_body) { |
64 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); | 65 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
65 ASSERT_TRUE(fetcher); | 66 ASSERT_TRUE(fetcher); |
66 fetcher->set_response_code(status_code); | 67 fetcher->set_response_code(status_code); |
67 fetcher->SetResponseString(response_body); | 68 fetcher->SetResponseString(response_body); |
68 } | 69 } |
69 | 70 |
70 void GCMChannelStatusRequestTest::SetResponseProtoData( | 71 void GCMChannelStatusRequestTest::SetResponseProtoData( |
71 GCMStatus status, int poll_interval_seconds) { | 72 GCMStatus status, int poll_interval_seconds) { |
72 gcm_proto::ExperimentStatusResponse response_proto; | 73 sync_pb::ExperimentStatusResponse response_proto; |
73 if (status != NOT_SPECIFIED) | 74 if (status != NOT_SPECIFIED) { |
74 response_proto.mutable_gcm_channel()->set_enabled(status == GCM_ENABLED); | 75 sync_pb::ExperimentsSpecifics* experiment_specifics = |
| 76 response_proto.add_experiment(); |
| 77 experiment_specifics->mutable_gcm_channel()->set_enabled(status == |
| 78 GCM_ENABLED); |
| 79 } |
75 | 80 |
76 // Zero |poll_interval_seconds| means the optional field is not set. | 81 // Zero |poll_interval_seconds| means the optional field is not set. |
77 if (poll_interval_seconds) | 82 if (poll_interval_seconds) |
78 response_proto.set_poll_interval_seconds(poll_interval_seconds); | 83 response_proto.set_poll_interval_seconds(poll_interval_seconds); |
79 | 84 |
80 std::string response_string; | 85 std::string response_string; |
81 response_proto.SerializeToString(&response_string); | 86 response_proto.SerializeToString(&response_string); |
82 SetResponseStatusAndString(net::HTTP_OK, response_string); | 87 SetResponseStatusAndString(net::HTTP_OK, response_string); |
83 } | 88 } |
84 | 89 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 StartRequest(); | 192 StartRequest(); |
188 SetResponseProtoData(GCM_DISABLED, poll_interval_seconds); | 193 SetResponseProtoData(GCM_DISABLED, poll_interval_seconds); |
189 CompleteFetch(); | 194 CompleteFetch(); |
190 | 195 |
191 EXPECT_TRUE(request_callback_invoked_); | 196 EXPECT_TRUE(request_callback_invoked_); |
192 EXPECT_FALSE(enabled_); | 197 EXPECT_FALSE(enabled_); |
193 EXPECT_EQ(poll_interval_seconds, poll_interval_seconds_); | 198 EXPECT_EQ(poll_interval_seconds, poll_interval_seconds_); |
194 } | 199 } |
195 | 200 |
196 } // namespace gcm | 201 } // namespace gcm |
OLD | NEW |