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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
#include "InputMediator.hpp"
#include "LuaRuntime.hpp"
#include "testUtils.h"
#include "widgets/InputLine.hpp"
#include "widgets/WebViewStack.hpp"
class InputMediatorSpec : public QObject {
Q_OBJECT
private slots:
void testInputTypes() {
context("when showCommandInput is called");
it("shows url input with default command") {
auto inputLine = InputLine();
auto webViewStack = WebViewStack();
auto luaRuntime = LuaRuntime::instance();
InputMediator inputMediator(&inputLine, &webViewStack, luaRuntime);
QCOMPARE(inputLine.isHidden(), true);
inputMediator.showCommandInput("open");
QCOMPARE(inputLine.isHidden(), false);
QCOMPARE(inputLine.prompt(), "[exec]");
QCOMPARE(inputLine.getInputText(), "open");
}
context("when showURLInput is called");
it("shows url input with default url") {
auto inputLine = InputLine();
auto webViewStack = WebViewStack();
auto luaRuntime = LuaRuntime::instance();
InputMediator inputMediator(&inputLine, &webViewStack, luaRuntime);
QCOMPARE(inputLine.isHidden(), true);
inputMediator.showURLInput("http://a.com");
QCOMPARE(inputLine.isHidden(), false);
QCOMPARE(inputLine.prompt(), "[url]");
QCOMPARE(inputLine.getInputText(), "http://a.com");
}
}
void testCommandEvaluationOpen() {
context("when command open is executed");
context("- without args");
it("opens url input") {
auto inputLine = InputLine();
auto webViewStack = WebViewStack();
auto luaRuntime = LuaRuntime::instance();
InputMediator inputMediator(&inputLine, &webViewStack, luaRuntime);
inputMediator.showCommandInput();
emit inputLine.submitted("open");
QCOMPARE(inputLine.prompt(), "[url]");
}
context("when command open is executed");
context("- with url as an arg");
it("opens url in current tab") {
auto inputLine = InputLine();
auto webViewStack = WebViewStack();
auto luaRuntime = LuaRuntime::instance();
InputMediator inputMediator(&inputLine, &webViewStack, luaRuntime);
inputMediator.showCommandInput();
emit inputLine.submitted("open http://a.com");
std::vector<QUrl> urls = {QUrl("http://a.com")};
QCOMPARE(webViewStack.urls(), urls);
QCOMPARE(webViewStack.currentWebViewIndex(), 0);
}
}
void testCommandEvaluationTabOpen() {
context("when command tabopen is run");
context("- without args");
it("opens url in a new tab") {
auto inputLine = InputLine();
auto webViewStack = WebViewStack();
auto luaRuntime = LuaRuntime::instance();
InputMediator inputMediator(&inputLine, &webViewStack, luaRuntime);
inputMediator.showCommandInput();
emit inputLine.submitted("tabopen");
QCOMPARE(inputLine.prompt(), "[url]");
}
context("when command tabopen is executed");
context("- with url as an arg");
it("opens url in a new tab") {
auto inputLine = InputLine();
auto webViewStack = WebViewStack();
auto luaRuntime = LuaRuntime::instance();
InputMediator inputMediator(&inputLine, &webViewStack, luaRuntime);
inputMediator.showCommandInput();
emit inputLine.submitted("tabopen http://a.com");
std::vector<QUrl> urls = {QUrl(WebViewStack::NewtabURL),
QUrl("http://a.com")};
QCOMPARE(webViewStack.urls(), urls);
QCOMPARE(webViewStack.currentWebViewIndex(), 1);
}
}
void testCommandEvaluationTabNextPrev() {
context("when command tabnext is executed");
it("jumps to next tab") {
auto inputLine = InputLine();
auto webViewStack = WebViewStack();
auto luaRuntime = LuaRuntime::instance();
InputMediator inputMediator(&inputLine, &webViewStack, luaRuntime);
webViewStack.openUrl(QUrl("https://a1.com"), OpenType::OpenUrl);
webViewStack.openUrl(QUrl("https://a2.com"), OpenType::OpenUrlInTab);
webViewStack.openUrl(QUrl("https://a2.com"), OpenType::OpenUrlInBgTab);
QCOMPARE(webViewStack.currentWebViewIndex(), 1);
inputMediator.showCommandInput();
emit inputLine.submitted("tabnext");
QCOMPARE(webViewStack.currentWebViewIndex(), 2);
}
context("when command tabprev is executed");
it("jumps to previous tab") {
auto inputLine = InputLine();
auto webViewStack = WebViewStack();
auto luaRuntime = LuaRuntime::instance();
InputMediator inputMediator(&inputLine, &webViewStack, luaRuntime);
webViewStack.openUrl(QUrl("https://a1.com"), OpenType::OpenUrl);
webViewStack.openUrl(QUrl("https://a2.com"), OpenType::OpenUrlInTab);
webViewStack.openUrl(QUrl("https://a2.com"), OpenType::OpenUrlInBgTab);
QCOMPARE(webViewStack.currentWebViewIndex(), 1);
inputMediator.showCommandInput();
emit inputLine.submitted("tabprev");
QCOMPARE(webViewStack.currentWebViewIndex(), 0);
}
}
void testHideInputLine() {
context("when hideInputLine is called");
it("hides input") {
auto inputLine = InputLine();
auto webViewStack = WebViewStack();
auto luaRuntime = LuaRuntime::instance();
InputMediator inputMediator(&inputLine, &webViewStack, luaRuntime);
inputMediator.showURLInput();
QCOMPARE(inputLine.isHidden(), false);
inputMediator.hideInputLine();
QCOMPARE(inputLine.isHidden(), true);
}
}
};
QTEST_REGISTER(InputMediatorSpec)
#include "InputMediatorSpec.moc"
|