| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/google/google_brand.h" |
| 9 #include "chrome/browser/profile_resetter/profile_resetter.h" | 10 #include "chrome/browser/profile_resetter/profile_resetter.h" |
| 10 #include "chrome/browser/ui/webui/settings/reset_settings_handler.h" | 11 #include "chrome/browser/ui/webui/settings/reset_settings_handler.h" |
| 11 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
| 12 #include "content/public/browser/web_ui_data_source.h" | 13 #include "content/public/browser/web_ui_data_source.h" |
| 13 #include "content/public/test/test_browser_thread_bundle.h" | 14 #include "content/public/test/test_browser_thread_bundle.h" |
| 14 #include "content/public/test/test_web_ui.h" | 15 #include "content/public/test/test_web_ui.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 using settings::ResetSettingsHandler; | 18 using settings::ResetSettingsHandler; |
| 18 | 19 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 } | 64 } |
| 64 | 65 |
| 65 private: | 66 private: |
| 66 MockProfileResetter resetter_; | 67 MockProfileResetter resetter_; |
| 67 | 68 |
| 68 DISALLOW_COPY_AND_ASSIGN(TestingResetSettingsHandler); | 69 DISALLOW_COPY_AND_ASSIGN(TestingResetSettingsHandler); |
| 69 }; | 70 }; |
| 70 | 71 |
| 71 class ResetSettingsHandlerTest : public testing::Test { | 72 class ResetSettingsHandlerTest : public testing::Test { |
| 72 public: | 73 public: |
| 73 ResetSettingsHandlerTest() : handler_(&profile_, &web_ui_) { | 74 ResetSettingsHandlerTest() { |
| 75 google_brand::BrandForTesting brand_for_testing(""); |
| 76 handler_.reset(new TestingResetSettingsHandler(&profile_, &web_ui_)); |
| 74 } | 77 } |
| 75 | 78 |
| 76 TestingResetSettingsHandler* handler() { return &handler_; } | 79 TestingResetSettingsHandler* handler() { return handler_.get(); } |
| 77 content::TestWebUI* web_ui() { return &web_ui_; } | 80 content::TestWebUI* web_ui() { return &web_ui_; } |
| 78 | 81 |
| 79 private: | 82 private: |
| 80 // The order here matters. | 83 // The order here matters. |
| 81 content::TestBrowserThreadBundle thread_bundle_; | 84 content::TestBrowserThreadBundle thread_bundle_; |
| 82 TestingProfile profile_; | 85 TestingProfile profile_; |
| 83 content::TestWebUI web_ui_; | 86 content::TestWebUI web_ui_; |
| 84 TestingResetSettingsHandler handler_; | 87 std::unique_ptr<TestingResetSettingsHandler> handler_; |
| 85 }; | 88 }; |
| 86 | 89 |
| 87 TEST_F(ResetSettingsHandlerTest, HandleResetProfileSettings) { | 90 TEST_F(ResetSettingsHandlerTest, HandleResetProfileSettings) { |
| 88 base::ListValue list; | 91 base::ListValue list; |
| 89 std::string expected_callback_id("dummyCallbackId"); | 92 std::string expected_callback_id("dummyCallbackId"); |
| 90 list.AppendString(expected_callback_id); | 93 list.AppendString(expected_callback_id); |
| 91 list.AppendBoolean(false); | 94 list.AppendBoolean(false); |
| 92 handler()->HandleResetProfileSettings(&list); | 95 handler()->HandleResetProfileSettings(&list); |
| 93 // Check that the delegate ProfileResetter was called. | 96 // Check that the delegate ProfileResetter was called. |
| 94 EXPECT_EQ(1u, handler()->resets()); | 97 EXPECT_EQ(1u, handler()->resets()); |
| 95 // Check that Javascript side is notified after resetting is done. | 98 // Check that Javascript side is notified after resetting is done. |
| 96 EXPECT_EQ("cr.webUIResponse", | 99 EXPECT_EQ("cr.webUIResponse", |
| 97 web_ui()->call_data()[0]->function_name()); | 100 web_ui()->call_data()[0]->function_name()); |
| 98 std::string callback_id; | 101 std::string callback_id; |
| 99 EXPECT_TRUE(web_ui()->call_data()[0]->arg1()->GetAsString(&callback_id)); | 102 EXPECT_TRUE(web_ui()->call_data()[0]->arg1()->GetAsString(&callback_id)); |
| 100 EXPECT_EQ(expected_callback_id, callback_id); | 103 EXPECT_EQ(expected_callback_id, callback_id); |
| 101 } | 104 } |
| 102 | 105 |
| 103 } // namespace | 106 } // namespace |
| OLD | NEW |