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

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

Issue 481433005: Extensions: Move id_util functions to crx_file component. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revert last patchset. function returns Extension* and can't use an assert. Created 6 years, 4 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 21 matching lines...) Expand all
32 #include "chrome/browser/extensions/test_extension_system.h" 32 #include "chrome/browser/extensions/test_extension_system.h"
33 #include "chrome/browser/extensions/updater/extension_downloader.h" 33 #include "chrome/browser/extensions/updater/extension_downloader.h"
34 #include "chrome/browser/extensions/updater/extension_downloader_delegate.h" 34 #include "chrome/browser/extensions/updater/extension_downloader_delegate.h"
35 #include "chrome/browser/extensions/updater/extension_updater.h" 35 #include "chrome/browser/extensions/updater/extension_updater.h"
36 #include "chrome/browser/extensions/updater/manifest_fetch_data.h" 36 #include "chrome/browser/extensions/updater/manifest_fetch_data.h"
37 #include "chrome/browser/extensions/updater/request_queue_impl.h" 37 #include "chrome/browser/extensions/updater/request_queue_impl.h"
38 #include "chrome/browser/google/google_brand.h" 38 #include "chrome/browser/google/google_brand.h"
39 #include "chrome/browser/prefs/pref_service_syncable.h" 39 #include "chrome/browser/prefs/pref_service_syncable.h"
40 #include "chrome/common/pref_names.h" 40 #include "chrome/common/pref_names.h"
41 #include "chrome/test/base/testing_profile.h" 41 #include "chrome/test/base/testing_profile.h"
42 #include "components/crx_file/id_util.h"
42 #include "components/omaha_query_params/omaha_query_params.h" 43 #include "components/omaha_query_params/omaha_query_params.h"
43 #include "content/public/browser/notification_details.h" 44 #include "content/public/browser/notification_details.h"
44 #include "content/public/browser/notification_observer.h" 45 #include "content/public/browser/notification_observer.h"
45 #include "content/public/browser/notification_registrar.h" 46 #include "content/public/browser/notification_registrar.h"
46 #include "content/public/browser/notification_service.h" 47 #include "content/public/browser/notification_service.h"
47 #include "content/public/browser/notification_source.h" 48 #include "content/public/browser/notification_source.h"
48 #include "content/public/test/test_browser_thread_bundle.h" 49 #include "content/public/test/test_browser_thread_bundle.h"
49 #include "content/public/test/test_utils.h" 50 #include "content/public/test/test_utils.h"
50 #include "extensions/browser/extension_prefs.h" 51 #include "extensions/browser/extension_prefs.h"
51 #include "extensions/browser/extension_registry.h" 52 #include "extensions/browser/extension_registry.h"
52 #include "extensions/browser/extension_system.h" 53 #include "extensions/browser/extension_system.h"
53 #include "extensions/common/extension.h" 54 #include "extensions/common/extension.h"
54 #include "extensions/common/id_util.h"
55 #include "extensions/common/manifest_constants.h" 55 #include "extensions/common/manifest_constants.h"
56 #include "google_apis/gaia/fake_identity_provider.h" 56 #include "google_apis/gaia/fake_identity_provider.h"
57 #include "google_apis/gaia/fake_oauth2_token_service.h" 57 #include "google_apis/gaia/fake_oauth2_token_service.h"
58 #include "libxml/globals.h" 58 #include "libxml/globals.h"
59 #include "net/base/backoff_entry.h" 59 #include "net/base/backoff_entry.h"
60 #include "net/base/escape.h" 60 #include "net/base/escape.h"
61 #include "net/base/load_flags.h" 61 #include "net/base/load_flags.h"
62 #include "net/http/http_request_headers.h" 62 #include "net/http/http_request_headers.h"
63 #include "net/url_request/test_url_fetcher_factory.h" 63 #include "net/url_request/test_url_fetcher_factory.h"
64 #include "net/url_request/url_request_status.h" 64 #include "net/url_request/url_request_status.h"
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 int count, 403 int count,
404 const GURL& update_url, 404 const GURL& update_url,
405 PendingExtensionManager* pending_extension_manager) { 405 PendingExtensionManager* pending_extension_manager) {
406 for (int i = 1; i <= count; ++i) { 406 for (int i = 1; i <= count; ++i) {
407 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install = 407 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install =
408 (i % 2 == 0) ? &ShouldInstallThemesOnly : &ShouldInstallExtensionsOnly; 408 (i % 2 == 0) ? &ShouldInstallThemesOnly : &ShouldInstallExtensionsOnly;
409 const bool kIsFromSync = true; 409 const bool kIsFromSync = true;
410 const bool kInstallSilently = true; 410 const bool kInstallSilently = true;
411 const bool kMarkAcknowledged = false; 411 const bool kMarkAcknowledged = false;
412 const bool kRemoteInstall = false; 412 const bool kRemoteInstall = false;
413 std::string id = id_util::GenerateId(base::StringPrintf("extension%i", i)); 413 std::string id =
414 crx_file::id_util::GenerateId(base::StringPrintf("extension%i", i));
414 415
415 pending_extension_manager->AddForTesting( 416 pending_extension_manager->AddForTesting(
416 PendingExtensionInfo(id, 417 PendingExtensionInfo(id,
417 std::string(), 418 std::string(),
418 update_url, 419 update_url,
419 Version(), 420 Version(),
420 should_allow_install, 421 should_allow_install,
421 kIsFromSync, 422 kIsFromSync,
422 kInstallSilently, 423 kInstallSilently,
423 Manifest::INTERNAL, 424 Manifest::INTERNAL,
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 // Check passing an empty list of parse results to DetermineUpdates 796 // Check passing an empty list of parse results to DetermineUpdates
796 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); 797 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0);
797 UpdateManifest::Results updates; 798 UpdateManifest::Results updates;
798 std::vector<int> updateable; 799 std::vector<int> updateable;
799 downloader.DetermineUpdates(fetch_data, updates, &updateable); 800 downloader.DetermineUpdates(fetch_data, updates, &updateable);
800 EXPECT_TRUE(updateable.empty()); 801 EXPECT_TRUE(updateable.empty());
801 802
802 // Create two updates - expect that DetermineUpdates will return the first 803 // Create two updates - expect that DetermineUpdates will return the first
803 // one (v1.0 installed, v1.1 available) but not the second one (both 804 // one (v1.0 installed, v1.1 available) but not the second one (both
804 // installed and available at v2.0). 805 // installed and available at v2.0).
805 const std::string id1 = id_util::GenerateId("1"); 806 const std::string id1 = crx_file::id_util::GenerateId("1");
806 const std::string id2 = id_util::GenerateId("2"); 807 const std::string id2 = crx_file::id_util::GenerateId("2");
807 fetch_data.AddExtension( 808 fetch_data.AddExtension(
808 id1, "1.0.0.0", &kNeverPingedData, kEmptyUpdateUrlData, std::string()); 809 id1, "1.0.0.0", &kNeverPingedData, kEmptyUpdateUrlData, std::string());
809 AddParseResult(id1, "1.1", "http://localhost/e1_1.1.crx", &updates); 810 AddParseResult(id1, "1.1", "http://localhost/e1_1.1.crx", &updates);
810 fetch_data.AddExtension( 811 fetch_data.AddExtension(
811 id2, "2.0.0.0", &kNeverPingedData, kEmptyUpdateUrlData, std::string()); 812 id2, "2.0.0.0", &kNeverPingedData, kEmptyUpdateUrlData, std::string());
812 AddParseResult(id2, "2.0.0.0", "http://localhost/e2_2.0.crx", &updates); 813 AddParseResult(id2, "2.0.0.0", "http://localhost/e2_2.0.crx", &updates);
813 814
814 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(false)); 815 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(false));
815 EXPECT_CALL(delegate, GetExtensionExistingVersion(id1, _)) 816 EXPECT_CALL(delegate, GetExtensionExistingVersion(id1, _))
816 .WillOnce(DoAll(SetArgPointee<1>("1.0.0.0"), 817 .WillOnce(DoAll(SetArgPointee<1>("1.0.0.0"),
(...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1947 TEST_F(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) { 1948 TEST_F(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) {
1948 net::TestURLFetcherFactory factory; 1949 net::TestURLFetcherFactory factory;
1949 MockService service(prefs_.get()); 1950 MockService service(prefs_.get());
1950 MockExtensionDownloaderDelegate delegate; 1951 MockExtensionDownloaderDelegate delegate;
1951 scoped_ptr<ExtensionDownloader> downloader( 1952 scoped_ptr<ExtensionDownloader> downloader(
1952 new ExtensionDownloader(&delegate, service.request_context())); 1953 new ExtensionDownloader(&delegate, service.request_context()));
1953 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); 1954 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get()));
1954 1955
1955 // First, verify that adding valid extensions does invoke the callbacks on 1956 // First, verify that adding valid extensions does invoke the callbacks on
1956 // the delegate. 1957 // the delegate.
1957 std::string id = id_util::GenerateId("foo"); 1958 std::string id = crx_file::id_util::GenerateId("foo");
1958 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false)); 1959 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false));
1959 EXPECT_TRUE( 1960 EXPECT_TRUE(
1960 downloader->AddPendingExtension(id, GURL("http://example.com/update"), 1961 downloader->AddPendingExtension(id, GURL("http://example.com/update"),
1961 0)); 1962 0));
1962 downloader->StartAllPending(NULL); 1963 downloader->StartAllPending(NULL);
1963 Mock::VerifyAndClearExpectations(&delegate); 1964 Mock::VerifyAndClearExpectations(&delegate);
1964 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); 1965 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get()));
1965 1966
1966 // Extensions with invalid update URLs should be rejected. 1967 // Extensions with invalid update URLs should be rejected.
1967 id = id_util::GenerateId("foo2"); 1968 id = crx_file::id_util::GenerateId("foo2");
1968 EXPECT_FALSE( 1969 EXPECT_FALSE(
1969 downloader->AddPendingExtension(id, GURL("http:google.com:foo"), 0)); 1970 downloader->AddPendingExtension(id, GURL("http:google.com:foo"), 0));
1970 downloader->StartAllPending(NULL); 1971 downloader->StartAllPending(NULL);
1971 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); 1972 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get()));
1972 1973
1973 // Extensions with empty IDs should be rejected. 1974 // Extensions with empty IDs should be rejected.
1974 EXPECT_FALSE(downloader->AddPendingExtension(std::string(), GURL(), 0)); 1975 EXPECT_FALSE(downloader->AddPendingExtension(std::string(), GURL(), 0));
1975 downloader->StartAllPending(NULL); 1976 downloader->StartAllPending(NULL);
1976 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); 1977 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get()));
1977 1978
1978 // TODO(akalin): Test that extensions with empty update URLs 1979 // TODO(akalin): Test that extensions with empty update URLs
1979 // converted from user scripts are rejected. 1980 // converted from user scripts are rejected.
1980 1981
1981 // Reset the ExtensionDownloader so that it drops the current fetcher. 1982 // Reset the ExtensionDownloader so that it drops the current fetcher.
1982 downloader.reset( 1983 downloader.reset(
1983 new ExtensionDownloader(&delegate, service.request_context())); 1984 new ExtensionDownloader(&delegate, service.request_context()));
1984 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); 1985 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get()));
1985 1986
1986 // Extensions with empty update URLs should have a default one 1987 // Extensions with empty update URLs should have a default one
1987 // filled in. 1988 // filled in.
1988 id = id_util::GenerateId("foo3"); 1989 id = crx_file::id_util::GenerateId("foo3");
1989 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false)); 1990 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false));
1990 EXPECT_TRUE(downloader->AddPendingExtension(id, GURL(), 0)); 1991 EXPECT_TRUE(downloader->AddPendingExtension(id, GURL(), 0));
1991 downloader->StartAllPending(NULL); 1992 downloader->StartAllPending(NULL);
1992 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); 1993 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get()));
1993 1994
1994 net::TestURLFetcher* fetcher = 1995 net::TestURLFetcher* fetcher =
1995 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); 1996 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId);
1996 ASSERT_TRUE(fetcher); 1997 ASSERT_TRUE(fetcher);
1997 EXPECT_FALSE(fetcher->GetOriginalURL().is_empty()); 1998 EXPECT_FALSE(fetcher->GetOriginalURL().is_empty());
1998 } 1999 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2041 // -prodversionmin (shouldn't update if browser version too old) 2042 // -prodversionmin (shouldn't update if browser version too old)
2042 // -manifests & updates arriving out of order / interleaved 2043 // -manifests & updates arriving out of order / interleaved
2043 // -malformed update url (empty, file://, has query, has a # fragment, etc.) 2044 // -malformed update url (empty, file://, has query, has a # fragment, etc.)
2044 // -An extension gets uninstalled while updates are in progress (so it doesn't 2045 // -An extension gets uninstalled while updates are in progress (so it doesn't
2045 // "come back from the dead") 2046 // "come back from the dead")
2046 // -An extension gets manually updated to v3 while we're downloading v2 (ie 2047 // -An extension gets manually updated to v3 while we're downloading v2 (ie
2047 // you don't get downgraded accidentally) 2048 // you don't get downgraded accidentally)
2048 // -An update manifest mentions multiple updates 2049 // -An update manifest mentions multiple updates
2049 2050
2050 } // namespace extensions 2051 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/unpacked_installer.cc ('k') | chrome/browser/extensions/updater/local_extension_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698