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

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

Issue 12212047: Linux/ChromeOS Chromium style checker cleanup, chrome/browser/extensions edition. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 7 years, 10 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) 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 "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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 provider_->VisitRegisteredExtension(); 311 provider_->VisitRegisteredExtension();
312 312
313 return ids_found_; 313 return ids_found_;
314 } 314 }
315 315
316 virtual bool OnExternalExtensionFileFound(const std::string& id, 316 virtual bool OnExternalExtensionFileFound(const std::string& id,
317 const Version* version, 317 const Version* version,
318 const FilePath& path, 318 const FilePath& path,
319 Manifest::Location unused, 319 Manifest::Location unused,
320 int creation_flags, 320 int creation_flags,
321 bool mark_acknowledged) { 321 bool mark_acknowledged) OVERRIDE {
322 EXPECT_EQ(expected_creation_flags_, creation_flags); 322 EXPECT_EQ(expected_creation_flags_, creation_flags);
323 323
324 ++ids_found_; 324 ++ids_found_;
325 DictionaryValue* pref; 325 DictionaryValue* pref;
326 // This tests is to make sure that the provider only notifies us of the 326 // This tests is to make sure that the provider only notifies us of the
327 // values we gave it. So if the id we doesn't exist in our internal 327 // values we gave it. So if the id we doesn't exist in our internal
328 // dictionary then something is wrong. 328 // dictionary then something is wrong.
329 EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) 329 EXPECT_TRUE(prefs_->GetDictionary(id, &pref))
330 << "Got back ID (" << id.c_str() << ") we weren't expecting"; 330 << "Got back ID (" << id.c_str() << ") we weren't expecting";
331 331
(...skipping 19 matching lines...) Expand all
351 EXPECT_EQ(Manifest::EXTERNAL_PREF, location); 351 EXPECT_EQ(Manifest::EXTERNAL_PREF, location);
352 352
353 // Remove it so we won't count it ever again. 353 // Remove it so we won't count it ever again.
354 prefs_->Remove(id, NULL); 354 prefs_->Remove(id, NULL);
355 } 355 }
356 return true; 356 return true;
357 } 357 }
358 358
359 virtual bool OnExternalExtensionUpdateUrlFound( 359 virtual bool OnExternalExtensionUpdateUrlFound(
360 const std::string& id, const GURL& update_url, 360 const std::string& id, const GURL& update_url,
361 Manifest::Location location) { 361 Manifest::Location location) OVERRIDE {
362 ++ids_found_; 362 ++ids_found_;
363 DictionaryValue* pref; 363 DictionaryValue* pref;
364 // This tests is to make sure that the provider only notifies us of the 364 // This tests is to make sure that the provider only notifies us of the
365 // values we gave it. So if the id we doesn't exist in our internal 365 // values we gave it. So if the id we doesn't exist in our internal
366 // dictionary then something is wrong. 366 // dictionary then something is wrong.
367 EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) 367 EXPECT_TRUE(prefs_->GetDictionary(id, &pref))
368 << L"Got back ID (" << id.c_str() << ") we weren't expecting"; 368 << L"Got back ID (" << id.c_str() << ") we weren't expecting";
369 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location); 369 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location);
370 370
371 if (pref) { 371 if (pref) {
372 EXPECT_TRUE(provider_->HasExtension(id)); 372 EXPECT_TRUE(provider_->HasExtension(id));
373 373
374 // External extensions with update URLs do not have versions. 374 // External extensions with update URLs do not have versions.
375 scoped_ptr<Version> v1; 375 scoped_ptr<Version> v1;
376 Manifest::Location location1 = Manifest::INVALID_LOCATION; 376 Manifest::Location location1 = Manifest::INVALID_LOCATION;
377 EXPECT_TRUE(provider_->GetExtensionDetails(id, &location1, &v1)); 377 EXPECT_TRUE(provider_->GetExtensionDetails(id, &location1, &v1));
378 EXPECT_FALSE(v1.get()); 378 EXPECT_FALSE(v1.get());
379 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location1); 379 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location1);
380 380
381 // Remove it so we won't count it again. 381 // Remove it so we won't count it again.
382 prefs_->Remove(id, NULL); 382 prefs_->Remove(id, NULL);
383 } 383 }
384 return true; 384 return true;
385 } 385 }
386 386
387 virtual void OnExternalProviderReady( 387 virtual void OnExternalProviderReady(
388 const extensions::ExternalProviderInterface* provider) { 388 const extensions::ExternalProviderInterface* provider) OVERRIDE {
389 EXPECT_EQ(provider, provider_.get()); 389 EXPECT_EQ(provider, provider_.get());
390 EXPECT_TRUE(provider->IsReady()); 390 EXPECT_TRUE(provider->IsReady());
391 } 391 }
392 392
393 private: 393 private:
394 int ids_found_; 394 int ids_found_;
395 FilePath fake_base_path_; 395 FilePath fake_base_path_;
396 int expected_creation_flags_; 396 int expected_creation_flags_;
397 scoped_ptr<extensions::ExternalProviderImpl> provider_; 397 scoped_ptr<extensions::ExternalProviderImpl> provider_;
398 scoped_ptr<DictionaryValue> prefs_; 398 scoped_ptr<DictionaryValue> prefs_;
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 555 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
556 content::NotificationService::AllSources()); 556 content::NotificationService::AllSources());
557 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 557 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
558 content::NotificationService::AllSources()); 558 content::NotificationService::AllSources());
559 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, 559 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED,
560 content::NotificationService::AllSources()); 560 content::NotificationService::AllSources());
561 } 561 }
562 562
563 virtual void Observe(int type, 563 virtual void Observe(int type,
564 const content::NotificationSource& source, 564 const content::NotificationSource& source,
565 const content::NotificationDetails& details) { 565 const content::NotificationDetails& details) OVERRIDE {
566 switch (type) { 566 switch (type) {
567 case chrome::NOTIFICATION_EXTENSION_LOADED: { 567 case chrome::NOTIFICATION_EXTENSION_LOADED: {
568 const Extension* extension = 568 const Extension* extension =
569 content::Details<const Extension>(details).ptr(); 569 content::Details<const Extension>(details).ptr();
570 loaded_.push_back(make_scoped_refptr(extension)); 570 loaded_.push_back(make_scoped_refptr(extension));
571 // The tests rely on the errors being in a certain order, which can vary 571 // The tests rely on the errors being in a certain order, which can vary
572 // depending on how filesystem iteration works. 572 // depending on how filesystem iteration works.
573 std::stable_sort(loaded_.begin(), loaded_.end(), ExtensionsOrder()); 573 std::stable_sort(loaded_.begin(), loaded_.end(), ExtensionsOrder());
574 break; 574 break;
575 } 575 }
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 content::NotificationRegistrar registrar_; 1056 content::NotificationRegistrar registrar_;
1057 }; 1057 };
1058 1058
1059 // Receives notifications from a PackExtensionJob, indicating either that 1059 // Receives notifications from a PackExtensionJob, indicating either that
1060 // packing succeeded or that there was some error. 1060 // packing succeeded or that there was some error.
1061 class PackExtensionTestClient : public extensions::PackExtensionJob::Client { 1061 class PackExtensionTestClient : public extensions::PackExtensionJob::Client {
1062 public: 1062 public:
1063 PackExtensionTestClient(const FilePath& expected_crx_path, 1063 PackExtensionTestClient(const FilePath& expected_crx_path,
1064 const FilePath& expected_private_key_path); 1064 const FilePath& expected_private_key_path);
1065 virtual void OnPackSuccess(const FilePath& crx_path, 1065 virtual void OnPackSuccess(const FilePath& crx_path,
1066 const FilePath& private_key_path); 1066 const FilePath& private_key_path) OVERRIDE;
1067 virtual void OnPackFailure(const std::string& error_message, 1067 virtual void OnPackFailure(const std::string& error_message,
1068 ExtensionCreator::ErrorType type); 1068 ExtensionCreator::ErrorType type) OVERRIDE;
1069 1069
1070 private: 1070 private:
1071 const FilePath expected_crx_path_; 1071 const FilePath expected_crx_path_;
1072 const FilePath expected_private_key_path_; 1072 const FilePath expected_private_key_path_;
1073 DISALLOW_COPY_AND_ASSIGN(PackExtensionTestClient); 1073 DISALLOW_COPY_AND_ASSIGN(PackExtensionTestClient);
1074 }; 1074 };
1075 1075
1076 PackExtensionTestClient::PackExtensionTestClient( 1076 PackExtensionTestClient::PackExtensionTestClient(
1077 const FilePath& expected_crx_path, 1077 const FilePath& expected_crx_path,
1078 const FilePath& expected_private_key_path) 1078 const FilePath& expected_private_key_path)
(...skipping 3441 matching lines...) Expand 10 before | Expand all | Expand 10 after
4520 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, 4520 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY,
4521 content::NotificationService::AllSources()); 4521 content::NotificationService::AllSources());
4522 } 4522 }
4523 4523
4524 void set_ready(bool value) { ready_ = value; } 4524 void set_ready(bool value) { ready_ = value; }
4525 bool ready() { return ready_; } 4525 bool ready() { return ready_; }
4526 4526
4527 private: 4527 private:
4528 virtual void Observe(int type, 4528 virtual void Observe(int type,
4529 const content::NotificationSource& source, 4529 const content::NotificationSource& source,
4530 const content::NotificationDetails& details) { 4530 const content::NotificationDetails& details) OVERRIDE {
4531 switch (type) { 4531 switch (type) {
4532 case chrome::NOTIFICATION_EXTENSIONS_READY: 4532 case chrome::NOTIFICATION_EXTENSIONS_READY:
4533 ready_ = true; 4533 ready_ = true;
4534 break; 4534 break;
4535 default: 4535 default:
4536 NOTREACHED(); 4536 NOTREACHED();
4537 } 4537 }
4538 } 4538 }
4539 4539
4540 content::NotificationRegistrar registrar_; 4540 content::NotificationRegistrar registrar_;
(...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after
5559 ASSERT_EQ(1u, service_->extensions()->size()); 5559 ASSERT_EQ(1u, service_->extensions()->size());
5560 EXPECT_EQ(test_id, extension->id()); 5560 EXPECT_EQ(test_id, extension->id());
5561 } 5561 }
5562 5562
5563 // Test that when multiple sources try to install an extension, 5563 // Test that when multiple sources try to install an extension,
5564 // we consistently choose the right one. To make tests easy to read, 5564 // we consistently choose the right one. To make tests easy to read,
5565 // methods that fake requests to install crx files in several ways 5565 // methods that fake requests to install crx files in several ways
5566 // are provided. 5566 // are provided.
5567 class ExtensionSourcePriorityTest : public ExtensionServiceTest { 5567 class ExtensionSourcePriorityTest : public ExtensionServiceTest {
5568 public: 5568 public:
5569 void SetUp() { 5569 virtual void SetUp() {
5570 ExtensionServiceTest::SetUp(); 5570 ExtensionServiceTest::SetUp();
5571 5571
5572 // All tests use a single extension. Put the id and path in member vars 5572 // All tests use a single extension. Put the id and path in member vars
5573 // that all methods can read. 5573 // that all methods can read.
5574 crx_id_ = kGoodId; 5574 crx_id_ = kGoodId;
5575 crx_path_ = data_dir_.AppendASCII("good.crx"); 5575 crx_path_ = data_dir_.AppendASCII("good.crx");
5576 } 5576 }
5577 5577
5578 // Fake an external source adding a URL to fetch an extension from. 5578 // Fake an external source adding a URL to fetch an extension from.
5579 bool AddPendingExternalPrefUrl() { 5579 bool AddPendingExternalPrefUrl() {
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
5839 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); 5839 EXPECT_FALSE(extensions::HasExternalInstallError(service_));
5840 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); 5840 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx));
5841 EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); 5841 EXPECT_TRUE(service_->IsExtensionEnabled(page_action));
5842 5842
5843 ExtensionPrefs* prefs = service_->extension_prefs(); 5843 ExtensionPrefs* prefs = service_->extension_prefs();
5844 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) & 5844 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) &
5845 Extension::DISABLE_SIDELOAD_WIPEOUT); 5845 Extension::DISABLE_SIDELOAD_WIPEOUT);
5846 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) & 5846 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) &
5847 Extension::DISABLE_SIDELOAD_WIPEOUT); 5847 Extension::DISABLE_SIDELOAD_WIPEOUT);
5848 } 5848 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_resource_protocols.cc ('k') | chrome/browser/extensions/extension_sorting_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698