From 3395426ab651a631aca8ee6b0a694a71df19100f Mon Sep 17 00:00:00 2001 From: Konstantin Tokarev Date: Thu, 3 Oct 2019 22:48:16 +0300 Subject: Import QtWebKit commit 49b749171e786df3adcd7a755df428c1846acd69 Change-Id: I4c82d8030969d941bb78b1cc4e77c0a66db8da2c Reviewed-by: Konstantin Tokarev --- .../qt/tests/qwebpage/resources/content.html | 6 - .../qt/tests/qwebpage/resources/frame_a.html | 2 - .../qt/tests/qwebpage/resources/frame_c.html | 1 - .../qt/tests/qwebpage/resources/framedindex.html | 6 - .../WebKit/qt/tests/qwebpage/resources/iframe.html | 6 - .../qt/tests/qwebpage/resources/iframe2.html | 7 - .../qt/tests/qwebpage/resources/iframe3.html | 5 - .../WebKit/qt/tests/qwebpage/resources/index.html | 6 - .../WebKit/qt/tests/qwebpage/resources/script.html | 3 - Source/WebKit/qt/tests/qwebpage/resources/user.css | 3 - Source/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp | 3501 -------------------- Source/WebKit/qt/tests/qwebpage/tst_qwebpage.qrc | 15 - 12 files changed, 3561 deletions(-) delete mode 100644 Source/WebKit/qt/tests/qwebpage/resources/content.html delete mode 100644 Source/WebKit/qt/tests/qwebpage/resources/frame_a.html delete mode 100644 Source/WebKit/qt/tests/qwebpage/resources/frame_c.html delete mode 100644 Source/WebKit/qt/tests/qwebpage/resources/framedindex.html delete mode 100644 Source/WebKit/qt/tests/qwebpage/resources/iframe.html delete mode 100644 Source/WebKit/qt/tests/qwebpage/resources/iframe2.html delete mode 100644 Source/WebKit/qt/tests/qwebpage/resources/iframe3.html delete mode 100644 Source/WebKit/qt/tests/qwebpage/resources/index.html delete mode 100644 Source/WebKit/qt/tests/qwebpage/resources/script.html delete mode 100644 Source/WebKit/qt/tests/qwebpage/resources/user.css delete mode 100644 Source/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp delete mode 100644 Source/WebKit/qt/tests/qwebpage/tst_qwebpage.qrc (limited to 'Source/WebKit/qt/tests/qwebpage') diff --git a/Source/WebKit/qt/tests/qwebpage/resources/content.html b/Source/WebKit/qt/tests/qwebpage/resources/content.html deleted file mode 100644 index 823a98306..000000000 --- a/Source/WebKit/qt/tests/qwebpage/resources/content.html +++ /dev/null @@ -1,6 +0,0 @@ - - -This is test content - - - diff --git a/Source/WebKit/qt/tests/qwebpage/resources/frame_a.html b/Source/WebKit/qt/tests/qwebpage/resources/frame_a.html deleted file mode 100644 index 9ff68f13a..000000000 --- a/Source/WebKit/qt/tests/qwebpage/resources/frame_a.html +++ /dev/null @@ -1,2 +0,0 @@ -Google -Yahoo diff --git a/Source/WebKit/qt/tests/qwebpage/resources/frame_c.html b/Source/WebKit/qt/tests/qwebpage/resources/frame_c.html deleted file mode 100644 index eba9ca0eb..000000000 --- a/Source/WebKit/qt/tests/qwebpage/resources/frame_c.html +++ /dev/null @@ -1 +0,0 @@ -Google diff --git a/Source/WebKit/qt/tests/qwebpage/resources/framedindex.html b/Source/WebKit/qt/tests/qwebpage/resources/framedindex.html deleted file mode 100644 index be4500483..000000000 --- a/Source/WebKit/qt/tests/qwebpage/resources/framedindex.html +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/Source/WebKit/qt/tests/qwebpage/resources/iframe.html b/Source/WebKit/qt/tests/qwebpage/resources/iframe.html deleted file mode 100644 index f17027c7a..000000000 --- a/Source/WebKit/qt/tests/qwebpage/resources/iframe.html +++ /dev/null @@ -1,6 +0,0 @@ - - -

top

- - - - diff --git a/Source/WebKit/qt/tests/qwebpage/resources/iframe3.html b/Source/WebKit/qt/tests/qwebpage/resources/iframe3.html deleted file mode 100644 index ed6ac5b94..000000000 --- a/Source/WebKit/qt/tests/qwebpage/resources/iframe3.html +++ /dev/null @@ -1,5 +0,0 @@ - - -

inner

