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

Unified Diff: chrome/browser/profile_resetter/profile_resetter_unittest.cc

Issue 16980002: Reset profile: unpin all pinned tabs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clean up all the checkboxes Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
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 67030a7ea895e227e3211097698d187eca5ccfa9..8127d75e676c66c4eec8c2e3da3c941c6417606e 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();
}
@@ -164,12 +188,10 @@ TEST_F(ExtensionsResetTest, ResetExtensionsByDisabling) {
// Let ThemeService finish creating the theme pack.
base::MessageLoop::current()->RunUntilIdle();
-#if !defined(OS_ANDROID)
// ThemeService isn't compiled for Android.
ThemeService* theme_service =
ThemeServiceFactory::GetForProfile(profile_.get());
EXPECT_FALSE(theme_service->UsingDefaultTheme());
-#endif
scoped_refptr<Extension> ext2 = CreateExtension(
"example2",
@@ -194,16 +216,13 @@ TEST_F(ExtensionsResetTest, ResetExtensionsByDisabling) {
resetter_->Reset(
ProfileResetter::EXTENSIONS,
- ProfileResetter::DISABLE_EXTENSIONS,
base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_)));
mock_object_.RunLoop();
EXPECT_EQ(2u, service_->extensions()->size());
EXPECT_TRUE(service_->extensions()->Contains(ext3->id()));
EXPECT_TRUE(service_->extensions()->Contains(ext4->id()));
-#if !defined(OS_ANDROID)
EXPECT_TRUE(theme_service->UsingDefaultTheme());
-#endif
}
TEST_F(ProfileResetterTest, ResetStartPage) {
@@ -216,8 +235,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 +244,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();
}

Powered by Google App Engine
This is Rietveld 408576698