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

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

Issue 2298283002: Site Settings Desktop: Support adding exceptions for incognito mode. (Closed)
Patch Set: Fix remaining tests Created 4 years, 3 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
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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 123
124 bool success = false; 124 bool success = false;
125 ASSERT_TRUE(data.arg2()->GetAsBoolean(&success)); 125 ASSERT_TRUE(data.arg2()->GetAsBoolean(&success));
126 ASSERT_TRUE(success); 126 ASSERT_TRUE(success);
127 127
128 bool valid; 128 bool valid;
129 ASSERT_TRUE(data.arg3()->GetAsBoolean(&valid)); 129 ASSERT_TRUE(data.arg3()->GetAsBoolean(&valid));
130 EXPECT_EQ(expected_validity, valid); 130 EXPECT_EQ(expected_validity, valid);
131 } 131 }
132 132
133 void ValidateIncognitoExists(
134 bool expected_incognito, size_t expected_total_calls) {
135 EXPECT_EQ(expected_total_calls, web_ui()->call_data().size());
136
137 const content::TestWebUI::CallData& data = *web_ui()->call_data().back();
138 EXPECT_EQ("cr.webUIListenerCallback", data.function_name());
139
140 std::string callback_id;
141 ASSERT_TRUE(data.arg1()->GetAsString(&callback_id));
142 EXPECT_EQ("onIncognitoStatusChanged", callback_id);
143
144 bool incognito;
145 ASSERT_TRUE(data.arg2()->GetAsBoolean(&incognito));
146 EXPECT_EQ(expected_incognito, incognito);
147 }
148
149 void CreateIncognitoProfile() {
150 incognito_profile_ = TestingProfile::Builder().BuildIncognito(&profile_);
151 }
152
153 void DestroyIncognitoProfile() {
154 profile_.DestroyOffTheRecordProfile();
155 ASSERT_FALSE(profile_.HasOffTheRecordProfile());
156 incognito_profile_ = nullptr;
157 }
158
133 private: 159 private:
134 content::TestBrowserThreadBundle thread_bundle_; 160 content::TestBrowserThreadBundle thread_bundle_;
135 TestingProfile profile_; 161 TestingProfile profile_;
162 TestingProfile* incognito_profile_;
136 content::TestWebUI web_ui_; 163 content::TestWebUI web_ui_;
137 SiteSettingsHandler handler_; 164 SiteSettingsHandler handler_;
138 }; 165 };
139 166
140 TEST_F(SiteSettingsHandlerTest, GetAndSetDefault) { 167 TEST_F(SiteSettingsHandlerTest, GetAndSetDefault) {
141 // Test the JS -> C++ -> JS callback path for getting and setting defaults. 168 // Test the JS -> C++ -> JS callback path for getting and setting defaults.
142 base::ListValue getArgs; 169 base::ListValue getArgs;
143 getArgs.AppendString(kCallbackId); 170 getArgs.AppendString(kCallbackId);
144 getArgs.AppendString("notifications"); 171 getArgs.AppendString("notifications");
145 handler()->HandleGetDefaultValueForContentType(&getArgs); 172 handler()->HandleGetDefaultValueForContentType(&getArgs);
(...skipping 14 matching lines...) Expand all
160 187
161 TEST_F(SiteSettingsHandlerTest, Origins) { 188 TEST_F(SiteSettingsHandlerTest, Origins) {
162 // Test the JS -> C++ -> JS callback path for configuring origins, by setting 189 // Test the JS -> C++ -> JS callback path for configuring origins, by setting
163 // Google.com to blocked. 190 // Google.com to blocked.
164 base::ListValue setArgs; 191 base::ListValue setArgs;
165 std::string google("http://www.google.com"); 192 std::string google("http://www.google.com");
166 setArgs.AppendString(google); // Primary pattern. 193 setArgs.AppendString(google); // Primary pattern.
167 setArgs.AppendString(google); // Secondary pattern. 194 setArgs.AppendString(google); // Secondary pattern.
168 setArgs.AppendString("notifications"); 195 setArgs.AppendString("notifications");
169 setArgs.AppendString("block"); 196 setArgs.AppendString("block");
197 setArgs.AppendBoolean(false); // Incognito.
170 handler()->HandleSetCategoryPermissionForOrigin(&setArgs); 198 handler()->HandleSetCategoryPermissionForOrigin(&setArgs);
171 EXPECT_EQ(1U, web_ui()->call_data().size()); 199 EXPECT_EQ(1U, web_ui()->call_data().size());
172 200
173 // Verify the change was successful. 201 // Verify the change was successful.
174 base::ListValue listArgs; 202 base::ListValue listArgs;
175 listArgs.AppendString(kCallbackId); 203 listArgs.AppendString(kCallbackId);
176 listArgs.AppendString("notifications"); 204 listArgs.AppendString("notifications");
177 handler()->HandleGetExceptionList(&listArgs); 205 handler()->HandleGetExceptionList(&listArgs);
178 ValidateOrigin(google, google, "block", "preference", 2U); 206 ValidateOrigin(google, google, "block", "preference", 2U);
179 207
180 // Reset things back to how they were. 208 // Reset things back to how they were.
181 base::ListValue resetArgs; 209 base::ListValue resetArgs;
182 resetArgs.AppendString(google); 210 resetArgs.AppendString(google);
183 resetArgs.AppendString(google); 211 resetArgs.AppendString(google);
184 resetArgs.AppendString("notifications"); 212 resetArgs.AppendString("notifications");
213 resetArgs.AppendBoolean(false); // Incognito.
185 handler()->HandleResetCategoryPermissionForOrigin(&resetArgs); 214 handler()->HandleResetCategoryPermissionForOrigin(&resetArgs);
186 EXPECT_EQ(3U, web_ui()->call_data().size()); 215 EXPECT_EQ(3U, web_ui()->call_data().size());
187 216
188 // Verify the reset was successful. 217 // Verify the reset was successful.
189 handler()->HandleGetExceptionList(&listArgs); 218 handler()->HandleGetExceptionList(&listArgs);
190 ValidateNoOrigin(4U); 219 ValidateNoOrigin(4U);
191 } 220 }
192 221
193 TEST_F(SiteSettingsHandlerTest, Patterns) { 222 TEST_F(SiteSettingsHandlerTest, Patterns) {
194 base::ListValue args; 223 base::ListValue args;
195 std::string pattern("[*.]google.com"); 224 std::string pattern("[*.]google.com");
196 args.AppendString(kCallbackId); 225 args.AppendString(kCallbackId);
197 args.AppendString(pattern); 226 args.AppendString(pattern);
198 handler()->HandleIsPatternValid(&args); 227 handler()->HandleIsPatternValid(&args);
199 ValidatePattern(true, 1U); 228 ValidatePattern(true, 1U);
200 229
201 base::ListValue invalid; 230 base::ListValue invalid;
202 std::string bad_pattern(";"); 231 std::string bad_pattern(";");
203 invalid.AppendString(kCallbackId); 232 invalid.AppendString(kCallbackId);
204 invalid.AppendString(bad_pattern); 233 invalid.AppendString(bad_pattern);
205 handler()->HandleIsPatternValid(&invalid); 234 handler()->HandleIsPatternValid(&invalid);
206 ValidatePattern(false, 2U); 235 ValidatePattern(false, 2U);
207 } 236 }
208 237
238 TEST_F(SiteSettingsHandlerTest, Incognito) {
239 base::ListValue args;
240 handler()->HandleUpdateIncognitoStatus(&args);
241 ValidateIncognitoExists(false, 1U);
242
243 CreateIncognitoProfile();
244 ValidateIncognitoExists(true, 2U);
245
246 DestroyIncognitoProfile();
247 ValidateIncognitoExists(false, 3U);
248 }
249
209 } // namespace settings 250 } // namespace settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698