summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/qwebenginesettings/tst_qwebenginesettings.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/qwebenginesettings/tst_qwebenginesettings.cpp')
-rw-r--r--tests/auto/widgets/qwebenginesettings/tst_qwebenginesettings.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebenginesettings/tst_qwebenginesettings.cpp b/tests/auto/widgets/qwebenginesettings/tst_qwebenginesettings.cpp
index 5cbcf4ec0..9c008cb90 100644
--- a/tests/auto/widgets/qwebenginesettings/tst_qwebenginesettings.cpp
+++ b/tests/auto/widgets/qwebenginesettings/tst_qwebenginesettings.cpp
@@ -17,11 +17,17 @@
Boston, MA 02110-1301, USA.
*/
+#include "../util.h"
+
#include <QtTest/QtTest>
+#include <qwebenginepage.h>
#include <qwebengineprofile.h>
#include <qwebenginesettings.h>
+#include <QtGui/qclipboard.h>
+#include <QtGui/qguiapplication.h>
+
class tst_QWebEngineSettings: public QObject {
Q_OBJECT
@@ -29,6 +35,8 @@ private Q_SLOTS:
void resetAttributes();
void defaultFontFamily_data();
void defaultFontFamily();
+ void javascriptClipboard_data();
+ void javascriptClipboard();
};
void tst_QWebEngineSettings::resetAttributes()
@@ -85,6 +93,75 @@ void tst_QWebEngineSettings::defaultFontFamily()
QVERIFY(!settings->fontFamily(static_cast<QWebEngineSettings::FontFamily>(fontFamily)).isEmpty());
}
+void tst_QWebEngineSettings::javascriptClipboard_data()
+{
+ QTest::addColumn<bool>("javascriptCanAccessClipboard");
+ QTest::addColumn<bool>("javascriptCanPaste");
+ QTest::addColumn<bool>("copyResult");
+ QTest::addColumn<bool>("pasteResult");
+
+ QTest::newRow("default") << false << false << false << false;
+ QTest::newRow("canCopy") << true << false << true << false;
+ // paste command requires both permissions
+ QTest::newRow("canPaste") << false << true << false << false;
+ QTest::newRow("canCopyAndPaste") << true << true << true << true;
+}
+
+void tst_QWebEngineSettings::javascriptClipboard()
+{
+ QFETCH(bool, javascriptCanAccessClipboard);
+ QFETCH(bool, javascriptCanPaste);
+ QFETCH(bool, copyResult);
+ QFETCH(bool, pasteResult);
+
+ QWebEnginePage page;
+
+ // check defaults
+ QCOMPARE(page.settings()->testAttribute(QWebEngineSettings::JavascriptCanAccessClipboard),
+ false);
+ QCOMPARE(page.settings()->testAttribute(QWebEngineSettings::JavascriptCanPaste), false);
+
+ // check accessors
+ page.settings()->setAttribute(QWebEngineSettings::JavascriptCanAccessClipboard,
+ javascriptCanAccessClipboard);
+ page.settings()->setAttribute(QWebEngineSettings::JavascriptCanPaste,
+ javascriptCanPaste);
+ QCOMPARE(page.settings()->testAttribute(QWebEngineSettings::JavascriptCanAccessClipboard),
+ javascriptCanAccessClipboard);
+ QCOMPARE(page.settings()->testAttribute(QWebEngineSettings::JavascriptCanPaste),
+ javascriptCanPaste);
+
+ QSignalSpy loadFinishedSpy(&page, SIGNAL(loadFinished(bool)));
+ page.setHtml("<html><body>"
+ "<input type='text' value='OriginalText' id='myInput'/>"
+ "</body></html>");
+ QVERIFY(loadFinishedSpy.wait());
+
+ // make sure that 'OriginalText' is selected
+ evaluateJavaScriptSync(&page, "document.getElementById('myInput').select()");
+ QCOMPARE(evaluateJavaScriptSync(&page, "window.getSelection().toString()").toString(),
+ "OriginalText");
+
+ // Check that the actual settings work by the
+ // - return value of queryCommandEnabled and
+ // - return value of execCommand
+ // - comparing the clipboard / input field
+ QGuiApplication::clipboard()->clear();
+ QCOMPARE(evaluateJavaScriptSync(&page, "document.queryCommandEnabled('copy')").toBool(),
+ copyResult);
+ QCOMPARE(evaluateJavaScriptSync(&page, "document.execCommand('copy')").toBool(), copyResult);
+ QCOMPARE(QApplication::clipboard()->text(),
+ (copyResult ? QString("OriginalText") : QString()));
+
+
+ QGuiApplication::clipboard()->setText("AnotherText");
+ QCOMPARE(evaluateJavaScriptSync(&page, "document.queryCommandEnabled('paste')").toBool(),
+ pasteResult);
+ QCOMPARE(evaluateJavaScriptSync(&page, "document.execCommand('paste')").toBool(), pasteResult);
+ QCOMPARE(evaluateJavaScriptSync(&page, "document.getElementById('myInput').value").toString(),
+ (pasteResult ? QString("AnotherText") : QString("OriginalText")));
+}
+
QTEST_MAIN(tst_QWebEngineSettings)
#include "tst_qwebenginesettings.moc"