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

Side by Side Diff: chrome/browser/profile_resetter/profile_resetter_unittest.cc

Issue 15654005: Reset homepage and startup pages (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed ResetStartPage, default startup page is different on CrOS Created 7 years, 7 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
« no previous file with comments | « chrome/browser/profile_resetter/profile_resetter.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/browser/profile_resetter/profile_resetter.h" 5 #include "chrome/browser/profile_resetter/profile_resetter.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/message_loop.h" 9 #include "chrome/browser/prefs/session_startup_pref.h"
10 #include "content/public/test/test_browser_thread.h" 10 #include "chrome/browser/search_engines/template_url_service_test_util.h"
11 #include "chrome/common/pref_names.h"
12 #include "chrome/test/base/testing_profile.h"
13 #include "content/public/test/test_utils.h"
11 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
12 15
13 namespace { 16 namespace {
14 17
15 class MockObject { 18 class MockObject {
16 public: 19 public:
20 void RunLoop() {
21 EXPECT_CALL(*this, Callback());
22 runner_ = new content::MessageLoopRunner;
23 runner_->Run();
24 }
25
26 void StopLoop() {
27 DCHECK(runner_);
28 Callback();
29 runner_->Quit();
30 }
31
32 private:
17 MOCK_METHOD0(Callback, void(void)); 33 MOCK_METHOD0(Callback, void(void));
34
35 scoped_refptr<content::MessageLoopRunner> runner_;
18 }; 36 };
19 37
20 class ProfileResetterTest : public testing::Test { 38 class ProfileResetterTest : public testing::Test {
21 public: 39 protected:
22 ProfileResetterTest() 40 ProfileResetterTest();
23 : ui_thread_(content::BrowserThread::UI, &message_loop_), 41 ~ProfileResetterTest();
24 resetter_(NULL) {} 42 // testing::Test:
43 virtual void SetUp() OVERRIDE;
44 virtual void TearDown() OVERRIDE;
25 45
26 ~ProfileResetterTest() {} 46 testing::StrictMock<MockObject> mock_object_;
47 TemplateURLServiceTestUtil test_util_;
48 scoped_ptr<ProfileResetter> resetter_;
27 49
28 private: 50 DISALLOW_COPY_AND_ASSIGN(ProfileResetterTest);
29 base::MessageLoopForUI message_loop_;
30 content::TestBrowserThread ui_thread_;
31
32 protected:
33 testing::StrictMock<MockObject> mock_object_;
34 ProfileResetter resetter_;
35 }; 51 };
36 52
53 ProfileResetterTest::ProfileResetterTest() {}
54
55 ProfileResetterTest::~ProfileResetterTest() {}
56
57 void ProfileResetterTest::SetUp() {
58 test_util_.SetUp();
59 resetter_.reset(new ProfileResetter(test_util_.profile()));
60 }
61
62 void ProfileResetterTest::TearDown() {
63 test_util_.TearDown();
64 }
65
37 TEST_F(ProfileResetterTest, ResetDefaultSearchEngine) { 66 TEST_F(ProfileResetterTest, ResetDefaultSearchEngine) {
38 EXPECT_CALL(mock_object_, Callback()); 67 test_util_.VerifyLoad();
39 resetter_.Reset( 68 resetter_->Reset(
40 ProfileResetter::DEFAULT_SEARCH_ENGINE, 69 ProfileResetter::DEFAULT_SEARCH_ENGINE,
41 ProfileResetter::DISABLE_EXTENSIONS, 70 ProfileResetter::DISABLE_EXTENSIONS,
42 base::Bind(&MockObject::Callback, base::Unretained(&mock_object_))); 71 base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_)));
72 mock_object_.RunLoop();
43 } 73 }
44 74
45 TEST_F(ProfileResetterTest, ResetHomepage) { 75 TEST_F(ProfileResetterTest, ResetHomepage) {
46 EXPECT_CALL(mock_object_, Callback()); 76 PrefService* prefs = test_util_.profile()->GetPrefs();
47 resetter_.Reset( 77 DCHECK(prefs);
78 prefs->SetBoolean(prefs::kHomePageIsNewTabPage, false);
79 prefs->SetString(prefs::kHomePage, "http://google.com");
80 prefs->SetBoolean(prefs::kShowHomeButton, true);
81
82 resetter_->Reset(
48 ProfileResetter::HOMEPAGE, 83 ProfileResetter::HOMEPAGE,
49 ProfileResetter::DISABLE_EXTENSIONS, 84 ProfileResetter::DISABLE_EXTENSIONS,
50 base::Bind(&MockObject::Callback, base::Unretained(&mock_object_))); 85 base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_)));
86 mock_object_.RunLoop();
87
88 EXPECT_TRUE(prefs->GetBoolean(prefs::kHomePageIsNewTabPage));
89 EXPECT_EQ(std::string(), prefs->GetString(prefs::kHomePage));
90 EXPECT_FALSE(prefs->GetBoolean(prefs::kShowHomeButton));
51 } 91 }
52 92
53 TEST_F(ProfileResetterTest, ResetContentSettings) { 93 TEST_F(ProfileResetterTest, ResetContentSettings) {
54 EXPECT_CALL(mock_object_, Callback()); 94 resetter_->Reset(
55 resetter_.Reset(
56 ProfileResetter::CONTENT_SETTINGS, 95 ProfileResetter::CONTENT_SETTINGS,
57 ProfileResetter::DISABLE_EXTENSIONS, 96 ProfileResetter::DISABLE_EXTENSIONS,
58 base::Bind(&MockObject::Callback, base::Unretained(&mock_object_))); 97 base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_)));
98 mock_object_.RunLoop();
59 } 99 }
60 100
61 TEST_F(ProfileResetterTest, ResetCookiesAndSiteData) { 101 TEST_F(ProfileResetterTest, ResetCookiesAndSiteData) {
62 EXPECT_CALL(mock_object_, Callback()); 102 resetter_->Reset(
63 resetter_.Reset(
64 ProfileResetter::COOKIES_AND_SITE_DATA, 103 ProfileResetter::COOKIES_AND_SITE_DATA,
65 ProfileResetter::DISABLE_EXTENSIONS, 104 ProfileResetter::DISABLE_EXTENSIONS,
66 base::Bind(&MockObject::Callback, base::Unretained(&mock_object_))); 105 base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_)));
106 mock_object_.RunLoop();
67 } 107 }
68 108
69 TEST_F(ProfileResetterTest, ResetExtensionsByDisabling) { 109 TEST_F(ProfileResetterTest, ResetExtensionsByDisabling) {
70 EXPECT_CALL(mock_object_, Callback()); 110 resetter_->Reset(
71 resetter_.Reset(
72 ProfileResetter::EXTENSIONS, 111 ProfileResetter::EXTENSIONS,
73 ProfileResetter::DISABLE_EXTENSIONS, 112 ProfileResetter::DISABLE_EXTENSIONS,
74 base::Bind(&MockObject::Callback, base::Unretained(&mock_object_))); 113 base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_)));
114 mock_object_.RunLoop();
75 } 115 }
76 116
77 TEST_F(ProfileResetterTest, ResetExtensionsByUninstalling) { 117 TEST_F(ProfileResetterTest, ResetExtensionsByUninstalling) {
78 EXPECT_CALL(mock_object_, Callback()); 118 resetter_->Reset(
79 resetter_.Reset(
80 ProfileResetter::EXTENSIONS, 119 ProfileResetter::EXTENSIONS,
81 ProfileResetter::UNINSTALL_EXTENSIONS, 120 ProfileResetter::UNINSTALL_EXTENSIONS,
82 base::Bind(&MockObject::Callback, base::Unretained(&mock_object_))); 121 base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_)));
122 mock_object_.RunLoop();
123 }
124
125 TEST_F(ProfileResetterTest, ResetStartPage) {
126 PrefService* prefs = test_util_.profile()->GetPrefs();
127 DCHECK(prefs);
128
129 SessionStartupPref startup_pref(SessionStartupPref::URLS);
130 startup_pref.urls.push_back(GURL("http://foo"));
131 startup_pref.urls.push_back(GURL("http://bar"));
132 SessionStartupPref::SetStartupPref(prefs, startup_pref);
133
134 resetter_->Reset(
135 ProfileResetter::STARTUP_PAGE,
136 ProfileResetter::DISABLE_EXTENSIONS,
137 base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_)));
138 mock_object_.RunLoop();
139
140 startup_pref = SessionStartupPref::GetStartupPref(prefs);
141 EXPECT_EQ(SessionStartupPref::GetDefaultStartupType(), startup_pref.type);
142 EXPECT_EQ(std::vector<GURL>(), startup_pref.urls);
83 } 143 }
84 144
85 TEST_F(ProfileResetterTest, ResetExtensionsAll) { 145 TEST_F(ProfileResetterTest, ResetExtensionsAll) {
86 // mock_object_ is a StrictMock, so we verify that it is called only once. 146 // mock_object_ is a StrictMock, so we verify that it is called only once.
87 EXPECT_CALL(mock_object_, Callback()); 147 test_util_.VerifyLoad();
88 resetter_.Reset( 148 resetter_->Reset(
89 ProfileResetter::ALL, 149 ProfileResetter::ALL,
90 ProfileResetter::UNINSTALL_EXTENSIONS, 150 ProfileResetter::UNINSTALL_EXTENSIONS,
91 base::Bind(&MockObject::Callback, base::Unretained(&mock_object_))); 151 base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_)));
152 mock_object_.RunLoop();
92 } 153 }
93 154
94 } // namespace 155 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/profile_resetter/profile_resetter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698