Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/ui/webui/settings/site_settings_handler.h" | 5 #include "chrome/browser/ui/webui/settings/site_settings_handler.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/ui/webui/site_settings_helper.h" | 10 #include "chrome/browser/ui/webui/site_settings_helper.h" |
| 11 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
| 12 #include "components/content_settings/core/common/content_settings.h" | 12 #include "components/content_settings/core/common/content_settings.h" |
| 13 #include "components/content_settings/core/common/content_settings_types.h" | 13 #include "components/content_settings/core/common/content_settings_types.h" |
| 14 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
| 15 #include "content/public/browser/web_ui_data_source.h" | 15 #include "content/public/browser/web_ui_data_source.h" |
| 16 #include "content/public/test/test_browser_thread_bundle.h" | 16 #include "content/public/test/test_browser_thread_bundle.h" |
| 17 #include "content/public/test/test_web_ui.h" | 17 #include "content/public/test/test_web_ui.h" |
| 18 #include "extensions/common/extension_builder.h" | 18 #include "extensions/common/extension_builder.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 const char kCallbackId[] = "test-callback-id"; | 23 const char kCallbackId[] = "test-callback-id"; |
| 24 const char kSetting[] = "setting"; | |
| 25 const char kSource[] = "source"; | |
| 24 | 26 |
| 25 } | 27 } |
| 26 | 28 |
| 27 namespace settings { | 29 namespace settings { |
| 28 | 30 |
| 29 class SiteSettingsHandlerTest : public testing::Test { | 31 class SiteSettingsHandlerTest : public testing::Test { |
| 30 public: | 32 public: |
| 31 SiteSettingsHandlerTest() : handler_(&profile_) {} | 33 SiteSettingsHandlerTest() : handler_(&profile_) {} |
| 32 | 34 |
| 33 void SetUp() override { | 35 void SetUp() override { |
| 34 handler()->set_web_ui(web_ui()); | 36 handler()->set_web_ui(web_ui()); |
| 35 handler()->AllowJavascript(); | 37 handler()->AllowJavascript(); |
| 36 web_ui()->ClearTrackedCalls(); | 38 web_ui()->ClearTrackedCalls(); |
| 37 } | 39 } |
| 38 | 40 |
| 39 Profile* profile() { return &profile_; } | 41 Profile* profile() { return &profile_; } |
| 40 content::TestWebUI* web_ui() { return &web_ui_; } | 42 content::TestWebUI* web_ui() { return &web_ui_; } |
| 41 SiteSettingsHandler* handler() { return &handler_; } | 43 SiteSettingsHandler* handler() { return &handler_; } |
| 42 | 44 |
| 43 void ValidateDefault(const std::string& expected_default, | 45 void ValidateDefault(const std::string& expected_setting, |
| 46 const std::string& expected_source, | |
| 44 size_t expected_total_calls) { | 47 size_t expected_total_calls) { |
| 45 EXPECT_EQ(expected_total_calls, web_ui()->call_data().size()); | 48 EXPECT_EQ(expected_total_calls, web_ui()->call_data().size()); |
| 46 | 49 |
| 47 const content::TestWebUI::CallData& data = *web_ui()->call_data().back(); | 50 const content::TestWebUI::CallData& data = *web_ui()->call_data().back(); |
| 48 EXPECT_EQ("cr.webUIResponse", data.function_name()); | 51 EXPECT_EQ("cr.webUIResponse", data.function_name()); |
| 49 | 52 |
| 50 std::string callback_id; | 53 std::string callback_id; |
| 51 ASSERT_TRUE(data.arg1()->GetAsString(&callback_id)); | 54 ASSERT_TRUE(data.arg1()->GetAsString(&callback_id)); |
| 52 EXPECT_EQ(kCallbackId, callback_id); | 55 EXPECT_EQ(kCallbackId, callback_id); |
| 53 | 56 |
| 54 bool success = false; | 57 bool success = false; |
| 55 ASSERT_TRUE(data.arg2()->GetAsBoolean(&success)); | 58 ASSERT_TRUE(data.arg2()->GetAsBoolean(&success)); |
| 56 ASSERT_TRUE(success); | 59 ASSERT_TRUE(success); |
| 57 | 60 |
| 58 std::string default_value; | 61 const base::DictionaryValue* default_value = NULL; |
|
Dan Beam
2016/11/29 05:17:14
use nullptr instead of NULL in new code
dschuyler
2016/11/29 22:28:12
Done.
| |
| 59 ASSERT_TRUE(data.arg3()->GetAsString(&default_value)); | 62 ASSERT_TRUE(data.arg3()->GetAsDictionary(&default_value)); |
| 60 EXPECT_EQ(expected_default, default_value); | 63 std::string setting; |
| 64 ASSERT_TRUE(default_value->GetString(kSetting, &setting)); | |
| 65 EXPECT_EQ(expected_setting, setting); | |
| 66 std::string source; | |
| 67 ASSERT_TRUE(default_value->GetString(kSource, &source)); | |
| 68 EXPECT_EQ(expected_source, source); | |
| 61 } | 69 } |
| 62 | 70 |
| 63 void ValidateOrigin( | 71 void ValidateOrigin( |
| 64 const std::string& expected_origin, | 72 const std::string& expected_origin, |
| 65 const std::string& expected_embedding, | 73 const std::string& expected_embedding, |
| 66 const std::string& expected_setting, | 74 const std::string& expected_setting, |
| 67 const std::string& expected_source, | 75 const std::string& expected_source, |
| 68 size_t expected_total_calls) { | 76 size_t expected_total_calls) { |
| 69 EXPECT_EQ(expected_total_calls, web_ui()->call_data().size()); | 77 EXPECT_EQ(expected_total_calls, web_ui()->call_data().size()); |
| 70 | 78 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 content::TestWebUI web_ui_; | 209 content::TestWebUI web_ui_; |
| 202 SiteSettingsHandler handler_; | 210 SiteSettingsHandler handler_; |
| 203 }; | 211 }; |
| 204 | 212 |
| 205 TEST_F(SiteSettingsHandlerTest, GetAndSetDefault) { | 213 TEST_F(SiteSettingsHandlerTest, GetAndSetDefault) { |
| 206 // Test the JS -> C++ -> JS callback path for getting and setting defaults. | 214 // Test the JS -> C++ -> JS callback path for getting and setting defaults. |
| 207 base::ListValue getArgs; | 215 base::ListValue getArgs; |
| 208 getArgs.AppendString(kCallbackId); | 216 getArgs.AppendString(kCallbackId); |
| 209 getArgs.AppendString("notifications"); | 217 getArgs.AppendString("notifications"); |
| 210 handler()->HandleGetDefaultValueForContentType(&getArgs); | 218 handler()->HandleGetDefaultValueForContentType(&getArgs); |
| 211 ValidateDefault("ask", 1U); | 219 ValidateDefault("ask", "default", 1U); |
| 212 | 220 |
| 213 // Set the default to 'Blocked'. | 221 // Set the default to 'Blocked'. |
| 214 base::ListValue setArgs; | 222 base::ListValue setArgs; |
| 215 setArgs.AppendString("notifications"); | 223 setArgs.AppendString("notifications"); |
| 216 setArgs.AppendString("block"); | 224 setArgs.AppendString("block"); |
| 217 handler()->HandleSetDefaultValueForContentType(&setArgs); | 225 handler()->HandleSetDefaultValueForContentType(&setArgs); |
| 218 | 226 |
| 219 EXPECT_EQ(2U, web_ui()->call_data().size()); | 227 EXPECT_EQ(2U, web_ui()->call_data().size()); |
| 220 | 228 |
| 221 // Verify that the default has been set to 'Blocked'. | 229 // Verify that the default has been set to 'Blocked'. |
| 222 handler()->HandleGetDefaultValueForContentType(&getArgs); | 230 handler()->HandleGetDefaultValueForContentType(&getArgs); |
| 223 ValidateDefault("block", 3U); | 231 ValidateDefault("block", "default", 3U); |
| 224 } | 232 } |
| 225 | 233 |
| 226 TEST_F(SiteSettingsHandlerTest, Origins) { | 234 TEST_F(SiteSettingsHandlerTest, Origins) { |
| 227 // Test the JS -> C++ -> JS callback path for configuring origins, by setting | 235 // Test the JS -> C++ -> JS callback path for configuring origins, by setting |
| 228 // Google.com to blocked. | 236 // Google.com to blocked. |
| 229 base::ListValue setArgs; | 237 base::ListValue setArgs; |
| 230 std::string google("http://www.google.com"); | 238 std::string google("http://www.google.com"); |
| 231 setArgs.AppendString(google); // Primary pattern. | 239 setArgs.AppendString(google); // Primary pattern. |
| 232 setArgs.AppendString(google); // Secondary pattern. | 240 setArgs.AppendString(google); // Secondary pattern. |
| 233 setArgs.AppendString("notifications"); | 241 setArgs.AppendString("notifications"); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 args.AppendString("http://www.google.com"); | 361 args.AppendString("http://www.google.com"); |
| 354 handler()->HandleRemoveZoomLevel(&args); | 362 handler()->HandleRemoveZoomLevel(&args); |
| 355 ValidateZoom("", "", 3U); | 363 ValidateZoom("", "", 3U); |
| 356 | 364 |
| 357 double default_level = host_zoom_map->GetDefaultZoomLevel(); | 365 double default_level = host_zoom_map->GetDefaultZoomLevel(); |
| 358 double level = host_zoom_map->GetZoomLevelForHostAndScheme("http", host); | 366 double level = host_zoom_map->GetZoomLevelForHostAndScheme("http", host); |
| 359 EXPECT_EQ(default_level, level); | 367 EXPECT_EQ(default_level, level); |
| 360 } | 368 } |
| 361 | 369 |
| 362 } // namespace settings | 370 } // namespace settings |
| OLD | NEW |