diff options
| -rw-r--r-- | TODO.org | 16 | ||||
| -rw-r--r-- | spec/LuaRuntimeApiSpec.cpp | 125 | ||||
| -rw-r--r-- | spec/LuaRuntimeSpec.cpp | 8 | ||||
| -rw-r--r-- | spec/WebViewStackSpec.cpp | 8 | ||||
| -rw-r--r-- | spec/testUtils.h | 11 | ||||
| -rw-r--r-- | src/InstanceManager.cpp | 6 | ||||
| -rw-r--r-- | src/LuaRuntimeApi.hpp | 3 | ||||
| -rw-r--r-- | src/WindowActionRouter.cpp | 2 | ||||
| -rw-r--r-- | src/WindowActionRouter.hpp | 1 |
9 files changed, 150 insertions, 30 deletions
@@ -1,13 +1,17 @@ ** Usable +- [X] `web.inspect`: like vim.inspect +- [X] static linking for libluv +- [X] Update window title on current webview title change - [X] Search text in page - [X] Dev tools +- [ ] Configuration +- [ ] Scroll api (for j/k/h/l/gg/G) - [ ] Tests for api - [ ] Fullscreen - [ ] Zoom in/out -- [ ] Scroll api (j/k/h/l/gg/G) - [ ] Permission requests handling/persisting -- [ ] window.opener controls (use createWindow api directly?) - [ ] Notifications +- [ ] window.opener controls (use createWindow api directly?) ** Bugs - [ ] INVESTIGATE: segfault on api module error @@ -20,7 +24,7 @@ - [ ] Tests for window - [ ] More tests for stack - [ ] Tests for router -- [ ] Run JS in page +- [ ] Run JS in page (web.view.eval_js()) - [ ] Window list api - [ ] Log stdout, errors and results from lua somewhere - [ ] Use table for all internals api options? @@ -39,11 +43,11 @@ - [ ] User stylesheets (per site and global?) - [ ] Support multiple modes for keymap.set: `web.keymap.set({'n','i'}, ...)` - [ ] static linking for qt -- [X] `web.inspect`: like vim.inspect - [ ] vendor web.inspect with build -- [X] static linking for libluv -- [X] Update window title on current webview title change - [ ] Right click context menu items +- [ ] Listen to renderprocesstermination signal +- [ ] Create view with html (web.view.set_html()) +- [ ] Change instance manager command format ** Later later - [ ] Custom file picker diff --git a/spec/LuaRuntimeApiSpec.cpp b/spec/LuaRuntimeApiSpec.cpp index 936244f..c340a03 100644 --- a/spec/LuaRuntimeApiSpec.cpp +++ b/spec/LuaRuntimeApiSpec.cpp @@ -25,7 +25,9 @@ private slots: void cleanupTestCase() { LuaRuntime::instance().stop_event_loop(); } - void test_web_event_add_event() { + void test_web_event_add_listener() { + describe("web.event.add_listener"); + context("when events, patterns and callback are specified correctly"); it("returns true and registers event") { auto &lua = LuaRuntime::instance(); @@ -116,6 +118,8 @@ private slots: } void test_web_event_dispatching() { + describe("web.event.add_listener (event dispatch)"); + context("when dispatching a registered event (without pattern)"); it("calls the registered event handler") { auto &lua = LuaRuntime::instance(); @@ -146,6 +150,8 @@ private slots: } void lua_api_view_set_url() { + describe("web.search.set_url"); + context("when called with a url and view id"); it("emits url_opened for the given view id") { auto &lua = LuaRuntime::instance(); @@ -192,23 +198,114 @@ private slots: } } - void lua_api_view_current() { - context("when called without a window id"); - it("emits url_opened for the given view id") { + void lua_api_search_set_text() { + describe("web.search.set_text"); + + context("when called with just the search text"); + it("emits search_requested with search text and view id 0") { auto &lua = LuaRuntime::instance(); - QSignalSpy evaluation_completed_spy(&lua, &LuaRuntime::evaluation_completed); + QSignalSpy search_requested(&lua, &LuaRuntime::search_requested); - lua.evaluate(R"( - return web.view.current() - )"); - QVERIFY(evaluation_completed_spy.wait()); + lua.evaluate("web.search.set_text('search text')"); + + QVERIFY(search_requested.wait()); + QCOMPARE(search_requested.first()[0], "search text"); + QCOMPARE(search_requested.first()[1], 0); + } + + context("when called with search text and view id"); + it("emits search_requested with search text and given view id") { + auto &lua = LuaRuntime::instance(); + QSignalSpy search_requested(&lua, &LuaRuntime::search_requested); + + lua.evaluate("web.search.set_text('search text', 2)"); + + QVERIFY(search_requested.wait()); + QCOMPARE(search_requested.first()[0], "search text"); + QCOMPARE(search_requested.first()[1], 2); + } + } + + void lua_api_search_next() { + describe("web.search.next"); + + context("when called without view id"); + it("emits search_next_requested with view id 0") { + auto &lua = LuaRuntime::instance(); + QSignalSpy search_next_requested(&lua, &LuaRuntime::search_next_requested); + + lua.evaluate("web.search.next()"); + + QVERIFY(search_next_requested.wait()); + QCOMPARE(search_next_requested.first().first(), 0); + } + + context("when called with view id"); + it("emits search_next_requested with given view id") { + auto &lua = LuaRuntime::instance(); + QSignalSpy search_next_requested(&lua, &LuaRuntime::search_next_requested); + + lua.evaluate("web.search.next(2)"); + + QVERIFY(search_next_requested.wait()); + QCOMPARE(search_next_requested.first().first(), 2); + } + } + + void lua_api_search_previous() { + describe("web.search.previous"); + + context("when called without view id"); + it("emits search_previous_requested with view id 0") { + auto &lua = LuaRuntime::instance(); + QSignalSpy search_previous_requested(&lua, &LuaRuntime::search_previous_requested); + + lua.evaluate("web.search.previous()"); + + QVERIFY(search_previous_requested.wait()); + QCOMPARE(search_previous_requested.first().first(), 0); + } + + context("when called with view id"); + it("emits search_previous_requested with given view id") { + auto &lua = LuaRuntime::instance(); + QSignalSpy search_previous_requested(&lua, &LuaRuntime::search_previous_requested); + + lua.evaluate("web.search.previous(2)"); + + QVERIFY(search_previous_requested.wait()); + QCOMPARE(search_previous_requested.first().first(), 2); + } + } + + void lua_api_search_get_text() { + describe("web.search.get_text"); + + it("returns the current search text") { + auto &lua = LuaRuntime::instance(); + auto &router = WindowActionRouter::instance(); + router.set_current_search_text("some search text"); + QSignalSpy evaluation_completed(&lua, &LuaRuntime::evaluation_completed); + + lua.evaluate("return web.search.get_text()"); + + QVERIFY(evaluation_completed.wait()); + QCOMPARE(evaluation_completed.first().first(), "some search text"); + } + } + + void lua_api_view_open_devtools() { + describe("web.view.open_devtools"); + + context("when called with view id"); + it("emits devtools_requested with view id") { + auto &lua = LuaRuntime::instance(); + QSignalSpy devtools_requested(&lua, &LuaRuntime::devtools_requested); - qDebug() << evaluation_completed_spy.first().first(); + lua.evaluate("web.view.open_devtools(42)"); - // QCOMPARE(evaluation_completed_spy.first().first(), 1); - // QCOMPARE(url_opened.first()[0], "https://updated-url.com"); - // QCOMPARE(url_opened.first()[1], OpenType::OpenUrl); - // QCOMPARE(url_opened.first()[2], 42); + QVERIFY(devtools_requested.wait()); + QCOMPARE(devtools_requested.first().first(), 42); } } }; diff --git a/spec/LuaRuntimeSpec.cpp b/spec/LuaRuntimeSpec.cpp index 97864b2..aeaaab2 100644 --- a/spec/LuaRuntimeSpec.cpp +++ b/spec/LuaRuntimeSpec.cpp @@ -14,6 +14,8 @@ private slots: void cleanupTestCase() { LuaRuntime::instance().stop_event_loop(); } void test_evaluate() { + describe("#evaluate"); + context("when given an expression returning a number"); it("emits evaluation_completed with the result") { auto &lua = LuaRuntime::instance(); @@ -68,6 +70,8 @@ private slots: } void test_queue_task() { + describe("#queue_task"); + context("when task is queued"); it("evaluates task asynchronously") { auto &lua = LuaRuntime::instance(); @@ -81,6 +85,8 @@ private slots: } void test_sanity_check_uv_timer() { + describe("uv timer"); + context("when a 1 second timer is set"); it("calls callback after 1 second") { auto &lua = LuaRuntime::instance(); @@ -101,6 +107,8 @@ private slots: } void test_sanity_check_uv_spawn() { + describe("uv spawn"); + it("calls exit callback when process exists") { auto &lua = LuaRuntime::instance(); QSignalSpy evaluation_completed_spy(&lua, &LuaRuntime::evaluation_completed); diff --git a/spec/WebViewStackSpec.cpp b/spec/WebViewStackSpec.cpp index 155218e..a63eca6 100644 --- a/spec/WebViewStackSpec.cpp +++ b/spec/WebViewStackSpec.cpp @@ -23,6 +23,8 @@ private slots: void cleanupTestCase() { LuaRuntime::instance().stop_event_loop(); } void test_initial_state() { + describe("constructor"); + context("when initialized"); it("opens an empty stack maintaining current url") { Configuration configuration; @@ -34,6 +36,8 @@ private slots: } void test_open_url() { + describe("#open_url"); + context("when openUrl is called with an empty stack"); it("opens a new webview") { Configuration configuration; @@ -115,6 +119,8 @@ private slots: } void test_close() { + describe("#close"); + context("when close is called"); context("- with invalid id"); it("does nothing") { @@ -189,6 +195,8 @@ private slots: } void test_new_window_request_signal() { + describe("signal newWindowRequested"); + context("when webview emits a newWindowRequested signal"); context("- of type new view"); it("opens a new web view and focuses it") { diff --git a/spec/testUtils.h b/spec/testUtils.h index 37bc9f9..a20291c 100644 --- a/spec/testUtils.h +++ b/spec/testUtils.h @@ -7,22 +7,27 @@ #define NOT ! #define ANSI_BOLD "\x1b[1m" +#define COLOR_DESCRIBE ANSI_BOLD #define COLOR_CONTEXT "\x1b[32m" ANSI_BOLD #define COLOR_IT "\x1b[36m" ANSI_BOLD #define COLOR_SKIP "\x1b[33m" ANSI_BOLD #define ANSI_RESET "\x1b[0m" +#define describe(msg) \ + printf(COLOR_DESCRIBE "%s" ANSI_RESET "\n", msg); \ + fflush(stdout); + #define context(msg) \ - printf("⚪" COLOR_CONTEXT "%s" ANSI_RESET "\n", msg); \ + printf("│ " COLOR_CONTEXT "%s" ANSI_RESET "\n", msg); \ fflush(stdout); #define it(msg) \ - printf(" ⚪" ANSI_BOLD COLOR_IT "it " ANSI_RESET COLOR_IT "%s" ANSI_RESET "\n", msg); \ + printf("└─⚪" ANSI_BOLD COLOR_IT "it " ANSI_RESET COLOR_IT "%s" ANSI_RESET "\n", msg); \ fflush(stdout); \ if (1) #define xit(msg) \ - printf(" ⚪" COLOR_SKIP "SKIPPED it %s" ANSI_RESET "\n", msg); \ + printf("└─⚪" COLOR_SKIP "SKIPPED it %s" ANSI_RESET "\n", msg); \ fflush(stdout); \ if (0) diff --git a/src/InstanceManager.cpp b/src/InstanceManager.cpp index 4fb27f9..3f961ec 100644 --- a/src/InstanceManager.cpp +++ b/src/InstanceManager.cpp @@ -34,8 +34,7 @@ void InstanceManager::server_init() { server = new QLocalServer(this); is_server_mode = true; - connect(server, &QLocalServer::newConnection, this, - &InstanceManager::handle_new_connection); + connect(server, &QLocalServer::newConnection, this, &InstanceManager::handle_new_connection); QLocalServer::removeServer(socket_path); if (!server->listen(socket_path)) { @@ -58,8 +57,7 @@ void InstanceManager::handle_new_connection() { if (client == nullptr) return; - connect(client, &QLocalSocket::disconnected, client, - &QLocalSocket::deleteLater); + connect(client, &QLocalSocket::disconnected, client, &QLocalSocket::deleteLater); client->waitForReadyRead(); while (client->canReadLine()) { diff --git a/src/LuaRuntimeApi.hpp b/src/LuaRuntimeApi.hpp index 80e8bc2..4767134 100644 --- a/src/LuaRuntimeApi.hpp +++ b/src/LuaRuntimeApi.hpp @@ -4,7 +4,6 @@ #include "LuaRuntime.hpp" #include "WindowActionRouter.hpp" -#include "lua.h" int lua_api_view_set_url(lua_State *state) { const char *url = lua_tostring(state, 1); @@ -190,7 +189,7 @@ int lua_event_register(lua_State *state) { int lua_api_search_set_text(lua_State *state) { const char *text = lua_tostring(state, 1); - WebViewId view_id = lua_isnoneornil(state, 1) ? 0 : lua_tointeger(state, 1); + WebViewId view_id = lua_isnoneornil(state, 2) ? 0 : lua_tointeger(state, 2); auto &runtime = LuaRuntime::instance(); emit runtime.search_requested(text, view_id); return 1; diff --git a/src/WindowActionRouter.cpp b/src/WindowActionRouter.cpp index 424dda9..2eabc94 100644 --- a/src/WindowActionRouter.cpp +++ b/src/WindowActionRouter.cpp @@ -64,7 +64,7 @@ void WindowActionRouter::initialize(Configuration *config) { // Search connect(&runtime, &LuaRuntime::search_requested, this, [this](const QString &text, WebViewId webview_id) { - current_search_text = text.trimmed(); + set_current_search_text(text.trimmed()); find_current_search_text(webview_id, true); }); connect(&runtime, &LuaRuntime::search_next_requested, this, diff --git a/src/WindowActionRouter.hpp b/src/WindowActionRouter.hpp index b749642..c43ee04 100644 --- a/src/WindowActionRouter.hpp +++ b/src/WindowActionRouter.hpp @@ -40,6 +40,7 @@ public: KeyMode fetch_current_mode() const; DEFINE_GETTER(fetch_current_search_text, current_search_text) + DEFINE_SETTER(set_current_search_text, current_search_text) DELEGATE(&event_queue, dispatch_event, dispatch_event) DELEGATE(&event_queue, register_event, register_event) |
