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

Side by Side Diff: chrome/browser/ui/webui/settings/reset_settings_handler_unittest.cc

Issue 1490503002: MD Settings: Adding unit test for ResetSettingsHandler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 5 years 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
OLDNEW
(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
45 class TestingResetSettingsHandler : public ResetSettingsHandler {
46 public:
47 TestingResetSettingsHandler(
48 TestingProfile* profile, bool allow_powerwash, content::WebUI* web_ui)
49 : ResetSettingsHandler(profile, allow_powerwash),
50 resetter_(profile) {
51 set_web_ui(web_ui);
52 }
53
54 size_t resets() const { return resetter_.resets(); }
55
56 using settings::ResetSettingsHandler::HandleResetProfileSettings;
57
58 protected:
59 MockProfileResetter* GetResetter() override {
Dan Beam 2015/12/02 20:08:36 ProfileResetter or find precedence for doing this
dpapad 2015/12/02 21:33:35 Done. Changed to ProfileResetter. MockProfileReset
Dan Beam 2015/12/02 21:36:15 i know :), which is part of why I suggested that
60 return &resetter_;
61 }
62
63 private:
64 MockProfileResetter resetter_;
65
66 DISALLOW_COPY_AND_ASSIGN(TestingResetSettingsHandler);
67 };
68
69
70 // The fixture for testing class Foo.
Dan Beam 2015/12/02 21:36:52 lol whoops
dpapad 2015/12/02 21:41:05 Already removed in latest patch (#6).
71 class ResetSettingsHandlerTest : public testing::Test {
72 public:
73 ResetSettingsHandlerTest() : handler_(&profile_, false, &web_ui_) {
74 }
75
76 TestingResetSettingsHandler* handler() {
77 return &handler_;
78 }
79
80 content::TestWebUI* web_ui() {
81 return &web_ui_;
82 }
83
84 private:
85 // The order here matters.
86 content::TestBrowserThreadBundle thread_bundle_;
87 TestingProfile profile_;
88 content::TestWebUI web_ui_;
89 TestingResetSettingsHandler handler_;
90 };
91
92 TEST_F(ResetSettingsHandlerTest, HandleResetProfileSettings) {
93 base::ListValue list;
94 list.AppendBoolean(false);
95 handler()->HandleResetProfileSettings(&list);
96 // Check that the delegate ProfileResetter was called.
97 EXPECT_EQ((size_t)1, handler()->resets());
Dan Beam 2015/12/02 20:08:36 1u
dpapad 2015/12/02 21:33:35 Done.
98 // Check that Javascript side is notified after resetting is done.
99 EXPECT_EQ("SettingsResetPage.doneResetting",
100 web_ui()->call_data()[0]->function_name());
101 }
102
103 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/settings/reset_settings_handler.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698