| Index: components/password_manager/core/browser/affiliation_utils_unittest.cc
|
| diff --git a/components/password_manager/core/browser/affiliation_utils_unittest.cc b/components/password_manager/core/browser/affiliation_utils_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3a4bfafdb2746ab35afd041498e8b015942c70f0
|
| --- /dev/null
|
| +++ b/components/password_manager/core/browser/affiliation_utils_unittest.cc
|
| @@ -0,0 +1,129 @@
|
| +// Copyright 2014 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.
|
| +
|
| +#include "components/password_manager/core/browser/affiliation_utils.h"
|
| +
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace password_manager {
|
| +
|
| +namespace {
|
| +const char kTestFacetURI1[] = "https://alpha.example.com/";
|
| +const char kTestFacetURI2[] = "https://beta.example.com/";
|
| +const char kTestFacetURI3[] = "https://gamma.example.com/";
|
| +} // namespace
|
| +
|
| +TEST(AffiliationUtilsTest, ValidWebFacetURIs) {
|
| + const char* kValidWebFacetURIs[]{"https://www.example.com/",
|
| + "https://www.example.com:/",
|
| + "https://www.example.com:8080/",
|
| + "https://new-gtld/"};
|
| + for (const char* uri : kValidWebFacetURIs) {
|
| + SCOPED_TRACE(testing::Message("URL was ") << uri);
|
| + EXPECT_TRUE(IsValidWebFacetURI(uri));
|
| + }
|
| +}
|
| +
|
| +TEST(AffiliationUtilsTest, InvalidWebFacetURIs) {
|
| + const char* kValidWebFacetURIs[]{
|
| + // Invalid URL (actually, will be treated as having only a host part).
|
| + "Does not look like a valid URL.",
|
| + // Path is not explicitly the root path ('/').
|
| + "https://www.example.com/path",
|
| + "https://www.example.com",
|
| + // Empty scheme or not HTTPS scheme.
|
| + "://www.example.com",
|
| + "http://www.example.com/",
|
| + // Forbidden components (empty or non-existing).
|
| + "https://@www.example.com/",
|
| + "https://user@www.example.com/",
|
| + "https://:@www.example.com/",
|
| + "https://:password@www.example.com/",
|
| + "https://www.example.com/?",
|
| + "https://www.example.com/?query",
|
| + "https://www.example.com/#",
|
| + "https://www.example.com/#ref",
|
| + };
|
| + for (const char* uri : kValidWebFacetURIs) {
|
| + SCOPED_TRACE(testing::Message("URL was ") << uri);
|
| + EXPECT_FALSE(IsValidWebFacetURI(uri));
|
| + }
|
| +}
|
| +
|
| +TEST(AffiliationUtilsTest, ValidAndroidFacetURIs) {
|
| + const char kValidAndroidFacetURI[] =
|
| + "android://"
|
| + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_=="
|
| + "@com.example.android/";
|
| + EXPECT_TRUE(IsValidAndroidFacetURI(kValidAndroidFacetURI));
|
| +}
|
| +
|
| +TEST(AffiliationUtilsTest, InvalidAndroidFacetURIs) {
|
| + const char* kValidWebFacetURIs[]{
|
| + // Invalid URL (actually, will be treated as having only a host part).
|
| + "Does not look like a valid URL.",
|
| + // Path is not explicitly the root path ('/').
|
| + "android://hash==@com.example.android",
|
| + "android://hash==@com.example.android/path",
|
| + // Empty scheme or not "android" scheme.
|
| + "://hash==@com.example.android/",
|
| + "http://hash==@com.example.android/",
|
| + // Empty or non-existent hash part.
|
| + "android://@com.example.android/",
|
| + "android://com.example.android/",
|
| + // Forbidden components (empty or non-existing).
|
| + "android://hash==:@com.example.android/",
|
| + "android://hash==:password@com.example.android/",
|
| + "android://hash==@com.example.android/?",
|
| + "android://hash==@com.example.android/?query",
|
| + "android://hash==@com.example.android/#",
|
| + "android://hash==@com.example.android/#ref",
|
| + };
|
| +
|
| + for (const char* uri : kValidWebFacetURIs) {
|
| + SCOPED_TRACE(testing::Message("URL was ") << uri);
|
| + EXPECT_FALSE(IsValidAndroidFacetURI(uri));
|
| + }
|
| +}
|
| +
|
| +TEST(AffiliationUtilsTest, EqualEquivalenceClasses) {
|
| + AffiliatedFacets a;
|
| + a.push_back(kTestFacetURI1);
|
| + a.push_back(kTestFacetURI2);
|
| + a.push_back(kTestFacetURI3);
|
| +
|
| + AffiliatedFacets b;
|
| + b.push_back(kTestFacetURI3);
|
| + b.push_back(kTestFacetURI1);
|
| + b.push_back(kTestFacetURI2);
|
| +
|
| + EXPECT_TRUE(AreEquivalenceClassesEqual(a, a));
|
| + EXPECT_TRUE(AreEquivalenceClassesEqual(b, b));
|
| + EXPECT_TRUE(AreEquivalenceClassesEqual(b, a));
|
| + EXPECT_TRUE(AreEquivalenceClassesEqual(a, b));
|
| +}
|
| +
|
| +TEST(AffiliationUtilsTest, NotEqualEquivalenceClasses) {
|
| + AffiliatedFacets a;
|
| + a.push_back(kTestFacetURI1);
|
| + a.push_back(kTestFacetURI2);
|
| +
|
| + AffiliatedFacets b;
|
| + b.push_back(kTestFacetURI2);
|
| + b.push_back(kTestFacetURI3);
|
| +
|
| + AffiliatedFacets c;
|
| + b.push_back(kTestFacetURI1);
|
| + b.push_back(kTestFacetURI2);
|
| + b.push_back(kTestFacetURI3);
|
| +
|
| + EXPECT_FALSE(AreEquivalenceClassesEqual(a, b));
|
| + EXPECT_FALSE(AreEquivalenceClassesEqual(a, c));
|
| + EXPECT_FALSE(AreEquivalenceClassesEqual(b, a));
|
| + EXPECT_FALSE(AreEquivalenceClassesEqual(b, c));
|
| + EXPECT_FALSE(AreEquivalenceClassesEqual(c, a));
|
| + EXPECT_FALSE(AreEquivalenceClassesEqual(c, b));
|
| +}
|
| +
|
| +} // namespace password_manager
|
|
|