summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-02-27 11:25:29 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-02-27 11:25:29 +0100
commit01d4c6440b52f2ce26ced45b6ad193e909db44af (patch)
treeadf466a63806aa8a9c504642f17a2466a945232a
parent2d8d15047fdbf046cdee9fba103587c19808d7d2 (diff)
parentdf5d831bae99662fab43ed2628187113c18aac2c (diff)
Merge remote-tracking branch 'origin/5.14' into 5.15
Conflicts: src/core/renderer_host/web_channel_ipc_transport_host.cpp tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp Change-Id: I47f2b893bc9f27cd9df641f76badc9e53b482ad4
m---------src/3rdparty0
-rw-r--r--src/core/web_contents_adapter.cpp46
-rw-r--r--src/core/web_contents_adapter.h1
-rw-r--r--src/core/web_event_factory.cpp7
-rw-r--r--src/webenginewidgets/api/qwebenginepage.cpp7
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp46
-rw-r--r--tests/auto/widgets/qwebengineprofile/BLACKLIST3
-rw-r--r--tests/auto/widgets/qwebengineprofile/qwebengineprofile.pro1
-rw-r--r--tests/auto/widgets/qwebengineprofile/resources/hedgehog.html9
-rw-r--r--tests/auto/widgets/qwebengineprofile/resources/hedgehog.pngbin0 -> 11273 bytes
-rw-r--r--tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp297
-rw-r--r--tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp40
12 files changed, 332 insertions, 125 deletions
diff --git a/src/3rdparty b/src/3rdparty
-Subproject 5b79320c01316f29510df90f7c6b508b9f72b8a
+Subproject 12a57d9c943eaa80d87481712fe58f7bf6678ba
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp
index 6d763faa5..02f52df15 100644
--- a/src/core/web_contents_adapter.cpp
+++ b/src/core/web_contents_adapter.cpp
@@ -67,6 +67,7 @@
#include "base/task/sequence_manager/thread_controller_with_message_pump_impl.h"
#include "base/values.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
+#include "content/browser/renderer_host/text_input_manager.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/child_process_security_policy.h"
@@ -369,6 +370,23 @@ static void deserializeNavigationHistory(QDataStream &input, int *currentIndex,
}
}
+static void Navigate(WebContentsAdapter *adapter, const content::NavigationController::LoadURLParams &params)
+{
+ Q_ASSERT(adapter);
+ adapter->webContents()->GetController().LoadURLWithParams(params);
+ adapter->focusIfNecessary();
+ adapter->resetSelection();
+}
+
+static void NavigateTask(QWeakPointer<WebContentsAdapter> weakAdapter, const content::NavigationController::LoadURLParams &params)
+{
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ const auto adapter = weakAdapter.toStrongRef();
+ if (!adapter)
+ return;
+ Navigate(adapter.get(), params);
+}
+
namespace {
static QList<WebContentsAdapter *> recursive_guard_loading_adapters;
@@ -705,21 +723,12 @@ void WebContentsAdapter::load(const QWebEngineHttpRequest &request)
}
}
- auto navigate = [](QWeakPointer<WebContentsAdapter> weakAdapter, const content::NavigationController::LoadURLParams &params) {
- const auto adapter = weakAdapter.toStrongRef();
- if (!adapter)
- return;
- adapter->webContents()->GetController().LoadURLWithParams(params);
- adapter->focusIfNecessary();
- };
-
- QWeakPointer<WebContentsAdapter> weakThis(sharedFromThis());
if (resizeNeeded) {
// Schedule navigation on the event loop.
base::PostTaskWithTraits(FROM_HERE, {content::BrowserThread::UI},
- base::BindOnce(navigate, std::move(weakThis), std::move(params)));
+ base::BindOnce(&NavigateTask, sharedFromThis().toWeakRef(), std::move(params)));
} else {
- navigate(std::move(weakThis), params);
+ Navigate(this, params);
}
}
@@ -752,9 +761,7 @@ void WebContentsAdapter::setContent(const QByteArray &data, const QString &mimeT
params.can_load_local_resources = true;
params.transition_type = ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_API);
params.override_user_agent = content::NavigationController::UA_OVERRIDE_TRUE;
- m_webContents->GetController().LoadURLWithParams(params);
- focusIfNecessary();
- m_webContents->CollapseSelection();
+ Navigate(this, params);
}
void WebContentsAdapter::save(const QString &filePath, int savePageFormat)
@@ -1687,6 +1694,17 @@ bool WebContentsAdapter::hasFocusedFrame() const
return m_webContents->GetFocusedFrame() != nullptr;
}
+void WebContentsAdapter::resetSelection()
+{
+ CHECK_INITIALIZED();
+ // unconditionally clears the selection in contrast to CollapseSelection, which checks focus state first
+ if (auto rwhv = static_cast<RenderWidgetHostViewQt *>(m_webContents->GetRenderWidgetHostView())) {
+ if (auto mgr = rwhv->GetTextInputManager())
+ if (auto selection = const_cast<content::TextInputManager::TextSelection *>(mgr->GetTextSelection(rwhv)))
+ selection->SetSelection(base::string16(), 0, gfx::Range(), false);
+ }
+}
+
WebContentsAdapterClient::RenderProcessTerminationStatus
WebContentsAdapterClient::renderProcessExitStatus(int terminationStatus) {
auto status = WebContentsAdapterClient::RenderProcessTerminationStatus(-1);
diff --git a/src/core/web_contents_adapter.h b/src/core/web_contents_adapter.h
index 1afcdc01a..ef9d21b8f 100644
--- a/src/core/web_contents_adapter.h
+++ b/src/core/web_contents_adapter.h
@@ -230,6 +230,7 @@ public:
void focusIfNecessary();
bool isFindTextInProgress() const;
bool hasFocusedFrame() const;
+ void resetSelection();
// meant to be used within WebEngineCore only
void initialize(content::SiteInstance *site);
diff --git a/src/core/web_event_factory.cpp b/src/core/web_event_factory.cpp
index ba04806d5..f4940f305 100644
--- a/src/core/web_event_factory.cpp
+++ b/src/core/web_event_factory.cpp
@@ -157,8 +157,11 @@ static Qt::KeyboardModifiers qtModifiersForEvent(const QInputEvent *ev)
//
// On Linux, the Control modifier transformation is applied [1]. For example,
// pressing Ctrl+@ generates the text "\u0000". We would like "@" instead.
+// Windows also translates some control key combinations into ASCII control
+// characters [2].
//
// [1]: https://www.x.org/releases/current/doc/kbproto/xkbproto.html#Interpreting_the_Control_Modifier
+// [2]: https://docs.microsoft.com/en-us/windows/win32/learnwin32/keyboard-input#character-messages
//
// On macOS, if the Control modifier is used, then no text is generated at all.
// We need some text.
@@ -171,8 +174,10 @@ static QString qtTextForKeyEvent(const QKeyEvent *ev, int qtKey, Qt::KeyboardMod
{
QString text = ev->text();
- if ((qtModifiers & Qt::ControlModifier) && keyboardDriver() == KeyboardDriver::Xkb)
+ if ((qtModifiers & Qt::ControlModifier) &&
+ (keyboardDriver() == KeyboardDriver::Xkb || keyboardDriver() == KeyboardDriver::Windows)) {
text.clear();
+ }
return text;
}
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp
index 54e4dd9af..ad6196850 100644
--- a/src/webenginewidgets/api/qwebenginepage.cpp
+++ b/src/webenginewidgets/api/qwebenginepage.cpp
@@ -1897,13 +1897,12 @@ void QWebEnginePagePrivate::visibleChanged(bool visible)
Registers the request interceptor \a interceptor to intercept URL requests.
The page does not take ownership of the pointer. This interceptor is called
- after any interceptors on the profile, and unlike profile interceptors, is run
- on the UI thread, making it thread-safer. Only URL requests from this page are
- intercepted.
+ after any interceptors on the profile, and unlike profile interceptors, only
+ URL requests from this page are intercepted.
To unset the request interceptor, set a \c nullptr.
- \sa QWebEngineUrlRequestInfo, QWebEngineProfile::setRequestInterceptor()
+ \sa QWebEngineUrlRequestInfo, QWebEngineProfile::setUrlRequestInterceptor()
*/
void QWebEnginePage::setUrlRequestInterceptor(QWebEngineUrlRequestInterceptor *interceptor)
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index 7fdf897ca..f500652c7 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -701,7 +701,7 @@ public:
CursorTrackedPage(QWidget *parent = 0): QWebEnginePage(parent) {
}
- QString selectedText() {
+ QString jsSelectedText() {
return evaluateJavaScriptSync(this, "window.getSelection().toString()").toString();
}
@@ -717,42 +717,52 @@ public:
int isSelectionCollapsed() {
return evaluateJavaScriptSync(this, "window.getSelection().getRangeAt(0).collapsed").toBool();
}
- bool hasSelection()
- {
- return !selectedText().isEmpty();
- }
};
void tst_QWebEnginePage::textSelection()
{
- QWebEngineView view;
- CursorTrackedPage *page = new CursorTrackedPage(&view);
- QString content("<html><body><p id=one>The quick brown fox</p>" \
+ CursorTrackedPage page;
+
+ QString textToSelect("The quick brown fox");
+ QString content = QString("<html><body><p id=one>%1</p>" \
"<p id=two>jumps over the lazy dog</p>" \
- "<p>May the source<br/>be with you!</p></body></html>");
- page->setView(&view);
- QSignalSpy loadSpy(&view, SIGNAL(loadFinished(bool)));
- page->setHtml(content);
+ "<p>May the source<br/>be with you!</p></body></html>").arg(textToSelect);
+
+ QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool)));
+ page.setHtml(content);
QTRY_COMPARE_WITH_TIMEOUT(loadSpy.count(), 1, 20000);
// these actions must exist
- QVERIFY(page->action(QWebEnginePage::SelectAll) != 0);
+ QVERIFY(page.action(QWebEnginePage::SelectAll) != 0);
// ..but SelectAll is disabled because the page has no focus due to disabled FocusOnNavigationEnabled.
- QCOMPARE(page->action(QWebEnginePage::SelectAll)->isEnabled(), false);
+ QCOMPARE(page.action(QWebEnginePage::SelectAll)->isEnabled(), false);
// Verify hasSelection returns false since there is no selection yet...
- QCOMPARE(page->hasSelection(), false);
+ QVERIFY(!page.hasSelection());
+ QVERIFY(page.jsSelectedText().isEmpty());
// this will select the first paragraph
QString selectScript = "var range = document.createRange(); " \
"var node = document.getElementById(\"one\"); " \
"range.selectNode(node); " \
"getSelection().addRange(range);";
- evaluateJavaScriptSync(page, selectScript);
- QCOMPARE(page->selectedText().trimmed(), QString::fromLatin1("The quick brown fox"));
+ evaluateJavaScriptSync(&page, selectScript);
+
// Make sure hasSelection returns true, since there is selected text now...
- QCOMPARE(page->hasSelection(), true);
+ QTRY_VERIFY(page.hasSelection());
+ QCOMPARE(page.selectedText().trimmed(), textToSelect);
+
+ QCOMPARE(page.jsSelectedText().trimmed(), textToSelect);
+
+ // navigate away and check that selection is cleared
+ page.load(QUrl("about:blank"));
+ QTRY_COMPARE(loadSpy.count(), 2);
+
+ QVERIFY(!page.hasSelection());
+ QVERIFY(page.selectedText().isEmpty());
+
+ QVERIFY(page.jsSelectedText().isEmpty());
}
diff --git a/tests/auto/widgets/qwebengineprofile/BLACKLIST b/tests/auto/widgets/qwebengineprofile/BLACKLIST
deleted file mode 100644
index 55806eec4..000000000
--- a/tests/auto/widgets/qwebengineprofile/BLACKLIST
+++ /dev/null
@@ -1,3 +0,0 @@
-[disableCache]
-*
-
diff --git a/tests/auto/widgets/qwebengineprofile/qwebengineprofile.pro b/tests/auto/widgets/qwebengineprofile/qwebengineprofile.pro
index e56bbe8f7..ca16cee39 100644
--- a/tests/auto/widgets/qwebengineprofile/qwebengineprofile.pro
+++ b/tests/auto/widgets/qwebengineprofile/qwebengineprofile.pro
@@ -1,3 +1,4 @@
include(../tests.pri)
+include(../../shared/http.pri)
exists($${TARGET}.qrc):RESOURCES += $${TARGET}.qrc
QT *= core-private gui-private
diff --git a/tests/auto/widgets/qwebengineprofile/resources/hedgehog.html b/tests/auto/widgets/qwebengineprofile/resources/hedgehog.html
new file mode 100644
index 000000000..d8abbcd48
--- /dev/null
+++ b/tests/auto/widgets/qwebengineprofile/resources/hedgehog.html
@@ -0,0 +1,9 @@
+<!doctype html>
+<html>
+ <head>
+ <title>BREAKING NEWS: 15 Hedgehogs With Things That Look Like Hedgehogs</title>
+ </head>
+ <body>
+ <img src="hedgehog.png"/>
+ </body>
+</html>
diff --git a/tests/auto/widgets/qwebengineprofile/resources/hedgehog.png b/tests/auto/widgets/qwebengineprofile/resources/hedgehog.png
new file mode 100644
index 000000000..4d56d8633
--- /dev/null
+++ b/tests/auto/widgets/qwebengineprofile/resources/hedgehog.png
Binary files differ
diff --git a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
index 1dd8a38c8..1f8162941 100644
--- a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
+++ b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
@@ -28,6 +28,7 @@
#include "../util.h"
#include <QtCore/qbuffer.h>
+#include <QtCore/qmimedatabase.h>
#include <QtTest/QtTest>
#include <QtWebEngineCore/qwebengineurlrequestinterceptor.h>
#include <QtWebEngineCore/qwebengineurlrequestjob.h>
@@ -44,6 +45,9 @@
#include <QWebChannel>
#endif
+#include <httpserver.h>
+#include <httpreqrep.h>
+
#include <map>
#include <mutex>
@@ -72,6 +76,10 @@ private Q_SLOTS:
void httpAcceptLanguage();
void downloadItem();
void changePersistentPath();
+ void changeHttpUserAgent();
+ void changeHttpAcceptLanguage();
+ void changeUseForGlobalCertificateVerification();
+ void changePersistentCookiesPolicy();
void initiator();
void badDeleteOrder();
void qtbug_71895(); // this should be the last test
@@ -83,6 +91,7 @@ void tst_QWebEngineProfile::initTestCase()
QWebEngineUrlScheme stream("stream");
QWebEngineUrlScheme letterto("letterto");
QWebEngineUrlScheme aviancarrier("aviancarrier");
+ QWebEngineUrlScheme myscheme("myscheme");
foo.setSyntax(QWebEngineUrlScheme::Syntax::Host);
stream.setSyntax(QWebEngineUrlScheme::Syntax::HostAndPort);
stream.setDefaultPort(8080);
@@ -93,6 +102,7 @@ void tst_QWebEngineProfile::initTestCase()
QWebEngineUrlScheme::registerScheme(stream);
QWebEngineUrlScheme::registerScheme(letterto);
QWebEngineUrlScheme::registerScheme(aviancarrier);
+ QWebEngineUrlScheme::registerScheme(myscheme);
}
void tst_QWebEngineProfile::init()
@@ -152,75 +162,125 @@ void tst_QWebEngineProfile::testProfile()
+ QStringLiteral("/QtWebEngine/Test"));
}
+class AutoDir : public QDir
+{
+public:
+ AutoDir(const QString &p) : QDir(p)
+ {
+ makeAbsolute();
+ removeRecursively();
+ }
+
+ ~AutoDir() { removeRecursively(); }
+};
+qint64 totalSize(QDir dir)
+{
+ qint64 sum = 0;
+ const QDir::Filters filters{QDir::Dirs, QDir::Files, QDir::NoSymLinks, QDir::NoDotAndDotDot};
+ for (const QFileInfo &entry : dir.entryInfoList(filters)) {
+ if (entry.isFile())
+ sum += entry.size();
+ else if (entry.isDir())
+ sum += totalSize(entry.filePath());
+ }
+ return sum;
+}
+
+class TestServer : public HttpServer
+{
+public:
+ TestServer()
+ {
+ connect(this, &HttpServer::newRequest, this, &TestServer::onNewRequest);
+ }
+
+private:
+ void onNewRequest(HttpReqRep *rr)
+ {
+ const QDir resourceDir(TESTS_SOURCE_DIR "qwebengineprofile/resources");
+ QString path = rr->requestPath();
+ path.remove(0, 1);
+
+ if (rr->requestMethod() != "GET" || !resourceDir.exists(path))
+ {
+ rr->setResponseStatus(404);
+ rr->sendResponse();
+ return;
+ }
+
+ QFile file(resourceDir.filePath(path));
+ file.open(QIODevice::ReadOnly);
+ QByteArray data = file.readAll();
+ rr->setResponseBody(data);
+ QMimeDatabase db;
+ QMimeType mime = db.mimeTypeForFileNameAndData(file.fileName(), data);
+ rr->setResponseHeader(QByteArrayLiteral("content-type"), mime.name().toUtf8());
+ if (!mime.inherits("text/html"))
+ rr->setResponseHeader(QByteArrayLiteral("cache-control"),
+ QByteArrayLiteral("public, max-age=31536000"));
+ rr->sendResponse();
+ }
+};
+
+static bool loadSync(QWebEnginePage *page, const QUrl &url, bool ok = true)
+{
+ QSignalSpy spy(page, &QWebEnginePage::loadFinished);
+ page->load(url);
+ return (!spy.empty() || spy.wait(20000)) && (spy.front().value(0).toBool() == ok);
+}
+
+static bool loadSync(QWebEngineView *view, const QUrl &url, bool ok = true)
+{
+ return loadSync(view->page(), url, ok);
+}
+
void tst_QWebEngineProfile::clearDataFromCache()
{
- QDir cacheDir("./tst_QWebEngineProfile_cacheDir");
- cacheDir.makeAbsolute();
- if (cacheDir.exists())
- cacheDir.removeRecursively();
- cacheDir.mkpath(cacheDir.path());
+ TestServer server;
+ QVERIFY(server.start());
+
+ AutoDir cacheDir("./tst_QWebEngineProfile_clearDataFromCache");
QWebEngineProfile profile(QStringLiteral("Test"));
profile.setCachePath(cacheDir.path());
profile.setHttpCacheType(QWebEngineProfile::DiskHttpCache);
- QWebEnginePage page(&profile, nullptr);
-
- QSignalSpy loadFinishedSpy(&page, SIGNAL(loadFinished(bool)));
- page.load(QUrl("http://qt-project.org"));
- if (!loadFinishedSpy.wait(10000) || !loadFinishedSpy.at(0).at(0).toBool())
- QSKIP("Couldn't load page from network, skipping test.");
-
- cacheDir.refresh();
- QVERIFY(cacheDir.entryList().contains("Cache"));
- cacheDir.cd("./Cache");
- int filesBeforeClear = cacheDir.entryList().count();
-
- QFileSystemWatcher fileSystemWatcher;
- fileSystemWatcher.addPath(cacheDir.path());
- QSignalSpy directoryChangedSpy(&fileSystemWatcher, SIGNAL(directoryChanged(const QString &)));
+ QWebEnginePage page(&profile);
+ QVERIFY(loadSync(&page, server.url("/hedgehog.html")));
- // It deletes most of the files, but not all of them.
+ QVERIFY(cacheDir.exists("Cache"));
+ qint64 sizeBeforeClear = totalSize(cacheDir);
profile.clearHttpCache();
+ // Wait for cache to be cleared.
QTest::qWait(1000);
- QTRY_VERIFY(directoryChangedSpy.count() > 0);
+ QVERIFY(sizeBeforeClear > totalSize(cacheDir));
- cacheDir.refresh();
- QVERIFY(filesBeforeClear > cacheDir.entryList().count());
-
- cacheDir.removeRecursively();
+ QVERIFY(server.stop());
}
void tst_QWebEngineProfile::disableCache()
{
- QWebEnginePage page;
- QDir cacheDir("./tst_QWebEngineProfile_cacheDir");
- if (cacheDir.exists())
- cacheDir.removeRecursively();
- cacheDir.mkpath(cacheDir.path());
+ TestServer server;
+ QVERIFY(server.start());
+
+ AutoDir cacheDir("./tst_QWebEngineProfile_disableCache");
+ QWebEnginePage page;
QWebEngineProfile *profile = page.profile();
profile->setCachePath(cacheDir.path());
- QVERIFY(!cacheDir.entryList().contains("Cache"));
+ QVERIFY(!cacheDir.exists("Cache"));
profile->setHttpCacheType(QWebEngineProfile::NoCache);
- QSignalSpy loadFinishedSpy(&page, SIGNAL(loadFinished(bool)));
- page.load(QUrl("http://qt-project.org"));
- if (!loadFinishedSpy.wait(10000) || !loadFinishedSpy.at(0).at(0).toBool())
- QSKIP("Couldn't load page from network, skipping test.");
-
- cacheDir.refresh();
- QVERIFY(!cacheDir.entryList().contains("Cache"));
+ // Wait for cache to be cleared.
+ QTest::qWait(1000);
+ QVERIFY(loadSync(&page, server.url("/hedgehog.html")));
+ QVERIFY(!cacheDir.exists("Cache"));
profile->setHttpCacheType(QWebEngineProfile::DiskHttpCache);
- page.load(QUrl("http://qt-project.org"));
- if (!loadFinishedSpy.wait(10000) || !loadFinishedSpy.at(1).at(0).toBool())
- QSKIP("Couldn't load page from network, skipping test.");
-
- cacheDir.refresh();
- QVERIFY(cacheDir.entryList().contains("Cache"));
+ QVERIFY(loadSync(&page, server.url("/hedgehog.html")));
+ QVERIFY(cacheDir.exists("Cache"));
- cacheDir.removeRecursively();
+ QVERIFY(server.stop());
}
class RedirectingUrlSchemeHandler : public QWebEngineUrlSchemeHandler
@@ -332,21 +392,6 @@ public:
}
};
-static bool loadSync(QWebEngineView *view, const QUrl &url, int timeout = 5000)
-{
- // Ripped off QTRY_VERIFY.
- QSignalSpy loadFinishedSpy(view, SIGNAL(loadFinished(bool)));
- view->load(url);
- if (loadFinishedSpy.isEmpty())
- QTest::qWait(0);
- for (int i = 0; i < timeout; i += 50) {
- if (!loadFinishedSpy.isEmpty())
- return true;
- QTest::qWait(50);
- }
- return false;
-}
-
void tst_QWebEngineProfile::urlSchemeHandlers()
{
RedirectingUrlSchemeHandler lettertoHandler;
@@ -369,7 +414,7 @@ void tst_QWebEngineProfile::urlSchemeHandlers()
// Remove the letterto scheme, and check whether it is not handled anymore.
profile.removeUrlScheme("letterto");
emailAddress = QStringLiteral("kjeld@olsen-banden.dk");
- QVERIFY(loadSync(&view, QUrl(QStringLiteral("letterto:") + emailAddress)));
+ QVERIFY(loadSync(&view, QUrl(QStringLiteral("letterto:") + emailAddress), false));
QVERIFY(toPlainTextSync(view.page()) != emailAddress);
// Check if gopher is still working after removing letterto.
@@ -380,7 +425,7 @@ void tst_QWebEngineProfile::urlSchemeHandlers()
// Does removeAll work?
profile.removeAllUrlSchemeHandlers();
url = QUrl(QStringLiteral("gopher://olsen-banden.dk/harry"));
- QVERIFY(loadSync(&view, url));
+ QVERIFY(loadSync(&view, url, false));
QVERIFY(toPlainTextSync(view.page()) != url.toString());
// Install a handler that is owned by the view. Make sure this doesn't crash on shutdown.
@@ -801,28 +846,132 @@ void tst_QWebEngineProfile::downloadItem()
QWebEngineProfile testProfile;
QWebEnginePage page(&testProfile);
QSignalSpy downloadSpy(&testProfile, SIGNAL(downloadRequested(QWebEngineDownloadItem *)));
- connect(&testProfile, &QWebEngineProfile::downloadRequested, this, [=] (QWebEngineDownloadItem *item) { item->accept(); });
page.load(QUrl::fromLocalFile(QCoreApplication::applicationFilePath()));
QTRY_COMPARE(downloadSpy.count(), 1);
}
void tst_QWebEngineProfile::changePersistentPath()
{
+ TestServer server;
+ QVERIFY(server.start());
+
+ AutoDir dataDir1(QStandardPaths::writableLocation(QStandardPaths::DataLocation)
+ + QStringLiteral("/QtWebEngine/Test"));
+ AutoDir dataDir2(QStandardPaths::writableLocation(QStandardPaths::DataLocation)
+ + QStringLiteral("/QtWebEngine/Test2"));
+
QWebEngineProfile testProfile(QStringLiteral("Test"));
- const QString oldPath = testProfile.persistentStoragePath();
- QVERIFY(oldPath.endsWith(QStringLiteral("Test")));
+ QCOMPARE(testProfile.persistentStoragePath(), dataDir1.path());
- // Make sure the profile has been used and the url-request-context-getter instantiated:
+ // Make sure the profile has been used:
QWebEnginePage page(&testProfile);
- QSignalSpy loadFinishedSpy(&page, SIGNAL(loadFinished(bool)));
- page.load(QUrl("http://qt-project.org"));
- if (!loadFinishedSpy.wait(10000) || !loadFinishedSpy.at(0).at(0).toBool())
- QSKIP("Couldn't load page from network, skipping test.");
+ QVERIFY(loadSync(&page, server.url("/hedgehog.html")));
// Test we do not crash (QTBUG-55322):
- testProfile.setPersistentStoragePath(oldPath + QLatin1Char('2'));
- const QString newPath = testProfile.persistentStoragePath();
- QVERIFY(newPath.endsWith(QStringLiteral("Test2")));
+ testProfile.setPersistentStoragePath(dataDir2.path());
+ QCOMPARE(testProfile.persistentStoragePath(), dataDir2.path());
+ QVERIFY(loadSync(&page, server.url("/hedgehog.html")));
+ QVERIFY(dataDir2.exists());
+
+ QVERIFY(server.stop());
+}
+
+void tst_QWebEngineProfile::changeHttpUserAgent()
+{
+ TestServer server;
+ QVERIFY(server.start());
+
+ QVector<QByteArray> userAgents;
+ connect(&server, &HttpServer::newRequest, [&](HttpReqRep *rr) {
+ if (rr->requestPath() == "/hedgehog.html")
+ userAgents.push_back(rr->requestHeader(QByteArrayLiteral("user-agent")));
+ });
+
+ QWebEngineProfile profile(QStringLiteral("Test"));
+ std::unique_ptr<QWebEnginePage> page;
+ page.reset(new QWebEnginePage(&profile));
+ QVERIFY(loadSync(page.get(), server.url("/hedgehog.html")));
+ page.reset();
+ profile.setHttpUserAgent("webturbine/42");
+ page.reset(new QWebEnginePage(&profile));
+ QVERIFY(loadSync(page.get(), server.url("/hedgehog.html")));
+
+ QCOMPARE(userAgents.size(), 2);
+ QCOMPARE(userAgents[1], "webturbine/42");
+ QVERIFY(userAgents[0] != userAgents[1]);
+
+ QVERIFY(server.stop());
+}
+
+void tst_QWebEngineProfile::changeHttpAcceptLanguage()
+{
+ TestServer server;
+ QVERIFY(server.start());
+
+ QVector<QByteArray> languages;
+ connect(&server, &HttpServer::newRequest, [&](HttpReqRep *rr) {
+ if (rr->requestPath() == "/hedgehog.html")
+ languages.push_back(rr->requestHeader(QByteArrayLiteral("accept-language")));
+ });
+
+ QWebEngineProfile profile(QStringLiteral("Test"));
+ std::unique_ptr<QWebEnginePage> page;
+ page.reset(new QWebEnginePage(&profile));
+ QVERIFY(loadSync(page.get(), server.url("/hedgehog.html")));
+ page.reset();
+ profile.setHttpAcceptLanguage("fi");
+ page.reset(new QWebEnginePage(&profile));
+ QVERIFY(loadSync(page.get(), server.url("/hedgehog.html")));
+
+ QCOMPARE(languages.size(), 2);
+ QCOMPARE(languages[1], "fi");
+ QVERIFY(languages[0] != languages[1]);
+
+ QVERIFY(server.stop());
+}
+
+void tst_QWebEngineProfile::changeUseForGlobalCertificateVerification()
+{
+ QSKIP("Needs 3rdparty fix");
+
+ TestServer server;
+ QVERIFY(server.start());
+
+ // Check that we don't crash
+
+ QWebEngineProfile profile(QStringLiteral("Test"));
+ std::unique_ptr<QWebEnginePage> page;
+ page.reset(new QWebEnginePage(&profile));
+ QVERIFY(loadSync(page.get(), server.url("/hedgehog.html")));
+ page.reset();
+ profile.setUseForGlobalCertificateVerification(true);
+ page.reset(new QWebEnginePage(&profile));
+ QVERIFY(loadSync(page.get(), server.url("/hedgehog.html")));
+ QVERIFY(server.stop());
+}
+
+void tst_QWebEngineProfile::changePersistentCookiesPolicy()
+{
+ TestServer server;
+ QVERIFY(server.start());
+
+ AutoDir dataDir("./tst_QWebEngineProfile_dataDir");
+
+ QWebEngineProfile profile(QStringLiteral("Test"));
+ QWebEnginePage page(&profile);
+
+ profile.setPersistentStoragePath(dataDir.path());
+ profile.setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies);
+
+ QVERIFY(loadSync(&page, server.url("/hedgehog.html")));
+ QVERIFY(!dataDir.exists("Cookies"));
+
+ profile.setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies);
+
+ QVERIFY(loadSync(&page, server.url("/hedgehog.html")));
+ QVERIFY(dataDir.exists("Cookies"));
+
+ QVERIFY(server.stop());
}
class InitiatorSpy : public QWebEngineUrlSchemeHandler
diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
index f15a65469..b733e509c 100644
--- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
+++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
@@ -199,6 +199,7 @@ private Q_SLOTS:
void visibilityState();
void visibilityState2();
void visibilityState3();
+ void jsKeyboardEvent_data();
void jsKeyboardEvent();
void deletePage();
void closeOpenerTab();
@@ -3383,6 +3384,28 @@ void tst_QWebEngineView::visibilityState3()
QCOMPARE(evaluateJavaScriptSync(&page2, "document.visibilityState").toString(), QStringLiteral("visible"));
}
+void tst_QWebEngineView::jsKeyboardEvent_data()
+{
+ QTest::addColumn<char>("key");
+ QTest::addColumn<Qt::KeyboardModifiers>("modifiers");
+ QTest::addColumn<QString>("expected");
+
+#if defined(Q_OS_MACOS)
+ // See Qt::AA_MacDontSwapCtrlAndMeta
+ Qt::KeyboardModifiers controlModifier = Qt::MetaModifier;
+#else
+ Qt::KeyboardModifiers controlModifier = Qt::ControlModifier;
+#endif
+
+ QTest::newRow("Ctrl+Shift+A") << 'A' << (controlModifier | Qt::ShiftModifier) << QStringLiteral(
+ "16,ShiftLeft,Shift,false,true,false;"
+ "17,ControlLeft,Control,true,true,false;"
+ "65,KeyA,A,true,true,false;");
+ QTest::newRow("Ctrl+z") << 'z' << controlModifier << QStringLiteral(
+ "17,ControlLeft,Control,true,false,false;"
+ "90,KeyZ,z,true,false,false;");
+}
+
void tst_QWebEngineView::jsKeyboardEvent()
{
QWebEngineView view;
@@ -3392,18 +3415,13 @@ void tst_QWebEngineView::jsKeyboardEvent()
"addEventListener('keydown', (ev) => {"
" log += [ev.keyCode, ev.code, ev.key, ev.ctrlKey, ev.shiftKey, ev.altKey].join(',') + ';';"
"});");
+
+ QFETCH(char, key);
+ QFETCH(Qt::KeyboardModifiers, modifiers);
+ QFETCH(QString, expected);
+
// Note that this only tests the fallback code path where native scan codes are not used.
-#if defined(Q_OS_MACOS)
- // See Qt::AA_MacDontSwapCtrlAndMeta
- QTest::keyClick(view.focusProxy(), 'A', Qt::MetaModifier | Qt::ShiftModifier);
-#else
- QTest::keyClick(view.focusProxy(), 'A', Qt::ControlModifier | Qt::ShiftModifier);
-#endif
- QString expected = QStringLiteral(
- "16,ShiftLeft,Shift,false,true,false;"
- "17,ControlLeft,Control,true,true,false;"
- "65,KeyA,A,true,true,false;"
- );
+ QTest::keyClick(view.focusProxy(), key, modifiers);
QTRY_VERIFY(evaluateJavaScriptSync(view.page(), "log") != QVariant(QString()));
QCOMPARE(evaluateJavaScriptSync(view.page(), "log"), expected);
}