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/values.h" |
| 6 #include "chrome/browser/profile_resetter/profile_resetter.h" |
| 7 #include "chrome/browser/ui/webui/settings/reset_settings_handler.h" |
| 8 #include "chrome/test/base/testing_profile.h" |
| 9 #include "content/public/browser/web_ui_data_source.h" |
| 10 #include "content/public/test/test_browser_thread_bundle.h" |
| 11 #include "content/public/test/test_web_ui.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 using settings::ResetSettingsHandler; |
| 15 |
| 16 namespace { |
| 17 |
| 18 // Mock version of ProfileResetter to be used in tests. |
| 19 class MockProfileResetter : public ProfileResetter { |
| 20 public: |
| 21 explicit MockProfileResetter(TestingProfile* profile) |
| 22 : ProfileResetter(profile) { |
| 23 } |
| 24 |
| 25 bool IsActive() const override { |
| 26 return false; |
| 27 } |
| 28 |
| 29 void Reset(ResettableFlags resettable_flags, |
| 30 scoped_ptr<BrandcodedDefaultSettings> master_settings, |
| 31 const base::Closure& callback) override { |
| 32 resets_++; |
| 33 callback.Run(); |
| 34 } |
| 35 |
| 36 size_t resets() const { |
| 37 return resets_; |
| 38 } |
| 39 |
| 40 private: |
| 41 size_t resets_ = 0; |
| 42 }; |
| 43 |
| 44 class TestingResetSettingsHandler : public ResetSettingsHandler { |
| 45 public: |
| 46 TestingResetSettingsHandler( |
| 47 TestingProfile* profile, bool allow_powerwash, content::WebUI* web_ui) |
| 48 : ResetSettingsHandler(profile, allow_powerwash), |
| 49 resetter_(profile) { |
| 50 set_web_ui(web_ui); |
| 51 } |
| 52 |
| 53 size_t resets() const { return resetter_.resets(); } |
| 54 |
| 55 using settings::ResetSettingsHandler::HandleResetProfileSettings; |
| 56 |
| 57 protected: |
| 58 ProfileResetter* GetResetter() override { |
| 59 return &resetter_; |
| 60 } |
| 61 |
| 62 private: |
| 63 MockProfileResetter resetter_; |
| 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(TestingResetSettingsHandler); |
| 66 }; |
| 67 |
| 68 class ResetSettingsHandlerTest : public testing::Test { |
| 69 public: |
| 70 ResetSettingsHandlerTest() : handler_(&profile_, false, &web_ui_) { |
| 71 } |
| 72 |
| 73 TestingResetSettingsHandler* handler() { return &handler_; } |
| 74 content::TestWebUI* web_ui() { return &web_ui_; } |
| 75 |
| 76 private: |
| 77 // The order here matters. |
| 78 content::TestBrowserThreadBundle thread_bundle_; |
| 79 TestingProfile profile_; |
| 80 content::TestWebUI web_ui_; |
| 81 TestingResetSettingsHandler handler_; |
| 82 }; |
| 83 |
| 84 TEST_F(ResetSettingsHandlerTest, HandleResetProfileSettings) { |
| 85 base::ListValue list; |
| 86 list.AppendBoolean(false); |
| 87 handler()->HandleResetProfileSettings(&list); |
| 88 // Check that the delegate ProfileResetter was called. |
| 89 EXPECT_EQ(1u, handler()->resets()); |
| 90 // Check that Javascript side is notified after resetting is done. |
| 91 EXPECT_EQ("SettingsResetPage.doneResetting", |
| 92 web_ui()->call_data()[0]->function_name()); |
| 93 } |
| 94 |
| 95 } // namespace |
OLD | NEW |