// 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 <stddef.h> #include "testing/gtest/include/gtest/gtest.h" #include "url/third_party/mozilla/url_parse.h" // Interesting IE file:isms... // // file:/foo/bar file:///foo/bar // The result here seems totally invalid!?!? This isn't UNC. // // file:/ // file:// or any other number of slashes // IE6 doesn't do anything at all if you click on this link. No error: // nothing. IE6's history system seems to always color this link, so I'm // guessing that it maps internally to the empty URL. // // C:\ file:///C:/ // / file:///C:/ // /foo file:///C:/foo // Interestingly, IE treats "/" as an alias for "c:\", which makes sense, // but is weird to think about on Windows. // // file:foo/ file:foo/ (invalid?!?!?) // file:/foo/ file:///foo/ (invalid?!?!?) // file://foo/ file://foo/ (UNC to server "foo") // file:///foo/ file:///foo/ (invalid) // file:////foo/ file://foo/ (UNC to server "foo") // Any more than four slashes is also treated as UNC. // // file:C:/ file://C:/ // file:/C:/ file://C:/ // The number of slashes after "file:" don't matter if the thing following // it looks like an absolute drive path. Also, slashes and backslashes are // equally valid here. namespace url { namespace { AssertionFailure; AssertionResult; AssertionSuccess; // Used for regular URL parse cases. struct URLParseCase { … }; // Simpler version of URLParseCase for testing path URLs. struct PathURLParseCase { … }; // Simpler version of URLParseCase for testing mailto URLs. struct MailtoURLParseCase { … }; // More complicated version of URLParseCase for testing filesystem URLs. struct FileSystemURLParseCase { … }; AssertionResult ComponentMatches(const char* input, const char* reference, const Component& component) { … } void ExpectInvalidComponent(const Component& component) { … } void URLParseCaseMatches(const URLParseCase& expected, const Parsed& parsed) { … } // Parsed ---------------------------------------------------------------------- TEST(URLParser, Length) { … } TEST(URLParser, CountCharactersBefore) { … } // Standard -------------------------------------------------------------------- // clang-format off // Input Scheme Usrname Passwd Host Port Path Query Ref // ------------------------------------ ------- -------- ---------- ------------ --- ---------- ------------ ----- static URLParseCase cases[] = …; // clang-format on TEST(URLParser, Standard) { … } // PathURL -------------------------------------------------------------------- // Various incarnations of path URLs. // clang-format off static PathURLParseCase path_cases[] = …; // clang-format on TEST(URLParser, PathURL) { … } // Various incarnations of file URLs. // clang-format off static URLParseCase file_cases[] = …; // clang-format on TEST(URLParser, ParseFileURL) { … } TEST(URLParser, ExtractFileName) { … } // Returns true if the parameter with index |parameter| in the given URL's // query string. The expected key can be NULL to indicate no such key index // should exist. The parameter number is 1-based. static bool NthParameterIs(const char* url, int parameter, const char* expected_key, const char* expected_value) { … } TEST(URLParser, ExtractQueryKeyValue) { … } // MailtoURL -------------------------------------------------------------------- // clang-format off static MailtoURLParseCase mailto_cases[] = …; // clang-format on TEST(URLParser, MailtoUrl) { … } // Various incarnations of filesystem URLs. static FileSystemURLParseCase filesystem_cases[] = …; TEST(URLParser, FileSystemURL) { … } // Non-special URLs which don't have an opaque path. static URLParseCase non_special_cases[] = …; TEST(URLParser, NonSpecial) { … } // Non-special URLs which have an opaque path. static URLParseCase non_special_opaque_path_cases[] = …; TEST(URLParser, NonSpecialOpaquePath) { … } } // namespace } // namespace url