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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/settings/reset_settings_handler_unittest.cc
diff --git a/chrome/browser/ui/webui/settings/reset_settings_handler_unittest.cc b/chrome/browser/ui/webui/settings/reset_settings_handler_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e7aaf20ff29c4cbeb3ddf95cc1f6bdbdef87dc9e
--- /dev/null
+++ b/chrome/browser/ui/webui/settings/reset_settings_handler_unittest.cc
@@ -0,0 +1,105 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/values.h"
+#include "chrome/browser/profile_resetter/profile_resetter.h"
+#include "chrome/browser/ui/webui/settings/reset_settings_handler.h"
+#include "chrome/test/base/testing_profile.h"
+#include "content/public/browser/web_ui_data_source.h"
+#include "content/public/test/test_browser_thread_bundle.h"
+#include "content/public/test/test_web_ui.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using settings::ResetSettingsHandler;
+
+namespace {
+
+// Mock version of ProfileResetter to be used in tests.
+class MockProfileResetter : public ProfileResetter {
+ public:
+ explicit MockProfileResetter(TestingProfile* profile)
+ : ProfileResetter(profile) {
+ }
+
+ bool IsActive() const override {
+ return false;
+ }
+
+ void Reset(ResettableFlags resettable_flags,
+ scoped_ptr<BrandcodedDefaultSettings> master_settings,
+ const base::Closure& callback) override {
+ resets_++;
+ callback.Run();
+ }
+
+ int resets() const {
Dan Beam 2015/12/02 04:40:08 size_t
dpapad 2015/12/02 19:55:22 Done.
+ return resets_;
+ }
+
+ private:
+ size_t resets_ = 0;
+};
+
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
+
+class TestingResetSettingsHandler : public ResetSettingsHandler {
+ public:
+ TestingResetSettingsHandler(
+ TestingProfile* profile, bool allow_powerwash, content::WebUI* web_ui)
+ : ResetSettingsHandler(profile, allow_powerwash),
+ resetter_(profile) {
+ set_web_ui(web_ui);
+ }
+
+ ~TestingResetSettingsHandler() override {
+ 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
+ }
+
+ 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
+ return &resetter_;
+ }
+
+ using settings::ResetSettingsHandler::HandleResetProfileSettings;
+
+ private:
+ MockProfileResetter resetter_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestingResetSettingsHandler);
+};
+
+// The fixture for testing class Foo.
+class ResetSettingsHandlerTest : public testing::Test {
+ public:
+ ResetSettingsHandlerTest() : handler_(&profile_, false, &web_ui_) {
+ }
+
+ TestingResetSettingsHandler* handler() {
+ return &handler_;
+ }
+
+ content::TestWebUI* web_ui() {
+ return &web_ui_;
+ }
+
+ private:
+ // The order here matters.
+ content::TestBrowserThreadBundle thread_bundle_;
+ TestingProfile profile_;
+ content::TestWebUI web_ui_;
+ TestingResetSettingsHandler handler_;
+};
+
Dan Beam 2015/12/02 04:40:08 remove extra \n
dpapad 2015/12/02 19:55:22 Done.
+
+TEST_F(ResetSettingsHandlerTest, HandleResetProfileSettings) {
+ base::ListValue list;
+ list.AppendBoolean(false);
+ handler()->HandleResetProfileSettings(&list);
+ // Check that the delegate ProfileResetter was called.
+ 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.
+ // Check that Javascript side is notified after resetting is done.
+ EXPECT_EQ("SettingsResetPage.doneResetting",
+ web_ui()->call_data()[0]->function_name());
+}
+
Dan Beam 2015/12/02 04:40:08 remove extra \n
dpapad 2015/12/02 19:55:22 Done.
+
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698