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

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

Issue 7465041: GTTF: Use a fresh TestingBrowserProcess for each test, part #4 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update Created 9 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/string_number_conversions.h" 12 #include "base/string_number_conversions.h"
13 #include "base/string_split.h" 13 #include "base/string_split.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "base/stringprintf.h" 15 #include "base/stringprintf.h"
16 #include "base/threading/thread.h" 16 #include "base/threading/thread.h"
17 #include "base/version.h" 17 #include "base/version.h"
18 #include "chrome/browser/extensions/crx_installer.h" 18 #include "chrome/browser/extensions/crx_installer.h"
19 #include "chrome/browser/extensions/extension_error_reporter.h" 19 #include "chrome/browser/extensions/extension_error_reporter.h"
20 #include "chrome/browser/extensions/extension_sync_data.h" 20 #include "chrome/browser/extensions/extension_sync_data.h"
21 #include "chrome/browser/extensions/extension_updater.h" 21 #include "chrome/browser/extensions/extension_updater.h"
22 #include "chrome/browser/extensions/test_extension_prefs.h" 22 #include "chrome/browser/extensions/test_extension_prefs.h"
23 #include "chrome/browser/extensions/test_extension_service.h" 23 #include "chrome/browser/extensions/test_extension_service.h"
24 #include "chrome/browser/prefs/pref_service.h" 24 #include "chrome/browser/prefs/pref_service.h"
25 #include "chrome/common/extensions/extension.h" 25 #include "chrome/common/extensions/extension.h"
26 #include "chrome/common/extensions/extension_constants.h" 26 #include "chrome/common/extensions/extension_constants.h"
27 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
28 #include "chrome/test/base/testing_profile.h" 28 #include "chrome/test/base/testing_profile.h"
29 #include "chrome/test/testing_browser_process_test.h"
29 #include "content/browser/browser_thread.h" 30 #include "content/browser/browser_thread.h"
30 #include "content/test/test_url_fetcher_factory.h" 31 #include "content/test/test_url_fetcher_factory.h"
31 #include "libxml/globals.h" 32 #include "libxml/globals.h"
32 #include "net/base/escape.h" 33 #include "net/base/escape.h"
33 #include "net/base/load_flags.h" 34 #include "net/base/load_flags.h"
34 #include "net/url_request/url_request_status.h" 35 #include "net/url_request/url_request_status.h"
35 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
36 37
37 using base::Time; 38 using base::Time;
38 using base::TimeDelta; 39 using base::TimeDelta;
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 EXPECT_TRUE(result->find(key) == result->end()); 280 EXPECT_TRUE(result->find(key) == result->end());
280 (*result)[key] = (key_val.size() == 2) ? key_val[1] : ""; 281 (*result)[key] = (key_val.size() == 2) ? key_val[1] : "";
281 } else { 282 } else {
282 NOTREACHED(); 283 NOTREACHED();
283 } 284 }
284 } 285 }
285 } 286 }
286 287
287 // All of our tests that need to use private APIs of ExtensionUpdater live 288 // All of our tests that need to use private APIs of ExtensionUpdater live
288 // inside this class (which is a friend to ExtensionUpdater). 289 // inside this class (which is a friend to ExtensionUpdater).
289 class ExtensionUpdaterTest : public testing::Test { 290 class ExtensionUpdaterTest : public TestingBrowserProcessTest {
290 public: 291 public:
291 static void SimulateTimerFired(ExtensionUpdater* updater) { 292 static void SimulateTimerFired(ExtensionUpdater* updater) {
292 EXPECT_TRUE(updater->timer_.IsRunning()); 293 EXPECT_TRUE(updater->timer_.IsRunning());
293 updater->timer_.Stop(); 294 updater->timer_.Stop();
294 updater->TimerFired(); 295 updater->TimerFired();
295 } 296 }
296 297
297 static void SimulateCheckSoon(const ExtensionUpdater& updater, 298 static void SimulateCheckSoon(const ExtensionUpdater& updater,
298 MessageLoop* message_loop) { 299 MessageLoop* message_loop) {
299 EXPECT_TRUE(updater.will_check_soon_); 300 EXPECT_TRUE(updater.will_check_soon_);
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 EXPECT_FALSE(last_ping_day.is_null()); 1034 EXPECT_FALSE(last_ping_day.is_null());
1034 int64 seconds_diff = (Time::Now() - last_ping_day).InSeconds(); 1035 int64 seconds_diff = (Time::Now() - last_ping_day).InSeconds();
1035 EXPECT_LT(seconds_diff - results.daystart_elapsed_seconds, 5); 1036 EXPECT_LT(seconds_diff - results.daystart_elapsed_seconds, 5);
1036 } 1037 }
1037 }; 1038 };
1038 1039
1039 // Because we test some private methods of ExtensionUpdater, it's easer for the 1040 // Because we test some private methods of ExtensionUpdater, it's easer for the
1040 // actual test code to live in ExtenionUpdaterTest methods instead of TEST_F 1041 // actual test code to live in ExtenionUpdaterTest methods instead of TEST_F
1041 // subclasses where friendship with ExtenionUpdater is not inherited. 1042 // subclasses where friendship with ExtenionUpdater is not inherited.
1042 1043
1043 TEST(ExtensionUpdaterTest, TestExtensionUpdateCheckRequests) { 1044 TEST_F(ExtensionUpdaterTest, TestExtensionUpdateCheckRequests) {
1044 ExtensionUpdaterTest::TestExtensionUpdateCheckRequests(false); 1045 ExtensionUpdaterTest::TestExtensionUpdateCheckRequests(false);
1045 } 1046 }
1046 1047
1047 TEST(ExtensionUpdaterTest, TestExtensionUpdateCheckRequestsPending) { 1048 TEST_F(ExtensionUpdaterTest, TestExtensionUpdateCheckRequestsPending) {
1048 ExtensionUpdaterTest::TestExtensionUpdateCheckRequests(true); 1049 ExtensionUpdaterTest::TestExtensionUpdateCheckRequests(true);
1049 } 1050 }
1050 1051
1051 // This test is disabled on Mac, see http://crbug.com/26035. 1052 TEST_F(ExtensionUpdaterTest, TestBlacklistUpdateCheckRequests) {
1052 TEST(ExtensionUpdaterTest, TestBlacklistUpdateCheckRequests) {
1053 ExtensionUpdaterTest::TestBlacklistUpdateCheckRequests(); 1053 ExtensionUpdaterTest::TestBlacklistUpdateCheckRequests();
1054 } 1054 }
1055 1055
1056 TEST(ExtensionUpdaterTest, TestUpdateUrlData) { 1056 TEST_F(ExtensionUpdaterTest, TestUpdateUrlData) {
1057 MessageLoop message_loop; 1057 MessageLoop message_loop;
1058 BrowserThread file_thread(BrowserThread::FILE, &message_loop); 1058 BrowserThread file_thread(BrowserThread::FILE, &message_loop);
1059 1059
1060 ExtensionUpdaterTest::TestUpdateUrlDataEmpty(); 1060 ExtensionUpdaterTest::TestUpdateUrlDataEmpty();
1061 ExtensionUpdaterTest::TestUpdateUrlDataSimple(); 1061 ExtensionUpdaterTest::TestUpdateUrlDataSimple();
1062 ExtensionUpdaterTest::TestUpdateUrlDataCompound(); 1062 ExtensionUpdaterTest::TestUpdateUrlDataCompound();
1063 ExtensionUpdaterTest::TestUpdateUrlDataFromGallery( 1063 ExtensionUpdaterTest::TestUpdateUrlDataFromGallery(
1064 Extension::GalleryUpdateUrl(false).spec()); 1064 Extension::GalleryUpdateUrl(false).spec());
1065 ExtensionUpdaterTest::TestUpdateUrlDataFromGallery( 1065 ExtensionUpdaterTest::TestUpdateUrlDataFromGallery(
1066 Extension::GalleryUpdateUrl(true).spec()); 1066 Extension::GalleryUpdateUrl(true).spec());
1067 } 1067 }
1068 1068
1069 TEST(ExtensionUpdaterTest, TestDetermineUpdates) { 1069 TEST_F(ExtensionUpdaterTest, TestDetermineUpdates) {
1070 ExtensionUpdaterTest::TestDetermineUpdates(); 1070 ExtensionUpdaterTest::TestDetermineUpdates();
1071 } 1071 }
1072 1072
1073 TEST(ExtensionUpdaterTest, TestDetermineUpdatesPending) { 1073 TEST_F(ExtensionUpdaterTest, TestDetermineUpdatesPending) {
1074 ExtensionUpdaterTest::TestDetermineUpdatesPending(); 1074 ExtensionUpdaterTest::TestDetermineUpdatesPending();
1075 } 1075 }
1076 1076
1077 TEST(ExtensionUpdaterTest, TestMultipleManifestDownloading) { 1077 TEST_F(ExtensionUpdaterTest, TestMultipleManifestDownloading) {
1078 ExtensionUpdaterTest::TestMultipleManifestDownloading(); 1078 ExtensionUpdaterTest::TestMultipleManifestDownloading();
1079 } 1079 }
1080 1080
1081 TEST(ExtensionUpdaterTest, TestSingleExtensionDownloading) { 1081 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloading) {
1082 ExtensionUpdaterTest::TestSingleExtensionDownloading(false); 1082 ExtensionUpdaterTest::TestSingleExtensionDownloading(false);
1083 } 1083 }
1084 1084
1085 TEST(ExtensionUpdaterTest, TestSingleExtensionDownloadingPending) { 1085 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingPending) {
1086 ExtensionUpdaterTest::TestSingleExtensionDownloading(true); 1086 ExtensionUpdaterTest::TestSingleExtensionDownloading(true);
1087 } 1087 }
1088 1088
1089 // This test is disabled on Mac, see http://crbug.com/26035. 1089 TEST_F(ExtensionUpdaterTest, TestBlacklistDownloading) {
1090 TEST(ExtensionUpdaterTest, TestBlacklistDownloading) {
1091 ExtensionUpdaterTest::TestBlacklistDownloading(); 1090 ExtensionUpdaterTest::TestBlacklistDownloading();
1092 } 1091 }
1093 1092
1094 TEST(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesFail) { 1093 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesFail) {
1095 ExtensionUpdaterTest::TestMultipleExtensionDownloading(false); 1094 ExtensionUpdaterTest::TestMultipleExtensionDownloading(false);
1096 } 1095 }
1097 TEST(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesSucceed) { 1096 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesSucceed) {
1098 ExtensionUpdaterTest::TestMultipleExtensionDownloading(true); 1097 ExtensionUpdaterTest::TestMultipleExtensionDownloading(true);
1099 } 1098 }
1100 1099
1101 TEST(ExtensionUpdaterTest, TestGalleryRequests) { 1100 TEST_F(ExtensionUpdaterTest, TestGalleryRequests) {
1102 // We want to test a variety of combinations of expected ping conditions for 1101 // We want to test a variety of combinations of expected ping conditions for
1103 // rollcall and active pings. 1102 // rollcall and active pings.
1104 int ping_cases[] = { ManifestFetchData::kNeverPinged, 0, 1, 5 }; 1103 int ping_cases[] = { ManifestFetchData::kNeverPinged, 0, 1, 5 };
1105 1104
1106 for (size_t i = 0; i < arraysize(ping_cases); i++) { 1105 for (size_t i = 0; i < arraysize(ping_cases); i++) {
1107 for (size_t j = 0; j < arraysize(ping_cases); j++) { 1106 for (size_t j = 0; j < arraysize(ping_cases); j++) {
1108 for (size_t k = 0; k < 2; k++) { 1107 for (size_t k = 0; k < 2; k++) {
1109 int rollcall_ping_days = ping_cases[i]; 1108 int rollcall_ping_days = ping_cases[i];
1110 int active_ping_days = ping_cases[j]; 1109 int active_ping_days = ping_cases[j];
1111 // Skip cases where rollcall_ping_days == -1, but active_ping_days > 0, 1110 // Skip cases where rollcall_ping_days == -1, but active_ping_days > 0,
1112 // because rollcall_ping_days == -1 means the app was just installed and 1111 // because rollcall_ping_days == -1 means the app was just installed and
1113 // this is the first update check after installation. 1112 // this is the first update check after installation.
1114 if (rollcall_ping_days == ManifestFetchData::kNeverPinged && 1113 if (rollcall_ping_days == ManifestFetchData::kNeverPinged &&
1115 active_ping_days > 0) 1114 active_ping_days > 0)
1116 continue; 1115 continue;
1117 1116
1118 bool active_bit = k > 0; 1117 bool active_bit = k > 0;
1119 ExtensionUpdaterTest::TestGalleryRequests( 1118 ExtensionUpdaterTest::TestGalleryRequests(
1120 rollcall_ping_days, active_ping_days, active_bit); 1119 rollcall_ping_days, active_ping_days, active_bit);
1121 ASSERT_FALSE(HasFailure()) << 1120 ASSERT_FALSE(HasFailure()) <<
1122 " rollcall_ping_days=" << ping_cases[i] << 1121 " rollcall_ping_days=" << ping_cases[i] <<
1123 " active_ping_days=" << ping_cases[j] << 1122 " active_ping_days=" << ping_cases[j] <<
1124 " active_bit=" << active_bit; 1123 " active_bit=" << active_bit;
1125 } 1124 }
1126 } 1125 }
1127 } 1126 }
1128 } 1127 }
1129 1128
1130 TEST(ExtensionUpdaterTest, TestHandleManifestResults) { 1129 TEST_F(ExtensionUpdaterTest, TestHandleManifestResults) {
1131 ExtensionUpdaterTest::TestHandleManifestResults(); 1130 ExtensionUpdaterTest::TestHandleManifestResults();
1132 } 1131 }
1133 1132
1134 TEST(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) { 1133 TEST_F(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) {
1135 MessageLoop message_loop; 1134 MessageLoop message_loop;
1136 BrowserThread file_thread(BrowserThread::FILE, &message_loop); 1135 BrowserThread file_thread(BrowserThread::FILE, &message_loop);
1137 1136
1138 MockService service; 1137 MockService service;
1139 ManifestFetchesBuilder builder(&service, service.extension_prefs()); 1138 ManifestFetchesBuilder builder(&service, service.extension_prefs());
1140 1139
1141 // Non-internal non-external extensions should be rejected. 1140 // Non-internal non-external extensions should be rejected.
1142 { 1141 {
1143 ExtensionList extensions; 1142 ExtensionList extensions;
1144 service.CreateTestExtensions(1, 1, &extensions, NULL, Extension::INVALID); 1143 service.CreateTestExtensions(1, 1, &extensions, NULL, Extension::INVALID);
(...skipping 28 matching lines...) Expand all
1173 false, false, 1172 false, false,
1174 Extension::INTERNAL)); 1173 Extension::INTERNAL));
1175 std::vector<ManifestFetchData*> fetches = builder.GetFetches(); 1174 std::vector<ManifestFetchData*> fetches = builder.GetFetches();
1176 ASSERT_EQ(1u, fetches.size()); 1175 ASSERT_EQ(1u, fetches.size());
1177 scoped_ptr<ManifestFetchData> fetch(fetches[0]); 1176 scoped_ptr<ManifestFetchData> fetch(fetches[0]);
1178 fetches.clear(); 1177 fetches.clear();
1179 EXPECT_FALSE(fetch->base_url().is_empty()); 1178 EXPECT_FALSE(fetch->base_url().is_empty());
1180 EXPECT_FALSE(fetch->full_url().is_empty()); 1179 EXPECT_FALSE(fetch->full_url().is_empty());
1181 } 1180 }
1182 1181
1183 TEST(ExtensionUpdaterTest, TestStartUpdateCheckMemory) { 1182 TEST_F(ExtensionUpdaterTest, TestStartUpdateCheckMemory) {
1184 MessageLoop message_loop; 1183 MessageLoop message_loop;
1185 BrowserThread ui_thread(BrowserThread::UI, &message_loop); 1184 BrowserThread ui_thread(BrowserThread::UI, &message_loop);
1186 BrowserThread file_thread(BrowserThread::FILE, &message_loop); 1185 BrowserThread file_thread(BrowserThread::FILE, &message_loop);
1187 1186
1188 ServiceForManifestTests service; 1187 ServiceForManifestTests service;
1189 TestURLFetcherFactory factory; 1188 TestURLFetcherFactory factory;
1190 ExtensionUpdater updater( 1189 ExtensionUpdater updater(
1191 &service, service.extension_prefs(), service.pref_service(), 1190 &service, service.extension_prefs(), service.pref_service(),
1192 service.profile(), kUpdateFrequencySecs); 1191 service.profile(), kUpdateFrequencySecs);
1193 updater.Start(); 1192 updater.Start();
1194 updater.StartUpdateCheck(new ManifestFetchData(GURL())); 1193 updater.StartUpdateCheck(new ManifestFetchData(GURL()));
1195 // This should delete the newly-created ManifestFetchData. 1194 // This should delete the newly-created ManifestFetchData.
1196 updater.StartUpdateCheck(new ManifestFetchData(GURL())); 1195 updater.StartUpdateCheck(new ManifestFetchData(GURL()));
1197 // This should add into |manifests_pending_|. 1196 // This should add into |manifests_pending_|.
1198 updater.StartUpdateCheck(new ManifestFetchData( 1197 updater.StartUpdateCheck(new ManifestFetchData(
1199 GURL("http://www.google.com"))); 1198 GURL("http://www.google.com")));
1200 // This should clear out |manifests_pending_|. 1199 // This should clear out |manifests_pending_|.
1201 updater.Stop(); 1200 updater.Stop();
1202 } 1201 }
1203 1202
1204 TEST(ExtensionUpdaterTest, TestCheckSoon) { 1203 TEST_F(ExtensionUpdaterTest, TestCheckSoon) {
1205 MessageLoop message_loop; 1204 MessageLoop message_loop;
1206 BrowserThread ui_thread(BrowserThread::UI, &message_loop); 1205 BrowserThread ui_thread(BrowserThread::UI, &message_loop);
1207 BrowserThread file_thread(BrowserThread::FILE, &message_loop); 1206 BrowserThread file_thread(BrowserThread::FILE, &message_loop);
1208 1207
1209 ServiceForManifestTests service; 1208 ServiceForManifestTests service;
1210 TestURLFetcherFactory factory; 1209 TestURLFetcherFactory factory;
1211 ExtensionUpdater updater( 1210 ExtensionUpdater updater(
1212 &service, service.extension_prefs(), service.pref_service(), 1211 &service, service.extension_prefs(), service.pref_service(),
1213 service.profile(), kUpdateFrequencySecs); 1212 service.profile(), kUpdateFrequencySecs);
1214 EXPECT_FALSE(updater.WillCheckSoon()); 1213 EXPECT_FALSE(updater.WillCheckSoon());
(...skipping 13 matching lines...) Expand all
1228 1227
1229 // TODO(asargent) - (http://crbug.com/12780) add tests for: 1228 // TODO(asargent) - (http://crbug.com/12780) add tests for:
1230 // -prodversionmin (shouldn't update if browser version too old) 1229 // -prodversionmin (shouldn't update if browser version too old)
1231 // -manifests & updates arriving out of order / interleaved 1230 // -manifests & updates arriving out of order / interleaved
1232 // -malformed update url (empty, file://, has query, has a # fragment, etc.) 1231 // -malformed update url (empty, file://, has query, has a # fragment, etc.)
1233 // -An extension gets uninstalled while updates are in progress (so it doesn't 1232 // -An extension gets uninstalled while updates are in progress (so it doesn't
1234 // "come back from the dead") 1233 // "come back from the dead")
1235 // -An extension gets manually updated to v3 while we're downloading v2 (ie 1234 // -An extension gets manually updated to v3 while we're downloading v2 (ie
1236 // you don't get downgraded accidentally) 1235 // you don't get downgraded accidentally)
1237 // -An update manifest mentions multiple updates 1236 // -An update manifest mentions multiple updates
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698