-
-
Notifications
You must be signed in to change notification settings - Fork 617
Expand file tree
/
Copy pathUrlPluginTest.cs
More file actions
117 lines (112 loc) · 4.11 KB
/
Copy pathUrlPluginTest.cs
File metadata and controls
117 lines (112 loc) · 4.11 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using NUnit.Framework;
using Flow.Launcher.Plugin.Url;
using System.Reflection;
namespace Flow.Launcher.Test.Plugins
{
[TestFixture]
public class UrlPluginTest
{
private static Main plugin;
[OneTimeSetUp]
public void OneTimeSetup()
{
var settingsProperty = typeof(Main).GetProperty("Settings", BindingFlags.NonPublic | BindingFlags.Static);
settingsProperty?.SetValue(null, new Settings());
plugin = new Main();
}
[TestCase("http://www.google.com")]
[TestCase("https://www.google.com")]
[TestCase("http://google.com")]
[TestCase("www.google.com")]
[TestCase("google.com")]
[TestCase("http://localhost")]
[TestCase("https://localhost")]
[TestCase("http://localhost:80")]
[TestCase("https://localhost:80")]
[TestCase("localhost")]
[TestCase("localhost:8080")]
[TestCase("http://110.10.10.10")]
[TestCase("110.10.10.10")]
[TestCase("110.10.10.10:8080")]
[TestCase("192.168.1.1")]
[TestCase("192.168.1.1:3000")]
[TestCase("[2001:db8::1]")]
[TestCase("[2001:db8::1]:8080")]
[TestCase("http://[2001:db8::1]")]
[TestCase("https://[2001:db8::1]:8080")]
[TestCase("[::1]")]
[TestCase("[::1]:8080")]
[TestCase("2001:db8::1")]
[TestCase("fe80:1:2::3:4")]
[TestCase("::1")]
[TestCase("HTTP://EXAMPLE.COM")]
[TestCase("HTTPS://EXAMPLE.COM")]
[TestCase("EXAMPLE.COM")]
[TestCase("LOCALHOST")]
[TestCase("Http://Example.Com")]
[TestCase("hTTps://ExAmPlE.CoM")]
[TestCase("LocalHost")]
[TestCase("example.com/path")]
[TestCase("example.com/path/to/resource")]
[TestCase("http://example.com/path")]
[TestCase("https://example.com/path?query=1")]
[TestCase("192.168.1.1/path/to/resource")]
[TestCase("192.168.1.1/path/to/resource?query=1")]
[TestCase("localhost:8080/api/endpoint")]
[TestCase("http://localhost/path")]
[TestCase("[::1]/path")]
[TestCase("[2001:db8::1]/path?query=1")]
[TestCase("192.168.1.1?query=value")]
[TestCase("192.168.1.1#fragment")]
[TestCase("localhost:8080?test=123")]
[TestCase("example.com#fragment")]
// Non-host-validated :// schemes
[TestCase("chrome://settings")]
[TestCase("edge://about")]
[TestCase("brave://settings")]
[TestCase("opera://history")]
[TestCase("vivaldi://bookmarks")]
[TestCase("chrome-extension://abc123def456/")]
[TestCase("moz-extension://abc123def456/")]
[TestCase("file:///C:/path/to/file.txt")]
// Colon-only schemes
[TestCase("about:blank")]
[TestCase("about:config")]
[TestCase("data:text/plain,hello")]
[TestCase("data:,Hello%2C%20World%21")]
// Chromium schemes in colon form
[TestCase("chrome:settings")]
[TestCase("chrome-extension:settings")]
public void WhenValidUrlThenIsUrlReturnsTrue(string url)
{
Assert.That(plugin.IsURL(url), Is.True);
}
[TestCase("2001:db8::1/path")]
[TestCase("wwww")]
[TestCase("wwww.c")]
[TestCase("not a url")]
[TestCase("just text")]
[TestCase("http://")]
[TestCase("://example.com")]
[TestCase("0.0.0.0")] // reserved default route address / IPAddress.Any
[TestCase("256.1.1.1")] // Invalid IPv4
[TestCase("example")] // No TLD
[TestCase("example..com")]
[TestCase("example .com")]
[TestCase("..example.com")]
[TestCase(".com")]
[TestCase("http://.com")]
[TestCase("2001:db8:::1")]
// Colon scheme with whitespace
[TestCase("about: blank")]
// Empty colon schemes
[TestCase("about:")]
[TestCase("chrome:")]
// Empty non host validated ://
[TestCase("chrome://")]
public void WhenInvalidUrlThenIsUrlReturnsFalse(string url)
{
Assert.That(plugin.IsURL(url), Is.False);
}
}
}