| Index: chrome/browser/profile_resetter/profile_resetter_unittest.cc
|
| diff --git a/chrome/browser/profile_resetter/profile_resetter_unittest.cc b/chrome/browser/profile_resetter/profile_resetter_unittest.cc
|
| index face781b2e9ac52544cf3ada521ff38117ec737b..75f2a6551bb61f2543fdf1cd5e524ff6053c1d39 100644
|
| --- a/chrome/browser/profile_resetter/profile_resetter_unittest.cc
|
| +++ b/chrome/browser/profile_resetter/profile_resetter_unittest.cc
|
| @@ -7,14 +7,18 @@
|
| #include "base/bind.h"
|
| #include "base/prefs/pref_service.h"
|
| #include "chrome/browser/extensions/extension_service_unittest.h"
|
| +#include "chrome/browser/extensions/tab_helper.h"
|
| #include "chrome/browser/prefs/session_startup_pref.h"
|
| #include "chrome/browser/search_engines/template_url_service_test_util.h"
|
| #include "chrome/browser/themes/theme_service.h"
|
| #include "chrome/browser/themes/theme_service_factory.h"
|
| +#include "chrome/browser/ui/tabs/tab_strip_model.h"
|
| #include "chrome/common/extensions/extension.h"
|
| #include "chrome/common/extensions/extension_manifest_constants.h"
|
| #include "chrome/common/pref_names.h"
|
| +#include "chrome/test/base/browser_with_test_window_test.h"
|
| #include "chrome/test/base/testing_profile.h"
|
| +#include "content/public/browser/web_contents.h"
|
| #include "content/public/test/test_utils.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
|
|
| @@ -43,26 +47,32 @@ class MockObject {
|
| scoped_refptr<content::MessageLoopRunner> runner_;
|
| };
|
|
|
| -class ProfileResetterTest : public testing::Test {
|
| +class ProfileResetterTestBase {
|
| + public:
|
| + ProfileResetterTestBase();
|
| + ~ProfileResetterTestBase();
|
| protected:
|
| - ProfileResetterTest();
|
| - ~ProfileResetterTest();
|
| + testing::StrictMock<MockObject> mock_object_;
|
| + scoped_ptr<ProfileResetter> resetter_;
|
|
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(ProfileResetterTestBase);
|
| +};
|
| +
|
| +ProfileResetterTestBase::ProfileResetterTestBase() {}
|
| +
|
| +ProfileResetterTestBase::~ProfileResetterTestBase() {}
|
| +
|
| +class ProfileResetterTest : public testing::Test,
|
| + public ProfileResetterTestBase {
|
| + protected:
|
| // testing::Test:
|
| virtual void SetUp() OVERRIDE;
|
| virtual void TearDown() OVERRIDE;
|
|
|
| - testing::StrictMock<MockObject> mock_object_;
|
| TemplateURLServiceTestUtil test_util_;
|
| - scoped_ptr<ProfileResetter> resetter_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(ProfileResetterTest);
|
| };
|
|
|
| -ProfileResetterTest::ProfileResetterTest() {}
|
| -
|
| -ProfileResetterTest::~ProfileResetterTest() {}
|
| -
|
| void ProfileResetterTest::SetUp() {
|
| test_util_.SetUp();
|
| resetter_.reset(new ProfileResetter(test_util_.profile()));
|
| @@ -73,12 +83,10 @@ void ProfileResetterTest::TearDown() {
|
| }
|
|
|
| // ExtensionsResetTest sets up the extension service.
|
| -class ExtensionsResetTest : public ExtensionServiceTestBase {
|
| +class ExtensionsResetTest : public ExtensionServiceTestBase,
|
| + public ProfileResetterTestBase {
|
| protected:
|
| virtual void SetUp() OVERRIDE;
|
| -
|
| - testing::StrictMock<MockObject> mock_object_;
|
| - scoped_ptr<ProfileResetter> resetter_;
|
| };
|
|
|
| void ExtensionsResetTest::SetUp() {
|
| @@ -97,6 +105,7 @@ scoped_refptr<Extension> CreateExtension(const std::string& name,
|
| DictionaryValue manifest;
|
| manifest.SetString(extension_manifest_keys::kVersion, "1.0.0.0");
|
| manifest.SetString(extension_manifest_keys::kName, name);
|
| + manifest.SetString("app.launch.web_url", "http://www.google.com");
|
| if (theme)
|
| manifest.Set(extension_manifest_keys::kTheme, new DictionaryValue());
|
| std::string error;
|
| @@ -110,11 +119,29 @@ scoped_refptr<Extension> CreateExtension(const std::string& name,
|
| return extension;
|
| }
|
|
|
| +class PinnedTabsResetTest : public BrowserWithTestWindowTest,
|
| + public ProfileResetterTestBase {
|
| + protected:
|
| + virtual void SetUp() OVERRIDE;
|
| +
|
| + content::WebContents* CreateWebContents();
|
| +};
|
| +
|
| +void PinnedTabsResetTest::SetUp() {
|
| + BrowserWithTestWindowTest::SetUp();
|
| + resetter_.reset(new ProfileResetter(profile()));
|
| +}
|
| +
|
| +content::WebContents* PinnedTabsResetTest::CreateWebContents() {
|
| + return content::WebContents::Create(
|
| + content::WebContents::CreateParams(profile()));
|
| +}
|
| +
|
| +/********************* Tests *********************/
|
|
|
| TEST_F(ProfileResetterTest, ResetDefaultSearchEngine) {
|
| resetter_->Reset(
|
| ProfileResetter::DEFAULT_SEARCH_ENGINE,
|
| - ProfileResetter::DISABLE_EXTENSIONS,
|
| base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_)));
|
| mock_object_.RunLoop();
|
| }
|
| @@ -128,7 +155,6 @@ TEST_F(ProfileResetterTest, ResetHomepage) {
|
|
|
| resetter_->Reset(
|
| ProfileResetter::HOMEPAGE,
|
| - ProfileResetter::DISABLE_EXTENSIONS,
|
| base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_)));
|
| mock_object_.RunLoop();
|
|
|
| @@ -140,7 +166,6 @@ TEST_F(ProfileResetterTest, ResetHomepage) {
|
| TEST_F(ProfileResetterTest, ResetContentSettings) {
|
| resetter_->Reset(
|
| ProfileResetter::CONTENT_SETTINGS,
|
| - ProfileResetter::DISABLE_EXTENSIONS,
|
| base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_)));
|
| mock_object_.RunLoop();
|
| }
|
| @@ -148,7 +173,6 @@ TEST_F(ProfileResetterTest, ResetContentSettings) {
|
| TEST_F(ProfileResetterTest, ResetCookiesAndSiteData) {
|
| resetter_->Reset(
|
| ProfileResetter::COOKIES_AND_SITE_DATA,
|
| - ProfileResetter::DISABLE_EXTENSIONS,
|
| base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_)));
|
| mock_object_.RunLoop();
|
| }
|
| @@ -194,7 +218,6 @@ TEST_F(ExtensionsResetTest, ResetExtensionsByDisabling) {
|
|
|
| resetter_->Reset(
|
| ProfileResetter::EXTENSIONS,
|
| - ProfileResetter::DISABLE_EXTENSIONS,
|
| base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_)));
|
| mock_object_.RunLoop();
|
|
|
| @@ -216,8 +239,7 @@ TEST_F(ProfileResetterTest, ResetStartPage) {
|
| SessionStartupPref::SetStartupPref(prefs, startup_pref);
|
|
|
| resetter_->Reset(
|
| - ProfileResetter::STARTUP_PAGE,
|
| - ProfileResetter::DISABLE_EXTENSIONS,
|
| + ProfileResetter::STARTUP_PAGES,
|
| base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_)));
|
| mock_object_.RunLoop();
|
|
|
| @@ -226,11 +248,50 @@ TEST_F(ProfileResetterTest, ResetStartPage) {
|
| EXPECT_EQ(std::vector<GURL>(), startup_pref.urls);
|
| }
|
|
|
| +TEST_F(PinnedTabsResetTest, ResetPinnedTabs) {
|
| + scoped_refptr<Extension> extension_app = CreateExtension(
|
| + "hello!",
|
| + base::FilePath(FILE_PATH_LITERAL("//nonexistent")),
|
| + Manifest::INVALID_LOCATION,
|
| + false);
|
| + content::WebContents* contents1 = CreateWebContents();
|
| + extensions::TabHelper::CreateForWebContents(contents1);
|
| + extensions::TabHelper::FromWebContents(contents1)->
|
| + SetExtensionApp(extension_app.get());
|
| + content::WebContents* contents2 = CreateWebContents();
|
| + content::WebContents* contents3 = CreateWebContents();
|
| + content::WebContents* contents4 = CreateWebContents();
|
| + TabStripModel* tab_strip_model = browser()->tab_strip_model();
|
| +
|
| + tab_strip_model->AppendWebContents(contents4, true);
|
| + tab_strip_model->AppendWebContents(contents3, true);
|
| + tab_strip_model->AppendWebContents(contents2, true);
|
| + tab_strip_model->SetTabPinned(2, true);
|
| + tab_strip_model->AppendWebContents(contents1, true);
|
| + tab_strip_model->SetTabPinned(3, true);
|
| +
|
| + EXPECT_EQ(contents2, tab_strip_model->GetWebContentsAt(0));
|
| + EXPECT_EQ(contents1, tab_strip_model->GetWebContentsAt(1));
|
| + EXPECT_EQ(contents3, tab_strip_model->GetWebContentsAt(2));
|
| + EXPECT_EQ(contents4, tab_strip_model->GetWebContentsAt(3));
|
| + EXPECT_EQ(3, tab_strip_model->IndexOfFirstNonMiniTab());
|
| +
|
| + resetter_->Reset(
|
| + ProfileResetter::PINNED_TABS,
|
| + base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_)));
|
| + mock_object_.RunLoop();
|
| +
|
| + EXPECT_EQ(contents1, tab_strip_model->GetWebContentsAt(0));
|
| + EXPECT_EQ(contents2, tab_strip_model->GetWebContentsAt(1));
|
| + EXPECT_EQ(contents3, tab_strip_model->GetWebContentsAt(2));
|
| + EXPECT_EQ(contents4, tab_strip_model->GetWebContentsAt(3));
|
| + EXPECT_EQ(1, tab_strip_model->IndexOfFirstNonMiniTab());
|
| +}
|
| +
|
| TEST_F(ProfileResetterTest, ResetFewFlags) {
|
| // mock_object_ is a StrictMock, so we verify that it is called only once.
|
| resetter_->Reset(
|
| ProfileResetter::DEFAULT_SEARCH_ENGINE | ProfileResetter::HOMEPAGE,
|
| - ProfileResetter::DISABLE_EXTENSIONS,
|
| base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_)));
|
| mock_object_.RunLoop();
|
| }
|
|
|