From e87693c54ca97ed3a6ed25f9eaae8ab223fc18b1 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Wed, 29 Apr 2020 18:49:07 +0300 Subject: libwebengine Make src/webengine into a static library - Add some tests - Updated manpage - Remove WebProfileManager::id and WebProfileManager::instance - Add consumable semantics checks to WebProfileManager - Add WebProfileManager::walk Add ApplicationMenu class --- src/webengine/test/view.cpp | 92 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/webengine/test/view.cpp (limited to 'src/webengine/test/view.cpp') diff --git a/src/webengine/test/view.cpp b/src/webengine/test/view.cpp new file mode 100644 index 0000000..8aa639a --- /dev/null +++ b/src/webengine/test/view.cpp @@ -0,0 +1,92 @@ +#define CATCH_CONFIG_RUNNER + +// clazy:excludeall=non-pod-global-static + +#include "webprofile.h" +#include "webview.h" +#include +#include +#include +#include +#include + +SCENARIO("WebView") +{ + const QString profile_id{ "default" }; + auto *settings = WebProfile::load(qgetenv("PROFILE"), "about:blank", QUrl{ "about:blank" }, QUrl{ "about:blank" }); + auto *profile = WebProfile::load(profile_id, settings, true); + + QMainWindow window; + auto *view = new WebView(profile, nullptr); + window.setCentralWidget(view); + window.show(); + window.resize(800, 600); + + WHEN("created") + { + THEN("using the default profile") + { + REQUIRE(view->profile() == profile); + } + THEN("serialized using default profile") + { + const auto data = view->serialize(); + REQUIRE(data.profile == profile_id); + REQUIRE(data.url.isEmpty()); + REQUIRE(!data.history.isEmpty()); + } + THEN("loading a url") + { + // block until a loadFinished signal + QEventLoop pause; + QObject::connect(view, &WebView::loadFinished, &pause, &QEventLoop::quit); + view->load(QUrl{ qgetenv("URL") }); + pause.exec(); + + REQUIRE(view->isLoaded()); + } + } + + WHEN("changing profiles") + { + const QString swap_profile_id{ "swap_profile" }; + auto *swap_settings = WebProfile::load(QString(), "about:blank", QUrl{ "about:blank" }, QUrl{ "about:blank" }); + auto *swap_profile = WebProfile::load(swap_profile_id, swap_settings, true); + + view->setProfile(swap_profile); + THEN("using the swap profile") + { + REQUIRE(view->profile() == swap_profile); + } + THEN("serialized using swap profile") + { + const auto data = view->serialize(); + REQUIRE(data.profile == swap_profile_id); + REQUIRE(data.url.isEmpty()); + REQUIRE(!data.history.isEmpty()); + } + + view->setProfile(profile); + delete swap_settings; + delete swap_profile; + } + + // cleanup + window.close(); + delete view; + delete settings; + delete profile; +} + +int main(int argc, char **argv) +{ + QtWebEngine::initialize(); + QApplication app(argc, argv); + + QTimer::singleShot(0, &app, [argc, argv, &app]() { + const auto n_failed = Catch::Session().run(argc, argv); + app.exit(n_failed); + }); + + return app.exec(); +} -- cgit v1.2.1