Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/callback.h" |
| 9 #include "base/message_loop.h" | 9 #include "chrome/browser/search_engines/template_url_service_test_util.h" |
| 10 #include "chrome/test/base/testing_profile.h" | |
| 10 #include "content/public/test/test_browser_thread.h" | 11 #include "content/public/test/test_browser_thread.h" |
| 12 #include "content/public/test/test_utils.h" | |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 12 | 14 |
| 13 namespace { | 15 namespace { |
| 14 | 16 |
| 15 class MockObject { | 17 class MockObject { |
| 16 public: | 18 public: |
| 19 void RunLoop() { | |
| 20 EXPECT_CALL(*this, Callback()); | |
| 21 runner_ = new content::MessageLoopRunner; | |
| 22 runner_->Run(); | |
| 23 } | |
| 24 | |
| 25 void StopLoop() { | |
| 26 Callback(); | |
| 27 DCHECK(runner_); | |
| 28 runner_->Quit(); | |
| 29 } | |
| 30 | |
| 31 private: | |
| 17 MOCK_METHOD0(Callback, void(void)); | 32 MOCK_METHOD0(Callback, void(void)); |
| 33 | |
| 34 scoped_refptr<content::MessageLoopRunner> runner_; | |
| 18 }; | 35 }; |
| 19 | 36 |
| 20 class ProfileResetterTest : public testing::Test { | 37 class ProfileResetterTest : public testing::Test { |
| 21 public: | 38 public: |
| 22 ProfileResetterTest() | 39 ProfileResetterTest() { |
|
Peter Kasting
2013/05/22 21:22:57
Nit: Don't inline constructors and destructors
vasilii
2013/05/23 17:03:42
Done.
| |
| 23 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 40 } |
| 24 resetter_(NULL) {} | 41 |
| 42 // testing::Test | |
|
Peter Kasting
2013/05/22 21:22:57
Nit: Add trailing colon
vasilii
2013/05/23 17:03:42
Done.
| |
| 43 virtual void SetUp(); | |
| 44 virtual void TearDown(); | |
| 25 | 45 |
| 26 ~ProfileResetterTest() {} | 46 ~ProfileResetterTest() {} |
|
Peter Kasting
2013/05/22 21:22:57
Nit: This goes right below the constructor
vasilii
2013/05/23 17:03:42
Done.
| |
| 27 | 47 |
| 28 private: | |
| 29 base::MessageLoopForUI message_loop_; | |
| 30 content::TestBrowserThread ui_thread_; | |
| 31 | |
| 32 protected: | 48 protected: |
| 33 testing::StrictMock<MockObject> mock_object_; | 49 testing::StrictMock<MockObject> mock_object_; |
| 34 ProfileResetter resetter_; | 50 TemplateURLServiceTestUtil test_util_; |
| 51 scoped_ptr<ProfileResetter> resetter_; | |
| 52 | |
| 53 DISALLOW_COPY_AND_ASSIGN(ProfileResetterTest); | |
| 35 }; | 54 }; |
| 36 | 55 |
| 56 void ProfileResetterTest::SetUp() { | |
| 57 test_util_.SetUp(); | |
| 58 resetter_.reset(new ProfileResetter(test_util_.profile())); | |
| 59 } | |
| 60 | |
| 61 void ProfileResetterTest::TearDown() { | |
| 62 test_util_.TearDown(); | |
| 63 } | |
| 64 | |
| 37 TEST_F(ProfileResetterTest, ResetDefaultSearchEngine) { | 65 TEST_F(ProfileResetterTest, ResetDefaultSearchEngine) { |
| 38 EXPECT_CALL(mock_object_, Callback()); | 66 test_util_.VerifyLoad(); |
| 39 resetter_.Reset( | 67 resetter_->Reset( |
| 40 ProfileResetter::DEFAULT_SEARCH_ENGINE, | 68 ProfileResetter::DEFAULT_SEARCH_ENGINE, |
| 41 ProfileResetter::DISABLE_EXTENSIONS, | 69 ProfileResetter::DISABLE_EXTENSIONS, |
| 42 base::Bind(&MockObject::Callback, base::Unretained(&mock_object_))); | 70 base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_))); |
| 71 mock_object_.RunLoop(); | |
| 43 } | 72 } |
| 44 | 73 |
| 45 TEST_F(ProfileResetterTest, ResetHomepage) { | 74 TEST_F(ProfileResetterTest, ResetHomepage) { |
| 46 EXPECT_CALL(mock_object_, Callback()); | 75 resetter_->Reset( |
| 47 resetter_.Reset( | |
| 48 ProfileResetter::HOMEPAGE, | 76 ProfileResetter::HOMEPAGE, |
| 49 ProfileResetter::DISABLE_EXTENSIONS, | 77 ProfileResetter::DISABLE_EXTENSIONS, |
| 50 base::Bind(&MockObject::Callback, base::Unretained(&mock_object_))); | 78 base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_))); |
| 79 mock_object_.RunLoop(); | |
| 51 } | 80 } |
| 52 | 81 |
| 53 TEST_F(ProfileResetterTest, ResetContentSettings) { | 82 TEST_F(ProfileResetterTest, ResetContentSettings) { |
| 54 EXPECT_CALL(mock_object_, Callback()); | 83 resetter_->Reset( |
| 55 resetter_.Reset( | |
| 56 ProfileResetter::CONTENT_SETTINGS, | 84 ProfileResetter::CONTENT_SETTINGS, |
| 57 ProfileResetter::DISABLE_EXTENSIONS, | 85 ProfileResetter::DISABLE_EXTENSIONS, |
| 58 base::Bind(&MockObject::Callback, base::Unretained(&mock_object_))); | 86 base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_))); |
| 87 mock_object_.RunLoop(); | |
| 59 } | 88 } |
| 60 | 89 |
| 61 TEST_F(ProfileResetterTest, ResetCookiesAndSiteData) { | 90 TEST_F(ProfileResetterTest, ResetCookiesAndSiteData) { |
| 62 EXPECT_CALL(mock_object_, Callback()); | 91 resetter_->Reset( |
| 63 resetter_.Reset( | |
| 64 ProfileResetter::COOKIES_AND_SITE_DATA, | 92 ProfileResetter::COOKIES_AND_SITE_DATA, |
| 65 ProfileResetter::DISABLE_EXTENSIONS, | 93 ProfileResetter::DISABLE_EXTENSIONS, |
| 66 base::Bind(&MockObject::Callback, base::Unretained(&mock_object_))); | 94 base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_))); |
| 95 mock_object_.RunLoop(); | |
| 67 } | 96 } |
| 68 | 97 |
| 69 TEST_F(ProfileResetterTest, ResetExtensionsByDisabling) { | 98 TEST_F(ProfileResetterTest, ResetExtensionsByDisabling) { |
| 70 EXPECT_CALL(mock_object_, Callback()); | 99 resetter_->Reset( |
| 71 resetter_.Reset( | |
| 72 ProfileResetter::EXTENSIONS, | 100 ProfileResetter::EXTENSIONS, |
| 73 ProfileResetter::DISABLE_EXTENSIONS, | 101 ProfileResetter::DISABLE_EXTENSIONS, |
| 74 base::Bind(&MockObject::Callback, base::Unretained(&mock_object_))); | 102 base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_))); |
| 103 mock_object_.RunLoop(); | |
| 75 } | 104 } |
| 76 | 105 |
| 77 TEST_F(ProfileResetterTest, ResetExtensionsByUninstalling) { | 106 TEST_F(ProfileResetterTest, ResetExtensionsByUninstalling) { |
| 78 EXPECT_CALL(mock_object_, Callback()); | 107 resetter_->Reset( |
| 79 resetter_.Reset( | |
| 80 ProfileResetter::EXTENSIONS, | 108 ProfileResetter::EXTENSIONS, |
| 81 ProfileResetter::UNINSTALL_EXTENSIONS, | 109 ProfileResetter::UNINSTALL_EXTENSIONS, |
| 82 base::Bind(&MockObject::Callback, base::Unretained(&mock_object_))); | 110 base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_))); |
| 111 mock_object_.RunLoop(); | |
| 83 } | 112 } |
| 84 | 113 |
| 85 TEST_F(ProfileResetterTest, ResetExtensionsAll) { | 114 TEST_F(ProfileResetterTest, ResetExtensionsAll) { |
| 86 // mock_object_ is a StrictMock, so we verify that it is called only once. | 115 // mock_object_ is a StrictMock, so we verify that it is called only once. |
| 87 EXPECT_CALL(mock_object_, Callback()); | 116 test_util_.VerifyLoad(); |
| 88 resetter_.Reset( | 117 resetter_->Reset( |
| 89 ProfileResetter::ALL, | 118 ProfileResetter::ALL, |
| 90 ProfileResetter::UNINSTALL_EXTENSIONS, | 119 ProfileResetter::UNINSTALL_EXTENSIONS, |
| 91 base::Bind(&MockObject::Callback, base::Unretained(&mock_object_))); | 120 base::Bind(&MockObject::StopLoop, base::Unretained(&mock_object_))); |
| 121 mock_object_.RunLoop(); | |
| 92 } | 122 } |
| 93 | 123 |
| 94 } // namespace | 124 } // namespace |
| OLD | NEW |