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

Side by Side Diff: chrome/browser/extensions/updater/extension_updater_unittest.cc

Issue 9718028: Allow autoupdate to update disabled extensions. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Review fixes and added tests. Created 8 years, 9 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
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 <map> 5 #include <map>
6 #include <set> 6 #include <set>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 } 253 }
254 254
255 class ServiceForManifestTests : public MockService { 255 class ServiceForManifestTests : public MockService {
256 public: 256 public:
257 ServiceForManifestTests() {} 257 ServiceForManifestTests() {}
258 258
259 virtual ~ServiceForManifestTests() {} 259 virtual ~ServiceForManifestTests() {}
260 260
261 virtual const Extension* GetExtensionById( 261 virtual const Extension* GetExtensionById(
262 const std::string& id, bool include_disabled) const OVERRIDE { 262 const std::string& id, bool include_disabled) const OVERRIDE {
263 return extensions_.GetByID(id); 263 const Extension* result = extensions_.GetByID(id);
264 if (result || !include_disabled)
265 return result;
266 return disabled_extensions_.GetByID(id);
264 } 267 }
265 268
266 virtual const ExtensionSet* extensions() const OVERRIDE { 269 virtual const ExtensionSet* extensions() const OVERRIDE {
267 return &extensions_; 270 return &extensions_;
268 } 271 }
269 272
273 virtual const ExtensionSet* disabled_extensions() const OVERRIDE {
274 return &disabled_extensions_;
275 }
276
270 virtual PendingExtensionManager* pending_extension_manager() OVERRIDE { 277 virtual PendingExtensionManager* pending_extension_manager() OVERRIDE {
271 return &pending_extension_manager_; 278 return &pending_extension_manager_;
272 } 279 }
273 280
274 void set_extensions(ExtensionList extensions) { 281 void set_extensions(ExtensionList extensions) {
275 for (ExtensionList::const_iterator it = extensions.begin(); 282 for (ExtensionList::const_iterator it = extensions.begin();
276 it != extensions.end(); ++it) { 283 it != extensions.end(); ++it) {
277 extensions_.Insert(*it); 284 extensions_.Insert(*it);
278 } 285 }
279 } 286 }
280 287
288 void set_disabled_extensions(ExtensionList disabled_extensions) {
289 for (ExtensionList::const_iterator it = disabled_extensions.begin();
290 it != disabled_extensions.end(); ++it) {
291 disabled_extensions_.Insert(*it);
292 }
293 }
294
281 private: 295 private:
282 ExtensionSet extensions_; 296 ExtensionSet extensions_;
297 ExtensionSet disabled_extensions_;
283 }; 298 };
284 299
285 class ServiceForDownloadTests : public MockService { 300 class ServiceForDownloadTests : public MockService {
286 public: 301 public:
287 ServiceForDownloadTests() 302 ServiceForDownloadTests()
288 : MockService() { 303 : MockService() {
289 } 304 }
290 305
291 // Add a fake crx installer to be returned by a call to UpdateExtension() 306 // Add a fake crx installer to be returned by a call to UpdateExtension()
292 // with a specific ID. Caller keeps ownership of |crx_installer|. 307 // with a specific ID. Caller keeps ownership of |crx_installer|.
(...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after
1333 // |delegate|. 1348 // |delegate|.
1334 ExtensionDownloader* downloader = 1349 ExtensionDownloader* downloader =
1335 new ExtensionDownloader(&delegate, service.request_context()); 1350 new ExtensionDownloader(&delegate, service.request_context());
1336 ResetDownloader(&updater, downloader); 1351 ResetDownloader(&updater, downloader);
1337 1352
1338 // Non-internal non-external extensions should be rejected. 1353 // Non-internal non-external extensions should be rejected.
1339 ExtensionList extensions; 1354 ExtensionList extensions;
1340 service.CreateTestExtensions(1, 1, &extensions, NULL, Extension::INVALID); 1355 service.CreateTestExtensions(1, 1, &extensions, NULL, Extension::INVALID);
1341 service.CreateTestExtensions(2, 1, &extensions, NULL, Extension::INTERNAL); 1356 service.CreateTestExtensions(2, 1, &extensions, NULL, Extension::INTERNAL);
1342 ASSERT_EQ(2u, extensions.size()); 1357 ASSERT_EQ(2u, extensions.size());
1343 const std::string& id = extensions[1]->id(); 1358 const std::string& updateable_id = extensions[1]->id();
1344 1359
1345 // These expectations fail if the delegate's methods are invoked for the 1360 // These expectations fail if the delegate's methods are invoked for the
1346 // first extension, which has a non-matching id. 1361 // first extension, which has a non-matching id.
1347 EXPECT_CALL(delegate, GetUpdateUrlData(id)).WillOnce(Return("")); 1362 EXPECT_CALL(delegate, GetUpdateUrlData(updateable_id)).WillOnce(Return(""));
1348 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)); 1363 EXPECT_CALL(delegate, GetPingDataForExtension(updateable_id, _));
1349 1364
1350 service.set_extensions(extensions); 1365 service.set_extensions(extensions);
1351 updater.set_blacklist_checks_enabled(false); 1366 updater.set_blacklist_checks_enabled(false);
1352 updater.Start(); 1367 updater.Start();
1353 updater.CheckNow(); 1368 updater.CheckNow();
1354 } 1369 }
1355 1370
1371 TEST_F(ExtensionUpdaterTest, TestUpdatingDisabledExtensions) {
1372 TestURLFetcherFactory factory;
1373 ServiceForManifestTests service;
1374 ExtensionUpdater updater(&service, service.extension_prefs(),
1375 service.pref_service(), service.profile(),
1376 kUpdateFrequencySecs);
1377 MockExtensionDownloaderDelegate delegate;
1378 // Set the downloader directly, so that all its events end up in the mock
1379 // |delegate|.
1380 ExtensionDownloader* downloader =
1381 new ExtensionDownloader(&delegate, service.request_context());
1382 ResetDownloader(&updater, downloader);
1383
1384 // Non-internal non-external extensions should be rejected.
1385 ExtensionList disabled_extensions;
1386 service.CreateTestExtensions(1, 1, &disabled_extensions, NULL,
1387 Extension::INVALID);
1388 service.CreateTestExtensions(2, 1, &disabled_extensions, NULL,
1389 Extension::INTERNAL);
1390 ASSERT_EQ(2u, disabled_extensions.size());
1391 const std::string& updateable_id = disabled_extensions[1]->id();
asargent_no_longer_on_chrome 2012/03/21 18:47:31 I think the test would be better if you removed th
Matt Tytel 2012/03/26 05:23:59 Done.
1392
1393 // These expectations fail if the delegate's methods are invoked for the
1394 // first extension, which has a non-matching id.
1395 EXPECT_CALL(delegate, GetUpdateUrlData(updateable_id)).WillOnce(Return(""));
1396 EXPECT_CALL(delegate, GetPingDataForExtension(updateable_id, _));
1397
1398 service.set_disabled_extensions(disabled_extensions);
1399 updater.set_blacklist_checks_enabled(false);
1400 updater.Start();
1401 updater.CheckNow();
1402 }
1403
1356 TEST_F(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) { 1404 TEST_F(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) {
1357 TestURLFetcherFactory factory; 1405 TestURLFetcherFactory factory;
1358 MockService service; 1406 MockService service;
1359 MockExtensionDownloaderDelegate delegate; 1407 MockExtensionDownloaderDelegate delegate;
1360 scoped_ptr<ExtensionDownloader> downloader( 1408 scoped_ptr<ExtensionDownloader> downloader(
1361 new ExtensionDownloader(&delegate, service.request_context())); 1409 new ExtensionDownloader(&delegate, service.request_context()));
1362 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); 1410 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get()));
1363 1411
1364 // First, verify that adding valid extensions does invoke the callbacks on 1412 // First, verify that adding valid extensions does invoke the callbacks on
1365 // the delegate. 1413 // the delegate.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 // -prodversionmin (shouldn't update if browser version too old) 1493 // -prodversionmin (shouldn't update if browser version too old)
1446 // -manifests & updates arriving out of order / interleaved 1494 // -manifests & updates arriving out of order / interleaved
1447 // -malformed update url (empty, file://, has query, has a # fragment, etc.) 1495 // -malformed update url (empty, file://, has query, has a # fragment, etc.)
1448 // -An extension gets uninstalled while updates are in progress (so it doesn't 1496 // -An extension gets uninstalled while updates are in progress (so it doesn't
1449 // "come back from the dead") 1497 // "come back from the dead")
1450 // -An extension gets manually updated to v3 while we're downloading v2 (ie 1498 // -An extension gets manually updated to v3 while we're downloading v2 (ie
1451 // you don't get downgraded accidentally) 1499 // you don't get downgraded accidentally)
1452 // -An update manifest mentions multiple updates 1500 // -An update manifest mentions multiple updates
1453 1501
1454 } // namespace extensions 1502 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698