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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
// Copyright 2015 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 "third_party/blink/renderer/platform/weborigin/known_ports.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace blink {
TEST(KnownPortsTest, IsDefaultPortForProtocol) {
struct TestCase {
const unsigned short port;
const char* protocol;
const bool is_known;
} inputs[] = {
// Known ones.
{80, "http", true},
{443, "https", true},
{80, "ws", true},
{443, "wss", true},
{21, "ftp", true},
{990, "ftps", true},
// Unknown ones.
{5, "foo", false},
{80, "http:", false},
{443, "http", false},
{21, "ftps", false},
{990, "ftp", false},
// With upper cases.
{80, "HTTP", false},
{443, "Https", false},
};
for (const TestCase& test : inputs) {
bool result = IsDefaultPortForProtocol(test.port, test.protocol);
EXPECT_EQ(test.is_known, result);
}
}
TEST(KnownPortsTest, DefaultPortForProtocol) {
struct TestCase {
const unsigned short port;
const char* protocol;
} inputs[] = {
// Known ones.
{80, "http"},
{443, "https"},
{80, "ws"},
{443, "wss"},
{21, "ftp"},
{990, "ftps"},
// Unknown ones.
{0, "foo"},
{0, "http:"},
{0, "HTTP"},
{0, "Https"},
};
for (const TestCase& test : inputs)
EXPECT_EQ(test.port, DefaultPortForProtocol(test.protocol));
}
TEST(KnownPortsTest, IsPortAllowedForScheme) {
struct TestCase {
const char* url;
const bool is_allowed;
} inputs[] = {
// Allowed ones.
{"http://example.com", true},
{"file://example.com", true},
{"file://example.com:87", true},
{"ftp://example.com:21", true},
{"http://example.com:80", true},
{"http://example.com:8889", true},
// Disallowed ones.
{"ftp://example.com:87", false},
{"ws://example.com:21", false},
};
for (const TestCase& test : inputs)
EXPECT_EQ(test.is_allowed, IsPortAllowedForScheme(KURL(test.url)));
}
} // namespace blink
|