blob: e8cccb32ccc62dc943b07678ac5b8a97e2a20c21 (
plain)
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
|
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
// clazy:excludeall=non-pod-global-static
#include <catch2/catch.hpp>
#include <session_json.hpp>
TEST_CASE("JsonSession default constructor")
{
JsonSession session;
REQUIRE(session.serialize() == "{}");
const auto tree = session.get();
REQUIRE(tree.count() == 0);
}
TEST_CASE("JsonSession command line constructor, single URL")
{
const QString profile = "";
const QString url = "https://some.url";
JsonSession session(profile, QStringList(url));
const auto tree = session.get();
REQUIRE(tree.count() == 1);
const auto window = tree.at(0);
REQUIRE(window.subwindows.count() == 1);
const auto subwindow = window.subwindows.at(0);
REQUIRE(subwindow.profile == profile);
REQUIRE(subwindow.tabs.count() == 1);
const auto tab = subwindow.tabs.at(0);
REQUIRE(tab.profile == profile);
REQUIRE(tab.url == url);
REQUIRE(tab.history.isEmpty());
}
TEST_CASE("JsonSession command line constructor, multiple URLs")
{
const QString profile = "default";
const QStringList urls{ "https://some.url", "http://other.url", "a random string" };
JsonSession session(profile, urls);
const auto tree = session.get();
REQUIRE(tree.count() == 1);
const auto window = tree.at(0);
REQUIRE(window.subwindows.count() == 1);
const auto subwindow = window.subwindows.at(0);
REQUIRE(subwindow.profile == profile);
REQUIRE(subwindow.tabs.count() == 3);
for(int i = 0; i < urls.size(); ++i) {
const auto tab = subwindow.tabs.at(i);
REQUIRE(tab.profile == profile);
REQUIRE(tab.url == urls.at(i));
REQUIRE(tab.history.isEmpty());
}
}
TEST_CASE("JsonSession QByteArray constuctor")
{
const QString profile = "";
const QString url = "about:blank";
JsonSession donor(profile, { url });
JsonSession session(donor.serialize());
const auto tree = session.get();
REQUIRE(tree.count() == 1);
const auto window = tree.at(0);
REQUIRE(window.subwindows.count() == 1);
const auto subwindow = window.subwindows.at(0);
REQUIRE(subwindow.profile == profile);
REQUIRE(subwindow.tabs.count() == 1);
const auto tab = subwindow.tabs.at(0);
REQUIRE(tab.profile == profile);
REQUIRE(tab.url == url);
REQUIRE(tab.history.isEmpty());
}
TEST_CASE("JsonSession MainWindowVector constructor")
{
const Session::WebView cview{ "profile", "url", "history" };
const Session::SubWindow csubwindow{ "profile", { cview } };
const Session::MainWindow cwindow{ { csubwindow } };
const JsonSession session{ { cwindow } };
const auto tree = session.get();
REQUIRE(tree.count() == 1);
const auto window = tree.at(0);
REQUIRE(window.subwindows.count() == 1);
const auto subwindow = window.subwindows.at(0);
REQUIRE(subwindow.profile == csubwindow.profile);
REQUIRE(subwindow.tabs.count() == 1);
const auto tab = subwindow.tabs.at(0);
REQUIRE(tab.profile == cview.profile);
REQUIRE(tab.url == cview.url);
REQUIRE(tab.history == cview.history);
}
|