OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <cmath> | 5 #include <cmath> |
6 | 6 |
7 #include "google_apis/gcm/engine/gcm_request_test_base.h" | 7 #include "google_apis/gcm/engine/gcm_request_test_base.h" |
8 #include "net/url_request/url_fetcher_delegate.h" | 8 #include "net/url_request/url_fetcher_delegate.h" |
9 | 9 |
10 namespace { | 10 namespace { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 fetcher->set_response_code(status_code); | 69 fetcher->set_response_code(status_code); |
70 fetcher->SetResponseString(response_body); | 70 fetcher->SetResponseString(response_body); |
71 } | 71 } |
72 | 72 |
73 void GCMRequestTestBase::CompleteFetch() { | 73 void GCMRequestTestBase::CompleteFetch() { |
74 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); | 74 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
75 ASSERT_TRUE(fetcher); | 75 ASSERT_TRUE(fetcher); |
76 fetcher->delegate()->OnURLFetchComplete(fetcher); | 76 fetcher->delegate()->OnURLFetchComplete(fetcher); |
77 } | 77 } |
78 | 78 |
| 79 void GCMRequestTestBase::VerifyFetcherUploadData( |
| 80 std::map<std::string, std::string>* expected_pairs) { |
| 81 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
| 82 ASSERT_TRUE(fetcher); |
| 83 |
| 84 // Verify data was formatted properly. |
| 85 std::string upload_data = fetcher->upload_data(); |
| 86 base::StringTokenizer data_tokenizer(upload_data, "&="); |
| 87 while (data_tokenizer.GetNext()) { |
| 88 auto iter = expected_pairs->find(data_tokenizer.token()); |
| 89 ASSERT_TRUE(iter != expected_pairs->end()) << data_tokenizer.token(); |
| 90 ASSERT_TRUE(data_tokenizer.GetNext()) << data_tokenizer.token(); |
| 91 ASSERT_EQ(iter->second, data_tokenizer.token()); |
| 92 // Ensure that none of the keys appears twice. |
| 93 expected_pairs->erase(iter); |
| 94 } |
| 95 |
| 96 ASSERT_EQ(0UL, expected_pairs->size()); |
| 97 } |
| 98 |
79 void GCMRequestTestBase::FastForwardToTriggerNextRetry() { | 99 void GCMRequestTestBase::FastForwardToTriggerNextRetry() { |
80 // Here we compute the maximum delay time by skipping the jitter fluctuation | 100 // Here we compute the maximum delay time by skipping the jitter fluctuation |
81 // that only affects in the negative way. | 101 // that only affects in the negative way. |
82 int next_retry_delay_ms = kDefaultBackoffPolicy.initial_delay_ms; | 102 int next_retry_delay_ms = kDefaultBackoffPolicy.initial_delay_ms; |
83 next_retry_delay_ms *= | 103 next_retry_delay_ms *= |
84 pow(kDefaultBackoffPolicy.multiply_factor, retry_count_); | 104 pow(kDefaultBackoffPolicy.multiply_factor, retry_count_); |
85 task_runner_->FastForwardBy( | 105 task_runner_->FastForwardBy( |
86 base::TimeDelta::FromMilliseconds(next_retry_delay_ms)); | 106 base::TimeDelta::FromMilliseconds(next_retry_delay_ms)); |
87 } | 107 } |
88 | 108 |
89 } // namespace gcm | 109 } // namespace gcm |
OLD | NEW |