1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
// Copyright (c) 2010 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 "chrome/browser/extensions/extension_install_ui.h"
#include "chrome/common/extensions/url_pattern.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
void CompareLists(const std::vector<std::string>& expected,
const std::vector<std::string>& actual) {
ASSERT_EQ(expected.size(), actual.size());
for (size_t i = 0; i < expected.size(); ++i) {
EXPECT_EQ(expected[i], actual[i]);
}
}
}
TEST(ExtensionInstallUITest, GetDistinctHostsForDisplay) {
std::vector<std::string> expected;
expected.push_back("www.foo.com");
expected.push_back("www.bar.com");
expected.push_back("www.baz.com");
// Simple list with no dupes.
std::vector<URLPattern> actual;
actual.push_back(
URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path"));
actual.push_back(
URLPattern(URLPattern::SCHEME_HTTP, "http://www.bar.com/path"));
actual.push_back(
URLPattern(URLPattern::SCHEME_HTTP, "http://www.baz.com/path"));
CompareLists(expected,
ExtensionInstallUI::GetDistinctHostsForDisplay(actual));
// Add some dupes.
actual.push_back(
URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path"));
actual.push_back(
URLPattern(URLPattern::SCHEME_HTTP, "http://www.baz.com/path"));
CompareLists(expected,
ExtensionInstallUI::GetDistinctHostsForDisplay(actual));
// Add a pattern that differs only by scheme. This should be filtered out.
actual.push_back(
URLPattern(URLPattern::SCHEME_HTTPS, "https://www.bar.com/path"));
CompareLists(expected,
ExtensionInstallUI::GetDistinctHostsForDisplay(actual));
// Add some dupes by path.
actual.push_back(
URLPattern(URLPattern::SCHEME_HTTP, "http://www.bar.com/pathypath"));
CompareLists(expected,
ExtensionInstallUI::GetDistinctHostsForDisplay(actual));
// We don't do anything special for subdomains.
actual.push_back(
URLPattern(URLPattern::SCHEME_HTTP, "http://monkey.www.bar.com/path"));
actual.push_back(
URLPattern(URLPattern::SCHEME_HTTP, "http://bar.com/path"));
expected.push_back("monkey.www.bar.com");
expected.push_back("bar.com");
CompareLists(expected,
ExtensionInstallUI::GetDistinctHostsForDisplay(actual));
}
|