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

Side by Side Diff: chrome/browser/supervised_user/supervised_user_url_filter_unittest.cc

Issue 2776493005: Convert SupervisedUserResourceThrottle to a NavigationThrottle. (Closed)
Patch Set: Response to comments Created 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/supervised_user/supervised_user_url_filter.h" 5 #include "chrome/browser/supervised_user/supervised_user_url_filter.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/browser/supervised_user/supervised_user_site_list.h" 15 #include "chrome/browser/supervised_user/supervised_user_site_list.h"
16 #include "extensions/features/features.h" 16 #include "extensions/features/features.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "url/gurl.h" 18 #include "url/gurl.h"
19 19
20 class SupervisedUserURLFilterTest : public ::testing::Test, 20 class SupervisedUserURLFilterTest : public ::testing::Test,
21 public SupervisedUserURLFilter::Observer { 21 public SupervisedUserURLFilter::Observer {
22 public: 22 public:
23 SupervisedUserURLFilterTest() : filter_(new SupervisedUserURLFilter) { 23 SupervisedUserURLFilterTest() {
24 filter_->SetDefaultFilteringBehavior(SupervisedUserURLFilter::BLOCK); 24 filter_.SetDefaultFilteringBehavior(SupervisedUserURLFilter::BLOCK);
25 filter_->AddObserver(this); 25 filter_.AddObserver(this);
26 } 26 }
27 27
28 ~SupervisedUserURLFilterTest() override { filter_->RemoveObserver(this); } 28 ~SupervisedUserURLFilterTest() override { filter_.RemoveObserver(this); }
29 29
30 // SupervisedUserURLFilter::Observer: 30 // SupervisedUserURLFilter::Observer:
31 void OnSiteListUpdated() override { run_loop_.Quit(); } 31 void OnSiteListUpdated() override { run_loop_.Quit(); }
32 32
33 protected: 33 protected:
34 bool IsURLWhitelisted(const std::string& url) { 34 bool IsURLWhitelisted(const std::string& url) {
35 return filter_->GetFilteringBehaviorForURL(GURL(url)) == 35 return filter_.GetFilteringBehaviorForURL(GURL(url)) ==
36 SupervisedUserURLFilter::ALLOW; 36 SupervisedUserURLFilter::ALLOW;
37 } 37 }
38 38
39 GURL GetEmbeddedURL(const std::string& url) { 39 GURL GetEmbeddedURL(const std::string& url) {
40 return filter_->GetEmbeddedURL(GURL(url)); 40 return filter_.GetEmbeddedURL(GURL(url));
41 } 41 }
42 42
43 base::MessageLoop message_loop_; 43 base::MessageLoop message_loop_;
44 base::RunLoop run_loop_; 44 base::RunLoop run_loop_;
45 scoped_refptr<SupervisedUserURLFilter> filter_; 45 SupervisedUserURLFilter filter_;
46 }; 46 };
47 47
48 TEST_F(SupervisedUserURLFilterTest, Basic) { 48 TEST_F(SupervisedUserURLFilterTest, Basic) {
49 std::vector<std::string> list; 49 std::vector<std::string> list;
50 // Allow domain and all subdomains, for any filtered scheme. 50 // Allow domain and all subdomains, for any filtered scheme.
51 list.push_back("google.com"); 51 list.push_back("google.com");
52 filter_->SetFromPatternsForTesting(list); 52 filter_.SetFromPatternsForTesting(list);
53 run_loop_.Run(); 53 run_loop_.Run();
54 54
55 EXPECT_TRUE(IsURLWhitelisted("http://google.com")); 55 EXPECT_TRUE(IsURLWhitelisted("http://google.com"));
56 EXPECT_TRUE(IsURLWhitelisted("http://google.com/")); 56 EXPECT_TRUE(IsURLWhitelisted("http://google.com/"));
57 EXPECT_TRUE(IsURLWhitelisted("http://google.com/whatever")); 57 EXPECT_TRUE(IsURLWhitelisted("http://google.com/whatever"));
58 EXPECT_TRUE(IsURLWhitelisted("https://google.com/")); 58 EXPECT_TRUE(IsURLWhitelisted("https://google.com/"));
59 EXPECT_FALSE(IsURLWhitelisted("http://notgoogle.com/")); 59 EXPECT_FALSE(IsURLWhitelisted("http://notgoogle.com/"));
60 EXPECT_TRUE(IsURLWhitelisted("http://mail.google.com")); 60 EXPECT_TRUE(IsURLWhitelisted("http://mail.google.com"));
61 EXPECT_TRUE(IsURLWhitelisted("http://x.mail.google.com")); 61 EXPECT_TRUE(IsURLWhitelisted("http://x.mail.google.com"));
62 EXPECT_TRUE(IsURLWhitelisted("https://x.mail.google.com/")); 62 EXPECT_TRUE(IsURLWhitelisted("https://x.mail.google.com/"));
63 EXPECT_TRUE(IsURLWhitelisted("http://x.y.google.com/a/b")); 63 EXPECT_TRUE(IsURLWhitelisted("http://x.y.google.com/a/b"));
64 EXPECT_FALSE(IsURLWhitelisted("http://youtube.com/")); 64 EXPECT_FALSE(IsURLWhitelisted("http://youtube.com/"));
65 65
66 EXPECT_TRUE(IsURLWhitelisted("bogus://youtube.com/")); 66 EXPECT_TRUE(IsURLWhitelisted("bogus://youtube.com/"));
67 EXPECT_TRUE(IsURLWhitelisted("chrome://youtube.com/")); 67 EXPECT_TRUE(IsURLWhitelisted("chrome://youtube.com/"));
68 EXPECT_TRUE(IsURLWhitelisted("chrome://extensions/")); 68 EXPECT_TRUE(IsURLWhitelisted("chrome://extensions/"));
69 EXPECT_TRUE(IsURLWhitelisted("chrome-extension://foo/main.html")); 69 EXPECT_TRUE(IsURLWhitelisted("chrome-extension://foo/main.html"));
70 EXPECT_TRUE(IsURLWhitelisted("file:///home/chronos/user/Downloads/img.jpg")); 70 EXPECT_TRUE(IsURLWhitelisted("file:///home/chronos/user/Downloads/img.jpg"));
71 } 71 }
72 72
73 TEST_F(SupervisedUserURLFilterTest, EffectiveURL) { 73 TEST_F(SupervisedUserURLFilterTest, EffectiveURL) {
74 std::vector<std::string> list; 74 std::vector<std::string> list;
75 // Allow domain and all subdomains, for any filtered scheme. 75 // Allow domain and all subdomains, for any filtered scheme.
76 list.push_back("example.com"); 76 list.push_back("example.com");
77 filter_->SetFromPatternsForTesting(list); 77 filter_.SetFromPatternsForTesting(list);
78 run_loop_.Run(); 78 run_loop_.Run();
79 79
80 ASSERT_TRUE(IsURLWhitelisted("http://example.com")); 80 ASSERT_TRUE(IsURLWhitelisted("http://example.com"));
81 ASSERT_TRUE(IsURLWhitelisted("https://example.com")); 81 ASSERT_TRUE(IsURLWhitelisted("https://example.com"));
82 82
83 // AMP Cache URLs. 83 // AMP Cache URLs.
84 EXPECT_FALSE(IsURLWhitelisted("https://cdn.ampproject.org")); 84 EXPECT_FALSE(IsURLWhitelisted("https://cdn.ampproject.org"));
85 EXPECT_TRUE(IsURLWhitelisted("https://cdn.ampproject.org/c/example.com")); 85 EXPECT_TRUE(IsURLWhitelisted("https://cdn.ampproject.org/c/example.com"));
86 EXPECT_TRUE(IsURLWhitelisted("https://cdn.ampproject.org/c/www.example.com")); 86 EXPECT_TRUE(IsURLWhitelisted("https://cdn.ampproject.org/c/www.example.com"));
87 EXPECT_TRUE( 87 EXPECT_TRUE(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 "https://translate.googleusercontent.com/translate?u=example.com")); 141 "https://translate.googleusercontent.com/translate?u=example.com"));
142 EXPECT_TRUE(IsURLWhitelisted( 142 EXPECT_TRUE(IsURLWhitelisted(
143 "https://translate.google.com/translate?u=www.example.com")); 143 "https://translate.google.com/translate?u=www.example.com"));
144 EXPECT_TRUE(IsURLWhitelisted( 144 EXPECT_TRUE(IsURLWhitelisted(
145 "https://translate.google.com/translate?u=https://example.com")); 145 "https://translate.google.com/translate?u=https://example.com"));
146 EXPECT_FALSE( 146 EXPECT_FALSE(
147 IsURLWhitelisted("https://translate.google.com/translate?u=other.com")); 147 IsURLWhitelisted("https://translate.google.com/translate?u=other.com"));
148 } 148 }
149 149
150 TEST_F(SupervisedUserURLFilterTest, Inactive) { 150 TEST_F(SupervisedUserURLFilterTest, Inactive) {
151 filter_->SetDefaultFilteringBehavior(SupervisedUserURLFilter::ALLOW); 151 filter_.SetDefaultFilteringBehavior(SupervisedUserURLFilter::ALLOW);
152 152
153 std::vector<std::string> list; 153 std::vector<std::string> list;
154 list.push_back("google.com"); 154 list.push_back("google.com");
155 filter_->SetFromPatternsForTesting(list); 155 filter_.SetFromPatternsForTesting(list);
156 run_loop_.Run(); 156 run_loop_.Run();
157 157
158 // If the filter is inactive, every URL should be whitelisted. 158 // If the filter is inactive, every URL should be whitelisted.
159 EXPECT_TRUE(IsURLWhitelisted("http://google.com")); 159 EXPECT_TRUE(IsURLWhitelisted("http://google.com"));
160 EXPECT_TRUE(IsURLWhitelisted("https://www.example.com")); 160 EXPECT_TRUE(IsURLWhitelisted("https://www.example.com"));
161 } 161 }
162 162
163 TEST_F(SupervisedUserURLFilterTest, Scheme) { 163 TEST_F(SupervisedUserURLFilterTest, Scheme) {
164 std::vector<std::string> list; 164 std::vector<std::string> list;
165 // Filter only http, ftp and ws schemes. 165 // Filter only http, ftp and ws schemes.
166 list.push_back("http://secure.com"); 166 list.push_back("http://secure.com");
167 list.push_back("ftp://secure.com"); 167 list.push_back("ftp://secure.com");
168 list.push_back("ws://secure.com"); 168 list.push_back("ws://secure.com");
169 filter_->SetFromPatternsForTesting(list); 169 filter_.SetFromPatternsForTesting(list);
170 run_loop_.Run(); 170 run_loop_.Run();
171 171
172 EXPECT_TRUE(IsURLWhitelisted("http://secure.com")); 172 EXPECT_TRUE(IsURLWhitelisted("http://secure.com"));
173 EXPECT_TRUE(IsURLWhitelisted("http://secure.com/whatever")); 173 EXPECT_TRUE(IsURLWhitelisted("http://secure.com/whatever"));
174 EXPECT_TRUE(IsURLWhitelisted("ftp://secure.com/")); 174 EXPECT_TRUE(IsURLWhitelisted("ftp://secure.com/"));
175 EXPECT_TRUE(IsURLWhitelisted("ws://secure.com")); 175 EXPECT_TRUE(IsURLWhitelisted("ws://secure.com"));
176 EXPECT_FALSE(IsURLWhitelisted("https://secure.com/")); 176 EXPECT_FALSE(IsURLWhitelisted("https://secure.com/"));
177 EXPECT_FALSE(IsURLWhitelisted("wss://secure.com")); 177 EXPECT_FALSE(IsURLWhitelisted("wss://secure.com"));
178 EXPECT_TRUE(IsURLWhitelisted("http://www.secure.com")); 178 EXPECT_TRUE(IsURLWhitelisted("http://www.secure.com"));
179 EXPECT_FALSE(IsURLWhitelisted("https://www.secure.com")); 179 EXPECT_FALSE(IsURLWhitelisted("https://www.secure.com"));
180 EXPECT_FALSE(IsURLWhitelisted("wss://www.secure.com")); 180 EXPECT_FALSE(IsURLWhitelisted("wss://www.secure.com"));
181 } 181 }
182 182
183 TEST_F(SupervisedUserURLFilterTest, Path) { 183 TEST_F(SupervisedUserURLFilterTest, Path) {
184 std::vector<std::string> list; 184 std::vector<std::string> list;
185 // Filter only a certain path prefix. 185 // Filter only a certain path prefix.
186 list.push_back("path.to/ruin"); 186 list.push_back("path.to/ruin");
187 filter_->SetFromPatternsForTesting(list); 187 filter_.SetFromPatternsForTesting(list);
188 run_loop_.Run(); 188 run_loop_.Run();
189 189
190 EXPECT_TRUE(IsURLWhitelisted("http://path.to/ruin")); 190 EXPECT_TRUE(IsURLWhitelisted("http://path.to/ruin"));
191 EXPECT_TRUE(IsURLWhitelisted("https://path.to/ruin")); 191 EXPECT_TRUE(IsURLWhitelisted("https://path.to/ruin"));
192 EXPECT_TRUE(IsURLWhitelisted("http://path.to/ruins")); 192 EXPECT_TRUE(IsURLWhitelisted("http://path.to/ruins"));
193 EXPECT_TRUE(IsURLWhitelisted("http://path.to/ruin/signup")); 193 EXPECT_TRUE(IsURLWhitelisted("http://path.to/ruin/signup"));
194 EXPECT_TRUE(IsURLWhitelisted("http://www.path.to/ruin")); 194 EXPECT_TRUE(IsURLWhitelisted("http://www.path.to/ruin"));
195 EXPECT_FALSE(IsURLWhitelisted("http://path.to/fortune")); 195 EXPECT_FALSE(IsURLWhitelisted("http://path.to/fortune"));
196 } 196 }
197 197
198 TEST_F(SupervisedUserURLFilterTest, PathAndScheme) { 198 TEST_F(SupervisedUserURLFilterTest, PathAndScheme) {
199 std::vector<std::string> list; 199 std::vector<std::string> list;
200 // Filter only a certain path prefix and scheme. 200 // Filter only a certain path prefix and scheme.
201 list.push_back("https://s.aaa.com/path"); 201 list.push_back("https://s.aaa.com/path");
202 filter_->SetFromPatternsForTesting(list); 202 filter_.SetFromPatternsForTesting(list);
203 run_loop_.Run(); 203 run_loop_.Run();
204 204
205 EXPECT_TRUE(IsURLWhitelisted("https://s.aaa.com/path")); 205 EXPECT_TRUE(IsURLWhitelisted("https://s.aaa.com/path"));
206 EXPECT_TRUE(IsURLWhitelisted("https://s.aaa.com/path/bbb")); 206 EXPECT_TRUE(IsURLWhitelisted("https://s.aaa.com/path/bbb"));
207 EXPECT_FALSE(IsURLWhitelisted("http://s.aaa.com/path")); 207 EXPECT_FALSE(IsURLWhitelisted("http://s.aaa.com/path"));
208 EXPECT_FALSE(IsURLWhitelisted("https://aaa.com/path")); 208 EXPECT_FALSE(IsURLWhitelisted("https://aaa.com/path"));
209 EXPECT_FALSE(IsURLWhitelisted("https://x.aaa.com/path")); 209 EXPECT_FALSE(IsURLWhitelisted("https://x.aaa.com/path"));
210 EXPECT_FALSE(IsURLWhitelisted("https://s.aaa.com/bbb")); 210 EXPECT_FALSE(IsURLWhitelisted("https://s.aaa.com/bbb"));
211 EXPECT_FALSE(IsURLWhitelisted("https://s.aaa.com/")); 211 EXPECT_FALSE(IsURLWhitelisted("https://s.aaa.com/"));
212 } 212 }
213 213
214 TEST_F(SupervisedUserURLFilterTest, Host) { 214 TEST_F(SupervisedUserURLFilterTest, Host) {
215 std::vector<std::string> list; 215 std::vector<std::string> list;
216 // Filter only a certain hostname, without subdomains. 216 // Filter only a certain hostname, without subdomains.
217 list.push_back(".www.example.com"); 217 list.push_back(".www.example.com");
218 filter_->SetFromPatternsForTesting(list); 218 filter_.SetFromPatternsForTesting(list);
219 run_loop_.Run(); 219 run_loop_.Run();
220 220
221 EXPECT_TRUE(IsURLWhitelisted("http://www.example.com")); 221 EXPECT_TRUE(IsURLWhitelisted("http://www.example.com"));
222 EXPECT_FALSE(IsURLWhitelisted("http://example.com")); 222 EXPECT_FALSE(IsURLWhitelisted("http://example.com"));
223 EXPECT_FALSE(IsURLWhitelisted("http://subdomain.example.com")); 223 EXPECT_FALSE(IsURLWhitelisted("http://subdomain.example.com"));
224 } 224 }
225 225
226 TEST_F(SupervisedUserURLFilterTest, IPAddress) { 226 TEST_F(SupervisedUserURLFilterTest, IPAddress) {
227 std::vector<std::string> list; 227 std::vector<std::string> list;
228 // Filter an ip address. 228 // Filter an ip address.
229 list.push_back("123.123.123.123"); 229 list.push_back("123.123.123.123");
230 filter_->SetFromPatternsForTesting(list); 230 filter_.SetFromPatternsForTesting(list);
231 run_loop_.Run(); 231 run_loop_.Run();
232 232
233 EXPECT_TRUE(IsURLWhitelisted("http://123.123.123.123/")); 233 EXPECT_TRUE(IsURLWhitelisted("http://123.123.123.123/"));
234 EXPECT_FALSE(IsURLWhitelisted("http://123.123.123.124/")); 234 EXPECT_FALSE(IsURLWhitelisted("http://123.123.123.124/"));
235 } 235 }
236 236
237 TEST_F(SupervisedUserURLFilterTest, Canonicalization) { 237 TEST_F(SupervisedUserURLFilterTest, Canonicalization) {
238 // We assume that the hosts and URLs are already canonicalized. 238 // We assume that the hosts and URLs are already canonicalized.
239 std::map<std::string, bool> hosts; 239 std::map<std::string, bool> hosts;
240 hosts["www.moose.org"] = true; 240 hosts["www.moose.org"] = true;
241 hosts["www.xn--n3h.net"] = true; 241 hosts["www.xn--n3h.net"] = true;
242 std::map<GURL, bool> urls; 242 std::map<GURL, bool> urls;
243 urls[GURL("http://www.example.com/foo/")] = true; 243 urls[GURL("http://www.example.com/foo/")] = true;
244 urls[GURL("http://www.example.com/%C3%85t%C3%B8mstr%C3%B6m")] = true; 244 urls[GURL("http://www.example.com/%C3%85t%C3%B8mstr%C3%B6m")] = true;
245 filter_->SetManualHosts(&hosts); 245 filter_.SetManualHosts(std::move(hosts));
246 filter_->SetManualURLs(&urls); 246 filter_.SetManualURLs(std::move(urls));
247 247
248 // Base cases. 248 // Base cases.
249 EXPECT_TRUE(IsURLWhitelisted("http://www.example.com/foo/")); 249 EXPECT_TRUE(IsURLWhitelisted("http://www.example.com/foo/"));
250 EXPECT_TRUE(IsURLWhitelisted( 250 EXPECT_TRUE(IsURLWhitelisted(
251 "http://www.example.com/%C3%85t%C3%B8mstr%C3%B6m")); 251 "http://www.example.com/%C3%85t%C3%B8mstr%C3%B6m"));
252 252
253 // Verify that non-URI characters are escaped. 253 // Verify that non-URI characters are escaped.
254 EXPECT_TRUE(IsURLWhitelisted( 254 EXPECT_TRUE(IsURLWhitelisted(
255 "http://www.example.com/\xc3\x85t\xc3\xb8mstr\xc3\xb6m")); 255 "http://www.example.com/\xc3\x85t\xc3\xb8mstr\xc3\xb6m"));
256 256
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 std::map<std::string, bool> hosts; 407 std::map<std::string, bool> hosts;
408 408
409 // Initally, the second rule is ignored because has the same value as the 409 // Initally, the second rule is ignored because has the same value as the
410 // default (block). When we change the default to allow, the first rule is 410 // default (block). When we change the default to allow, the first rule is
411 // ignored instead. 411 // ignored instead.
412 hosts["*.google.com"] = true; 412 hosts["*.google.com"] = true;
413 hosts["www.google.*"] = false; 413 hosts["www.google.*"] = false;
414 414
415 hosts["accounts.google.com"] = false; 415 hosts["accounts.google.com"] = false;
416 hosts["mail.google.com"] = true; 416 hosts["mail.google.com"] = true;
417 filter_->SetManualHosts(&hosts); 417 filter_.SetManualHosts(std::move(hosts));
418 418
419 // Initially, the default filtering behavior is BLOCK. 419 // Initially, the default filtering behavior is BLOCK.
420 EXPECT_TRUE(IsURLWhitelisted("http://www.google.com/foo/")); 420 EXPECT_TRUE(IsURLWhitelisted("http://www.google.com/foo/"));
421 EXPECT_FALSE(IsURLWhitelisted("http://accounts.google.com/bar/")); 421 EXPECT_FALSE(IsURLWhitelisted("http://accounts.google.com/bar/"));
422 EXPECT_FALSE(IsURLWhitelisted("http://www.google.co.uk/blurp/")); 422 EXPECT_FALSE(IsURLWhitelisted("http://www.google.co.uk/blurp/"));
423 EXPECT_TRUE(IsURLWhitelisted("http://mail.google.com/moose/")); 423 EXPECT_TRUE(IsURLWhitelisted("http://mail.google.com/moose/"));
424 424
425 filter_->SetDefaultFilteringBehavior(SupervisedUserURLFilter::ALLOW); 425 filter_.SetDefaultFilteringBehavior(SupervisedUserURLFilter::ALLOW);
426 EXPECT_FALSE(IsURLWhitelisted("http://www.google.com/foo/")); 426 EXPECT_FALSE(IsURLWhitelisted("http://www.google.com/foo/"));
427 EXPECT_FALSE(IsURLWhitelisted("http://accounts.google.com/bar/")); 427 EXPECT_FALSE(IsURLWhitelisted("http://accounts.google.com/bar/"));
428 EXPECT_FALSE(IsURLWhitelisted("http://www.google.co.uk/blurp/")); 428 EXPECT_FALSE(IsURLWhitelisted("http://www.google.co.uk/blurp/"));
429 EXPECT_TRUE(IsURLWhitelisted("http://mail.google.com/moose/")); 429 EXPECT_TRUE(IsURLWhitelisted("http://mail.google.com/moose/"));
430 } 430 }
431 431
432 TEST_F(SupervisedUserURLFilterTest, WhitelistsPatterns) { 432 TEST_F(SupervisedUserURLFilterTest, WhitelistsPatterns) {
433 std::vector<std::string> patterns1; 433 std::vector<std::string> patterns1;
434 patterns1.push_back("google.com"); 434 patterns1.push_back("google.com");
435 patterns1.push_back("example.com"); 435 patterns1.push_back("example.com");
(...skipping 13 matching lines...) Expand all
449 new SupervisedUserSiteList(id1, title1, entry_point, base::FilePath(), 449 new SupervisedUserSiteList(id1, title1, entry_point, base::FilePath(),
450 patterns1, hostname_hashes)); 450 patterns1, hostname_hashes));
451 scoped_refptr<SupervisedUserSiteList> site_list2 = make_scoped_refptr( 451 scoped_refptr<SupervisedUserSiteList> site_list2 = make_scoped_refptr(
452 new SupervisedUserSiteList(id2, title2, entry_point, base::FilePath(), 452 new SupervisedUserSiteList(id2, title2, entry_point, base::FilePath(),
453 patterns2, hostname_hashes)); 453 patterns2, hostname_hashes));
454 454
455 std::vector<scoped_refptr<SupervisedUserSiteList>> site_lists; 455 std::vector<scoped_refptr<SupervisedUserSiteList>> site_lists;
456 site_lists.push_back(site_list1); 456 site_lists.push_back(site_list1);
457 site_lists.push_back(site_list2); 457 site_lists.push_back(site_list2);
458 458
459 filter_->SetFromSiteListsForTesting(site_lists); 459 filter_.SetFromSiteListsForTesting(site_lists);
460 filter_->SetDefaultFilteringBehavior(SupervisedUserURLFilter::BLOCK); 460 filter_.SetDefaultFilteringBehavior(SupervisedUserURLFilter::BLOCK);
461 run_loop_.Run(); 461 run_loop_.Run();
462 462
463 std::map<std::string, base::string16> expected_whitelists; 463 std::map<std::string, base::string16> expected_whitelists;
464 expected_whitelists[id1] = title1; 464 expected_whitelists[id1] = title1;
465 expected_whitelists[id2] = title2; 465 expected_whitelists[id2] = title2;
466 466
467 std::map<std::string, base::string16> actual_whitelists = 467 std::map<std::string, base::string16> actual_whitelists =
468 filter_->GetMatchingWhitelistTitles(GURL("https://example.com")); 468 filter_.GetMatchingWhitelistTitles(GURL("https://example.com"));
469 ASSERT_EQ(expected_whitelists, actual_whitelists); 469 ASSERT_EQ(expected_whitelists, actual_whitelists);
470 470
471 expected_whitelists.erase(id2); 471 expected_whitelists.erase(id2);
472 472
473 actual_whitelists = 473 actual_whitelists =
474 filter_->GetMatchingWhitelistTitles(GURL("https://google.com")); 474 filter_.GetMatchingWhitelistTitles(GURL("https://google.com"));
475 ASSERT_EQ(expected_whitelists, actual_whitelists); 475 ASSERT_EQ(expected_whitelists, actual_whitelists);
476 } 476 }
477 477
478 TEST_F(SupervisedUserURLFilterTest, WhitelistsHostnameHashes) { 478 TEST_F(SupervisedUserURLFilterTest, WhitelistsHostnameHashes) {
479 std::vector<std::string> patterns1; 479 std::vector<std::string> patterns1;
480 patterns1.push_back("google.com"); 480 patterns1.push_back("google.com");
481 patterns1.push_back("example.com"); 481 patterns1.push_back("example.com");
482 482
483 std::vector<std::string> patterns2; 483 std::vector<std::string> patterns2;
484 patterns2.push_back("secure.com"); 484 patterns2.push_back("secure.com");
(...skipping 25 matching lines...) Expand all
510 patterns2, hostname_hashes2)); 510 patterns2, hostname_hashes2));
511 scoped_refptr<SupervisedUserSiteList> site_list3 = make_scoped_refptr( 511 scoped_refptr<SupervisedUserSiteList> site_list3 = make_scoped_refptr(
512 new SupervisedUserSiteList(id3, title3, entry_point, base::FilePath(), 512 new SupervisedUserSiteList(id3, title3, entry_point, base::FilePath(),
513 patterns3, hostname_hashes3)); 513 patterns3, hostname_hashes3));
514 514
515 std::vector<scoped_refptr<SupervisedUserSiteList>> site_lists; 515 std::vector<scoped_refptr<SupervisedUserSiteList>> site_lists;
516 site_lists.push_back(site_list1); 516 site_lists.push_back(site_list1);
517 site_lists.push_back(site_list2); 517 site_lists.push_back(site_list2);
518 site_lists.push_back(site_list3); 518 site_lists.push_back(site_list3);
519 519
520 filter_->SetFromSiteListsForTesting(site_lists); 520 filter_.SetFromSiteListsForTesting(site_lists);
521 filter_->SetDefaultFilteringBehavior(SupervisedUserURLFilter::BLOCK); 521 filter_.SetDefaultFilteringBehavior(SupervisedUserURLFilter::BLOCK);
522 run_loop_.Run(); 522 run_loop_.Run();
523 523
524 std::map<std::string, base::string16> expected_whitelists; 524 std::map<std::string, base::string16> expected_whitelists;
525 expected_whitelists[id1] = title1; 525 expected_whitelists[id1] = title1;
526 expected_whitelists[id2] = title2; 526 expected_whitelists[id2] = title2;
527 expected_whitelists[id3] = title3; 527 expected_whitelists[id3] = title3;
528 528
529 std::map<std::string, base::string16> actual_whitelists = 529 std::map<std::string, base::string16> actual_whitelists =
530 filter_->GetMatchingWhitelistTitles(GURL("http://example.com")); 530 filter_.GetMatchingWhitelistTitles(GURL("http://example.com"));
531 ASSERT_EQ(expected_whitelists, actual_whitelists); 531 ASSERT_EQ(expected_whitelists, actual_whitelists);
532 532
533 expected_whitelists.erase(id1); 533 expected_whitelists.erase(id1);
534 534
535 actual_whitelists = 535 actual_whitelists =
536 filter_->GetMatchingWhitelistTitles(GURL("https://secure.com")); 536 filter_.GetMatchingWhitelistTitles(GURL("https://secure.com"));
537 ASSERT_EQ(expected_whitelists, actual_whitelists); 537 ASSERT_EQ(expected_whitelists, actual_whitelists);
538 } 538 }
539 539
540 #if BUILDFLAG(ENABLE_EXTENSIONS) 540 #if BUILDFLAG(ENABLE_EXTENSIONS)
541 TEST_F(SupervisedUserURLFilterTest, ChromeWebstoreDownloadsAreAlwaysAllowed) { 541 TEST_F(SupervisedUserURLFilterTest, ChromeWebstoreDownloadsAreAlwaysAllowed) {
542 // When installing an extension from Chrome Webstore, it tries to download the 542 // When installing an extension from Chrome Webstore, it tries to download the
543 // crx file from "https://clients2.google.com/service/update2/", which 543 // crx file from "https://clients2.google.com/service/update2/", which
544 // redirects to "https://clients2.googleusercontent.com/crx/blobs/" 544 // redirects to "https://clients2.googleusercontent.com/crx/blobs/"
545 // or "https://chrome.google.com/webstore/download/". 545 // or "https://chrome.google.com/webstore/download/".
546 // All URLs should be whitelisted regardless from the default filtering 546 // All URLs should be whitelisted regardless from the default filtering
547 // behavior. 547 // behavior.
548 GURL crx_download_url1( 548 GURL crx_download_url1(
549 "https://clients2.google.com/service/update2/" 549 "https://clients2.google.com/service/update2/"
550 "crx?response=redirect&os=linux&arch=x64&nacl_arch=x86-64&prod=" 550 "crx?response=redirect&os=linux&arch=x64&nacl_arch=x86-64&prod="
551 "chromiumcrx&prodchannel=&prodversion=55.0.2882.0&lang=en-US&x=id%" 551 "chromiumcrx&prodchannel=&prodversion=55.0.2882.0&lang=en-US&x=id%"
552 "3Dciniambnphakdoflgeamacamhfllbkmo%26installsource%3Dondemand%26uc"); 552 "3Dciniambnphakdoflgeamacamhfllbkmo%26installsource%3Dondemand%26uc");
553 GURL crx_download_url2( 553 GURL crx_download_url2(
554 "https://clients2.googleusercontent.com/crx/blobs/" 554 "https://clients2.googleusercontent.com/crx/blobs/"
555 "QgAAAC6zw0qH2DJtnXe8Z7rUJP1iCQF099oik9f2ErAYeFAX7_" 555 "QgAAAC6zw0qH2DJtnXe8Z7rUJP1iCQF099oik9f2ErAYeFAX7_"
556 "CIyrNH5qBru1lUSBNvzmjILCGwUjcIBaJqxgegSNy2melYqfodngLxKtHsGBehAMZSmuWSg6" 556 "CIyrNH5qBru1lUSBNvzmjILCGwUjcIBaJqxgegSNy2melYqfodngLxKtHsGBehAMZSmuWSg6"
557 "FupAcPS3Ih6NSVCOB9KNh6Mw/extension_2_0.crx"); 557 "FupAcPS3Ih6NSVCOB9KNh6Mw/extension_2_0.crx");
558 GURL crx_download_url3( 558 GURL crx_download_url3(
559 "https://chrome.google.com/webstore/download/" 559 "https://chrome.google.com/webstore/download/"
560 "QgAAAC6zw0qH2DJtnXe8Z7rUJP1iCQF099oik9f2ErAYeFAX7_" 560 "QgAAAC6zw0qH2DJtnXe8Z7rUJP1iCQF099oik9f2ErAYeFAX7_"
561 "CIyrNH5qBru1lUSBNvzmjILCGwUjcIBaJqxgegSNy2melYqfodngLxKtHsGBehAMZSmuWSg6" 561 "CIyrNH5qBru1lUSBNvzmjILCGwUjcIBaJqxgegSNy2melYqfodngLxKtHsGBehAMZSmuWSg6"
562 "FupAcPS3Ih6NSVCOB9KNh6Mw/extension_2_0.crx"); 562 "FupAcPS3Ih6NSVCOB9KNh6Mw/extension_2_0.crx");
563 563
564 filter_->SetDefaultFilteringBehavior(SupervisedUserURLFilter::BLOCK); 564 filter_.SetDefaultFilteringBehavior(SupervisedUserURLFilter::BLOCK);
565 EXPECT_EQ(SupervisedUserURLFilter::ALLOW, 565 EXPECT_EQ(SupervisedUserURLFilter::ALLOW,
566 filter_->GetFilteringBehaviorForURL(crx_download_url1)); 566 filter_.GetFilteringBehaviorForURL(crx_download_url1));
567 EXPECT_EQ(SupervisedUserURLFilter::ALLOW, 567 EXPECT_EQ(SupervisedUserURLFilter::ALLOW,
568 filter_->GetFilteringBehaviorForURL(crx_download_url2)); 568 filter_.GetFilteringBehaviorForURL(crx_download_url2));
569 EXPECT_EQ(SupervisedUserURLFilter::ALLOW, 569 EXPECT_EQ(SupervisedUserURLFilter::ALLOW,
570 filter_->GetFilteringBehaviorForURL(crx_download_url3)); 570 filter_.GetFilteringBehaviorForURL(crx_download_url3));
571 571
572 // Set explicit host rules to block those website, and make sure the 572 // Set explicit host rules to block those website, and make sure the
573 // update URLs still work. 573 // update URLs still work.
574 std::map<std::string, bool> hosts; 574 std::map<std::string, bool> hosts;
575 hosts["clients2.google.com"] = false; 575 hosts["clients2.google.com"] = false;
576 hosts["clients2.googleusercontent.com"] = false; 576 hosts["clients2.googleusercontent.com"] = false;
577 filter_->SetManualHosts(&hosts); 577 filter_.SetManualHosts(std::move(hosts));
578 filter_->SetDefaultFilteringBehavior(SupervisedUserURLFilter::ALLOW); 578 filter_.SetDefaultFilteringBehavior(SupervisedUserURLFilter::ALLOW);
579 EXPECT_EQ(SupervisedUserURLFilter::ALLOW, 579 EXPECT_EQ(SupervisedUserURLFilter::ALLOW,
580 filter_->GetFilteringBehaviorForURL(crx_download_url1)); 580 filter_.GetFilteringBehaviorForURL(crx_download_url1));
581 EXPECT_EQ(SupervisedUserURLFilter::ALLOW, 581 EXPECT_EQ(SupervisedUserURLFilter::ALLOW,
582 filter_->GetFilteringBehaviorForURL(crx_download_url2)); 582 filter_.GetFilteringBehaviorForURL(crx_download_url2));
583 EXPECT_EQ(SupervisedUserURLFilter::ALLOW, 583 EXPECT_EQ(SupervisedUserURLFilter::ALLOW,
584 filter_->GetFilteringBehaviorForURL(crx_download_url3)); 584 filter_.GetFilteringBehaviorForURL(crx_download_url3));
585 } 585 }
586 #endif 586 #endif
587 587
588 TEST_F(SupervisedUserURLFilterTest, GetEmbeddedURLAmpCache) { 588 TEST_F(SupervisedUserURLFilterTest, GetEmbeddedURLAmpCache) {
589 // Base case. 589 // Base case.
590 EXPECT_EQ(GURL("http://example.com"), 590 EXPECT_EQ(GURL("http://example.com"),
591 GetEmbeddedURL("https://cdn.ampproject.org/c/example.com")); 591 GetEmbeddedURL("https://cdn.ampproject.org/c/example.com"));
592 // "s/" means "use https". 592 // "s/" means "use https".
593 EXPECT_EQ(GURL("https://example.com"), 593 EXPECT_EQ(GURL("https://example.com"),
594 GetEmbeddedURL("https://cdn.ampproject.org/c/s/example.com")); 594 GetEmbeddedURL("https://cdn.ampproject.org/c/s/example.com"));
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 GetEmbeddedURL( 744 GetEmbeddedURL(
745 "https://translate2.googleusercontent.com/path?u=example.com")); 745 "https://translate2.googleusercontent.com/path?u=example.com"));
746 // Different TLD is not supported for googleusercontent. 746 // Different TLD is not supported for googleusercontent.
747 EXPECT_EQ(GURL(), 747 EXPECT_EQ(GURL(),
748 GetEmbeddedURL( 748 GetEmbeddedURL(
749 "https://translate.googleusercontent.de/path?u=example.com")); 749 "https://translate.googleusercontent.de/path?u=example.com"));
750 // Query parameter ("u=...") is missing. 750 // Query parameter ("u=...") is missing.
751 EXPECT_EQ(GURL(), 751 EXPECT_EQ(GURL(),
752 GetEmbeddedURL("https://translate.google.com/path?t=example.com")); 752 GetEmbeddedURL("https://translate.google.com/path?t=example.com"));
753 } 753 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698