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

Side by Side Diff: url/origin_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 | « url/origin.cc ('k') | no next file » | 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 EXPECT_EQ(0, origin.port()); 58 EXPECT_EQ(0, origin.port());
59 EXPECT_TRUE(origin.unique()); 59 EXPECT_TRUE(origin.unique());
60 EXPECT_FALSE(origin.IsSameOriginWith(origin)); 60 EXPECT_FALSE(origin.IsSameOriginWith(origin));
61 EXPECT_FALSE(unique_origin.IsSameOriginWith(origin)); 61 EXPECT_FALSE(unique_origin.IsSameOriginWith(origin));
62 EXPECT_FALSE(origin.IsSameOriginWith(unique_origin)); 62 EXPECT_FALSE(origin.IsSameOriginWith(unique_origin));
63 63
64 ExpectParsedUrlsEqual(GURL(origin.Serialize()), origin.GetURL()); 64 ExpectParsedUrlsEqual(GURL(origin.Serialize()), origin.GetURL());
65 } 65 }
66 } 66 }
67 67
68 TEST(OriginTest, ConstructFromTuple) {
69 struct TestCases {
70 const char* const scheme;
71 const char* const host;
72 const uint16_t port;
73 const char* const suborigin;
74 } cases[] = {
75 {"http", "example.com", 80, ""},
76 {"http", "example.com", 123, ""},
77 {"https", "example.com", 443, ""},
78 {"http-so", "foobar.example.com", 80, "foobar"},
79 {"http-so", "foobar.example.com", 123, "foobar"},
80 {"https-so", "foobar.example.com", 443, "foobar"},
81 };
82
83 for (const auto& test_case : cases) {
84 testing::Message scope_message;
85 if (test_case.suborigin != std::string()) {
86 scope_message << test_case.scheme << "-so://" << test_case.suborigin
87 << "." << test_case.host << ":" << test_case.port;
88 } else {
89 scope_message << test_case.scheme << "://" << test_case.host << ":"
90 << test_case.port;
91 }
92 SCOPED_TRACE(scope_message);
93
94 url::Origin origin_without_suborigin =
95 url::Origin::CreateFromNormalizedTuple(test_case.scheme, test_case.host,
96 test_case.port);
97
98 url::Origin origin_with_suborigin =
99 url::Origin::CreateFromNormalizedTupleWithSuborigin(
100 test_case.scheme, test_case.host, test_case.port,
101 test_case.suborigin);
102
103 EXPECT_EQ(test_case.scheme, origin_without_suborigin.scheme());
104 EXPECT_EQ(test_case.host, origin_without_suborigin.host());
105 EXPECT_EQ(test_case.port, origin_without_suborigin.port());
106
107 EXPECT_EQ(test_case.scheme, origin_with_suborigin.scheme());
108 EXPECT_EQ(test_case.host, origin_with_suborigin.host());
109 EXPECT_EQ(test_case.port, origin_with_suborigin.port());
110 EXPECT_EQ(test_case.suborigin, origin_with_suborigin.suborigin());
111 }
112 }
113
68 TEST(OriginTest, ConstructFromGURL) { 114 TEST(OriginTest, ConstructFromGURL) {
69 url::Origin different_origin(GURL("https://not-in-the-list.test/")); 115 url::Origin different_origin(GURL("https://not-in-the-list.test/"));
70 116
71 struct TestCases { 117 struct TestCases {
72 const char* const url; 118 const char* const url;
73 const char* const expected_scheme; 119 const char* const expected_scheme;
74 const char* const expected_host; 120 const char* const expected_host;
75 const uint16_t expected_port; 121 const uint16_t expected_port;
76 } cases[] = { 122 } cases[] = {
77 // IP Addresses 123 // IP Addresses
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 GURL invalid_url("google.com"); 501 GURL invalid_url("google.com");
456 ASSERT_FALSE(invalid_url.is_valid()); 502 ASSERT_FALSE(invalid_url.is_valid());
457 EXPECT_FALSE(url::Origin(invalid_url).DomainIs("google.com")); 503 EXPECT_FALSE(url::Origin(invalid_url).DomainIs("google.com"));
458 504
459 // Unique origins. 505 // Unique origins.
460 EXPECT_FALSE(url::Origin().DomainIs("")); 506 EXPECT_FALSE(url::Origin().DomainIs(""));
461 EXPECT_FALSE(url::Origin().DomainIs("com")); 507 EXPECT_FALSE(url::Origin().DomainIs("com"));
462 } 508 }
463 509
464 } // namespace url 510 } // namespace url
OLDNEW
« no previous file with comments | « url/origin.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698