chromium/url/url_canon_unittest.cc

// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/350788890): Remove this and spanify to fix the errors.
#pragma allow_unsafe_buffers
#endif

#include "url/url_canon.h"

#include <errno.h>
#include <stddef.h>
#include <string_view>

#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/gtest_util.h"
#include "base/test/scoped_feature_list.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/third_party/mozilla/url_parse.h"
#include "url/url_canon_internal.h"
#include "url/url_canon_stdstring.h"
#include "url/url_features.h"
#include "url/url_test_utils.h"

namespace url {

namespace {

struct ComponentCase {};

// ComponentCase but with dual 8-bit/16-bit input. Generally, the unit tests
// treat each input as optional, and will only try processing if non-NULL.
// The output is always 8-bit.
struct DualComponentCase {};

// Test cases for CanonicalizeIPAddress(). The inputs are identical to
// DualComponentCase, but the output has extra CanonHostInfo fields.
struct IPAddressCase {};

struct ReplaceCase {};

// Magic string used in the replacements code that tells SetupReplComp to
// call the clear function.
const char kDeleteComp[] =;

// Sets up a replacement for a single component. This is given pointers to
// the set and clear function for the component being replaced, and will
// either set the component (if it exists) or clear it (if the replacement
// string matches kDeleteComp).
//
// This template is currently used only for the 8-bit case, and the strlen
// causes it to fail in other cases. It is left a template in case we have
// tests for wide replacements.
template<typename CHAR>
void SetupReplComp(
    void (Replacements<CHAR>::*set)(const CHAR*, const Component&),
    void (Replacements<CHAR>::*clear)(),
    Replacements<CHAR>* rep,
    const CHAR* str) {}

bool CanonicalizeSpecialPath(const char* spec,
                             const Component& path,
                             CanonOutput* output,
                             Component* out_path) {}

bool CanonicalizeSpecialPath(const char16_t* spec,
                             const Component& path,
                             CanonOutput* output,
                             Component* out_path) {}

bool CanonicalizeNonSpecialPath(const char* spec,
                                const Component& path,
                                CanonOutput* output,
                                Component* out_path) {}

bool CanonicalizeNonSpecialPath(const char16_t* spec,
                                const Component& path,
                                CanonOutput* output,
                                Component* out_path) {}

}  // namespace

TEST(URLCanonTest, DoAppendUTF8) {}

TEST(URLCanonTest, DoAppendUTF8Invalid) {}

TEST(URLCanonTest, UTF) {}

TEST(URLCanonTest, Scheme) {}

// IDNA mode to use in CanonHost tests.
enum class IDNAMode {};

class URLCanonHostTest
    : public ::testing::Test,
      public ::testing::WithParamInterface<IDNAMode> {};

INSTANTIATE_TEST_SUITE_P();

TEST_P(URLCanonHostTest, Host) {}

TEST(URLCanonTest, SpecialHostPuncutationChar) {}

TEST(URLCanonTest, ForbiddenHostCodePoint) {}

TEST(URLCanonTest, IPv4) {}

TEST(URLCanonTest, IPv6) {}

TEST(URLCanonTest, IPEmpty) {}

// Verifies that CanonicalizeHostSubstring produces the expected output and
// does not "fix" IP addresses. Because this code is a subset of
// CanonicalizeHost, the shared functionality is not tested.
TEST(URLCanonTest, CanonicalizeHostSubstring) {}

TEST(URLCanonTest, UserInfo) {}

TEST(URLCanonTest, Port) {}

DualComponentCase kCommonPathCases[] =;

CanonFunc8Bit;
CanonFunc16Bit;

void DoPathTest(const DualComponentCase* path_cases,
                size_t num_cases,
                CanonFunc8Bit canon_func_8,
                CanonFunc16Bit canon_func_16) {}

TEST(URLCanonTest, SpecialPath) {}

TEST(URLCanonTest, NonSpecialPath) {}

TEST(URLCanonTest, PartialPath) {}

TEST(URLCanonTest, Query) {}

TEST(URLCanonTest, Ref) {}

TEST(URLCanonTest, CanonicalizeStandardURL) {}

TEST(URLCanonTest, CanonicalizeNonSpecialURL) {}

TEST(URLCanonTest, CanonicalizeNonSpecialURLOutputParsed) {}

// The codepath here is the same as for regular canonicalization, so we just
// need to test that things are replaced or not correctly.
TEST(URLCanonTest, ReplaceStandardURL) {}

TEST(URLCanonTest, ReplaceFileURL) {}

TEST(URLCanonTest, ReplaceFileSystemURL) {}

TEST(URLCanonTest, ReplacePathURL) {}

TEST(URLCanonTest, ReplaceMailtoURL) {}

TEST(URLCanonTest, CanonicalizeFileURL) {}

TEST(URLCanonTest, CanonicalizeFileSystemURL) {}

TEST(URLCanonTest, CanonicalizePathURL) {}

TEST(URLCanonTest, CanonicalizePathURLPath) {}

TEST(URLCanonTest, CanonicalizeMailtoURL) {}

#ifndef WIN32

TEST(URLCanonTest, _itoa_s) {}

TEST(URLCanonTest, _itow_s) {}

#endif  // !WIN32

// Returns true if the given two structures are the same.
static bool ParsedIsEqual(const Parsed& a, const Parsed& b) {}

TEST(URLCanonTest, ResolveRelativeURL) {}

class URLCanonTypedTest : public ::testing::TestWithParam<bool> {};

TEST_P(URLCanonTypedTest, NonSpecialResolveRelativeURL) {}

INSTANTIATE_TEST_SUITE_P();

// It used to be the case that when we did a replacement with a long buffer of
// UTF-16 characters, we would get invalid data in the URL. This is because the
// buffer that it used to hold the UTF-8 data was resized, while some pointers
// were still kept to the old buffer that was removed.
TEST(URLCanonTest, ReplacementOverflow) {}

TEST(URLCanonTest, DefaultPortForScheme) {}

TEST(URLCanonTest, FindWindowsDriveLetter) {}

TEST(URLCanonTest, IDNToASCII) {}

void ComponentCaseMatches(bool success,
                          std::string_view out_str,
                          const Component& out_comp,
                          const DualComponentCase& expected) {}

TEST(URLCanonTest, OpaqueHost) {}

void IPAddressCaseMatches(std::string_view out_str,
                          const CanonHostInfo& host_info,
                          const IPAddressCase& expected) {}

TEST(URLCanonTest, NonSpecialHostIPv6Address) {}

}  // namespace url