diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-03-16 15:28:00 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-03-16 15:29:59 +0530 |
| commit | 041f8933be28d0fcff1196792f30c5ca3176c155 (patch) | |
| tree | 5fceaf5844f3312e8db63425c5c25825df594861 /spec | |
| parent | 350d2bd7ccf80b91abdff154344f0ce88080a195 (diff) | |
| download | null-browser-041f8933be28d0fcff1196792f30c5ca3176c155.tar.gz null-browser-041f8933be28d0fcff1196792f30c5ca3176c155.zip | |
Add configuration class
Diffstat (limited to '')
| -rw-r--r-- | spec/InputMediatorSpec.cpp | 47 | ||||
| -rw-r--r-- | spec/WebViewStackSpec.cpp | 77 |
2 files changed, 75 insertions, 49 deletions
diff --git a/spec/InputMediatorSpec.cpp b/spec/InputMediatorSpec.cpp index 464e156..abc2232 100644 --- a/spec/InputMediatorSpec.cpp +++ b/spec/InputMediatorSpec.cpp @@ -11,8 +11,9 @@ private slots: void testInputTypes() { context("when showCommandInput is called"); it("shows url input with default command") { - auto inputLine = InputLine(); - auto webViewStack = WebViewStack(); + InputLine inputLine; + Configuration configuration; + WebViewStack webViewStack(&configuration); auto luaRuntime = LuaRuntime::instance(); InputMediator inputMediator(&inputLine, &webViewStack, luaRuntime); QCOMPARE(inputLine.isHidden(), true); @@ -26,8 +27,9 @@ private slots: context("when showURLInput is called"); it("shows url input with default url") { - auto inputLine = InputLine(); - auto webViewStack = WebViewStack(); + InputLine inputLine; + Configuration configuration; + WebViewStack webViewStack(&configuration); auto luaRuntime = LuaRuntime::instance(); InputMediator inputMediator(&inputLine, &webViewStack, luaRuntime); QCOMPARE(inputLine.isHidden(), true); @@ -44,8 +46,9 @@ private slots: context("when command open is executed"); context("- without args"); it("opens url input") { - auto inputLine = InputLine(); - auto webViewStack = WebViewStack(); + InputLine inputLine; + Configuration configuration; + WebViewStack webViewStack(&configuration); auto luaRuntime = LuaRuntime::instance(); InputMediator inputMediator(&inputLine, &webViewStack, luaRuntime); @@ -58,8 +61,9 @@ private slots: context("when command open is executed"); context("- with url as an arg"); it("opens url in current tab") { - auto inputLine = InputLine(); - auto webViewStack = WebViewStack(); + InputLine inputLine; + Configuration configuration; + WebViewStack webViewStack(&configuration); auto luaRuntime = LuaRuntime::instance(); InputMediator inputMediator(&inputLine, &webViewStack, luaRuntime); @@ -76,8 +80,9 @@ private slots: context("when command tabopen is run"); context("- without args"); it("opens url in a new tab") { - auto inputLine = InputLine(); - auto webViewStack = WebViewStack(); + InputLine inputLine; + Configuration configuration; + WebViewStack webViewStack(&configuration); auto luaRuntime = LuaRuntime::instance(); InputMediator inputMediator(&inputLine, &webViewStack, luaRuntime); @@ -90,15 +95,16 @@ private slots: 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(); + InputLine inputLine; + Configuration configuration; + WebViewStack webViewStack(&configuration); 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), + std::vector<QUrl> urls = {QUrl(configuration.newTabUrl), QUrl("http://a.com")}; QCOMPARE(webViewStack.urls(), urls); QCOMPARE(webViewStack.currentWebViewIndex(), 1); @@ -108,8 +114,9 @@ private slots: void testCommandEvaluationTabNextPrev() { context("when command tabnext is executed"); it("jumps to next tab") { - auto inputLine = InputLine(); - auto webViewStack = WebViewStack(); + InputLine inputLine; + Configuration configuration; + WebViewStack webViewStack(&configuration); auto luaRuntime = LuaRuntime::instance(); InputMediator inputMediator(&inputLine, &webViewStack, luaRuntime); webViewStack.openUrl(QUrl("https://a1.com"), OpenType::OpenUrl); @@ -125,8 +132,9 @@ private slots: context("when command tabprev is executed"); it("jumps to previous tab") { - auto inputLine = InputLine(); - auto webViewStack = WebViewStack(); + InputLine inputLine; + Configuration configuration; + WebViewStack webViewStack(&configuration); auto luaRuntime = LuaRuntime::instance(); InputMediator inputMediator(&inputLine, &webViewStack, luaRuntime); webViewStack.openUrl(QUrl("https://a1.com"), OpenType::OpenUrl); @@ -144,8 +152,9 @@ private slots: void testHideInputLine() { context("when hideInputLine is called"); it("hides input") { - auto inputLine = InputLine(); - auto webViewStack = WebViewStack(); + InputLine inputLine; + Configuration configuration; + WebViewStack webViewStack(&configuration); auto luaRuntime = LuaRuntime::instance(); InputMediator inputMediator(&inputLine, &webViewStack, luaRuntime); inputMediator.showURLInput(); diff --git a/spec/WebViewStackSpec.cpp b/spec/WebViewStackSpec.cpp index 5824437..e8df0c1 100644 --- a/spec/WebViewStackSpec.cpp +++ b/spec/WebViewStackSpec.cpp @@ -2,6 +2,7 @@ #include <QWebEngineProfile> #include <vector> +#include "Configuration.hpp" #include "testUtils.h" #include "widgets/WebViewStack.hpp" @@ -19,10 +20,11 @@ private slots: void testInitialState() { context("when initialized"); it("opens a single tab") { - WebViewStack webViewStack; + Configuration configuration; + WebViewStack webViewStack(&configuration); QCOMPARE(webViewStack.count(), 1); - QCOMPARE(webViewStack.currentUrl(), WebViewStack::NewtabURL); + QCOMPARE(webViewStack.currentUrl(), configuration.newTabUrl); webViewStack.deleteLater(); } } @@ -30,42 +32,45 @@ private slots: void testOpenUrl() { context("when openUrl is called without an open type"); it("replaces current tab url with newtab url") { - WebViewStack webViewStack; + Configuration configuration; + WebViewStack webViewStack(&configuration); webViewStack.openUrl(QUrl("http://a.com"), OpenType::OpenUrl); - webViewStack.openUrl(); + webViewStack.openUrl(QUrl(configuration.newTabUrl)); QCOMPARE(webViewStack.count(), 1); - std::vector<QUrl> urls = {QUrl(WebViewStack::NewtabURL)}; + std::vector<QUrl> urls = {QUrl(configuration.newTabUrl)}; QCOMPARE(webViewStack.urls(), urls); QCOMPARE(webViewStack.currentWebViewIndex(), 0); - QCOMPARE(webViewStack.currentUrl(), WebViewStack::NewtabURL); + QCOMPARE(webViewStack.currentUrl(), configuration.newTabUrl); } context("when creating a new webview with a url and focus is false"); it("opens the given url in background") { - WebViewStack webViewStack; + Configuration configuration; + WebViewStack webViewStack(&configuration); webViewStack.openUrl(QUrl("https://duckduckgo.com"), OpenType::OpenUrlInBgTab); QCOMPARE(webViewStack.count(), 2); - std::vector<QUrl> urls = {QUrl(WebViewStack::NewtabURL), + std::vector<QUrl> urls = {QUrl(configuration.newTabUrl), QUrl("https://duckduckgo.com")}; QCOMPARE(webViewStack.urls(), urls); QCOMPARE(webViewStack.currentWebViewIndex(), 0); - QCOMPARE(webViewStack.currentUrl(), WebViewStack::NewtabURL); + QCOMPARE(webViewStack.currentUrl(), configuration.newTabUrl); } context("when creating a new webview with a url and focus is true"); it("opens the given url as current view") { - WebViewStack webViewStack; + Configuration configuration; + WebViewStack webViewStack(&configuration); webViewStack.openUrl(QUrl("https://duckduckgo.com"), OpenType::OpenUrlInTab); QCOMPARE(webViewStack.count(), 2); - std::vector<QUrl> urls = {QUrl(WebViewStack::NewtabURL), + std::vector<QUrl> urls = {QUrl(configuration.newTabUrl), QUrl("https://duckduckgo.com")}; QCOMPARE(webViewStack.urls(), urls); QCOMPARE(webViewStack.currentWebViewIndex(), 1); @@ -77,18 +82,20 @@ private slots: context("when nextWebView is called"); context("- and there is only 1 tab"); it("does nothing") { - WebViewStack webViewStack; + Configuration configuration; + WebViewStack webViewStack(&configuration); webViewStack.next(); QCOMPARE(webViewStack.currentWebViewIndex(), 0); - QCOMPARE(webViewStack.currentUrl(), WebViewStack::NewtabURL); + QCOMPARE(webViewStack.currentUrl(), configuration.newTabUrl); } context("when nextWebView is called"); context("- and there are tabs after the current tab"); it("goes to the next tab") { - WebViewStack webViewStack; + Configuration configuration; + WebViewStack webViewStack(&configuration); webViewStack.openUrl(QUrl("http://a1.com"), OpenType::OpenUrlInBgTab); webViewStack.openUrl(QUrl("http://a2.com"), OpenType::OpenUrlInBgTab); @@ -101,7 +108,8 @@ private slots: context("when nextWebView is called"); context("- and current tab is the last tab"); it("jumps to the first tab") { - WebViewStack webViewStack; + Configuration configuration; + WebViewStack webViewStack(&configuration); webViewStack.openUrl(QUrl("http://a1.com"), OpenType::OpenUrlInBgTab); webViewStack.openUrl(QUrl("http://a2.com"), OpenType::OpenUrlInTab); QCOMPARE(webViewStack.currentWebViewIndex(), 2); @@ -109,7 +117,7 @@ private slots: webViewStack.next(); QCOMPARE(webViewStack.currentWebViewIndex(), 0); - QCOMPARE(webViewStack.currentUrl(), WebViewStack::NewtabURL); + QCOMPARE(webViewStack.currentUrl(), configuration.newTabUrl); } } @@ -117,18 +125,20 @@ private slots: context("when previousWebView is called"); context("- and there is only 1 tab"); it("does nothing") { - WebViewStack webViewStack; + Configuration configuration; + WebViewStack webViewStack(&configuration); webViewStack.previous(); QCOMPARE(webViewStack.currentWebViewIndex(), 0); - QCOMPARE(webViewStack.currentUrl(), WebViewStack::NewtabURL); + QCOMPARE(webViewStack.currentUrl(), configuration.newTabUrl); } context("when previousWebView is called"); context("- and there are tabs before the current tab"); it("goes to the next tab") { - WebViewStack webViewStack; + Configuration configuration; + WebViewStack webViewStack(&configuration); webViewStack.openUrl(QUrl("http://a1.com"), OpenType::OpenUrlInBgTab); webViewStack.openUrl(QUrl("http://a2.com"), OpenType::OpenUrlInTab); QCOMPARE(webViewStack.currentWebViewIndex(), 2); @@ -142,7 +152,8 @@ private slots: context("when previousWebView is called"); context("- and current tab is the last tab"); it("jumps to the last tab") { - WebViewStack webViewStack; + Configuration configuration; + WebViewStack webViewStack(&configuration); webViewStack.openUrl(QUrl("http://a1.com"), OpenType::OpenUrlInBgTab); webViewStack.openUrl(QUrl("http://a2.com"), OpenType::OpenUrlInBgTab); @@ -157,7 +168,8 @@ private slots: context("when closeWebView is called"); context("- with out of bounds index"); it("does nothing") { - WebViewStack webViewStack; + Configuration configuration; + WebViewStack webViewStack(&configuration); webViewStack.openUrl(QUrl("https://a.com"), OpenType::OpenUrl); webViewStack.close(1); @@ -171,7 +183,8 @@ private slots: context("when closeWebView is called"); context("- and there is only 1 tab"); it("closes the tab and opens empty tab in its place") { - WebViewStack webViewStack; + Configuration configuration; + WebViewStack webViewStack(&configuration); webViewStack.openUrl(QUrl("https://a.com"), OpenType::OpenUrl); QCOMPARE(webViewStack.count(), 1); @@ -179,16 +192,17 @@ private slots: QCOMPARE(webViewStack.count(), 1); QCOMPARE(webViewStack.urls(), - (std::vector<QUrl>{WebViewStack::NewtabURL})); + (std::vector<QUrl>{configuration.newTabUrl})); QCOMPARE(webViewStack.currentWebViewIndex(), 0); - QCOMPARE(webViewStack.currentUrl(), WebViewStack::NewtabURL); + QCOMPARE(webViewStack.currentUrl(), configuration.newTabUrl); } context("when closeWebView is called"); context("- with the current tab index"); context("- and there are some tabs after"); it("closes the tab and focuses the next tab") { - WebViewStack webViewStack; + Configuration configuration; + WebViewStack webViewStack(&configuration); webViewStack.openUrl(QUrl("https://a1.com"), OpenType::OpenUrlInTab); webViewStack.openUrl(QUrl("https://a2.com"), OpenType::OpenUrlInBgTab); QCOMPARE(webViewStack.count(), 3); @@ -199,7 +213,7 @@ private slots: QCOMPARE(webViewStack.count(), 2); QCOMPARE( webViewStack.urls(), - (std::vector<QUrl>{WebViewStack::NewtabURL, QUrl("https://a2.com")})); + (std::vector<QUrl>{configuration.newTabUrl, QUrl("https://a2.com")})); QCOMPARE(webViewStack.currentWebViewIndex(), 1); QCOMPARE(webViewStack.currentUrl(), QUrl("https://a2.com")); } @@ -208,7 +222,8 @@ private slots: context("- with the current tab index"); context("- which is the last tab"); it("closes the tab and focusses previous tab") { - WebViewStack webViewStack; + Configuration configuration; + WebViewStack webViewStack(&configuration); webViewStack.openUrl(QUrl("https://a1.com"), OpenType::OpenUrlInBgTab); webViewStack.openUrl(QUrl("https://a2.com"), OpenType::OpenUrlInTab); QCOMPARE(webViewStack.count(), 3); @@ -219,7 +234,7 @@ private slots: QCOMPARE(webViewStack.count(), 2); QCOMPARE( webViewStack.urls(), - (std::vector<QUrl>{WebViewStack::NewtabURL, QUrl("https://a1.com")})); + (std::vector<QUrl>{configuration.newTabUrl, QUrl("https://a1.com")})); QCOMPARE(webViewStack.currentWebViewIndex(), 1); QCOMPARE(webViewStack.currentUrl(), QUrl("https://a1.com")); } @@ -229,7 +244,8 @@ private slots: context("when webview emits a newWindowRequested signal"); context("- of type new tab"); it("opens a new web view and focusses it") { - WebViewStack webViewStack; + Configuration configuration; + WebViewStack webViewStack(&configuration); webViewStack.openUrl(QUrl("https://a.com"), OpenType::OpenUrl); auto webview = webViewStack.findChild<QWebEngineView *>(); QCOMPARE(webViewStack.count(), 1); @@ -250,7 +266,8 @@ private slots: context("when webview emits a newWindowRequested signal"); context("- of type new background tab"); it("opens a new web view in the background") { - WebViewStack webViewStack; + Configuration configuration; + WebViewStack webViewStack(&configuration); webViewStack.openUrl(QUrl("https://a.com"), OpenType::OpenUrl); auto webview = webViewStack.findChild<QWebEngineView *>(); |
