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/rappor/log_uploader.h" | 5 #include "components/rappor/log_uploader.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
9 #include "net/url_request/test_url_fetcher_factory.h" | 9 #include "net/url_request/test_url_fetcher_factory.h" |
10 #include "net/url_request/url_request_test_util.h" | 10 #include "net/url_request/url_request_test_util.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 protected: | 63 protected: |
64 // Required for base::MessageLoopProxy::current(). | 64 // Required for base::MessageLoopProxy::current(). |
65 base::MessageLoopForUI loop_; | 65 base::MessageLoopForUI loop_; |
66 scoped_refptr<net::TestURLRequestContextGetter> request_context_; | 66 scoped_refptr<net::TestURLRequestContextGetter> request_context_; |
67 net::FakeURLFetcherFactory factory_; | 67 net::FakeURLFetcherFactory factory_; |
68 | 68 |
69 DISALLOW_COPY_AND_ASSIGN(LogUploaderTest); | 69 DISALLOW_COPY_AND_ASSIGN(LogUploaderTest); |
70 }; | 70 }; |
71 | 71 |
72 TEST_F(LogUploaderTest, Success) { | 72 TEST_F(LogUploaderTest, Success) { |
73 TestLogUploader uploader(request_context_); | 73 TestLogUploader uploader(request_context_.get()); |
74 | 74 |
75 factory_.SetFakeResponse(GURL(kTestServerURL), | 75 factory_.SetFakeResponse(GURL(kTestServerURL), |
76 std::string(), | 76 std::string(), |
77 net::HTTP_OK, | 77 net::HTTP_OK, |
78 net::URLRequestStatus::SUCCESS); | 78 net::URLRequestStatus::SUCCESS); |
79 | 79 |
80 uploader.QueueLog("log1"); | 80 uploader.QueueLog("log1"); |
81 base::MessageLoop::current()->RunUntilIdle(); | 81 base::MessageLoop::current()->RunUntilIdle(); |
82 // Log should be discarded instead of retransmitted. | 82 // Log should be discarded instead of retransmitted. |
83 EXPECT_EQ(uploader.last_interval_set(), base::TimeDelta()); | 83 EXPECT_EQ(uploader.last_interval_set(), base::TimeDelta()); |
84 } | 84 } |
85 | 85 |
86 TEST_F(LogUploaderTest, Rejection) { | 86 TEST_F(LogUploaderTest, Rejection) { |
87 TestLogUploader uploader(request_context_); | 87 TestLogUploader uploader(request_context_.get()); |
88 | 88 |
89 factory_.SetFakeResponse(GURL(kTestServerURL), | 89 factory_.SetFakeResponse(GURL(kTestServerURL), |
90 std::string(), | 90 std::string(), |
91 net::HTTP_BAD_REQUEST, | 91 net::HTTP_BAD_REQUEST, |
92 net::URLRequestStatus::SUCCESS); | 92 net::URLRequestStatus::SUCCESS); |
93 | 93 |
94 uploader.QueueLog("log1"); | 94 uploader.QueueLog("log1"); |
95 base::MessageLoop::current()->RunUntilIdle(); | 95 base::MessageLoop::current()->RunUntilIdle(); |
96 // Log should be discarded instead of retransmitted. | 96 // Log should be discarded instead of retransmitted. |
97 EXPECT_EQ(uploader.last_interval_set(), base::TimeDelta()); | 97 EXPECT_EQ(uploader.last_interval_set(), base::TimeDelta()); |
98 } | 98 } |
99 | 99 |
100 TEST_F(LogUploaderTest, Failure) { | 100 TEST_F(LogUploaderTest, Failure) { |
101 TestLogUploader uploader(request_context_); | 101 TestLogUploader uploader(request_context_.get()); |
102 | 102 |
103 factory_.SetFakeResponse(GURL(kTestServerURL), | 103 factory_.SetFakeResponse(GURL(kTestServerURL), |
104 std::string(), | 104 std::string(), |
105 net::HTTP_INTERNAL_SERVER_ERROR, | 105 net::HTTP_INTERNAL_SERVER_ERROR, |
106 net::URLRequestStatus::SUCCESS); | 106 net::URLRequestStatus::SUCCESS); |
107 | 107 |
108 uploader.QueueLog("log1"); | 108 uploader.QueueLog("log1"); |
109 base::MessageLoop::current()->RunUntilIdle(); | 109 base::MessageLoop::current()->RunUntilIdle(); |
110 // Log should be scheduled for retransmission. | 110 // Log should be scheduled for retransmission. |
111 base::TimeDelta error_interval = uploader.last_interval_set(); | 111 base::TimeDelta error_interval = uploader.last_interval_set(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 // Backoff until the maximum is reached. | 145 // Backoff until the maximum is reached. |
146 while (next > current) { | 146 while (next > current) { |
147 current = next; | 147 current = next; |
148 next = TestLogUploader::BackOff(current); | 148 next = TestLogUploader::BackOff(current); |
149 } | 149 } |
150 // Maximum backoff should have been reached. | 150 // Maximum backoff should have been reached. |
151 EXPECT_EQ(next, current); | 151 EXPECT_EQ(next, current); |
152 } | 152 } |
153 | 153 |
154 } // namespace rappor | 154 } // namespace rappor |
OLD | NEW |