OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/extensions/api/web_request/web_request_permissions.h" |
| 6 |
| 7 #include "base/message_loop.h" |
| 8 #include "chrome/test/base/testing_profile.h" |
| 9 #include "net/url_request/url_request_test_util.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 TEST(ExtensionWebRequestHelpersTest, TestHideRequestForURL) { |
| 13 MessageLoopForIO message_loop; |
| 14 TestURLRequestContext context; |
| 15 const char* sensitive_urls[] = { |
| 16 "http://www.google.com/chrome", |
| 17 "https://www.google.com/chrome", |
| 18 "http://www.google.com/chrome/foobar", |
| 19 "https://www.google.com/chrome/foobar", |
| 20 "http://chrome.google.com", |
| 21 "https://chrome.google.com", |
| 22 "http://client2.google.com", |
| 23 "https://client2.google.com", |
| 24 // No http version of webstore. |
| 25 "https://chrome.google.com/webstore", |
| 26 "http://clients2.google.com/service/update2/crx", |
| 27 "https://clients2.google.com/service/update2/crx", |
| 28 "http://www.gstatic.com/chrome/extensions/blacklist", |
| 29 "https://www.gstatic.com/chrome/extensions/blacklist", |
| 30 "notregisteredscheme://www.foobar.com" |
| 31 }; |
| 32 const char* non_sensitive_urls[] = { |
| 33 "http://www.google.com/" |
| 34 }; |
| 35 // Check that requests are rejected based on the destination |
| 36 for (size_t i = 0; i < arraysize(sensitive_urls); ++i) { |
| 37 GURL sensitive_url(sensitive_urls[i]); |
| 38 TestURLRequest request(sensitive_url, NULL, &context); |
| 39 EXPECT_TRUE(WebRequestPermissions::HideRequest(&request)) |
| 40 << sensitive_urls[i]; |
| 41 } |
| 42 // Check that requests are accepted if they don't touch sensitive urls. |
| 43 for (size_t i = 0; i < arraysize(non_sensitive_urls); ++i) { |
| 44 GURL non_sensitive_url(non_sensitive_urls[i]); |
| 45 TestURLRequest request(non_sensitive_url, NULL, &context); |
| 46 EXPECT_FALSE(WebRequestPermissions::HideRequest(&request)) |
| 47 << non_sensitive_urls[i]; |
| 48 } |
| 49 // Check that requests are rejected if their first party url is sensitive. |
| 50 ASSERT_GE(arraysize(non_sensitive_urls), 1u); |
| 51 GURL non_sensitive_url(non_sensitive_urls[0]); |
| 52 for (size_t i = 0; i < arraysize(sensitive_urls); ++i) { |
| 53 TestURLRequest request(non_sensitive_url, NULL, &context); |
| 54 GURL sensitive_url(sensitive_urls[i]); |
| 55 request.set_first_party_for_cookies(sensitive_url); |
| 56 EXPECT_TRUE(WebRequestPermissions::HideRequest(&request)) |
| 57 << sensitive_urls[i]; |
| 58 } |
| 59 } |
OLD | NEW |