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

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

Issue 7677032: ntp4: make app-install-via-drag less janky (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more test fixes 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 "base/message_loop.h" 5 #include "base/message_loop.h"
6 #include "base/path_service.h" 6 #include "base/path_service.h"
7 #include "base/scoped_temp_dir.h" 7 #include "base/scoped_temp_dir.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 std::string id4_; 571 std::string id4_;
572 }; 572 };
573 TEST_F(ExtensionPrefsIdleInstallInfo, IdleInstallInfo) {} 573 TEST_F(ExtensionPrefsIdleInstallInfo, IdleInstallInfo) {}
574 574
575 class ExtensionPrefsOnExtensionInstalled : public ExtensionPrefsTest { 575 class ExtensionPrefsOnExtensionInstalled : public ExtensionPrefsTest {
576 public: 576 public:
577 virtual void Initialize() { 577 virtual void Initialize() {
578 extension_ = prefs_.AddExtension("on_extension_installed"); 578 extension_ = prefs_.AddExtension("on_extension_installed");
579 EXPECT_FALSE(prefs()->IsExtensionDisabled(extension_->id())); 579 EXPECT_FALSE(prefs()->IsExtensionDisabled(extension_->id()));
580 prefs()->OnExtensionInstalled( 580 prefs()->OnExtensionInstalled(
581 extension_.get(), Extension::DISABLED, false); 581 extension_.get(), Extension::DISABLED, false, 0);
582 } 582 }
583 583
584 virtual void Verify() { 584 virtual void Verify() {
585 EXPECT_TRUE(prefs()->IsExtensionDisabled(extension_->id())); 585 EXPECT_TRUE(prefs()->IsExtensionDisabled(extension_->id()));
586 } 586 }
587 587
588 private: 588 private:
589 scoped_refptr<Extension> extension_; 589 scoped_refptr<Extension> extension_;
590 }; 590 };
591 TEST_F(ExtensionPrefsOnExtensionInstalled, 591 TEST_F(ExtensionPrefsOnExtensionInstalled,
592 ExtensionPrefsOnExtensionInstalled) {} 592 ExtensionPrefsOnExtensionInstalled) {}
593 593
594 class ExtensionPrefsAppLaunchIndex : public ExtensionPrefsTest { 594 class ExtensionPrefsAppLaunchIndex : public ExtensionPrefsTest {
595 public: 595 public:
596 virtual void Initialize() { 596 virtual void Initialize() {
597 // No extensions yet. 597 // No extensions yet.
598 EXPECT_EQ(0, prefs()->GetNextAppLaunchIndex()); 598 EXPECT_EQ(0, prefs()->GetNextAppLaunchIndex(0));
599 599
600 extension_ = prefs_.AddExtension("on_extension_installed"); 600 extension_ = prefs_.AddExtension("on_extension_installed");
601 EXPECT_FALSE(prefs()->IsExtensionDisabled(extension_->id())); 601 EXPECT_FALSE(prefs()->IsExtensionDisabled(extension_->id()));
602 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, false); 602 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED,
603 false, 0);
603 } 604 }
604 605
605 virtual void Verify() { 606 virtual void Verify() {
606 int launch_index = prefs()->GetAppLaunchIndex(extension_->id()); 607 int launch_index = prefs()->GetAppLaunchIndex(extension_->id());
607 // Extension should have been assigned a launch index > 0. 608 // Extension should have been assigned a launch index > 0.
608 EXPECT_GT(launch_index, 0); 609 EXPECT_GT(launch_index, 0);
609 EXPECT_EQ(launch_index + 1, prefs()->GetNextAppLaunchIndex()); 610 EXPECT_EQ(launch_index + 1, prefs()->GetNextAppLaunchIndex(0));
610 // Set a new launch index of one higher and verify. 611 // Set a new launch index of one higher and verify.
611 prefs()->SetAppLaunchIndex(extension_->id(), 612 prefs()->SetAppLaunchIndex(extension_->id(),
612 prefs()->GetNextAppLaunchIndex()); 613 prefs()->GetNextAppLaunchIndex(0));
613 int new_launch_index = prefs()->GetAppLaunchIndex(extension_->id()); 614 int new_launch_index = prefs()->GetAppLaunchIndex(extension_->id());
614 EXPECT_EQ(launch_index + 1, new_launch_index); 615 EXPECT_EQ(launch_index + 1, new_launch_index);
615 616
616 // This extension doesn't exist, so it should return -1. 617 // This extension doesn't exist, so it should return -1.
617 EXPECT_EQ(-1, prefs()->GetAppLaunchIndex("foo")); 618 EXPECT_EQ(-1, prefs()->GetAppLaunchIndex("foo"));
619
620 // The second page doesn't have any apps so its next launch index should
621 // still be 0.
622 EXPECT_EQ(prefs()->GetNextAppLaunchIndex(1), 0);
618 } 623 }
619 624
620 private: 625 private:
621 scoped_refptr<Extension> extension_; 626 scoped_refptr<Extension> extension_;
622 }; 627 };
623 TEST_F(ExtensionPrefsAppLaunchIndex, ExtensionPrefsAppLaunchIndex) {} 628 TEST_F(ExtensionPrefsAppLaunchIndex, ExtensionPrefsAppLaunchIndex) {}
624 629
625 class ExtensionPrefsPageIndex : public ExtensionPrefsTest { 630 class ExtensionPrefsPageIndex : public ExtensionPrefsTest {
626 public: 631 public:
627 virtual void Initialize() { 632 virtual void Initialize() {
628 extension_id_ = prefs_.AddExtensionAndReturnId("page_index"); 633 extension_ = prefs_.AddExtension("page_index");
629 634 // Install to page 3 (index 2).
630 int page_index = prefs()->GetPageIndex(extension_id_); 635 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED,
631 // Extension should not have been assigned a page 636 false, 2);
632 EXPECT_EQ(page_index, -1); 637 EXPECT_EQ(2, prefs()->GetPageIndex(extension_->id()));
633
634 // Set the page index
635 prefs()->SetPageIndex(extension_id_, 2);
636 } 638 }
637 639
638 virtual void Verify() { 640 virtual void Verify() {
641 // Set the page index.
642 prefs()->SetPageIndex(extension_->id(), 1);
639 // Verify the page index. 643 // Verify the page index.
640 int page_index = prefs()->GetPageIndex(extension_id_); 644 EXPECT_EQ(1, prefs()->GetPageIndex(extension_->id()));
641 EXPECT_EQ(page_index, 2);
642 645
643 // This extension doesn't exist, so it should return -1. 646 // This extension doesn't exist, so it should return -1.
644 EXPECT_EQ(-1, prefs()->GetPageIndex("foo")); 647 EXPECT_EQ(-1, prefs()->GetPageIndex("foo"));
645 } 648 }
646 649
647 private: 650 private:
648 std::string extension_id_; 651 scoped_refptr<Extension> extension_;
649 }; 652 };
650 TEST_F(ExtensionPrefsPageIndex, ExtensionPrefsPageIndex) {} 653 TEST_F(ExtensionPrefsPageIndex, ExtensionPrefsPageIndex) {}
651 654
652 class ExtensionPrefsAppDraggedByUser : public ExtensionPrefsTest { 655 class ExtensionPrefsAppDraggedByUser : public ExtensionPrefsTest {
653 public: 656 public:
654 virtual void Initialize() { 657 virtual void Initialize() {
655 extension_ = prefs_.AddExtension("on_extension_installed"); 658 extension_ = prefs_.AddExtension("on_extension_installed");
656 EXPECT_FALSE(prefs()->WasAppDraggedByUser(extension_->id())); 659 EXPECT_FALSE(prefs()->WasAppDraggedByUser(extension_->id()));
657 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, false); 660 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED,
661 false, 0);
658 } 662 }
659 663
660 virtual void Verify() { 664 virtual void Verify() {
661 // Set the flag and see if it persisted. 665 // Set the flag and see if it persisted.
662 prefs()->SetAppDraggedByUser(extension_->id()); 666 prefs()->SetAppDraggedByUser(extension_->id());
663 EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id())); 667 EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id()));
664 668
665 // Make sure it doesn't change on consecutive calls. 669 // Make sure it doesn't change on consecutive calls.
666 prefs()->SetAppDraggedByUser(extension_->id()); 670 prefs()->SetAppDraggedByUser(extension_->id());
667 EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id())); 671 EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id()));
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 801
798 // Flags indicating whether each of the extensions has been installed, yet. 802 // Flags indicating whether each of the extensions has been installed, yet.
799 bool installed[3]; 803 bool installed[3];
800 804
801 private: 805 private:
802 void EnsureExtensionInstalled(Extension *ext) { 806 void EnsureExtensionInstalled(Extension *ext) {
803 // Install extension the first time a preference is set for it. 807 // Install extension the first time a preference is set for it.
804 Extension* extensions[] = {ext1_, ext2_, ext3_}; 808 Extension* extensions[] = {ext1_, ext2_, ext3_};
805 for (int i = 0; i < 3; ++i) { 809 for (int i = 0; i < 3; ++i) {
806 if (ext == extensions[i] && !installed[i]) { 810 if (ext == extensions[i] && !installed[i]) {
807 prefs()->OnExtensionInstalled(ext, Extension::ENABLED, false); 811 prefs()->OnExtensionInstalled(ext, Extension::ENABLED, false, 0);
808 installed[i] = true; 812 installed[i] = true;
809 break; 813 break;
810 } 814 }
811 } 815 }
812 } 816 }
813 817
814 void EnsureExtensionUninstalled(const std::string& extension_id) { 818 void EnsureExtensionUninstalled(const std::string& extension_id) {
815 Extension* extensions[] = {ext1_, ext2_, ext3_}; 819 Extension* extensions[] = {ext1_, ext2_, ext3_};
816 for (int i = 0; i < 3; ++i) { 820 for (int i = 0; i < 3; ++i) {
817 if (extensions[i]->id() == extension_id) { 821 if (extensions[i]->id() == extension_id) {
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 testing::Mock::VerifyAndClearExpectations(v1i); 1069 testing::Mock::VerifyAndClearExpectations(v1i);
1066 testing::Mock::VerifyAndClearExpectations(v2); 1070 testing::Mock::VerifyAndClearExpectations(v2);
1067 testing::Mock::VerifyAndClearExpectations(v2i); 1071 testing::Mock::VerifyAndClearExpectations(v2i);
1068 } 1072 }
1069 1073
1070 virtual void Verify() { 1074 virtual void Verify() {
1071 } 1075 }
1072 }; 1076 };
1073 TEST_F(ExtensionPrefsSetExtensionControlledPref, 1077 TEST_F(ExtensionPrefsSetExtensionControlledPref,
1074 ExtensionPrefsSetExtensionControlledPref) {} 1078 ExtensionPrefsSetExtensionControlledPref) {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698