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

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

Issue 2391383003: Add Origin::CreateFromNormalizedTuple and call from WebSecurityOrigin (Closed)
Patch Set: ncarter review Created 4 years, 2 months 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/public/platform/WebSecurityOrigin.h » ('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"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" 12 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
13 #include "third_party/WebKit/public/platform/WebString.h" 13 #include "third_party/WebKit/public/platform/WebString.h"
14 #include "url/origin.h" 14 #include "url/origin.h"
15 15
16 namespace content { 16 namespace content {
17 17
18 TEST(BlinkPlatformTest, castWebSecurityOrigin) { 18 void CheckCastedOriginsAlreadyNormalized(
19 const blink::WebSecurityOrigin& origin) {
20 url::Origin checked_origin =
21 url::Origin::UnsafelyCreateOriginWithoutNormalization(
22 origin.protocol().utf8(), origin.host().utf8(),
23 origin.effectivePort());
24 url::Origin non_checked_origin = url::Origin::CreateFromNormalizedTuple(
25 origin.protocol().utf8(), origin.host().utf8(), origin.effectivePort());
26 EXPECT_EQ(checked_origin.scheme(), non_checked_origin.scheme());
27 EXPECT_EQ(checked_origin.host(), non_checked_origin.host());
28 EXPECT_EQ(checked_origin.port(), non_checked_origin.port());
29 }
30
31 TEST(BlinkPlatformTest, CastWebSecurityOrigin) {
19 struct TestCase { 32 struct TestCase {
20 const char* origin; 33 const char* url;
21 const char* scheme; 34 const char* scheme;
22 const char* host; 35 const char* host;
23 uint16_t port; 36 uint16_t port;
24 } cases[] = { 37 } cases[] = {
25 {"http://example.com", "http", "example.com", 80}, 38 {"http://example.com", "http", "example.com", 80},
26 {"http://example.com:80", "http", "example.com", 80}, 39 {"http://example.com:80", "http", "example.com", 80},
27 {"http://example.com:81", "http", "example.com", 81}, 40 {"http://example.com:81", "http", "example.com", 81},
28 {"https://example.com", "https", "example.com", 443}, 41 {"https://example.com", "https", "example.com", 443},
29 {"https://example.com:443", "https", "example.com", 443}, 42 {"https://example.com:443", "https", "example.com", 443},
30 {"https://example.com:444", "https", "example.com", 444}, 43 {"https://example.com:444", "https", "example.com", 444},
44
45 // Copied from url/origin_unittest.cc
46
47 // IP Addresses
48 {"http://192.168.9.1/", "http", "192.168.9.1", 80},
49 {"http://[2001:db8::1]/", "http", "[2001:db8::1]", 80},
50
51 // Punycode
52 {"http://☃.net/", "http", "xn--n3h.net", 80},
53 {"blob:http://☃.net/", "http", "xn--n3h.net", 80},
54
55 // Generic URLs
56 {"http://example.com/", "http", "example.com", 80},
57 {"http://example.com:123/", "http", "example.com", 123},
58 {"https://example.com/", "https", "example.com", 443},
59 {"https://example.com:123/", "https", "example.com", 123},
60 {"http://user:pass@example.com/", "http", "example.com", 80},
61 {"http://example.com:123/?query", "http", "example.com", 123},
62 {"https://example.com/#1234", "https", "example.com", 443},
63 {"https://u:p@example.com:123/?query#1234", "https", "example.com", 123},
64
65 // Registered URLs
66 {"ftp://example.com/", "ftp", "example.com", 21},
67 {"ws://example.com/", "ws", "example.com", 80},
68 {"wss://example.com/", "wss", "example.com", 443},
69
70 // file: URLs
71 {"file:///etc/passwd", "file", "", 0},
72 {"file://example.com/etc/passwd", "file", "example.com", 0},
73
74 // Filesystem:
75 {"filesystem:http://example.com/type/", "http", "example.com", 80},
76 {"filesystem:http://example.com:123/type/", "http", "example.com", 123},
77 {"filesystem:https://example.com/type/", "https", "example.com", 443},
78 {"filesystem:https://example.com:123/type/", "https", "example.com", 123},
79
80 // Blob:
81 {"blob:http://example.com/guid-goes-here", "http", "example.com", 80},
82 {"blob:http://example.com:123/guid-goes-here", "http", "example.com",
83 123},
84 {"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},
86 {"blob:https://example.co.uk/guid-goes-here", "https", "example.co.uk", 44 3},
ncarter (slow) 2016/10/11 23:29:46 80 cols.
31 }; 87 };
32 88
33 for (const auto& test : cases) { 89 for (const auto& test : cases) {
34 blink::WebSecurityOrigin web_origin = 90 blink::WebSecurityOrigin web_origin =
35 blink::WebSecurityOrigin::createFromString( 91 blink::WebSecurityOrigin::createFromString(
36 blink::WebString::fromUTF8(test.origin)); 92 blink::WebString::fromUTF8(test.url));
37 EXPECT_EQ(test.scheme, web_origin.protocol().utf8()); 93 EXPECT_EQ(test.scheme, web_origin.protocol().utf8());
38 EXPECT_EQ(test.host, web_origin.host().utf8()); 94 EXPECT_EQ(test.host, web_origin.host().utf8());
39 EXPECT_EQ(test.port, web_origin.effectivePort()); 95 EXPECT_EQ(test.port, web_origin.effectivePort());
40 96
41 url::Origin url_origin = web_origin; 97 url::Origin url_origin = web_origin;
42 EXPECT_EQ(test.scheme, url_origin.scheme()); 98 EXPECT_EQ(test.scheme, url_origin.scheme());
43 EXPECT_EQ(test.host, url_origin.host()); 99 EXPECT_EQ(test.host, url_origin.host());
44 EXPECT_EQ(test.port, url_origin.port()); 100 EXPECT_EQ(test.port, url_origin.port());
45 101
46 web_origin = url::Origin(GURL(test.origin)); 102 web_origin = url::Origin(GURL(test.url));
47 EXPECT_EQ(test.scheme, web_origin.protocol().utf8()); 103 EXPECT_EQ(test.scheme, web_origin.protocol().utf8());
48 EXPECT_EQ(test.host, web_origin.host().utf8()); 104 EXPECT_EQ(test.host, web_origin.host().utf8());
49 EXPECT_EQ(test.port, web_origin.effectivePort()); 105 EXPECT_EQ(test.port, web_origin.effectivePort());
106
107 CheckCastedOriginsAlreadyNormalized(web_origin);
50 } 108 }
51 109
52 blink::WebSecurityOrigin web_origin = 110 blink::WebSecurityOrigin web_origin =
53 blink::WebSecurityOrigin::createUnique(); 111 blink::WebSecurityOrigin::createUnique();
54 EXPECT_TRUE(web_origin.isUnique()); 112 EXPECT_TRUE(web_origin.isUnique());
55 113
56 url::Origin url_origin = web_origin; 114 url::Origin url_origin = web_origin;
57 EXPECT_TRUE(url_origin.unique()); 115 EXPECT_TRUE(url_origin.unique());
58 116
59 web_origin = url::Origin(GURL("")); 117 web_origin = url::Origin(GURL(""));
60 EXPECT_TRUE(web_origin.isUnique()); 118 EXPECT_TRUE(web_origin.isUnique());
61 } 119 }
62 120
121 // This test ensures that WebSecurityOrigins can safely use
122 // url::Origin::CreateFromNormalizedTuple when doing conversions.
123 TEST(BlinkPlatformTest, WebSecurityOriginNormalization) {
124 struct TestCases {
125 const char* url;
126 } cases[] = {{""},
127 {"javascript:alert(1)"},
128 {"file://example.com:443/etc/passwd"},
129 {"blob:https://example.com/uuid-goes-here"},
130 {"filesystem:https://example.com/temporary/yay.png"},
131 {"data"},
132 {"blob:"},
133 {"xkcd://927"},
134 {"filesystem"},
135 {"data://example.com:80"},
136 {"http://☃.net:80"},
137 {"http\nmore://example.com:80"},
138 {"http\rmore://:example.com:80"},
139 {"http\n://example.com:80"},
140 {"http\r://example.com:80"},
141 {"http://example.com\nnot-example.com:80"},
142 {"http://example.com\rnot-example.com:80"},
143 {"http://example.com\n:80"},
144 {"http://example.com\r:80"},
145 {"http://example.com:0"},
146 {"http://EXAMPLE.com"},
147 {"http://EXAMPLE.com/%3Afoo"},
148 {"https://example.com:443"},
149 {"file:///"},
150 {"file:///root:80"}};
151
152 for (const auto& test : cases) {
153 SCOPED_TRACE(testing::Message() << test.url);
154 blink::WebSecurityOrigin web_origin =
155 blink::WebSecurityOrigin::createFromString(
156 blink::WebString::fromUTF8(test.url));
157 CheckCastedOriginsAlreadyNormalized(web_origin);
158 }
159 }
160
63 } // namespace content 161 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/public/platform/WebSecurityOrigin.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698