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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 virtual 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 virtual 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 virtual bool GetExtensionDetails( |
276 const std::string& id, | 276 const std::string& id, |
277 Manifest::Location* location, | 277 Manifest::Location* location, |
278 scoped_ptr<Version>* version) const OVERRIDE { | 278 scoped_ptr<Version>* version) const override { |
279 DataMap::const_iterator it = extension_map_.find(id); | 279 DataMap::const_iterator it = extension_map_.find(id); |
280 if (it == extension_map_.end()) | 280 if (it == extension_map_.end()) |
281 return false; | 281 return false; |
282 | 282 |
283 if (version) | 283 if (version) |
284 version->reset(new Version(it->second.first)); | 284 version->reset(new Version(it->second.first)); |
285 | 285 |
286 if (location) | 286 if (location) |
287 *location = location_; | 287 *location = location_; |
288 | 288 |
289 return true; | 289 return true; |
290 } | 290 } |
291 | 291 |
292 virtual bool IsReady() const OVERRIDE { | 292 virtual bool IsReady() const override { |
293 return true; | 293 return true; |
294 } | 294 } |
295 | 295 |
296 virtual void ServiceShutdown() OVERRIDE { | 296 virtual void ServiceShutdown() override { |
297 } | 297 } |
298 | 298 |
299 int visit_count() const { return visit_count_; } | 299 int visit_count() const { return visit_count_; } |
300 void set_visit_count(int visit_count) { | 300 void set_visit_count(int visit_count) { |
301 visit_count_ = visit_count; | 301 visit_count_ = visit_count; |
302 } | 302 } |
303 | 303 |
304 private: | 304 private: |
305 typedef std::map< std::string, std::pair<std::string, base::FilePath> > | 305 typedef std::map< std::string, std::pair<std::string, base::FilePath> > |
306 DataMap; | 306 DataMap; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 provider_->VisitRegisteredExtension(); | 367 provider_->VisitRegisteredExtension(); |
368 | 368 |
369 return ids_found_; | 369 return ids_found_; |
370 } | 370 } |
371 | 371 |
372 virtual bool OnExternalExtensionFileFound(const std::string& id, | 372 virtual bool OnExternalExtensionFileFound(const std::string& id, |
373 const Version* version, | 373 const Version* version, |
374 const base::FilePath& path, | 374 const base::FilePath& path, |
375 Manifest::Location unused, | 375 Manifest::Location unused, |
376 int creation_flags, | 376 int creation_flags, |
377 bool mark_acknowledged) OVERRIDE { | 377 bool mark_acknowledged) override { |
378 EXPECT_EQ(expected_creation_flags_, creation_flags); | 378 EXPECT_EQ(expected_creation_flags_, creation_flags); |
379 | 379 |
380 ++ids_found_; | 380 ++ids_found_; |
381 base::DictionaryValue* pref; | 381 base::DictionaryValue* pref; |
382 // This tests is to make sure that the provider only notifies us of the | 382 // 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 | 383 // values we gave it. So if the id we doesn't exist in our internal |
384 // dictionary then something is wrong. | 384 // dictionary then something is wrong. |
385 EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) | 385 EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) |
386 << "Got back ID (" << id.c_str() << ") we weren't expecting"; | 386 << "Got back ID (" << id.c_str() << ") we weren't expecting"; |
387 | 387 |
(...skipping 23 matching lines...) Expand all Loading... |
411 } | 411 } |
412 return true; | 412 return true; |
413 } | 413 } |
414 | 414 |
415 virtual bool OnExternalExtensionUpdateUrlFound( | 415 virtual bool OnExternalExtensionUpdateUrlFound( |
416 const std::string& id, | 416 const std::string& id, |
417 const std::string& install_parameter, | 417 const std::string& install_parameter, |
418 const GURL& update_url, | 418 const GURL& update_url, |
419 Manifest::Location location, | 419 Manifest::Location location, |
420 int creation_flags, | 420 int creation_flags, |
421 bool mark_acknowledged) OVERRIDE { | 421 bool mark_acknowledged) override { |
422 ++ids_found_; | 422 ++ids_found_; |
423 base::DictionaryValue* pref; | 423 base::DictionaryValue* pref; |
424 // This tests is to make sure that the provider only notifies us of the | 424 // 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 | 425 // values we gave it. So if the id we doesn't exist in our internal |
426 // dictionary then something is wrong. | 426 // dictionary then something is wrong. |
427 EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) | 427 EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) |
428 << L"Got back ID (" << id.c_str() << ") we weren't expecting"; | 428 << L"Got back ID (" << id.c_str() << ") we weren't expecting"; |
429 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location); | 429 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location); |
430 | 430 |
431 if (pref) { | 431 if (pref) { |
(...skipping 10 matching lines...) Expand all Loading... |
442 pref->GetString("install_parameter", &parsed_install_parameter); | 442 pref->GetString("install_parameter", &parsed_install_parameter); |
443 EXPECT_EQ(parsed_install_parameter, install_parameter); | 443 EXPECT_EQ(parsed_install_parameter, install_parameter); |
444 | 444 |
445 // Remove it so we won't count it again. | 445 // Remove it so we won't count it again. |
446 prefs_->Remove(id, NULL); | 446 prefs_->Remove(id, NULL); |
447 } | 447 } |
448 return true; | 448 return true; |
449 } | 449 } |
450 | 450 |
451 virtual void OnExternalProviderReady( | 451 virtual void OnExternalProviderReady( |
452 const extensions::ExternalProviderInterface* provider) OVERRIDE { | 452 const extensions::ExternalProviderInterface* provider) override { |
453 EXPECT_EQ(provider, provider_.get()); | 453 EXPECT_EQ(provider, provider_.get()); |
454 EXPECT_TRUE(provider->IsReady()); | 454 EXPECT_TRUE(provider->IsReady()); |
455 } | 455 } |
456 | 456 |
457 private: | 457 private: |
458 int ids_found_; | 458 int ids_found_; |
459 base::FilePath fake_base_path_; | 459 base::FilePath fake_base_path_; |
460 int expected_creation_flags_; | 460 int expected_creation_flags_; |
461 scoped_ptr<extensions::ExternalProviderImpl> provider_; | 461 scoped_ptr<extensions::ExternalProviderImpl> provider_; |
462 scoped_ptr<base::DictionaryValue> prefs_; | 462 scoped_ptr<base::DictionaryValue> prefs_; |
(...skipping 20 matching lines...) Expand all Loading... |
483 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | 483 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
484 content::NotificationService::AllSources()); | 484 content::NotificationService::AllSources()); |
485 registrar_.Add( | 485 registrar_.Add( |
486 this, | 486 this, |
487 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, | 487 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, |
488 content::NotificationService::AllSources()); | 488 content::NotificationService::AllSources()); |
489 } | 489 } |
490 | 490 |
491 virtual void Observe(int type, | 491 virtual void Observe(int type, |
492 const content::NotificationSource& source, | 492 const content::NotificationSource& source, |
493 const content::NotificationDetails& details) OVERRIDE { | 493 const content::NotificationDetails& details) override { |
494 switch (type) { | 494 switch (type) { |
495 case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: { | 495 case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: { |
496 const Extension* extension = | 496 const Extension* extension = |
497 content::Details<const Extension>(details).ptr(); | 497 content::Details<const Extension>(details).ptr(); |
498 loaded_.push_back(make_scoped_refptr(extension)); | 498 loaded_.push_back(make_scoped_refptr(extension)); |
499 // The tests rely on the errors being in a certain order, which can vary | 499 // The tests rely on the errors being in a certain order, which can vary |
500 // depending on how filesystem iteration works. | 500 // depending on how filesystem iteration works. |
501 std::stable_sort(loaded_.begin(), loaded_.end(), ExtensionsOrder()); | 501 std::stable_sort(loaded_.begin(), loaded_.end(), ExtensionsOrder()); |
502 break; | 502 break; |
503 } | 503 } |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1148 content::NotificationRegistrar registrar_; | 1148 content::NotificationRegistrar registrar_; |
1149 }; | 1149 }; |
1150 | 1150 |
1151 // Receives notifications from a PackExtensionJob, indicating either that | 1151 // Receives notifications from a PackExtensionJob, indicating either that |
1152 // packing succeeded or that there was some error. | 1152 // packing succeeded or that there was some error. |
1153 class PackExtensionTestClient : public extensions::PackExtensionJob::Client { | 1153 class PackExtensionTestClient : public extensions::PackExtensionJob::Client { |
1154 public: | 1154 public: |
1155 PackExtensionTestClient(const base::FilePath& expected_crx_path, | 1155 PackExtensionTestClient(const base::FilePath& expected_crx_path, |
1156 const base::FilePath& expected_private_key_path); | 1156 const base::FilePath& expected_private_key_path); |
1157 virtual void OnPackSuccess(const base::FilePath& crx_path, | 1157 virtual void OnPackSuccess(const base::FilePath& crx_path, |
1158 const base::FilePath& private_key_path) OVERRIDE; | 1158 const base::FilePath& private_key_path) override; |
1159 virtual void OnPackFailure(const std::string& error_message, | 1159 virtual void OnPackFailure(const std::string& error_message, |
1160 ExtensionCreator::ErrorType type) OVERRIDE; | 1160 ExtensionCreator::ErrorType type) override; |
1161 | 1161 |
1162 private: | 1162 private: |
1163 const base::FilePath expected_crx_path_; | 1163 const base::FilePath expected_crx_path_; |
1164 const base::FilePath expected_private_key_path_; | 1164 const base::FilePath expected_private_key_path_; |
1165 DISALLOW_COPY_AND_ASSIGN(PackExtensionTestClient); | 1165 DISALLOW_COPY_AND_ASSIGN(PackExtensionTestClient); |
1166 }; | 1166 }; |
1167 | 1167 |
1168 PackExtensionTestClient::PackExtensionTestClient( | 1168 PackExtensionTestClient::PackExtensionTestClient( |
1169 const base::FilePath& expected_crx_path, | 1169 const base::FilePath& expected_crx_path, |
1170 const base::FilePath& expected_private_key_path) | 1170 const base::FilePath& expected_private_key_path) |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1459 // TODO(erikkay): add tests for upgrade cases. | 1459 // TODO(erikkay): add tests for upgrade cases. |
1460 } | 1460 } |
1461 | 1461 |
1462 struct MockExtensionRegistryObserver | 1462 struct MockExtensionRegistryObserver |
1463 : public extensions::ExtensionRegistryObserver { | 1463 : public extensions::ExtensionRegistryObserver { |
1464 virtual void OnExtensionWillBeInstalled( | 1464 virtual void OnExtensionWillBeInstalled( |
1465 content::BrowserContext* browser_context, | 1465 content::BrowserContext* browser_context, |
1466 const Extension* extension, | 1466 const Extension* extension, |
1467 bool is_update, | 1467 bool is_update, |
1468 bool from_ephemeral, | 1468 bool from_ephemeral, |
1469 const std::string& old_name) OVERRIDE { | 1469 const std::string& old_name) override { |
1470 last_extension_installed = extension->id(); | 1470 last_extension_installed = extension->id(); |
1471 } | 1471 } |
1472 | 1472 |
1473 virtual void OnExtensionUninstalled( | 1473 virtual void OnExtensionUninstalled( |
1474 content::BrowserContext* browser_context, | 1474 content::BrowserContext* browser_context, |
1475 const Extension* extension, | 1475 const Extension* extension, |
1476 extensions::UninstallReason reason) OVERRIDE { | 1476 extensions::UninstallReason reason) override { |
1477 last_extension_uninstalled = extension->id(); | 1477 last_extension_uninstalled = extension->id(); |
1478 } | 1478 } |
1479 | 1479 |
1480 std::string last_extension_installed; | 1480 std::string last_extension_installed; |
1481 std::string last_extension_uninstalled; | 1481 std::string last_extension_uninstalled; |
1482 }; | 1482 }; |
1483 | 1483 |
1484 // Test that correct notifications are sent to ExtensionRegistryObserver on | 1484 // Test that correct notifications are sent to ExtensionRegistryObserver on |
1485 // extension install and uninstall. | 1485 // extension install and uninstall. |
1486 TEST_F(ExtensionServiceTest, InstallObserverNotified) { | 1486 TEST_F(ExtensionServiceTest, InstallObserverNotified) { |
(...skipping 3640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5127 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, | 5127 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, |
5128 content::NotificationService::AllSources()); | 5128 content::NotificationService::AllSources()); |
5129 } | 5129 } |
5130 | 5130 |
5131 void set_ready(bool value) { ready_ = value; } | 5131 void set_ready(bool value) { ready_ = value; } |
5132 bool ready() { return ready_; } | 5132 bool ready() { return ready_; } |
5133 | 5133 |
5134 private: | 5134 private: |
5135 virtual void Observe(int type, | 5135 virtual void Observe(int type, |
5136 const content::NotificationSource& source, | 5136 const content::NotificationSource& source, |
5137 const content::NotificationDetails& details) OVERRIDE { | 5137 const content::NotificationDetails& details) override { |
5138 switch (type) { | 5138 switch (type) { |
5139 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED: | 5139 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED: |
5140 ready_ = true; | 5140 ready_ = true; |
5141 break; | 5141 break; |
5142 default: | 5142 default: |
5143 NOTREACHED(); | 5143 NOTREACHED(); |
5144 } | 5144 } |
5145 } | 5145 } |
5146 | 5146 |
5147 content::NotificationRegistrar registrar_; | 5147 content::NotificationRegistrar registrar_; |
(...skipping 2001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7149 | 7149 |
7150 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, | 7150 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, |
7151 content::Source<Profile>(profile()), | 7151 content::Source<Profile>(profile()), |
7152 content::NotificationService::NoDetails()); | 7152 content::NotificationService::NoDetails()); |
7153 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); | 7153 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); |
7154 EXPECT_EQ(0u, registry()->enabled_extensions().size()); | 7154 EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
7155 EXPECT_EQ(0u, registry()->disabled_extensions().size()); | 7155 EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
7156 EXPECT_EQ(0u, registry()->terminated_extensions().size()); | 7156 EXPECT_EQ(0u, registry()->terminated_extensions().size()); |
7157 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); | 7157 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
7158 } | 7158 } |
OLD | NEW |