OLD | NEW |
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 "chrome/browser/extensions/extension_service_unittest.h" | 5 #include "chrome/browser/extensions/extension_service_unittest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 // ExternalExtensionProvider implementation: | 148 // ExternalExtensionProvider implementation: |
149 virtual void VisitRegisteredExtension() { | 149 virtual void VisitRegisteredExtension() { |
150 visit_count_++; | 150 visit_count_++; |
151 for (DataMap::const_iterator i = extension_map_.begin(); | 151 for (DataMap::const_iterator i = extension_map_.begin(); |
152 i != extension_map_.end(); ++i) { | 152 i != extension_map_.end(); ++i) { |
153 scoped_ptr<Version> version; | 153 scoped_ptr<Version> version; |
154 version.reset(Version::GetVersionFromString(i->second.first)); | 154 version.reset(Version::GetVersionFromString(i->second.first)); |
155 | 155 |
156 visitor_->OnExternalExtensionFileFound( | 156 visitor_->OnExternalExtensionFileFound( |
157 i->first, version.get(), i->second.second, location_, | 157 i->first, version.get(), i->second.second, location_, |
158 Extension::NO_FLAGS); | 158 Extension::NO_FLAGS, false); |
159 } | 159 } |
160 visitor_->OnExternalProviderReady(this); | 160 visitor_->OnExternalProviderReady(this); |
161 } | 161 } |
162 | 162 |
163 virtual bool HasExtension(const std::string& id) const { | 163 virtual bool HasExtension(const std::string& id) const { |
164 return extension_map_.find(id) != extension_map_.end(); | 164 return extension_map_.find(id) != extension_map_.end(); |
165 } | 165 } |
166 | 166 |
167 virtual bool GetExtensionDetails(const std::string& id, | 167 virtual bool GetExtensionDetails(const std::string& id, |
168 Extension::Location* location, | 168 Extension::Location* location, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 // Ask the provider to look up all extensions and return them. | 247 // Ask the provider to look up all extensions and return them. |
248 provider_->VisitRegisteredExtension(); | 248 provider_->VisitRegisteredExtension(); |
249 | 249 |
250 return ids_found_; | 250 return ids_found_; |
251 } | 251 } |
252 | 252 |
253 virtual void OnExternalExtensionFileFound(const std::string& id, | 253 virtual void OnExternalExtensionFileFound(const std::string& id, |
254 const Version* version, | 254 const Version* version, |
255 const FilePath& path, | 255 const FilePath& path, |
256 Extension::Location unused, | 256 Extension::Location unused, |
257 int creation_flags) { | 257 int creation_flags, |
| 258 bool mark_acknowledged) { |
258 EXPECT_EQ(Extension::NO_FLAGS, creation_flags); | 259 EXPECT_EQ(Extension::NO_FLAGS, creation_flags); |
259 | 260 |
260 ++ids_found_; | 261 ++ids_found_; |
261 DictionaryValue* pref; | 262 DictionaryValue* pref; |
262 // This tests is to make sure that the provider only notifies us of the | 263 // This tests is to make sure that the provider only notifies us of the |
263 // values we gave it. So if the id we doesn't exist in our internal | 264 // values we gave it. So if the id we doesn't exist in our internal |
264 // dictionary then something is wrong. | 265 // dictionary then something is wrong. |
265 EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) | 266 EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) |
266 << "Got back ID (" << id.c_str() << ") we weren't expecting"; | 267 << "Got back ID (" << id.c_str() << ") we weren't expecting"; |
267 | 268 |
(...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1248 InitializeEmptyExtensionService(); | 1249 InitializeEmptyExtensionService(); |
1249 | 1250 |
1250 FilePath path = data_dir_.AppendASCII("good.crx"); | 1251 FilePath path = data_dir_.AppendASCII("good.crx"); |
1251 set_extensions_enabled(true); | 1252 set_extensions_enabled(true); |
1252 | 1253 |
1253 scoped_ptr<Version> version; | 1254 scoped_ptr<Version> version; |
1254 version.reset(Version::GetVersionFromString("1.0.0.0")); | 1255 version.reset(Version::GetVersionFromString("1.0.0.0")); |
1255 // Install an external extension. | 1256 // Install an external extension. |
1256 service_->OnExternalExtensionFileFound(good_crx, version.get(), | 1257 service_->OnExternalExtensionFileFound(good_crx, version.get(), |
1257 path, Extension::EXTERNAL_PREF, | 1258 path, Extension::EXTERNAL_PREF, |
1258 Extension::FROM_BOOKMARK); | 1259 Extension::FROM_BOOKMARK, false); |
1259 loop_.RunAllPending(); | 1260 loop_.RunAllPending(); |
1260 | 1261 |
1261 const Extension* extension = service_->GetExtensionById(good_crx, false); | 1262 const Extension* extension = service_->GetExtensionById(good_crx, false); |
1262 ASSERT_TRUE(extension); | 1263 ASSERT_TRUE(extension); |
1263 ASSERT_EQ(Extension::FROM_BOOKMARK, | 1264 ASSERT_EQ(Extension::FROM_BOOKMARK, |
1264 Extension::FROM_BOOKMARK & extension->creation_flags()); | 1265 Extension::FROM_BOOKMARK & extension->creation_flags()); |
1265 } | 1266 } |
1266 | 1267 |
1267 // Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED | 1268 // Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED |
1268 TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) { | 1269 TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) { |
1269 InitializeEmptyExtensionService(); | 1270 InitializeEmptyExtensionService(); |
1270 | 1271 |
1271 FilePath path = data_dir_.AppendASCII("good.crx"); | 1272 FilePath path = data_dir_.AppendASCII("good.crx"); |
1272 set_extensions_enabled(true); | 1273 set_extensions_enabled(true); |
1273 | 1274 |
1274 scoped_ptr<Version> version; | 1275 scoped_ptr<Version> version; |
1275 version.reset(Version::GetVersionFromString("1.0.0.0")); | 1276 version.reset(Version::GetVersionFromString("1.0.0.0")); |
1276 // Install an external extension. | 1277 // Install an external extension. |
1277 service_->OnExternalExtensionFileFound(good_crx, version.get(), | 1278 service_->OnExternalExtensionFileFound(good_crx, version.get(), |
1278 path, Extension::EXTERNAL_PREF, | 1279 path, Extension::EXTERNAL_PREF, |
1279 Extension::NO_FLAGS); | 1280 Extension::NO_FLAGS, false); |
1280 loop_.RunAllPending(); | 1281 loop_.RunAllPending(); |
1281 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); | 1282 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); |
1282 | 1283 |
1283 // Uninstall it and check that its killbit gets set. | 1284 // Uninstall it and check that its killbit gets set. |
1284 UninstallExtension(good_crx, false); | 1285 UninstallExtension(good_crx, false); |
1285 ValidateIntegerPref(good_crx, "location", | 1286 ValidateIntegerPref(good_crx, "location", |
1286 Extension::EXTERNAL_EXTENSION_UNINSTALLED); | 1287 Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
1287 | 1288 |
1288 // Try to re-install it externally. This should fail because of the killbit. | 1289 // Try to re-install it externally. This should fail because of the killbit. |
1289 service_->OnExternalExtensionFileFound(good_crx, version.get(), | 1290 service_->OnExternalExtensionFileFound(good_crx, version.get(), |
1290 path, Extension::EXTERNAL_PREF, | 1291 path, Extension::EXTERNAL_PREF, |
1291 Extension::NO_FLAGS); | 1292 Extension::NO_FLAGS, false); |
1292 loop_.RunAllPending(); | 1293 loop_.RunAllPending(); |
1293 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); | 1294 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); |
1294 ValidateIntegerPref(good_crx, "location", | 1295 ValidateIntegerPref(good_crx, "location", |
1295 Extension::EXTERNAL_EXTENSION_UNINSTALLED); | 1296 Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
1296 | 1297 |
1297 version.reset(Version::GetVersionFromString("1.0.0.1")); | 1298 version.reset(Version::GetVersionFromString("1.0.0.1")); |
1298 // Repeat the same thing with a newer version of the extension. | 1299 // Repeat the same thing with a newer version of the extension. |
1299 path = data_dir_.AppendASCII("good2.crx"); | 1300 path = data_dir_.AppendASCII("good2.crx"); |
1300 service_->OnExternalExtensionFileFound(good_crx, version.get(), | 1301 service_->OnExternalExtensionFileFound(good_crx, version.get(), |
1301 path, Extension::EXTERNAL_PREF, | 1302 path, Extension::EXTERNAL_PREF, |
1302 Extension::NO_FLAGS); | 1303 Extension::NO_FLAGS, false); |
1303 loop_.RunAllPending(); | 1304 loop_.RunAllPending(); |
1304 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); | 1305 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); |
1305 ValidateIntegerPref(good_crx, "location", | 1306 ValidateIntegerPref(good_crx, "location", |
1306 Extension::EXTERNAL_EXTENSION_UNINSTALLED); | 1307 Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
1307 | 1308 |
1308 // Try adding the same extension from an external update URL. | 1309 // Try adding the same extension from an external update URL. |
1309 service_->pending_extension_manager()->AddFromExternalUpdateUrl( | 1310 service_->pending_extension_manager()->AddFromExternalUpdateUrl( |
1310 good_crx, | 1311 good_crx, |
1311 GURL("http:://fake.update/url"), | 1312 GURL("http:://fake.update/url"), |
1312 Extension::EXTERNAL_PREF_DOWNLOAD); | 1313 Extension::EXTERNAL_PREF_DOWNLOAD); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1352 version.reset(Version::GetVersionFromString("1.0.0.0")); | 1353 version.reset(Version::GetVersionFromString("1.0.0.0")); |
1353 | 1354 |
1354 const std::string wrong_id = all_zero; | 1355 const std::string wrong_id = all_zero; |
1355 const std::string correct_id = good_crx; | 1356 const std::string correct_id = good_crx; |
1356 ASSERT_NE(correct_id, wrong_id); | 1357 ASSERT_NE(correct_id, wrong_id); |
1357 | 1358 |
1358 // Install an external extension with an ID from the external | 1359 // Install an external extension with an ID from the external |
1359 // source that is not equal to the ID in the extension manifest. | 1360 // source that is not equal to the ID in the extension manifest. |
1360 service_->OnExternalExtensionFileFound( | 1361 service_->OnExternalExtensionFileFound( |
1361 wrong_id, version.get(), path, Extension::EXTERNAL_PREF, | 1362 wrong_id, version.get(), path, Extension::EXTERNAL_PREF, |
1362 Extension::NO_FLAGS); | 1363 Extension::NO_FLAGS, false); |
1363 | 1364 |
1364 loop_.RunAllPending(); | 1365 loop_.RunAllPending(); |
1365 ASSERT_FALSE(service_->GetExtensionById(good_crx, false)); | 1366 ASSERT_FALSE(service_->GetExtensionById(good_crx, false)); |
1366 | 1367 |
1367 // Try again with the right ID. Expect success. | 1368 // Try again with the right ID. Expect success. |
1368 service_->OnExternalExtensionFileFound( | 1369 service_->OnExternalExtensionFileFound( |
1369 correct_id, version.get(), path, Extension::EXTERNAL_PREF, | 1370 correct_id, version.get(), path, Extension::EXTERNAL_PREF, |
1370 Extension::NO_FLAGS); | 1371 Extension::NO_FLAGS, false); |
1371 loop_.RunAllPending(); | 1372 loop_.RunAllPending(); |
1372 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); | 1373 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); |
1373 } | 1374 } |
1374 | 1375 |
1375 // Test that external extensions with incorrect versions are not installed. | 1376 // Test that external extensions with incorrect versions are not installed. |
1376 TEST_F(ExtensionServiceTest, FailOnWrongVersion) { | 1377 TEST_F(ExtensionServiceTest, FailOnWrongVersion) { |
1377 InitializeEmptyExtensionService(); | 1378 InitializeEmptyExtensionService(); |
1378 FilePath path = data_dir_.AppendASCII("good.crx"); | 1379 FilePath path = data_dir_.AppendASCII("good.crx"); |
1379 set_extensions_enabled(true); | 1380 set_extensions_enabled(true); |
1380 | 1381 |
1381 // Install an external extension with a version from the external | 1382 // Install an external extension with a version from the external |
1382 // source that is not equal to the version in the extension manifest. | 1383 // source that is not equal to the version in the extension manifest. |
1383 scoped_ptr<Version> wrong_version; | 1384 scoped_ptr<Version> wrong_version; |
1384 wrong_version.reset(Version::GetVersionFromString("1.2.3.4")); | 1385 wrong_version.reset(Version::GetVersionFromString("1.2.3.4")); |
1385 service_->OnExternalExtensionFileFound( | 1386 service_->OnExternalExtensionFileFound( |
1386 good_crx, wrong_version.get(), path, Extension::EXTERNAL_PREF, | 1387 good_crx, wrong_version.get(), path, Extension::EXTERNAL_PREF, |
1387 Extension::NO_FLAGS); | 1388 Extension::NO_FLAGS, false); |
1388 | 1389 |
1389 loop_.RunAllPending(); | 1390 loop_.RunAllPending(); |
1390 ASSERT_FALSE(service_->GetExtensionById(good_crx, false)); | 1391 ASSERT_FALSE(service_->GetExtensionById(good_crx, false)); |
1391 | 1392 |
1392 // Try again with the right version. Expect success. | 1393 // Try again with the right version. Expect success. |
1393 scoped_ptr<Version> correct_version; | 1394 scoped_ptr<Version> correct_version; |
1394 correct_version.reset(Version::GetVersionFromString("1.0.0.0")); | 1395 correct_version.reset(Version::GetVersionFromString("1.0.0.0")); |
1395 service_->OnExternalExtensionFileFound( | 1396 service_->OnExternalExtensionFileFound( |
1396 good_crx, correct_version.get(), path, Extension::EXTERNAL_PREF, | 1397 good_crx, correct_version.get(), path, Extension::EXTERNAL_PREF, |
1397 Extension::NO_FLAGS); | 1398 Extension::NO_FLAGS, false); |
1398 loop_.RunAllPending(); | 1399 loop_.RunAllPending(); |
1399 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); | 1400 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); |
1400 } | 1401 } |
1401 | 1402 |
1402 // Install a user script (they get converted automatically to an extension) | 1403 // Install a user script (they get converted automatically to an extension) |
1403 TEST_F(ExtensionServiceTest, InstallUserScript) { | 1404 TEST_F(ExtensionServiceTest, InstallUserScript) { |
1404 // The details of script conversion are tested elsewhere, this just tests | 1405 // The details of script conversion are tested elsewhere, this just tests |
1405 // integration with ExtensionService. | 1406 // integration with ExtensionService. |
1406 InitializeEmptyExtensionService(); | 1407 InitializeEmptyExtensionService(); |
1407 | 1408 |
(...skipping 2757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4165 crx_id_, GURL(), Extension::EXTERNAL_PREF_DOWNLOAD); | 4166 crx_id_, GURL(), Extension::EXTERNAL_PREF_DOWNLOAD); |
4166 } | 4167 } |
4167 | 4168 |
4168 // Fake an external file from external_extensions.json. | 4169 // Fake an external file from external_extensions.json. |
4169 void AddPendingExternalPrefFileInstall() { | 4170 void AddPendingExternalPrefFileInstall() { |
4170 scoped_ptr<Version> version; | 4171 scoped_ptr<Version> version; |
4171 version.reset(Version::GetVersionFromString("1.0.0.0")); | 4172 version.reset(Version::GetVersionFromString("1.0.0.0")); |
4172 | 4173 |
4173 service_->OnExternalExtensionFileFound( | 4174 service_->OnExternalExtensionFileFound( |
4174 crx_id_, version.get(), crx_path_, Extension::EXTERNAL_PREF, | 4175 crx_id_, version.get(), crx_path_, Extension::EXTERNAL_PREF, |
4175 Extension::NO_FLAGS); | 4176 Extension::NO_FLAGS, false); |
4176 } | 4177 } |
4177 | 4178 |
4178 // Fake a request from sync to install an extension. | 4179 // Fake a request from sync to install an extension. |
4179 bool AddPendingSyncInstall() { | 4180 bool AddPendingSyncInstall() { |
4180 return service_->pending_extension_manager()->AddFromSync( | 4181 return service_->pending_extension_manager()->AddFromSync( |
4181 crx_id_, GURL(kGoodUpdateURL), &IsExtension, kGoodInstallSilently); | 4182 crx_id_, GURL(kGoodUpdateURL), &IsExtension, kGoodInstallSilently); |
4182 } | 4183 } |
4183 | 4184 |
4184 // Fake a policy install. | 4185 // Fake a policy install. |
4185 void AddPendingPolicyInstall() { | 4186 void AddPendingPolicyInstall() { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4289 ASSERT_FALSE(AddPendingSyncInstall()); | 4290 ASSERT_FALSE(AddPendingSyncInstall()); |
4290 | 4291 |
4291 // Wait for the external source to install. | 4292 // Wait for the external source to install. |
4292 WaitForCrxInstall(crx_path_, INSTALL_NEW); | 4293 WaitForCrxInstall(crx_path_, INSTALL_NEW); |
4293 ASSERT_TRUE(IsCrxInstalled()); | 4294 ASSERT_TRUE(IsCrxInstalled()); |
4294 | 4295 |
4295 // Now that the extension is installed, sync request should fail | 4296 // Now that the extension is installed, sync request should fail |
4296 // because the extension is already installed. | 4297 // because the extension is already installed. |
4297 ASSERT_FALSE(AddPendingSyncInstall()); | 4298 ASSERT_FALSE(AddPendingSyncInstall()); |
4298 } | 4299 } |
OLD | NEW |