- - diff --git a/Source/WebKit/qt/tests/qwebpage/resources/index.html b/Source/WebKit/qt/tests/qwebpage/resources/index.html deleted file mode 100644 index 638df364e..000000000 --- a/Source/WebKit/qt/tests/qwebpage/resources/index.html +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/Source/WebKit/qt/tests/qwebpage/resources/script.html b/Source/WebKit/qt/tests/qwebpage/resources/script.html deleted file mode 100644 index ede986415..000000000 --- a/Source/WebKit/qt/tests/qwebpage/resources/script.html +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/Source/WebKit/qt/tests/qwebpage/resources/user.css b/Source/WebKit/qt/tests/qwebpage/resources/user.css deleted file mode 100644 index 4ccb2f0fc..000000000 --- a/Source/WebKit/qt/tests/qwebpage/resources/user.css +++ /dev/null @@ -1,3 +0,0 @@ -p { - background-image: url('http://does.not/exist.png'); -} \ No newline at end of file diff --git a/Source/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp b/Source/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp deleted file mode 100644 index db4c911e6..000000000 --- a/Source/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp +++ /dev/null @@ -1,3501 +0,0 @@ -/* - Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) - Copyright (C) 2009 Girish Ramakrishnan - Copyright (C) 2010 Holger Hans Peter Freyther - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "../util.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef HAVE_QTTESTSUPPORT -#include "../WebCoreSupport/DumpRenderTreeSupportQt.h" -#endif - -static void removeRecursive(const QString& dirname) -{ - QDir dir(dirname); - QFileInfoList entries(dir.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot)); - for (int i = 0; i < entries.count(); ++i) - if (entries[i].isDir()) - removeRecursive(entries[i].filePath()); - else - dir.remove(entries[i].fileName()); - QDir().rmdir(dirname); -} - -class TestInputContext : public QPlatformInputContext -{ -public: - TestInputContext() - : m_visible(false) - { - QInputMethodPrivate* inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod()); - inputMethodPrivate->testContext = this; - } - - ~TestInputContext() - { - QInputMethodPrivate* inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod()); - inputMethodPrivate->testContext = 0; - } - - virtual void showInputPanel() - { - m_visible = true; - } - virtual void hideInputPanel() - { - m_visible = false; - } - virtual bool isInputPanelVisible() const - { - return m_visible; - } - - bool m_visible; -}; - -class tst_QWebPage : public QObject -{ - Q_OBJECT - -public: - tst_QWebPage(); - virtual ~tst_QWebPage(); - -public Q_SLOTS: - void init(); - void cleanup(); - void cleanupFiles(); - -private Q_SLOTS: - void initTestCase(); - void cleanupTestCase(); - -#ifdef HAVE_QTTESTSUPPORT - void thirdPartyCookiePolicy(); -#endif - - void contextMenuCopy(); - void contextMenuPopulatedOnce(); - void acceptNavigationRequest(); - void domainSpecificKeyEvent(); - void geolocationRequestJS(); - void loadFinished(); - void actionStates(); - void popupFormSubmission(); - void acceptNavigationRequestWithNewWindow(); - void userStyleSheet(); - void userStyleSheetFromLocalFileUrl(); - void userStyleSheetFromQrcUrl(); - void loadHtml5Video(); - void modified(); - void contextMenuCrash(); - void updatePositionDependentActionsCrash(); - void database(); - void createPluginWithPluginsEnabled(); - void createPluginWithPluginsDisabled(); - void destroyPlugin_data(); - void destroyPlugin(); - void createViewlessPlugin_data(); - void createViewlessPlugin(); - void graphicsWidgetPlugin(); - -#ifdef HAVE_QTTESTSUPPORT - void multiplePageGroupsAndLocalStorage(); -#endif - - void cursorMovements(); - void textSelection(); - void textEditing(); - void backActionUpdate(); - void frameAt(); - void requestCache(); - void loadCachedPage(); - -#ifdef HAVE_QTTESTSUPPORT - void protectBindingsRuntimeObjectsFromCollector(); -#endif - - void localURLSchemes(); - void testOptionalJSObjects(); - void testLocalStorageVisibility(); - void testEnablePersistentStorage(); - void consoleOutput(); - void inputMethods_data(); - void inputMethods(); - void inputMethodsTextFormat_data(); - void inputMethodsTextFormat(); - void defaultTextEncoding(); - void errorPageExtension(); - void errorPageExtensionInIFrames(); - void errorPageExtensionInFrameset(); - void userAgentApplicationName(); - void userAgentNewlineStripping(); - void undoActionHaveCustomText(); - - void viewModes(); - - void crashTests_LazyInitializationOfMainFrame(); - - void screenshot_data(); - void screenshot(); - - void changeVisibilityState(); - -#if defined(ENABLE_WEBGL) && ENABLE_WEBGL - void acceleratedWebGLScreenshotWithoutView(); - void unacceleratedWebGLScreenshotWithoutView(); -#endif - - void originatingObjectInNetworkRequests(); - void networkReplyParentDidntChange(); - void destroyQNAMBeforeAbortDoesntCrash(); - void testJSPrompt(); - void showModalDialog(); - void testStopScheduledPageRefresh(); - void findText(); - void supportedContentType(); - // [Qt] tst_QWebPage::infiniteLoopJS() timeouts with DFG JIT - // https://bugs.webkit.org/show_bug.cgi?id=79040 - // void infiniteLoopJS(); - void navigatorCookieEnabled(); - void deleteQWebViewTwice(); - void renderOnRepaintRequestedShouldNotRecurse(); - void loadSignalsOrder_data(); - void loadSignalsOrder(); - void openWindowDefaultSize(); - void cssMediaTypeGlobalSetting(); - void cssMediaTypePageSetting(); - -#ifdef Q_OS_MACOS - void macCopyUnicodeToClipboard(); -#endif - -private: - QWebView* m_view { nullptr }; - QWebPage* m_page { nullptr }; - QString tmpDirPath() const - { - static QString tmpd = QDir::tempPath() + "/tst_qwebpage-" - + QDateTime::currentDateTime().toString(QLatin1String("yyyyMMddhhmmss")); - return tmpd; - } -}; - -tst_QWebPage::tst_QWebPage() -{ -} - -tst_QWebPage::~tst_QWebPage() -{ -} - -void tst_QWebPage::init() -{ - m_view = new QWebView(); - m_page = m_view->page(); -} - -void tst_QWebPage::cleanup() -{ - delete m_view; -} - -void tst_QWebPage::cleanupFiles() -{ - removeRecursive(tmpDirPath()); -} - -void tst_QWebPage::initTestCase() -{ - cleanupFiles(); // In case there are old files from previous runs -} - -void tst_QWebPage::cleanupTestCase() -{ - cleanupFiles(); // Be nice -} - -class NavigationRequestOverride : public QWebPage -{ -public: - NavigationRequestOverride(QWebView* parent, bool initialValue) : QWebPage(parent), m_acceptNavigationRequest(initialValue) {} - - bool m_acceptNavigationRequest; -protected: - virtual bool acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest &request, QWebPage::NavigationType type) { - Q_UNUSED(frame); - Q_UNUSED(request); - Q_UNUSED(type); - - return m_acceptNavigationRequest; - } -}; - -void tst_QWebPage::acceptNavigationRequest() -{ - QSignalSpy loadSpy(m_view, SIGNAL(loadFinished(bool))); - - NavigationRequestOverride* newPage = new NavigationRequestOverride(m_view, false); - m_view->setPage(newPage); - - m_view->setHtml(QString("
" - "
"), QUrl()); - QTRY_COMPARE(loadSpy.count(), 1); - - m_view->page()->mainFrame()->evaluateJavaScript("tstform.submit();"); - - newPage->m_acceptNavigationRequest = true; - m_view->page()->mainFrame()->evaluateJavaScript("tstform.submit();"); - QTRY_COMPARE(loadSpy.count(), 2); - - QCOMPARE(m_view->page()->mainFrame()->toPlainText(), QString("foo?")); - - // Restore default page - m_view->setPage(0); -} - -void tst_QWebPage::domainSpecificKeyEvent() -{ - QWebView webView; - webView.show(); - QTest::qWaitForWindowExposed(&webView); - - webView.setHtml(QLatin1String("" - "test")); - - // Enable settings to use nativeVirtualKey as DOM key value. - webView.page()->setProperty("_q_useNativeVirtualKeyAsDOMKey", true); - // Simulate domain specific keyevent to WebKit by passing it as nativeVirtualKey in QKeyEvent. - // Qt::Key_Pause --> 0x51 - QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Pause, Qt::NoModifier, 0, 81, 0); - QApplication::sendEvent(&webView, &keyEvent); - keyEvent = QKeyEvent(QEvent::KeyRelease, Qt::Key_Pause, Qt::NoModifier, 0, 81, 0); - QApplication::sendEvent(&webView, &keyEvent); - const QLatin1String expectedReceivedKeyArray1("keydown:81:0,keyup:81:0"); - QString receivedKeyArray = webView.page()->mainFrame()->evaluateJavaScript(QLatin1String("receivedKeyArray")).toStringList().join(","); - QVERIFY(receivedKeyArray == expectedReceivedKeyArray1); - - // Normal PC keyboard key converstion flow shouldn't be affected when sending nativeVirtual key as 0. - // Qt::Key_Pause --> VK_PAUSE(0x13) - webView.page()->mainFrame()->evaluateJavaScript(QLatin1String("receivedKeyArray = new Array()")); // Reset - keyEvent = QKeyEvent(QEvent::KeyPress, Qt::Key_Pause, Qt::NoModifier, 0, 0, 0); - QApplication::sendEvent(&webView, &keyEvent); - keyEvent = QKeyEvent(QEvent::KeyRelease, Qt::Key_Pause, Qt::NoModifier, 0, 0, 0); - QApplication::sendEvent(&webView, &keyEvent); - const QLatin1String expectedReceivedKeyArray2("keydown:19:0,keyup:19:0"); - receivedKeyArray = webView.page()->mainFrame()->evaluateJavaScript(QLatin1String("receivedKeyArray")).toStringList().join(","); - QVERIFY(receivedKeyArray == expectedReceivedKeyArray2); - - // Negative case. - // Disable settings to use nativeVirtualKey as DOM key value. - webView.page()->setProperty("_q_useNativeVirtualKeyAsDOMKey", false); - // Qt::Key_Pause --> VK_PAUSE(0x13) - webView.page()->mainFrame()->evaluateJavaScript(QLatin1String("receivedKeyArray = new Array()")); // Reset - keyEvent = QKeyEvent(QEvent::KeyPress, Qt::Key_Pause, Qt::NoModifier, 0, 81, 0); - QApplication::sendEvent(&webView, &keyEvent); - keyEvent = QKeyEvent(QEvent::KeyRelease, Qt::Key_Pause, Qt::NoModifier, 0, 81, 0); - QApplication::sendEvent(&webView, &keyEvent); - const QLatin1String expectedReceivedKeyArray3("keydown:19:0,keyup:19:0"); - receivedKeyArray = webView.page()->mainFrame()->evaluateJavaScript(QLatin1String("receivedKeyArray")).toStringList().join(","); - QVERIFY(receivedKeyArray == expectedReceivedKeyArray3); -} - -class JSTestPage : public QWebPage -{ -Q_OBJECT -public: - JSTestPage(QObject* parent = 0) - : QWebPage(parent) {} - - virtual bool shouldInterruptJavaScript() - { - return true; - } -public Q_SLOTS: - void requestPermission(QWebFrame* frame, QWebPage::Feature feature) - { - if (m_allowGeolocation) - setFeaturePermission(frame, feature, PermissionGrantedByUser); - else - setFeaturePermission(frame, feature, PermissionDeniedByUser); - } - -public: - void setGeolocationPermission(bool allow) - { - m_allowGeolocation = allow; - } - -private: - bool m_allowGeolocation { false }; -}; - -// [Qt] tst_QWebPage::infiniteLoopJS() timeouts with DFG JIT -// https://bugs.webkit.org/show_bug.cgi?id=79040 -/* -void tst_QWebPage::infiniteLoopJS() -{ - JSTestPage* newPage = new JSTestPage(m_view); - m_view->setPage(newPage); - m_view->setHtml(QString("test"), QUrl()); - m_view->page()->mainFrame()->evaluateJavaScript("var run = true;var a = 1;while(run){a++;}"); - delete newPage; -} -*/ - -void tst_QWebPage::geolocationRequestJS() -{ - JSTestPage* newPage = new JSTestPage(m_view); - - if (newPage->mainFrame()->evaluateJavaScript(QLatin1String("!navigator.geolocation")).toBool()) { - delete newPage; - W_QSKIP("Geolocation is not supported.", SkipSingle); - } - - connect(newPage, SIGNAL(featurePermissionRequested(QWebFrame*, QWebPage::Feature)), - newPage, SLOT(requestPermission(QWebFrame*, QWebPage::Feature))); - - newPage->setGeolocationPermission(false); - m_view->setPage(newPage); - m_view->setHtml(QString("test"), QUrl()); - m_view->page()->mainFrame()->evaluateJavaScript("var errorCode = 0; function error(err) { errorCode = err.code; } function success(pos) { } navigator.geolocation.getCurrentPosition(success, error)"); - QTest::qWait(2000); - QVariant empty = m_view->page()->mainFrame()->evaluateJavaScript("errorCode"); - - QEXPECT_FAIL("", "https://bugs.webkit.org/show_bug.cgi?id=102235", Continue); - QVERIFY(empty.type() == QVariant::Double && empty.toInt() != 0); - - newPage->setGeolocationPermission(true); - m_view->page()->mainFrame()->evaluateJavaScript("errorCode = 0; navigator.geolocation.getCurrentPosition(success, error);"); - empty = m_view->page()->mainFrame()->evaluateJavaScript("errorCode"); - - //http://dev.w3.org/geo/api/spec-source.html#position - //PositionError: const unsigned short PERMISSION_DENIED = 1; - QVERIFY(empty.type() == QVariant::Double && empty.toInt() != 1); - delete newPage; -} - -void tst_QWebPage::loadFinished() -{ - qRegisterMetaType("QWebFrame*"); - qRegisterMetaType("QNetworkRequest*"); - QSignalSpy spyLoadStarted(m_view, SIGNAL(loadStarted())); - QSignalSpy spyLoadFinished(m_view, SIGNAL(loadFinished(bool))); - - m_view->page()->mainFrame()->load(QUrl("data:text/html,foo \">" - "")); - QTRY_COMPARE(spyLoadFinished.count(), 1); - - QTRY_VERIFY(spyLoadStarted.count() > 1); - QTRY_VERIFY(spyLoadFinished.count() > 1); - - spyLoadFinished.clear(); - - m_view->page()->mainFrame()->load(QUrl("data:text/html,")); - QTRY_COMPARE(spyLoadFinished.count(), 1); - QCOMPARE(spyLoadFinished.count(), 1); -} - -void tst_QWebPage::actionStates() -{ - QWebPage* page = m_view->page(); - - page->mainFrame()->load(QUrl("qrc:///resources/script.html")); - - QAction* reloadAction = page->action(QWebPage::Reload); - QAction* stopAction = page->action(QWebPage::Stop); - - QTRY_VERIFY(reloadAction->isEnabled()); - QTRY_VERIFY(!stopAction->isEnabled()); -} - -class ConsolePage : public QWebPage -{ -public: - ConsolePage(QObject* parent = 0) : QWebPage(parent) {} - - virtual void javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID) - { - messages.append(message); - lineNumbers.append(lineNumber); - sourceIDs.append(sourceID); - } - - QStringList messages; - QList lineNumbers; - QStringList sourceIDs; -}; - -void tst_QWebPage::consoleOutput() -{ - ConsolePage page; - page.mainFrame()->evaluateJavaScript("this is not valid JavaScript"); - QCOMPARE(page.messages.count(), 1); - QCOMPARE(page.lineNumbers.at(0), 1); -} - -class TestPage : public QWebPage { - Q_OBJECT -public: - TestPage(QObject* parent = 0) : QWebPage(parent) - { - connect(this, SIGNAL(geometryChangeRequested(QRect)), this, SLOT(slotGeometryChangeRequested(QRect))); - } - - struct Navigation { - QPointer frame; - QNetworkRequest request; - NavigationType type; - }; - - QList navigations; - QList createdWindows; - QRect requestedGeometry; - - virtual bool acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest &request, NavigationType type) { - Navigation n; - n.frame = frame; - n.request = request; - n.type = type; - navigations.append(n); - return true; - } - - virtual QWebPage* createWindow(WebWindowType) { - TestPage* page = new TestPage(this); - createdWindows.append(page); - return page; - } - -private Q_SLOTS: - void slotGeometryChangeRequested(const QRect& geom) { - requestedGeometry = geom; - } -}; - -void tst_QWebPage::popupFormSubmission() -{ - TestPage page; - page.settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true); - page.mainFrame()->setHtml("
"\ - ""\ - "
"); - page.mainFrame()->evaluateJavaScript("window.open('', 'myNewWin', 'width=500,height=300,toolbar=0')"); - page.mainFrame()->evaluateJavaScript("document.form1.submit();"); - - QTest::qWait(500); - // The number of popup created should be one. - QVERIFY(page.createdWindows.size() == 1); - - QString url = page.createdWindows.takeFirst()->mainFrame()->url().toString(); - // Check if the form submission was OK. - QEXPECT_FAIL("", "https://bugs.webkit.org/show_bug.cgi?id=118597", Continue); - QVERIFY(url.contains("?foo=bar")); -} - -void tst_QWebPage::acceptNavigationRequestWithNewWindow() -{ - TestPage* page = new TestPage(m_view); - page->settings()->setAttribute(QWebSettings::LinksIncludedInFocusChain, true); - m_page = page; - m_view->setPage(m_page); - - m_view->setUrl(QString("data:text/html,Click me")); - QVERIFY(::waitForSignal(m_view, SIGNAL(loadFinished(bool)))); - - QFocusEvent fe(QEvent::FocusIn); - m_page->event(&fe); - - QVERIFY(m_page->focusNextPrevChild(/*next*/ true)); - - QKeyEvent keyEnter(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier); - m_page->event(&keyEnter); - - QCOMPARE(page->navigations.count(), 2); - - TestPage::Navigation n = page->navigations.at(1); - QVERIFY(n.frame.isNull()); - QCOMPARE(n.request.url().toString(), QString("data:text/html,Reached")); - QVERIFY(n.type == QWebPage::NavigationTypeLinkClicked); - - QCOMPARE(page->createdWindows.count(), 1); -} - -class TestNetworkManager : public QNetworkAccessManager -{ -public: - TestNetworkManager(QObject* parent) : QNetworkAccessManager(parent) {} - - QList requestedUrls; - QList requests; - -protected: - virtual QNetworkReply* createRequest(Operation op, const QNetworkRequest &request, QIODevice* outgoingData) { - requests.append(request); - requestedUrls.append(request.url()); - return QNetworkAccessManager::createRequest(op, request, outgoingData); - } -}; - -void tst_QWebPage::userStyleSheet() -{ - TestNetworkManager* networkManager = new TestNetworkManager(m_page); - m_page->setNetworkAccessManager(networkManager); - - m_page->settings()->setUserStyleSheetUrl(QUrl(QString::fromLatin1("data:text/css;charset=utf-8;base64," - + QByteArray("p { background-image: url('http://does.not/exist.png');}").toBase64()))); - m_view->setHtml("

hello world

"); - QVERIFY(::waitForSignal(m_view, SIGNAL(loadFinished(bool)))); - - QVERIFY(networkManager->requestedUrls.count() >= 1); - QCOMPARE(networkManager->requestedUrls.at(0), QUrl("http://does.not/exist.png")); -} - -void tst_QWebPage::userStyleSheetFromLocalFileUrl() -{ - TestNetworkManager* networkManager = new TestNetworkManager(m_page); - m_page->setNetworkAccessManager(networkManager); - - QUrl styleSheetUrl = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebpage/resources/user.css")); - m_page->settings()->setUserStyleSheetUrl(styleSheetUrl); - m_view->setHtml("

hello world

"); - QVERIFY(::waitForSignal(m_view, SIGNAL(loadFinished(bool)))); - - QVERIFY(networkManager->requestedUrls.count() >= 1); - QCOMPARE(networkManager->requestedUrls.at(0), QUrl("http://does.not/exist.png")); -} - -void tst_QWebPage::userStyleSheetFromQrcUrl() -{ - TestNetworkManager* networkManager = new TestNetworkManager(m_page); - m_page->setNetworkAccessManager(networkManager); - - m_page->settings()->setUserStyleSheetUrl(QUrl("qrc:///resources/user.css")); - m_view->setHtml("

hello world

"); - QVERIFY(::waitForSignal(m_view, SIGNAL(loadFinished(bool)))); - - QVERIFY(networkManager->requestedUrls.count() >= 1); - QCOMPARE(networkManager->requestedUrls.at(0), QUrl("http://does.not/exist.png")); -} - -void tst_QWebPage::loadHtml5Video() -{ -#if defined(USE_QT_MULTIMEDIA) && USE_QT_MULTIMEDIA - QByteArray url("http://does.not/exist?a=1%2Cb=2"); - m_view->setHtml("

"); - QTest::qWait(2000); - QUrl mUrl = DumpRenderTreeSupportQt::mediaContentUrlByElementId(m_page->mainFrame()->handle(), "video"); - QEXPECT_FAIL("", "https://bugs.webkit.org/show_bug.cgi?id=65452", Continue); - QCOMPARE(mUrl.toEncoded(), url); -#else - W_QSKIP("This test requires Qt Multimedia", SkipAll); -#endif -} - -void tst_QWebPage::viewModes() -{ - m_view->setHtml(""); - m_page->setProperty("_q_viewMode", "minimized"); - - QVariant empty = m_page->mainFrame()->evaluateJavaScript("window.styleMedia.matchMedium(\"(-webkit-view-mode)\")"); - QVERIFY(empty.type() == QVariant::Bool && empty.toBool()); - - QVariant minimized = m_page->mainFrame()->evaluateJavaScript("window.styleMedia.matchMedium(\"(-webkit-view-mode: minimized)\")"); - QVERIFY(minimized.type() == QVariant::Bool && minimized.toBool()); - - QVariant maximized = m_page->mainFrame()->evaluateJavaScript("window.styleMedia.matchMedium(\"(-webkit-view-mode: maximized)\")"); - QVERIFY(maximized.type() == QVariant::Bool && !maximized.toBool()); -} - -void tst_QWebPage::modified() -{ - m_page->mainFrame()->setUrl(QUrl("data:text/html,blub")); - QVERIFY(::waitForSignal(m_view, SIGNAL(loadFinished(bool)))); - - m_page->mainFrame()->setUrl(QUrl("data:text/html,blah")); - QVERIFY(::waitForSignal(m_view, SIGNAL(loadFinished(bool)))); - - QVERIFY(!m_page->isModified()); - -// m_page->mainFrame()->evaluateJavaScript("alert(document.getElementById('foo'))"); - m_page->mainFrame()->evaluateJavaScript("document.getElementById('foo').focus()"); - m_page->mainFrame()->evaluateJavaScript("document.execCommand('InsertText', true, 'Test');"); - - QVERIFY(m_page->isModified()); - - m_page->mainFrame()->evaluateJavaScript("document.execCommand('Undo', true);"); - - QVERIFY(!m_page->isModified()); - - m_page->mainFrame()->evaluateJavaScript("document.execCommand('Redo', true);"); - - QVERIFY(m_page->isModified()); - - QVERIFY(m_page->history()->canGoBack()); - QVERIFY(!m_page->history()->canGoForward()); - QCOMPARE(m_page->history()->count(), 2); - QVERIFY(m_page->history()->backItem().isValid()); - QVERIFY(!m_page->history()->forwardItem().isValid()); - - m_page->history()->back(); - QVERIFY(::waitForSignal(m_view, SIGNAL(loadFinished(bool)))); - - QVERIFY(!m_page->history()->canGoBack()); - QVERIFY(m_page->history()->canGoForward()); - - QVERIFY(!m_page->isModified()); - - QVERIFY(m_page->history()->currentItemIndex() == 0); - - m_page->history()->setMaximumItemCount(3); - QVERIFY(m_page->history()->maximumItemCount() == 3); - - QVariant variant("string test"); - m_page->history()->currentItem().setUserData(variant); - QVERIFY(m_page->history()->currentItem().userData().toString() == "string test"); - - m_page->mainFrame()->setUrl(QUrl("data:text/html,This is second page")); - m_page->mainFrame()->setUrl(QUrl("data:text/html,This is third page")); - QVERIFY(m_page->history()->count() == 2); - m_page->mainFrame()->setUrl(QUrl("data:text/html,This is fourth page")); - QVERIFY(m_page->history()->count() == 2); - m_page->mainFrame()->setUrl(QUrl("data:text/html,This is fifth page")); - QVERIFY(::waitForSignal(m_page, SIGNAL(saveFrameStateRequested(QWebFrame*,QWebHistoryItem*)))); -} - -// https://bugs.webkit.org/show_bug.cgi?id=51331 -void tst_QWebPage::updatePositionDependentActionsCrash() -{ - QWebView view; - view.setHtml("

test"); - QPoint pos(0, 0); - view.page()->updatePositionDependentActions(pos); - QMenu* contextMenu = 0; - foreach (QObject* child, view.children()) { - contextMenu = qobject_cast(child); - if (contextMenu) - break; - } - QVERIFY(!contextMenu); -} - -// https://bugs.webkit.org/show_bug.cgi?id=20357 -void tst_QWebPage::contextMenuCrash() -{ - QWebView view; - view.setHtml("

test"); - QPoint pos(0, 0); - QContextMenuEvent event(QContextMenuEvent::Mouse, pos); - view.page()->swallowContextMenuEvent(&event); - view.page()->updatePositionDependentActions(pos); - QMenu* contextMenu = 0; - foreach (QObject* child, view.children()) { - contextMenu = qobject_cast(child); - if (contextMenu) - break; - } - QVERIFY(contextMenu); - delete contextMenu; -} - -void tst_QWebPage::database() -{ - QString path = tmpDirPath(); - m_page->settings()->setOfflineStoragePath(path); - QVERIFY(m_page->settings()->offlineStoragePath() == path); - - QWebSettings::setOfflineStorageDefaultQuota(1024 * 1024); - QVERIFY(QWebSettings::offlineStorageDefaultQuota() == 1024 * 1024); - - m_page->settings()->setAttribute(QWebSettings::LocalStorageEnabled, true); - m_page->settings()->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true); - - QString dbFileName = path + "Databases.db"; - - if (QFile::exists(dbFileName)) - QFile::remove(dbFileName); - - qRegisterMetaType("QWebFrame*"); - QSignalSpy spy(m_page, SIGNAL(databaseQuotaExceeded(QWebFrame*,QString))); - m_view->setHtml(QString("

"), QUrl("http://www.myexample.com")); - QTRY_COMPARE(spy.count(), 1); - m_page->mainFrame()->evaluateJavaScript("var db2; db2=openDatabase('testdb', '1.0', 'test database API', 50000);"); - QTRY_COMPARE(spy.count(),1); - - m_page->mainFrame()->evaluateJavaScript("localStorage.test='This is a test for local storage';"); - m_view->setHtml(QString("text"), QUrl("http://www.myexample.com")); - - QVariant s1 = m_page->mainFrame()->evaluateJavaScript("localStorage.test"); - QCOMPARE(s1.toString(), QString("This is a test for local storage")); - - m_page->mainFrame()->evaluateJavaScript("sessionStorage.test='This is a test for session storage';"); - m_view->setHtml(QString("text"), QUrl("http://www.myexample.com")); - QVariant s2 = m_page->mainFrame()->evaluateJavaScript("sessionStorage.test"); - QCOMPARE(s2.toString(), QString("This is a test for session storage")); - - m_view->setHtml(QString("
"), QUrl("http://www.myexample.com")); - m_page->mainFrame()->evaluateJavaScript("var db3; db3=openDatabase('testdb', '1.0', 'test database API', 50000);db3.transaction(function(tx) { tx.executeSql('CREATE TABLE IF NOT EXISTS Test (text TEXT)', []); }, function(tx, result) { }, function(tx, error) { });"); - QTest::qWait(200); - - // Remove all databases. - QWebSecurityOrigin origin = m_page->mainFrame()->securityOrigin(); - QList dbs = origin.databases(); - for (int i = 0; i < dbs.count(); i++) { - QString fileName = dbs[i].fileName(); - QVERIFY(QFile::exists(fileName)); - QWebDatabase::removeDatabase(dbs[i]); - QVERIFY(!QFile::exists(fileName)); - } - QVERIFY(!origin.databases().size()); - // Remove removed test :-) - QWebDatabase::removeAllDatabases(); - QVERIFY(!origin.databases().size()); -} - -class PluginPage : public QWebPage -{ -public: - PluginPage(QObject *parent = 0) - : QWebPage(parent) {} - - struct CallInfo - { - CallInfo(const QString &c, const QUrl &u, - const QStringList &pn, const QStringList &pv, - QObject *r) - : classid(c), url(u), paramNames(pn), - paramValues(pv), returnValue(r) - {} - QString classid; - QUrl url; - QStringList paramNames; - QStringList paramValues; - QObject *returnValue; - }; - - QList calls; - -protected: - virtual QObject *createPlugin(const QString &classid, const QUrl &url, - const QStringList ¶mNames, - const QStringList ¶mValues) - { - QObject *result = 0; - if (classid == "pushbutton") - result = new QPushButton(); -#ifndef QT_NO_INPUTDIALOG - else if (classid == "lineedit") - result = new QLineEdit(); -#endif - else if (classid == "graphicswidget") - result = new QGraphicsWidget(); - if (result) - result->setObjectName(classid); - calls.append(CallInfo(classid, url, paramNames, paramValues, result)); - return result; - } -}; - -static void createPlugin(QWebView *view) -{ - QSignalSpy loadSpy(view, SIGNAL(loadFinished(bool))); - - PluginPage* newPage = new PluginPage(view); - view->setPage(newPage); - - // type has to be application/x-qt-plugin - view->setHtml(QString("")); - QTRY_COMPARE(loadSpy.count(), 1); - QCOMPARE(newPage->calls.count(), 0); - - view->setHtml(QString("")); - QTRY_COMPARE(loadSpy.count(), 2); - QCOMPARE(newPage->calls.count(), 1); - { - PluginPage::CallInfo ci = newPage->calls.takeFirst(); - QCOMPARE(ci.classid, QString::fromLatin1("pushbutton")); - QCOMPARE(ci.url, QUrl()); - QCOMPARE(ci.paramNames.count(), 3); - QCOMPARE(ci.paramValues.count(), 3); - QCOMPARE(ci.paramNames.at(0), QString::fromLatin1("type")); - QCOMPARE(ci.paramValues.at(0), QString::fromLatin1("application/x-qt-plugin")); - QCOMPARE(ci.paramNames.at(1), QString::fromLatin1("classid")); - QCOMPARE(ci.paramValues.at(1), QString::fromLatin1("pushbutton")); - QCOMPARE(ci.paramNames.at(2), QString::fromLatin1("id")); - QCOMPARE(ci.paramValues.at(2), QString::fromLatin1("mybutton")); - QVERIFY(ci.returnValue != 0); - QVERIFY(ci.returnValue->inherits("QPushButton")); - } - // test JS bindings - QCOMPARE(newPage->mainFrame()->evaluateJavaScript("document.getElementById('mybutton').toString()").toString(), - QString::fromLatin1("[object HTMLObjectElement]")); - QCOMPARE(newPage->mainFrame()->evaluateJavaScript("mybutton.toString()").toString(), - QString::fromLatin1("[object HTMLObjectElement]")); - QCOMPARE(newPage->mainFrame()->evaluateJavaScript("typeof mybutton.objectName").toString(), - QString::fromLatin1("string")); - QCOMPARE(newPage->mainFrame()->evaluateJavaScript("mybutton.objectName").toString(), - QString::fromLatin1("pushbutton")); - QCOMPARE(newPage->mainFrame()->evaluateJavaScript("typeof mybutton.clicked").toString(), - QString::fromLatin1("function")); - QCOMPARE(newPage->mainFrame()->evaluateJavaScript("mybutton.clicked.toString()").toString(), - QString::fromLatin1("function clicked() {\n [native code]\n}")); - - view->setHtml(QString("" - "" - "" - "
"), QUrl("http://foo.bar.baz")); - QTRY_COMPARE(loadSpy.count(), 3); - QCOMPARE(newPage->calls.count(), 2); - { - PluginPage::CallInfo ci = newPage->calls.takeFirst(); - QCOMPARE(ci.classid, QString::fromLatin1("lineedit")); - QCOMPARE(ci.url, QUrl()); - QCOMPARE(ci.paramNames.count(), 3); - QCOMPARE(ci.paramValues.count(), 3); - QCOMPARE(ci.paramNames.at(0), QString::fromLatin1("type")); - QCOMPARE(ci.paramValues.at(0), QString::fromLatin1("application/x-qt-plugin")); - QCOMPARE(ci.paramNames.at(1), QString::fromLatin1("classid")); - QCOMPARE(ci.paramValues.at(1), QString::fromLatin1("lineedit")); - QCOMPARE(ci.paramNames.at(2), QString::fromLatin1("id")); - QCOMPARE(ci.paramValues.at(2), QString::fromLatin1("myedit")); - QVERIFY(ci.returnValue != 0); - QVERIFY(ci.returnValue->inherits("QLineEdit")); - } - { - PluginPage::CallInfo ci = newPage->calls.takeFirst(); - QCOMPARE(ci.classid, QString::fromLatin1("pushbutton")); - QCOMPARE(ci.url, QUrl()); - QCOMPARE(ci.paramNames.count(), 3); - QCOMPARE(ci.paramValues.count(), 3); - QCOMPARE(ci.paramNames.at(0), QString::fromLatin1("type")); - QCOMPARE(ci.paramValues.at(0), QString::fromLatin1("application/x-qt-plugin")); - QCOMPARE(ci.paramNames.at(1), QString::fromLatin1("classid")); - QCOMPARE(ci.paramValues.at(1), QString::fromLatin1("pushbutton")); - QCOMPARE(ci.paramNames.at(2), QString::fromLatin1("id")); - QCOMPARE(ci.paramValues.at(2), QString::fromLatin1("mybutton")); - QVERIFY(ci.returnValue != 0); - QVERIFY(ci.returnValue->inherits("QPushButton")); - } -} - -void tst_QWebPage::graphicsWidgetPlugin() -{ - m_view->settings()->setAttribute(QWebSettings::PluginsEnabled, true); - QGraphicsWebView webView; - - QSignalSpy loadSpy(&webView, SIGNAL(loadFinished(bool))); - - PluginPage* newPage = new PluginPage(&webView); - webView.setPage(newPage); - - // type has to be application/x-qt-plugin - webView.setHtml(QString("")); - QTRY_COMPARE(loadSpy.count(), 1); - QCOMPARE(newPage->calls.count(), 0); - - webView.setHtml(QString("")); - QTRY_COMPARE(loadSpy.count(), 2); - QCOMPARE(newPage->calls.count(), 1); - { - PluginPage::CallInfo ci = newPage->calls.takeFirst(); - QCOMPARE(ci.classid, QString::fromLatin1("graphicswidget")); - QCOMPARE(ci.url, QUrl()); - QCOMPARE(ci.paramNames.count(), 3); - QCOMPARE(ci.paramValues.count(), 3); - QCOMPARE(ci.paramNames.at(0), QString::fromLatin1("type")); - QCOMPARE(ci.paramValues.at(0), QString::fromLatin1("application/x-qt-plugin")); - QCOMPARE(ci.paramNames.at(1), QString::fromLatin1("classid")); - QCOMPARE(ci.paramValues.at(1), QString::fromLatin1("graphicswidget")); - QCOMPARE(ci.paramNames.at(2), QString::fromLatin1("id")); - QCOMPARE(ci.paramValues.at(2), QString::fromLatin1("mygraphicswidget")); - QVERIFY(ci.returnValue); - QVERIFY(ci.returnValue->inherits("QGraphicsWidget")); - } - // test JS bindings - QCOMPARE(newPage->mainFrame()->evaluateJavaScript("document.getElementById('mygraphicswidget').toString()").toString(), - QString::fromLatin1("[object HTMLObjectElement]")); - QCOMPARE(newPage->mainFrame()->evaluateJavaScript("mygraphicswidget.toString()").toString(), - QString::fromLatin1("[object HTMLObjectElement]")); - QCOMPARE(newPage->mainFrame()->evaluateJavaScript("typeof mygraphicswidget.objectName").toString(), - QString::fromLatin1("string")); - QCOMPARE(newPage->mainFrame()->evaluateJavaScript("mygraphicswidget.objectName").toString(), - QString::fromLatin1("graphicswidget")); - QCOMPARE(newPage->mainFrame()->evaluateJavaScript("typeof mygraphicswidget.geometryChanged").toString(), - QString::fromLatin1("function")); - QCOMPARE(newPage->mainFrame()->evaluateJavaScript("mygraphicswidget.geometryChanged.toString()").toString(), - QString::fromLatin1("function geometryChanged() {\n [native code]\n}")); -} - -void tst_QWebPage::createPluginWithPluginsEnabled() -{ - m_view->settings()->setAttribute(QWebSettings::PluginsEnabled, true); - createPlugin(m_view); -} - -void tst_QWebPage::createPluginWithPluginsDisabled() -{ - // Qt Plugins should be loaded by QtWebKit even when PluginsEnabled is - // false. The client decides whether a Qt plugin is enabled or not when - // it decides whether or not to instantiate it. - m_view->settings()->setAttribute(QWebSettings::PluginsEnabled, false); - createPlugin(m_view); -} - -// Standard base class for template PluginTracerPage. In tests it is used as interface. -class PluginCounterPage : public QWebPage { -public: - int m_count; - QPointer m_widget; - QObject* m_pluginParent; - PluginCounterPage(QObject* parent = 0) - : QWebPage(parent) - , m_count(0) - , m_pluginParent(0) - { - settings()->setAttribute(QWebSettings::PluginsEnabled, true); - } - ~PluginCounterPage() - { - if (m_pluginParent) - m_pluginParent->deleteLater(); - } -}; - -template -class PluginTracerPage : public PluginCounterPage { -public: - PluginTracerPage(QObject* parent = 0) - : PluginCounterPage(parent) - { - // this is a dummy parent object for the created plugin - m_pluginParent = new T; - } - virtual QObject* createPlugin(const QString&, const QUrl&, const QStringList&, const QStringList&) - { - m_count++; - m_widget = new T; - // need a cast to the specific type, as QObject::setParent cannot be called, - // because it is not virtual. Instead it is necesary to call QWidget::setParent, - // which also takes a QWidget* instead of a QObject*. Therefore we need to - // upcast to T*, which is a QWidget. - static_cast(m_widget.data())->setParent(static_cast(m_pluginParent)); - return m_widget.data(); - } -}; - -class PluginFactory { -public: - enum FactoredType {QWidgetType, QGraphicsWidgetType}; - static PluginCounterPage* create(FactoredType type, QObject* parent = 0) - { - PluginCounterPage* result = 0; - switch (type) { - case QWidgetType: - result = new PluginTracerPage(parent); - break; - case QGraphicsWidgetType: - result = new PluginTracerPage(parent); - break; - default: {/*Oops*/}; - } - return result; - } - - static void prepareTestData() - { - QTest::addColumn("type"); - QTest::newRow("QWidget") << (int)PluginFactory::QWidgetType; - QTest::newRow("QGraphicsWidget") << (int)PluginFactory::QGraphicsWidgetType; - } -}; - -void tst_QWebPage::destroyPlugin_data() -{ - PluginFactory::prepareTestData(); -} - -void tst_QWebPage::destroyPlugin() -{ - QFETCH(int, type); - PluginCounterPage* page = PluginFactory::create((PluginFactory::FactoredType)type, m_view); - m_view->setPage(page); - - // we create the plugin, so the widget should be constructed - QString content(""); - m_view->setHtml(content); - QVERIFY(page->m_widget); - QCOMPARE(page->m_count, 1); - - // navigate away, the plugin widget should be destructed - m_view->setHtml("Hi"); - QTestEventLoop::instance().enterLoop(1); - QVERIFY(!page->m_widget); -} - -void tst_QWebPage::createViewlessPlugin_data() -{ - PluginFactory::prepareTestData(); -} - -void tst_QWebPage::createViewlessPlugin() -{ - QFETCH(int, type); - PluginCounterPage* page = PluginFactory::create((PluginFactory::FactoredType)type); - QString content(""); - page->mainFrame()->setHtml(content); - QCOMPARE(page->m_count, 1); - QVERIFY(page->m_widget); - QVERIFY(page->m_pluginParent); - QVERIFY(page->m_widget.data()->parent() == page->m_pluginParent); - delete page; - -} - -#ifdef HAVE_QTTESTSUPPORT -void tst_QWebPage::multiplePageGroupsAndLocalStorage() -{ - QDir dir(tmpDirPath()); - dir.mkdir("path1"); - dir.mkdir("path2"); - - QWebView view1; - QWebView view2; - - view1.page()->settings()->setAttribute(QWebSettings::LocalStorageEnabled, true); - view1.page()->settings()->setLocalStoragePath(QDir::toNativeSeparators(tmpDirPath() + "/path1")); - DumpRenderTreeSupportQt::webPageSetGroupName(view1.page()->handle(), "group1"); - view2.page()->settings()->setAttribute(QWebSettings::LocalStorageEnabled, true); - view2.page()->settings()->setLocalStoragePath(QDir::toNativeSeparators(tmpDirPath() + "/path2")); - DumpRenderTreeSupportQt::webPageSetGroupName(view2.page()->handle(), "group2"); - QCOMPARE(DumpRenderTreeSupportQt::webPageGroupName(view1.page()->handle()), QString("group1")); - QCOMPARE(DumpRenderTreeSupportQt::webPageGroupName(view2.page()->handle()), QString("group2")); - - - view1.setHtml(QString(" "), QUrl("http://www.myexample.com")); - view2.setHtml(QString(" "), QUrl("http://www.myexample.com")); - - view1.page()->mainFrame()->evaluateJavaScript("localStorage.test='value1';"); - view2.page()->mainFrame()->evaluateJavaScript("localStorage.test='value2';"); - - view1.setHtml(QString(" "), QUrl("http://www.myexample.com")); - view2.setHtml(QString(" "), QUrl("http://www.myexample.com")); - - QVariant s1 = view1.page()->mainFrame()->evaluateJavaScript("localStorage.test"); - QCOMPARE(s1.toString(), QString("value1")); - - QVariant s2 = view2.page()->mainFrame()->evaluateJavaScript("localStorage.test"); - QCOMPARE(s2.toString(), QString("value2")); - - QTest::qWait(1000); - - QFile::remove(QDir::toNativeSeparators(tmpDirPath() + "/path1/http_www.myexample.com_0.localstorage")); - QFile::remove(QDir::toNativeSeparators(tmpDirPath() + "/path2/http_www.myexample.com_0.localstorage")); - dir.rmdir(QDir::toNativeSeparators("./path1")); - dir.rmdir(QDir::toNativeSeparators("./path2")); -} -#endif - -class CursorTrackedPage : public QWebPage -{ -public: - - CursorTrackedPage(QWidget *parent = 0): QWebPage(parent) { - setViewportSize(QSize(1024, 768)); // big space - } - - QString selectedText() { - return mainFrame()->evaluateJavaScript("window.getSelection().toString()").toString(); - } - - int selectionStartOffset() { - return mainFrame()->evaluateJavaScript("window.getSelection().getRangeAt(0).startOffset").toInt(); - } - - int selectionEndOffset() { - return mainFrame()->evaluateJavaScript("window.getSelection().getRangeAt(0).endOffset").toInt(); - } - - // true if start offset == end offset, i.e. no selected text - int isSelectionCollapsed() { - return mainFrame()->evaluateJavaScript("window.getSelection().getRangeAt(0).collapsed").toBool(); - } -}; - -void tst_QWebPage::cursorMovements() -{ - CursorTrackedPage* page = new CursorTrackedPage; - QString content("

The quick brown fox

jumps over the lazy dog

May the source
be with you!

"); - page->mainFrame()->setHtml(content); - - // this will select the first paragraph - QString script = "var range = document.createRange(); " \ - "var node = document.getElementById(\"one\"); " \ - "range.selectNode(node); " \ - "getSelection().addRange(range);"; - page->mainFrame()->evaluateJavaScript(script); - QCOMPARE(page->selectedText().trimmed(), QString::fromLatin1("The quick brown fox")); - - QRegExp regExp(" style=\".*\""); - regExp.setMinimal(true); - QCOMPARE(page->selectedHtml().trimmed().replace(regExp, ""), QString::fromLatin1("

The quick brown fox

")); - - // these actions must exist - QVERIFY(page->action(QWebPage::MoveToNextChar) != 0); - QVERIFY(page->action(QWebPage::MoveToPreviousChar) != 0); - QVERIFY(page->action(QWebPage::MoveToNextWord) != 0); - QVERIFY(page->action(QWebPage::MoveToPreviousWord) != 0); - QVERIFY(page->action(QWebPage::MoveToNextLine) != 0); - QVERIFY(page->action(QWebPage::MoveToPreviousLine) != 0); - QVERIFY(page->action(QWebPage::MoveToStartOfLine) != 0); - QVERIFY(page->action(QWebPage::MoveToEndOfLine) != 0); - QVERIFY(page->action(QWebPage::MoveToStartOfBlock) != 0); - QVERIFY(page->action(QWebPage::MoveToEndOfBlock) != 0); - QVERIFY(page->action(QWebPage::MoveToStartOfDocument) != 0); - QVERIFY(page->action(QWebPage::MoveToEndOfDocument) != 0); - - // right now they are disabled because contentEditable is false - QCOMPARE(page->action(QWebPage::MoveToNextChar)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::MoveToPreviousChar)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::MoveToNextWord)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::MoveToPreviousWord)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::MoveToNextLine)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::MoveToPreviousLine)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::MoveToStartOfLine)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::MoveToEndOfLine)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::MoveToStartOfBlock)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::MoveToEndOfBlock)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::MoveToStartOfDocument)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::MoveToEndOfDocument)->isEnabled(), false); - - // make it editable before navigating the cursor - page->setContentEditable(true); - - // here the actions are enabled after contentEditable is true - QCOMPARE(page->action(QWebPage::MoveToNextChar)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::MoveToPreviousChar)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::MoveToNextWord)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::MoveToPreviousWord)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::MoveToNextLine)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::MoveToPreviousLine)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::MoveToStartOfLine)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::MoveToEndOfLine)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::MoveToStartOfBlock)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::MoveToEndOfBlock)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::MoveToStartOfDocument)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::MoveToEndOfDocument)->isEnabled(), true); - - // cursor will be before the word "jump" - page->triggerAction(QWebPage::MoveToNextChar); - QVERIFY(page->isSelectionCollapsed()); - QCOMPARE(page->selectionStartOffset(), 0); - - // cursor will be between 'j' and 'u' in the word "jump" - page->triggerAction(QWebPage::MoveToNextChar); - QVERIFY(page->isSelectionCollapsed()); - QCOMPARE(page->selectionStartOffset(), 1); - - // cursor will be between 'u' and 'm' in the word "jump" - page->triggerAction(QWebPage::MoveToNextChar); - QVERIFY(page->isSelectionCollapsed()); - QCOMPARE(page->selectionStartOffset(), 2); - - // cursor will be after the word "jump" - page->triggerAction(QWebPage::MoveToNextWord); - QVERIFY(page->isSelectionCollapsed()); - QCOMPARE(page->selectionStartOffset(), 5); - - // cursor will be after the word "lazy" - page->triggerAction(QWebPage::MoveToNextWord); - page->triggerAction(QWebPage::MoveToNextWord); - page->triggerAction(QWebPage::MoveToNextWord); - QVERIFY(page->isSelectionCollapsed()); - QCOMPARE(page->selectionStartOffset(), 19); - - // cursor will be between 'z' and 'y' in "lazy" - page->triggerAction(QWebPage::MoveToPreviousChar); - QVERIFY(page->isSelectionCollapsed()); - QCOMPARE(page->selectionStartOffset(), 18); - - // cursor will be between 'a' and 'z' in "lazy" - page->triggerAction(QWebPage::MoveToPreviousChar); - QVERIFY(page->isSelectionCollapsed()); - QCOMPARE(page->selectionStartOffset(), 17); - - // cursor will be before the word "lazy" - page->triggerAction(QWebPage::MoveToPreviousWord); - QVERIFY(page->isSelectionCollapsed()); - QCOMPARE(page->selectionStartOffset(), 15); - - // cursor will be before the word "quick" - page->triggerAction(QWebPage::MoveToPreviousWord); - page->triggerAction(QWebPage::MoveToPreviousWord); - page->triggerAction(QWebPage::MoveToPreviousWord); - page->triggerAction(QWebPage::MoveToPreviousWord); - page->triggerAction(QWebPage::MoveToPreviousWord); - page->triggerAction(QWebPage::MoveToPreviousWord); - QVERIFY(page->isSelectionCollapsed()); - QCOMPARE(page->selectionStartOffset(), 4); - - // cursor will be between 'p' and 's' in the word "jumps" - page->triggerAction(QWebPage::MoveToNextWord); - page->triggerAction(QWebPage::MoveToNextWord); - page->triggerAction(QWebPage::MoveToNextWord); - page->triggerAction(QWebPage::MoveToNextChar); - page->triggerAction(QWebPage::MoveToNextChar); - page->triggerAction(QWebPage::MoveToNextChar); - page->triggerAction(QWebPage::MoveToNextChar); - page->triggerAction(QWebPage::MoveToNextChar); - QVERIFY(page->isSelectionCollapsed()); - QCOMPARE(page->selectionStartOffset(), 4); - - // cursor will be before the word "jumps" - page->triggerAction(QWebPage::MoveToStartOfLine); - QVERIFY(page->isSelectionCollapsed()); - QCOMPARE(page->selectionStartOffset(), 0); - - // cursor will be after the word "dog" - page->triggerAction(QWebPage::MoveToEndOfLine); - QVERIFY(page->isSelectionCollapsed()); - QCOMPARE(page->selectionStartOffset(), 23); - - // cursor will be between 'w' and 'n' in "brown" - page->triggerAction(QWebPage::MoveToStartOfLine); - page->triggerAction(QWebPage::MoveToPreviousWord); - page->triggerAction(QWebPage::MoveToPreviousWord); - page->triggerAction(QWebPage::MoveToNextChar); - page->triggerAction(QWebPage::MoveToNextChar); - page->triggerAction(QWebPage::MoveToNextChar); - page->triggerAction(QWebPage::MoveToNextChar); - QVERIFY(page->isSelectionCollapsed()); - QCOMPARE(page->selectionStartOffset(), 14); - - // cursor will be after the word "fox" - page->triggerAction(QWebPage::MoveToEndOfLine); - QVERIFY(page->isSelectionCollapsed()); - QCOMPARE(page->selectionStartOffset(), 19); - - // cursor will be before the word "The" - page->triggerAction(QWebPage::MoveToStartOfDocument); - QVERIFY(page->isSelectionCollapsed()); - QCOMPARE(page->selectionStartOffset(), 0); - - // cursor will be after the word "you!" - page->triggerAction(QWebPage::MoveToEndOfDocument); - QVERIFY(page->isSelectionCollapsed()); - QCOMPARE(page->selectionStartOffset(), 12); - - // cursor will be before the word "be" - page->triggerAction(QWebPage::MoveToStartOfBlock); - QVERIFY(page->isSelectionCollapsed()); - QCOMPARE(page->selectionStartOffset(), 0); - - // cursor will be after the word "you!" - page->triggerAction(QWebPage::MoveToEndOfBlock); - QVERIFY(page->isSelectionCollapsed()); - QCOMPARE(page->selectionStartOffset(), 12); - - // try to move before the document start - page->triggerAction(QWebPage::MoveToStartOfDocument); - page->triggerAction(QWebPage::MoveToPreviousChar); - QVERIFY(page->isSelectionCollapsed()); - QCOMPARE(page->selectionStartOffset(), 0); - page->triggerAction(QWebPage::MoveToStartOfDocument); - page->triggerAction(QWebPage::MoveToPreviousWord); - QVERIFY(page->isSelectionCollapsed()); - QCOMPARE(page->selectionStartOffset(), 0); - - // try to move past the document end - page->triggerAction(QWebPage::MoveToEndOfDocument); - page->triggerAction(QWebPage::MoveToNextChar); - QVERIFY(page->isSelectionCollapsed()); - QCOMPARE(page->selectionStartOffset(), 12); - page->triggerAction(QWebPage::MoveToEndOfDocument); - page->triggerAction(QWebPage::MoveToNextWord); - QVERIFY(page->isSelectionCollapsed()); - QCOMPARE(page->selectionStartOffset(), 12); - - delete page; -} - -void tst_QWebPage::textSelection() -{ - CursorTrackedPage* page = new CursorTrackedPage; - QString content("

The quick brown fox

" \ - "

jumps over the lazy dog

" \ - "

May the source
be with you!

"); - page->mainFrame()->setHtml(content); - - // these actions must exist - QVERIFY(page->action(QWebPage::SelectAll) != 0); - QVERIFY(page->action(QWebPage::SelectNextChar) != 0); - QVERIFY(page->action(QWebPage::SelectPreviousChar) != 0); - QVERIFY(page->action(QWebPage::SelectNextWord) != 0); - QVERIFY(page->action(QWebPage::SelectPreviousWord) != 0); - QVERIFY(page->action(QWebPage::SelectNextLine) != 0); - QVERIFY(page->action(QWebPage::SelectPreviousLine) != 0); - QVERIFY(page->action(QWebPage::SelectStartOfLine) != 0); - QVERIFY(page->action(QWebPage::SelectEndOfLine) != 0); - QVERIFY(page->action(QWebPage::SelectStartOfBlock) != 0); - QVERIFY(page->action(QWebPage::SelectEndOfBlock) != 0); - QVERIFY(page->action(QWebPage::SelectStartOfDocument) != 0); - QVERIFY(page->action(QWebPage::SelectEndOfDocument) != 0); - - // right now they are disabled because contentEditable is false and - // there isn't an existing selection to modify - QCOMPARE(page->action(QWebPage::SelectNextChar)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::SelectPreviousChar)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::SelectNextWord)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::SelectPreviousWord)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::SelectNextLine)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::SelectPreviousLine)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::SelectStartOfLine)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::SelectEndOfLine)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::SelectStartOfBlock)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::SelectEndOfBlock)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::SelectStartOfDocument)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::SelectEndOfDocument)->isEnabled(), false); - - // ..but SelectAll is awalys enabled - QCOMPARE(page->action(QWebPage::SelectAll)->isEnabled(), true); - - // Verify hasSelection returns false since there is no selection yet... - QCOMPARE(page->hasSelection(), false); - - // this will select the first paragraph - QString selectScript = "var range = document.createRange(); " \ - "var node = document.getElementById(\"one\"); " \ - "range.selectNode(node); " \ - "getSelection().addRange(range);"; - page->mainFrame()->evaluateJavaScript(selectScript); - QCOMPARE(page->selectedText().trimmed(), QString::fromLatin1("The quick brown fox")); - QRegExp regExp(" style=\".*\""); - regExp.setMinimal(true); - QCOMPARE(page->selectedHtml().trimmed().replace(regExp, ""), QString::fromLatin1("

The quick brown fox

")); - - // Make sure hasSelection returns true, since there is selected text now... - QCOMPARE(page->hasSelection(), true); - - // here the actions are enabled after a selection has been created - QCOMPARE(page->action(QWebPage::SelectNextChar)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::SelectPreviousChar)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::SelectNextWord)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::SelectPreviousWord)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::SelectNextLine)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::SelectPreviousLine)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::SelectStartOfLine)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::SelectEndOfLine)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::SelectStartOfBlock)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::SelectEndOfBlock)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::SelectStartOfDocument)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::SelectEndOfDocument)->isEnabled(), true); - - // make it editable before navigating the cursor - page->setContentEditable(true); - - // cursor will be before the word "The", this makes sure there is a charet - page->triggerAction(QWebPage::MoveToStartOfDocument); - QVERIFY(page->isSelectionCollapsed()); - QCOMPARE(page->selectionStartOffset(), 0); - - // here the actions are enabled after contentEditable is true - QCOMPARE(page->action(QWebPage::SelectNextChar)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::SelectPreviousChar)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::SelectNextWord)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::SelectPreviousWord)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::SelectNextLine)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::SelectPreviousLine)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::SelectStartOfLine)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::SelectEndOfLine)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::SelectStartOfBlock)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::SelectEndOfBlock)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::SelectStartOfDocument)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::SelectEndOfDocument)->isEnabled(), true); - - delete page; -} - -void tst_QWebPage::textEditing() -{ - CursorTrackedPage* page = new CursorTrackedPage; - QString content("

The quick brown fox

" \ - "

jumps over the lazy dog

" \ - "

May the source
be with you!

"); - page->mainFrame()->setHtml(content); - - // these actions must exist - QVERIFY(page->action(QWebPage::Cut) != 0); - QVERIFY(page->action(QWebPage::Copy) != 0); - QVERIFY(page->action(QWebPage::Paste) != 0); - QVERIFY(page->action(QWebPage::DeleteStartOfWord) != 0); - QVERIFY(page->action(QWebPage::DeleteEndOfWord) != 0); - QVERIFY(page->action(QWebPage::SetTextDirectionDefault) != 0); - QVERIFY(page->action(QWebPage::SetTextDirectionLeftToRight) != 0); - QVERIFY(page->action(QWebPage::SetTextDirectionRightToLeft) != 0); - QVERIFY(page->action(QWebPage::ToggleBold) != 0); - QVERIFY(page->action(QWebPage::ToggleItalic) != 0); - QVERIFY(page->action(QWebPage::ToggleUnderline) != 0); - QVERIFY(page->action(QWebPage::InsertParagraphSeparator) != 0); - QVERIFY(page->action(QWebPage::InsertLineSeparator) != 0); - QVERIFY(page->action(QWebPage::PasteAndMatchStyle) != 0); - QVERIFY(page->action(QWebPage::RemoveFormat) != 0); - QVERIFY(page->action(QWebPage::ToggleStrikethrough) != 0); - QVERIFY(page->action(QWebPage::ToggleSubscript) != 0); - QVERIFY(page->action(QWebPage::ToggleSuperscript) != 0); - QVERIFY(page->action(QWebPage::InsertUnorderedList) != 0); - QVERIFY(page->action(QWebPage::InsertOrderedList) != 0); - QVERIFY(page->action(QWebPage::Indent) != 0); - QVERIFY(page->action(QWebPage::Outdent) != 0); - QVERIFY(page->action(QWebPage::AlignCenter) != 0); - QVERIFY(page->action(QWebPage::AlignJustified) != 0); - QVERIFY(page->action(QWebPage::AlignLeft) != 0); - QVERIFY(page->action(QWebPage::AlignRight) != 0); - - // right now they are disabled because contentEditable is false - QCOMPARE(page->action(QWebPage::Cut)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::Paste)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::DeleteStartOfWord)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::DeleteEndOfWord)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::SetTextDirectionDefault)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::SetTextDirectionLeftToRight)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::SetTextDirectionRightToLeft)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::ToggleBold)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::ToggleItalic)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::ToggleUnderline)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::InsertParagraphSeparator)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::InsertLineSeparator)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::PasteAndMatchStyle)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::RemoveFormat)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::ToggleStrikethrough)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::ToggleSubscript)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::ToggleSuperscript)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::InsertUnorderedList)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::InsertOrderedList)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::Indent)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::Outdent)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::AlignCenter)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::AlignJustified)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::AlignLeft)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::AlignRight)->isEnabled(), false); - - // Select everything - page->triggerAction(QWebPage::SelectAll); - - // make sure it is enabled since there is a selection - QCOMPARE(page->action(QWebPage::Copy)->isEnabled(), true); - - // make it editable before navigating the cursor - page->setContentEditable(true); - - // clear the selection - page->triggerAction(QWebPage::MoveToStartOfDocument); - QVERIFY(page->isSelectionCollapsed()); - QCOMPARE(page->selectionStartOffset(), 0); - - // make sure it is disabled since there isn't a selection - QCOMPARE(page->action(QWebPage::Copy)->isEnabled(), false); - - // here the actions are enabled after contentEditable is true - QCOMPARE(page->action(QWebPage::Paste)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::DeleteStartOfWord)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::DeleteEndOfWord)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::SetTextDirectionDefault)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::SetTextDirectionLeftToRight)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::SetTextDirectionRightToLeft)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::ToggleBold)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::ToggleItalic)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::ToggleUnderline)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::InsertParagraphSeparator)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::InsertLineSeparator)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::PasteAndMatchStyle)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::ToggleStrikethrough)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::ToggleSubscript)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::ToggleSuperscript)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::InsertUnorderedList)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::InsertOrderedList)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::Indent)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::Outdent)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::AlignCenter)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::AlignJustified)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::AlignLeft)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::AlignRight)->isEnabled(), true); - - // make sure these are disabled since there isn't a selection - QCOMPARE(page->action(QWebPage::Cut)->isEnabled(), false); - QCOMPARE(page->action(QWebPage::RemoveFormat)->isEnabled(), false); - - // make sure everything is selected - page->triggerAction(QWebPage::SelectAll); - - // this is only true if there is an editable selection - QCOMPARE(page->action(QWebPage::Cut)->isEnabled(), true); - QCOMPARE(page->action(QWebPage::RemoveFormat)->isEnabled(), true); - - delete page; -} - -void tst_QWebPage::requestCache() -{ - TestPage page; - QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool))); - - page.mainFrame()->setUrl(QString("data:text/html,Click me")); - QTRY_COMPARE(loadSpy.count(), 1); - QTRY_COMPARE(page.navigations.count(), 1); - - page.mainFrame()->setUrl(QString("data:text/html,Click me2")); - QTRY_COMPARE(loadSpy.count(), 2); - QTRY_COMPARE(page.navigations.count(), 2); - - page.triggerAction(QWebPage::Stop); - QVERIFY(page.history()->canGoBack()); - page.triggerAction(QWebPage::Back); - - QTRY_COMPARE(loadSpy.count(), 3); - QTRY_COMPARE(page.navigations.count(), 3); - QCOMPARE(page.navigations.at(0).request.attribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork).toInt(), - (int)QNetworkRequest::PreferNetwork); - QCOMPARE(page.navigations.at(1).request.attribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork).toInt(), - (int)QNetworkRequest::PreferNetwork); - QCOMPARE(page.navigations.at(2).request.attribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork).toInt(), - (int)QNetworkRequest::PreferCache); -} - -void tst_QWebPage::loadCachedPage() -{ - TestPage page; - QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool))); - page.settings()->setMaximumPagesInCache(3); - - page.mainFrame()->load(QUrl("data:text/html,This is first page")); - - QTRY_COMPARE(loadSpy.count(), 1); - QTRY_COMPARE(page.navigations.count(), 1); - - QUrl firstPageUrl = page.mainFrame()->url(); - page.mainFrame()->load(QUrl("data:text/html,This is second page")); - - QTRY_COMPARE(loadSpy.count(), 2); - QTRY_COMPARE(page.navigations.count(), 2); - - page.triggerAction(QWebPage::Stop); - QVERIFY(page.history()->canGoBack()); - - QSignalSpy urlSpy(page.mainFrame(), SIGNAL(urlChanged(QUrl))); - QVERIFY(urlSpy.isValid()); - - page.triggerAction(QWebPage::Back); - ::waitForSignal(page.mainFrame(), SIGNAL(urlChanged(QUrl))); - QCOMPARE(urlSpy.size(), 1); - - QList arguments1 = urlSpy.takeFirst(); - QCOMPARE(arguments1.at(0).toUrl(), firstPageUrl); - -} -void tst_QWebPage::backActionUpdate() -{ - QWebView view; - QWebPage *page = view.page(); - QAction *action = page->action(QWebPage::Back); - QVERIFY(!action->isEnabled()); - QSignalSpy loadSpy(page, SIGNAL(loadFinished(bool))); - QUrl url = QUrl("qrc:///resources/framedindex.html"); - page->mainFrame()->load(url); - QTRY_COMPARE(loadSpy.count(), 1); - QVERIFY(!action->isEnabled()); - QTest::mouseClick(&view, Qt::LeftButton, 0, QPoint(10, 10)); - QTRY_COMPARE(loadSpy.count(), 2); - - QVERIFY(action->isEnabled()); -} - -void frameAtHelper(QWebPage* webPage, QWebFrame* webFrame, QPoint framePosition) -{ - if (!webFrame) - return; - - framePosition += QPoint(webFrame->pos()); - QList children = webFrame->childFrames(); - for (int i = 0; i < children.size(); ++i) { - if (children.at(i)->childFrames().size() > 0) - frameAtHelper(webPage, children.at(i), framePosition); - - QRect frameRect(children.at(i)->pos() + framePosition, children.at(i)->geometry().size()); - QVERIFY(children.at(i) == webPage->frameAt(frameRect.topLeft())); - } -} - -void tst_QWebPage::frameAt() -{ - QWebView webView; - QWebPage* webPage = webView.page(); - QSignalSpy loadSpy(webPage, SIGNAL(loadFinished(bool))); - QUrl url = QUrl("qrc:///resources/iframe.html"); - webPage->mainFrame()->load(url); - QTRY_COMPARE(loadSpy.count(), 1); - frameAtHelper(webPage, webPage->mainFrame(), webPage->mainFrame()->pos()); -} - -void tst_QWebPage::inputMethods_data() -{ - QTest::addColumn("viewType"); - QTest::newRow("QWebView") << "QWebView"; - QTest::newRow("QGraphicsWebView") << "QGraphicsWebView"; -} - -static Qt::InputMethodHints inputMethodHints(QObject* object) -{ - if (QGraphicsObject* o = qobject_cast(object)) - return o->inputMethodHints(); - if (QWidget* w = qobject_cast(object)) - return w->inputMethodHints(); - return Qt::InputMethodHints(); -} - -static bool inputMethodEnabled(QObject* object) -{ - if (QGraphicsObject* o = qobject_cast(object)) - return o->flags() & QGraphicsItem::ItemAcceptsInputMethod; - if (QWidget* w = qobject_cast(object)) - return w->testAttribute(Qt::WA_InputMethodEnabled); - return false; -} - -static void clickOnPage(QWebPage* page, const QPoint& position) -{ - QMouseEvent evpres(QEvent::MouseButtonPress, position, Qt::LeftButton, Qt::NoButton, Qt::NoModifier); - page->event(&evpres); - QMouseEvent evrel(QEvent::MouseButtonRelease, position, Qt::LeftButton, Qt::NoButton, Qt::NoModifier); - page->event(&evrel); -} - -void tst_QWebPage::inputMethods() -{ - QFETCH(QString, viewType); - QWebPage* page = new QWebPage; - QObject* view = 0; - QObject* container = 0; - if (viewType == "QWebView") { - QWebView* wv = new QWebView; - wv->setPage(page); - view = wv; - container = view; - } else if (viewType == "QGraphicsWebView") { - QGraphicsWebView* wv = new QGraphicsWebView; - wv->setPage(page); - view = wv; - - QGraphicsView* gv = new QGraphicsView; - QGraphicsScene* scene = new QGraphicsScene(gv); - gv->setScene(scene); - scene->addItem(wv); - wv->setGeometry(QRect(0, 0, 500, 500)); - - container = gv; - } else - QVERIFY2(false, "Unknown view type"); - - page->settings()->setFontFamily(QWebSettings::SerifFont, page->settings()->fontFamily(QWebSettings::FixedFont)); - page->mainFrame()->setHtml("" \ - "
" \ - "" \ - ""); - page->mainFrame()->setFocus(); - - TestInputContext testContext; - - QWebElementCollection inputs = page->mainFrame()->documentElement().findAll("input"); - QPoint textInputCenter = inputs.at(0).geometry().center(); - - clickOnPage(page, textInputCenter); - - // This part of the test checks if the SIP (Software Input Panel) is triggered, - // which normally happens on mobile platforms, when a user input form receives - // a mouse click. - int inputPanel = 0; - if (viewType == "QWebView") { - if (QWebView* wv = qobject_cast(view)) - inputPanel = wv->style()->styleHint(QStyle::SH_RequestSoftwareInputPanel); - } else if (viewType == "QGraphicsWebView") { - if (QGraphicsWebView* wv = qobject_cast(view)) - inputPanel = wv->style()->styleHint(QStyle::SH_RequestSoftwareInputPanel); - } - - // For non-mobile platforms RequestSoftwareInputPanel event is not called - // because there is no SIP (Software Input Panel) triggered. In the case of a - // mobile platform, an input panel, e.g. virtual keyboard, is usually invoked - // and the RequestSoftwareInputPanel event is called. For these two situations - // this part of the test can verified as the checks below. - if (inputPanel) - QVERIFY(testContext.isInputPanelVisible()); - else - QVERIFY(!testContext.isInputPanelVisible()); - testContext.hideInputPanel(); - - clickOnPage(page, textInputCenter); - QVERIFY(testContext.isInputPanelVisible()); - - //ImMicroFocus - QVariant variant = page->inputMethodQuery(Qt::ImMicroFocus); - QVERIFY(inputs.at(0).geometry().contains(variant.toRect().topLeft())); - - // We assigned the serif font famility to be the same as the fixef font family. - // Then test ImFont on a serif styled element, we should get our fixef font family. - variant = page->inputMethodQuery(Qt::ImFont); - QFont font = variant.value(); - QCOMPARE(page->settings()->fontFamily(QWebSettings::FixedFont), font.family()); - - QList inputAttributes; - - //Insert text. - { - QInputMethodEvent eventText("QtWebKit", inputAttributes); - QSignalSpy signalSpy(page, SIGNAL(microFocusChanged())); - page->event(&eventText); - QCOMPARE(signalSpy.count(), 0); - } - - { - QInputMethodEvent eventText("", inputAttributes); - eventText.setCommitString(QString("QtWebKit"), 0, 0); - page->event(&eventText); - } - - //ImMaximumTextLength - variant = page->inputMethodQuery(Qt::ImMaximumTextLength); - QCOMPARE(20, variant.toInt()); - - //Set selection - inputAttributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, 3, 2, QVariant()); - QInputMethodEvent eventSelection("",inputAttributes); - page->event(&eventSelection); - - //ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - int anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 3); - - //ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - int cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 5); - - //ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - QString selectionValue = variant.value(); - QCOMPARE(selectionValue, QString("eb")); - - //Set selection with negative length - inputAttributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, 6, -5, QVariant()); - QInputMethodEvent eventSelection3("",inputAttributes); - page->event(&eventSelection3); - - //ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 1); - - //ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 6); - - //ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value(); - QCOMPARE(selectionValue, QString("tWebK")); - - //ImSurroundingText - variant = page->inputMethodQuery(Qt::ImSurroundingText); - QString value = variant.value(); - QCOMPARE(value, QString("QtWebKit")); - - { - QList attributes; - // Clear the selection, so the next test does not clear any contents. - QInputMethodEvent::Attribute newSelection(QInputMethodEvent::Selection, 0, 0, QVariant()); - attributes.append(newSelection); - QInputMethodEvent event("composition", attributes); - page->event(&event); - } - - // A ongoing composition should not change the surrounding text before it is committed. - variant = page->inputMethodQuery(Qt::ImSurroundingText); - value = variant.value(); - QCOMPARE(value, QString("QtWebKit")); - - // Cancel current composition first - inputAttributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, 0, 0, QVariant()); - QInputMethodEvent eventSelection4("", inputAttributes); - page->event(&eventSelection4); - - // START - Tests for Selection when the Editor is NOT in Composition mode - - // LEFT to RIGHT selection - // Deselect the selection by sending MouseButtonPress events - // This moves the current cursor to the end of the text - clickOnPage(page, textInputCenter); - - { - QList attributes; - QInputMethodEvent event(QString(), attributes); - event.setCommitString("XXX", 0, 0); - page->event(&event); - event.setCommitString(QString(), -2, 2); // Erase two characters. - page->event(&event); - event.setCommitString(QString(), -1, 1); // Erase one character. - page->event(&event); - variant = page->inputMethodQuery(Qt::ImSurroundingText); - value = variant.value(); - QCOMPARE(value, QString("QtWebKit")); - } - - //Move to the start of the line - page->triggerAction(QWebPage::MoveToStartOfLine); - - QKeyEvent keyRightEventPress(QEvent::KeyPress, Qt::Key_Right, Qt::NoModifier); - QKeyEvent keyRightEventRelease(QEvent::KeyRelease, Qt::Key_Right, Qt::NoModifier); - - //Move 2 characters RIGHT - for (int j = 0; j < 2; ++j) { - page->event(&keyRightEventPress); - page->event(&keyRightEventRelease); - } - - //Select to the end of the line - page->triggerAction(QWebPage::SelectEndOfLine); - - //ImAnchorPosition QtWebKit - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 2); - - //ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 8); - - //ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value(); - QCOMPARE(selectionValue, QString("WebKit")); - - //RIGHT to LEFT selection - //Deselect the selection (this moves the current cursor to the end of the text) - clickOnPage(page, textInputCenter); - - //ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 8); - - //ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 8); - - //ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value(); - QCOMPARE(selectionValue, QString("")); - - QKeyEvent keyLeftEventPress(QEvent::KeyPress, Qt::Key_Left, Qt::NoModifier); - QKeyEvent keyLeftEventRelease(QEvent::KeyRelease, Qt::Key_Left, Qt::NoModifier); - - //Move 2 characters LEFT - for (int i = 0; i < 2; ++i) { - page->event(&keyLeftEventPress); - page->event(&keyLeftEventRelease); - } - - //Select to the start of the line - page->triggerAction(QWebPage::SelectStartOfLine); - - //ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 6); - - //ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 0); - - //ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value(); - QCOMPARE(selectionValue, QString("QtWebK")); - - //END - Tests for Selection when the Editor is not in Composition mode - - //ImhHiddenText - QPoint passwordInputCenter = inputs.at(1).geometry().center(); - clickOnPage(page, passwordInputCenter); - - QVERIFY(inputMethodEnabled(view)); - QVERIFY(inputMethodHints(view) & Qt::ImhHiddenText); - - clickOnPage(page, textInputCenter); - QVERIFY(!(inputMethodHints(view) & Qt::ImhHiddenText)); - - page->mainFrame()->setHtml("

nothing to input here"); - testContext.hideInputPanel(); - - QWebElement para = page->mainFrame()->findFirstElement("p"); - clickOnPage(page, para.geometry().center()); - - QVERIFY(!testContext.isInputPanelVisible()); - - //START - Test for sending empty QInputMethodEvent - page->mainFrame()->setHtml("" \ - "" \ - ""); - page->mainFrame()->evaluateJavaScript("var inputEle = document.getElementById('input3'); inputEle.focus(); inputEle.select();"); - - //Send empty QInputMethodEvent - QInputMethodEvent emptyEvent; - page->event(&emptyEvent); - - QString inputValue = page->mainFrame()->evaluateJavaScript("document.getElementById('input3').value").toString(); - QCOMPARE(inputValue, QString("QtWebKit2")); - //END - Test for sending empty QInputMethodEvent - - page->mainFrame()->setHtml("" \ - "" \ - ""); - page->mainFrame()->evaluateJavaScript("var inputEle = document.getElementById('input4'); inputEle.focus(); inputEle.select();"); - - // Clear the selection, also cancel the ongoing composition if there is one. - { - QList attributes; - QInputMethodEvent::Attribute newSelection(QInputMethodEvent::Selection, 0, 0, QVariant()); - attributes.append(newSelection); - QInputMethodEvent event("", attributes); - page->event(&event); - } - - // ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value(); - QCOMPARE(selectionValue, QString("")); - - variant = page->inputMethodQuery(Qt::ImSurroundingText); - QString surroundingValue = variant.value(); - QCOMPARE(surroundingValue, QString("QtWebKit inputMethod")); - - // ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 0); - - // ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 0); - - // 1. Insert a character to the begining of the line. - // Send temporary text, which makes the editor has composition 'm'. - { - QList attributes; - QInputMethodEvent event("m", attributes); - page->event(&event); - } - - // ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value(); - QCOMPARE(selectionValue, QString("")); - - // ImSurroundingText - variant = page->inputMethodQuery(Qt::ImSurroundingText); - surroundingValue = variant.value(); - QCOMPARE(surroundingValue, QString("QtWebKit inputMethod")); - - // ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 0); - - // ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 0); - - // Send temporary text, which makes the editor has composition 'n'. - { - QList attributes; - QInputMethodEvent event("n", attributes); - page->event(&event); - } - - // ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value(); - QCOMPARE(selectionValue, QString("")); - - // ImSurroundingText - variant = page->inputMethodQuery(Qt::ImSurroundingText); - surroundingValue = variant.value(); - QCOMPARE(surroundingValue, QString("QtWebKit inputMethod")); - - // ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 0); - - // ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 0); - - // Send commit text, which makes the editor conforms composition. - { - QList attributes; - QInputMethodEvent event("", attributes); - event.setCommitString("o"); - page->event(&event); - } - - // ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value(); - QCOMPARE(selectionValue, QString("")); - - // ImSurroundingText - variant = page->inputMethodQuery(Qt::ImSurroundingText); - surroundingValue = variant.value(); - QCOMPARE(surroundingValue, QString("oQtWebKit inputMethod")); - - // ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 1); - - // ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 1); - - // 2. insert a character to the middle of the line. - // Send temporary text, which makes the editor has composition 'd'. - { - QList attributes; - QInputMethodEvent event("d", attributes); - page->event(&event); - } - - // ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value(); - QCOMPARE(selectionValue, QString("")); - - // ImSurroundingText - variant = page->inputMethodQuery(Qt::ImSurroundingText); - surroundingValue = variant.value(); - QCOMPARE(surroundingValue, QString("oQtWebKit inputMethod")); - - // ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 1); - - // ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 1); - - // Send commit text, which makes the editor conforms composition. - { - QList attributes; - QInputMethodEvent event("", attributes); - event.setCommitString("e"); - page->event(&event); - } - - // ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value(); - QCOMPARE(selectionValue, QString("")); - - // ImSurroundingText - variant = page->inputMethodQuery(Qt::ImSurroundingText); - surroundingValue = variant.value(); - QCOMPARE(surroundingValue, QString("oeQtWebKit inputMethod")); - - // ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 2); - - // ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 2); - - // 3. Insert a character to the end of the line. - page->triggerAction(QWebPage::MoveToEndOfLine); - - // Send temporary text, which makes the editor has composition 't'. - { - QList attributes; - QInputMethodEvent event("t", attributes); - page->event(&event); - } - - // ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value(); - QCOMPARE(selectionValue, QString("")); - - // ImSurroundingText - variant = page->inputMethodQuery(Qt::ImSurroundingText); - surroundingValue = variant.value(); - QCOMPARE(surroundingValue, QString("oeQtWebKit inputMethod")); - - // ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 22); - - // ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 22); - - // Send commit text, which makes the editor conforms composition. - { - QList attributes; - QInputMethodEvent event("", attributes); - event.setCommitString("t"); - page->event(&event); - } - - // ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value(); - QCOMPARE(selectionValue, QString("")); - - // ImSurroundingText - variant = page->inputMethodQuery(Qt::ImSurroundingText); - surroundingValue = variant.value(); - QCOMPARE(surroundingValue, QString("oeQtWebKit inputMethodt")); - - // ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 23); - - // ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 23); - - // 4. Replace the selection. - page->triggerAction(QWebPage::SelectPreviousWord); - - // ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value(); - QCOMPARE(selectionValue, QString("inputMethodt")); - - // ImSurroundingText - variant = page->inputMethodQuery(Qt::ImSurroundingText); - surroundingValue = variant.value(); - QCOMPARE(surroundingValue, QString("oeQtWebKit inputMethodt")); - - // ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 11); - - // ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 23); - - // Send temporary text, which makes the editor has composition 'w'. - { - QList attributes; - QInputMethodEvent event("w", attributes); - page->event(&event); - } - - // ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value(); - QCOMPARE(selectionValue, QString("")); - - // ImSurroundingText - variant = page->inputMethodQuery(Qt::ImSurroundingText); - surroundingValue = variant.value(); - QCOMPARE(surroundingValue, QString("oeQtWebKit ")); - - // ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 11); - - // ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 11); - - // Send commit text, which makes the editor conforms composition. - { - QList attributes; - QInputMethodEvent event("", attributes); - event.setCommitString("2"); - page->event(&event); - } - - // ImCurrentSelection - variant = page->inputMethodQuery(Qt::ImCurrentSelection); - selectionValue = variant.value(); - QCOMPARE(selectionValue, QString("")); - - // ImSurroundingText - variant = page->inputMethodQuery(Qt::ImSurroundingText); - surroundingValue = variant.value(); - QCOMPARE(surroundingValue, QString("oeQtWebKit 2")); - - // ImCursorPosition - variant = page->inputMethodQuery(Qt::ImCursorPosition); - cursorPosition = variant.toInt(); - QCOMPARE(cursorPosition, 12); - - // ImAnchorPosition - variant = page->inputMethodQuery(Qt::ImAnchorPosition); - anchorPosition = variant.toInt(); - QCOMPARE(anchorPosition, 12); - - // Check sending RequestSoftwareInputPanel event - page->mainFrame()->setHtml("" \ - "" \ - "

abc
"\ - ""); - QWebElement inputElement = page->mainFrame()->findFirstElement("div"); - clickOnPage(page, inputElement.geometry().center()); - - QVERIFY(!testContext.isInputPanelVisible()); - - // START - Newline test for textarea - qApp->processEvents(); - page->mainFrame()->setHtml("" \ - "