OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <algorithm> | 5 #include <algorithm> |
6 #include <set> | 6 #include <set> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 } // namespace | 235 } // namespace |
236 | 236 |
237 class MockExtensionProvider : public extensions::ExternalProviderInterface { | 237 class MockExtensionProvider : public extensions::ExternalProviderInterface { |
238 public: | 238 public: |
239 MockExtensionProvider( | 239 MockExtensionProvider( |
240 VisitorInterface* visitor, | 240 VisitorInterface* visitor, |
241 Manifest::Location location) | 241 Manifest::Location location) |
242 : location_(location), visitor_(visitor), visit_count_(0) { | 242 : location_(location), visitor_(visitor), visit_count_(0) { |
243 } | 243 } |
244 | 244 |
245 virtual ~MockExtensionProvider() {} | 245 ~MockExtensionProvider() override {} |
246 | 246 |
247 void UpdateOrAddExtension(const std::string& id, | 247 void UpdateOrAddExtension(const std::string& id, |
248 const std::string& version, | 248 const std::string& version, |
249 const base::FilePath& path) { | 249 const base::FilePath& path) { |
250 extension_map_[id] = std::make_pair(version, path); | 250 extension_map_[id] = std::make_pair(version, path); |
251 } | 251 } |
252 | 252 |
253 void RemoveExtension(const std::string& id) { | 253 void RemoveExtension(const std::string& id) { |
254 extension_map_.erase(id); | 254 extension_map_.erase(id); |
255 } | 255 } |
256 | 256 |
257 // ExternalProvider implementation: | 257 // ExternalProvider implementation: |
258 virtual void VisitRegisteredExtension() override { | 258 void VisitRegisteredExtension() override { |
259 visit_count_++; | 259 visit_count_++; |
260 for (DataMap::const_iterator i = extension_map_.begin(); | 260 for (DataMap::const_iterator i = extension_map_.begin(); |
261 i != extension_map_.end(); ++i) { | 261 i != extension_map_.end(); ++i) { |
262 Version version(i->second.first); | 262 Version version(i->second.first); |
263 | 263 |
264 visitor_->OnExternalExtensionFileFound( | 264 visitor_->OnExternalExtensionFileFound( |
265 i->first, &version, i->second.second, location_, | 265 i->first, &version, i->second.second, location_, |
266 Extension::NO_FLAGS, false); | 266 Extension::NO_FLAGS, false); |
267 } | 267 } |
268 visitor_->OnExternalProviderReady(this); | 268 visitor_->OnExternalProviderReady(this); |
269 } | 269 } |
270 | 270 |
271 virtual bool HasExtension(const std::string& id) const override { | 271 bool HasExtension(const std::string& id) const override { |
272 return extension_map_.find(id) != extension_map_.end(); | 272 return extension_map_.find(id) != extension_map_.end(); |
273 } | 273 } |
274 | 274 |
275 virtual bool GetExtensionDetails( | 275 bool GetExtensionDetails(const std::string& id, |
276 const std::string& id, | 276 Manifest::Location* location, |
277 Manifest::Location* location, | 277 scoped_ptr<Version>* version) const override { |
278 scoped_ptr<Version>* version) const override { | |
279 DataMap::const_iterator it = extension_map_.find(id); | 278 DataMap::const_iterator it = extension_map_.find(id); |
280 if (it == extension_map_.end()) | 279 if (it == extension_map_.end()) |
281 return false; | 280 return false; |
282 | 281 |
283 if (version) | 282 if (version) |
284 version->reset(new Version(it->second.first)); | 283 version->reset(new Version(it->second.first)); |
285 | 284 |
286 if (location) | 285 if (location) |
287 *location = location_; | 286 *location = location_; |
288 | 287 |
289 return true; | 288 return true; |
290 } | 289 } |
291 | 290 |
292 virtual bool IsReady() const override { | 291 bool IsReady() const override { return true; } |
293 return true; | |
294 } | |
295 | 292 |
296 virtual void ServiceShutdown() override { | 293 void ServiceShutdown() override {} |
297 } | |
298 | 294 |
299 int visit_count() const { return visit_count_; } | 295 int visit_count() const { return visit_count_; } |
300 void set_visit_count(int visit_count) { | 296 void set_visit_count(int visit_count) { |
301 visit_count_ = visit_count; | 297 visit_count_ = visit_count; |
302 } | 298 } |
303 | 299 |
304 private: | 300 private: |
305 typedef std::map< std::string, std::pair<std::string, base::FilePath> > | 301 typedef std::map< std::string, std::pair<std::string, base::FilePath> > |
306 DataMap; | 302 DataMap; |
307 DataMap extension_map_; | 303 DataMap extension_map_; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 } | 358 } |
363 | 359 |
364 // Reset our counter. | 360 // Reset our counter. |
365 ids_found_ = 0; | 361 ids_found_ = 0; |
366 // Ask the provider to look up all extensions and return them. | 362 // Ask the provider to look up all extensions and return them. |
367 provider_->VisitRegisteredExtension(); | 363 provider_->VisitRegisteredExtension(); |
368 | 364 |
369 return ids_found_; | 365 return ids_found_; |
370 } | 366 } |
371 | 367 |
372 virtual bool OnExternalExtensionFileFound(const std::string& id, | 368 bool OnExternalExtensionFileFound(const std::string& id, |
373 const Version* version, | 369 const Version* version, |
374 const base::FilePath& path, | 370 const base::FilePath& path, |
375 Manifest::Location unused, | 371 Manifest::Location unused, |
376 int creation_flags, | 372 int creation_flags, |
377 bool mark_acknowledged) override { | 373 bool mark_acknowledged) override { |
378 EXPECT_EQ(expected_creation_flags_, creation_flags); | 374 EXPECT_EQ(expected_creation_flags_, creation_flags); |
379 | 375 |
380 ++ids_found_; | 376 ++ids_found_; |
381 base::DictionaryValue* pref; | 377 base::DictionaryValue* pref; |
382 // This tests is to make sure that the provider only notifies us of the | 378 // This tests is to make sure that the provider only notifies us of the |
383 // values we gave it. So if the id we doesn't exist in our internal | 379 // values we gave it. So if the id we doesn't exist in our internal |
384 // dictionary then something is wrong. | 380 // dictionary then something is wrong. |
385 EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) | 381 EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) |
386 << "Got back ID (" << id.c_str() << ") we weren't expecting"; | 382 << "Got back ID (" << id.c_str() << ") we weren't expecting"; |
387 | 383 |
(...skipping 17 matching lines...) Expand all Loading... |
405 EXPECT_STREQ(version->GetString().c_str(), v1->GetString().c_str()); | 401 EXPECT_STREQ(version->GetString().c_str(), v1->GetString().c_str()); |
406 EXPECT_STREQ(version->GetString().c_str(), v2->GetString().c_str()); | 402 EXPECT_STREQ(version->GetString().c_str(), v2->GetString().c_str()); |
407 EXPECT_EQ(Manifest::EXTERNAL_PREF, location); | 403 EXPECT_EQ(Manifest::EXTERNAL_PREF, location); |
408 | 404 |
409 // Remove it so we won't count it ever again. | 405 // Remove it so we won't count it ever again. |
410 prefs_->Remove(id, NULL); | 406 prefs_->Remove(id, NULL); |
411 } | 407 } |
412 return true; | 408 return true; |
413 } | 409 } |
414 | 410 |
415 virtual bool OnExternalExtensionUpdateUrlFound( | 411 bool OnExternalExtensionUpdateUrlFound(const std::string& id, |
416 const std::string& id, | 412 const std::string& install_parameter, |
417 const std::string& install_parameter, | 413 const GURL& update_url, |
418 const GURL& update_url, | 414 Manifest::Location location, |
419 Manifest::Location location, | 415 int creation_flags, |
420 int creation_flags, | 416 bool mark_acknowledged) override { |
421 bool mark_acknowledged) override { | |
422 ++ids_found_; | 417 ++ids_found_; |
423 base::DictionaryValue* pref; | 418 base::DictionaryValue* pref; |
424 // This tests is to make sure that the provider only notifies us of the | 419 // This tests is to make sure that the provider only notifies us of the |
425 // values we gave it. So if the id we doesn't exist in our internal | 420 // values we gave it. So if the id we doesn't exist in our internal |
426 // dictionary then something is wrong. | 421 // dictionary then something is wrong. |
427 EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) | 422 EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) |
428 << L"Got back ID (" << id.c_str() << ") we weren't expecting"; | 423 << L"Got back ID (" << id.c_str() << ") we weren't expecting"; |
429 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location); | 424 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location); |
430 | 425 |
431 if (pref) { | 426 if (pref) { |
432 EXPECT_TRUE(provider_->HasExtension(id)); | 427 EXPECT_TRUE(provider_->HasExtension(id)); |
433 | 428 |
434 // External extensions with update URLs do not have versions. | 429 // External extensions with update URLs do not have versions. |
435 scoped_ptr<Version> v1; | 430 scoped_ptr<Version> v1; |
436 Manifest::Location location1 = Manifest::INVALID_LOCATION; | 431 Manifest::Location location1 = Manifest::INVALID_LOCATION; |
437 EXPECT_TRUE(provider_->GetExtensionDetails(id, &location1, &v1)); | 432 EXPECT_TRUE(provider_->GetExtensionDetails(id, &location1, &v1)); |
438 EXPECT_FALSE(v1.get()); | 433 EXPECT_FALSE(v1.get()); |
439 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location1); | 434 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location1); |
440 | 435 |
441 std::string parsed_install_parameter; | 436 std::string parsed_install_parameter; |
442 pref->GetString("install_parameter", &parsed_install_parameter); | 437 pref->GetString("install_parameter", &parsed_install_parameter); |
443 EXPECT_EQ(parsed_install_parameter, install_parameter); | 438 EXPECT_EQ(parsed_install_parameter, install_parameter); |
444 | 439 |
445 // Remove it so we won't count it again. | 440 // Remove it so we won't count it again. |
446 prefs_->Remove(id, NULL); | 441 prefs_->Remove(id, NULL); |
447 } | 442 } |
448 return true; | 443 return true; |
449 } | 444 } |
450 | 445 |
451 virtual void OnExternalProviderReady( | 446 void OnExternalProviderReady( |
452 const extensions::ExternalProviderInterface* provider) override { | 447 const extensions::ExternalProviderInterface* provider) override { |
453 EXPECT_EQ(provider, provider_.get()); | 448 EXPECT_EQ(provider, provider_.get()); |
454 EXPECT_TRUE(provider->IsReady()); | 449 EXPECT_TRUE(provider->IsReady()); |
455 } | 450 } |
456 | 451 |
457 private: | 452 private: |
458 int ids_found_; | 453 int ids_found_; |
459 base::FilePath fake_base_path_; | 454 base::FilePath fake_base_path_; |
460 int expected_creation_flags_; | 455 int expected_creation_flags_; |
461 scoped_ptr<extensions::ExternalProviderImpl> provider_; | 456 scoped_ptr<extensions::ExternalProviderImpl> provider_; |
(...skipping 19 matching lines...) Expand all Loading... |
481 content::NotificationService::AllSources()); | 476 content::NotificationService::AllSources()); |
482 registrar_.Add(this, | 477 registrar_.Add(this, |
483 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | 478 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
484 content::NotificationService::AllSources()); | 479 content::NotificationService::AllSources()); |
485 registrar_.Add( | 480 registrar_.Add( |
486 this, | 481 this, |
487 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, | 482 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, |
488 content::NotificationService::AllSources()); | 483 content::NotificationService::AllSources()); |
489 } | 484 } |
490 | 485 |
491 virtual void Observe(int type, | 486 void Observe(int type, |
492 const content::NotificationSource& source, | 487 const content::NotificationSource& source, |
493 const content::NotificationDetails& details) override { | 488 const content::NotificationDetails& details) override { |
494 switch (type) { | 489 switch (type) { |
495 case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: { | 490 case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: { |
496 const Extension* extension = | 491 const Extension* extension = |
497 content::Details<const Extension>(details).ptr(); | 492 content::Details<const Extension>(details).ptr(); |
498 loaded_.push_back(make_scoped_refptr(extension)); | 493 loaded_.push_back(make_scoped_refptr(extension)); |
499 // The tests rely on the errors being in a certain order, which can vary | 494 // The tests rely on the errors being in a certain order, which can vary |
500 // depending on how filesystem iteration works. | 495 // depending on how filesystem iteration works. |
501 std::stable_sort(loaded_.begin(), loaded_.end(), ExtensionsOrder()); | 496 std::stable_sort(loaded_.begin(), loaded_.end(), ExtensionsOrder()); |
502 break; | 497 break; |
503 } | 498 } |
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1147 size_t expected_extensions_count_; | 1142 size_t expected_extensions_count_; |
1148 content::NotificationRegistrar registrar_; | 1143 content::NotificationRegistrar registrar_; |
1149 }; | 1144 }; |
1150 | 1145 |
1151 // Receives notifications from a PackExtensionJob, indicating either that | 1146 // Receives notifications from a PackExtensionJob, indicating either that |
1152 // packing succeeded or that there was some error. | 1147 // packing succeeded or that there was some error. |
1153 class PackExtensionTestClient : public extensions::PackExtensionJob::Client { | 1148 class PackExtensionTestClient : public extensions::PackExtensionJob::Client { |
1154 public: | 1149 public: |
1155 PackExtensionTestClient(const base::FilePath& expected_crx_path, | 1150 PackExtensionTestClient(const base::FilePath& expected_crx_path, |
1156 const base::FilePath& expected_private_key_path); | 1151 const base::FilePath& expected_private_key_path); |
1157 virtual void OnPackSuccess(const base::FilePath& crx_path, | 1152 void OnPackSuccess(const base::FilePath& crx_path, |
1158 const base::FilePath& private_key_path) override; | 1153 const base::FilePath& private_key_path) override; |
1159 virtual void OnPackFailure(const std::string& error_message, | 1154 void OnPackFailure(const std::string& error_message, |
1160 ExtensionCreator::ErrorType type) override; | 1155 ExtensionCreator::ErrorType type) override; |
1161 | 1156 |
1162 private: | 1157 private: |
1163 const base::FilePath expected_crx_path_; | 1158 const base::FilePath expected_crx_path_; |
1164 const base::FilePath expected_private_key_path_; | 1159 const base::FilePath expected_private_key_path_; |
1165 DISALLOW_COPY_AND_ASSIGN(PackExtensionTestClient); | 1160 DISALLOW_COPY_AND_ASSIGN(PackExtensionTestClient); |
1166 }; | 1161 }; |
1167 | 1162 |
1168 PackExtensionTestClient::PackExtensionTestClient( | 1163 PackExtensionTestClient::PackExtensionTestClient( |
1169 const base::FilePath& expected_crx_path, | 1164 const base::FilePath& expected_crx_path, |
1170 const base::FilePath& expected_private_key_path) | 1165 const base::FilePath& expected_private_key_path) |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1454 ValidatePrefKeyCount(++pref_count); | 1449 ValidatePrefKeyCount(++pref_count); |
1455 ValidateIntegerPref(good2048, "state", Extension::ENABLED); | 1450 ValidateIntegerPref(good2048, "state", Extension::ENABLED); |
1456 ValidateIntegerPref(good2048, "location", Manifest::INTERNAL); | 1451 ValidateIntegerPref(good2048, "location", Manifest::INTERNAL); |
1457 | 1452 |
1458 // TODO(erikkay): add more tests for many of the failure cases. | 1453 // TODO(erikkay): add more tests for many of the failure cases. |
1459 // TODO(erikkay): add tests for upgrade cases. | 1454 // TODO(erikkay): add tests for upgrade cases. |
1460 } | 1455 } |
1461 | 1456 |
1462 struct MockExtensionRegistryObserver | 1457 struct MockExtensionRegistryObserver |
1463 : public extensions::ExtensionRegistryObserver { | 1458 : public extensions::ExtensionRegistryObserver { |
1464 virtual void OnExtensionWillBeInstalled( | 1459 void OnExtensionWillBeInstalled(content::BrowserContext* browser_context, |
1465 content::BrowserContext* browser_context, | 1460 const Extension* extension, |
1466 const Extension* extension, | 1461 bool is_update, |
1467 bool is_update, | 1462 bool from_ephemeral, |
1468 bool from_ephemeral, | 1463 const std::string& old_name) override { |
1469 const std::string& old_name) override { | |
1470 last_extension_installed = extension->id(); | 1464 last_extension_installed = extension->id(); |
1471 } | 1465 } |
1472 | 1466 |
1473 virtual void OnExtensionUninstalled( | 1467 void OnExtensionUninstalled(content::BrowserContext* browser_context, |
1474 content::BrowserContext* browser_context, | 1468 const Extension* extension, |
1475 const Extension* extension, | 1469 extensions::UninstallReason reason) override { |
1476 extensions::UninstallReason reason) override { | |
1477 last_extension_uninstalled = extension->id(); | 1470 last_extension_uninstalled = extension->id(); |
1478 } | 1471 } |
1479 | 1472 |
1480 std::string last_extension_installed; | 1473 std::string last_extension_installed; |
1481 std::string last_extension_uninstalled; | 1474 std::string last_extension_uninstalled; |
1482 }; | 1475 }; |
1483 | 1476 |
1484 // Test that correct notifications are sent to ExtensionRegistryObserver on | 1477 // Test that correct notifications are sent to ExtensionRegistryObserver on |
1485 // extension install and uninstall. | 1478 // extension install and uninstall. |
1486 TEST_F(ExtensionServiceTest, InstallObserverNotified) { | 1479 TEST_F(ExtensionServiceTest, InstallObserverNotified) { |
(...skipping 3629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5116 ExtensionsReadyRecorder() : ready_(false) { | 5109 ExtensionsReadyRecorder() : ready_(false) { |
5117 registrar_.Add(this, | 5110 registrar_.Add(this, |
5118 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, | 5111 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, |
5119 content::NotificationService::AllSources()); | 5112 content::NotificationService::AllSources()); |
5120 } | 5113 } |
5121 | 5114 |
5122 void set_ready(bool value) { ready_ = value; } | 5115 void set_ready(bool value) { ready_ = value; } |
5123 bool ready() { return ready_; } | 5116 bool ready() { return ready_; } |
5124 | 5117 |
5125 private: | 5118 private: |
5126 virtual void Observe(int type, | 5119 void Observe(int type, |
5127 const content::NotificationSource& source, | 5120 const content::NotificationSource& source, |
5128 const content::NotificationDetails& details) override { | 5121 const content::NotificationDetails& details) override { |
5129 switch (type) { | 5122 switch (type) { |
5130 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED: | 5123 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED: |
5131 ready_ = true; | 5124 ready_ = true; |
5132 break; | 5125 break; |
5133 default: | 5126 default: |
5134 NOTREACHED(); | 5127 NOTREACHED(); |
5135 } | 5128 } |
5136 } | 5129 } |
5137 | 5130 |
5138 content::NotificationRegistrar registrar_; | 5131 content::NotificationRegistrar registrar_; |
(...skipping 1999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7138 | 7131 |
7139 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, | 7132 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, |
7140 content::Source<Profile>(profile()), | 7133 content::Source<Profile>(profile()), |
7141 content::NotificationService::NoDetails()); | 7134 content::NotificationService::NoDetails()); |
7142 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); | 7135 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); |
7143 EXPECT_EQ(0u, registry()->enabled_extensions().size()); | 7136 EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
7144 EXPECT_EQ(0u, registry()->disabled_extensions().size()); | 7137 EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
7145 EXPECT_EQ(0u, registry()->terminated_extensions().size()); | 7138 EXPECT_EQ(0u, registry()->terminated_extensions().size()); |
7146 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); | 7139 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
7147 } | 7140 } |
OLD | NEW |