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

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

Issue 15572002: Implemented 'Reset Search engines' feature. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Addressed Dominic's comments 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 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 64ad49168efa9fcf76149a80c864cda375b3102a..ba714d756503d24adf13be4bf54317b49422f2a8 100644
--- a/chrome/browser/profile_resetter/profile_resetter_unittest.cc
+++ b/chrome/browser/profile_resetter/profile_resetter_unittest.cc
@@ -6,89 +6,119 @@
#include "base/bind.h"
#include "base/callback.h"
-#include "base/message_loop.h"
+#include "chrome/browser/search_engines/template_url_service_test_util.h"
+#include "chrome/test/base/testing_profile.h"
#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace {
class MockObject {
public:
+ void RunLoop() {
+ EXPECT_CALL(*this, Callback());
+ runner_ = new content::MessageLoopRunner;
+ runner_->Run();
+ }
+
+ void StopLoop() {
+ Callback();
+ DCHECK(runner_);
+ runner_->Quit();
+ }
+
+ private:
MOCK_METHOD0(Callback, void(void));
+
+ scoped_refptr<content::MessageLoopRunner> runner_;
};
class ProfileResetterTest : public testing::Test {
public:
- ProfileResetterTest()
- : ui_thread_(content::BrowserThread::UI, &message_loop_),
- resetter_(NULL) {}
+ ProfileResetterTest() {
Peter Kasting 2013/05/22 21:22:57 Nit: Don't inline constructors and destructors
vasilii 2013/05/23 17:03:42 Done.
+ }
- ~ProfileResetterTest() {}
+ // testing::Test
Peter Kasting 2013/05/22 21:22:57 Nit: Add trailing colon
vasilii 2013/05/23 17:03:42 Done.
+ virtual void SetUp();
+ virtual void TearDown();
- private:
- base::MessageLoopForUI message_loop_;
- content::TestBrowserThread ui_thread_;
+ ~ProfileResetterTest() {}
Peter Kasting 2013/05/22 21:22:57 Nit: This goes right below the constructor
vasilii 2013/05/23 17:03:42 Done.
protected:
testing::StrictMock<MockObject> mock_object_;
- ProfileResetter resetter_;
+ TemplateURLServiceTestUtil test_util_;
+ scoped_ptr<ProfileResetter> resetter_;
+
+ DISALLOW_COPY_AND_ASSIGN(ProfileResetterTest);
};
+void ProfileResetterTest::SetUp() {
+ test_util_.SetUp();
+ resetter_.reset(new ProfileResetter(test_util_.profile()));
+}
+
+void ProfileResetterTest::TearDown() {
+ test_util_.TearDown();
+}
+
TEST_F(ProfileResetterTest, ResetDefaultSearchEngine) {
- EXPECT_CALL(mock_object_, Callback());
- resetter_.Reset(
+ test_util_.VerifyLoad();
+ resetter_->Reset(
ProfileResetter::DEFAULT_SEARCH_ENGINE,
ProfileResetter::DISABLE_EXTENSIONS,
- base::Bind(&MockObject::Callback, base::Unretained(&mock_object_)));
+ base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_)));
+ mock_object_.RunLoop();
}
TEST_F(ProfileResetterTest, ResetHomepage) {
- EXPECT_CALL(mock_object_, Callback());
- resetter_.Reset(
+ resetter_->Reset(
ProfileResetter::HOMEPAGE,
ProfileResetter::DISABLE_EXTENSIONS,
- base::Bind(&MockObject::Callback, base::Unretained(&mock_object_)));
+ base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_)));
+ mock_object_.RunLoop();
}
TEST_F(ProfileResetterTest, ResetContentSettings) {
- EXPECT_CALL(mock_object_, Callback());
- resetter_.Reset(
+ resetter_->Reset(
ProfileResetter::CONTENT_SETTINGS,
ProfileResetter::DISABLE_EXTENSIONS,
- base::Bind(&MockObject::Callback, base::Unretained(&mock_object_)));
+ base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_)));
+ mock_object_.RunLoop();
}
TEST_F(ProfileResetterTest, ResetCookiesAndSiteData) {
- EXPECT_CALL(mock_object_, Callback());
- resetter_.Reset(
+ resetter_->Reset(
ProfileResetter::COOKIES_AND_SITE_DATA,
ProfileResetter::DISABLE_EXTENSIONS,
- base::Bind(&MockObject::Callback, base::Unretained(&mock_object_)));
+ base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_)));
+ mock_object_.RunLoop();
}
TEST_F(ProfileResetterTest, ResetExtensionsByDisabling) {
- EXPECT_CALL(mock_object_, Callback());
- resetter_.Reset(
+ resetter_->Reset(
ProfileResetter::EXTENSIONS,
ProfileResetter::DISABLE_EXTENSIONS,
- base::Bind(&MockObject::Callback, base::Unretained(&mock_object_)));
+ base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_)));
+ mock_object_.RunLoop();
}
TEST_F(ProfileResetterTest, ResetExtensionsByUninstalling) {
- EXPECT_CALL(mock_object_, Callback());
- resetter_.Reset(
+ resetter_->Reset(
ProfileResetter::EXTENSIONS,
ProfileResetter::UNINSTALL_EXTENSIONS,
- base::Bind(&MockObject::Callback, base::Unretained(&mock_object_)));
+ base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_)));
+ mock_object_.RunLoop();
}
TEST_F(ProfileResetterTest, ResetExtensionsAll) {
// mock_object_ is a StrictMock, so we verify that it is called only once.
- EXPECT_CALL(mock_object_, Callback());
- resetter_.Reset(
+ test_util_.VerifyLoad();
+ resetter_->Reset(
ProfileResetter::ALL,
ProfileResetter::UNINSTALL_EXTENSIONS,
- base::Bind(&MockObject::Callback, base::Unretained(&mock_object_)));
+ base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_)));
+ mock_object_.RunLoop();
}
} // namespace

Powered by Google App Engine
This is Rietveld 408576698