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/domain_reliability/uploader.h" | 5 #include "components/domain_reliability/uploader.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 class DomainReliabilityUploaderTest : public testing::Test { | 22 class DomainReliabilityUploaderTest : public testing::Test { |
23 protected: | 23 protected: |
24 DomainReliabilityUploaderTest() | 24 DomainReliabilityUploaderTest() |
25 : test_browser_thread_bundle_( | 25 : test_browser_thread_bundle_( |
26 content::TestBrowserThreadBundle::IO_MAINLOOP), | 26 content::TestBrowserThreadBundle::IO_MAINLOOP), |
27 url_request_context_getter_(new net::TestURLRequestContextGetter( | 27 url_request_context_getter_(new net::TestURLRequestContextGetter( |
28 base::MessageLoopProxy::current())), | 28 base::MessageLoopProxy::current())), |
29 uploader_(DomainReliabilityUploader::Create( | 29 uploader_(DomainReliabilityUploader::Create( |
30 url_request_context_getter_)) {} | 30 url_request_context_getter_)) {} |
31 | 31 |
32 DomainReliabilityUploader::UploadCallback MakeUploadCallback(int index) { | 32 DomainReliabilityUploader::UploadCallback MakeUploadCallback(size_t index) { |
33 return base::Bind(&DomainReliabilityUploaderTest::OnUploadComplete, | 33 return base::Bind(&DomainReliabilityUploaderTest::OnUploadComplete, |
34 base::Unretained(this), | 34 base::Unretained(this), |
35 index); | 35 index); |
36 } | 36 } |
37 | 37 |
38 void OnUploadComplete(int index, bool success) { | 38 void OnUploadComplete(size_t index, bool success) { |
39 EXPECT_FALSE(upload_complete_[index]); | 39 EXPECT_FALSE(upload_complete_[index]); |
40 upload_complete_[index] = true; | 40 upload_complete_[index] = true; |
41 upload_successful_[index] = success; | 41 upload_successful_[index] = success; |
42 } | 42 } |
43 | 43 |
44 content::TestBrowserThreadBundle test_browser_thread_bundle_; | 44 content::TestBrowserThreadBundle test_browser_thread_bundle_; |
45 net::TestURLFetcherFactory url_fetcher_factory_; | 45 net::TestURLFetcherFactory url_fetcher_factory_; |
46 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_; | 46 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_; |
47 scoped_ptr<DomainReliabilityUploader> uploader_; | 47 scoped_ptr<DomainReliabilityUploader> uploader_; |
48 | 48 |
49 std::map<int, bool> upload_complete_; | 49 // Whether the upload callback was called for a particular collector index. |
50 std::map<int, bool> upload_successful_; | 50 std::map<size_t, bool> upload_complete_; |
| 51 // Whether the upload to a particular collector was successful. |
| 52 std::map<size_t, bool> upload_successful_; |
51 }; | 53 }; |
52 | 54 |
53 TEST_F(DomainReliabilityUploaderTest, Create) { | 55 TEST_F(DomainReliabilityUploaderTest, Create) { |
54 net::TestURLFetcher* fetcher; | 56 net::TestURLFetcher* fetcher; |
55 | 57 |
56 fetcher = url_fetcher_factory_.GetFetcherByID(0); | 58 fetcher = url_fetcher_factory_.GetFetcherByID(0); |
57 EXPECT_FALSE(fetcher); | 59 EXPECT_FALSE(fetcher); |
58 } | 60 } |
59 | 61 |
60 TEST_F(DomainReliabilityUploaderTest, SuccessfulUpload) { | 62 TEST_F(DomainReliabilityUploaderTest, SuccessfulUpload) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 fetcher->set_response_code(500); | 99 fetcher->set_response_code(500); |
98 fetcher->SetResponseString(""); | 100 fetcher->SetResponseString(""); |
99 | 101 |
100 EXPECT_FALSE(upload_complete_[0]); | 102 EXPECT_FALSE(upload_complete_[0]); |
101 fetcher->delegate()->OnURLFetchComplete(fetcher); | 103 fetcher->delegate()->OnURLFetchComplete(fetcher); |
102 EXPECT_TRUE(upload_complete_[0]); | 104 EXPECT_TRUE(upload_complete_[0]); |
103 EXPECT_FALSE(upload_successful_[0]); | 105 EXPECT_FALSE(upload_successful_[0]); |
104 } | 106 } |
105 | 107 |
106 } // namespace domain_reliability | 108 } // namespace domain_reliability |
OLD | NEW |