Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(521)

Side by Side Diff: components/domain_reliability/uploader_unittest.cc

Issue 491753003: Domain Reliability: Don't upload when metrics reporting is off. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix pref handling Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 10 matching lines...) Expand all
21 namespace domain_reliability { 21 namespace domain_reliability {
22 namespace { 22 namespace {
23 23
24 class DomainReliabilityUploaderTest : public testing::Test { 24 class DomainReliabilityUploaderTest : public testing::Test {
25 protected: 25 protected:
26 DomainReliabilityUploaderTest() 26 DomainReliabilityUploaderTest()
27 : network_task_runner_(new base::TestSimpleTaskRunner()), 27 : network_task_runner_(new base::TestSimpleTaskRunner()),
28 url_request_context_getter_(new net::TestURLRequestContextGetter( 28 url_request_context_getter_(new net::TestURLRequestContextGetter(
29 network_task_runner_)), 29 network_task_runner_)),
30 uploader_(DomainReliabilityUploader::Create( 30 uploader_(DomainReliabilityUploader::Create(
31 url_request_context_getter_)) {} 31 url_request_context_getter_)) {
32 uploader_->set_discard_uploads(false);
33 }
32 34
33 DomainReliabilityUploader::UploadCallback MakeUploadCallback(size_t index) { 35 DomainReliabilityUploader::UploadCallback MakeUploadCallback(size_t index) {
34 return base::Bind(&DomainReliabilityUploaderTest::OnUploadComplete, 36 return base::Bind(&DomainReliabilityUploaderTest::OnUploadComplete,
35 base::Unretained(this), 37 base::Unretained(this),
36 index); 38 index);
37 } 39 }
38 40
39 void OnUploadComplete(size_t index, bool success) { 41 void OnUploadComplete(size_t index, bool success) {
40 EXPECT_FALSE(upload_complete_[index]); 42 EXPECT_FALSE(upload_complete_[index]);
41 upload_complete_[index] = true; 43 upload_complete_[index] = true;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 fetcher->set_status(net::URLRequestStatus()); 103 fetcher->set_status(net::URLRequestStatus());
102 fetcher->set_response_code(500); 104 fetcher->set_response_code(500);
103 fetcher->SetResponseString(""); 105 fetcher->SetResponseString("");
104 106
105 EXPECT_FALSE(upload_complete_[0]); 107 EXPECT_FALSE(upload_complete_[0]);
106 fetcher->delegate()->OnURLFetchComplete(fetcher); 108 fetcher->delegate()->OnURLFetchComplete(fetcher);
107 EXPECT_TRUE(upload_complete_[0]); 109 EXPECT_TRUE(upload_complete_[0]);
108 EXPECT_FALSE(upload_successful_[0]); 110 EXPECT_FALSE(upload_successful_[0]);
109 } 111 }
110 112
113 TEST_F(DomainReliabilityUploaderTest, DiscardedUpload) {
114 net::TestURLFetcher* fetcher;
115
116 uploader_->set_discard_uploads(true);
117
118 std::string report_json = "{}";
119 GURL upload_url = GURL("https://example/upload");
120 uploader_->UploadReport(report_json, upload_url, MakeUploadCallback(0));
121
122 fetcher = url_fetcher_factory_.GetFetcherByID(0);
123 EXPECT_FALSE(fetcher);
124 }
125
111 } // namespace 126 } // namespace
112 } // namespace domain_reliability 127 } // namespace domain_reliability
OLDNEW
« components/domain_reliability/monitor.cc ('K') | « components/domain_reliability/uploader.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698