diff --git a/webenginepart/autotests/webenginepartcookiejar_test.cpp b/webenginepart/autotests/webenginepartcookiejar_test.cpp --- a/webenginepart/autotests/webenginepartcookiejar_test.cpp +++ b/webenginepart/autotests/webenginepartcookiejar_test.cpp @@ -126,9 +126,7 @@ const CookieData &ex = expected.at(i); const CookieData &in = input.at(i); QNetworkCookie c = in.cookie(); - if (in.domain.isEmpty()) { - c.normalize(QUrl("https://" + in.host)); - } + c.normalize(QUrl("https://" + in.host)); QTest::newRow(labels.at(i).toLatin1()) << c << ex.name << ex.value << ex.domain << ex.path << ex.host << ex.expiration << ex.secure; } } @@ -158,7 +156,7 @@ QCOMPARE(fields.count(), resFields.count()); QCOMPARE(resFields.at(0), domain); - QCOMPARE(resFields.at(1), path); + QCOMPARE(resFields.at(1), path.isEmpty() ? "/" : path); QCOMPARE(resFields.at(2), name); if (!domain.isEmpty()){ QEXPECT_FAIL("", "The value returned by KCookieServer strips the leftmost part of the fqdn. Why?", Continue); @@ -229,14 +227,15 @@ QTest::addColumn("cookie"); QTest::addColumn("name"); QTest::addColumn("domain"); + QTest::addColumn("path"); QTest::addColumn("host"); const QStringList labels{ "remove persistent cookie with domain and path", "remove session cookie with domain and path", "remove persistent cookie with domain and no path", "remove persistent cookie with path and no domain", - "remove persistent cookie without secure", + "remove persistent cookie without secure" }; const QList input{ @@ -253,35 +252,39 @@ const CookieData &ex = expected.at(i); const CookieData &in = input.at(i); QNetworkCookie c = in.cookie(); - if (in.domain.isEmpty()) { - c.normalize(QUrl("https://" + in.host)); - } - QTest::newRow(labels.at(i).toLatin1()) << c << ex.name << ex.domain << ex.host; + c.normalize(QUrl("https://" + in.host)); + QTest::newRow(labels.at(i).toLatin1()) << c << ex.name << ex.domain << ex.path << ex.host; }} void TestWebEnginePartCookieJar::testCookieRemovedFromStoreAreRemovedFromKCookieServer() { QFETCH(const QNetworkCookie, cookie); QFETCH(const QString, name); QFETCH(const QString, domain); + QFETCH(const QString, path); QFETCH(const QString, host); //Add cookie to KCookieServer QDBusError e = addCookieToKCookieServer(cookie, host); QVERIFY2(!e.isValid(), qPrintable(m_server->lastError().message())); + auto findCookies=[this, &domain, &host, &path, &name](){ + QDBusReply reply = m_server->call(QDBus::Block, "findCookies", QVariant::fromValue(QList{2}), domain, host, path.isEmpty() ? "/" : path, name); + return reply; + }; + //Ensure cookie has been added to KCookieServer - QDBusReply reply = m_server->call(QDBus::Block, "findCookies", QVariant::fromValue(QList{2}), domain, host, "", ""); + QDBusReply reply = findCookies(); QVERIFY2(reply.isValid(), qPrintable(reply.error().message())); - QStringList cookies = reply.value(); - QVERIFY2(cookies.contains(name), "Cookie wasn't added to server"); - + QVERIFY2(reply.value().contains(name), "Cookie wasn't added to server"); + //Emit QWebEngineCookieStore::cookieRemoved signal and check that cookie has indeed been removed emit m_store->cookieRemoved(cookie); - reply = m_server->call(QDBus::Block, "findCookies", QVariant::fromValue(QList{2}), domain, "", "", ""); + + //Check that cookie is no longer in KCookieServer + reply = findCookies(); QVERIFY2(reply.isValid(), qPrintable(reply.error().message())); - cookies = reply.value(); - QVERIFY2(!cookies.contains(name), "Cookie wasn't removed from server"); + QVERIFY2(!reply.value().contains(name), "Cookie wasn't removed from server"); } QDBusError TestWebEnginePartCookieJar::addCookieToKCookieServer(const QNetworkCookie& _cookie, const QString& host) diff --git a/webenginepart/src/webenginepartcookiejar.cpp b/webenginepart/src/webenginepartcookiejar.cpp --- a/webenginepart/src/webenginepartcookiejar.cpp +++ b/webenginepart/src/webenginepartcookiejar.cpp @@ -269,7 +269,7 @@ } removeCookieDomain(cookie); - QDBusPendingCall pcall = m_cookieServer.asyncCall("deleteCookie", cookie.domain(), url.toString(), cookie.path(), QString(cookie.name())); + QDBusPendingCall pcall = m_cookieServer.asyncCall("deleteCookie", cookie.domain(), url.host(), cookie.path(), QString(cookie.name())); QDBusPendingCallWatcher *w = new QDBusPendingCallWatcher(pcall, this); connect(w, &QDBusPendingCallWatcher::finished, this, &WebEnginePartCookieJar::cookieRemovalFailed); } @@ -331,7 +331,7 @@ { QNetworkCookie c; auto extractField = [data, start](CookieDetails field){return data.at(start + static_cast(field));}; - c.setDomain(data.at(start+static_cast(CookieDetails::domain)).toUtf8()); + c.setDomain(extractField(CookieDetails::domain).toUtf8()); c.setExpirationDate(QDateTime::fromSecsSinceEpoch(extractField(CookieDetails::expirationDate).toInt())); c.setName(extractField(CookieDetails::name).toUtf8()); c.setPath(extractField(CookieDetails::path).toUtf8());