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

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

Issue 17274006: Reset profile: reset cookies and site data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/profile_resetter/profile_resetter_test_base.cc ('k') | chrome/chrome_tests.gypi » ('j') | 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"
8 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/extensions/extension_service_unittest.h" 8 #include "chrome/browser/extensions/extension_service_unittest.h"
10 #include "chrome/browser/extensions/tab_helper.h" 9 #include "chrome/browser/extensions/tab_helper.h"
11 #include "chrome/browser/prefs/session_startup_pref.h" 10 #include "chrome/browser/prefs/session_startup_pref.h"
11 #include "chrome/browser/profile_resetter/profile_resetter_test_base.h"
12 #include "chrome/browser/search_engines/template_url_service_test_util.h" 12 #include "chrome/browser/search_engines/template_url_service_test_util.h"
13 #include "chrome/browser/themes/theme_service.h" 13 #include "chrome/browser/themes/theme_service.h"
14 #include "chrome/browser/themes/theme_service_factory.h" 14 #include "chrome/browser/themes/theme_service_factory.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" 15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/common/extensions/extension.h" 16 #include "chrome/common/extensions/extension.h"
17 #include "chrome/common/extensions/extension_manifest_constants.h" 17 #include "chrome/common/extensions/extension_manifest_constants.h"
18 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
19 #include "chrome/test/base/browser_with_test_window_test.h" 19 #include "chrome/test/base/browser_with_test_window_test.h"
20 #include "chrome/test/base/testing_profile.h"
21 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
22 #include "content/public/test/test_utils.h" 21
23 #include "testing/gmock/include/gmock/gmock.h"
24 22
25 namespace { 23 namespace {
26 24
27 using extensions::Extension; 25 using extensions::Extension;
28 using extensions::Manifest; 26 using extensions::Manifest;
29 27
30 class MockObject {
31 public:
32 void RunLoop() {
33 EXPECT_CALL(*this, Callback());
34 runner_ = new content::MessageLoopRunner;
35 runner_->Run();
36 }
37
38 void StopLoop() {
39 DCHECK(runner_.get());
40 Callback();
41 runner_->Quit();
42 }
43
44 private:
45 MOCK_METHOD0(Callback, void(void));
46
47 scoped_refptr<content::MessageLoopRunner> runner_;
48 };
49
50 class ProfileResetterTestBase {
51 public:
52 ProfileResetterTestBase();
53 ~ProfileResetterTestBase();
54 protected:
55 testing::StrictMock<MockObject> mock_object_;
56 scoped_ptr<ProfileResetter> resetter_;
57
58 private:
59 DISALLOW_COPY_AND_ASSIGN(ProfileResetterTestBase);
60 };
61
62 ProfileResetterTestBase::ProfileResetterTestBase() {}
63
64 ProfileResetterTestBase::~ProfileResetterTestBase() {}
65
66 class ProfileResetterTest : public testing::Test, 28 class ProfileResetterTest : public testing::Test,
67 public ProfileResetterTestBase { 29 public ProfileResetterTestBase {
68 protected: 30 protected:
69 // testing::Test: 31 // testing::Test:
70 virtual void SetUp() OVERRIDE; 32 virtual void SetUp() OVERRIDE;
71 virtual void TearDown() OVERRIDE; 33 virtual void TearDown() OVERRIDE;
72 34
73 TemplateURLServiceTestUtil test_util_; 35 TemplateURLServiceTestUtil test_util_;
74 }; 36 };
75 37
(...skipping 12 matching lines...) Expand all
88 protected: 50 protected:
89 virtual void SetUp() OVERRIDE; 51 virtual void SetUp() OVERRIDE;
90 }; 52 };
91 53
92 void ExtensionsResetTest::SetUp() { 54 void ExtensionsResetTest::SetUp() {
93 ExtensionServiceTestBase::SetUp(); 55 ExtensionServiceTestBase::SetUp();
94 InitializeEmptyExtensionService(); 56 InitializeEmptyExtensionService();
95 resetter_.reset(new ProfileResetter(profile_.get())); 57 resetter_.reset(new ProfileResetter(profile_.get()));
96 } 58 }
97 59
98 // Returns a barebones test Extension object with the specified |name|. The
99 // returned extension will include background permission iff
100 // |background_permission| is true.
101 scoped_refptr<Extension> CreateExtension(const std::string& name, 60 scoped_refptr<Extension> CreateExtension(const std::string& name,
102 const base::FilePath& path, 61 const base::FilePath& path,
103 Manifest::Location location, 62 Manifest::Location location,
104 bool theme) { 63 bool theme) {
105 DictionaryValue manifest; 64 DictionaryValue manifest;
106 manifest.SetString(extension_manifest_keys::kVersion, "1.0.0.0"); 65 manifest.SetString(extension_manifest_keys::kVersion, "1.0.0.0");
107 manifest.SetString(extension_manifest_keys::kName, name); 66 manifest.SetString(extension_manifest_keys::kName, name);
108 manifest.SetString("app.launch.web_url", "http://www.google.com"); 67 manifest.SetString("app.launch.web_url", "http://www.google.com");
109 if (theme) 68 if (theme)
110 manifest.Set(extension_manifest_keys::kTheme, new DictionaryValue()); 69 manifest.Set(extension_manifest_keys::kTheme, new DictionaryValue());
(...skipping 22 matching lines...) Expand all
133 } 92 }
134 93
135 content::WebContents* PinnedTabsResetTest::CreateWebContents() { 94 content::WebContents* PinnedTabsResetTest::CreateWebContents() {
136 return content::WebContents::Create( 95 return content::WebContents::Create(
137 content::WebContents::CreateParams(profile())); 96 content::WebContents::CreateParams(profile()));
138 } 97 }
139 98
140 /********************* Tests *********************/ 99 /********************* Tests *********************/
141 100
142 TEST_F(ProfileResetterTest, ResetDefaultSearchEngine) { 101 TEST_F(ProfileResetterTest, ResetDefaultSearchEngine) {
102 PrefService* prefs = test_util_.profile()->GetPrefs();
103 DCHECK(prefs);
104 prefs->SetString(prefs::kLastPromptedGoogleURL, "http://www.foo.com/");
105
143 resetter_->Reset( 106 resetter_->Reset(
144 ProfileResetter::DEFAULT_SEARCH_ENGINE, 107 ProfileResetter::DEFAULT_SEARCH_ENGINE,
145 base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_))); 108 base::Bind(&ProfileResetterMockObject::StopLoop,
109 base::Unretained(&mock_object_)));
146 mock_object_.RunLoop(); 110 mock_object_.RunLoop();
111
112 EXPECT_EQ("", prefs->GetString(prefs::kLastPromptedGoogleURL));
147 } 113 }
148 114
149 TEST_F(ProfileResetterTest, ResetHomepage) { 115 TEST_F(ProfileResetterTest, ResetHomepage) {
150 PrefService* prefs = test_util_.profile()->GetPrefs(); 116 PrefService* prefs = test_util_.profile()->GetPrefs();
151 DCHECK(prefs); 117 DCHECK(prefs);
152 prefs->SetBoolean(prefs::kHomePageIsNewTabPage, false); 118 prefs->SetBoolean(prefs::kHomePageIsNewTabPage, false);
153 prefs->SetString(prefs::kHomePage, "http://google.com"); 119 prefs->SetString(prefs::kHomePage, "http://google.com");
154 prefs->SetBoolean(prefs::kShowHomeButton, true); 120 prefs->SetBoolean(prefs::kShowHomeButton, true);
155 121
156 resetter_->Reset( 122 resetter_->Reset(
157 ProfileResetter::HOMEPAGE, 123 ProfileResetter::HOMEPAGE,
158 base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_))); 124 base::Bind(&ProfileResetterMockObject::StopLoop,
125 base::Unretained(&mock_object_)));
159 mock_object_.RunLoop(); 126 mock_object_.RunLoop();
160 127
161 EXPECT_TRUE(prefs->GetBoolean(prefs::kHomePageIsNewTabPage)); 128 EXPECT_TRUE(prefs->GetBoolean(prefs::kHomePageIsNewTabPage));
162 EXPECT_EQ(std::string(), prefs->GetString(prefs::kHomePage)); 129 EXPECT_EQ(std::string(), prefs->GetString(prefs::kHomePage));
163 EXPECT_FALSE(prefs->GetBoolean(prefs::kShowHomeButton)); 130 EXPECT_FALSE(prefs->GetBoolean(prefs::kShowHomeButton));
164 } 131 }
165 132
166 TEST_F(ProfileResetterTest, ResetContentSettings) { 133 TEST_F(ProfileResetterTest, ResetContentSettings) {
167 resetter_->Reset( 134 resetter_->Reset(
168 ProfileResetter::CONTENT_SETTINGS, 135 ProfileResetter::CONTENT_SETTINGS,
169 base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_))); 136 base::Bind(&ProfileResetterMockObject::StopLoop,
137 base::Unretained(&mock_object_)));
170 mock_object_.RunLoop(); 138 mock_object_.RunLoop();
171 } 139 }
172 140
173 TEST_F(ProfileResetterTest, ResetCookiesAndSiteData) {
174 resetter_->Reset(
175 ProfileResetter::COOKIES_AND_SITE_DATA,
176 base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_)));
177 mock_object_.RunLoop();
178 }
179
180 TEST_F(ExtensionsResetTest, ResetExtensionsByDisabling) { 141 TEST_F(ExtensionsResetTest, ResetExtensionsByDisabling) {
181 base::ScopedTempDir temp_dir; 142 base::ScopedTempDir temp_dir;
182 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 143 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
183 144
184 scoped_refptr<Extension> theme = CreateExtension("example1", temp_dir.path(), 145 scoped_refptr<Extension> theme = CreateExtension("example1", temp_dir.path(),
185 Manifest::INVALID_LOCATION, 146 Manifest::INVALID_LOCATION,
186 true); 147 true);
187 service_->FinishInstallationForTest(theme.get()); 148 service_->FinishInstallationForTest(theme.get());
188 // Let ThemeService finish creating the theme pack. 149 // Let ThemeService finish creating the theme pack.
189 base::MessageLoop::current()->RunUntilIdle(); 150 base::MessageLoop::current()->RunUntilIdle();
(...skipping 19 matching lines...) Expand all
209 scoped_refptr<Extension> ext4 = 170 scoped_refptr<Extension> ext4 =
210 CreateExtension("example4", 171 CreateExtension("example4",
211 base::FilePath(FILE_PATH_LITERAL("//nonexistent3")), 172 base::FilePath(FILE_PATH_LITERAL("//nonexistent3")),
212 Manifest::EXTERNAL_POLICY_DOWNLOAD, 173 Manifest::EXTERNAL_POLICY_DOWNLOAD,
213 false); 174 false);
214 service_->AddExtension(ext4.get()); 175 service_->AddExtension(ext4.get());
215 EXPECT_EQ(4u, service_->extensions()->size()); 176 EXPECT_EQ(4u, service_->extensions()->size());
216 177
217 resetter_->Reset( 178 resetter_->Reset(
218 ProfileResetter::EXTENSIONS, 179 ProfileResetter::EXTENSIONS,
219 base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_))); 180 base::Bind(&ProfileResetterMockObject::StopLoop,
181 base::Unretained(&mock_object_)));
220 mock_object_.RunLoop(); 182 mock_object_.RunLoop();
221 183
222 EXPECT_EQ(2u, service_->extensions()->size()); 184 EXPECT_EQ(2u, service_->extensions()->size());
223 EXPECT_TRUE(service_->extensions()->Contains(ext3->id())); 185 EXPECT_TRUE(service_->extensions()->Contains(ext3->id()));
224 EXPECT_TRUE(service_->extensions()->Contains(ext4->id())); 186 EXPECT_TRUE(service_->extensions()->Contains(ext4->id()));
225 EXPECT_TRUE(theme_service->UsingDefaultTheme()); 187 EXPECT_TRUE(theme_service->UsingDefaultTheme());
226 } 188 }
227 189
228 TEST_F(ProfileResetterTest, ResetStartPage) { 190 TEST_F(ProfileResetterTest, ResetStartPage) {
229 PrefService* prefs = test_util_.profile()->GetPrefs(); 191 PrefService* prefs = test_util_.profile()->GetPrefs();
230 DCHECK(prefs); 192 DCHECK(prefs);
231 193
232 SessionStartupPref startup_pref(SessionStartupPref::URLS); 194 SessionStartupPref startup_pref(SessionStartupPref::URLS);
233 startup_pref.urls.push_back(GURL("http://foo")); 195 startup_pref.urls.push_back(GURL("http://foo"));
234 startup_pref.urls.push_back(GURL("http://bar")); 196 startup_pref.urls.push_back(GURL("http://bar"));
235 SessionStartupPref::SetStartupPref(prefs, startup_pref); 197 SessionStartupPref::SetStartupPref(prefs, startup_pref);
236 198
237 resetter_->Reset( 199 resetter_->Reset(
238 ProfileResetter::STARTUP_PAGES, 200 ProfileResetter::STARTUP_PAGES,
239 base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_))); 201 base::Bind(&ProfileResetterMockObject::StopLoop,
202 base::Unretained(&mock_object_)));
240 mock_object_.RunLoop(); 203 mock_object_.RunLoop();
241 204
242 startup_pref = SessionStartupPref::GetStartupPref(prefs); 205 startup_pref = SessionStartupPref::GetStartupPref(prefs);
243 EXPECT_EQ(SessionStartupPref::GetDefaultStartupType(), startup_pref.type); 206 EXPECT_EQ(SessionStartupPref::GetDefaultStartupType(), startup_pref.type);
244 EXPECT_EQ(std::vector<GURL>(), startup_pref.urls); 207 EXPECT_EQ(std::vector<GURL>(), startup_pref.urls);
245 } 208 }
246 209
247 TEST_F(PinnedTabsResetTest, ResetPinnedTabs) { 210 TEST_F(PinnedTabsResetTest, ResetPinnedTabs) {
248 scoped_refptr<Extension> extension_app = CreateExtension( 211 scoped_refptr<Extension> extension_app = CreateExtension(
249 "hello!", 212 "hello!",
250 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), 213 base::FilePath(FILE_PATH_LITERAL("//nonexistent")),
251 Manifest::INVALID_LOCATION, 214 Manifest::INVALID_LOCATION,
252 false); 215 false);
253 content::WebContents* contents1 = CreateWebContents(); 216 scoped_ptr<content::WebContents> contents1(CreateWebContents());
254 extensions::TabHelper::CreateForWebContents(contents1); 217 extensions::TabHelper::CreateForWebContents(contents1.get());
255 extensions::TabHelper::FromWebContents(contents1)-> 218 extensions::TabHelper::FromWebContents(contents1.get())->
256 SetExtensionApp(extension_app.get()); 219 SetExtensionApp(extension_app.get());
257 content::WebContents* contents2 = CreateWebContents(); 220 scoped_ptr<content::WebContents> contents2(CreateWebContents());
258 content::WebContents* contents3 = CreateWebContents(); 221 scoped_ptr<content::WebContents> contents3(CreateWebContents());
259 content::WebContents* contents4 = CreateWebContents(); 222 scoped_ptr<content::WebContents> contents4(CreateWebContents());
260 TabStripModel* tab_strip_model = browser()->tab_strip_model(); 223 TabStripModel* tab_strip_model = browser()->tab_strip_model();
261 224
262 tab_strip_model->AppendWebContents(contents4, true); 225 tab_strip_model->AppendWebContents(contents4.get(), true);
263 tab_strip_model->AppendWebContents(contents3, true); 226 tab_strip_model->AppendWebContents(contents3.get(), true);
264 tab_strip_model->AppendWebContents(contents2, true); 227 tab_strip_model->AppendWebContents(contents2.get(), true);
265 tab_strip_model->SetTabPinned(2, true); 228 tab_strip_model->SetTabPinned(2, true);
266 tab_strip_model->AppendWebContents(contents1, true); 229 tab_strip_model->AppendWebContents(contents1.get(), true);
267 tab_strip_model->SetTabPinned(3, true); 230 tab_strip_model->SetTabPinned(3, true);
268 231
269 EXPECT_EQ(contents2, tab_strip_model->GetWebContentsAt(0)); 232 EXPECT_EQ(contents2, tab_strip_model->GetWebContentsAt(0));
270 EXPECT_EQ(contents1, tab_strip_model->GetWebContentsAt(1)); 233 EXPECT_EQ(contents1, tab_strip_model->GetWebContentsAt(1));
271 EXPECT_EQ(contents3, tab_strip_model->GetWebContentsAt(2)); 234 EXPECT_EQ(contents3, tab_strip_model->GetWebContentsAt(2));
272 EXPECT_EQ(contents4, tab_strip_model->GetWebContentsAt(3)); 235 EXPECT_EQ(contents4, tab_strip_model->GetWebContentsAt(3));
273 EXPECT_EQ(3, tab_strip_model->IndexOfFirstNonMiniTab()); 236 EXPECT_EQ(3, tab_strip_model->IndexOfFirstNonMiniTab());
274 237
275 resetter_->Reset( 238 resetter_->Reset(
276 ProfileResetter::PINNED_TABS, 239 ProfileResetter::PINNED_TABS,
277 base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_))); 240 base::Bind(&ProfileResetterMockObject::StopLoop,
241 base::Unretained(&mock_object_)));
278 mock_object_.RunLoop(); 242 mock_object_.RunLoop();
279 243
280 EXPECT_EQ(contents1, tab_strip_model->GetWebContentsAt(0)); 244 EXPECT_EQ(contents1, tab_strip_model->GetWebContentsAt(0));
281 EXPECT_EQ(contents2, tab_strip_model->GetWebContentsAt(1)); 245 EXPECT_EQ(contents2, tab_strip_model->GetWebContentsAt(1));
282 EXPECT_EQ(contents3, tab_strip_model->GetWebContentsAt(2)); 246 EXPECT_EQ(contents3, tab_strip_model->GetWebContentsAt(2));
283 EXPECT_EQ(contents4, tab_strip_model->GetWebContentsAt(3)); 247 EXPECT_EQ(contents4, tab_strip_model->GetWebContentsAt(3));
284 EXPECT_EQ(1, tab_strip_model->IndexOfFirstNonMiniTab()); 248 EXPECT_EQ(1, tab_strip_model->IndexOfFirstNonMiniTab());
285 } 249 }
286 250
287 TEST_F(ProfileResetterTest, ResetFewFlags) { 251 TEST_F(ProfileResetterTest, ResetFewFlags) {
288 // mock_object_ is a StrictMock, so we verify that it is called only once. 252 // mock_object_ is a StrictMock, so we verify that it is called only once.
289 resetter_->Reset( 253 resetter_->Reset(
290 ProfileResetter::DEFAULT_SEARCH_ENGINE | ProfileResetter::HOMEPAGE, 254 ProfileResetter::DEFAULT_SEARCH_ENGINE | ProfileResetter::HOMEPAGE,
291 base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_))); 255 base::Bind(&ProfileResetterMockObject::StopLoop,
256 base::Unretained(&mock_object_)));
292 mock_object_.RunLoop(); 257 mock_object_.RunLoop();
293 } 258 }
294 259
295 } // namespace 260 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/profile_resetter/profile_resetter_test_base.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698