1 // Copyright 2021 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "url/origin_abstract_tests.h"
9 void ExpectParsedUrlsEqual(const GURL& a, const GURL& b) {
11 const Parsed& a_parsed = a.parsed_for_possibly_invalid_spec();
12 const Parsed& b_parsed = b.parsed_for_possibly_invalid_spec();
13 EXPECT_EQ(a_parsed.scheme.begin, b_parsed.scheme.begin);
14 EXPECT_EQ(a_parsed.scheme.len, b_parsed.scheme.len);
15 EXPECT_EQ(a_parsed.username.begin, b_parsed.username.begin);
16 EXPECT_EQ(a_parsed.username.len, b_parsed.username.len);
17 EXPECT_EQ(a_parsed.password.begin, b_parsed.password.begin);
18 EXPECT_EQ(a_parsed.password.len, b_parsed.password.len);
19 EXPECT_EQ(a_parsed.host.begin, b_parsed.host.begin);
20 EXPECT_EQ(a_parsed.host.len, b_parsed.host.len);
21 EXPECT_EQ(a_parsed.port.begin, b_parsed.port.begin);
22 EXPECT_EQ(a_parsed.port.len, b_parsed.port.len);
23 EXPECT_EQ(a_parsed.path.begin, b_parsed.path.begin);
24 EXPECT_EQ(a_parsed.path.len, b_parsed.path.len);
25 EXPECT_EQ(a_parsed.query.begin, b_parsed.query.begin);
26 EXPECT_EQ(a_parsed.query.len, b_parsed.query.len);
27 EXPECT_EQ(a_parsed.ref.begin, b_parsed.ref.begin);
28 EXPECT_EQ(a_parsed.ref.len, b_parsed.ref.len);
32 Origin UrlOriginTestTraits::CreateOriginFromString(std::string_view s) {
33 return Origin::Create(GURL(s));
37 Origin UrlOriginTestTraits::CreateUniqueOpaqueOrigin() {
42 Origin UrlOriginTestTraits::CreateWithReferenceOrigin(
44 const Origin& reference_origin) {
45 return Origin::Resolve(GURL(url), reference_origin);
49 Origin UrlOriginTestTraits::DeriveNewOpaqueOrigin(
50 const Origin& reference_origin) {
51 return reference_origin.DeriveNewOpaqueOrigin();
55 bool UrlOriginTestTraits::IsOpaque(const Origin& origin) {
56 return origin.opaque();
60 std::string UrlOriginTestTraits::GetScheme(const Origin& origin) {
61 return origin.scheme();
65 std::string UrlOriginTestTraits::GetHost(const Origin& origin) {
70 uint16_t UrlOriginTestTraits::GetPort(const Origin& origin) {
75 SchemeHostPort UrlOriginTestTraits::GetTupleOrPrecursorTupleIfOpaque(
76 const Origin& origin) {
77 return origin.GetTupleOrPrecursorTupleIfOpaque();
81 bool UrlOriginTestTraits::IsSameOrigin(const Origin& a, const Origin& b) {
82 return a.IsSameOriginWith(b);
86 std::string UrlOriginTestTraits::Serialize(const Origin& origin) {
87 std::string serialized = origin.Serialize();
89 // Extra test assertion for GetURL (which doesn't have an equivalent in
90 // blink::SecurityOrigin).
91 ExpectParsedUrlsEqual(GURL(serialized), origin.GetURL());
97 bool UrlOriginTestTraits::IsValidUrl(std::string_view str) {
98 return GURL(str).is_valid();
101 // This is an abstract test suite which is instantiated by each implementation.
102 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AbstractOriginTest);