Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/message_loop/message_loop.h" | |
| 6 #include "base/values.h" | |
| 7 #include "chrome/browser/profile_resetter/profile_resetter.h" | |
| 8 #include "chrome/browser/ui/webui/settings/reset_settings_handler.h" | |
| 9 #include "chrome/test/base/testing_profile.h" | |
| 10 #include "content/public/browser/web_ui_data_source.h" | |
| 11 #include "content/public/test/test_browser_thread.h" | |
| 12 #include "content/public/test/test_web_ui.h" | |
| 13 #include "testing/gmock/include/gmock/gmock.h" | |
| 14 #include "testing/gtest/include/gtest/gtest.h" | |
| 15 | |
| 16 using settings::ResetSettingsHandler; | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 /* Mock version of ProfileResetter to be used in tests. */ | |
|
Dan Beam
2015/12/01 04:27:37
// Single line comment.
dpapad
2015/12/01 19:06:04
Done.
| |
| 21 class MockProfileResetter : public ProfileResetter { | |
| 22 public: | |
| 23 explicit MockProfileResetter(TestingProfile* profile) | |
| 24 : ProfileResetter(profile) { | |
| 25 } | |
| 26 | |
| 27 bool IsActive() const override { | |
|
Dan Beam
2015/12/01 17:29:04
battre@: here ^
| |
| 28 return false; | |
| 29 } | |
| 30 | |
| 31 void Reset(ResettableFlags resettable_flags, | |
| 32 scoped_ptr<BrandcodedDefaultSettings> master_settings, | |
| 33 const base::Closure& callback) override { | |
|
Dan Beam
2015/12/01 17:29:04
battre@: and here ^
| |
| 34 resets_++; | |
| 35 callback.Run(); | |
| 36 } | |
| 37 | |
| 38 int resets() const { | |
| 39 return resets_; | |
| 40 } | |
| 41 | |
| 42 private: | |
| 43 int resets_ = 0; | |
|
Dan Beam
2015/12/01 04:27:37
nit: size_t
dpapad
2015/12/01 19:06:04
Done.
| |
| 44 }; | |
| 45 | |
| 46 | |
| 47 class TestingResetSettingsHandler : public ResetSettingsHandler { | |
| 48 public: | |
| 49 TestingResetSettingsHandler( | |
| 50 TestingProfile* profile, bool allow_powerwash, content::WebUI* web_ui) | |
| 51 : ResetSettingsHandler(profile, allow_powerwash), | |
| 52 profile_(make_scoped_ptr(profile)), | |
| 53 resetter_(profile) { | |
| 54 set_web_ui(web_ui); | |
| 55 } | |
| 56 | |
| 57 ~TestingResetSettingsHandler() override { | |
| 58 set_web_ui(nullptr); | |
| 59 } | |
| 60 | |
| 61 MockProfileResetter* GetResetter() override { | |
| 62 return &resetter_; | |
| 63 } | |
| 64 | |
| 65 using settings::ResetSettingsHandler::HandleResetProfileSettings; | |
| 66 | |
| 67 private: | |
| 68 scoped_ptr<TestingProfile> profile_; | |
|
Dan Beam
2015/12/01 04:27:37
why should the handler own the profile? this shou
| |
| 69 MockProfileResetter resetter_; | |
| 70 | |
| 71 DISALLOW_COPY_AND_ASSIGN(TestingResetSettingsHandler); | |
| 72 }; | |
| 73 | |
| 74 // The fixture for testing class Foo. | |
| 75 class ResetSettingsHandlerTest : public testing::Test { | |
| 76 public: | |
| 77 ResetSettingsHandlerTest() | |
| 78 : web_ui_(new content::TestWebUI()), | |
| 79 ui_thread_(content::BrowserThread::UI, &message_loop_) { | |
| 80 handler_.reset(new TestingResetSettingsHandler( | |
| 81 new TestingProfile(), false, web_ui_.get())); | |
| 82 } | |
| 83 | |
| 84 protected: | |
| 85 // The order here matters, because the |message_loop_| needs to exist during | |
| 86 // destruction of |handler_|. | |
| 87 base::MessageLoopForUI message_loop_; | |
| 88 scoped_ptr<TestingResetSettingsHandler> handler_; | |
|
Dan Beam
2015/12/01 04:27:37
nit: instead of protected member, private member +
Dan Beam
2015/12/01 04:27:37
why does this need to be a scoped_ptr? just initi
dpapad
2015/12/01 19:06:04
Done. Also removed usage of deprecated TestBrowser
| |
| 89 scoped_ptr<content::TestWebUI> web_ui_; | |
|
Dan Beam
2015/12/01 04:27:37
why does this need to be a scoped_ptr?
dpapad
2015/12/01 19:06:04
Removed.
| |
| 90 | |
| 91 private: | |
| 92 content::TestBrowserThread ui_thread_; | |
| 93 }; | |
| 94 | |
| 95 | |
| 96 TEST_F(ResetSettingsHandlerTest, HandleResetProfileSettings) { | |
| 97 base::ListValue list; | |
| 98 list.AppendBoolean(false); | |
| 99 handler_->HandleResetProfileSettings(&list); | |
| 100 // Check that the delegate ProfileResetter was called. | |
| 101 EXPECT_EQ(1, handler_->GetResetter()->resets()); | |
| 102 // Check that Javascript side is notified after resetting is done. | |
| 103 EXPECT_EQ("SettingsResetPage.doneResetting", | |
| 104 web_ui_->call_data()[0]->function_name()); | |
|
Dan Beam
2015/12/01 04:27:37
doesn't this effectively check that resets_ >= 1?
dpapad
2015/12/01 19:06:04
It does. The assertion at line 101 checks that res
Dan Beam
2015/12/02 04:40:07
ok
| |
| 105 } | |
| 106 | |
| 107 | |
| 108 } // namespace | |
| OLD | NEW |