#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(); }