OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 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 "base/strings/utf_string_conversions.h" |
| 6 #include "content/public/common/context_menu_params.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 9 #include "ui/base/range/range.h" |
| 10 #include "webkit/child/site_isolation_policy.h" |
| 11 |
| 12 namespace webkit_glue { |
| 13 |
| 14 TEST(SiteIsolationPolicyTest, IsNetworkScheme) { |
| 15 GURL data_url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA=="); |
| 16 EXPECT_FALSE(SiteIsolationPolicy::IsNetworkScheme(data_url)); |
| 17 } |
| 18 |
| 19 TEST(SiteIsolationPolicyTest, IsSameSite) { |
| 20 GURL url0("https://mock1.a.com:8080/page1.html"); |
| 21 GURL url1("https://mock2.a.com:9090/page2.html"); |
| 22 GURL url2("https://a.com/page3.html"); |
| 23 |
| 24 EXPECT_TRUE(SiteIsolationPolicy::IsSameSite(url0, url1)); |
| 25 EXPECT_TRUE(SiteIsolationPolicy::IsSameSite(url1, url2)); |
| 26 EXPECT_TRUE(SiteIsolationPolicy::IsSameSite(url2, url0)); |
| 27 } |
| 28 |
| 29 TEST(SiteIsolationPolicyTest, IsValidCorsHeaderSet) { |
| 30 GURL frame_origin("http://www.google.com"); |
| 31 GURL site_origin("http://www.yahoo.com"); |
| 32 |
| 33 EXPECT_TRUE(SiteIsolationPolicy::IsValidCorsHeaderSet( |
| 34 frame_origin, site_origin, "*")); |
| 35 EXPECT_FALSE(SiteIsolationPolicy::IsValidCorsHeaderSet( |
| 36 frame_origin, site_origin, "\"*\"")); |
| 37 EXPECT_TRUE(SiteIsolationPolicy::IsValidCorsHeaderSet( |
| 38 frame_origin, site_origin, "http://mail.google.com")); |
| 39 EXPECT_FALSE(SiteIsolationPolicy::IsValidCorsHeaderSet( |
| 40 frame_origin, site_origin, "https://mail.google.com")); |
| 41 EXPECT_FALSE(SiteIsolationPolicy::IsValidCorsHeaderSet( |
| 42 frame_origin, site_origin, "http://yahoo.com")); |
| 43 EXPECT_FALSE(SiteIsolationPolicy::IsValidCorsHeaderSet( |
| 44 frame_origin, site_origin, "www.google.com")); |
| 45 } |
| 46 |
| 47 TEST(SiteIsolationPolicyTest, SniffForHTML) { |
| 48 const char* html_data = " \t\r\n <HtMladfokadfkado"; |
| 49 const char* non_html_data = " var name=window.location;\nadfadf"; |
| 50 |
| 51 EXPECT_TRUE(SiteIsolationPolicy::SniffForHTML(html_data, strlen(html_data))); |
| 52 EXPECT_FALSE( |
| 53 SiteIsolationPolicy::SniffForHTML(non_html_data, strlen(non_html_data))); |
| 54 } |
| 55 |
| 56 TEST(SiteIsolationPolicyTest, SniffForXML) { |
| 57 const char* xml_data = " \t \r \n <?xml version=\"1.0\"?>\n <catalog"; |
| 58 const char* non_xml_data = " var name=window.location;\nadfadf"; |
| 59 |
| 60 EXPECT_TRUE(SiteIsolationPolicy::SniffForXML(xml_data, strlen(xml_data))); |
| 61 EXPECT_FALSE( |
| 62 SiteIsolationPolicy::SniffForXML(non_xml_data, strlen(non_xml_data))); |
| 63 } |
| 64 |
| 65 TEST(SiteIsolationPolicyTest, SniffForJSON) { |
| 66 const char* json_data = "\t\t\r\n { \"name\" : \"chrome\", "; |
| 67 const char* non_json_data = "\t\t\r\n { name : \"chrome\", "; |
| 68 |
| 69 EXPECT_TRUE(SiteIsolationPolicy::SniffForJSON(json_data, strlen(json_data))); |
| 70 EXPECT_FALSE( |
| 71 SiteIsolationPolicy::SniffForJSON(non_json_data, strlen(non_json_data))); |
| 72 } |
| 73 |
| 74 TEST(SiteIsolationPolicyTest, SniffForJS) { |
| 75 const char* js_data = "\t\t\r\n var a = 4"; |
| 76 const char* json_data = "\t\t\r\n { \"name\" : \"chrome\", "; |
| 77 |
| 78 EXPECT_TRUE(SiteIsolationPolicy::SniffForJS(js_data, strlen(js_data))); |
| 79 EXPECT_FALSE(SiteIsolationPolicy::SniffForJS(json_data, strlen(json_data))); |
| 80 } |
| 81 |
| 82 } // namespace conten |
OLD | NEW |