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

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

Issue 12093036: Move Extension Location and Type enums to Manifest, and move InstallWarning to its own file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <list> 5 #include <list>
6 #include <map> 6 #include <map>
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 228
229 Blacklist* blacklist() { return &blacklist_; } 229 Blacklist* blacklist() { return &blacklist_; }
230 230
231 // Creates test extensions and inserts them into list. The name and 231 // Creates test extensions and inserts them into list. The name and
232 // version are all based on their index. If |update_url| is non-null, it 232 // version are all based on their index. If |update_url| is non-null, it
233 // will be used as the update_url for each extension. 233 // will be used as the update_url for each extension.
234 // The |id| is used to distinguish extension names and make sure that 234 // The |id| is used to distinguish extension names and make sure that
235 // no two extensions share the same name. 235 // no two extensions share the same name.
236 void CreateTestExtensions(int id, int count, ExtensionList *list, 236 void CreateTestExtensions(int id, int count, ExtensionList *list,
237 const std::string* update_url, 237 const std::string* update_url,
238 Extension::Location location) { 238 Manifest::Location location) {
239 for (int i = 1; i <= count; i++) { 239 for (int i = 1; i <= count; i++) {
240 DictionaryValue manifest; 240 DictionaryValue manifest;
241 manifest.SetString(extension_manifest_keys::kVersion, 241 manifest.SetString(extension_manifest_keys::kVersion,
242 base::StringPrintf("%d.0.0.0", i)); 242 base::StringPrintf("%d.0.0.0", i));
243 manifest.SetString(extension_manifest_keys::kName, 243 manifest.SetString(extension_manifest_keys::kName,
244 base::StringPrintf("Extension %d.%d", id, i)); 244 base::StringPrintf("Extension %d.%d", id, i));
245 if (update_url) 245 if (update_url)
246 manifest.SetString(extension_manifest_keys::kUpdateURL, *update_url); 246 manifest.SetString(extension_manifest_keys::kUpdateURL, *update_url);
247 scoped_refptr<Extension> e = 247 scoped_refptr<Extension> e =
248 prefs_->AddExtensionWithManifest(manifest, location); 248 prefs_->AddExtensionWithManifest(manifest, location);
(...skipping 13 matching lines...) Expand all
262 }; 262 };
263 263
264 264
265 std::string GenerateId(std::string input) { 265 std::string GenerateId(std::string input) {
266 std::string result; 266 std::string result;
267 EXPECT_TRUE(Extension::GenerateId(input, &result)); 267 EXPECT_TRUE(Extension::GenerateId(input, &result));
268 return result; 268 return result;
269 } 269 }
270 270
271 bool ShouldInstallExtensionsOnly(const Extension& extension) { 271 bool ShouldInstallExtensionsOnly(const Extension& extension) {
272 return extension.GetType() == Extension::TYPE_EXTENSION; 272 return extension.GetType() == Manifest::TYPE_EXTENSION;
273 } 273 }
274 274
275 bool ShouldInstallThemesOnly(const Extension& extension) { 275 bool ShouldInstallThemesOnly(const Extension& extension) {
276 return extension.is_theme(); 276 return extension.is_theme();
277 } 277 }
278 278
279 bool ShouldAlwaysInstall(const Extension& extension) { 279 bool ShouldAlwaysInstall(const Extension& extension) {
280 return true; 280 return true;
281 } 281 }
282 282
283 // Loads some pending extension records into a pending extension manager. 283 // Loads some pending extension records into a pending extension manager.
284 void SetupPendingExtensionManagerForTest( 284 void SetupPendingExtensionManagerForTest(
285 int count, 285 int count,
286 const GURL& update_url, 286 const GURL& update_url,
287 PendingExtensionManager* pending_extension_manager) { 287 PendingExtensionManager* pending_extension_manager) {
288 for (int i = 1; i <= count; ++i) { 288 for (int i = 1; i <= count; ++i) {
289 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install = 289 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install =
290 (i % 2 == 0) ? &ShouldInstallThemesOnly : &ShouldInstallExtensionsOnly; 290 (i % 2 == 0) ? &ShouldInstallThemesOnly : &ShouldInstallExtensionsOnly;
291 const bool kIsFromSync = true; 291 const bool kIsFromSync = true;
292 const bool kInstallSilently = true; 292 const bool kInstallSilently = true;
293 std::string id = GenerateId(base::StringPrintf("extension%i", i)); 293 std::string id = GenerateId(base::StringPrintf("extension%i", i));
294 294
295 pending_extension_manager->AddForTesting( 295 pending_extension_manager->AddForTesting(
296 PendingExtensionInfo(id, 296 PendingExtensionInfo(id,
297 update_url, 297 update_url,
298 Version(), 298 Version(),
299 should_allow_install, 299 should_allow_install,
300 kIsFromSync, 300 kIsFromSync,
301 kInstallSilently, 301 kInstallSilently,
302 Extension::INTERNAL)); 302 Manifest::INTERNAL));
303 } 303 }
304 } 304 }
305 305
306 class ServiceForManifestTests : public MockService { 306 class ServiceForManifestTests : public MockService {
307 public: 307 public:
308 explicit ServiceForManifestTests(TestExtensionPrefs* prefs) 308 explicit ServiceForManifestTests(TestExtensionPrefs* prefs)
309 : MockService(prefs) { 309 : MockService(prefs) {
310 } 310 }
311 311
312 virtual ~ServiceForManifestTests() {} 312 virtual ~ServiceForManifestTests() {}
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 std::string update_url("http://foo.com/bar"); 515 std::string update_url("http://foo.com/bar");
516 ExtensionList extensions; 516 ExtensionList extensions;
517 NotificationsObserver observer; 517 NotificationsObserver observer;
518 PendingExtensionManager* pending_extension_manager = 518 PendingExtensionManager* pending_extension_manager =
519 service.pending_extension_manager(); 519 service.pending_extension_manager();
520 if (pending) { 520 if (pending) {
521 SetupPendingExtensionManagerForTest(1, GURL(update_url), 521 SetupPendingExtensionManagerForTest(1, GURL(update_url),
522 pending_extension_manager); 522 pending_extension_manager);
523 } else { 523 } else {
524 service.CreateTestExtensions(1, 1, &extensions, &update_url, 524 service.CreateTestExtensions(1, 1, &extensions, &update_url,
525 Extension::INTERNAL); 525 Manifest::INTERNAL);
526 service.set_extensions(extensions); 526 service.set_extensions(extensions);
527 } 527 }
528 528
529 // Set up and start the updater. 529 // Set up and start the updater.
530 net::TestURLFetcherFactory factory; 530 net::TestURLFetcherFactory factory;
531 ExtensionUpdater updater( 531 ExtensionUpdater updater(
532 &service, service.extension_prefs(), service.pref_service(), 532 &service, service.extension_prefs(), service.pref_service(),
533 service.profile(), service.blacklist(), 60*60*24); 533 service.profile(), service.blacklist(), 60*60*24);
534 updater.Start(); 534 updater.Start();
535 // Disable blacklist checks (tested elsewhere) so that we only see the 535 // Disable blacklist checks (tested elsewhere) so that we only see the
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 660
661 void TestUpdateUrlDataFromGallery(const std::string& gallery_url) { 661 void TestUpdateUrlDataFromGallery(const std::string& gallery_url) {
662 net::TestURLFetcherFactory factory; 662 net::TestURLFetcherFactory factory;
663 663
664 MockService service(prefs_.get()); 664 MockService service(prefs_.get());
665 MockExtensionDownloaderDelegate delegate; 665 MockExtensionDownloaderDelegate delegate;
666 ExtensionDownloader downloader(&delegate, service.request_context()); 666 ExtensionDownloader downloader(&delegate, service.request_context());
667 ExtensionList extensions; 667 ExtensionList extensions;
668 std::string url(gallery_url); 668 std::string url(gallery_url);
669 669
670 service.CreateTestExtensions(1, 1, &extensions, &url, Extension::INTERNAL); 670 service.CreateTestExtensions(1, 1, &extensions, &url, Manifest::INTERNAL);
671 671
672 const std::string& id = extensions[0]->id(); 672 const std::string& id = extensions[0]->id();
673 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)); 673 EXPECT_CALL(delegate, GetPingDataForExtension(id, _));
674 674
675 downloader.AddExtension(*extensions[0], 0); 675 downloader.AddExtension(*extensions[0], 0);
676 downloader.StartAllPending(); 676 downloader.StartAllPending();
677 net::TestURLFetcher* fetcher = 677 net::TestURLFetcher* fetcher =
678 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); 678 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId);
679 ASSERT_TRUE(fetcher); 679 ASSERT_TRUE(fetcher);
680 // Make sure that extensions that update from the gallery ignore any 680 // Make sure that extensions that update from the gallery ignore any
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 997
998 if (pending) { 998 if (pending) {
999 const bool kIsFromSync = true; 999 const bool kIsFromSync = true;
1000 const bool kInstallSilently = true; 1000 const bool kInstallSilently = true;
1001 PendingExtensionManager* pending_extension_manager = 1001 PendingExtensionManager* pending_extension_manager =
1002 service->pending_extension_manager(); 1002 service->pending_extension_manager();
1003 pending_extension_manager->AddForTesting( 1003 pending_extension_manager->AddForTesting(
1004 PendingExtensionInfo(id, test_url, version, 1004 PendingExtensionInfo(id, test_url, version,
1005 &ShouldAlwaysInstall, kIsFromSync, 1005 &ShouldAlwaysInstall, kIsFromSync,
1006 kInstallSilently, 1006 kInstallSilently,
1007 Extension::INTERNAL)); 1007 Manifest::INTERNAL));
1008 } 1008 }
1009 1009
1010 // Call back the ExtensionUpdater with a 200 response and some test data 1010 // Call back the ExtensionUpdater with a 200 response and some test data
1011 FilePath extension_file_path(FILE_PATH_LITERAL("/whatever")); 1011 FilePath extension_file_path(FILE_PATH_LITERAL("/whatever"));
1012 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); 1012 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId);
1013 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); 1013 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
1014 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); 1014 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags);
1015 1015
1016 if (retry) { 1016 if (retry) {
1017 // Reply with response code 500 to cause ExtensionDownloader to retry 1017 // Reply with response code 500 to cause ExtensionDownloader to retry
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1281 net::TestURLFetcherFactory factory; 1281 net::TestURLFetcherFactory factory;
1282 1282
1283 // Set up 2 mock extensions, one with a google.com update url and one 1283 // Set up 2 mock extensions, one with a google.com update url and one
1284 // without. 1284 // without.
1285 prefs_.reset(new TestExtensionPrefs(loop_.message_loop_proxy())); 1285 prefs_.reset(new TestExtensionPrefs(loop_.message_loop_proxy()));
1286 ServiceForManifestTests service(prefs_.get()); 1286 ServiceForManifestTests service(prefs_.get());
1287 ExtensionList tmp; 1287 ExtensionList tmp;
1288 GURL url1("http://clients2.google.com/service/update2/crx"); 1288 GURL url1("http://clients2.google.com/service/update2/crx");
1289 GURL url2("http://www.somewebsite.com"); 1289 GURL url2("http://www.somewebsite.com");
1290 service.CreateTestExtensions(1, 1, &tmp, &url1.possibly_invalid_spec(), 1290 service.CreateTestExtensions(1, 1, &tmp, &url1.possibly_invalid_spec(),
1291 Extension::INTERNAL); 1291 Manifest::INTERNAL);
1292 service.CreateTestExtensions(2, 1, &tmp, &url2.possibly_invalid_spec(), 1292 service.CreateTestExtensions(2, 1, &tmp, &url2.possibly_invalid_spec(),
1293 Extension::INTERNAL); 1293 Manifest::INTERNAL);
1294 EXPECT_EQ(2u, tmp.size()); 1294 EXPECT_EQ(2u, tmp.size());
1295 service.set_extensions(tmp); 1295 service.set_extensions(tmp);
1296 1296
1297 ExtensionPrefs* prefs = service.extension_prefs(); 1297 ExtensionPrefs* prefs = service.extension_prefs();
1298 const std::string& id = tmp[0]->id(); 1298 const std::string& id = tmp[0]->id();
1299 Time now = Time::Now(); 1299 Time now = Time::Now();
1300 if (rollcall_ping_days == 0) { 1300 if (rollcall_ping_days == 0) {
1301 prefs->SetLastPingDay(id, now - TimeDelta::FromSeconds(15)); 1301 prefs->SetLastPingDay(id, now - TimeDelta::FromSeconds(15));
1302 } else if (rollcall_ping_days > 0) { 1302 } else if (rollcall_ping_days > 0) {
1303 Time last_ping_day = now - 1303 Time last_ping_day = now -
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1402 1402
1403 // This makes sure that the extension updater properly stores the results 1403 // This makes sure that the extension updater properly stores the results
1404 // of a <daystart> tag from a manifest fetch in one of two cases: 1) This is 1404 // of a <daystart> tag from a manifest fetch in one of two cases: 1) This is
1405 // the first time we fetched the extension, or 2) We sent a ping value of 1405 // the first time we fetched the extension, or 2) We sent a ping value of
1406 // >= 1 day for the extension. 1406 // >= 1 day for the extension.
1407 void TestHandleManifestResults() { 1407 void TestHandleManifestResults() {
1408 ServiceForManifestTests service(prefs_.get()); 1408 ServiceForManifestTests service(prefs_.get());
1409 GURL update_url("http://www.google.com/manifest"); 1409 GURL update_url("http://www.google.com/manifest");
1410 ExtensionList tmp; 1410 ExtensionList tmp;
1411 service.CreateTestExtensions(1, 1, &tmp, &update_url.spec(), 1411 service.CreateTestExtensions(1, 1, &tmp, &update_url.spec(),
1412 Extension::INTERNAL); 1412 Manifest::INTERNAL);
1413 service.set_extensions(tmp); 1413 service.set_extensions(tmp);
1414 1414
1415 ExtensionUpdater updater( 1415 ExtensionUpdater updater(
1416 &service, service.extension_prefs(), service.pref_service(), 1416 &service, service.extension_prefs(), service.pref_service(),
1417 service.profile(), service.blacklist(), kUpdateFrequencySecs); 1417 service.profile(), service.blacklist(), kUpdateFrequencySecs);
1418 updater.Start(); 1418 updater.Start();
1419 ResetDownloader( 1419 ResetDownloader(
1420 &updater, 1420 &updater,
1421 new ExtensionDownloader(&updater, service.request_context())); 1421 new ExtensionDownloader(&updater, service.request_context()));
1422 1422
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1536 service.blacklist(), kUpdateFrequencySecs); 1536 service.blacklist(), kUpdateFrequencySecs);
1537 MockExtensionDownloaderDelegate delegate; 1537 MockExtensionDownloaderDelegate delegate;
1538 // Set the downloader directly, so that all its events end up in the mock 1538 // Set the downloader directly, so that all its events end up in the mock
1539 // |delegate|. 1539 // |delegate|.
1540 ExtensionDownloader* downloader = 1540 ExtensionDownloader* downloader =
1541 new ExtensionDownloader(&delegate, service.request_context()); 1541 new ExtensionDownloader(&delegate, service.request_context());
1542 ResetDownloader(&updater, downloader); 1542 ResetDownloader(&updater, downloader);
1543 1543
1544 // Non-internal non-external extensions should be rejected. 1544 // Non-internal non-external extensions should be rejected.
1545 ExtensionList extensions; 1545 ExtensionList extensions;
1546 service.CreateTestExtensions(1, 1, &extensions, NULL, Extension::INVALID); 1546 service.CreateTestExtensions(1, 1, &extensions, NULL,
1547 service.CreateTestExtensions(2, 1, &extensions, NULL, Extension::INTERNAL); 1547 Manifest::INVALID_LOCATION);
1548 service.CreateTestExtensions(2, 1, &extensions, NULL, Manifest::INTERNAL);
1548 ASSERT_EQ(2u, extensions.size()); 1549 ASSERT_EQ(2u, extensions.size());
1549 const std::string& updateable_id = extensions[1]->id(); 1550 const std::string& updateable_id = extensions[1]->id();
1550 1551
1551 // These expectations fail if the delegate's methods are invoked for the 1552 // These expectations fail if the delegate's methods are invoked for the
1552 // first extension, which has a non-matching id. 1553 // first extension, which has a non-matching id.
1553 EXPECT_CALL(delegate, GetUpdateUrlData(updateable_id)).WillOnce(Return("")); 1554 EXPECT_CALL(delegate, GetUpdateUrlData(updateable_id)).WillOnce(Return(""));
1554 EXPECT_CALL(delegate, GetPingDataForExtension(updateable_id, _)); 1555 EXPECT_CALL(delegate, GetPingDataForExtension(updateable_id, _));
1555 1556
1556 service.set_extensions(extensions); 1557 service.set_extensions(extensions);
1557 ExtensionUpdater::CheckParams params; 1558 ExtensionUpdater::CheckParams params;
(...skipping 12 matching lines...) Expand all
1570 // Set the downloader directly, so that all its events end up in the mock 1571 // Set the downloader directly, so that all its events end up in the mock
1571 // |delegate|. 1572 // |delegate|.
1572 ExtensionDownloader* downloader = 1573 ExtensionDownloader* downloader =
1573 new ExtensionDownloader(&delegate, service.request_context()); 1574 new ExtensionDownloader(&delegate, service.request_context());
1574 ResetDownloader(&updater, downloader); 1575 ResetDownloader(&updater, downloader);
1575 1576
1576 // Non-internal non-external extensions should be rejected. 1577 // Non-internal non-external extensions should be rejected.
1577 ExtensionList enabled_extensions; 1578 ExtensionList enabled_extensions;
1578 ExtensionList disabled_extensions; 1579 ExtensionList disabled_extensions;
1579 service.CreateTestExtensions(1, 1, &enabled_extensions, NULL, 1580 service.CreateTestExtensions(1, 1, &enabled_extensions, NULL,
1580 Extension::INTERNAL); 1581 Manifest::INTERNAL);
1581 service.CreateTestExtensions(2, 1, &disabled_extensions, NULL, 1582 service.CreateTestExtensions(2, 1, &disabled_extensions, NULL,
1582 Extension::INTERNAL); 1583 Manifest::INTERNAL);
1583 ASSERT_EQ(1u, enabled_extensions.size()); 1584 ASSERT_EQ(1u, enabled_extensions.size());
1584 ASSERT_EQ(1u, disabled_extensions.size()); 1585 ASSERT_EQ(1u, disabled_extensions.size());
1585 const std::string& enabled_id = enabled_extensions[0]->id(); 1586 const std::string& enabled_id = enabled_extensions[0]->id();
1586 const std::string& disabled_id = disabled_extensions[0]->id(); 1587 const std::string& disabled_id = disabled_extensions[0]->id();
1587 1588
1588 // We expect that both enabled and disabled extensions are auto-updated. 1589 // We expect that both enabled and disabled extensions are auto-updated.
1589 EXPECT_CALL(delegate, GetUpdateUrlData(enabled_id)).WillOnce(Return("")); 1590 EXPECT_CALL(delegate, GetUpdateUrlData(enabled_id)).WillOnce(Return(""));
1590 EXPECT_CALL(delegate, GetPingDataForExtension(enabled_id, _)); 1591 EXPECT_CALL(delegate, GetPingDataForExtension(enabled_id, _));
1591 EXPECT_CALL(delegate, GetUpdateUrlData(disabled_id)).WillOnce(Return("")); 1592 EXPECT_CALL(delegate, GetUpdateUrlData(disabled_id)).WillOnce(Return(""));
1592 EXPECT_CALL(delegate, GetPingDataForExtension(disabled_id, _)); 1593 EXPECT_CALL(delegate, GetPingDataForExtension(disabled_id, _));
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1692 // -prodversionmin (shouldn't update if browser version too old) 1693 // -prodversionmin (shouldn't update if browser version too old)
1693 // -manifests & updates arriving out of order / interleaved 1694 // -manifests & updates arriving out of order / interleaved
1694 // -malformed update url (empty, file://, has query, has a # fragment, etc.) 1695 // -malformed update url (empty, file://, has query, has a # fragment, etc.)
1695 // -An extension gets uninstalled while updates are in progress (so it doesn't 1696 // -An extension gets uninstalled while updates are in progress (so it doesn't
1696 // "come back from the dead") 1697 // "come back from the dead")
1697 // -An extension gets manually updated to v3 while we're downloading v2 (ie 1698 // -An extension gets manually updated to v3 while we're downloading v2 (ie
1698 // you don't get downgraded accidentally) 1699 // you don't get downgraded accidentally)
1699 // -An update manifest mentions multiple updates 1700 // -An update manifest mentions multiple updates
1700 1701
1701 } // namespace extensions 1702 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/updater/extension_updater.cc ('k') | chrome/browser/extensions/user_script_listener_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698