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

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

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

Powered by Google App Engine
This is Rietveld 408576698