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

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: ChromeConfigurator owns the ping manager. 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"
10 #include "base/memory/scoped_vector.h"
11 #include "base/message_loop.h"
12 #include "base/path_service.h"
13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/stringprintf.h"
15 #include "base/values.h"
16 #include "chrome/browser/chrome_notification_types.h" 7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/component_updater/component_updater_ping_manager.h"
17 #include "chrome/browser/component_updater/component_updater_service.h" 9 #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" 10 #include "chrome/browser/component_updater/test/test_installer.h"
21 #include "chrome/common/chrome_paths.h" 11 #include "chrome/common/chrome_paths.h"
22 #include "content/public/browser/notification_observer.h"
23 #include "content/public/browser/notification_service.h" 12 #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" 13 #include "content/test/net/url_request_prepackaged_interceptor.h"
27 #include "libxml/globals.h" 14 #include "libxml/globals.h"
28 #include "net/base/upload_bytes_element_reader.h" 15 #include "net/base/upload_bytes_element_reader.h"
29 #include "net/url_request/url_fetcher.h" 16 #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" 17 #include "url/gurl.h"
36 18
37 using content::BrowserThread; 19 using content::BrowserThread;
38 using content::TestNotificationTracker; 20 using content::TestNotificationTracker;
39 21
40 TestConfigurator::TestConfigurator() 22 TestConfigurator::TestConfigurator()
41 : times_(1), recheck_time_(0), ondemand_time_(0), cus_(NULL) { 23 : times_(1),
24 recheck_time_(0),
25 ondemand_time_(0),
26 cus_(NULL),
27 context_(new net::TestURLRequestContextGetter(
28 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))) {
42 } 29 }
43 30
44 TestConfigurator::~TestConfigurator() { 31 TestConfigurator::~TestConfigurator() {
32 if (cus_)
33 cus_->RemoveObserver(ping_manager_.get());
34 }
35
36 void TestConfigurator::Init(ComponentUpdateService* cus) {
37 cus_ = cus;
38 ping_manager_.reset(new component_updater::PingManager(PingUrl(),
39 RequestContext()));
40 cus_->AddObserver(ping_manager_.get());
45 } 41 }
46 42
47 int TestConfigurator::InitialDelay() { return 0; } 43 int TestConfigurator::InitialDelay() { return 0; }
48 44
49 int TestConfigurator::NextCheckDelay() { 45 int TestConfigurator::NextCheckDelay() {
50 // This is called when a new full cycle of checking for updates is going 46 // 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 47 // to happen. In test we normally only test one cycle so it is a good
52 // time to break from the test messageloop Run() method so the test can 48 // time to break from the test messageloop Run() method so the test can
53 // finish. 49 // finish.
54 if (--times_ <= 0) { 50 if (--times_ <= 0) {
(...skipping 21 matching lines...) Expand all
76 72
77 int TestConfigurator::MinimumReCheckWait() { 73 int TestConfigurator::MinimumReCheckWait() {
78 return recheck_time_; 74 return recheck_time_;
79 } 75 }
80 76
81 int TestConfigurator::OnDemandDelay() { 77 int TestConfigurator::OnDemandDelay() {
82 return ondemand_time_; 78 return ondemand_time_;
83 } 79 }
84 80
85 GURL TestConfigurator::UpdateUrl() { 81 GURL TestConfigurator::UpdateUrl() {
86 return GURL("http://localhost/upd"); 82 return GURL("http://localhost/upd");
83 }
84
85 GURL TestConfigurator::PingUrl() {
86 return GURL("http://localhost2/ping");
87 } 87 }
88 88
89 const char* TestConfigurator::ExtraRequestParams() { return "extra=foo"; } 89 const char* TestConfigurator::ExtraRequestParams() { return "extra=foo"; }
90 90
91 size_t TestConfigurator::UrlSizeLimit() { return 256; } 91 size_t TestConfigurator::UrlSizeLimit() { return 256; }
92 92
93 net::URLRequestContextGetter* TestConfigurator::RequestContext() { 93 net::URLRequestContextGetter* TestConfigurator::RequestContext() {
94 return new net::TestURLRequestContextGetter( 94 return context_.get();
95 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
96 } 95 }
97 96
98 // Don't use the utility process to decode files. 97 // Don't use the utility process to decode files.
99 bool TestConfigurator::InProcess() { return true; } 98 bool TestConfigurator::InProcess() { return true; }
100 99
101 void TestConfigurator::OnEvent(Events event, int extra) { }
102
103 ComponentPatcher* TestConfigurator::CreateComponentPatcher() { 100 ComponentPatcher* TestConfigurator::CreateComponentPatcher() {
104 return new MockComponentPatcher(); 101 return new MockComponentPatcher();
105 } 102 }
106 103
107 bool TestConfigurator::DeltasEnabled() const { 104 bool TestConfigurator::DeltasEnabled() const {
108 return true; 105 return true;
109 } 106 }
110 107
111 // Set how many update checks are called, the default value is just once. 108 // Set how many update checks are called, the default value is just once.
112 void TestConfigurator::SetLoopCount(int times) { times_ = times; } 109 void TestConfigurator::SetLoopCount(int times) { times_ = times; }
113 110
114 void TestConfigurator::SetRecheckTime(int seconds) { 111 void TestConfigurator::SetRecheckTime(int seconds) {
115 recheck_time_ = seconds; 112 recheck_time_ = seconds;
116 } 113 }
117 114
118 void TestConfigurator::SetOnDemandTime(int seconds) { 115 void TestConfigurator::SetOnDemandTime(int seconds) {
119 ondemand_time_ = seconds; 116 ondemand_time_ = seconds;
120 } 117 }
121 118
122 void TestConfigurator::AddComponentToCheck(CrxComponent* com, 119 void TestConfigurator::AddComponentToCheck(CrxComponent* com,
123 int at_loop_iter) { 120 int at_loop_iter) {
124 components_to_check_.push_back(std::make_pair(com, at_loop_iter)); 121 components_to_check_.push_back(std::make_pair(com, at_loop_iter));
125 } 122 }
126 123
127 void TestConfigurator::SetComponentUpdateService(ComponentUpdateService* cus) { 124 ComponentUpdaterTest::ComponentUpdaterTest()
128 cus_ = cus; 125 : test_config_(NULL),
129 } 126 ui_thread_(BrowserThread::UI, &message_loop_),
130 127 file_thread_(BrowserThread::FILE),
131 ComponentUpdaterTest::ComponentUpdaterTest() : test_config_(NULL) { 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_->Init(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 component installation falls back to downloading and installing 681 // Verify that component installation falls back to downloading and installing
647 // a full update if the differential update fails (in this case, because the 682 // a full update if the differential update fails (in this case, because the
648 // installer does not know about the existing files). We do two loops; the final 683 // installer does not know about the existing files). We do two loops; the final
649 // loop should do nothing. 684 // loop should do nothing.
650 // We also check that exactly 4 network requests are issued: 685 // We also check that exactly 4 non-ping network requests are issued:
651 // 1- update check (loop 1) 686 // 1- update check (loop 1)
652 // 2- download differential crx 687 // 2- download differential crx
653 // 3- download full crx 688 // 3- download full crx
654 // 4- update check (loop 2 - no update available) 689 // 4- update check (loop 2 - no update available)
690 // There should be one ping for the first attempted update.
655 TEST_F(ComponentUpdaterTest, DifferentialUpdateFails) { 691 TEST_F(ComponentUpdaterTest, DifferentialUpdateFails) {
656 base::MessageLoop message_loop; 692 std::map<std::string, std::string> map;
657 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 693 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\""));
658 content::TestBrowserThread file_thread(BrowserThread::FILE); 694 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\""));
659 content::TestBrowserThread io_thread(BrowserThread::IO); 695 map.insert(std::pair<std::string, std::string>("diffresult", "\"0\""));
660 696 map.insert(std::pair<std::string, std::string>("differrorcode", "\"16\""));
661 io_thread.StartIOThread(); 697 PingChecker ping_checker(map);
662 file_thread.Start(); 698 URLRequestPostInterceptor post_interceptor(&ping_checker);
663
664 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 699 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
665 700
666 TestInstaller installer; 701 TestInstaller installer;
667 CrxComponent com; 702 CrxComponent com;
668 RegisterComponent(&com, kTestComponent_ihfo, Version("1.0"), &installer); 703 RegisterComponent(&com, kTestComponent_ihfo, Version("1.0"), &installer);
669 704
670 const GURL expected_update_url_1( 705 const GURL expected_update_url_1(
671 "http://localhost/upd?extra=foo" 706 "http://localhost/upd?extra=foo"
672 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D%26uc"); 707 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D%26uc");
673 const GURL expected_update_url_2( 708 const GURL expected_update_url_2(
(...skipping 14 matching lines...) Expand all
688 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); 723 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"));
689 interceptor.SetResponse( 724 interceptor.SetResponse(
690 expected_crx_url_1_diff_2, 725 expected_crx_url_1_diff_2,
691 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx")); 726 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"));
692 interceptor.SetResponse(expected_crx_url_2, 727 interceptor.SetResponse(expected_crx_url_2,
693 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx")); 728 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"));
694 729
695 test_configurator()->SetLoopCount(2); 730 test_configurator()->SetLoopCount(2);
696 731
697 component_updater()->Start(); 732 component_updater()->Start();
698 message_loop.Run(); 733 message_loop_.Run();
699 734
700 // A failed differential update does not count as a failed install. 735 // A failed differential update does not count as a failed install.
701 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 736 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
702 EXPECT_EQ(1, static_cast<TestInstaller*>(com.installer)->install_count()); 737 EXPECT_EQ(1, static_cast<TestInstaller*>(com.installer)->install_count());
703 738
739 EXPECT_EQ(1, ping_checker.NumHits());
740 EXPECT_EQ(0, ping_checker.NumMisses());
704 EXPECT_EQ(4, interceptor.GetHitCount()); 741 EXPECT_EQ(4, interceptor.GetHitCount());
705 742
706 component_updater()->Stop(); 743 component_updater()->Stop();
707 } 744 }
708 745
746 // Verify that a failed installation causes an install failure ping.
747 TEST_F(ComponentUpdaterTest, CheckFailedInstallPing) {
748 std::map<std::string, std::string> map;
749 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\""));
750 map.insert(std::pair<std::string, std::string>("eventresult", "\"0\""));
751 map.insert(std::pair<std::string, std::string>("errorcode", "\"9\""));
752 map.insert(std::pair<std::string, std::string>("previousversion",
753 "\"0.9\""));
754 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\""));
755 PingChecker ping_checker(map);
756 URLRequestPostInterceptor post_interceptor(&ping_checker);
757 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
758
759 // This test installer reports installation failure.
760 class : public TestInstaller {
761 virtual bool Install(const base::DictionaryValue& manifest,
762 const base::FilePath& unpack_path) OVERRIDE {
763 ++install_count_;
764 base::Delete(unpack_path, true);
765 return false;
766 }
767 } installer;
768
769 CrxComponent com;
770 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer);
771
772 // Start with 0.9, and attempt update to 1.0
773 const GURL expected_update_url_1(
774 "http://localhost/upd?extra=foo"
775 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc");
776
777 interceptor.SetResponse(expected_update_url_1,
778 test_file("updatecheck_reply_1.xml"));
779 interceptor.SetResponse(GURL(expected_crx_url),
780 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
781
782 // Loop twice to issue two checks: (1) with original 0.9 version
783 // and (2), which should retry with 0.9.
784 test_configurator()->SetLoopCount(2);
785 component_updater()->Start();
786 message_loop_.Run();
787
788 // Loop once more, but expect no ping because a noupdate response is issued.
789 // This is necessary to clear out the fire-and-forget ping from the previous
790 // iteration.
791 interceptor.SetResponse(expected_update_url_1,
792 test_file("updatecheck_reply_noupdate.xml"));
793 test_configurator()->SetLoopCount(1);
794 component_updater()->Start();
795 message_loop_.Run();
796
797 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
798 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count());
799
800 EXPECT_EQ(2, ping_checker.NumHits());
801 EXPECT_EQ(0, ping_checker.NumMisses());
802 EXPECT_EQ(5, interceptor.GetHitCount());
803
804 component_updater()->Stop();
805 }
806
709 // Verify that we successfully propagate a patcher error. 807 // Verify that we successfully propagate a patcher error.
710 // ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx contains an incorrect 808 // ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx contains an incorrect
711 // patching instruction that should fail. 809 // patching instruction that should fail.
712 TEST_F(ComponentUpdaterTest, DifferentialUpdateFailErrorcode) { 810 TEST_F(ComponentUpdaterTest, DifferentialUpdateFailErrorcode) {
713 base::MessageLoop message_loop; 811 std::map<std::string, std::string> map;
714 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 812 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\""));
715 content::TestBrowserThread file_thread(BrowserThread::FILE); 813 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\""));
716 content::TestBrowserThread io_thread(BrowserThread::IO); 814 map.insert(std::pair<std::string, std::string>("diffresult", "\"0\""));
717 815 map.insert(std::pair<std::string, std::string>("differrorcode", "\"14\""));
718 io_thread.StartIOThread(); 816 map.insert(std::pair<std::string, std::string>("diffextracode1", "\"305\""));
719 file_thread.Start(); 817 PingChecker ping_checker(map);
720 818 URLRequestPostInterceptor post_interceptor(&ping_checker);
721 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 819 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
722 820
723 VersionedTestInstaller installer; 821 VersionedTestInstaller installer;
724 CrxComponent com; 822 CrxComponent com;
725 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer); 823 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer);
726 824
727 const GURL expected_update_url_0( 825 const GURL expected_update_url_0(
728 "http://localhost/upd?extra=foo" 826 "http://localhost/upd?extra=foo"
729 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc"); 827 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc");
730 const GURL expected_update_url_1( 828 const GURL expected_update_url_1(
(...skipping 19 matching lines...) Expand all
750 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); 848 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"));
751 interceptor.SetResponse( 849 interceptor.SetResponse(
752 expected_crx_url_1_diff_2, 850 expected_crx_url_1_diff_2,
753 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx")); 851 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx"));
754 interceptor.SetResponse(expected_crx_url_2, 852 interceptor.SetResponse(expected_crx_url_2,
755 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx")); 853 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"));
756 854
757 test_configurator()->SetLoopCount(3); 855 test_configurator()->SetLoopCount(3);
758 856
759 component_updater()->Start(); 857 component_updater()->Start();
760 message_loop.Run(); 858 message_loop_.Run();
761 859
762 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 860 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
763 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); 861 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count());
764 862
863 EXPECT_EQ(1, ping_checker.NumHits());
864 EXPECT_EQ(1, ping_checker.NumMisses());
765 EXPECT_EQ(6, interceptor.GetHitCount()); 865 EXPECT_EQ(6, interceptor.GetHitCount());
766 866
767 component_updater()->Stop(); 867 component_updater()->Stop();
768 } 868 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698