aboutsummaryrefslogtreecommitdiff
path: root/lib/session_formats/test/json.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/session_formats/test/json.cpp')
-rw-r--r--lib/session_formats/test/json.cpp103
1 files changed, 103 insertions, 0 deletions
diff --git a/lib/session_formats/test/json.cpp b/lib/session_formats/test/json.cpp
new file mode 100644
index 0000000..4c6b683
--- /dev/null
+++ b/lib/session_formats/test/json.cpp
@@ -0,0 +1,103 @@
+#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
+#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);
+}