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

Side by Side Diff: chrome/browser/component_updater/test/component_updater_service_unittest.cc

Issue 18516010: Implemented completion pings for component updates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <list> 5 #include "chrome/browser/component_updater/test/component_updater_service_unitte st.h"
6 #include <utility>
7 #include "base/compiler_specific.h"
8 #include "base/file_util.h" 6 #include "base/file_util.h"
9 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
10 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/path_service.h" 9 #include "base/path_service.h"
13 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
15 #include "base/values.h" 12 #include "base/values.h"
16 #include "chrome/browser/chrome_notification_types.h" 13 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/component_updater/component_updater_service.h" 14 #include "chrome/browser/component_updater/component_updater_service.h"
18 #include "chrome/browser/component_updater/test/component_patcher_mock.h"
19 #include "chrome/browser/component_updater/test/component_updater_service_unitte st.h"
20 #include "chrome/browser/component_updater/test/test_installer.h" 15 #include "chrome/browser/component_updater/test/test_installer.h"
21 #include "chrome/common/chrome_paths.h" 16 #include "chrome/common/chrome_paths.h"
22 #include "content/public/browser/notification_observer.h"
23 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
24 #include "content/public/test/test_browser_thread.h"
25 #include "content/public/test/test_notification_tracker.h"
26 #include "content/test/net/url_request_prepackaged_interceptor.h" 18 #include "content/test/net/url_request_prepackaged_interceptor.h"
27 #include "libxml/globals.h" 19 #include "libxml/globals.h"
28 #include "net/base/upload_bytes_element_reader.h" 20 #include "net/base/upload_bytes_element_reader.h"
29 #include "net/url_request/url_fetcher.h" 21 #include "net/url_request/url_fetcher.h"
30 #include "net/url_request/url_request.h"
31 #include "net/url_request/url_request_filter.h"
32 #include "net/url_request/url_request_simple_job.h"
33 #include "net/url_request/url_request_test_util.h"
34 #include "testing/gtest/include/gtest/gtest.h"
35 #include "url/gurl.h" 22 #include "url/gurl.h"
36 23
37 using content::BrowserThread; 24 using content::BrowserThread;
38 using content::TestNotificationTracker; 25 using content::TestNotificationTracker;
39 26
40 TestConfigurator::TestConfigurator() 27 TestConfigurator::TestConfigurator()
41 : times_(1), recheck_time_(0), ondemand_time_(0), cus_(NULL) { 28 : times_(1),
29 recheck_time_(0),
30 ondemand_time_(0),
31 cus_(NULL),
32 context_(new net::TestURLRequestContextGetter(
33 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))) {
42 } 34 }
43 35
44 TestConfigurator::~TestConfigurator() { 36 TestConfigurator::~TestConfigurator() {
45 } 37 }
46 38
47 int TestConfigurator::InitialDelay() { return 0; } 39 int TestConfigurator::InitialDelay() { return 0; }
48 40
49 int TestConfigurator::NextCheckDelay() { 41 int TestConfigurator::NextCheckDelay() {
50 // This is called when a new full cycle of checking for updates is going 42 // This is called when a new full cycle of checking for updates is going
51 // to happen. In test we normally only test one cycle so it is a good 43 // to happen. In test we normally only test one cycle so it is a good
(...skipping 27 matching lines...) Expand all
79 } 71 }
80 72
81 int TestConfigurator::OnDemandDelay() { 73 int TestConfigurator::OnDemandDelay() {
82 return ondemand_time_; 74 return ondemand_time_;
83 } 75 }
84 76
85 GURL TestConfigurator::UpdateUrl() { 77 GURL TestConfigurator::UpdateUrl() {
86 return GURL("http://localhost/upd"); 78 return GURL("http://localhost/upd");
87 } 79 }
88 80
81 GURL TestConfigurator::PingUrl() {
82 return GURL("http://localhost2/ping");
83 }
84
89 const char* TestConfigurator::ExtraRequestParams() { return "extra=foo"; } 85 const char* TestConfigurator::ExtraRequestParams() { return "extra=foo"; }
90 86
91 size_t TestConfigurator::UrlSizeLimit() { return 256; } 87 size_t TestConfigurator::UrlSizeLimit() { return 256; }
92 88
93 net::URLRequestContextGetter* TestConfigurator::RequestContext() { 89 net::URLRequestContextGetter* TestConfigurator::RequestContext() {
94 return new net::TestURLRequestContextGetter( 90 return context_.get();
95 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
96 } 91 }
97 92
98 // Don't use the utility process to decode files. 93 // Don't use the utility process to decode files.
99 bool TestConfigurator::InProcess() { return true; } 94 bool TestConfigurator::InProcess() { return true; }
100 95
101 void TestConfigurator::OnEvent(Events event, int extra) { }
102
103 ComponentPatcher* TestConfigurator::CreateComponentPatcher() { 96 ComponentPatcher* TestConfigurator::CreateComponentPatcher() {
104 return new MockComponentPatcher(); 97 return new MockComponentPatcher();
105 } 98 }
106 99
107 bool TestConfigurator::DeltasEnabled() const { 100 bool TestConfigurator::DeltasEnabled() const {
108 return true; 101 return true;
109 } 102 }
110 103
111 // Set how many update checks are called, the default value is just once. 104 // Set how many update checks are called, the default value is just once.
112 void TestConfigurator::SetLoopCount(int times) { times_ = times; } 105 void TestConfigurator::SetLoopCount(int times) { times_ = times; }
113 106
114 void TestConfigurator::SetRecheckTime(int seconds) { 107 void TestConfigurator::SetRecheckTime(int seconds) {
115 recheck_time_ = seconds; 108 recheck_time_ = seconds;
116 } 109 }
117 110
118 void TestConfigurator::SetOnDemandTime(int seconds) { 111 void TestConfigurator::SetOnDemandTime(int seconds) {
119 ondemand_time_ = seconds; 112 ondemand_time_ = seconds;
120 } 113 }
121 114
122 void TestConfigurator::AddComponentToCheck(CrxComponent* com, 115 void TestConfigurator::AddComponentToCheck(CrxComponent* com,
123 int at_loop_iter) { 116 int at_loop_iter) {
124 components_to_check_.push_back(std::make_pair(com, at_loop_iter)); 117 components_to_check_.push_back(std::make_pair(com, at_loop_iter));
125 } 118 }
126 119
127 void TestConfigurator::SetComponentUpdateService(ComponentUpdateService* cus) { 120 void TestConfigurator::SetComponentUpdateService(ComponentUpdateService* cus) {
128 cus_ = cus; 121 cus_ = cus;
129 } 122 }
130 123
131 ComponentUpdaterTest::ComponentUpdaterTest() : test_config_(NULL) { 124 ComponentUpdaterTest::ComponentUpdaterTest()
125 : test_config_(NULL),
126 ui_thread_(BrowserThread::UI, &message_loop_),
127 file_thread_(BrowserThread::FILE),
128 io_thread_(BrowserThread::IO) {
132 // The component updater instance under test. 129 // The component updater instance under test.
133 test_config_ = new TestConfigurator; 130 test_config_ = new TestConfigurator;
134 component_updater_.reset(ComponentUpdateServiceFactory(test_config_)); 131 component_updater_.reset(ComponentUpdateServiceFactory(test_config_));
135 test_config_->SetComponentUpdateService(component_updater_.get()); 132 test_config_->SetComponentUpdateService(component_updater_.get());
133
136 // The test directory is chrome/test/data/components. 134 // The test directory is chrome/test/data/components.
137 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); 135 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_);
138 test_data_dir_ = test_data_dir_.AppendASCII("components"); 136 test_data_dir_ = test_data_dir_.AppendASCII("components");
139 137
140 // Subscribe to all component updater notifications. 138 // Subscribe to all component updater notifications.
141 const int notifications[] = { 139 const int notifications[] = {
142 chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, 140 chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED,
143 chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, 141 chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING,
144 chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, 142 chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND,
145 chrome::NOTIFICATION_COMPONENT_UPDATE_READY 143 chrome::NOTIFICATION_COMPONENT_UPDATE_READY
146 }; 144 };
147 145
148 for (int ix = 0; ix != arraysize(notifications); ++ix) { 146 for (int ix = 0; ix != arraysize(notifications); ++ix) {
149 notification_tracker_.ListenFor( 147 notification_tracker_.ListenFor(
150 notifications[ix], content::NotificationService::AllSources()); 148 notifications[ix], content::NotificationService::AllSources());
151 } 149 }
152 net::URLFetcher::SetEnableInterceptionForTests(true); 150 net::URLFetcher::SetEnableInterceptionForTests(true);
151
152 io_thread_.StartIOThread();
153 file_thread_.Start();
153 } 154 }
154 155
155 ComponentUpdaterTest::~ComponentUpdaterTest() { 156 ComponentUpdaterTest::~ComponentUpdaterTest() {
156 net::URLFetcher::SetEnableInterceptionForTests(false); 157 net::URLFetcher::SetEnableInterceptionForTests(false);
157 } 158 }
158 159
159 void ComponentUpdaterTest::TearDown() { 160 void ComponentUpdaterTest::TearDown() {
160 xmlCleanupGlobals(); 161 xmlCleanupGlobals();
161 } 162 }
162 163
(...skipping 27 matching lines...) Expand all
190 com->pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); 191 com->pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash));
191 } else { 192 } else {
192 com->name = "test_ihfo"; 193 com->name = "test_ihfo";
193 com->pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash)); 194 com->pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash));
194 } 195 }
195 com->version = version; 196 com->version = version;
196 com->installer = installer; 197 com->installer = installer;
197 return component_updater_->RegisterComponent(*com); 198 return component_updater_->RegisterComponent(*com);
198 } 199 }
199 200
201 PingChecker::PingChecker(const std::map<std::string, std::string>& attributes)
202 : num_hits_(0), num_misses_(0), attributes_(attributes) {
203 }
204
205 PingChecker::~PingChecker() {}
206
207 void PingChecker::Trial(net::URLRequest* request) {
208 if (Test(request))
209 ++num_hits_;
210 else
211 ++num_misses_;
212 }
213
214 bool PingChecker::Test(net::URLRequest* request) {
215 if (request->has_upload()) {
216 const net::UploadDataStream* stream = request->get_upload();
217 const net::UploadBytesElementReader* reader =
218 stream->element_readers()[0]->AsBytesReader();
219 int size = reader->length();
220 scoped_refptr <net::IOBuffer> buffer = new net::IOBuffer(size);
221 std::string data(reader->bytes());
222 // For now, we assume that there is only one ping per POST.
223 std::string::size_type start = data.find("<o:event");
224 if (start != std::string::npos) {
225 std::string::size_type end = data.find(">", start);
226 if (end != std::string::npos) {
227 std::string ping = data.substr(start, end - start);
228 std::map<std::string, std::string>::const_iterator iter;
229 for (iter = attributes_.begin(); iter != attributes_.end(); ++iter) {
230 // does the ping contain the specified attribute/value?
231 if (ping.find(std::string(" ") + (iter->first) +
232 std::string("=") + (iter->second)) == string::npos) {
233 return false;
234 }
235 }
236 return true;
237 }
238 }
239 }
240 return false;
241 }
242
200 // Verify that our test fixture work and the component updater can 243 // Verify that our test fixture work and the component updater can
201 // be created and destroyed with no side effects. 244 // be created and destroyed with no side effects.
202 TEST_F(ComponentUpdaterTest, VerifyFixture) { 245 TEST_F(ComponentUpdaterTest, VerifyFixture) {
203 EXPECT_TRUE(component_updater() != NULL); 246 EXPECT_TRUE(component_updater() != NULL);
204 EXPECT_EQ(0ul, notification_tracker().size()); 247 EXPECT_EQ(0ul, notification_tracker().size());
205 } 248 }
206 249
207 // Verify that the component updater can be caught in a quick 250 // Verify that the component updater can be caught in a quick
208 // start-shutdown situation. Failure of this test will be a crash. Also 251 // start-shutdown situation. Failure of this test will be a crash. Also
209 // if there is no work to do, there are no notifications generated. 252 // if there is no work to do, there are no notifications generated.
210 TEST_F(ComponentUpdaterTest, StartStop) { 253 TEST_F(ComponentUpdaterTest, StartStop) {
211 base::MessageLoop message_loop;
212 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
213
214 component_updater()->Start(); 254 component_updater()->Start();
215 message_loop.RunUntilIdle(); 255 message_loop_.RunUntilIdle();
216 component_updater()->Stop(); 256 component_updater()->Stop();
217 257
218 EXPECT_EQ(0ul, notification_tracker().size()); 258 EXPECT_EQ(0ul, notification_tracker().size());
219 } 259 }
220 260
221 // Verify that when the server has no updates, we go back to sleep and 261 // Verify that when the server has no updates, we go back to sleep and
222 // the COMPONENT_UPDATER_STARTED and COMPONENT_UPDATER_SLEEPING notifications 262 // the COMPONENT_UPDATER_STARTED and COMPONENT_UPDATER_SLEEPING notifications
223 // are generated. 263 // are generated.
224 TEST_F(ComponentUpdaterTest, CheckCrxSleep) { 264 TEST_F(ComponentUpdaterTest, CheckCrxSleep) {
225 base::MessageLoop message_loop;
226 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
227 content::TestBrowserThread file_thread(BrowserThread::FILE);
228 content::TestBrowserThread io_thread(BrowserThread::IO);
229
230 io_thread.StartIOThread();
231 file_thread.Start();
232
233 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 265 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
234 266
235 TestInstaller installer; 267 TestInstaller installer;
236 CrxComponent com; 268 CrxComponent com;
237 EXPECT_EQ(ComponentUpdateService::kOk, 269 EXPECT_EQ(ComponentUpdateService::kOk,
238 RegisterComponent(&com, 270 RegisterComponent(&com,
239 kTestComponent_abag, 271 kTestComponent_abag,
240 Version("1.1"), 272 Version("1.1"),
241 &installer)); 273 &installer));
242 274
243 const GURL expected_update_url( 275 const GURL expected_update_url(
244 "http://localhost/upd?extra=foo" 276 "http://localhost/upd?extra=foo"
245 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D1.1%26fp%3D%26uc"); 277 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D1.1%26fp%3D%26uc");
246 278
247 interceptor.SetResponse(expected_update_url, 279 interceptor.SetResponse(expected_update_url,
248 test_file("updatecheck_reply_1.xml")); 280 test_file("updatecheck_reply_1.xml"));
249 281
250 // We loop twice, but there are no updates so we expect two sleep messages. 282 // We loop twice, but there are no updates so we expect two sleep messages.
251 test_configurator()->SetLoopCount(2); 283 test_configurator()->SetLoopCount(2);
252 component_updater()->Start(); 284 component_updater()->Start();
253 285
254 ASSERT_EQ(1ul, notification_tracker().size()); 286 ASSERT_EQ(1ul, notification_tracker().size());
255 TestNotificationTracker::Event ev1 = notification_tracker().at(0); 287 TestNotificationTracker::Event ev1 = notification_tracker().at(0);
256 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev1.type); 288 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev1.type);
257 289
258 message_loop.Run(); 290 message_loop_.Run();
259 291
260 ASSERT_EQ(3ul, notification_tracker().size()); 292 ASSERT_EQ(3ul, notification_tracker().size());
261 TestNotificationTracker::Event ev2 = notification_tracker().at(1); 293 TestNotificationTracker::Event ev2 = notification_tracker().at(1);
262 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); 294 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type);
263 TestNotificationTracker::Event ev3 = notification_tracker().at(2); 295 TestNotificationTracker::Event ev3 = notification_tracker().at(2);
264 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); 296 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type);
265 EXPECT_EQ(2, interceptor.GetHitCount()); 297 EXPECT_EQ(2, interceptor.GetHitCount());
266 298
267 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 299 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
268 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); 300 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count());
269 301
270 component_updater()->Stop(); 302 component_updater()->Stop();
271 303
272 // Loop twice again but this case we simulate a server error by returning 304 // Loop twice again but this case we simulate a server error by returning
273 // an empty file. 305 // an empty file.
274 306
275 interceptor.SetResponse(expected_update_url, 307 interceptor.SetResponse(expected_update_url,
276 test_file("updatecheck_reply_empty")); 308 test_file("updatecheck_reply_empty"));
277 309
278 notification_tracker().Reset(); 310 notification_tracker().Reset();
279 test_configurator()->SetLoopCount(2); 311 test_configurator()->SetLoopCount(2);
280 component_updater()->Start(); 312 component_updater()->Start();
281 313
282 message_loop.Run(); 314 message_loop_.Run();
283 315
284 ASSERT_EQ(3ul, notification_tracker().size()); 316 ASSERT_EQ(3ul, notification_tracker().size());
285 ev1 = notification_tracker().at(0); 317 ev1 = notification_tracker().at(0);
286 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev1.type); 318 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev1.type);
287 ev2 = notification_tracker().at(1); 319 ev2 = notification_tracker().at(1);
288 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); 320 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type);
289 ev3 = notification_tracker().at(2); 321 ev3 = notification_tracker().at(2);
290 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); 322 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type);
291 EXPECT_EQ(4, interceptor.GetHitCount()); 323 EXPECT_EQ(4, interceptor.GetHitCount());
292 324
293 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 325 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
294 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); 326 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count());
295 327
296 component_updater()->Stop(); 328 component_updater()->Stop();
297 } 329 }
298 330
299 // Verify that we can check for updates and install one component. Besides 331 // Verify that we can check for updates and install one component. Besides
300 // the notifications above NOTIFICATION_COMPONENT_UPDATE_FOUND and 332 // the notifications above NOTIFICATION_COMPONENT_UPDATE_FOUND and
301 // NOTIFICATION_COMPONENT_UPDATE_READY should have been fired. We do two loops 333 // NOTIFICATION_COMPONENT_UPDATE_READY should have been fired. We do two loops
302 // so the second time around there should be nothing left to do. 334 // so the second time around there should be nothing left to do.
303 // We also check that only 3 network requests are issued: 335 // We also check that only 3 non-ping network requests are issued:
304 // 1- manifest check 336 // 1- manifest check
305 // 2- download crx 337 // 2- download crx
306 // 3- second manifest check. 338 // 3- second manifest check.
307 TEST_F(ComponentUpdaterTest, InstallCrx) { 339 TEST_F(ComponentUpdaterTest, InstallCrx) {
308 base::MessageLoop message_loop; 340 std::map<std::string, std::string> map;
309 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 341 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\""));
310 content::TestBrowserThread file_thread(BrowserThread::FILE); 342 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\""));
311 content::TestBrowserThread io_thread(BrowserThread::IO); 343 map.insert(std::pair<std::string, std::string>("previousversion",
312 344 "\"0.9\""));
313 io_thread.StartIOThread(); 345 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\""));
314 file_thread.Start(); 346 PingChecker ping_checker(map);
315 347 URLRequestPostInterceptor post_interceptor(&ping_checker);
316 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 348 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
317 349
318 TestInstaller installer1; 350 TestInstaller installer1;
319 CrxComponent com1; 351 CrxComponent com1;
320 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1); 352 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1);
321 TestInstaller installer2; 353 TestInstaller installer2;
322 CrxComponent com2; 354 CrxComponent com2;
323 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); 355 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2);
324 356
325 const GURL expected_update_url_1( 357 const GURL expected_update_url_1(
326 "http://localhost/upd?extra=foo" 358 "http://localhost/upd?extra=foo"
327 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc" 359 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"
328 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"); 360 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc");
329 361
330 const GURL expected_update_url_2( 362 const GURL expected_update_url_2(
331 "http://localhost/upd?extra=foo" 363 "http://localhost/upd?extra=foo"
332 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc" 364 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"
333 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26fp%3D%26uc"); 365 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26fp%3D%26uc");
334 366
335 interceptor.SetResponse(expected_update_url_1, 367 interceptor.SetResponse(expected_update_url_1,
336 test_file("updatecheck_reply_1.xml")); 368 test_file("updatecheck_reply_1.xml"));
337 interceptor.SetResponse(expected_update_url_2, 369 interceptor.SetResponse(expected_update_url_2,
338 test_file("updatecheck_reply_1.xml")); 370 test_file("updatecheck_reply_1.xml"));
339 interceptor.SetResponse(GURL(expected_crx_url), 371 interceptor.SetResponse(GURL(expected_crx_url),
340 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); 372 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
341 373
342 test_configurator()->SetLoopCount(2); 374 test_configurator()->SetLoopCount(2);
343 375
344 component_updater()->Start(); 376 component_updater()->Start();
345 message_loop.Run(); 377 message_loop_.Run();
346 378
347 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); 379 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
348 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); 380 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count());
349 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); 381 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
350 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); 382 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count());
351 383
352 EXPECT_EQ(3, interceptor.GetHitCount()); 384 EXPECT_EQ(3, interceptor.GetHitCount());
385 EXPECT_EQ(1, ping_checker.NumHits());
386 EXPECT_EQ(0, ping_checker.NumMisses());
353 387
354 ASSERT_EQ(5ul, notification_tracker().size()); 388 ASSERT_EQ(5ul, notification_tracker().size());
355 389
356 TestNotificationTracker::Event ev1 = notification_tracker().at(1); 390 TestNotificationTracker::Event ev1 = notification_tracker().at(1);
357 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); 391 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type);
358 392
359 TestNotificationTracker::Event ev2 = notification_tracker().at(2); 393 TestNotificationTracker::Event ev2 = notification_tracker().at(2);
360 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); 394 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type);
361 395
362 TestNotificationTracker::Event ev3 = notification_tracker().at(3); 396 TestNotificationTracker::Event ev3 = notification_tracker().at(3);
363 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); 397 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type);
364 398
365 TestNotificationTracker::Event ev4 = notification_tracker().at(4); 399 TestNotificationTracker::Event ev4 = notification_tracker().at(4);
366 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type); 400 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type);
367 401
368 component_updater()->Stop(); 402 component_updater()->Stop();
369 } 403 }
370 404
371 // This test checks that the "prodversionmin" value is handled correctly. In 405 // This test checks that the "prodversionmin" value is handled correctly. In
372 // particular there should not be an install because the minimum product 406 // particular there should not be an install because the minimum product
373 // version is much higher than of chrome. 407 // version is much higher than of chrome.
374 TEST_F(ComponentUpdaterTest, ProdVersionCheck) { 408 TEST_F(ComponentUpdaterTest, ProdVersionCheck) {
375 base::MessageLoop message_loop; 409 std::map<std::string, std::string> map;
376 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 410 PingChecker ping_checker(map);
377 content::TestBrowserThread file_thread(BrowserThread::FILE); 411 URLRequestPostInterceptor post_interceptor(&ping_checker);
378 content::TestBrowserThread io_thread(BrowserThread::IO);
379
380 io_thread.StartIOThread();
381 file_thread.Start();
382
383 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 412 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
384 413
385 TestInstaller installer; 414 TestInstaller installer;
386 CrxComponent com; 415 CrxComponent com;
387 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer); 416 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer);
388 417
389 const GURL expected_update_url( 418 const GURL expected_update_url(
390 "http://localhost/upd?extra=foo&x=id%3D" 419 "http://localhost/upd?extra=foo&x=id%3D"
391 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"); 420 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc");
392 421
393 interceptor.SetResponse(expected_update_url, 422 interceptor.SetResponse(expected_update_url,
394 test_file("updatecheck_reply_2.xml")); 423 test_file("updatecheck_reply_2.xml"));
395 interceptor.SetResponse(GURL(expected_crx_url), 424 interceptor.SetResponse(GURL(expected_crx_url),
396 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); 425 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
397 426
398 test_configurator()->SetLoopCount(1); 427 test_configurator()->SetLoopCount(1);
399 component_updater()->Start(); 428 component_updater()->Start();
400 message_loop.Run(); 429 message_loop_.Run();
401 430
431 EXPECT_EQ(0, ping_checker.NumHits());
432 EXPECT_EQ(0, ping_checker.NumMisses());
402 EXPECT_EQ(1, interceptor.GetHitCount()); 433 EXPECT_EQ(1, interceptor.GetHitCount());
403 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 434 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
404 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); 435 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count());
405 436
406 component_updater()->Stop(); 437 component_updater()->Stop();
407 } 438 }
408 439
409 // Test that a ping for an update check can cause installs. 440 // Test that a ping for an update check can cause installs.
410 // Here is the timeline: 441 // Here is the timeline:
411 // - First loop: we return a reply that indicates no update, so 442 // - First loop: we return a reply that indicates no update, so
412 // nothing happens. 443 // nothing happens.
413 // - We ping. 444 // - We ping.
414 // - This triggers a second loop, which has a reply that triggers an install. 445 // - This triggers a second loop, which has a reply that triggers an install.
415 TEST_F(ComponentUpdaterTest, CheckForUpdateSoon) { 446 TEST_F(ComponentUpdaterTest, CheckForUpdateSoon) {
416 base::MessageLoop message_loop; 447 std::map<std::string, std::string> map;
417 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 448 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\""));
418 content::TestBrowserThread file_thread(BrowserThread::FILE); 449 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\""));
419 content::TestBrowserThread io_thread(BrowserThread::IO); 450 map.insert(std::pair<std::string, std::string>("previousversion",
420 451 "\"0.9\""));
421 io_thread.StartIOThread(); 452 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\""));
422 file_thread.Start(); 453 PingChecker ping_checker(map);
423 454 URLRequestPostInterceptor post_interceptor(&ping_checker);
424 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 455 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
425 456
426 TestInstaller installer1; 457 TestInstaller installer1;
427 CrxComponent com1; 458 CrxComponent com1;
428 RegisterComponent(&com1, kTestComponent_abag, Version("2.2"), &installer1); 459 RegisterComponent(&com1, kTestComponent_abag, Version("2.2"), &installer1);
429 TestInstaller installer2; 460 TestInstaller installer2;
430 CrxComponent com2; 461 CrxComponent com2;
431 RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"), &installer2); 462 RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"), &installer2);
432 463
433 const GURL expected_update_url_1( 464 const GURL expected_update_url_1(
(...skipping 10 matching lines...) Expand all
444 interceptor.SetResponse(expected_update_url_1, 475 interceptor.SetResponse(expected_update_url_1,
445 test_file("updatecheck_reply_empty")); 476 test_file("updatecheck_reply_empty"));
446 interceptor.SetResponse(expected_update_url_2, 477 interceptor.SetResponse(expected_update_url_2,
447 test_file("updatecheck_reply_1.xml")); 478 test_file("updatecheck_reply_1.xml"));
448 interceptor.SetResponse(GURL(expected_crx_url), 479 interceptor.SetResponse(GURL(expected_crx_url),
449 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); 480 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
450 // Test success. 481 // Test success.
451 test_configurator()->SetLoopCount(2); 482 test_configurator()->SetLoopCount(2);
452 test_configurator()->AddComponentToCheck(&com2, 1); 483 test_configurator()->AddComponentToCheck(&com2, 1);
453 component_updater()->Start(); 484 component_updater()->Start();
454 message_loop.Run(); 485 message_loop_.Run();
455 486
456 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); 487 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
457 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count()); 488 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count());
458 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); 489 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
459 EXPECT_EQ(1, static_cast<TestInstaller*>(com2.installer)->install_count()); 490 EXPECT_EQ(1, static_cast<TestInstaller*>(com2.installer)->install_count());
460 491
461 EXPECT_EQ(3, interceptor.GetHitCount()); 492 EXPECT_EQ(3, interceptor.GetHitCount());
462 493
463 ASSERT_EQ(5ul, notification_tracker().size()); 494 ASSERT_EQ(5ul, notification_tracker().size());
464 495
(...skipping 29 matching lines...) Expand all
494 525
495 // No update: error from no server response 526 // No update: error from no server response
496 interceptor.SetResponse(expected_update_url_3, 527 interceptor.SetResponse(expected_update_url_3,
497 test_file("updatecheck_reply_empty")); 528 test_file("updatecheck_reply_empty"));
498 notification_tracker().Reset(); 529 notification_tracker().Reset();
499 test_configurator()->SetLoopCount(1); 530 test_configurator()->SetLoopCount(1);
500 component_updater()->Start(); 531 component_updater()->Start();
501 EXPECT_EQ(ComponentUpdateService::kOk, 532 EXPECT_EQ(ComponentUpdateService::kOk,
502 component_updater()->CheckForUpdateSoon(com2)); 533 component_updater()->CheckForUpdateSoon(com2));
503 534
504 message_loop.Run(); 535 message_loop_.Run();
505 536
506 ASSERT_EQ(2ul, notification_tracker().size()); 537 ASSERT_EQ(2ul, notification_tracker().size());
507 ev0 = notification_tracker().at(0); 538 ev0 = notification_tracker().at(0);
508 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); 539 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type);
509 ev1 = notification_tracker().at(1); 540 ev1 = notification_tracker().at(1);
510 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type); 541 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type);
511 component_updater()->Stop(); 542 component_updater()->Stop();
512 543
513 // No update: already updated to 1.0 so nothing new 544 // No update: already updated to 1.0 so nothing new
514 interceptor.SetResponse(expected_update_url_3, 545 interceptor.SetResponse(expected_update_url_3,
515 test_file("updatecheck_reply_1.xml")); 546 test_file("updatecheck_reply_1.xml"));
516 notification_tracker().Reset(); 547 notification_tracker().Reset();
517 test_configurator()->SetLoopCount(1); 548 test_configurator()->SetLoopCount(1);
518 component_updater()->Start(); 549 component_updater()->Start();
519 EXPECT_EQ(ComponentUpdateService::kOk, 550 EXPECT_EQ(ComponentUpdateService::kOk,
520 component_updater()->CheckForUpdateSoon(com2)); 551 component_updater()->CheckForUpdateSoon(com2));
521 552
522 message_loop.Run(); 553 message_loop_.Run();
523 554
555 EXPECT_EQ(1, ping_checker.NumHits());
556 EXPECT_EQ(0, ping_checker.NumMisses());
524 ASSERT_EQ(2ul, notification_tracker().size()); 557 ASSERT_EQ(2ul, notification_tracker().size());
525 ev0 = notification_tracker().at(0); 558 ev0 = notification_tracker().at(0);
526 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); 559 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type);
527 ev1 = notification_tracker().at(1); 560 ev1 = notification_tracker().at(1);
528 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type); 561 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type);
529 component_updater()->Stop(); 562 component_updater()->Stop();
530 } 563 }
531 564
532 // Verify that a previously registered component can get re-registered 565 // Verify that a previously registered component can get re-registered
533 // with a different version. 566 // with a different version.
534 TEST_F(ComponentUpdaterTest, CheckReRegistration) { 567 TEST_F(ComponentUpdaterTest, CheckReRegistration) {
535 base::MessageLoop message_loop; 568 std::map<std::string, std::string> map;
536 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 569 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\""));
537 content::TestBrowserThread file_thread(BrowserThread::FILE); 570 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\""));
538 content::TestBrowserThread io_thread(BrowserThread::IO); 571 map.insert(std::pair<std::string, std::string>("previousversion",
539 572 "\"0.9\""));
540 io_thread.StartIOThread(); 573 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\""));
541 file_thread.Start(); 574 PingChecker ping_checker(map);
542 575 URLRequestPostInterceptor post_interceptor(&ping_checker);
543 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 576 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
544 577
545 TestInstaller installer1; 578 TestInstaller installer1;
546 CrxComponent com1; 579 CrxComponent com1;
547 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1); 580 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1);
548 TestInstaller installer2; 581 TestInstaller installer2;
549 CrxComponent com2; 582 CrxComponent com2;
550 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); 583 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2);
551 584
552 // Start with 0.9, and update to 1.0 585 // Start with 0.9, and update to 1.0
(...skipping 12 matching lines...) Expand all
565 interceptor.SetResponse(expected_update_url_2, 598 interceptor.SetResponse(expected_update_url_2,
566 test_file("updatecheck_reply_1.xml")); 599 test_file("updatecheck_reply_1.xml"));
567 interceptor.SetResponse(GURL(expected_crx_url), 600 interceptor.SetResponse(GURL(expected_crx_url),
568 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); 601 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
569 602
570 // Loop twice to issue two checks: (1) with original 0.9 version 603 // Loop twice to issue two checks: (1) with original 0.9 version
571 // and (2) with the updated 1.0 version. 604 // and (2) with the updated 1.0 version.
572 test_configurator()->SetLoopCount(2); 605 test_configurator()->SetLoopCount(2);
573 606
574 component_updater()->Start(); 607 component_updater()->Start();
575 message_loop.Run(); 608 message_loop_.Run();
576 609
577 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); 610 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
578 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); 611 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count());
579 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); 612 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
580 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); 613 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count());
581 614
615 EXPECT_EQ(1, ping_checker.NumHits());
616 EXPECT_EQ(0, ping_checker.NumMisses());
582 EXPECT_EQ(3, interceptor.GetHitCount()); 617 EXPECT_EQ(3, interceptor.GetHitCount());
583 618
584 ASSERT_EQ(5ul, notification_tracker().size()); 619 ASSERT_EQ(5ul, notification_tracker().size());
585 620
586 TestNotificationTracker::Event ev0 = notification_tracker().at(0); 621 TestNotificationTracker::Event ev0 = notification_tracker().at(0);
587 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); 622 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type);
588 623
589 TestNotificationTracker::Event ev1 = notification_tracker().at(1); 624 TestNotificationTracker::Event ev1 = notification_tracker().at(1);
590 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); 625 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type);
591 626
(...skipping 23 matching lines...) Expand all
615 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"); 650 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc");
616 651
617 interceptor.SetResponse(expected_update_url_3, 652 interceptor.SetResponse(expected_update_url_3,
618 test_file("updatecheck_reply_1.xml")); 653 test_file("updatecheck_reply_1.xml"));
619 654
620 notification_tracker().Reset(); 655 notification_tracker().Reset();
621 656
622 // Loop once just to notice the check happening with the re-register version. 657 // Loop once just to notice the check happening with the re-register version.
623 test_configurator()->SetLoopCount(1); 658 test_configurator()->SetLoopCount(1);
624 component_updater()->Start(); 659 component_updater()->Start();
625 message_loop.Run(); 660 message_loop_.Run();
626 661
627 ASSERT_EQ(2ul, notification_tracker().size()); 662 ASSERT_EQ(2ul, notification_tracker().size());
628 663
629 ev0 = notification_tracker().at(0); 664 ev0 = notification_tracker().at(0);
630 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); 665 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type);
631 666
632 ev1 = notification_tracker().at(1); 667 ev1 = notification_tracker().at(1);
633 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type); 668 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type);
634 669
635 EXPECT_EQ(4, interceptor.GetHitCount()); 670 EXPECT_EQ(4, interceptor.GetHitCount());
636 671
637 // We created a new installer, so the counts go back to 0. 672 // We created a new installer, so the counts go back to 0.
638 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); 673 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
639 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count()); 674 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count());
640 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); 675 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
641 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); 676 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count());
642 677
643 component_updater()->Stop(); 678 component_updater()->Stop();
644 } 679 }
645 680
646 // Verify that we can download and install a component and a differential 681 // Verify that we can download and install a component and a differential
647 // update to that component. We do three loops; the final loop should do 682 // update to that component. We do three loops; the final loop should do
648 // nothing. 683 // nothing.
649 // We also check that exactly 5 network requests are issued: 684 // We also check that exactly 5 non-ping network requests are issued:
650 // 1- update check (response: v1 available) 685 // 1- update check (response: v1 available)
651 // 2- download crx (v1) 686 // 2- download crx (v1)
652 // 3- update check (response: v2 available) 687 // 3- update check (response: v2 available)
653 // 4- download differential crx (v1 to v2) 688 // 4- download differential crx (v1 to v2)
654 // 5- update check (response: no further update available) 689 // 5- update check (response: no further update available)
690 // There should be two pings, one for each update. The second will bear a
691 // diffresult=1, while the first will not.
655 TEST_F(ComponentUpdaterTest, DifferentialUpdate) { 692 TEST_F(ComponentUpdaterTest, DifferentialUpdate) {
656 base::MessageLoop message_loop; 693 std::map<std::string, std::string> map;
657 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 694 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\""));
658 content::TestBrowserThread file_thread(BrowserThread::FILE); 695 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\""));
659 content::TestBrowserThread io_thread(BrowserThread::IO); 696 map.insert(std::pair<std::string, std::string>("diffresult", "\"1\""));
660 697 PingChecker ping_checker(map);
661 io_thread.StartIOThread(); 698 URLRequestPostInterceptor post_interceptor(&ping_checker);
662 file_thread.Start();
663
664 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 699 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
665 700
666 VersionedTestInstaller installer; 701 VersionedTestInstaller installer;
667 CrxComponent com; 702 CrxComponent com;
668 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer); 703 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer);
669 704
670 const GURL expected_update_url_0( 705 const GURL expected_update_url_0(
671 "http://localhost/upd?extra=foo" 706 "http://localhost/upd?extra=foo"
672 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc"); 707 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc");
673 const GURL expected_update_url_1( 708 const GURL expected_update_url_1(
(...skipping 15 matching lines...) Expand all
689 test_file("updatecheck_diff_reply_3.xml")); 724 test_file("updatecheck_diff_reply_3.xml"));
690 interceptor.SetResponse(expected_crx_url_1, 725 interceptor.SetResponse(expected_crx_url_1,
691 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); 726 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"));
692 interceptor.SetResponse( 727 interceptor.SetResponse(
693 expected_crx_url_1_diff_2, 728 expected_crx_url_1_diff_2,
694 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx")); 729 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"));
695 730
696 test_configurator()->SetLoopCount(3); 731 test_configurator()->SetLoopCount(3);
697 732
698 component_updater()->Start(); 733 component_updater()->Start();
699 message_loop.Run(); 734 message_loop_.Run();
700 735
701 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 736 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
702 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); 737 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count());
703 738
739 // One ping has the diffresult=1, the other does not.
740 EXPECT_EQ(1, ping_checker.NumHits());
741 EXPECT_EQ(1, ping_checker.NumMisses());
742
704 EXPECT_EQ(5, interceptor.GetHitCount()); 743 EXPECT_EQ(5, interceptor.GetHitCount());
705 744
706 component_updater()->Stop(); 745 component_updater()->Stop();
707 } 746 }
708 747
709 // Verify that component installation falls back to downloading and installing 748 // Verify that component installation falls back to downloading and installing
710 // a full update if the differential update fails (in this case, because the 749 // a full update if the differential update fails (in this case, because the
711 // installer does not know about the existing files). We do two loops; the final 750 // installer does not know about the existing files). We do two loops; the final
712 // loop should do nothing. 751 // loop should do nothing.
713 // We also check that exactly 4 network requests are issued: 752 // We also check that exactly 4 non-ping network requests are issued:
714 // 1- update check (loop 1) 753 // 1- update check (loop 1)
715 // 2- download differential crx 754 // 2- download differential crx
716 // 3- download full crx 755 // 3- download full crx
717 // 4- update check (loop 2 - no update available) 756 // 4- update check (loop 2 - no update available)
757 // There should be one ping for the first attempted update.
718 TEST_F(ComponentUpdaterTest, DifferentialUpdateFails) { 758 TEST_F(ComponentUpdaterTest, DifferentialUpdateFails) {
719 base::MessageLoop message_loop; 759 std::map<std::string, std::string> map;
720 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 760 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\""));
721 content::TestBrowserThread file_thread(BrowserThread::FILE); 761 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\""));
722 content::TestBrowserThread io_thread(BrowserThread::IO); 762 map.insert(std::pair<std::string, std::string>("diffresult", "\"0\""));
723 763 map.insert(std::pair<std::string, std::string>("differrorcode", "\"16\""));
724 io_thread.StartIOThread(); 764 PingChecker ping_checker(map);
725 file_thread.Start(); 765 URLRequestPostInterceptor post_interceptor(&ping_checker);
726
727 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 766 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
728 767
729 TestInstaller installer; 768 TestInstaller installer;
730 CrxComponent com; 769 CrxComponent com;
731 RegisterComponent(&com, kTestComponent_ihfo, Version("1.0"), &installer); 770 RegisterComponent(&com, kTestComponent_ihfo, Version("1.0"), &installer);
732 771
733 const GURL expected_update_url_1( 772 const GURL expected_update_url_1(
734 "http://localhost/upd?extra=foo" 773 "http://localhost/upd?extra=foo"
735 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D%26uc"); 774 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D%26uc");
736 const GURL expected_update_url_2( 775 const GURL expected_update_url_2(
(...skipping 14 matching lines...) Expand all
751 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); 790 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"));
752 interceptor.SetResponse( 791 interceptor.SetResponse(
753 expected_crx_url_1_diff_2, 792 expected_crx_url_1_diff_2,
754 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx")); 793 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"));
755 interceptor.SetResponse(expected_crx_url_2, 794 interceptor.SetResponse(expected_crx_url_2,
756 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx")); 795 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"));
757 796
758 test_configurator()->SetLoopCount(2); 797 test_configurator()->SetLoopCount(2);
759 798
760 component_updater()->Start(); 799 component_updater()->Start();
761 message_loop.Run(); 800 message_loop_.Run();
762 801
763 // A failed differential update does not count as a failed install. 802 // A failed differential update does not count as a failed install.
764 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 803 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
765 EXPECT_EQ(1, static_cast<TestInstaller*>(com.installer)->install_count()); 804 EXPECT_EQ(1, static_cast<TestInstaller*>(com.installer)->install_count());
766 805
806 EXPECT_EQ(1, ping_checker.NumHits());
807 EXPECT_EQ(0, ping_checker.NumMisses());
767 EXPECT_EQ(4, interceptor.GetHitCount()); 808 EXPECT_EQ(4, interceptor.GetHitCount());
768 809
769 component_updater()->Stop(); 810 component_updater()->Stop();
770 } 811 }
771 812
813 // Verify that a failed installation causes an install failure ping.
814 TEST_F(ComponentUpdaterTest, CheckFailedInstallPing) {
815 std::map<std::string, std::string> map;
816 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\""));
817 map.insert(std::pair<std::string, std::string>("eventresult", "\"0\""));
818 map.insert(std::pair<std::string, std::string>("errorcode", "\"9\""));
819 map.insert(std::pair<std::string, std::string>("previousversion",
820 "\"0.9\""));
821 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\""));
822 PingChecker ping_checker(map);
823 URLRequestPostInterceptor post_interceptor(&ping_checker);
824 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
825
826 // This test installer reports installation failure.
827 class : public TestInstaller {
828 virtual bool Install(const base::DictionaryValue& manifest,
829 const base::FilePath& unpack_path) OVERRIDE {
830 ++install_count_;
831 base::DeleteFile(unpack_path, true);
832 return false;
833 }
834 } installer;
835
836 CrxComponent com;
837 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer);
838
839 // Start with 0.9, and attempt update to 1.0
840 const GURL expected_update_url_1(
841 "http://localhost/upd?extra=foo"
842 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc");
843
844 interceptor.SetResponse(expected_update_url_1,
845 test_file("updatecheck_reply_1.xml"));
846 interceptor.SetResponse(GURL(expected_crx_url),
847 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
848
849 // Loop twice to issue two checks: (1) with original 0.9 version
850 // and (2), which should retry with 0.9.
851 test_configurator()->SetLoopCount(2);
852 component_updater()->Start();
853 message_loop_.Run();
854
855 // Loop once more, but expect no ping because a noupdate response is issued.
856 // This is necessary to clear out the fire-and-forget ping from the previous
857 // iteration.
858 interceptor.SetResponse(expected_update_url_1,
859 test_file("updatecheck_reply_noupdate.xml"));
860 test_configurator()->SetLoopCount(1);
861 component_updater()->Start();
862 message_loop_.Run();
863
864 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
865 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count());
866
867 EXPECT_EQ(2, ping_checker.NumHits());
868 EXPECT_EQ(0, ping_checker.NumMisses());
869 EXPECT_EQ(5, interceptor.GetHitCount());
870
871 component_updater()->Stop();
872 }
873
772 // Verify that we successfully propagate a patcher error. 874 // Verify that we successfully propagate a patcher error.
773 // ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx contains an incorrect 875 // ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx contains an incorrect
774 // patching instruction that should fail. 876 // patching instruction that should fail.
775 TEST_F(ComponentUpdaterTest, DifferentialUpdateFailErrorcode) { 877 TEST_F(ComponentUpdaterTest, DifferentialUpdateFailErrorcode) {
776 base::MessageLoop message_loop; 878 std::map<std::string, std::string> map;
777 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 879 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\""));
778 content::TestBrowserThread file_thread(BrowserThread::FILE); 880 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\""));
779 content::TestBrowserThread io_thread(BrowserThread::IO); 881 map.insert(std::pair<std::string, std::string>("diffresult", "\"0\""));
780 882 map.insert(std::pair<std::string, std::string>("differrorcode", "\"14\""));
781 io_thread.StartIOThread(); 883 map.insert(std::pair<std::string, std::string>("diffextracode1", "\"305\""));
782 file_thread.Start(); 884 PingChecker ping_checker(map);
783 885 URLRequestPostInterceptor post_interceptor(&ping_checker);
784 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 886 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
785 887
786 VersionedTestInstaller installer; 888 VersionedTestInstaller installer;
787 CrxComponent com; 889 CrxComponent com;
788 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer); 890 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer);
789 891
790 const GURL expected_update_url_0( 892 const GURL expected_update_url_0(
791 "http://localhost/upd?extra=foo" 893 "http://localhost/upd?extra=foo"
792 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc"); 894 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc");
793 const GURL expected_update_url_1( 895 const GURL expected_update_url_1(
(...skipping 19 matching lines...) Expand all
813 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); 915 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"));
814 interceptor.SetResponse( 916 interceptor.SetResponse(
815 expected_crx_url_1_diff_2, 917 expected_crx_url_1_diff_2,
816 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx")); 918 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx"));
817 interceptor.SetResponse(expected_crx_url_2, 919 interceptor.SetResponse(expected_crx_url_2,
818 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx")); 920 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"));
819 921
820 test_configurator()->SetLoopCount(3); 922 test_configurator()->SetLoopCount(3);
821 923
822 component_updater()->Start(); 924 component_updater()->Start();
823 message_loop.Run(); 925 message_loop_.Run();
824 926
825 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 927 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
826 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); 928 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count());
827 929
930 EXPECT_EQ(1, ping_checker.NumHits());
931 EXPECT_EQ(1, ping_checker.NumMisses());
828 EXPECT_EQ(6, interceptor.GetHitCount()); 932 EXPECT_EQ(6, interceptor.GetHitCount());
829 933
830 component_updater()->Stop(); 934 component_updater()->Stop();
831 } 935 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698