2 Star 0 Fork 0

chromium_develop/chromium_url

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
gurl_abstract_tests.h 5.25 KB
一键复制 编辑 原始数据 按行查看 历史
李想 提交于 2022-08-16 16:29 . chromium origin init
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef URL_GURL_ABSTRACT_TESTS_H_
#define URL_GURL_ABSTRACT_TESTS_H_
// Test suite for tests that cover both url::Url and blink::SecurityUrl.
//
// AbstractUrlTest below abstracts away differences between GURL and blink::KURL
// by parametrizing the tests with a class that has to expose the following
// members:
// using UrlType = ...;
// static UrlType CreateUrlFromString(base::StringPiece s);
// static bool IsAboutBlank(const UrlType& url);
// static bool IsAboutSrcdoc(const UrlType& url);
template <typename TUrlTraits>
class AbstractUrlTest : public testing::Test {
protected:
// Wrappers that help ellide away TUrlTraits.
//
// Note that calling the wrappers needs to be prefixed with `this->...` to
// avoid hitting: explicit qualification required to use member 'IsAboutBlank'
// from dependent base class.
using UrlType = typename TUrlTraits::UrlType;
UrlType CreateUrlFromString(base::StringPiece s) {
return TUrlTraits::CreateUrlFromString(s);
}
bool IsAboutBlank(const UrlType& url) {
return TUrlTraits::IsAboutBlank(url);
}
bool IsAboutSrcdoc(const UrlType& url) {
return TUrlTraits::IsAboutSrcdoc(url);
}
};
TYPED_TEST_SUITE_P(AbstractUrlTest);
TYPED_TEST_P(AbstractUrlTest, IsAboutBlankTest) {
// See https://tools.ietf.org/html/rfc6694 which explicitly allows
// `about-query` and `about-fragment` parts in about: URLs.
const std::string kAboutBlankUrls[] = {"about:blank", "about:blank?foo",
"about:blank/#foo",
"about:blank?foo#foo"};
for (const auto& input : kAboutBlankUrls) {
SCOPED_TRACE(testing::Message() << "Test input: " << input);
auto url = this->CreateUrlFromString(input);
EXPECT_TRUE(this->IsAboutBlank(url));
}
const std::string kNotAboutBlankUrls[] = {"",
"about",
"about:",
"about:blanky",
"about:blan",
"about:about:blank:",
"data:blank",
"http:blank",
"about://blank",
"about:blank/foo",
"about://:8000/blank",
"about://foo:foo@/blank",
"foo@about:blank",
"foo:bar@about:blank",
"about:blank:8000",
"about:blANk"};
for (const auto& input : kNotAboutBlankUrls) {
SCOPED_TRACE(testing::Message() << "Test input: " << input);
auto url = this->CreateUrlFromString(input);
EXPECT_FALSE(this->IsAboutBlank(url));
}
}
TYPED_TEST_P(AbstractUrlTest, IsAboutSrcdocTest) {
// See https://tools.ietf.org/html/rfc6694 which explicitly allows
// `about-query` and `about-fragment` parts in about: URLs.
//
// `about:srcdoc` is defined in
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#about:srcdoc
// which refers to rfc6694 for details.
const std::string kAboutSrcdocUrls[] = {
"about:srcdoc", "about:srcdoc/", "about:srcdoc?foo", "about:srcdoc/#foo",
"about:srcdoc?foo#foo"};
for (const auto& input : kAboutSrcdocUrls) {
SCOPED_TRACE(testing::Message() << "Test input: " << input);
auto url = this->CreateUrlFromString(input);
EXPECT_TRUE(this->IsAboutSrcdoc(url));
}
const std::string kNotAboutSrcdocUrls[] = {"",
"about",
"about:",
"about:srcdocx",
"about:srcdo",
"about:about:srcdoc:",
"data:srcdoc",
"http:srcdoc",
"about:srcdo",
"about://srcdoc",
"about://srcdoc\\",
"about:srcdoc/foo",
"about://:8000/srcdoc",
"about://foo:foo@/srcdoc",
"foo@about:srcdoc",
"foo:bar@about:srcdoc",
"about:srcdoc:8000",
"about:srCDOc"};
for (const auto& input : kNotAboutSrcdocUrls) {
SCOPED_TRACE(testing::Message() << "Test input: " << input);
auto url = this->CreateUrlFromString(input);
EXPECT_FALSE(this->IsAboutSrcdoc(url));
}
}
REGISTER_TYPED_TEST_SUITE_P(AbstractUrlTest,
IsAboutBlankTest,
IsAboutSrcdocTest);
#endif // URL_GURL_ABSTRACT_TESTS_H_
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chromium_develop/chromium_url.git
git@gitee.com:chromium_develop/chromium_url.git
chromium_develop
chromium_url
chromium_url
master

搜索帮助