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

Side by Side Diff: components/update_client/ping_manager_unittest.cc

Issue 2888183003: Consolidate the update_client serialization code. (Closed)
Patch Set: wip Created 3 years, 7 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
« no previous file with comments | « components/update_client/ping_manager.cc ('k') | components/update_client/protocol_builder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/update_client/ping_manager.h" 5 #include "components/update_client/ping_manager.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
16 #include "base/version.h" 16 #include "base/version.h"
17 #include "components/update_client/component.h" 17 #include "components/update_client/component.h"
18 #include "components/update_client/protocol_builder.h"
18 #include "components/update_client/test_configurator.h" 19 #include "components/update_client/test_configurator.h"
19 #include "components/update_client/update_engine.h" 20 #include "components/update_client/update_engine.h"
20 #include "components/update_client/url_request_post_interceptor.h" 21 #include "components/update_client/url_request_post_interceptor.h"
21 #include "net/url_request/url_request_test_util.h" 22 #include "net/url_request/url_request_test_util.h"
22 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
23 24
24 using std::string; 25 using std::string;
25 26
26 namespace update_client { 27 namespace update_client {
27 28
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 80
80 // Test eventresult="1" is sent for successful updates. 81 // Test eventresult="1" is sent for successful updates.
81 const auto update_context = MakeFakeUpdateContext(); 82 const auto update_context = MakeFakeUpdateContext();
82 83
83 { 84 {
84 Component component(*update_context, "abc"); 85 Component component(*update_context, "abc");
85 86
86 component.state_ = base::MakeUnique<Component::StateUpdated>(&component); 87 component.state_ = base::MakeUnique<Component::StateUpdated>(&component);
87 component.previous_version_ = base::Version("1.0"); 88 component.previous_version_ = base::Version("1.0");
88 component.next_version_ = base::Version("2.0"); 89 component.next_version_ = base::Version("2.0");
90 component.AppendEvent(BuildUpdateCompleteEventElement(component));
89 91
90 ping_manager_->SendPing(component); 92 ping_manager_->SendPing(component);
91 base::RunLoop().RunUntilIdle(); 93 base::RunLoop().RunUntilIdle();
92 94
93 EXPECT_EQ(1, interceptor->GetCount()) << interceptor->GetRequestsAsString(); 95 EXPECT_EQ(1, interceptor->GetCount()) << interceptor->GetRequestsAsString();
94 EXPECT_NE(string::npos, 96 EXPECT_NE(string::npos,
95 interceptor->GetRequests()[0].find( 97 interceptor->GetRequests()[0].find(
96 "<app appid=\"abc\" version=\"1.0\" nextversion=\"2.0\">" 98 "<app appid=\"abc\" version=\"1.0\" nextversion=\"2.0\">"
97 "<event eventtype=\"3\" eventresult=\"1\"/></app>")) 99 "<event eventtype=\"3\" eventresult=\"1\"/></app>"))
98 << interceptor->GetRequestsAsString(); 100 << interceptor->GetRequestsAsString();
99 interceptor->Reset(); 101 interceptor->Reset();
100 } 102 }
101 103
102 { 104 {
103 // Test eventresult="0" is sent for failed updates. 105 // Test eventresult="0" is sent for failed updates.
104 Component component(*update_context, "abc"); 106 Component component(*update_context, "abc");
105 component.state_ = 107 component.state_ =
106 base::MakeUnique<Component::StateUpdateError>(&component); 108 base::MakeUnique<Component::StateUpdateError>(&component);
107 component.previous_version_ = base::Version("1.0"); 109 component.previous_version_ = base::Version("1.0");
108 component.next_version_ = base::Version("2.0"); 110 component.next_version_ = base::Version("2.0");
111 component.AppendEvent(BuildUpdateCompleteEventElement(component));
109 112
110 ping_manager_->SendPing(component); 113 ping_manager_->SendPing(component);
111 base::RunLoop().RunUntilIdle(); 114 base::RunLoop().RunUntilIdle();
112 115
113 EXPECT_EQ(1, interceptor->GetCount()) << interceptor->GetRequestsAsString(); 116 EXPECT_EQ(1, interceptor->GetCount()) << interceptor->GetRequestsAsString();
114 EXPECT_NE(string::npos, 117 EXPECT_NE(string::npos,
115 interceptor->GetRequests()[0].find( 118 interceptor->GetRequests()[0].find(
116 "<app appid=\"abc\" version=\"1.0\" nextversion=\"2.0\">" 119 "<app appid=\"abc\" version=\"1.0\" nextversion=\"2.0\">"
117 "<event eventtype=\"3\" eventresult=\"0\"/></app>")) 120 "<event eventtype=\"3\" eventresult=\"0\"/></app>"))
118 << interceptor->GetRequestsAsString(); 121 << interceptor->GetRequestsAsString();
119 interceptor->Reset(); 122 interceptor->Reset();
120 } 123 }
121 124
122 { 125 {
123 // Test the error values and the fingerprints. 126 // Test the error values and the fingerprints.
124 Component component(*update_context, "abc"); 127 Component component(*update_context, "abc");
125 component.state_ = 128 component.state_ =
126 base::MakeUnique<Component::StateUpdateError>(&component); 129 base::MakeUnique<Component::StateUpdateError>(&component);
127 component.previous_version_ = base::Version("1.0"); 130 component.previous_version_ = base::Version("1.0");
128 component.next_version_ = base::Version("2.0"); 131 component.next_version_ = base::Version("2.0");
129 component.previous_fp_ = "prev fp"; 132 component.previous_fp_ = "prev fp";
130 component.next_fp_ = "next fp"; 133 component.next_fp_ = "next fp";
131 component.error_category_ = 1; 134 component.error_category_ = 1;
132 component.error_code_ = 2; 135 component.error_code_ = 2;
133 component.extra_code1_ = -1; 136 component.extra_code1_ = -1;
134 component.diff_error_category_ = 10; 137 component.diff_error_category_ = 10;
135 component.diff_error_code_ = 20; 138 component.diff_error_code_ = 20;
136 component.diff_extra_code1_ = -10; 139 component.diff_extra_code1_ = -10;
137 component.crx_diffurls_.push_back(GURL("http://host/path")); 140 component.crx_diffurls_.push_back(GURL("http://host/path"));
141 component.AppendEvent(BuildUpdateCompleteEventElement(component));
138 142
139 ping_manager_->SendPing(component); 143 ping_manager_->SendPing(component);
140 base::RunLoop().RunUntilIdle(); 144 base::RunLoop().RunUntilIdle();
141 145
142 EXPECT_EQ(1, interceptor->GetCount()) << interceptor->GetRequestsAsString(); 146 EXPECT_EQ(1, interceptor->GetCount()) << interceptor->GetRequestsAsString();
143 EXPECT_NE(string::npos, 147 EXPECT_NE(string::npos,
144 interceptor->GetRequests()[0].find( 148 interceptor->GetRequests()[0].find(
145 "<app appid=\"abc\" version=\"1.0\" nextversion=\"2.0\">" 149 "<app appid=\"abc\" version=\"1.0\" nextversion=\"2.0\">"
146 "<event eventtype=\"3\" eventresult=\"0\" errorcat=\"1\" " 150 "<event eventtype=\"3\" eventresult=\"0\" errorcat=\"1\" "
147 "errorcode=\"2\" extracode1=\"-1\" diffresult=\"0\" " 151 "errorcode=\"2\" extracode1=\"-1\" diffresult=\"0\" "
148 "differrorcat=\"10\" " 152 "differrorcat=\"10\" "
149 "differrorcode=\"20\" diffextracode1=\"-10\" " 153 "differrorcode=\"20\" diffextracode1=\"-10\" "
150 "previousfp=\"prev fp\" nextfp=\"next fp\"/></app>")) 154 "previousfp=\"prev fp\" nextfp=\"next fp\"/></app>"))
151 << interceptor->GetRequestsAsString(); 155 << interceptor->GetRequestsAsString();
152 interceptor->Reset(); 156 interceptor->Reset();
153 } 157 }
154 158
155 { 159 {
156 // Test the download metrics. 160 // Test the download metrics.
157 Component component(*update_context, "abc"); 161 Component component(*update_context, "abc");
158 component.state_ = base::MakeUnique<Component::StateUpdated>(&component); 162 component.state_ = base::MakeUnique<Component::StateUpdated>(&component);
159 component.previous_version_ = base::Version("1.0"); 163 component.previous_version_ = base::Version("1.0");
160 component.next_version_ = base::Version("2.0"); 164 component.next_version_ = base::Version("2.0");
165 component.AppendEvent(BuildUpdateCompleteEventElement(component));
161 166
162 CrxDownloader::DownloadMetrics download_metrics; 167 CrxDownloader::DownloadMetrics download_metrics;
163 download_metrics.url = GURL("http://host1/path1"); 168 download_metrics.url = GURL("http://host1/path1");
164 download_metrics.downloader = CrxDownloader::DownloadMetrics::kUrlFetcher; 169 download_metrics.downloader = CrxDownloader::DownloadMetrics::kUrlFetcher;
165 download_metrics.error = -1; 170 download_metrics.error = -1;
166 download_metrics.downloaded_bytes = 123; 171 download_metrics.downloaded_bytes = 123;
167 download_metrics.total_bytes = 456; 172 download_metrics.total_bytes = 456;
168 download_metrics.download_time_ms = 987; 173 download_metrics.download_time_ms = 987;
169 component.download_metrics_.push_back(download_metrics); 174 component.AppendEvent(BuildDownloadCompleteEventElement(download_metrics));
170 175
171 download_metrics = CrxDownloader::DownloadMetrics(); 176 download_metrics = CrxDownloader::DownloadMetrics();
172 download_metrics.url = GURL("http://host2/path2"); 177 download_metrics.url = GURL("http://host2/path2");
173 download_metrics.downloader = CrxDownloader::DownloadMetrics::kBits; 178 download_metrics.downloader = CrxDownloader::DownloadMetrics::kBits;
174 download_metrics.error = 0; 179 download_metrics.error = 0;
175 download_metrics.downloaded_bytes = 1230; 180 download_metrics.downloaded_bytes = 1230;
176 download_metrics.total_bytes = 4560; 181 download_metrics.total_bytes = 4560;
177 download_metrics.download_time_ms = 9870; 182 download_metrics.download_time_ms = 9870;
178 component.download_metrics_.push_back(download_metrics); 183 component.AppendEvent(BuildDownloadCompleteEventElement(download_metrics));
179 184
180 ping_manager_->SendPing(component); 185 ping_manager_->SendPing(component);
181 base::RunLoop().RunUntilIdle(); 186 base::RunLoop().RunUntilIdle();
182 187
183 EXPECT_EQ(1, interceptor->GetCount()) << interceptor->GetRequestsAsString(); 188 EXPECT_EQ(1, interceptor->GetCount()) << interceptor->GetRequestsAsString();
184 EXPECT_NE( 189 EXPECT_NE(
185 string::npos, 190 string::npos,
186 interceptor->GetRequests()[0].find( 191 interceptor->GetRequests()[0].find(
187 "<app appid=\"abc\" version=\"1.0\" nextversion=\"2.0\">" 192 "<app appid=\"abc\" version=\"1.0\" nextversion=\"2.0\">"
188 "<event eventtype=\"3\" eventresult=\"1\"/>" 193 "<event eventtype=\"3\" eventresult=\"1\"/>"
(...skipping 26 matching lines...) Expand all
215 } 220 }
216 221
217 { 222 {
218 // Tests that the default for |requires_network_encryption| is true. 223 // Tests that the default for |requires_network_encryption| is true.
219 Component component(*update_context, "abc"); 224 Component component(*update_context, "abc");
220 EXPECT_FALSE(ping_manager_->SendPing(component)); 225 EXPECT_FALSE(ping_manager_->SendPing(component));
221 } 226 }
222 } 227 }
223 228
224 } // namespace update_client 229 } // namespace update_client
OLDNEW
« no previous file with comments | « components/update_client/ping_manager.cc ('k') | components/update_client/protocol_builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698