OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 "url/origin.h" | |
6 #include "testing/gtest/include/gtest/gtest.h" | |
7 #include "url/gurl.h" | |
8 | |
9 namespace { | |
10 | |
11 TEST(OriginTest, uniqueOrigin) { | |
Ryan Sleevi
2015/07/10 11:59:54
Not in Blink, so Chromium naming
TEST(OriginTest,
Mike West
2015/07/17 09:58:10
GRRRRR.
| |
12 url::Origin uniqueOrigin; | |
Ryan Sleevi
2015/07/10 11:59:54
unique_origin
Mike West
2015/07/17 09:58:09
GRRR.
| |
13 EXPECT_EQ("", uniqueOrigin.scheme()); | |
14 EXPECT_EQ("", uniqueOrigin.host()); | |
15 EXPECT_EQ(0, uniqueOrigin.port()); | |
16 EXPECT_TRUE(uniqueOrigin.unique()); | |
17 EXPECT_FALSE(uniqueOrigin.IsSameOriginWith(uniqueOrigin)); | |
18 | |
19 const char* urls[] = {"data:text/html,Hello!", | |
Ryan Sleevi
2015/07/10 11:59:54
const char* const urls[]
Mike West
2015/07/17 09:58:09
const char* const const_urls[] const
| |
20 "javascript:alert(1)", | |
21 "file://example.com:443/etc/passwd", | |
22 "yay", | |
23 "http::///invalid.example.com/"}; | |
24 | |
25 for (const auto& test : urls) { | |
26 SCOPED_TRACE(test); | |
27 GURL url(test); | |
28 url::Origin origin(url); | |
29 EXPECT_EQ("", origin.scheme()); | |
30 EXPECT_EQ("", origin.host()); | |
31 EXPECT_EQ(0, origin.port()); | |
32 EXPECT_TRUE(origin.unique()); | |
33 EXPECT_FALSE(origin.IsSameOriginWith(origin)); | |
34 EXPECT_FALSE(uniqueOrigin.IsSameOriginWith(origin)); | |
35 EXPECT_FALSE(origin.IsSameOriginWith(uniqueOrigin)); | |
36 } | |
37 } | |
38 | |
39 TEST(OriginTest, GURLConstruction) { | |
Ryan Sleevi
2015/07/10 11:59:54
nit: TEST(OriginTest, ConstructFromGURL) {
| |
40 url::Origin differentOrigin(GURL("https://not-in-the-list.test/")); | |
Ryan Sleevi
2015/07/10 11:59:54
different_origin
| |
41 | |
42 struct TestCases { | |
43 const char* url; | |
Ryan Sleevi
2015/07/10 11:59:54
const char* const (and friends)
| |
44 const char* scheme; | |
45 const char* host; | |
46 uint16 port; | |
Ryan Sleevi
2015/07/10 11:59:54
These are all expected_scheme, expected_host, expe
| |
47 } cases[] = { | |
Ryan Sleevi
2015/07/10 11:59:54
Perhaps add some test cases for non-generic but re
| |
48 // IP Addresses | |
49 {"http://192.168.9.1/", "http", "192.168.9.1", 80}, | |
50 {"http://[2001:db8::1]/", "http", "[2001:db8::1]", 80}, | |
51 | |
52 // Punycode | |
53 {"http://☃.net/", "http", "xn--n3h.net", 80}, | |
54 {"blob:http://☃.net/", "http", "xn--n3h.net", 80}, | |
55 | |
56 // Webby URLs | |
Ryan Sleevi
2015/07/10 11:59:54
I cringe somewhat at the colloquial "webby" - "gen
Mike West
2015/07/17 09:58:09
You are no fun. :(
| |
57 {"http://example.com/", "http", "example.com", 80}, | |
58 {"http://example.com:123/", "http", "example.com", 123}, | |
59 {"https://example.com/", "https", "example.com", 443}, | |
60 {"https://example.com:123/", "https", "example.com", 123}, | |
61 {"http://user:pass@example.com/", "http", "example.com", 80}, | |
62 {"http://example.com:123/?query", "http", "example.com", 123}, | |
63 {"https://example.com/#1234", "https", "example.com", 443}, | |
64 {"https://u:p@example.com:123/?query#1234", "https", "example.com", 123}, | |
65 | |
66 // file: URLs | |
67 {"file:///etc/passwd", "file", "", 0}, | |
68 {"file://example.com/etc/passwd", "file", "example.com", 0}, | |
69 | |
70 // Filesystem: | |
71 {"filesystem:http://example.com/type/", "http", "example.com", 80}, | |
72 {"filesystem:http://example.com:123/type/", "http", "example.com", 123}, | |
73 {"filesystem:https://example.com/type/", "https", "example.com", 443}, | |
74 {"filesystem:https://example.com:123/type/", "https", "example.com", 123}, | |
75 | |
76 // Blob: | |
77 {"blob:http://example.com/guid-goes-here", "http", "example.com", 80}, | |
78 {"blob:http://example.com:123/guid-goes-here", "http", "example.com", 123} , | |
79 {"blob:https://example.com/guid-goes-here", "https", "example.com", 443}, | |
80 {"blob:http://u:p@example.com/guid-goes-here", "http", "example.com", 80}, | |
81 }; | |
82 | |
83 for (const auto& test : cases) { | |
84 SCOPED_TRACE(test.url); | |
85 GURL url(test.url); | |
Ryan Sleevi
2015/07/10 11:59:54
perhaps your test should make sure that the GURL i
| |
86 url::Origin origin(url); | |
87 EXPECT_EQ(test.scheme, origin.scheme()); | |
88 EXPECT_EQ(test.host, origin.host()); | |
89 EXPECT_EQ(test.port, origin.port()); | |
90 EXPECT_FALSE(origin.unique()); | |
91 EXPECT_TRUE(origin.IsSameOriginWith(origin)); | |
92 EXPECT_FALSE(differentOrigin.IsSameOriginWith(origin)); | |
93 EXPECT_FALSE(origin.IsSameOriginWith(differentOrigin)); | |
94 } | |
95 } | |
96 /* | |
97 TEST(SchemeHostPortTest, Serialization) { | |
98 struct TestCases { | |
99 const char* url; | |
Ryan Sleevi
2015/07/10 11:59:54
const char* const (and friends)
| |
100 const char* expected; | |
101 } cases[] = { | |
102 {"http://192.168.9.1/", "http://192.168.9.1"}, | |
103 {"http://[2001:db8::1]/", "http://[2001:db8::1]"}, | |
104 {"http://☃.net/", "http://xn--n3h.net"}, | |
105 {"http://example.com/", "http://example.com"}, | |
106 {"http://example.com:123/", "http://example.com:123"}, | |
107 {"https://example.com/", "https://example.com"}, | |
108 {"https://example.com:123/", "https://example.com:123"}, | |
109 {"file:///etc/passwd", "file://"}, | |
110 {"file://example.com/etc/passwd", "file://example.com"}, | |
111 }; | |
112 | |
113 for (const auto& test : cases) { | |
114 SCOPED_TRACE(test.url); | |
115 GURL url(test.url); | |
116 url::SchemeHostPort tuple(url); | |
117 EXPECT_EQ(test.expected, tuple.Serialize()); | |
118 } | |
119 } | |
120 | |
121 TEST(SchemeHostPortTest, Comparison) { | |
122 // These tuples are arranged in increasing order: | |
123 struct SchemeHostPorts { | |
124 const char* scheme; | |
125 const char* host; | |
126 uint16 port; | |
127 } tuples[] = { | |
128 {"http", "a", 80}, | |
129 {"http", "a", 81}, | |
130 {"http", "b", 80}, | |
131 {"http", "b", 81}, | |
132 {"https", "a", 80}, | |
133 {"https", "a", 81}, | |
134 {"https", "b", 80}, | |
135 {"https", "b", 81}, | |
136 }; | |
137 | |
138 for (size_t i = 0; i < arraysize(tuples); i++) { | |
139 url::SchemeHostPort current(tuples[i].scheme, tuples[i].host, | |
140 tuples[i].port); | |
141 for (size_t j = 0; j < arraysize(tuples); j++) { | |
142 url::SchemeHostPort toCompare(tuples[j].scheme, tuples[j].host, | |
143 tuples[j].port); | |
144 EXPECT_EQ(i < j, current < toCompare) << i << " < " << j; | |
145 EXPECT_EQ(i > j, current > toCompare) << i << " > " << j; | |
146 } | |
147 } | |
148 } | |
149 */ | |
150 } // namespace url | |
OLD | NEW |