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

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/chrome_notification_types.h"
9 #include "chrome/browser/ui/webui/site_settings_helper.h" 10 #include "chrome/browser/ui/webui/site_settings_helper.h"
10 #include "chrome/test/base/testing_profile.h" 11 #include "chrome/test/base/testing_profile.h"
11 #include "components/content_settings/core/common/content_settings.h" 12 #include "components/content_settings/core/common/content_settings.h"
12 #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"
13 #include "content/public/browser/web_ui_data_source.h" 15 #include "content/public/browser/web_ui_data_source.h"
14 #include "content/public/test/test_browser_thread_bundle.h" 16 #include "content/public/test/test_browser_thread_bundle.h"
15 #include "content/public/test/test_web_ui.h" 17 #include "content/public/test/test_web_ui.h"
16 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
17 19
18 namespace { 20 namespace {
19 21
20 const char kCallbackId[] = "test-callback-id"; 22 const char kCallbackId[] = "test-callback-id";
21 23
22 } 24 }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 125
124 bool success = false; 126 bool success = false;
125 ASSERT_TRUE(data.arg2()->GetAsBoolean(&success)); 127 ASSERT_TRUE(data.arg2()->GetAsBoolean(&success));
126 ASSERT_TRUE(success); 128 ASSERT_TRUE(success);
127 129
128 bool valid; 130 bool valid;
129 ASSERT_TRUE(data.arg3()->GetAsBoolean(&valid)); 131 ASSERT_TRUE(data.arg3()->GetAsBoolean(&valid));
130 EXPECT_EQ(expected_validity, valid); 132 EXPECT_EQ(expected_validity, valid);
131 } 133 }
132 134
135 void ValidateIncognitoExists(
136 bool expected_incognito, size_t expected_total_calls) {
137 EXPECT_EQ(expected_total_calls, web_ui()->call_data().size());
138
139 const content::TestWebUI::CallData& data = *web_ui()->call_data().back();
140 EXPECT_EQ("cr.webUIListenerCallback", data.function_name());
141
142 std::string callback_id;
143 ASSERT_TRUE(data.arg1()->GetAsString(&callback_id));
144 EXPECT_EQ("onIncognitoStatusChanged", callback_id);
145
146 bool incognito;
147 ASSERT_TRUE(data.arg2()->GetAsBoolean(&incognito));
148 EXPECT_EQ(expected_incognito, incognito);
149 }
150
151 void CreateIncognitoProfile() {
152 incognito_profile_ = TestingProfile::Builder().BuildIncognito(&profile_);
153 }
154
155 void DestroyIncognitoProfile() {
156 content::NotificationService::current()->Notify(
157 chrome::NOTIFICATION_PROFILE_DESTROYED,
158 content::Source<Profile>(static_cast<Profile*>(incognito_profile_)),
159 content::NotificationService::NoDetails());
160 profile_.SetOffTheRecordProfile(nullptr);
161 ASSERT_FALSE(profile_.HasOffTheRecordProfile());
162 incognito_profile_ = nullptr;
163 }
164
133 private: 165 private:
134 content::TestBrowserThreadBundle thread_bundle_; 166 content::TestBrowserThreadBundle thread_bundle_;
135 TestingProfile profile_; 167 TestingProfile profile_;
168 TestingProfile* incognito_profile_;
136 content::TestWebUI web_ui_; 169 content::TestWebUI web_ui_;
137 SiteSettingsHandler handler_; 170 SiteSettingsHandler handler_;
138 }; 171 };
139 172
140 TEST_F(SiteSettingsHandlerTest, GetAndSetDefault) { 173 TEST_F(SiteSettingsHandlerTest, GetAndSetDefault) {
141 // Test the JS -> C++ -> JS callback path for getting and setting defaults. 174 // Test the JS -> C++ -> JS callback path for getting and setting defaults.
142 base::ListValue getArgs; 175 base::ListValue getArgs;
143 getArgs.AppendString(kCallbackId); 176 getArgs.AppendString(kCallbackId);
144 getArgs.AppendString("notifications"); 177 getArgs.AppendString("notifications");
145 handler()->HandleGetDefaultValueForContentType(&getArgs); 178 handler()->HandleGetDefaultValueForContentType(&getArgs);
(...skipping 14 matching lines...) Expand all
160 193
161 TEST_F(SiteSettingsHandlerTest, Origins) { 194 TEST_F(SiteSettingsHandlerTest, Origins) {
162 // Test the JS -> C++ -> JS callback path for configuring origins, by setting 195 // Test the JS -> C++ -> JS callback path for configuring origins, by setting
163 // Google.com to blocked. 196 // Google.com to blocked.
164 base::ListValue setArgs; 197 base::ListValue setArgs;
165 std::string google("http://www.google.com"); 198 std::string google("http://www.google.com");
166 setArgs.AppendString(google); // Primary pattern. 199 setArgs.AppendString(google); // Primary pattern.
167 setArgs.AppendString(google); // Secondary pattern. 200 setArgs.AppendString(google); // Secondary pattern.
168 setArgs.AppendString("notifications"); 201 setArgs.AppendString("notifications");
169 setArgs.AppendString("block"); 202 setArgs.AppendString("block");
203 setArgs.AppendBoolean(false); // Incognito.
170 handler()->HandleSetCategoryPermissionForOrigin(&setArgs); 204 handler()->HandleSetCategoryPermissionForOrigin(&setArgs);
171 EXPECT_EQ(1U, web_ui()->call_data().size()); 205 EXPECT_EQ(1U, web_ui()->call_data().size());
172 206
173 // Verify the change was successful. 207 // Verify the change was successful.
174 base::ListValue listArgs; 208 base::ListValue listArgs;
175 listArgs.AppendString(kCallbackId); 209 listArgs.AppendString(kCallbackId);
176 listArgs.AppendString("notifications"); 210 listArgs.AppendString("notifications");
177 handler()->HandleGetExceptionList(&listArgs); 211 handler()->HandleGetExceptionList(&listArgs);
178 ValidateOrigin(google, google, "block", "preference", 2U); 212 ValidateOrigin(google, google, "block", "preference", 2U);
179 213
180 // Reset things back to how they were. 214 // Reset things back to how they were.
181 base::ListValue resetArgs; 215 base::ListValue resetArgs;
182 resetArgs.AppendString(google); 216 resetArgs.AppendString(google);
183 resetArgs.AppendString(google); 217 resetArgs.AppendString(google);
184 resetArgs.AppendString("notifications"); 218 resetArgs.AppendString("notifications");
219 resetArgs.AppendBoolean(false); // Incognito.
185 handler()->HandleResetCategoryPermissionForOrigin(&resetArgs); 220 handler()->HandleResetCategoryPermissionForOrigin(&resetArgs);
186 EXPECT_EQ(3U, web_ui()->call_data().size()); 221 EXPECT_EQ(3U, web_ui()->call_data().size());
187 222
188 // Verify the reset was successful. 223 // Verify the reset was successful.
189 handler()->HandleGetExceptionList(&listArgs); 224 handler()->HandleGetExceptionList(&listArgs);
190 ValidateNoOrigin(4U); 225 ValidateNoOrigin(4U);
191 } 226 }
192 227
193 TEST_F(SiteSettingsHandlerTest, Patterns) { 228 TEST_F(SiteSettingsHandlerTest, Patterns) {
194 base::ListValue args; 229 base::ListValue args;
195 std::string pattern("[*.]google.com"); 230 std::string pattern("[*.]google.com");
196 args.AppendString(kCallbackId); 231 args.AppendString(kCallbackId);
197 args.AppendString(pattern); 232 args.AppendString(pattern);
198 handler()->HandleIsPatternValid(&args); 233 handler()->HandleIsPatternValid(&args);
199 ValidatePattern(true, 1U); 234 ValidatePattern(true, 1U);
200 235
201 base::ListValue invalid; 236 base::ListValue invalid;
202 std::string bad_pattern(";"); 237 std::string bad_pattern(";");
203 invalid.AppendString(kCallbackId); 238 invalid.AppendString(kCallbackId);
204 invalid.AppendString(bad_pattern); 239 invalid.AppendString(bad_pattern);
205 handler()->HandleIsPatternValid(&invalid); 240 handler()->HandleIsPatternValid(&invalid);
206 ValidatePattern(false, 2U); 241 ValidatePattern(false, 2U);
207 } 242 }
208 243
244 TEST_F(SiteSettingsHandlerTest, Incognito) {
245 base::ListValue args;
246 handler()->HandleUpdateIncognitoStatus(&args);
247 ValidateIncognitoExists(false, 1U);
248
249 CreateIncognitoProfile();
250 ValidateIncognitoExists(true, 2U);
251
252 DestroyIncognitoProfile();
253 ValidateIncognitoExists(false, 3U);
254 }
255
209 } // namespace settings 256 } // namespace settings
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/settings/site_settings_handler.cc ('k') | chrome/browser/ui/webui/site_settings_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698