| 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/ui/webui/site_settings_helper.h" | 9 #include "chrome/browser/ui/webui/site_settings_helper.h" |
| 10 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 TestingProfile profile_; | 134 TestingProfile profile_; |
| 135 content::TestWebUI web_ui_; | 135 content::TestWebUI web_ui_; |
| 136 SiteSettingsHandler handler_; | 136 SiteSettingsHandler handler_; |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 TEST_F(SiteSettingsHandlerTest, GetAndSetDefault) { | 139 TEST_F(SiteSettingsHandlerTest, GetAndSetDefault) { |
| 140 ContentSettingsType type = CONTENT_SETTINGS_TYPE_NOTIFICATIONS; | 140 ContentSettingsType type = CONTENT_SETTINGS_TYPE_NOTIFICATIONS; |
| 141 | 141 |
| 142 // Test the JS -> C++ -> JS callback path for getting and setting defaults. | 142 // Test the JS -> C++ -> JS callback path for getting and setting defaults. |
| 143 base::ListValue getArgs; | 143 base::ListValue getArgs; |
| 144 getArgs.Append(new base::StringValue(kCallbackId)); | 144 getArgs.AppendString(kCallbackId); |
| 145 getArgs.Append(new base::FundamentalValue(type)); | 145 getArgs.AppendInteger(type); |
| 146 handler()->HandleGetDefaultValueForContentType(&getArgs); | 146 handler()->HandleGetDefaultValueForContentType(&getArgs); |
| 147 ValidateDefault(true, 1U); | 147 ValidateDefault(true, 1U); |
| 148 | 148 |
| 149 // Set the default to 'Blocked'. | 149 // Set the default to 'Blocked'. |
| 150 base::ListValue setArgs; | 150 base::ListValue setArgs; |
| 151 setArgs.Append(new base::FundamentalValue(type)); | 151 setArgs.AppendInteger(type); |
| 152 setArgs.Append(new base::StringValue("block")); | 152 setArgs.AppendString("block"); |
| 153 handler()->HandleSetDefaultValueForContentType(&setArgs); | 153 handler()->HandleSetDefaultValueForContentType(&setArgs); |
| 154 | 154 |
| 155 EXPECT_EQ(2U, web_ui()->call_data().size()); | 155 EXPECT_EQ(2U, web_ui()->call_data().size()); |
| 156 | 156 |
| 157 // Verify that the default has been set to 'Blocked'. | 157 // Verify that the default has been set to 'Blocked'. |
| 158 handler()->HandleGetDefaultValueForContentType(&getArgs); | 158 handler()->HandleGetDefaultValueForContentType(&getArgs); |
| 159 ValidateDefault(false, 3U); | 159 ValidateDefault(false, 3U); |
| 160 } | 160 } |
| 161 | 161 |
| 162 TEST_F(SiteSettingsHandlerTest, Origins) { | 162 TEST_F(SiteSettingsHandlerTest, Origins) { |
| 163 ContentSettingsType type = CONTENT_SETTINGS_TYPE_NOTIFICATIONS; | 163 ContentSettingsType type = CONTENT_SETTINGS_TYPE_NOTIFICATIONS; |
| 164 | 164 |
| 165 // Test the JS -> C++ -> JS callback path for configuring origins, by setting | 165 // Test the JS -> C++ -> JS callback path for configuring origins, by setting |
| 166 // Google.com to blocked. | 166 // Google.com to blocked. |
| 167 base::ListValue setArgs; | 167 base::ListValue setArgs; |
| 168 std::string google("http://www.google.com"); | 168 std::string google("http://www.google.com"); |
| 169 setArgs.Append(new base::StringValue(google)); // Primary pattern. | 169 setArgs.AppendString(google); // Primary pattern. |
| 170 setArgs.Append(new base::StringValue(google)); // Secondary pattern. | 170 setArgs.AppendString(google); // Secondary pattern. |
| 171 setArgs.Append(new base::FundamentalValue(type)); | 171 setArgs.AppendInteger(type); |
| 172 setArgs.Append(new base::StringValue("block")); | 172 setArgs.AppendString("block"); |
| 173 handler()->HandleSetCategoryPermissionForOrigin(&setArgs); | 173 handler()->HandleSetCategoryPermissionForOrigin(&setArgs); |
| 174 EXPECT_EQ(1U, web_ui()->call_data().size()); | 174 EXPECT_EQ(1U, web_ui()->call_data().size()); |
| 175 | 175 |
| 176 // Verify the change was successful. | 176 // Verify the change was successful. |
| 177 base::ListValue listArgs; | 177 base::ListValue listArgs; |
| 178 listArgs.Append(new base::StringValue(kCallbackId)); | 178 listArgs.AppendString(kCallbackId); |
| 179 listArgs.Append(new base::FundamentalValue(type)); | 179 listArgs.AppendInteger(type); |
| 180 handler()->HandleGetExceptionList(&listArgs); | 180 handler()->HandleGetExceptionList(&listArgs); |
| 181 ValidateOrigin(google, google, "block", "preference", 2U); | 181 ValidateOrigin(google, google, "block", "preference", 2U); |
| 182 | 182 |
| 183 // Reset things back to how they were. | 183 // Reset things back to how they were. |
| 184 base::ListValue resetArgs; | 184 base::ListValue resetArgs; |
| 185 resetArgs.Append(new base::StringValue(google)); | 185 resetArgs.AppendString(google); |
| 186 resetArgs.Append(new base::StringValue(google)); | 186 resetArgs.AppendString(google); |
| 187 resetArgs.Append(new base::FundamentalValue(type)); | 187 resetArgs.AppendInteger(type); |
| 188 handler()->HandleResetCategoryPermissionForOrigin(&resetArgs); | 188 handler()->HandleResetCategoryPermissionForOrigin(&resetArgs); |
| 189 EXPECT_EQ(3U, web_ui()->call_data().size()); | 189 EXPECT_EQ(3U, web_ui()->call_data().size()); |
| 190 | 190 |
| 191 // Verify the reset was successful. | 191 // Verify the reset was successful. |
| 192 handler()->HandleGetExceptionList(&listArgs); | 192 handler()->HandleGetExceptionList(&listArgs); |
| 193 ValidateNoOrigin(4U); | 193 ValidateNoOrigin(4U); |
| 194 } | 194 } |
| 195 | 195 |
| 196 TEST_F(SiteSettingsHandlerTest, Patterns) { | 196 TEST_F(SiteSettingsHandlerTest, Patterns) { |
| 197 base::ListValue args; | 197 base::ListValue args; |
| 198 std::string pattern("[*.]google.com"); | 198 std::string pattern("[*.]google.com"); |
| 199 args.Append(new base::StringValue(kCallbackId)); | 199 args.AppendString(kCallbackId); |
| 200 args.Append(new base::StringValue(pattern)); | 200 args.AppendString(pattern); |
| 201 handler()->HandleIsPatternValid(&args); | 201 handler()->HandleIsPatternValid(&args); |
| 202 ValidatePattern(true, 1U); | 202 ValidatePattern(true, 1U); |
| 203 | 203 |
| 204 base::ListValue invalid; | 204 base::ListValue invalid; |
| 205 std::string bad_pattern(";"); | 205 std::string bad_pattern(";"); |
| 206 invalid.Append(new base::StringValue(kCallbackId)); | 206 invalid.AppendString(kCallbackId); |
| 207 invalid.Append(new base::StringValue(bad_pattern)); | 207 invalid.AppendString(bad_pattern); |
| 208 handler()->HandleIsPatternValid(&invalid); | 208 handler()->HandleIsPatternValid(&invalid); |
| 209 ValidatePattern(false, 2U); | 209 ValidatePattern(false, 2U); |
| 210 } | 210 } |
| 211 | 211 |
| 212 } // namespace settings | 212 } // namespace settings |
| OLD | NEW |