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

Side by Side Diff: content/common/origin_util_unittest.cc

Issue 2403713002: Add suborigin logic to url::Origin (Closed)
Patch Set: Fix unit test 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 | « content/common/origin_util.cc ('k') | content/common/url_schemes.cc » ('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 2015 The Chromium Authors. All rights reserved. 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 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/public/common/origin_util.h" 5 #include "content/public/common/origin_util.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "url/gurl.h" 7 #include "url/gurl.h"
8 8
9 namespace content { 9 namespace content {
10 10
(...skipping 29 matching lines...) Expand all
40 40
41 EXPECT_FALSE( 41 EXPECT_FALSE(
42 IsOriginSecure(GURL("filesystem:http://www.example.com/temporary/"))); 42 IsOriginSecure(GURL("filesystem:http://www.example.com/temporary/")));
43 EXPECT_FALSE( 43 EXPECT_FALSE(
44 IsOriginSecure(GURL("filesystem:ftp://www.example.com/temporary/"))); 44 IsOriginSecure(GURL("filesystem:ftp://www.example.com/temporary/")));
45 EXPECT_TRUE(IsOriginSecure(GURL("filesystem:ftp://127.0.0.1/temporary/"))); 45 EXPECT_TRUE(IsOriginSecure(GURL("filesystem:ftp://127.0.0.1/temporary/")));
46 EXPECT_TRUE( 46 EXPECT_TRUE(
47 IsOriginSecure(GURL("filesystem:https://www.example.com/temporary/"))); 47 IsOriginSecure(GURL("filesystem:https://www.example.com/temporary/")));
48 } 48 }
49 49
50 TEST(OriginUtilTest, Suborigins) {
51 GURL no_suborigin_simple_url("https://b");
52 GURL suborigin_simple_url("https-so://a.b");
53 GURL no_suborigin_path_url("https://example.com/some/path");
54 GURL suborigin_path_url("https-so://foobar.example.com/some/path");
55 GURL no_suborigin_url_with_port("https://example.com:1234");
56 GURL suborigin_url_with_port("https-so://foobar.example.com:1234");
57 GURL no_suborigin_url_with_query("https://example.com/some/path?query");
58 GURL suborigin_url_with_query(
59 "https-so://foobar.example.com/some/path?query");
60 GURL no_suborigin_url_with_fragment("https://example.com/some/path#fragment");
61 GURL suborigin_url_with_fragment(
62 "https-so://foobar.example.com/some/path#fragment");
63 GURL no_suborigin_url_big(
64 "https://example.com:1234/some/path?query#fragment");
65 GURL suborigin_url_big(
66 "https-so://foobar.example.com:1234/some/path?query#fragment");
67
68 EXPECT_FALSE(HasSuborigin(no_suborigin_simple_url));
69 EXPECT_FALSE(HasSuborigin(no_suborigin_path_url));
70 EXPECT_TRUE(HasSuborigin(suborigin_simple_url));
71 EXPECT_TRUE(HasSuborigin(suborigin_path_url));
72 EXPECT_TRUE(HasSuborigin(suborigin_url_with_port));
73 EXPECT_TRUE(HasSuborigin(suborigin_url_with_query));
74 EXPECT_TRUE(HasSuborigin(suborigin_url_with_fragment));
75 EXPECT_TRUE(HasSuborigin(suborigin_url_big));
76
77 EXPECT_EQ("", SuboriginFromUrl(no_suborigin_simple_url));
78 EXPECT_EQ("", SuboriginFromUrl(no_suborigin_path_url));
79 EXPECT_EQ("a", SuboriginFromUrl(suborigin_simple_url));
80 EXPECT_EQ("foobar", SuboriginFromUrl(suborigin_path_url));
81 EXPECT_EQ("foobar", SuboriginFromUrl(suborigin_url_with_port));
82 EXPECT_EQ("foobar", SuboriginFromUrl(suborigin_url_with_query));
83 EXPECT_EQ("foobar", SuboriginFromUrl(suborigin_url_with_fragment));
84 EXPECT_EQ("foobar", SuboriginFromUrl(suborigin_url_big));
85
86 EXPECT_EQ(no_suborigin_simple_url,
87 StripSuboriginFromUrl(no_suborigin_simple_url));
88 EXPECT_EQ(no_suborigin_path_url,
89 StripSuboriginFromUrl(no_suborigin_path_url));
90 EXPECT_EQ(no_suborigin_simple_url,
91 StripSuboriginFromUrl(suborigin_simple_url));
92 EXPECT_EQ(no_suborigin_path_url, StripSuboriginFromUrl(suborigin_path_url));
93 EXPECT_EQ(no_suborigin_url_with_port,
94 StripSuboriginFromUrl(suborigin_url_with_port));
95 EXPECT_EQ(no_suborigin_url_with_query,
96 StripSuboriginFromUrl(suborigin_url_with_query));
97 EXPECT_EQ(no_suborigin_url_with_fragment,
98 StripSuboriginFromUrl(suborigin_url_with_fragment));
99 EXPECT_EQ(no_suborigin_url_big, StripSuboriginFromUrl(suborigin_url_big));
100
101 // Failure cases/invalid suborigins
102 GURL just_dot_url("https-so://.");
103 GURL empty_hostname_url("https-so://");
104 GURL empty_suborigin_url("https-so://.foo");
105 GURL no_dot_url("https-so://foo");
106 GURL suborigin_but_empty_host_url("https-so://foo.");
107 EXPECT_FALSE(HasSuborigin(just_dot_url));
108 EXPECT_FALSE(HasSuborigin(empty_hostname_url));
109 EXPECT_FALSE(HasSuborigin(empty_suborigin_url));
110 EXPECT_FALSE(HasSuborigin(no_dot_url));
111 EXPECT_FALSE(HasSuborigin(suborigin_but_empty_host_url));
112
113 EXPECT_EQ("", SuboriginFromUrl(just_dot_url));
114 EXPECT_EQ("", SuboriginFromUrl(empty_hostname_url));
115 EXPECT_EQ("", SuboriginFromUrl(empty_suborigin_url));
116 EXPECT_EQ("", SuboriginFromUrl(no_dot_url));
117 EXPECT_EQ("", SuboriginFromUrl(suborigin_but_empty_host_url));
118
119 EXPECT_EQ(just_dot_url, StripSuboriginFromUrl(just_dot_url));
120 EXPECT_EQ(empty_hostname_url, StripSuboriginFromUrl(empty_hostname_url));
121 EXPECT_EQ(empty_suborigin_url, StripSuboriginFromUrl(empty_suborigin_url));
122 EXPECT_EQ(no_dot_url, StripSuboriginFromUrl(no_dot_url));
123 EXPECT_EQ(suborigin_but_empty_host_url,
124 StripSuboriginFromUrl(suborigin_but_empty_host_url));
125 }
126
127 } // namespace content 50 } // namespace content
OLDNEW
« no previous file with comments | « content/common/origin_util.cc ('k') | content/common/url_schemes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698