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

Side by Side Diff: content/child/blink_platform_impl_unittest.cc

Issue 2449233002: Add suborigins to WebSecurityOrigin (Closed)
Patch Set: Rebase on ToT Created 4 years, 1 month 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/exported/WebSecurityOrigin.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/child/blink_platform_impl.h" 5 #include "content/child/blink_platform_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 16 matching lines...) Expand all
27 EXPECT_EQ(checked_origin.host(), non_checked_origin.host()); 27 EXPECT_EQ(checked_origin.host(), non_checked_origin.host());
28 EXPECT_EQ(checked_origin.port(), non_checked_origin.port()); 28 EXPECT_EQ(checked_origin.port(), non_checked_origin.port());
29 } 29 }
30 30
31 TEST(BlinkPlatformTest, CastWebSecurityOrigin) { 31 TEST(BlinkPlatformTest, CastWebSecurityOrigin) {
32 struct TestCase { 32 struct TestCase {
33 const char* url; 33 const char* url;
34 const char* scheme; 34 const char* scheme;
35 const char* host; 35 const char* host;
36 uint16_t port; 36 uint16_t port;
37 const char* suborigin;
37 } cases[] = { 38 } cases[] = {
38 {"http://example.com", "http", "example.com", 80}, 39 {"http://example.com", "http", "example.com", 80, ""},
39 {"http://example.com:80", "http", "example.com", 80}, 40 {"http://example.com:80", "http", "example.com", 80, ""},
40 {"http://example.com:81", "http", "example.com", 81}, 41 {"http://example.com:81", "http", "example.com", 81, ""},
41 {"https://example.com", "https", "example.com", 443}, 42 {"https://example.com", "https", "example.com", 443, ""},
42 {"https://example.com:443", "https", "example.com", 443}, 43 {"https://example.com:443", "https", "example.com", 443, ""},
43 {"https://example.com:444", "https", "example.com", 444}, 44 {"https://example.com:444", "https", "example.com", 444, ""},
44 45
45 // Copied from url/origin_unittest.cc 46 // Copied from url/origin_unittest.cc
46 47
47 // IP Addresses 48 // IP Addresses
48 {"http://192.168.9.1/", "http", "192.168.9.1", 80}, 49 {"http://192.168.9.1/", "http", "192.168.9.1", 80, ""},
49 {"http://[2001:db8::1]/", "http", "[2001:db8::1]", 80}, 50 {"http://[2001:db8::1]/", "http", "[2001:db8::1]", 80, ""},
50 51
51 // Punycode 52 // Punycode
52 {"http://☃.net/", "http", "xn--n3h.net", 80}, 53 {"http://☃.net/", "http", "xn--n3h.net", 80, ""},
53 {"blob:http://☃.net/", "http", "xn--n3h.net", 80}, 54 {"blob:http://☃.net/", "http", "xn--n3h.net", 80, ""},
54 55
55 // Generic URLs 56 // Generic URLs
56 {"http://example.com/", "http", "example.com", 80}, 57 {"http://example.com/", "http", "example.com", 80, ""},
57 {"http://example.com:123/", "http", "example.com", 123}, 58 {"http://example.com:123/", "http", "example.com", 123, ""},
58 {"https://example.com/", "https", "example.com", 443}, 59 {"https://example.com/", "https", "example.com", 443, ""},
59 {"https://example.com:123/", "https", "example.com", 123}, 60 {"https://example.com:123/", "https", "example.com", 123, ""},
60 {"http://user:pass@example.com/", "http", "example.com", 80}, 61 {"http://user:pass@example.com/", "http", "example.com", 80, ""},
61 {"http://example.com:123/?query", "http", "example.com", 123}, 62 {"http://example.com:123/?query", "http", "example.com", 123, ""},
62 {"https://example.com/#1234", "https", "example.com", 443}, 63 {"https://example.com/#1234", "https", "example.com", 443, ""},
63 {"https://u:p@example.com:123/?query#1234", "https", "example.com", 123}, 64 {"https://u:p@example.com:123/?query#1234", "https", "example.com", 123,
65 ""},
64 66
65 // Registered URLs 67 // Registered URLs
66 {"ftp://example.com/", "ftp", "example.com", 21}, 68 {"ftp://example.com/", "ftp", "example.com", 21, ""},
67 {"ws://example.com/", "ws", "example.com", 80}, 69 {"ws://example.com/", "ws", "example.com", 80, ""},
68 {"wss://example.com/", "wss", "example.com", 443}, 70 {"wss://example.com/", "wss", "example.com", 443, ""},
69 71
70 // file: URLs 72 // file: URLs
71 {"file:///etc/passwd", "file", "", 0}, 73 {"file:///etc/passwd", "file", "", 0, ""},
72 {"file://example.com/etc/passwd", "file", "example.com", 0}, 74 {"file://example.com/etc/passwd", "file", "example.com", 0, ""},
73 75
74 // Filesystem: 76 // Filesystem:
75 {"filesystem:http://example.com/type/", "http", "example.com", 80}, 77 {"filesystem:http://example.com/type/", "http", "example.com", 80, ""},
76 {"filesystem:http://example.com:123/type/", "http", "example.com", 123}, 78 {"filesystem:http://example.com:123/type/", "http", "example.com", 123,
77 {"filesystem:https://example.com/type/", "https", "example.com", 443}, 79 ""},
78 {"filesystem:https://example.com:123/type/", "https", "example.com", 123}, 80 {"filesystem:https://example.com/type/", "https", "example.com", 443, ""},
81 {"filesystem:https://example.com:123/type/", "https", "example.com", 123,
82 ""},
79 83
80 // Blob: 84 // Blob:
81 {"blob:http://example.com/guid-goes-here", "http", "example.com", 80}, 85 {"blob:http://example.com/guid-goes-here", "http", "example.com", 80, ""},
82 {"blob:http://example.com:123/guid-goes-here", "http", "example.com", 86 {"blob:http://example.com:123/guid-goes-here", "http", "example.com", 123,
83 123}, 87 ""},
84 {"blob:https://example.com/guid-goes-here", "https", "example.com", 443}, 88 {"blob:https://example.com/guid-goes-here", "https", "example.com", 443,
85 {"blob:http://u:p@example.com/guid-goes-here", "http", "example.com", 80}, 89 ""},
90 {"blob:http://u:p@example.com/guid-goes-here", "http", "example.com", 80,
91 ""},
86 {"blob:https://example.co.uk/guid-goes-here", "https", "example.co.uk", 92 {"blob:https://example.co.uk/guid-goes-here", "https", "example.co.uk",
87 443}, 93 443, ""},
94
95 // Suborigins
96 {"http-so://foobar.example.com", "http", "example.com", 80, "foobar"},
97 {"http-so://foobar.example.com:80", "http", "example.com", 80, "foobar"},
98 {"http-so://foobar.example.com:81", "http", "example.com", 81, "foobar"},
99 {"https-so://foobar.example.com", "https", "example.com", 443, "foobar"},
100 {"https-so://foobar.example.com:443", "https", "example.com", 443,
101 "foobar"},
102 {"https-so://foobar.example.com:444", "https", "example.com", 444,
103 "foobar"},
88 }; 104 };
89 105
90 for (const auto& test : cases) { 106 for (const auto& test : cases) {
107 SCOPED_TRACE(testing::Message() << test.url);
91 blink::WebSecurityOrigin web_origin = 108 blink::WebSecurityOrigin web_origin =
92 blink::WebSecurityOrigin::createFromString( 109 blink::WebSecurityOrigin::createFromString(
93 blink::WebString::fromUTF8(test.url)); 110 blink::WebString::fromUTF8(test.url));
94 EXPECT_EQ(test.scheme, web_origin.protocol().utf8()); 111 EXPECT_EQ(test.scheme, web_origin.protocol().utf8());
95 EXPECT_EQ(test.host, web_origin.host().utf8()); 112 EXPECT_EQ(test.host, web_origin.host().utf8());
96 EXPECT_EQ(test.port, web_origin.effectivePort()); 113 EXPECT_EQ(test.port, web_origin.effectivePort());
114 EXPECT_EQ(test.suborigin, web_origin.suborigin().utf8());
97 115
98 url::Origin url_origin = web_origin; 116 url::Origin url_origin = web_origin;
99 EXPECT_EQ(test.scheme, url_origin.scheme()); 117 EXPECT_EQ(test.scheme, url_origin.scheme());
100 EXPECT_EQ(test.host, url_origin.host()); 118 EXPECT_EQ(test.host, url_origin.host());
101 EXPECT_EQ(test.port, url_origin.port()); 119 EXPECT_EQ(test.port, url_origin.port());
120 EXPECT_EQ(test.suborigin, url_origin.suborigin());
102 121
103 web_origin = url::Origin(GURL(test.url)); 122 web_origin = url::Origin(GURL(test.url));
104 EXPECT_EQ(test.scheme, web_origin.protocol().utf8()); 123 EXPECT_EQ(test.scheme, web_origin.protocol().utf8());
105 EXPECT_EQ(test.host, web_origin.host().utf8()); 124 EXPECT_EQ(test.host, web_origin.host().utf8());
106 EXPECT_EQ(test.port, web_origin.effectivePort()); 125 EXPECT_EQ(test.port, web_origin.effectivePort());
126 EXPECT_EQ(test.suborigin, web_origin.suborigin().utf8());
107 127
108 CheckCastedOriginsAlreadyNormalized(web_origin); 128 CheckCastedOriginsAlreadyNormalized(web_origin);
109 } 129 }
110 130
111 blink::WebSecurityOrigin web_origin = 131 {
112 blink::WebSecurityOrigin::createUnique(); 132 SCOPED_TRACE(testing::Message() << "null");
113 EXPECT_TRUE(web_origin.isUnique()); 133 blink::WebSecurityOrigin web_origin =
134 blink::WebSecurityOrigin::createUnique();
135 EXPECT_TRUE(web_origin.isUnique());
114 136
115 url::Origin url_origin = web_origin; 137 url::Origin url_origin = web_origin;
116 EXPECT_TRUE(url_origin.unique()); 138 EXPECT_TRUE(url_origin.unique());
139 EXPECT_EQ("", url_origin.suborigin());
117 140
118 web_origin = url::Origin(GURL("")); 141 web_origin = url::Origin(GURL(""));
119 EXPECT_TRUE(web_origin.isUnique()); 142 EXPECT_TRUE(web_origin.isUnique());
143 }
120 } 144 }
121 145
122 // This test ensures that WebSecurityOrigins can safely use 146 // This test ensures that WebSecurityOrigins can safely use
123 // url::Origin::CreateFromNormalizedTuple when doing conversions. 147 // url::Origin::CreateFromNormalizedTuple when doing conversions.
124 TEST(BlinkPlatformTest, WebSecurityOriginNormalization) { 148 TEST(BlinkPlatformTest, WebSecurityOriginNormalization) {
125 struct TestCases { 149 struct TestCases {
126 const char* url; 150 const char* url;
127 } cases[] = {{""}, 151 } cases[] = {{""},
128 {"javascript:alert(1)"}, 152 {"javascript:alert(1)"},
129 {"file://example.com:443/etc/passwd"}, 153 {"file://example.com:443/etc/passwd"},
(...skipping 23 matching lines...) Expand all
153 for (const auto& test : cases) { 177 for (const auto& test : cases) {
154 SCOPED_TRACE(testing::Message() << test.url); 178 SCOPED_TRACE(testing::Message() << test.url);
155 blink::WebSecurityOrigin web_origin = 179 blink::WebSecurityOrigin web_origin =
156 blink::WebSecurityOrigin::createFromString( 180 blink::WebSecurityOrigin::createFromString(
157 blink::WebString::fromUTF8(test.url)); 181 blink::WebString::fromUTF8(test.url));
158 CheckCastedOriginsAlreadyNormalized(web_origin); 182 CheckCastedOriginsAlreadyNormalized(web_origin);
159 } 183 }
160 } 184 }
161 185
162 } // namespace content 186 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/exported/WebSecurityOrigin.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698