| 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 "net/url_request/test_url_fetcher_factory.h" | 7 #include "net/url_request/test_url_fetcher_factory.h" |
| 8 #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" | 9 #include "sync/protocol/experiment_status.pb.h" |
| 10 #include "sync/protocol/experiments_specifics.pb.h" | 10 #include "sync/protocol/experiments_specifics.pb.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 101 } |
| 102 | 102 |
| 103 void GCMChannelStatusRequestTest::OnRequestCompleted( | 103 void GCMChannelStatusRequestTest::OnRequestCompleted( |
| 104 bool update_received, bool enabled, int poll_interval_seconds) { | 104 bool update_received, bool enabled, int poll_interval_seconds) { |
| 105 request_callback_invoked_ = true; | 105 request_callback_invoked_ = true; |
| 106 update_received_ = update_received; | 106 update_received_ = update_received; |
| 107 enabled_ = enabled; | 107 enabled_ = enabled; |
| 108 poll_interval_seconds_ = poll_interval_seconds; | 108 poll_interval_seconds_ = poll_interval_seconds; |
| 109 } | 109 } |
| 110 | 110 |
| 111 TEST_F(GCMChannelStatusRequestTest, RequestData) { |
| 112 StartRequest(); |
| 113 |
| 114 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
| 115 ASSERT_TRUE(fetcher); |
| 116 |
| 117 EXPECT_EQ(GURL(request_->channel_status_request_url_), |
| 118 fetcher->GetOriginalURL()); |
| 119 |
| 120 net::HttpRequestHeaders headers; |
| 121 fetcher->GetExtraRequestHeaders(&headers); |
| 122 std::string user_agent_header; |
| 123 headers.GetHeader("User-Agent", &user_agent_header); |
| 124 EXPECT_FALSE(user_agent_header.empty()); |
| 125 EXPECT_EQ(request_->user_agent_, user_agent_header); |
| 126 |
| 127 std::string upload_data = fetcher->upload_data(); |
| 128 EXPECT_FALSE(upload_data.empty()); |
| 129 sync_pb::ExperimentStatusRequest proto_data; |
| 130 proto_data.ParseFromString(upload_data); |
| 131 EXPECT_EQ(1, proto_data.experiment_name_size()); |
| 132 EXPECT_EQ("gcm_channel", proto_data.experiment_name(0)); |
| 133 } |
| 134 |
| 111 TEST_F(GCMChannelStatusRequestTest, ResponseHttpStatusNotOK) { | 135 TEST_F(GCMChannelStatusRequestTest, ResponseHttpStatusNotOK) { |
| 112 StartRequest(); | 136 StartRequest(); |
| 113 SetResponseStatusAndString(net::HTTP_UNAUTHORIZED, ""); | 137 SetResponseStatusAndString(net::HTTP_UNAUTHORIZED, ""); |
| 114 CompleteFetch(); | 138 CompleteFetch(); |
| 115 | 139 |
| 116 EXPECT_FALSE(request_callback_invoked_); | 140 EXPECT_FALSE(request_callback_invoked_); |
| 117 } | 141 } |
| 118 | 142 |
| 119 TEST_F(GCMChannelStatusRequestTest, ResponseEmpty) { | 143 TEST_F(GCMChannelStatusRequestTest, ResponseEmpty) { |
| 120 StartRequest(); | 144 StartRequest(); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 SetResponseProtoData(GCM_DISABLED, poll_interval_seconds); | 230 SetResponseProtoData(GCM_DISABLED, poll_interval_seconds); |
| 207 CompleteFetch(); | 231 CompleteFetch(); |
| 208 | 232 |
| 209 EXPECT_TRUE(request_callback_invoked_); | 233 EXPECT_TRUE(request_callback_invoked_); |
| 210 EXPECT_TRUE(update_received_); | 234 EXPECT_TRUE(update_received_); |
| 211 EXPECT_FALSE(enabled_); | 235 EXPECT_FALSE(enabled_); |
| 212 EXPECT_EQ(poll_interval_seconds, poll_interval_seconds_); | 236 EXPECT_EQ(poll_interval_seconds, poll_interval_seconds_); |
| 213 } | 237 } |
| 214 | 238 |
| 215 } // namespace gcm | 239 } // namespace gcm |
| OLD | NEW |