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

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

Issue 11415216: Make Blacklist::IsBlacklist asynchronous (it will need to be for safe (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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"
11 #include "base/bind_helpers.h"
10 #include "base/command_line.h" 12 #include "base/command_line.h"
11 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
12 #include "base/file_util.h" 14 #include "base/file_util.h"
13 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/message_loop.h"
18 #include "base/run_loop.h"
19 #include "base/sequenced_task_runner.h"
15 #include "base/stl_util.h" 20 #include "base/stl_util.h"
16 #include "base/string_number_conversions.h" 21 #include "base/string_number_conversions.h"
17 #include "base/string_split.h" 22 #include "base/string_split.h"
18 #include "base/string_util.h" 23 #include "base/string_util.h"
19 #include "base/stringprintf.h" 24 #include "base/stringprintf.h"
20 #include "base/threading/thread.h" 25 #include "base/threading/thread.h"
21 #include "base/version.h" 26 #include "base/version.h"
22 #include "chrome/browser/extensions/blacklist.h" 27 #include "chrome/browser/extensions/blacklist.h"
23 #include "chrome/browser/extensions/crx_installer.h" 28 #include "chrome/browser/extensions/crx_installer.h"
24 #include "chrome/browser/extensions/extension_error_reporter.h" 29 #include "chrome/browser/extensions/extension_error_reporter.h"
25 #include "chrome/browser/extensions/extension_sync_data.h" 30 #include "chrome/browser/extensions/extension_sync_data.h"
26 #include "chrome/browser/extensions/extension_system.h" 31 #include "chrome/browser/extensions/extension_system.h"
32 #include "chrome/browser/extensions/test_blacklist.h"
27 #include "chrome/browser/extensions/test_extension_prefs.h" 33 #include "chrome/browser/extensions/test_extension_prefs.h"
28 #include "chrome/browser/extensions/test_extension_service.h" 34 #include "chrome/browser/extensions/test_extension_service.h"
29 #include "chrome/browser/extensions/test_extension_system.h" 35 #include "chrome/browser/extensions/test_extension_system.h"
30 #include "chrome/browser/extensions/updater/extension_downloader.h" 36 #include "chrome/browser/extensions/updater/extension_downloader.h"
31 #include "chrome/browser/extensions/updater/extension_downloader_delegate.h" 37 #include "chrome/browser/extensions/updater/extension_downloader_delegate.h"
32 #include "chrome/browser/extensions/updater/extension_updater.h" 38 #include "chrome/browser/extensions/updater/extension_updater.h"
33 #include "chrome/browser/extensions/updater/manifest_fetch_data.h" 39 #include "chrome/browser/extensions/updater/manifest_fetch_data.h"
34 #include "chrome/browser/google/google_util.h" 40 #include "chrome/browser/google/google_util.h"
35 #include "chrome/browser/prefs/pref_service.h" 41 #include "chrome/browser/prefs/pref_service.h"
36 #include "chrome/common/chrome_notification_types.h" 42 #include "chrome/common/chrome_notification_types.h"
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 FilePath tmpfile_path = service->install_path(); 915 FilePath tmpfile_path = service->install_path();
910 EXPECT_FALSE(tmpfile_path.empty()); 916 EXPECT_FALSE(tmpfile_path.empty());
911 EXPECT_EQ(test_url, service->download_url()); 917 EXPECT_EQ(test_url, service->download_url());
912 EXPECT_EQ(extension_file_path, tmpfile_path); 918 EXPECT_EQ(extension_file_path, tmpfile_path);
913 } 919 }
914 920
915 void TestBlacklistDownloading() { 921 void TestBlacklistDownloading() {
916 net::TestURLFetcherFactory factory; 922 net::TestURLFetcherFactory factory;
917 net::TestURLFetcher* fetcher = NULL; 923 net::TestURLFetcher* fetcher = NULL;
918 MockService service(prefs_.get()); 924 MockService service(prefs_.get());
925 TestBlacklist blacklist(service.blacklist());
919 ExtensionUpdater updater( 926 ExtensionUpdater updater(
920 &service, service.extension_prefs(), service.pref_service(), 927 &service, service.extension_prefs(), service.pref_service(),
921 service.profile(), service.blacklist(), kUpdateFrequencySecs); 928 service.profile(), blacklist.blacklist(), kUpdateFrequencySecs);
922 updater.Start(); 929 updater.Start();
923 ResetDownloader( 930 ResetDownloader(
924 &updater, 931 &updater,
925 new ExtensionDownloader(&updater, service.request_context())); 932 new ExtensionDownloader(&updater, service.request_context()));
926 GURL test_url("http://localhost/extension.crx"); 933 GURL test_url("http://localhost/extension.crx");
927 934
928 std::string id = "com.google.crx.blacklist"; 935 std::string id = "com.google.crx.blacklist";
929 936
930 std::string hash = 937 std::string hash =
931 "CCEA231D3CD30A348DA1383ED311EAC11E82360773CB2BA4E2C3A5FF16E337CC"; 938 "CCEA231D3CD30A348DA1383ED311EAC11E82360773CB2BA4E2C3A5FF16E337CC";
932 939
933 std::string version = "0.0.1"; 940 std::string version = "0.0.1";
934 std::set<int> requests; 941 std::set<int> requests;
935 requests.insert(0); 942 requests.insert(0);
936 updater.downloader_->FetchUpdatedExtension(id, test_url, hash, version, 943 updater.downloader_->FetchUpdatedExtension(id, test_url, hash, version,
937 requests); 944 requests);
938 945
939 // Call back the ExtensionUpdater with a 200 response and some test data. 946 // Call back the ExtensionUpdater with a 200 response and some test data.
940 std::string extension_data("aaaabbbbcccceeeeaaaabbbbcccceeee"); 947 std::string extension_data("aaaabbbbcccceeeeaaaabbbbcccceeee");
941 EXPECT_FALSE(service.blacklist()->IsBlacklisted(extension_data)); 948 EXPECT_FALSE(blacklist.IsBlacklisted(extension_data));
942 949
943 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); 950 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId);
944 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); 951 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
945 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); 952 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags);
946 953
947 fetcher->set_url(test_url); 954 fetcher->set_url(test_url);
948 fetcher->set_status(net::URLRequestStatus()); 955 fetcher->set_status(net::URLRequestStatus());
949 fetcher->set_response_code(200); 956 fetcher->set_response_code(200);
950 fetcher->SetResponseString(extension_data); 957 fetcher->SetResponseString(extension_data);
951 fetcher->delegate()->OnURLFetchComplete(fetcher); 958 fetcher->delegate()->OnURLFetchComplete(fetcher);
952 959
953 RunUntilIdle(); 960 RunUntilIdle();
954 961
955 EXPECT_TRUE(service.blacklist()->IsBlacklisted(extension_data)); 962 EXPECT_TRUE(blacklist.IsBlacklisted(extension_data));
956 963
957 EXPECT_EQ(version, service.pref_service()-> 964 EXPECT_EQ(version, service.pref_service()->
958 GetString(prefs::kExtensionBlacklistUpdateVersion)); 965 GetString(prefs::kExtensionBlacklistUpdateVersion));
959 } 966 }
960 967
961 // Two extensions are updated. If |updates_start_running| is true, the 968 // Two extensions are updated. If |updates_start_running| is true, the
962 // mock extensions service has UpdateExtension(...) return true, and 969 // mock extensions service has UpdateExtension(...) return true, and
963 // the test is responsible for creating fake CrxInstallers. Otherwise, 970 // the test is responsible for creating fake CrxInstallers. Otherwise,
964 // UpdateExtension() returns false, signaling install failures. 971 // UpdateExtension() returns false, signaling install failures.
965 void TestMultipleExtensionDownloading(bool updates_start_running) { 972 void TestMultipleExtensionDownloading(bool updates_start_running) {
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
1536 // -prodversionmin (shouldn't update if browser version too old) 1543 // -prodversionmin (shouldn't update if browser version too old)
1537 // -manifests & updates arriving out of order / interleaved 1544 // -manifests & updates arriving out of order / interleaved
1538 // -malformed update url (empty, file://, has query, has a # fragment, etc.) 1545 // -malformed update url (empty, file://, has query, has a # fragment, etc.)
1539 // -An extension gets uninstalled while updates are in progress (so it doesn't 1546 // -An extension gets uninstalled while updates are in progress (so it doesn't
1540 // "come back from the dead") 1547 // "come back from the dead")
1541 // -An extension gets manually updated to v3 while we're downloading v2 (ie 1548 // -An extension gets manually updated to v3 while we're downloading v2 (ie
1542 // you don't get downgraded accidentally) 1549 // you don't get downgraded accidentally)
1543 // -An update manifest mentions multiple updates 1550 // -An update manifest mentions multiple updates
1544 1551
1545 } // namespace extensions 1552 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698