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, IsSafeScheme) { |
| 15 GURL data_url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA=="); |
| 16 EXPECT_TRUE(SiteIsolationPolicy::IsSafeScheme(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_TRUE(SiteIsolationPolicy::IsValidCorsHeaderSet( |
| 36 frame_origin, site_origin, "\"*\"")); |
| 37 EXPECT_TRUE(SiteIsolationPolicy::IsValidCorsHeaderSet( |
| 38 frame_origin, site_origin, "www.google.com")); |
| 39 EXPECT_TRUE(SiteIsolationPolicy::IsValidCorsHeaderSet( |
| 40 frame_origin, site_origin, "mail.google.com")); |
| 41 EXPECT_FALSE(SiteIsolationPolicy::IsValidCorsHeaderSet( |
| 42 frame_origin, site_origin, "yahoo.com")); |
| 43 } |
| 44 |
| 45 TEST(SiteIsolationPolicyTest, SniffForHTML) { |
| 46 const char* html_data = " \t\r\n <HtMladfokadfkado"; |
| 47 const char* non_html_data = " var name=window.location;\nadfadf"; |
| 48 |
| 49 EXPECT_TRUE(SiteIsolationPolicy::SniffForHTML(html_data, strlen(html_data))); |
| 50 EXPECT_FALSE( |
| 51 SiteIsolationPolicy::SniffForHTML(non_html_data, strlen(non_html_data))); |
| 52 } |
| 53 |
| 54 TEST(SiteIsolationPolicyTest, SniffForXML) { |
| 55 const char* xml_data = " \t \r \n <?xml version=\"1.0\"?>\n <catalog"; |
| 56 const char* non_xml_data = " var name=window.location;\nadfadf"; |
| 57 |
| 58 EXPECT_TRUE(SiteIsolationPolicy::SniffForXML(xml_data, strlen(xml_data))); |
| 59 EXPECT_FALSE( |
| 60 SiteIsolationPolicy::SniffForXML(non_xml_data, strlen(non_xml_data))); |
| 61 } |
| 62 |
| 63 TEST(SiteIsolationPolicyTest, SniffForJSON) { |
| 64 const char* json_data = "\t\t\r\n { \"name\" : \"chrome\", "; |
| 65 const char* non_json_data = "\t\t\r\n { name : \"chrome\", "; |
| 66 |
| 67 EXPECT_TRUE(SiteIsolationPolicy::SniffForJSON(json_data, strlen(json_data))); |
| 68 EXPECT_FALSE( |
| 69 SiteIsolationPolicy::SniffForJSON(non_json_data, strlen(non_json_data))); |
| 70 } |
| 71 |
| 72 TEST(SiteIsolationPolicyTest, SniffForJS) { |
| 73 const char* js_data = "\t\t\r\n var a = 4"; |
| 74 const char* json_data = "\t\t\r\n { \"name\" : \"chrome\", "; |
| 75 |
| 76 EXPECT_TRUE(SiteIsolationPolicy::SniffForJS(js_data, strlen(js_data))); |
| 77 EXPECT_FALSE(SiteIsolationPolicy::SniffForJS(json_data, strlen(json_data))); |
| 78 } |
| 79 |
| 80 } // namespace conten |
OLD | NEW |