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

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: Synced Created 8 years, 8 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
« no previous file with comments | « chrome/browser/extensions/updater/extension_updater.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 } 254 }
255 255
256 class ServiceForManifestTests : public MockService { 256 class ServiceForManifestTests : public MockService {
257 public: 257 public:
258 ServiceForManifestTests() {} 258 ServiceForManifestTests() {}
259 259
260 virtual ~ServiceForManifestTests() {} 260 virtual ~ServiceForManifestTests() {}
261 261
262 virtual const Extension* GetExtensionById( 262 virtual const Extension* GetExtensionById(
263 const std::string& id, bool include_disabled) const OVERRIDE { 263 const std::string& id, bool include_disabled) const OVERRIDE {
264 return extensions_.GetByID(id); 264 const Extension* result = extensions_.GetByID(id);
265 if (result || !include_disabled)
266 return result;
267 return disabled_extensions_.GetByID(id);
265 } 268 }
266 269
267 virtual const ExtensionSet* extensions() const OVERRIDE { 270 virtual const ExtensionSet* extensions() const OVERRIDE {
268 return &extensions_; 271 return &extensions_;
269 } 272 }
270 273
274 virtual const ExtensionSet* disabled_extensions() const OVERRIDE {
275 return &disabled_extensions_;
276 }
277
271 virtual PendingExtensionManager* pending_extension_manager() OVERRIDE { 278 virtual PendingExtensionManager* pending_extension_manager() OVERRIDE {
272 return &pending_extension_manager_; 279 return &pending_extension_manager_;
273 } 280 }
274 281
275 void set_extensions(ExtensionList extensions) { 282 void set_extensions(ExtensionList extensions) {
276 for (ExtensionList::const_iterator it = extensions.begin(); 283 for (ExtensionList::const_iterator it = extensions.begin();
277 it != extensions.end(); ++it) { 284 it != extensions.end(); ++it) {
278 extensions_.Insert(*it); 285 extensions_.Insert(*it);
279 } 286 }
280 } 287 }
281 288
289 void set_disabled_extensions(ExtensionList disabled_extensions) {
290 for (ExtensionList::const_iterator it = disabled_extensions.begin();
291 it != disabled_extensions.end(); ++it) {
292 disabled_extensions_.Insert(*it);
293 }
294 }
295
282 private: 296 private:
283 ExtensionSet extensions_; 297 ExtensionSet extensions_;
298 ExtensionSet disabled_extensions_;
284 }; 299 };
285 300
286 class ServiceForDownloadTests : public MockService { 301 class ServiceForDownloadTests : public MockService {
287 public: 302 public:
288 ServiceForDownloadTests() 303 ServiceForDownloadTests()
289 : MockService() { 304 : MockService() {
290 } 305 }
291 306
292 // Add a fake crx installer to be returned by a call to UpdateExtension() 307 // Add a fake crx installer to be returned by a call to UpdateExtension()
293 // with a specific ID. Caller keeps ownership of |crx_installer|. 308 // with a specific ID. Caller keeps ownership of |crx_installer|.
(...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after
1334 // |delegate|. 1349 // |delegate|.
1335 ExtensionDownloader* downloader = 1350 ExtensionDownloader* downloader =
1336 new ExtensionDownloader(&delegate, service.request_context()); 1351 new ExtensionDownloader(&delegate, service.request_context());
1337 ResetDownloader(&updater, downloader); 1352 ResetDownloader(&updater, downloader);
1338 1353
1339 // Non-internal non-external extensions should be rejected. 1354 // Non-internal non-external extensions should be rejected.
1340 ExtensionList extensions; 1355 ExtensionList extensions;
1341 service.CreateTestExtensions(1, 1, &extensions, NULL, Extension::INVALID); 1356 service.CreateTestExtensions(1, 1, &extensions, NULL, Extension::INVALID);
1342 service.CreateTestExtensions(2, 1, &extensions, NULL, Extension::INTERNAL); 1357 service.CreateTestExtensions(2, 1, &extensions, NULL, Extension::INTERNAL);
1343 ASSERT_EQ(2u, extensions.size()); 1358 ASSERT_EQ(2u, extensions.size());
1344 const std::string& id = extensions[1]->id(); 1359 const std::string& updateable_id = extensions[1]->id();
1345 1360
1346 // These expectations fail if the delegate's methods are invoked for the 1361 // These expectations fail if the delegate's methods are invoked for the
1347 // first extension, which has a non-matching id. 1362 // first extension, which has a non-matching id.
1348 EXPECT_CALL(delegate, GetUpdateUrlData(id)).WillOnce(Return("")); 1363 EXPECT_CALL(delegate, GetUpdateUrlData(updateable_id)).WillOnce(Return(""));
1349 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)); 1364 EXPECT_CALL(delegate, GetPingDataForExtension(updateable_id, _));
1350 1365
1351 service.set_extensions(extensions); 1366 service.set_extensions(extensions);
1352 updater.set_blacklist_checks_enabled(false); 1367 updater.set_blacklist_checks_enabled(false);
1353 updater.Start(); 1368 updater.Start();
1354 updater.CheckNow(); 1369 updater.CheckNow();
1355 } 1370 }
1356 1371
1372 TEST_F(ExtensionUpdaterTest, TestUpdatingDisabledExtensions) {
1373 TestURLFetcherFactory factory;
1374 ServiceForManifestTests service;
1375 ExtensionUpdater updater(&service, service.extension_prefs(),
1376 service.pref_service(), service.profile(),
1377 kUpdateFrequencySecs);
1378 MockExtensionDownloaderDelegate delegate;
1379 // Set the downloader directly, so that all its events end up in the mock
1380 // |delegate|.
1381 ExtensionDownloader* downloader =
1382 new ExtensionDownloader(&delegate, service.request_context());
1383 ResetDownloader(&updater, downloader);
1384
1385 // Non-internal non-external extensions should be rejected.
1386 ExtensionList enabled_extensions;
1387 ExtensionList disabled_extensions;
1388 service.CreateTestExtensions(1, 1, &enabled_extensions, NULL,
1389 Extension::INTERNAL);
1390 service.CreateTestExtensions(2, 1, &disabled_extensions, NULL,
1391 Extension::INTERNAL);
1392 ASSERT_EQ(1u, enabled_extensions.size());
1393 ASSERT_EQ(1u, disabled_extensions.size());
1394 const std::string& enabled_id = enabled_extensions[0]->id();
1395 const std::string& disabled_id = disabled_extensions[0]->id();
1396
1397 // We expect that both enabled and disabled extensions are auto-updated.
1398 EXPECT_CALL(delegate, GetUpdateUrlData(enabled_id)).WillOnce(Return(""));
1399 EXPECT_CALL(delegate, GetPingDataForExtension(enabled_id, _));
1400 EXPECT_CALL(delegate, GetUpdateUrlData(disabled_id)).WillOnce(Return(""));
1401 EXPECT_CALL(delegate, GetPingDataForExtension(disabled_id, _));
1402
1403 service.set_extensions(enabled_extensions);
1404 service.set_disabled_extensions(disabled_extensions);
1405 updater.set_blacklist_checks_enabled(false);
1406 updater.Start();
1407 updater.CheckNow();
1408 }
1409
1357 TEST_F(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) { 1410 TEST_F(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) {
1358 TestURLFetcherFactory factory; 1411 TestURLFetcherFactory factory;
1359 MockService service; 1412 MockService service;
1360 MockExtensionDownloaderDelegate delegate; 1413 MockExtensionDownloaderDelegate delegate;
1361 scoped_ptr<ExtensionDownloader> downloader( 1414 scoped_ptr<ExtensionDownloader> downloader(
1362 new ExtensionDownloader(&delegate, service.request_context())); 1415 new ExtensionDownloader(&delegate, service.request_context()));
1363 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); 1416 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get()));
1364 1417
1365 // First, verify that adding valid extensions does invoke the callbacks on 1418 // First, verify that adding valid extensions does invoke the callbacks on
1366 // the delegate. 1419 // the delegate.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 // -prodversionmin (shouldn't update if browser version too old) 1499 // -prodversionmin (shouldn't update if browser version too old)
1447 // -manifests & updates arriving out of order / interleaved 1500 // -manifests & updates arriving out of order / interleaved
1448 // -malformed update url (empty, file://, has query, has a # fragment, etc.) 1501 // -malformed update url (empty, file://, has query, has a # fragment, etc.)
1449 // -An extension gets uninstalled while updates are in progress (so it doesn't 1502 // -An extension gets uninstalled while updates are in progress (so it doesn't
1450 // "come back from the dead") 1503 // "come back from the dead")
1451 // -An extension gets manually updated to v3 while we're downloading v2 (ie 1504 // -An extension gets manually updated to v3 while we're downloading v2 (ie
1452 // you don't get downgraded accidentally) 1505 // you don't get downgraded accidentally)
1453 // -An update manifest mentions multiple updates 1506 // -An update manifest mentions multiple updates
1454 1507
1455 } // namespace extensions 1508 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/updater/extension_updater.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698