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

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

Issue 15908002: Differential updates for components. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 6 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 "chrome/browser/component_updater/component_updater_service.h"
6
7 #include <list> 5 #include <list>
8 #include <utility> 6 #include <utility>
9 7
10 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
11 #include "base/file_util.h" 9 #include "base/file_util.h"
12 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
13 #include "base/memory/scoped_vector.h" 11 #include "base/memory/scoped_vector.h"
14 #include "base/message_loop.h" 12 #include "base/message_loop.h"
15 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/stringprintf.h"
15 #include "base/strings/string_number_conversions.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #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/test_installer.h"
20 #include "chrome/browser/component_updater/test/url_request_post_interceptor.h"
17 #include "chrome/common/chrome_notification_types.h" 21 #include "chrome/common/chrome_notification_types.h"
18 #include "chrome/common/chrome_paths.h" 22 #include "chrome/common/chrome_paths.h"
19 #include "content/public/browser/notification_observer.h" 23 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_service.h" 24 #include "content/public/browser/notification_service.h"
21 #include "content/public/test/test_browser_thread.h" 25 #include "content/public/test/test_browser_thread.h"
22 #include "content/public/test/test_notification_tracker.h" 26 #include "content/public/test/test_notification_tracker.h"
23 #include "content/test/net/url_request_prepackaged_interceptor.h" 27 #include "content/test/net/url_request_prepackaged_interceptor.h"
24 #include "googleurl/src/gurl.h" 28 #include "googleurl/src/gurl.h"
25 #include "libxml/globals.h" 29 #include "libxml/globals.h"
30 #include "net/base/upload_bytes_element_reader.h"
26 #include "net/url_request/url_fetcher.h" 31 #include "net/url_request/url_fetcher.h"
32 #include "net/url_request/url_request.h"
33 #include "net/url_request/url_request_filter.h"
34 #include "net/url_request/url_request_simple_job.h"
27 #include "net/url_request/url_request_test_util.h" 35 #include "net/url_request/url_request_test_util.h"
28 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
29 37
30 using content::BrowserThread; 38 using content::BrowserThread;
31 using content::TestNotificationTracker; 39 using content::TestNotificationTracker;
32 40
33 namespace { 41 namespace {
34 // Overrides some of the component updater behaviors so it is easier to test 42
35 // and loops faster. In actual usage it takes hours do to a full cycle. 43 // component 1 has extension id "jebgalgnebhfojomionfpkfelancnnkf", and
44 // the RSA public key the following hash:
45 const uint8 jebg_hash[] = {0x94, 0x16, 0x0b, 0x6d, 0x41, 0x75, 0xe9, 0xec,
46 0x8e, 0xd5, 0xfa, 0x54, 0xb0, 0xd2, 0xdd, 0xa5,
47 0x6e, 0x05, 0x6b, 0xe8, 0x73, 0x47, 0xf6, 0xc4,
48 0x11, 0x9f, 0xbc, 0xb3, 0x09, 0xb3, 0x5b, 0x40};
49 // component 2 has extension id "abagagagagagagagagagagagagagagag", and
50 // the RSA public key the following hash:
51 const uint8 abag_hash[] = {0x01, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
52 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
53 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
54 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x01};
55 // component 3 has extension id "ihfokbkgjpifnbbojhneepfflplebdkc", and
56 // the RSA public key the following hash:
57 const uint8 ihfo_hash[] = {0x87, 0x5e, 0xa1, 0xa6, 0x9f, 0x85, 0xd1, 0x1e,
58 0x97, 0xd4, 0x4f, 0x55, 0xbf, 0xb4, 0x13, 0xa2,
59 0xe7, 0xc5, 0xc8, 0xf5, 0x60, 0x19, 0x78, 0x1b,
60 0x6d, 0xe9, 0x4c, 0xeb, 0x96, 0x05, 0x42, 0x17};
61
36 class TestConfigurator : public ComponentUpdateService::Configurator { 62 class TestConfigurator : public ComponentUpdateService::Configurator {
37 public: 63 public:
38 TestConfigurator() 64 TestConfigurator();
39 : times_(1), recheck_time_(0), ondemand_time_(0), cus_(NULL) {
40 }
41 65
42 virtual int InitialDelay() OVERRIDE { return 0; } 66 virtual int InitialDelay() OVERRIDE;
43 67
44 typedef std::pair<CrxComponent*, int> CheckAtLoopCount; 68 typedef std::pair<CrxComponent*, int> CheckAtLoopCount;
45 69
46 virtual int NextCheckDelay() OVERRIDE { 70 virtual int NextCheckDelay() OVERRIDE;
47 // This is called when a new full cycle of checking for updates is going
48 // to happen. In test we normally only test one cycle so it is a good
49 // time to break from the test messageloop Run() method so the test can
50 // finish.
51 if (--times_ <= 0) {
52 base::MessageLoop::current()->Quit();
53 return 0;
54 71
55 } 72 virtual int StepDelay() OVERRIDE;
56 73
57 // Look for checks to issue in the middle of the loop. 74 virtual int MinimumReCheckWait() OVERRIDE;
58 for (std::list<CheckAtLoopCount>::iterator
59 i = components_to_check_.begin();
60 i != components_to_check_.end(); ) {
61 if (i->second == times_) {
62 cus_->CheckForUpdateSoon(*i->first);
63 i = components_to_check_.erase(i);
64 } else {
65 ++i;
66 }
67 }
68 return 1;
69 }
70 75
71 virtual int StepDelay() OVERRIDE { 76 virtual int OnDemandDelay() OVERRIDE;
72 return 0;
73 }
74 77
75 virtual int MinimumReCheckWait() OVERRIDE { 78 virtual GURL UpdateUrl(CrxComponent::UrlSource source) OVERRIDE;
76 return recheck_time_;
77 }
78 79
79 virtual int OnDemandDelay() OVERRIDE { 80 virtual const char* ExtraRequestParams() OVERRIDE;
80 return ondemand_time_;
81 }
82 81
83 virtual GURL UpdateUrl(CrxComponent::UrlSource source) OVERRIDE { 82 virtual size_t UrlSizeLimit() OVERRIDE;
84 switch (source) {
85 case CrxComponent::BANDAID:
86 return GURL("http://localhost/upd");
87 case CrxComponent::CWS_PUBLIC:
88 return GURL("http://localhost/cws");
89 default:
90 return GURL("http://wronghost/bad");
91 };
92 }
93 83
94 virtual const char* ExtraRequestParams() OVERRIDE { return "extra=foo"; } 84 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE;
95
96 virtual size_t UrlSizeLimit() OVERRIDE { return 256; }
97
98 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE {
99 return new net::TestURLRequestContextGetter(
100 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
101 }
102 85
103 // Don't use the utility process to decode files. 86 // Don't use the utility process to decode files.
104 virtual bool InProcess() OVERRIDE { return true; } 87 virtual bool InProcess() OVERRIDE;
105 88
106 virtual void OnEvent(Events event, int extra) OVERRIDE { } 89 virtual void OnEvent(Events event, int extra) OVERRIDE;
107 90
108 // Set how many update checks are called, the default value is just once. 91 virtual ComponentPatcher* CreateComponentPatcher() OVERRIDE;
109 void SetLoopCount(int times) { times_ = times; }
110 92
111 void SetRecheckTime(int seconds) { 93 virtual bool DeltasEnabled() const OVERRIDE;
112 recheck_time_ = seconds;
113 }
114 94
115 void SetOnDemandTime(int seconds) { 95 void SetLoopCount(int times);
116 ondemand_time_ = seconds;
117 }
118 96
119 void AddComponentToCheck(CrxComponent* com, int at_loop_iter) { 97 void SetRecheckTime(int seconds);
120 components_to_check_.push_back(std::make_pair(com, at_loop_iter));
121 }
122 98
123 void SetComponentUpdateService(ComponentUpdateService* cus) { 99 void SetOnDemandTime(int seconds);
124 cus_ = cus; 100
125 } 101 void AddComponentToCheck(CrxComponent* com, int at_loop_iter);
102
103 void SetComponentUpdateService(ComponentUpdateService* cus);
126 104
127 private: 105 private:
128 int times_; 106 int times_;
129 int recheck_time_; 107 int recheck_time_;
130 int ondemand_time_; 108 int ondemand_time_;
131 109
132 std::list<CheckAtLoopCount> components_to_check_; 110 std::list<CheckAtLoopCount> components_to_check_;
133 ComponentUpdateService* cus_; 111 ComponentUpdateService* cus_;
134 }; 112 };
135 113
136 class TestInstaller : public ComponentInstaller {
137 public :
138 explicit TestInstaller()
139 : error_(0), install_count_(0) {
140 }
141
142 virtual void OnUpdateError(int error) OVERRIDE {
143 EXPECT_NE(0, error);
144 error_ = error;
145 }
146
147 virtual bool Install(const base::DictionaryValue& manifest,
148 const base::FilePath& unpack_path) OVERRIDE {
149 ++install_count_;
150 return file_util::Delete(unpack_path, true);
151 }
152
153 int error() const { return error_; }
154
155 int install_count() const { return install_count_; }
156
157 private:
158 int error_;
159 int install_count_;
160 };
161
162 // component 1 has extension id "jebgalgnebhfojomionfpkfelancnnkf", and
163 // the RSA public key the following hash:
164 const uint8 jebg_hash[] = {0x94,0x16,0x0b,0x6d,0x41,0x75,0xe9,0xec,0x8e,0xd5,
165 0xfa,0x54,0xb0,0xd2,0xdd,0xa5,0x6e,0x05,0x6b,0xe8,
166 0x73,0x47,0xf6,0xc4,0x11,0x9f,0xbc,0xb3,0x09,0xb3,
167 0x5b,0x40};
168 // component 2 has extension id "abagagagagagagagagagagagagagagag", and
169 // the RSA public key the following hash:
170 const uint8 abag_hash[] = {0x01,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,
171 0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,
172 0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,
173 0x06,0x01};
174
175 const char expected_crx_url[] =
176 "http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx";
177
178 } // namespace
179
180 // Common fixture for all the component updater tests.
181 class ComponentUpdaterTest : public testing::Test { 114 class ComponentUpdaterTest : public testing::Test {
182 public: 115 public:
183 enum TestComponents { 116 enum TestComponents {
184 kTestComponent_abag, 117 kTestComponent_abag,
185 kTestComponent_jebg 118 kTestComponent_jebg,
119 kTestComponent_ihfo,
186 }; 120 };
187 121
188 ComponentUpdaterTest() : test_config_(NULL) { 122 ComponentUpdaterTest();
189 // The component updater instance under test. 123
190 test_config_ = new TestConfigurator; 124 virtual ~ComponentUpdaterTest();
191 component_updater_.reset(ComponentUpdateServiceFactory(test_config_)); 125
192 test_config_->SetComponentUpdateService(component_updater_.get()); 126 virtual void TearDown();
193 // The test directory is chrome/test/data/components. 127
194 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); 128 ComponentUpdateService* component_updater();
195 test_data_dir_ = test_data_dir_.AppendASCII("components");
196
197 // Subscribe to all component updater notifications.
198 const int notifications[] = {
199 chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED,
200 chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING,
201 chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND,
202 chrome::NOTIFICATION_COMPONENT_UPDATE_READY
203 };
204
205 for (int ix = 0; ix != arraysize(notifications); ++ix) {
206 notification_tracker_.ListenFor(
207 notifications[ix], content::NotificationService::AllSources());
208 }
209 net::URLFetcher::SetEnableInterceptionForTests(true);
210 }
211
212 virtual ~ComponentUpdaterTest() {
213 net::URLFetcher::SetEnableInterceptionForTests(false);
214 }
215
216 virtual void TearDown() {
217 xmlCleanupGlobals();
218 }
219
220 ComponentUpdateService* component_updater() {
221 return component_updater_.get();
222 }
223 129
224 // Makes the full path to a component updater test file. 130 // Makes the full path to a component updater test file.
225 const base::FilePath test_file(const char* file) { 131 const base::FilePath test_file(const char* file);
226 return test_data_dir_.AppendASCII(file); 132
227 } 133 TestNotificationTracker& notification_tracker();
228 134
229 TestNotificationTracker& notification_tracker() { 135 TestConfigurator* test_configurator();
230 return notification_tracker_;
231 }
232
233 TestConfigurator* test_configurator() {
234 return test_config_;
235 }
236 136
237 ComponentUpdateService::Status RegisterComponent(CrxComponent* com, 137 ComponentUpdateService::Status RegisterComponent(CrxComponent* com,
238 TestComponents component, 138 TestComponents component,
239 const Version& version) { 139 const Version& version,
240 if (component == kTestComponent_abag) { 140 TestInstaller* installer);
241 com->name = "test_abag";
242 com->pk_hash.assign(abag_hash, abag_hash + arraysize(abag_hash));
243 } else {
244 com->name = "test_jebg";
245 com->pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash));
246 }
247 com->version = version;
248 TestInstaller* installer = new TestInstaller;
249 com->installer = installer;
250 test_installers_.push_back(installer);
251 return component_updater_->RegisterComponent(*com);
252 }
253 141
254 private: 142 private:
255 scoped_ptr<ComponentUpdateService> component_updater_; 143 scoped_ptr<ComponentUpdateService> component_updater_;
256 base::FilePath test_data_dir_; 144 base::FilePath test_data_dir_;
257 TestNotificationTracker notification_tracker_; 145 TestNotificationTracker notification_tracker_;
258 TestConfigurator* test_config_; 146 TestConfigurator* test_config_;
259 // ComponentInstaller objects to delete after each test.
260 ScopedVector<TestInstaller> test_installers_;
261 }; 147 };
262 148
149 const char expected_crx_url[] =
150 "http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx";
151
152 } // namespace
153
154 TestConfigurator::TestConfigurator()
155 : times_(1), recheck_time_(0), ondemand_time_(0), cus_(NULL) {
156 }
157
158 int TestConfigurator::InitialDelay() { return 0; }
159
160 int TestConfigurator::NextCheckDelay() {
161 // This is called when a new full cycle of checking for updates is going
162 // to happen. In test we normally only test one cycle so it is a good
163 // time to break from the test messageloop Run() method so the test can
164 // finish.
165 if (--times_ <= 0) {
166 base::MessageLoop::current()->Quit();
167 return 0;
168 }
169
170 // Look for checks to issue in the middle of the loop.
171 for (std::list<CheckAtLoopCount>::iterator
172 i = components_to_check_.begin();
173 i != components_to_check_.end(); ) {
174 if (i->second == times_) {
175 cus_->CheckForUpdateSoon(*i->first);
176 i = components_to_check_.erase(i);
177 } else {
178 ++i;
179 }
180 }
181 return 1;
182 }
183
184 int TestConfigurator::StepDelay() {
185 return 0;
186 }
187
188 int TestConfigurator::MinimumReCheckWait() {
189 return recheck_time_;
190 }
191
192 int TestConfigurator::OnDemandDelay() {
193 return ondemand_time_;
194 }
195
196 GURL TestConfigurator::UpdateUrl(CrxComponent::UrlSource source) {
197 switch (source) {
198 case CrxComponent::BANDAID:
199 return GURL("http://localhost/upd");
200 case CrxComponent::CWS_PUBLIC:
201 return GURL("http://localhost/cws");
202 default:
203 return GURL("http://wronghost/bad");
204 };
205 }
206
207 const char* TestConfigurator::ExtraRequestParams() { return "extra=foo"; }
208
209 size_t TestConfigurator::UrlSizeLimit() { return 256; }
210
211 net::URLRequestContextGetter* TestConfigurator::RequestContext() {
212 return new net::TestURLRequestContextGetter(
213 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
214 }
215
216 // Don't use the utility process to decode files.
217 bool TestConfigurator::InProcess() { return true; }
218
219 void TestConfigurator::OnEvent(Events event, int extra) { }
220
221 ComponentPatcher* TestConfigurator::CreateComponentPatcher() {
222 return new MockComponentPatcher();
223 }
224
225 bool TestConfigurator::DeltasEnabled() const {
226 return true;
227 }
228
229 // Set how many update checks are called, the default value is just once.
230 void TestConfigurator::SetLoopCount(int times) { times_ = times; }
231
232 void TestConfigurator::SetRecheckTime(int seconds) {
233 recheck_time_ = seconds;
234 }
235
236 void TestConfigurator::SetOnDemandTime(int seconds) {
237 ondemand_time_ = seconds;
238 }
239
240 void TestConfigurator::AddComponentToCheck(CrxComponent* com,
241 int at_loop_iter) {
242 components_to_check_.push_back(std::make_pair(com, at_loop_iter));
243 }
244
245 void TestConfigurator::SetComponentUpdateService(ComponentUpdateService* cus) {
246 cus_ = cus;
247 }
248
249 ComponentUpdaterTest::ComponentUpdaterTest() : test_config_(NULL) {
250 // The component updater instance under test.
251 test_config_ = new TestConfigurator;
252 component_updater_.reset(ComponentUpdateServiceFactory(test_config_));
253 test_config_->SetComponentUpdateService(component_updater_.get());
254 // The test directory is chrome/test/data/components.
255 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_);
256 test_data_dir_ = test_data_dir_.AppendASCII("components");
257
258 // Subscribe to all component updater notifications.
259 const int notifications[] = {
260 chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED,
261 chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING,
262 chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND,
263 chrome::NOTIFICATION_COMPONENT_UPDATE_READY
264 };
265
266 for (int ix = 0; ix != arraysize(notifications); ++ix) {
267 notification_tracker_.ListenFor(
268 notifications[ix], content::NotificationService::AllSources());
269 }
270 net::URLFetcher::SetEnableInterceptionForTests(true);
271 }
272
273 ComponentUpdaterTest::~ComponentUpdaterTest() {
274 net::URLFetcher::SetEnableInterceptionForTests(false);
275 }
276
277 void ComponentUpdaterTest::TearDown() {
278 xmlCleanupGlobals();
279 }
280
281 ComponentUpdateService* ComponentUpdaterTest::component_updater() {
282 return component_updater_.get();
283 }
284
285 // Makes the full path to a component updater test file.
286 const base::FilePath ComponentUpdaterTest::test_file(const char* file) {
287 return test_data_dir_.AppendASCII(file);
288 }
289
290 TestNotificationTracker& ComponentUpdaterTest::notification_tracker() {
291 return notification_tracker_;
292 }
293
294 TestConfigurator* ComponentUpdaterTest::test_configurator() {
295 return test_config_;
296 }
297
298 ComponentUpdateService::Status ComponentUpdaterTest::RegisterComponent(
299 CrxComponent* com,
300 TestComponents component,
301 const Version& version,
302 TestInstaller* installer) {
303 if (component == kTestComponent_abag) {
304 com->name = "test_abag";
305 com->pk_hash.assign(abag_hash, abag_hash + arraysize(abag_hash));
306 } else if (component == kTestComponent_jebg) {
307 com->name = "test_jebg";
308 com->pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash));
309 } else {
310 com->name = "test_ihfo";
311 com->pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash));
312 }
313 com->version = version;
314 com->installer = installer;
315 return component_updater_->RegisterComponent(*com);
316 }
317
263 // Verify that our test fixture work and the component updater can 318 // Verify that our test fixture work and the component updater can
264 // be created and destroyed with no side effects. 319 // be created and destroyed with no side effects.
265 TEST_F(ComponentUpdaterTest, VerifyFixture) { 320 TEST_F(ComponentUpdaterTest, VerifyFixture) {
266 EXPECT_TRUE(component_updater() != NULL); 321 EXPECT_TRUE(component_updater() != NULL);
267 EXPECT_EQ(0ul, notification_tracker().size()); 322 EXPECT_EQ(0ul, notification_tracker().size());
268 } 323 }
269 324
270 // Verify that the component updater can be caught in a quick 325 // Verify that the component updater can be caught in a quick
271 // start-shutdown situation. Failure of this test will be a crash. Also 326 // start-shutdown situation. Failure of this test will be a crash. Also
272 // if there is no work to do, there are no notifications generated. 327 // if there is no work to do, there are no notifications generated.
(...skipping 15 matching lines...) Expand all
288 base::MessageLoop message_loop; 343 base::MessageLoop message_loop;
289 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 344 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
290 content::TestBrowserThread file_thread(BrowserThread::FILE); 345 content::TestBrowserThread file_thread(BrowserThread::FILE);
291 content::TestBrowserThread io_thread(BrowserThread::IO); 346 content::TestBrowserThread io_thread(BrowserThread::IO);
292 347
293 io_thread.StartIOThread(); 348 io_thread.StartIOThread();
294 file_thread.Start(); 349 file_thread.Start();
295 350
296 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 351 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
297 352
353 TestInstaller installer;
298 CrxComponent com; 354 CrxComponent com;
299 EXPECT_EQ(ComponentUpdateService::kOk, 355 EXPECT_EQ(ComponentUpdateService::kOk,
300 RegisterComponent(&com, kTestComponent_abag, Version("1.1"))); 356 RegisterComponent(&com,
357 kTestComponent_abag,
358 Version("1.1"),
359 &installer));
301 360
302 const GURL expected_update_url( 361 const GURL expected_update_url(
303 "http://localhost/upd?extra=foo&x=id%3D" 362 "http://localhost/upd?extra=foo"
304 "abagagagagagagagagagagagagagagag%26v%3D1.1%26uc"); 363 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D1.1%26fp%3D%26uc");
305 364
306 interceptor.SetResponse(expected_update_url, 365 interceptor.SetResponse(expected_update_url,
307 test_file("updatecheck_reply_1.xml")); 366 test_file("updatecheck_reply_1.xml"));
308 367
309 // We loop twice, but there are no updates so we expect two sleep messages. 368 // We loop twice, but there are no updates so we expect two sleep messages.
310 test_configurator()->SetLoopCount(2); 369 test_configurator()->SetLoopCount(2);
311 component_updater()->Start(); 370 component_updater()->Start();
312 371
313 ASSERT_EQ(1ul, notification_tracker().size()); 372 ASSERT_EQ(1ul, notification_tracker().size());
314 TestNotificationTracker::Event ev1 = notification_tracker().at(0); 373 TestNotificationTracker::Event ev1 = notification_tracker().at(0);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 base::MessageLoop message_loop; 426 base::MessageLoop message_loop;
368 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 427 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
369 content::TestBrowserThread file_thread(BrowserThread::FILE); 428 content::TestBrowserThread file_thread(BrowserThread::FILE);
370 content::TestBrowserThread io_thread(BrowserThread::IO); 429 content::TestBrowserThread io_thread(BrowserThread::IO);
371 430
372 io_thread.StartIOThread(); 431 io_thread.StartIOThread();
373 file_thread.Start(); 432 file_thread.Start();
374 433
375 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 434 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
376 435
436 TestInstaller installer1;
377 CrxComponent com1; 437 CrxComponent com1;
378 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9")); 438 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1);
439 TestInstaller installer2;
379 CrxComponent com2; 440 CrxComponent com2;
380 RegisterComponent(&com2, kTestComponent_abag, Version("2.2")); 441 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2);
381 442
382 const GURL expected_update_url_1( 443 const GURL expected_update_url_1(
383 "http://localhost/upd?extra=foo&x=id%3D" 444 "http://localhost/upd?extra=foo"
384 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc&x=id%3D" 445 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"
385 "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc"); 446 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc");
386 447
387 const GURL expected_update_url_2( 448 const GURL expected_update_url_2(
388 "http://localhost/upd?extra=foo&x=id%3D" 449 "http://localhost/upd?extra=foo"
389 "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc&x=id%3D" 450 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"
390 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26uc"); 451 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26fp%3D%26uc");
391 452
392 interceptor.SetResponse(expected_update_url_1, 453 interceptor.SetResponse(expected_update_url_1,
393 test_file("updatecheck_reply_1.xml")); 454 test_file("updatecheck_reply_1.xml"));
394 interceptor.SetResponse(expected_update_url_2, 455 interceptor.SetResponse(expected_update_url_2,
395 test_file("updatecheck_reply_1.xml")); 456 test_file("updatecheck_reply_1.xml"));
396 interceptor.SetResponse(GURL(expected_crx_url), 457 interceptor.SetResponse(GURL(expected_crx_url),
397 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); 458 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
398 459
399 test_configurator()->SetLoopCount(2); 460 test_configurator()->SetLoopCount(2);
400 461
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 base::MessageLoop message_loop; 493 base::MessageLoop message_loop;
433 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 494 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
434 content::TestBrowserThread file_thread(BrowserThread::FILE); 495 content::TestBrowserThread file_thread(BrowserThread::FILE);
435 content::TestBrowserThread io_thread(BrowserThread::IO); 496 content::TestBrowserThread io_thread(BrowserThread::IO);
436 497
437 io_thread.StartIOThread(); 498 io_thread.StartIOThread();
438 file_thread.Start(); 499 file_thread.Start();
439 500
440 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 501 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
441 502
503 TestInstaller installer1;
442 CrxComponent com1; 504 CrxComponent com1;
443 RegisterComponent(&com1, kTestComponent_abag, Version("2.2")); 505 RegisterComponent(&com1, kTestComponent_abag, Version("2.2"), &installer1);
506 TestInstaller installer2;
444 CrxComponent com2; 507 CrxComponent com2;
445 com2.source = CrxComponent::CWS_PUBLIC; 508 com2.source = CrxComponent::CWS_PUBLIC;
446 RegisterComponent(&com2, kTestComponent_jebg, Version("0.9")); 509 RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"), &installer2);
447 510
448 const GURL expected_update_url_1( 511 const GURL expected_update_url_1(
449 "http://localhost/upd?extra=foo&x=id%3D" 512 "http://localhost/upd?extra=foo&x=id%3D"
450 "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc"); 513 "abagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc");
451 514
452 const GURL expected_update_url_2( 515 const GURL expected_update_url_2(
453 "http://localhost/cws?extra=foo&x=id%3D" 516 "http://localhost/cws?extra=foo&x=id%3D"
454 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc"); 517 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc");
455 518
456 interceptor.SetResponse(expected_update_url_1, 519 interceptor.SetResponse(expected_update_url_1,
457 test_file("updatecheck_reply_3.xml")); 520 test_file("updatecheck_reply_3.xml"));
458 interceptor.SetResponse(expected_update_url_2, 521 interceptor.SetResponse(expected_update_url_2,
459 test_file("updatecheck_reply_1.xml")); 522 test_file("updatecheck_reply_1.xml"));
460 interceptor.SetResponse(GURL(expected_crx_url), 523 interceptor.SetResponse(GURL(expected_crx_url),
461 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); 524 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
462 525
463 test_configurator()->SetLoopCount(3); 526 test_configurator()->SetLoopCount(3);
464 527
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 base::MessageLoop message_loop; 567 base::MessageLoop message_loop;
505 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 568 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
506 content::TestBrowserThread file_thread(BrowserThread::FILE); 569 content::TestBrowserThread file_thread(BrowserThread::FILE);
507 content::TestBrowserThread io_thread(BrowserThread::IO); 570 content::TestBrowserThread io_thread(BrowserThread::IO);
508 571
509 io_thread.StartIOThread(); 572 io_thread.StartIOThread();
510 file_thread.Start(); 573 file_thread.Start();
511 574
512 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 575 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
513 576
577 TestInstaller installer;
514 CrxComponent com; 578 CrxComponent com;
515 RegisterComponent(&com, kTestComponent_jebg, Version("0.9")); 579 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer);
516 580
517 const GURL expected_update_url( 581 const GURL expected_update_url(
518 "http://localhost/upd?extra=foo&x=id%3D" 582 "http://localhost/upd?extra=foo&x=id%3D"
519 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc"); 583 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc");
520 584
521 interceptor.SetResponse(expected_update_url, 585 interceptor.SetResponse(expected_update_url,
522 test_file("updatecheck_reply_2.xml")); 586 test_file("updatecheck_reply_2.xml"));
523 interceptor.SetResponse(GURL(expected_crx_url), 587 interceptor.SetResponse(GURL(expected_crx_url),
524 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); 588 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
525 589
526 test_configurator()->SetLoopCount(1); 590 test_configurator()->SetLoopCount(1);
527 component_updater()->Start(); 591 component_updater()->Start();
528 message_loop.Run(); 592 message_loop.Run();
529 593
(...skipping 14 matching lines...) Expand all
544 base::MessageLoop message_loop; 608 base::MessageLoop message_loop;
545 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 609 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
546 content::TestBrowserThread file_thread(BrowserThread::FILE); 610 content::TestBrowserThread file_thread(BrowserThread::FILE);
547 content::TestBrowserThread io_thread(BrowserThread::IO); 611 content::TestBrowserThread io_thread(BrowserThread::IO);
548 612
549 io_thread.StartIOThread(); 613 io_thread.StartIOThread();
550 file_thread.Start(); 614 file_thread.Start();
551 615
552 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 616 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
553 617
618 TestInstaller installer1;
554 CrxComponent com1; 619 CrxComponent com1;
555 RegisterComponent(&com1, kTestComponent_abag, Version("2.2")); 620 RegisterComponent(&com1, kTestComponent_abag, Version("2.2"), &installer1);
621 TestInstaller installer2;
556 CrxComponent com2; 622 CrxComponent com2;
557 RegisterComponent(&com2, kTestComponent_jebg, Version("0.9")); 623 RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"), &installer2);
558 624
559 const GURL expected_update_url_1( 625 const GURL expected_update_url_1(
560 "http://localhost/upd?extra=foo&x=id%3D" 626 "http://localhost/upd?extra=foo"
561 "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc&x=id%3D" 627 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"
562 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc"); 628 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc");
563 629
564 const GURL expected_update_url_2( 630 const GURL expected_update_url_2(
565 "http://localhost/upd?extra=foo&x=id%3D" 631 "http://localhost/upd?extra=foo"
566 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc&x=id%3D" 632 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"
567 "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc"); 633 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc");
568 634
569 interceptor.SetResponse(expected_update_url_1, 635 interceptor.SetResponse(expected_update_url_1,
570 test_file("updatecheck_reply_empty")); 636 test_file("updatecheck_reply_empty"));
571 interceptor.SetResponse(expected_update_url_2, 637 interceptor.SetResponse(expected_update_url_2,
572 test_file("updatecheck_reply_1.xml")); 638 test_file("updatecheck_reply_1.xml"));
573 interceptor.SetResponse(GURL(expected_crx_url), 639 interceptor.SetResponse(GURL(expected_crx_url),
574 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); 640 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
575 // Test success. 641 // Test success.
576 test_configurator()->SetLoopCount(2); 642 test_configurator()->SetLoopCount(2);
577 test_configurator()->AddComponentToCheck(&com2, 1); 643 test_configurator()->AddComponentToCheck(&com2, 1);
(...skipping 28 matching lines...) Expand all
606 test_configurator()->SetOnDemandTime(60 * 60); 672 test_configurator()->SetOnDemandTime(60 * 60);
607 EXPECT_EQ(ComponentUpdateService::kError, 673 EXPECT_EQ(ComponentUpdateService::kError,
608 component_updater()->CheckForUpdateSoon(com2)); 674 component_updater()->CheckForUpdateSoon(com2));
609 // Okay, now reset to 0 for the other tests. 675 // Okay, now reset to 0 for the other tests.
610 test_configurator()->SetOnDemandTime(0); 676 test_configurator()->SetOnDemandTime(0);
611 component_updater()->Stop(); 677 component_updater()->Stop();
612 678
613 // Test a few error cases. NOTE: We don't have callbacks for 679 // Test a few error cases. NOTE: We don't have callbacks for
614 // when the updates failed yet. 680 // when the updates failed yet.
615 const GURL expected_update_url_3( 681 const GURL expected_update_url_3(
616 "http://localhost/upd?extra=foo&x=id%3D" 682 "http://localhost/upd?extra=foo"
617 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26uc&x=id%3D" 683 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26fp%3D%26uc"
618 "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc"); 684 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc");
619 685
620 // No update: error from no server response 686 // No update: error from no server response
621 interceptor.SetResponse(expected_update_url_3, 687 interceptor.SetResponse(expected_update_url_3,
622 test_file("updatecheck_reply_empty")); 688 test_file("updatecheck_reply_empty"));
623 notification_tracker().Reset(); 689 notification_tracker().Reset();
624 test_configurator()->SetLoopCount(1); 690 test_configurator()->SetLoopCount(1);
625 component_updater()->Start(); 691 component_updater()->Start();
626 EXPECT_EQ(ComponentUpdateService::kOk, 692 EXPECT_EQ(ComponentUpdateService::kOk,
627 component_updater()->CheckForUpdateSoon(com2)); 693 component_updater()->CheckForUpdateSoon(com2));
628 694
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 base::MessageLoop message_loop; 726 base::MessageLoop message_loop;
661 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 727 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
662 content::TestBrowserThread file_thread(BrowserThread::FILE); 728 content::TestBrowserThread file_thread(BrowserThread::FILE);
663 content::TestBrowserThread io_thread(BrowserThread::IO); 729 content::TestBrowserThread io_thread(BrowserThread::IO);
664 730
665 io_thread.StartIOThread(); 731 io_thread.StartIOThread();
666 file_thread.Start(); 732 file_thread.Start();
667 733
668 content::URLLocalHostRequestPrepackagedInterceptor interceptor; 734 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
669 735
736 TestInstaller installer1;
670 CrxComponent com1; 737 CrxComponent com1;
671 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9")); 738 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1);
739 TestInstaller installer2;
672 CrxComponent com2; 740 CrxComponent com2;
673 RegisterComponent(&com2, kTestComponent_abag, Version("2.2")); 741 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2);
674 742
675 // Start with 0.9, and update to 1.0 743 // Start with 0.9, and update to 1.0
676 const GURL expected_update_url_1( 744 const GURL expected_update_url_1(
677 "http://localhost/upd?extra=foo&x=id%3D" 745 "http://localhost/upd?extra=foo"
678 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc&x=id%3D" 746 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"
679 "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc"); 747 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc");
680 748
681 const GURL expected_update_url_2( 749 const GURL expected_update_url_2(
682 "http://localhost/upd?extra=foo&x=id%3D" 750 "http://localhost/upd?extra=foo"
683 "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc&x=id%3D" 751 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"
684 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26uc"); 752 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26fp%3D%26uc");
685 753
686 interceptor.SetResponse(expected_update_url_1, 754 interceptor.SetResponse(expected_update_url_1,
687 test_file("updatecheck_reply_1.xml")); 755 test_file("updatecheck_reply_1.xml"));
688 interceptor.SetResponse(expected_update_url_2, 756 interceptor.SetResponse(expected_update_url_2,
689 test_file("updatecheck_reply_1.xml")); 757 test_file("updatecheck_reply_1.xml"));
690 interceptor.SetResponse(GURL(expected_crx_url), 758 interceptor.SetResponse(GURL(expected_crx_url),
691 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); 759 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
692 760
693 // Loop twice to issue two checks: (1) with original 0.9 version 761 // Loop twice to issue two checks: (1) with original 0.9 version
694 // and (2) with the updated 1.0 version. 762 // and (2) with the updated 1.0 version.
(...skipping 20 matching lines...) Expand all
715 TestNotificationTracker::Event ev2 = notification_tracker().at(2); 783 TestNotificationTracker::Event ev2 = notification_tracker().at(2);
716 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); 784 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type);
717 785
718 TestNotificationTracker::Event ev3 = notification_tracker().at(3); 786 TestNotificationTracker::Event ev3 = notification_tracker().at(3);
719 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); 787 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type);
720 788
721 TestNotificationTracker::Event ev4 = notification_tracker().at(4); 789 TestNotificationTracker::Event ev4 = notification_tracker().at(4);
722 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type); 790 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type);
723 791
724 // Now re-register, pretending to be an even newer version (2.2) 792 // Now re-register, pretending to be an even newer version (2.2)
793 TestInstaller installer3;
725 component_updater()->Stop(); 794 component_updater()->Stop();
726 EXPECT_EQ(ComponentUpdateService::kReplaced, 795 EXPECT_EQ(ComponentUpdateService::kReplaced,
727 RegisterComponent(&com1, kTestComponent_jebg, Version("2.2"))); 796 RegisterComponent(&com1,
797 kTestComponent_jebg,
798 Version("2.2"),
799 &installer3));
728 800
729 // Check that we send out 2.2 as our version. 801 // Check that we send out 2.2 as our version.
730 // Interceptor's hit count should go up by 1. 802 // Interceptor's hit count should go up by 1.
731 const GURL expected_update_url_3( 803 const GURL expected_update_url_3(
732 "http://localhost/upd?extra=foo&x=id%3D" 804 "http://localhost/upd?extra=foo"
733 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D2.2%26uc&x=id%3D" 805 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D2.2%26fp%3D%26uc"
734 "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc"); 806 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc");
735 807
736 interceptor.SetResponse(expected_update_url_3, 808 interceptor.SetResponse(expected_update_url_3,
737 test_file("updatecheck_reply_1.xml")); 809 test_file("updatecheck_reply_1.xml"));
738 810
739 notification_tracker().Reset(); 811 notification_tracker().Reset();
740 812
741 // Loop once just to notice the check happening with the re-register version. 813 // Loop once just to notice the check happening with the re-register version.
742 test_configurator()->SetLoopCount(1); 814 test_configurator()->SetLoopCount(1);
743 component_updater()->Start(); 815 component_updater()->Start();
744 message_loop.Run(); 816 message_loop.Run();
745 817
746 ASSERT_EQ(2ul, notification_tracker().size()); 818 ASSERT_EQ(2ul, notification_tracker().size());
747 819
748 ev0 = notification_tracker().at(0); 820 ev0 = notification_tracker().at(0);
749 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); 821 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type);
750 822
751 ev1 = notification_tracker().at(1); 823 ev1 = notification_tracker().at(1);
752 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type); 824 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type);
753 825
754 EXPECT_EQ(4, interceptor.GetHitCount()); 826 EXPECT_EQ(4, interceptor.GetHitCount());
755 827
756 // The test harness's Register() function creates a new installer, 828 // We created a new installer, so the counts go back to 0.
757 // so the counts go back to 0.
758 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); 829 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
759 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count()); 830 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count());
760 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); 831 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
761 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); 832 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count());
762 833
763 component_updater()->Stop(); 834 component_updater()->Stop();
764 } 835 }
836
837 // Verify that we can download and install a component and a differential
838 // update to that component. We do three loops; the final loop should do
839 // nothing.
840 // We also check that exactly 5 network requests are issued:
841 // 1- update check (response: v1 available)
842 // 2- download crx (v1)
843 // 3- update check (response: v2 available)
844 // 4- download differential crx (v1 to v2)
845 // 5- update check (response: no further update available)
846 TEST_F(ComponentUpdaterTest, DifferentialUpdate) {
847 base::MessageLoop message_loop;
848 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
849 content::TestBrowserThread file_thread(BrowserThread::FILE);
850 content::TestBrowserThread io_thread(BrowserThread::IO);
851
852 io_thread.StartIOThread();
853 file_thread.Start();
854
855 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
856
857 VersionedTestInstaller installer;
858 CrxComponent com;
859 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer);
860
861 const GURL expected_update_url_0(
862 "http://localhost/upd?extra=foo"
863 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc");
864 const GURL expected_update_url_1(
865 "http://localhost/upd?extra=foo"
866 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D1%26uc");
867 const GURL expected_update_url_2(
868 "http://localhost/upd?extra=foo"
869 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D2.0%26fp%3Df22%26uc");
870 const GURL expected_crx_url_1(
871 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx");
872 const GURL expected_crx_url_1_diff_2(
873 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx");
874
875 interceptor.SetResponse(expected_update_url_0,
876 test_file("updatecheck_diff_reply_1.xml"));
877 interceptor.SetResponse(expected_update_url_1,
878 test_file("updatecheck_diff_reply_2.xml"));
879 interceptor.SetResponse(expected_update_url_2,
880 test_file("updatecheck_diff_reply_3.xml"));
881 interceptor.SetResponse(expected_crx_url_1,
882 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"));
883 interceptor.SetResponse(
884 expected_crx_url_1_diff_2,
885 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"));
886
887 test_configurator()->SetLoopCount(3);
888
889 component_updater()->Start();
890 message_loop.Run();
891
892 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
893 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count());
894
895 EXPECT_EQ(5, interceptor.GetHitCount());
896
897 component_updater()->Stop();
898 }
899
900 // Verify that component installation falls back to downloading and installing
901 // a full update if the differential update fails (in this case, because the
902 // installer does not know about the existing files). We do two loops; the final
903 // loop should do nothing.
904 // We also check that exactly 4 network requests are issued:
905 // 1- update check (loop 1)
906 // 2- download differential crx
907 // 3- download full crx
908 // 4- update check (loop 2 - no update available)
909 TEST_F(ComponentUpdaterTest, DifferentialUpdateFails) {
910 base::MessageLoop message_loop;
911 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
912 content::TestBrowserThread file_thread(BrowserThread::FILE);
913 content::TestBrowserThread io_thread(BrowserThread::IO);
914
915 io_thread.StartIOThread();
916 file_thread.Start();
917
918 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
919
920 TestInstaller installer;
921 CrxComponent com;
922 RegisterComponent(&com, kTestComponent_ihfo, Version("1.0"), &installer);
923
924 const GURL expected_update_url_1(
925 "http://localhost/upd?extra=foo"
926 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D%26uc");
927 const GURL expected_update_url_2(
928 "http://localhost/upd?extra=foo"
929 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D2.0%26fp%3Df22%26uc");
930 const GURL expected_crx_url_1(
931 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx");
932 const GURL expected_crx_url_1_diff_2(
933 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx");
934 const GURL expected_crx_url_2(
935 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx");
936
937 interceptor.SetResponse(expected_update_url_1,
938 test_file("updatecheck_diff_reply_2.xml"));
939 interceptor.SetResponse(expected_update_url_2,
940 test_file("updatecheck_diff_reply_3.xml"));
941 interceptor.SetResponse(expected_crx_url_1,
942 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"));
943 interceptor.SetResponse(
944 expected_crx_url_1_diff_2,
945 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"));
946 interceptor.SetResponse(expected_crx_url_2,
947 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"));
948
949 test_configurator()->SetLoopCount(2);
950
951 component_updater()->Start();
952 message_loop.Run();
953
954 // A failed differential update does not count as a failed install.
955 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
956 EXPECT_EQ(1, static_cast<TestInstaller*>(com.installer)->install_count());
957
958 EXPECT_EQ(4, interceptor.GetHitCount());
959
960 component_updater()->Stop();
961 }
962
963 // Verify that we successfully propagate a patcher error.
964 // ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx contains an incorrect
965 // patching instruction that should fail.
966 TEST_F(ComponentUpdaterTest, DifferentialUpdateFailErrorcode) {
967 base::MessageLoop message_loop;
968 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
969 content::TestBrowserThread file_thread(BrowserThread::FILE);
970 content::TestBrowserThread io_thread(BrowserThread::IO);
971
972 io_thread.StartIOThread();
973 file_thread.Start();
974
975 content::URLLocalHostRequestPrepackagedInterceptor interceptor;
976
977 VersionedTestInstaller installer;
978 CrxComponent com;
979 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer);
980
981 const GURL expected_update_url_0(
982 "http://localhost/upd?extra=foo"
983 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc");
984 const GURL expected_update_url_1(
985 "http://localhost/upd?extra=foo"
986 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D1%26uc");
987 const GURL expected_update_url_2(
988 "http://localhost/upd?extra=foo"
989 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D2.0%26fp%3Df22%26uc");
990 const GURL expected_crx_url_1(
991 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx");
992 const GURL expected_crx_url_1_diff_2(
993 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx");
994 const GURL expected_crx_url_2(
995 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx");
996
997 interceptor.SetResponse(expected_update_url_0,
998 test_file("updatecheck_diff_reply_1.xml"));
999 interceptor.SetResponse(expected_update_url_1,
1000 test_file("updatecheck_diff_reply_2.xml"));
1001 interceptor.SetResponse(expected_update_url_2,
1002 test_file("updatecheck_diff_reply_3.xml"));
1003 interceptor.SetResponse(expected_crx_url_1,
1004 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"));
1005 interceptor.SetResponse(
1006 expected_crx_url_1_diff_2,
1007 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx"));
1008 interceptor.SetResponse(expected_crx_url_2,
1009 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"));
1010
1011 test_configurator()->SetLoopCount(3);
1012
1013 component_updater()->Start();
1014 message_loop.Run();
1015
1016 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
1017 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count());
1018
1019 EXPECT_EQ(6, interceptor.GetHitCount());
1020
1021 component_updater()->Stop();
1022 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698