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

Side by Side Diff: chrome/browser/ui/webui/settings/site_settings_handler_unittest.cc

Issue 1909413002: Site Settings: Implement dialog for adding site exceptions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback Created 4 years, 8 months 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
« no previous file with comments | « chrome/browser/ui/webui/settings/site_settings_handler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 96
97 bool success = false; 97 bool success = false;
98 ASSERT_TRUE(data.arg2()->GetAsBoolean(&success)); 98 ASSERT_TRUE(data.arg2()->GetAsBoolean(&success));
99 ASSERT_TRUE(success); 99 ASSERT_TRUE(success);
100 100
101 const base::ListValue* exceptions; 101 const base::ListValue* exceptions;
102 ASSERT_TRUE(data.arg3()->GetAsList(&exceptions)); 102 ASSERT_TRUE(data.arg3()->GetAsList(&exceptions));
103 EXPECT_EQ(0U, exceptions->GetSize()); 103 EXPECT_EQ(0U, exceptions->GetSize());
104 } 104 }
105 105
106 void ValidatePattern(bool expected_validity, size_t expected_total_calls) {
107 EXPECT_EQ(expected_total_calls, web_ui()->call_data().size());
108
109 const content::TestWebUI::CallData& data = *web_ui()->call_data().back();
110 EXPECT_EQ("cr.webUIResponse", data.function_name());
111
112 std::string callback_id;
113 ASSERT_TRUE(data.arg1()->GetAsString(&callback_id));
114 EXPECT_EQ(kCallbackId, callback_id);
115
116 bool success = false;
117 ASSERT_TRUE(data.arg2()->GetAsBoolean(&success));
118 ASSERT_TRUE(success);
119
120 bool valid;
121 ASSERT_TRUE(data.arg3()->GetAsBoolean(&valid));
122 EXPECT_EQ(expected_validity, valid);
123 }
124
106 private: 125 private:
107 content::TestBrowserThreadBundle thread_bundle_; 126 content::TestBrowserThreadBundle thread_bundle_;
108 TestingProfile profile_; 127 TestingProfile profile_;
109 content::TestWebUI web_ui_; 128 content::TestWebUI web_ui_;
110 }; 129 };
111 130
112 TEST_F(SiteSettingsHandlerTest, GetAndSetDefault) { 131 TEST_F(SiteSettingsHandlerTest, GetAndSetDefault) {
113 SiteSettingsHandler handler(profile()); 132 SiteSettingsHandler handler(profile());
114 handler.set_web_ui(web_ui()); 133 handler.set_web_ui(web_ui());
115 134
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 resetArgs.Append(new base::StringValue(google)); 184 resetArgs.Append(new base::StringValue(google));
166 resetArgs.Append(new base::FundamentalValue(type)); 185 resetArgs.Append(new base::FundamentalValue(type));
167 handler.HandleResetCategoryPermissionForOrigin(&resetArgs); 186 handler.HandleResetCategoryPermissionForOrigin(&resetArgs);
168 EXPECT_EQ(3U, web_ui()->call_data().size()); 187 EXPECT_EQ(3U, web_ui()->call_data().size());
169 188
170 // Verify the reset was successful. 189 // Verify the reset was successful.
171 handler.HandleGetExceptionList(&listArgs); 190 handler.HandleGetExceptionList(&listArgs);
172 ValidateNoOrigin(4U); 191 ValidateNoOrigin(4U);
173 } 192 }
174 193
194 TEST_F(SiteSettingsHandlerTest, Patterns) {
195 SiteSettingsHandler handler(profile());
196 handler.set_web_ui(web_ui());
197
198 base::ListValue args;
199 std::string pattern("[*.]google.com");
200 args.Append(new base::StringValue(kCallbackId));
201 args.Append(new base::StringValue(pattern));
202 handler.HandleIsPatternValid(&args);
203 ValidatePattern(true, 1U);
204
205 base::ListValue invalid;
206 std::string bad_pattern(";");
207 invalid.Append(new base::StringValue(kCallbackId));
208 invalid.Append(new base::StringValue(bad_pattern));
209 handler.HandleIsPatternValid(&invalid);
210 ValidatePattern(false, 2U);
211 }
212
175 } // namespace settings 213 } // namespace settings
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/settings/site_settings_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698