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

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

Powered by Google App Engine
This is Rietveld 408576698