Fix for Geolocation webTCT failures
[platform/framework/web/chromium-efl.git] / url / gurl_abstract_tests.h
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.
4
5 #ifndef URL_GURL_ABSTRACT_TESTS_H_
6 #define URL_GURL_ABSTRACT_TESTS_H_
7
8 // Test suite for tests that cover both url::Url and blink::SecurityUrl.
9 //
10 // AbstractUrlTest below abstracts away differences between GURL and blink::KURL
11 // by parametrizing the tests with a class that has to expose the following
12 // members:
13 //   using UrlType = ...;
14 //   static UrlType CreateUrlFromString(std::string_view s);
15 //   static bool IsAboutBlank(const UrlType& url);
16 //   static bool IsAboutSrcdoc(const UrlType& url);
17 template <typename TUrlTraits>
18 class AbstractUrlTest : public testing::Test {
19  protected:
20   // Wrappers that help ellide away TUrlTraits.
21   //
22   // Note that calling the wrappers needs to be prefixed with `this->...` to
23   // avoid hitting: explicit qualification required to use member 'IsAboutBlank'
24   // from dependent base class.
25   using UrlType = typename TUrlTraits::UrlType;
26   UrlType CreateUrlFromString(std::string_view s) {
27     return TUrlTraits::CreateUrlFromString(s);
28   }
29   bool IsAboutBlank(const UrlType& url) {
30     return TUrlTraits::IsAboutBlank(url);
31   }
32   bool IsAboutSrcdoc(const UrlType& url) {
33     return TUrlTraits::IsAboutSrcdoc(url);
34   }
35 };
36
37 TYPED_TEST_SUITE_P(AbstractUrlTest);
38
39 TYPED_TEST_P(AbstractUrlTest, IsAboutBlankTest) {
40   // See https://tools.ietf.org/html/rfc6694 which explicitly allows
41   // `about-query` and `about-fragment` parts in about: URLs.
42   const std::string kAboutBlankUrls[] = {"about:blank", "about:blank?foo",
43                                          "about:blank/#foo",
44                                          "about:blank?foo#foo"};
45   for (const auto& input : kAboutBlankUrls) {
46     SCOPED_TRACE(testing::Message() << "Test input: " << input);
47     auto url = this->CreateUrlFromString(input);
48     EXPECT_TRUE(this->IsAboutBlank(url));
49   }
50
51   const std::string kNotAboutBlankUrls[] = {"",
52                                             "about",
53                                             "about:",
54                                             "about:blanky",
55                                             "about:blan",
56                                             "about:about:blank:",
57                                             "data:blank",
58                                             "http:blank",
59                                             "about://blank",
60                                             "about:blank/foo",
61                                             "about://:8000/blank",
62                                             "about://foo:foo@/blank",
63                                             "foo@about:blank",
64                                             "foo:bar@about:blank",
65                                             "about:blank:8000",
66                                             "about:blANk"};
67   for (const auto& input : kNotAboutBlankUrls) {
68     SCOPED_TRACE(testing::Message() << "Test input: " << input);
69     auto url = this->CreateUrlFromString(input);
70     EXPECT_FALSE(this->IsAboutBlank(url));
71   }
72 }
73
74 TYPED_TEST_P(AbstractUrlTest, IsAboutSrcdocTest) {
75   // See https://tools.ietf.org/html/rfc6694 which explicitly allows
76   // `about-query` and `about-fragment` parts in about: URLs.
77   //
78   // `about:srcdoc` is defined in
79   // https://html.spec.whatwg.org/multipage/urls-and-fetching.html#about:srcdoc
80   // which refers to rfc6694 for details.
81   const std::string kAboutSrcdocUrls[] = {
82       "about:srcdoc", "about:srcdoc/", "about:srcdoc?foo", "about:srcdoc/#foo",
83       "about:srcdoc?foo#foo"};
84   for (const auto& input : kAboutSrcdocUrls) {
85     SCOPED_TRACE(testing::Message() << "Test input: " << input);
86     auto url = this->CreateUrlFromString(input);
87     EXPECT_TRUE(this->IsAboutSrcdoc(url));
88   }
89
90   const std::string kNotAboutSrcdocUrls[] = {"",
91                                              "about",
92                                              "about:",
93                                              "about:srcdocx",
94                                              "about:srcdo",
95                                              "about:about:srcdoc:",
96                                              "data:srcdoc",
97                                              "http:srcdoc",
98                                              "about:srcdo",
99                                              "about://srcdoc",
100                                              "about://srcdoc\\",
101                                              "about:srcdoc/foo",
102                                              "about://:8000/srcdoc",
103                                              "about://foo:foo@/srcdoc",
104                                              "foo@about:srcdoc",
105                                              "foo:bar@about:srcdoc",
106                                              "about:srcdoc:8000",
107                                              "about:srCDOc"};
108   for (const auto& input : kNotAboutSrcdocUrls) {
109     SCOPED_TRACE(testing::Message() << "Test input: " << input);
110     auto url = this->CreateUrlFromString(input);
111     EXPECT_FALSE(this->IsAboutSrcdoc(url));
112   }
113 }
114
115 REGISTER_TYPED_TEST_SUITE_P(AbstractUrlTest,
116                             IsAboutBlankTest,
117                             IsAboutSrcdocTest);
118
119 #endif  // URL_GURL_ABSTRACT_TESTS_H_