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

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: Addressing 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 int resets() const {
Dan Beam 2015/12/02 04:40:08 size_t
dpapad 2015/12/02 19:55:22 Done.
37 return resets_;
38 }
39
40 private:
41 size_t resets_ = 0;
42 };
43
Dan Beam 2015/12/02 04:40:08 remove extra \n
dpapad 2015/12/02 19:55:22 Styleguide does not prohibit double blank lines fo
Dan Beam 2015/12/02 20:08:36 the style guide hurts your case by strongly encour
dpapad 2015/12/02 21:33:35 Removed per request, I don't mind that much either
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 ~TestingResetSettingsHandler() override {
55 set_web_ui(nullptr);
Dan Beam 2015/12/02 04:40:08 why is this necessary? destruction order issue?
dpapad 2015/12/02 19:55:22 Removed, it is not necessary, removed. It was ther
56 }
57
58 MockProfileResetter* GetResetter() override {
Dan Beam 2015/12/02 04:40:08 how is this override working if you're using MockP
dpapad 2015/12/02 19:55:23 Because C++ allows covariant return types, see exa
59 return &resetter_;
60 }
61
62 using settings::ResetSettingsHandler::HandleResetProfileSettings;
63
64 private:
65 MockProfileResetter resetter_;
66
67 DISALLOW_COPY_AND_ASSIGN(TestingResetSettingsHandler);
68 };
69
70 // The fixture for testing class Foo.
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
Dan Beam 2015/12/02 04:40:08 remove extra \n
dpapad 2015/12/02 19:55:22 Done.
92
93 TEST_F(ResetSettingsHandlerTest, HandleResetProfileSettings) {
94 base::ListValue list;
95 list.AppendBoolean(false);
96 handler()->HandleResetProfileSettings(&list);
97 // Check that the delegate ProfileResetter was called.
98 EXPECT_EQ(1, handler()->GetResetter()->resets());
Dan Beam 2015/12/02 04:40:08 nit: add public: size_t resets() const { retur
dpapad 2015/12/02 19:55:22 Done.
99 // Check that Javascript side is notified after resetting is done.
100 EXPECT_EQ("SettingsResetPage.doneResetting",
101 web_ui()->call_data()[0]->function_name());
102 }
103
Dan Beam 2015/12/02 04:40:08 remove extra \n
dpapad 2015/12/02 19:55:22 Done.
104
105 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698