| OLD | NEW |
| (Empty) |
| 1 // Copyright 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/string_piece.h" | |
| 6 #include "base/strings/utf_string_conversions.h" | |
| 7 #include "content/child/site_isolation_policy.h" | |
| 8 #include "content/public/common/context_menu_params.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 #include "third_party/WebKit/public/platform/WebURLResponse.h" | |
| 11 #include "ui/gfx/range/range.h" | |
| 12 | |
| 13 using base::StringPiece; | |
| 14 | |
| 15 namespace content { | |
| 16 | |
| 17 TEST(CrossSiteDocumentClassifierTest, IsBlockableScheme) { | |
| 18 GURL data_url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA=="); | |
| 19 GURL ftp_url("ftp://google.com"); | |
| 20 GURL mailto_url("mailto:google@google.com"); | |
| 21 GURL about_url("about:chrome"); | |
| 22 GURL http_url("http://google.com"); | |
| 23 GURL https_url("https://google.com"); | |
| 24 | |
| 25 EXPECT_FALSE(CrossSiteDocumentClassifier::IsBlockableScheme(data_url)); | |
| 26 EXPECT_FALSE(CrossSiteDocumentClassifier::IsBlockableScheme(ftp_url)); | |
| 27 EXPECT_FALSE(CrossSiteDocumentClassifier::IsBlockableScheme(mailto_url)); | |
| 28 EXPECT_FALSE(CrossSiteDocumentClassifier::IsBlockableScheme(about_url)); | |
| 29 EXPECT_TRUE(CrossSiteDocumentClassifier::IsBlockableScheme(http_url)); | |
| 30 EXPECT_TRUE(CrossSiteDocumentClassifier::IsBlockableScheme(https_url)); | |
| 31 } | |
| 32 | |
| 33 TEST(CrossSiteDocumentClassifierTest, IsSameSite) { | |
| 34 GURL a_com_url0("https://mock1.a.com:8080/page1.html"); | |
| 35 GURL a_com_url1("https://mock2.a.com:9090/page2.html"); | |
| 36 GURL a_com_url2("https://a.com/page3.html"); | |
| 37 EXPECT_TRUE(CrossSiteDocumentClassifier::IsSameSite(a_com_url0, a_com_url1)); | |
| 38 EXPECT_TRUE(CrossSiteDocumentClassifier::IsSameSite(a_com_url1, a_com_url2)); | |
| 39 EXPECT_TRUE(CrossSiteDocumentClassifier::IsSameSite(a_com_url2, a_com_url0)); | |
| 40 | |
| 41 GURL b_com_url0("https://mock1.b.com/index.html"); | |
| 42 EXPECT_FALSE(CrossSiteDocumentClassifier::IsSameSite(a_com_url0, b_com_url0)); | |
| 43 | |
| 44 GURL about_blank_url("about:blank"); | |
| 45 EXPECT_FALSE( | |
| 46 CrossSiteDocumentClassifier::IsSameSite(a_com_url0, about_blank_url)); | |
| 47 | |
| 48 GURL chrome_url("chrome://extension"); | |
| 49 EXPECT_FALSE(CrossSiteDocumentClassifier::IsSameSite(a_com_url0, chrome_url)); | |
| 50 | |
| 51 GURL empty_url(""); | |
| 52 EXPECT_FALSE(CrossSiteDocumentClassifier::IsSameSite(a_com_url0, empty_url)); | |
| 53 } | |
| 54 | |
| 55 TEST(CrossSiteDocumentClassifierTest, IsValidCorsHeaderSet) { | |
| 56 GURL frame_origin("http://www.google.com"); | |
| 57 GURL site_origin("http://www.yahoo.com"); | |
| 58 | |
| 59 EXPECT_TRUE(CrossSiteDocumentClassifier::IsValidCorsHeaderSet( | |
| 60 frame_origin, site_origin, "*")); | |
| 61 EXPECT_FALSE(CrossSiteDocumentClassifier::IsValidCorsHeaderSet( | |
| 62 frame_origin, site_origin, "\"*\"")); | |
| 63 EXPECT_TRUE(CrossSiteDocumentClassifier::IsValidCorsHeaderSet( | |
| 64 frame_origin, site_origin, "http://mail.google.com")); | |
| 65 EXPECT_FALSE(CrossSiteDocumentClassifier::IsValidCorsHeaderSet( | |
| 66 frame_origin, site_origin, "https://mail.google.com")); | |
| 67 EXPECT_FALSE(CrossSiteDocumentClassifier::IsValidCorsHeaderSet( | |
| 68 frame_origin, site_origin, "http://yahoo.com")); | |
| 69 EXPECT_FALSE(CrossSiteDocumentClassifier::IsValidCorsHeaderSet( | |
| 70 frame_origin, site_origin, "www.google.com")); | |
| 71 } | |
| 72 | |
| 73 TEST(CrossSiteDocumentClassifierTest, SniffForHTML) { | |
| 74 StringPiece html_data(" \t\r\n <HtMladfokadfkado"); | |
| 75 StringPiece comment_html_data(" <!-- this is comment --> <html><body>"); | |
| 76 StringPiece two_comments_html_data( | |
| 77 "<!-- this is comment -->\n<!-- this is comment --><html><body>"); | |
| 78 StringPiece mixed_comments_html_data( | |
| 79 "<!-- this is comment <!-- --> <script></script>"); | |
| 80 StringPiece non_html_data(" var name=window.location;\nadfadf"); | |
| 81 StringPiece comment_js_data(" <!-- this is comment -> document.write(1); "); | |
| 82 StringPiece empty_data(""); | |
| 83 | |
| 84 EXPECT_TRUE(CrossSiteDocumentClassifier::SniffForHTML(html_data)); | |
| 85 EXPECT_TRUE(CrossSiteDocumentClassifier::SniffForHTML(comment_html_data)); | |
| 86 EXPECT_TRUE( | |
| 87 CrossSiteDocumentClassifier::SniffForHTML(two_comments_html_data)); | |
| 88 EXPECT_TRUE( | |
| 89 CrossSiteDocumentClassifier::SniffForHTML(mixed_comments_html_data)); | |
| 90 EXPECT_FALSE(CrossSiteDocumentClassifier::SniffForHTML(non_html_data)); | |
| 91 EXPECT_FALSE(CrossSiteDocumentClassifier::SniffForHTML(comment_js_data)); | |
| 92 | |
| 93 // Basic bounds check. | |
| 94 EXPECT_FALSE(CrossSiteDocumentClassifier::SniffForHTML(empty_data)); | |
| 95 } | |
| 96 | |
| 97 TEST(CrossSiteDocumentClassifierTest, SniffForXML) { | |
| 98 StringPiece xml_data(" \t \r \n <?xml version=\"1.0\"?>\n <catalog"); | |
| 99 StringPiece non_xml_data(" var name=window.location;\nadfadf"); | |
| 100 StringPiece empty_data(""); | |
| 101 | |
| 102 EXPECT_TRUE(CrossSiteDocumentClassifier::SniffForXML(xml_data)); | |
| 103 EXPECT_FALSE(CrossSiteDocumentClassifier::SniffForXML(non_xml_data)); | |
| 104 | |
| 105 // Basic bounds check. | |
| 106 EXPECT_FALSE(CrossSiteDocumentClassifier::SniffForXML(empty_data)); | |
| 107 } | |
| 108 | |
| 109 TEST(CrossSiteDocumentClassifierTest, SniffForJSON) { | |
| 110 StringPiece json_data("\t\t\r\n { \"name\" : \"chrome\", "); | |
| 111 StringPiece non_json_data0("\t\t\r\n { name : \"chrome\", "); | |
| 112 StringPiece non_json_data1("\t\t\r\n foo({ \"name\" : \"chrome\", "); | |
| 113 StringPiece empty_data(""); | |
| 114 | |
| 115 EXPECT_TRUE(CrossSiteDocumentClassifier::SniffForJSON(json_data)); | |
| 116 EXPECT_FALSE(CrossSiteDocumentClassifier::SniffForJSON(non_json_data0)); | |
| 117 EXPECT_FALSE(CrossSiteDocumentClassifier::SniffForJSON(non_json_data1)); | |
| 118 | |
| 119 // Basic bounds check. | |
| 120 EXPECT_FALSE(CrossSiteDocumentClassifier::SniffForJSON(empty_data)); | |
| 121 } | |
| 122 | |
| 123 TEST(SiteIsolationStatsGathererTest, SniffForJS) { | |
| 124 StringPiece basic_js_data("var a = 4"); | |
| 125 StringPiece js_data("\t\t\r\n var a = 4"); | |
| 126 StringPiece json_data("\t\t\r\n { \"name\" : \"chrome\", "); | |
| 127 StringPiece empty_data(""); | |
| 128 | |
| 129 EXPECT_TRUE(SiteIsolationStatsGatherer::SniffForJS(js_data)); | |
| 130 EXPECT_FALSE(SiteIsolationStatsGatherer::SniffForJS(json_data)); | |
| 131 | |
| 132 // Basic bounds check. | |
| 133 EXPECT_FALSE(SiteIsolationStatsGatherer::SniffForJS(empty_data)); | |
| 134 } | |
| 135 | |
| 136 } // namespace content | |
| OLD | NEW |