summaryrefslogtreecommitdiffstats
path: root/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebKit/qt/tests/qwebpage/tst_qwebpage.cpp')
-rw-r--r--WebKit/qt/tests/qwebpage/tst_qwebpage.cpp913
1 files changed, 831 insertions, 82 deletions
diff --git a/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp b/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp
index ba7a87e..c27ba02 100644
--- a/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp
+++ b/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp
@@ -20,12 +20,16 @@
*/
#include "../util.h"
+#include "../WebCoreSupport/DumpRenderTreeSupportQt.h"
#include <QDir>
#include <QGraphicsWidget>
#include <QLineEdit>
+#include <QLocale>
#include <QMenu>
#include <QPushButton>
+#include <QStyle>
#include <QtTest/QtTest>
+#include <QTextCharFormat>
#include <qgraphicsscene.h>
#include <qgraphicsview.h>
#include <qgraphicswebview.h>
@@ -37,6 +41,7 @@
#include <qwebpage.h>
#include <qwebsecurityorigin.h>
#include <qwebview.h>
+#include <qimagewriter.h>
class EventSpy : public QObject, public QList<QEvent::Type>
{
@@ -72,14 +77,15 @@ private slots:
void cleanupTestCase();
void acceptNavigationRequest();
- void infiniteLoopJS();
+ void geolocationRequestJS();
void loadFinished();
void acceptNavigationRequestWithNewWindow();
void userStyleSheet();
void modified();
void contextMenuCrash();
void database();
- void createPlugin();
+ void createPluginWithPluginsEnabled();
+ void createPluginWithPluginsDisabled();
void destroyPlugin_data();
void destroyPlugin();
void createViewlessPlugin_data();
@@ -91,6 +97,7 @@ private slots:
void backActionUpdate();
void frameAt();
void requestCache();
+ void loadCachedPage();
void protectBindingsRuntimeObjectsFromCollector();
void localURLSchemes();
void testOptionalJSObjects();
@@ -98,10 +105,16 @@ private slots:
void consoleOutput();
void inputMethods_data();
void inputMethods();
+ void inputMethodsTextFormat_data();
+ void inputMethodsTextFormat();
void defaultTextEncoding();
void errorPageExtension();
void errorPageExtensionInIFrames();
void errorPageExtensionInFrameset();
+ void userAgentApplicationName();
+ void userAgentLocaleChange();
+
+ void viewModes();
void crashTests_LazyInitializationOfMainFrame();
@@ -111,7 +124,11 @@ private slots:
void originatingObjectInNetworkRequests();
void testJSPrompt();
void showModalDialog();
-
+ void testStopScheduledPageRefresh();
+ void findText();
+ void supportedContentType();
+ void infiniteLoopJS();
+
private:
QWebView* m_view;
QWebPage* m_page;
@@ -201,16 +218,64 @@ public:
public slots:
bool shouldInterruptJavaScript() {
- return true;
+ return true;
+ }
+ 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;
};
void tst_QWebPage::infiniteLoopJS()
{
JSTestPage* newPage = new JSTestPage(m_view);
m_view->setPage(newPage);
- m_view->setHtml(QString("<html><bodytest</body></html>"), QUrl());
+ m_view->setHtml(QString("<html><body>test</body></html>"), QUrl());
m_view->page()->mainFrame()->evaluateJavaScript("var run = true;var a = 1;while(run){a++;}");
+ delete newPage;
+}
+
+void tst_QWebPage::geolocationRequestJS()
+{
+ /*
+ This test is disabled because it can only succeed if ENABLE(GEOLOCATION) is true.
+ The code needs to be updated when the API of requestPermissionFromUser is updated.
+ */
+ QSKIP("Test disabled as long as geolocation is disabled from the build.", SkipSingle);
+
+ JSTestPage* newPage = new JSTestPage(m_view);
+ connect(newPage, SIGNAL(requestPermissionFromUser(QWebFrame*, QWebPage::Feature)),
+ newPage, SLOT(requestPermission(QWebFrame*, QWebPage::Feature)));
+
+ newPage->setGeolocationPermission(false);
+ m_view->setPage(newPage);
+ m_view->setHtml(QString("<html><body>test</body></html>"), 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");
+
+ 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()
@@ -220,9 +285,9 @@ void tst_QWebPage::loadFinished()
QSignalSpy spyLoadStarted(m_view, SIGNAL(loadStarted()));
QSignalSpy spyLoadFinished(m_view, SIGNAL(loadFinished(bool)));
- m_view->setHtml(QString("data:text/html,<frameset cols=\"25%,75%\"><frame src=\"data:text/html,"
- "<head><meta http-equiv='refresh' content='1'></head>foo \">"
- "<frame src=\"data:text/html,bar\"></frameset>"), QUrl());
+ m_view->page()->mainFrame()->load(QUrl("data:text/html,<frameset cols=\"25%,75%\"><frame src=\"data:text/html,"
+ "<head><meta http-equiv='refresh' content='1'></head>foo \">"
+ "<frame src=\"data:text/html,bar\"></frameset>"));
QTRY_COMPARE(spyLoadFinished.count(), 1);
QTRY_VERIFY(spyLoadStarted.count() > 1);
@@ -230,8 +295,8 @@ void tst_QWebPage::loadFinished()
spyLoadFinished.clear();
- m_view->setHtml(QString("data:text/html,<frameset cols=\"25%,75%\"><frame src=\"data:text/html,"
- "foo \"><frame src=\"data:text/html,bar\"></frameset>"), QUrl());
+ m_view->page()->mainFrame()->load(QUrl("data:text/html,<frameset cols=\"25%,75%\"><frame src=\"data:text/html,"
+ "foo \"><frame src=\"data:text/html,bar\"></frameset>"));
QTRY_COMPARE(spyLoadFinished.count(), 1);
QCOMPARE(spyLoadFinished.count(), 1);
}
@@ -350,6 +415,21 @@ void tst_QWebPage::userStyleSheet()
QCOMPARE(networkManager->requestedUrls.at(0), QUrl("http://does.not/exist.png"));
}
+void tst_QWebPage::viewModes()
+{
+ m_view->setHtml("<body></body>");
+ 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,<body>blub"));
@@ -515,27 +595,20 @@ protected:
}
};
-void tst_QWebPage::createPlugin()
+static void createPlugin(QWebView *view)
{
- QSignalSpy loadSpy(m_view, SIGNAL(loadFinished(bool)));
+ QSignalSpy loadSpy(view, SIGNAL(loadFinished(bool)));
- PluginPage* newPage = new PluginPage(m_view);
- m_view->setPage(newPage);
+ PluginPage* newPage = new PluginPage(view);
+ view->setPage(newPage);
- // plugins not enabled by default, so the plugin shouldn't be loaded
- m_view->setHtml(QString("<html><body><object type='application/x-qt-plugin' classid='pushbutton' id='mybutton'/></body></html>"));
+ // type has to be application/x-qt-plugin
+ view->setHtml(QString("<html><body><object type='application/x-foobarbaz' classid='pushbutton' id='mybutton'/></body></html>"));
QTRY_COMPARE(loadSpy.count(), 1);
QCOMPARE(newPage->calls.count(), 0);
- m_view->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
-
- // type has to be application/x-qt-plugin
- m_view->setHtml(QString("<html><body><object type='application/x-foobarbaz' classid='pushbutton' id='mybutton'/></body></html>"));
+ view->setHtml(QString("<html><body><object type='application/x-qt-plugin' classid='pushbutton' id='mybutton'/></body></html>"));
QTRY_COMPARE(loadSpy.count(), 2);
- QCOMPARE(newPage->calls.count(), 0);
-
- m_view->setHtml(QString("<html><body><object type='application/x-qt-plugin' classid='pushbutton' id='mybutton'/></body></html>"));
- QTRY_COMPARE(loadSpy.count(), 3);
QCOMPARE(newPage->calls.count(), 1);
{
PluginPage::CallInfo ci = newPage->calls.takeFirst();
@@ -566,11 +639,11 @@ void tst_QWebPage::createPlugin()
QCOMPARE(newPage->mainFrame()->evaluateJavaScript("mybutton.clicked.toString()").toString(),
QString::fromLatin1("function clicked() {\n [native code]\n}"));
- m_view->setHtml(QString("<html><body><table>"
+ view->setHtml(QString("<html><body><table>"
"<tr><object type='application/x-qt-plugin' classid='lineedit' id='myedit'/></tr>"
"<tr><object type='application/x-qt-plugin' classid='pushbutton' id='mybutton'/></tr>"
"</table></body></html>"), QUrl("http://foo.bar.baz"));
- QTRY_COMPARE(loadSpy.count(), 4);
+ QTRY_COMPARE(loadSpy.count(), 3);
QCOMPARE(newPage->calls.count(), 2);
{
PluginPage::CallInfo ci = newPage->calls.takeFirst();
@@ -602,14 +675,22 @@ void tst_QWebPage::createPlugin()
QVERIFY(ci.returnValue != 0);
QVERIFY(ci.returnValue->inherits("QPushButton"));
}
+}
- m_view->settings()->setAttribute(QWebSettings::PluginsEnabled, false);
-
- m_view->setHtml(QString("<html><body><object type='application/x-qt-plugin' classid='pushbutton' id='mybutton'/></body></html>"));
- QTRY_COMPARE(loadSpy.count(), 5);
- QCOMPARE(newPage->calls.count(), 0);
+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 {
@@ -722,10 +803,6 @@ void tst_QWebPage::createViewlessPlugin()
}
-// import private API
-void QWEBKIT_EXPORT qt_webpage_setGroupName(QWebPage* page, const QString& groupName);
-QString QWEBKIT_EXPORT qt_webpage_groupName(QWebPage* page);
-
void tst_QWebPage::multiplePageGroupsAndLocalStorage()
{
QDir dir(QDir::currentPath());
@@ -737,12 +814,12 @@ void tst_QWebPage::multiplePageGroupsAndLocalStorage()
view1.page()->settings()->setAttribute(QWebSettings::LocalStorageEnabled, true);
view1.page()->settings()->setLocalStoragePath(QDir::toNativeSeparators(QDir::currentPath() + "/path1"));
- qt_webpage_setGroupName(view1.page(), "group1");
+ DumpRenderTreeSupportQt::webPageSetGroupName(view1.page(), "group1");
view2.page()->settings()->setAttribute(QWebSettings::LocalStorageEnabled, true);
view2.page()->settings()->setLocalStoragePath(QDir::toNativeSeparators(QDir::currentPath() + "/path2"));
- qt_webpage_setGroupName(view2.page(), "group2");
- QCOMPARE(qt_webpage_groupName(view1.page()), QString("group1"));
- QCOMPARE(qt_webpage_groupName(view2.page()), QString("group2"));
+ DumpRenderTreeSupportQt::webPageSetGroupName(view2.page(), "group2");
+ QCOMPARE(DumpRenderTreeSupportQt::webPageGroupName(view1.page()), QString("group1"));
+ QCOMPARE(DumpRenderTreeSupportQt::webPageGroupName(view2.page()), QString("group2"));
view1.setHtml(QString("<html><body> </body></html>"), QUrl("http://www.myexample.com"));
@@ -797,7 +874,7 @@ public:
void tst_QWebPage::cursorMovements()
{
CursorTrackedPage* page = new CursorTrackedPage;
- QString content("<html><body<p id=one>The quick brown fox</p><p id=two>jumps over the lazy dog</p><p>May the source<br/>be with you!</p></body></html>");
+ QString content("<html><body><p id=one>The quick brown fox</p><p id=two>jumps over the lazy dog</p><p>May the source<br/>be with you!</p></body></html>");
page->mainFrame()->setHtml(content);
// this will select the first paragraph
@@ -989,7 +1066,7 @@ void tst_QWebPage::cursorMovements()
void tst_QWebPage::textSelection()
{
CursorTrackedPage* page = new CursorTrackedPage;
- QString content("<html><body<p id=one>The quick brown fox</p>" \
+ QString content("<html><body><p id=one>The quick brown fox</p>" \
"<p id=two>jumps over the lazy dog</p>" \
"<p>May the source<br/>be with you!</p></body></html>");
page->mainFrame()->setHtml(content);
@@ -1077,7 +1154,7 @@ void tst_QWebPage::textSelection()
void tst_QWebPage::textEditing()
{
CursorTrackedPage* page = new CursorTrackedPage;
- QString content("<html><body<p id=one>The quick brown fox</p>" \
+ QString content("<html><body><p id=one>The quick brown fox</p>" \
"<p id=two>jumps over the lazy dog</p>" \
"<p>May the source<br/>be with you!</p></body></html>");
page->mainFrame()->setHtml(content);
@@ -1220,6 +1297,37 @@ void tst_QWebPage::requestCache()
(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<QVariant> arguments1 = urlSpy.takeFirst();
+ QCOMPARE(arguments1.at(0).toUrl(), firstPageUrl);
+
+}
void tst_QWebPage::backActionUpdate()
{
QWebView view;
@@ -1268,12 +1376,9 @@ void tst_QWebPage::inputMethods_data()
{
QTest::addColumn<QString>("viewType");
QTest::newRow("QWebView") << "QWebView";
-#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
QTest::newRow("QGraphicsWebView") << "QGraphicsWebView";
-#endif
}
-#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
static Qt::InputMethodHints inputMethodHints(QObject* object)
{
if (QGraphicsObject* o = qobject_cast<QGraphicsObject*>(object))
@@ -1282,14 +1387,11 @@ static Qt::InputMethodHints inputMethodHints(QObject* object)
return w->inputMethodHints();
return Qt::InputMethodHints();
}
-#endif
static bool inputMethodEnabled(QObject* object)
{
-#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
if (QGraphicsObject* o = qobject_cast<QGraphicsObject*>(object))
return o->flags() & QGraphicsItem::ItemAcceptsInputMethod;
-#endif
if (QWidget* w = qobject_cast<QWidget*>(object))
return w->testAttribute(Qt::WA_InputMethodEnabled);
return false;
@@ -1306,9 +1408,7 @@ void tst_QWebPage::inputMethods()
wv->setPage(page);
view = wv;
container = view;
- }
-#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
- else if (viewType == "QGraphicsWebView") {
+ } else if (viewType == "QGraphicsWebView") {
QGraphicsWebView* wv = new QGraphicsWebView;
wv->setPage(page);
view = wv;
@@ -1320,9 +1420,7 @@ void tst_QWebPage::inputMethods()
wv->setGeometry(QRect(0, 0, 500, 500));
container = gv;
- }
-#endif
- else
+ } else
QVERIFY2(false, "Unknown view type");
page->settings()->setFontFamily(QWebSettings::SerifFont, "FooSerifFont");
@@ -1341,17 +1439,32 @@ void tst_QWebPage::inputMethods()
QMouseEvent evrel(QEvent::MouseButtonRelease, inputs.at(0).geometry().center(), Qt::LeftButton, Qt::NoButton, Qt::NoModifier);
page->event(&evrel);
-#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
- QVERIFY(!viewEventSpy.contains(QEvent::RequestSoftwareInputPanel));
-#endif
+ // 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<QWebView*>(view))
+ inputPanel = wv->style()->styleHint(QStyle::SH_RequestSoftwareInputPanel);
+ } else if (viewType == "QGraphicsWebView") {
+ if (QGraphicsWebView* wv = qobject_cast<QGraphicsWebView*>(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(viewEventSpy.contains(QEvent::RequestSoftwareInputPanel));
+ else
+ QVERIFY(!viewEventSpy.contains(QEvent::RequestSoftwareInputPanel));
viewEventSpy.clear();
page->event(&evpres);
page->event(&evrel);
-
-#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
QVERIFY(viewEventSpy.contains(QEvent::RequestSoftwareInputPanel));
-#endif
//ImMicroFocus
QVariant variant = page->inputMethodQuery(Qt::ImMicroFocus);
@@ -1379,7 +1492,6 @@ void tst_QWebPage::inputMethods()
page->event(&eventText);
}
-#if QT_VERSION >= 0x040600
//ImMaximumTextLength
variant = page->inputMethodQuery(Qt::ImMaximumTextLength);
QCOMPARE(20, variant.toInt());
@@ -1403,14 +1515,32 @@ void tst_QWebPage::inputMethods()
variant = page->inputMethodQuery(Qt::ImCurrentSelection);
QString selectionValue = variant.value<QString>();
QCOMPARE(selectionValue, QString("eb"));
-#endif
+
+ //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<QString>();
+ QCOMPARE(selectionValue, QString("tWebK"));
//ImSurroundingText
variant = page->inputMethodQuery(Qt::ImSurroundingText);
QString value = variant.value<QString>();
QCOMPARE(value, QString("QtWebKit"));
-#if QT_VERSION >= 0x040600
{
QList<QInputMethodEvent::Attribute> attributes;
// Clear the selection, so the next test does not clear any contents.
@@ -1424,7 +1554,112 @@ void tst_QWebPage::inputMethods()
variant = page->inputMethodQuery(Qt::ImSurroundingText);
value = variant.value<QString>();
QCOMPARE(value, QString("QtWebKit"));
-#endif
+
+ // 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
+ page->event(&evpres);
+ page->event(&evrel);
+
+ {
+ QList<QInputMethodEvent::Attribute> 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<QString>();
+ 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<QString>();
+ QCOMPARE(selectionValue, QString("WebKit"));
+
+ //RIGHT to LEFT selection
+ //Deselect the selection (this moves the current cursor to the end of the text)
+ page->event(&evpres);
+ page->event(&evrel);
+
+ //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<QString>();
+ 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<QString>();
+ QCOMPARE(selectionValue, QString("QtWebK"));
+
+ //END - Tests for Selection when the Editor is not in Composition mode
//ImhHiddenText
QMouseEvent evpresPassword(QEvent::MouseButtonPress, inputs.at(1).geometry().center(), Qt::LeftButton, Qt::NoButton, Qt::NoModifier);
@@ -1433,13 +1668,11 @@ void tst_QWebPage::inputMethods()
page->event(&evrelPassword);
QVERIFY(inputMethodEnabled(view));
-#if QT_VERSION >= 0x040600
QVERIFY(inputMethodHints(view) & Qt::ImhHiddenText);
page->event(&evpres);
page->event(&evrel);
QVERIFY(!(inputMethodHints(view) & Qt::ImhHiddenText));
-#endif
page->mainFrame()->setHtml("<html><body><p>nothing to input here");
viewEventSpy.clear();
@@ -1452,15 +1685,383 @@ void tst_QWebPage::inputMethods()
page->event(&evrel);
}
-#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
QVERIFY(!viewEventSpy.contains(QEvent::RequestSoftwareInputPanel));
-#endif
+
+ //START - Test for sending empty QInputMethodEvent
+ page->mainFrame()->setHtml("<html><body>" \
+ "<input type='text' id='input3' value='QtWebKit2'/>" \
+ "</body></html>");
+ 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("<html><body>" \
+ "<input type='text' id='input4' value='QtWebKit inputMethod'/>" \
+ "</body></html>");
+ 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<QInputMethodEvent::Attribute> 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<QString>();
+ QCOMPARE(selectionValue, QString(""));
+
+ variant = page->inputMethodQuery(Qt::ImSurroundingText);
+ QString surroundingValue = variant.value<QString>();
+ 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<QInputMethodEvent::Attribute> attributes;
+ QInputMethodEvent event("m", attributes);
+ page->event(&event);
+ }
+
+ // ImCurrentSelection
+ variant = page->inputMethodQuery(Qt::ImCurrentSelection);
+ selectionValue = variant.value<QString>();
+ QCOMPARE(selectionValue, QString(""));
+
+ // ImSurroundingText
+ variant = page->inputMethodQuery(Qt::ImSurroundingText);
+ surroundingValue = variant.value<QString>();
+ 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<QInputMethodEvent::Attribute> attributes;
+ QInputMethodEvent event("n", attributes);
+ page->event(&event);
+ }
+
+ // ImCurrentSelection
+ variant = page->inputMethodQuery(Qt::ImCurrentSelection);
+ selectionValue = variant.value<QString>();
+ QCOMPARE(selectionValue, QString(""));
+
+ // ImSurroundingText
+ variant = page->inputMethodQuery(Qt::ImSurroundingText);
+ surroundingValue = variant.value<QString>();
+ 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<QInputMethodEvent::Attribute> attributes;
+ QInputMethodEvent event("", attributes);
+ event.setCommitString("o");
+ page->event(&event);
+ }
+
+ // ImCurrentSelection
+ variant = page->inputMethodQuery(Qt::ImCurrentSelection);
+ selectionValue = variant.value<QString>();
+ QCOMPARE(selectionValue, QString(""));
+
+ // ImSurroundingText
+ variant = page->inputMethodQuery(Qt::ImSurroundingText);
+ surroundingValue = variant.value<QString>();
+ 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<QInputMethodEvent::Attribute> attributes;
+ QInputMethodEvent event("d", attributes);
+ page->event(&event);
+ }
+
+ // ImCurrentSelection
+ variant = page->inputMethodQuery(Qt::ImCurrentSelection);
+ selectionValue = variant.value<QString>();
+ QCOMPARE(selectionValue, QString(""));
+
+ // ImSurroundingText
+ variant = page->inputMethodQuery(Qt::ImSurroundingText);
+ surroundingValue = variant.value<QString>();
+ 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<QInputMethodEvent::Attribute> attributes;
+ QInputMethodEvent event("", attributes);
+ event.setCommitString("e");
+ page->event(&event);
+ }
+
+ // ImCurrentSelection
+ variant = page->inputMethodQuery(Qt::ImCurrentSelection);
+ selectionValue = variant.value<QString>();
+ QCOMPARE(selectionValue, QString(""));
+
+ // ImSurroundingText
+ variant = page->inputMethodQuery(Qt::ImSurroundingText);
+ surroundingValue = variant.value<QString>();
+ 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<QInputMethodEvent::Attribute> attributes;
+ QInputMethodEvent event("t", attributes);
+ page->event(&event);
+ }
+
+ // ImCurrentSelection
+ variant = page->inputMethodQuery(Qt::ImCurrentSelection);
+ selectionValue = variant.value<QString>();
+ QCOMPARE(selectionValue, QString(""));
+
+ // ImSurroundingText
+ variant = page->inputMethodQuery(Qt::ImSurroundingText);
+ surroundingValue = variant.value<QString>();
+ 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<QInputMethodEvent::Attribute> attributes;
+ QInputMethodEvent event("", attributes);
+ event.setCommitString("t");
+ page->event(&event);
+ }
+
+ // ImCurrentSelection
+ variant = page->inputMethodQuery(Qt::ImCurrentSelection);
+ selectionValue = variant.value<QString>();
+ QCOMPARE(selectionValue, QString(""));
+
+ // ImSurroundingText
+ variant = page->inputMethodQuery(Qt::ImSurroundingText);
+ surroundingValue = variant.value<QString>();
+ 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<QString>();
+ QCOMPARE(selectionValue, QString("inputMethodt"));
+
+ // ImSurroundingText
+ variant = page->inputMethodQuery(Qt::ImSurroundingText);
+ surroundingValue = variant.value<QString>();
+ 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<QInputMethodEvent::Attribute> attributes;
+ QInputMethodEvent event("w", attributes);
+ page->event(&event);
+ }
+
+ // ImCurrentSelection
+ variant = page->inputMethodQuery(Qt::ImCurrentSelection);
+ selectionValue = variant.value<QString>();
+ QCOMPARE(selectionValue, QString(""));
+
+ // ImSurroundingText
+ variant = page->inputMethodQuery(Qt::ImSurroundingText);
+ surroundingValue = variant.value<QString>();
+ 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<QInputMethodEvent::Attribute> attributes;
+ QInputMethodEvent event("", attributes);
+ event.setCommitString("2");
+ page->event(&event);
+ }
+
+ // ImCurrentSelection
+ variant = page->inputMethodQuery(Qt::ImCurrentSelection);
+ selectionValue = variant.value<QString>();
+ QCOMPARE(selectionValue, QString(""));
+
+ // ImSurroundingText
+ variant = page->inputMethodQuery(Qt::ImSurroundingText);
+ surroundingValue = variant.value<QString>();
+ 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);
delete container;
}
-// import a little DRT helper function to trigger the garbage collector
-void QWEBKIT_EXPORT qt_drt_garbageCollector_collect();
+void tst_QWebPage::inputMethodsTextFormat_data()
+{
+ QTest::addColumn<QString>("string");
+ QTest::addColumn<int>("start");
+ QTest::addColumn<int>("length");
+
+ QTest::newRow("") << QString("") << 0 << 0;
+ QTest::newRow("Q") << QString("Q") << 0 << 1;
+ QTest::newRow("Qt") << QString("Qt") << 0 << 1;
+ QTest::newRow("Qt") << QString("Qt") << 0 << 2;
+ QTest::newRow("Qt") << QString("Qt") << 1 << 1;
+ QTest::newRow("Qt ") << QString("Qt ") << 0 << 1;
+ QTest::newRow("Qt ") << QString("Qt ") << 1 << 1;
+ QTest::newRow("Qt ") << QString("Qt ") << 2 << 1;
+ QTest::newRow("Qt ") << QString("Qt ") << 2 << -1;
+ QTest::newRow("Qt ") << QString("Qt ") << -2 << 3;
+ QTest::newRow("Qt ") << QString("Qt ") << 0 << 3;
+ QTest::newRow("Qt by") << QString("Qt by") << 0 << 1;
+ QTest::newRow("Qt by Nokia") << QString("Qt by Nokia") << 0 << 1;
+}
+
+
+void tst_QWebPage::inputMethodsTextFormat()
+{
+ QWebPage* page = new QWebPage;
+ QWebView* view = new QWebView;
+ view->setPage(page);
+ page->settings()->setFontFamily(QWebSettings::SerifFont, "FooSerifFont");
+ page->mainFrame()->setHtml("<html><body>" \
+ "<input type='text' id='input1' style='font-family: serif' value='' maxlength='20'/>");
+ page->mainFrame()->evaluateJavaScript("document.getElementById('input1').focus()");
+ page->mainFrame()->setFocus();
+ view->show();
+
+ QFETCH(QString, string);
+ QFETCH(int, start);
+ QFETCH(int, length);
+
+ QList<QInputMethodEvent::Attribute> attrs;
+ QTextCharFormat format;
+ format.setUnderlineStyle(QTextCharFormat::SingleUnderline);
+ format.setUnderlineColor(Qt::red);
+ attrs.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, start, length, format));
+ QInputMethodEvent im(string, attrs);
+ page->event(&im);
+
+ QTest::qWait(1000);
+
+ delete view;
+}
void tst_QWebPage::protectBindingsRuntimeObjectsFromCollector()
{
@@ -1478,7 +2079,7 @@ void tst_QWebPage::protectBindingsRuntimeObjectsFromCollector()
newPage->mainFrame()->evaluateJavaScript("testme('foo')");
- qt_drt_garbageCollector_collect();
+ DumpRenderTreeSupportQt::garbageCollectorCollect();
// don't crash!
newPage->mainFrame()->evaluateJavaScript("testme('bar')");
@@ -1603,7 +2204,8 @@ public:
{
ErrorPageExtensionReturn* errorPage = static_cast<ErrorPageExtensionReturn*>(output);
- errorPage->content = "data:text/html,error";
+ errorPage->contentType = "text/html";
+ errorPage->content = "error";
return true;
}
};
@@ -1620,7 +2222,7 @@ void tst_QWebPage::errorPageExtension()
page->mainFrame()->setUrl(QUrl("http://non.existent/url"));
QTRY_COMPARE(spyLoadFinished.count(), 2);
- QCOMPARE(page->mainFrame()->toPlainText(), QString("data:text/html,error"));
+ QCOMPARE(page->mainFrame()->toPlainText(), QString("error"));
QCOMPARE(page->history()->count(), 2);
QCOMPARE(page->history()->currentItem().url(), QUrl("http://non.existent/url"));
QCOMPARE(page->history()->canGoBack(), true);
@@ -1647,14 +2249,15 @@ void tst_QWebPage::errorPageExtensionInIFrames()
ErrorPage* page = new ErrorPage;
m_view->setPage(page);
- m_view->setHtml(QString("data:text/html,"
- "<h1>h1</h1>"
- "<iframe src='data:text/html,<p/>p'></iframe>"
- "<iframe src='non-existent.html'></iframe>"));
+ m_view->page()->mainFrame()->load(QUrl(
+ "data:text/html,"
+ "<h1>h1</h1>"
+ "<iframe src='data:text/html,<p/>p'></iframe>"
+ "<iframe src='http://non.existent/url'></iframe>"));
QSignalSpy spyLoadFinished(m_view, SIGNAL(loadFinished(bool)));
QTRY_COMPARE(spyLoadFinished.count(), 1);
- QCOMPARE(page->mainFrame()->childFrames()[1]->toPlainText(), QString("data:text/html,error"));
+ QCOMPARE(page->mainFrame()->childFrames()[1]->toPlainText(), QString("error"));
m_view->setPage(0);
}
@@ -1668,11 +2271,43 @@ void tst_QWebPage::errorPageExtensionInFrameset()
QSignalSpy spyLoadFinished(m_view, SIGNAL(loadFinished(bool)));
QTRY_COMPARE(spyLoadFinished.count(), 1);
- QCOMPARE(page->mainFrame()->childFrames()[1]->toPlainText(), QString("data:text/html,error"));
+ QCOMPARE(page->mainFrame()->childFrames()[1]->toPlainText(), QString("error"));
m_view->setPage(0);
}
+class FriendlyWebPage : public QWebPage
+{
+public:
+ friend class tst_QWebPage;
+};
+
+void tst_QWebPage::userAgentApplicationName()
+{
+ const QString oldApplicationName = QCoreApplication::applicationName();
+ FriendlyWebPage page;
+
+ const QString applicationNameMarker = QString::fromUtf8("StrangeName\342\210\236");
+ QCoreApplication::setApplicationName(applicationNameMarker);
+ QVERIFY(page.userAgentForUrl(QUrl()).contains(applicationNameMarker));
+
+ QCoreApplication::setApplicationName(oldApplicationName);
+}
+
+void tst_QWebPage::userAgentLocaleChange()
+{
+ FriendlyWebPage page;
+ m_view->setPage(&page);
+
+ const QString markerString = QString::fromLatin1(" nn-NO)");
+
+ if (page.userAgentForUrl(QUrl()).contains(markerString))
+ QSKIP("marker string already present", SkipSingle);
+
+ m_view->setLocale(QLocale(QString::fromLatin1("nn_NO")));
+ QVERIFY(page.userAgentForUrl(QUrl()).contains(markerString));
+}
+
void tst_QWebPage::crashTests_LazyInitializationOfMainFrame()
{
{
@@ -1746,7 +2381,7 @@ void tst_QWebPage::originatingObjectInNetworkRequests()
m_page->setNetworkAccessManager(networkManager);
networkManager->requests.clear();
- m_view->setHtml(QString("data:text/html,<frameset cols=\"25%,75%\"><frame src=\"data:text/html,"
+ m_view->setHtml(QString("<frameset cols=\"25%,75%\"><frame src=\"data:text/html,"
"<head><meta http-equiv='refresh' content='1'></head>foo \">"
"<frame src=\"data:text/html,bar\"></frameset>"), QUrl());
QVERIFY(::waitForSignal(m_view, SIGNAL(loadFinished(bool))));
@@ -1756,10 +2391,8 @@ void tst_QWebPage::originatingObjectInNetworkRequests()
QList<QWebFrame*> childFrames = m_page->mainFrame()->childFrames();
QCOMPARE(childFrames.count(), 2);
-#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
for (int i = 0; i < 2; ++i)
QVERIFY(qobject_cast<QWebFrame*>(networkManager->requests.at(i).originatingObject()) == childFrames.at(i));
-#endif
}
/**
@@ -1850,5 +2483,121 @@ void tst_QWebPage::showModalDialog()
QCOMPARE(res, QString("This is a test"));
}
+void tst_QWebPage::testStopScheduledPageRefresh()
+{
+ // Without QWebPage::StopScheduledPageRefresh
+ QWebPage page1;
+ page1.setNetworkAccessManager(new TestNetworkManager(&page1));
+ page1.mainFrame()->setHtml("<html><head>"
+ "<meta http-equiv=\"refresh\"content=\"0;URL=qrc:///resources/index.html\">"
+ "</head><body><h1>Page redirects immediately...</h1>"
+ "</body></html>");
+ QVERIFY(::waitForSignal(&page1, SIGNAL(loadFinished(bool))));
+ QTest::qWait(500);
+ QCOMPARE(page1.mainFrame()->url(), QUrl(QLatin1String("qrc:///resources/index.html")));
+
+ // With QWebPage::StopScheduledPageRefresh
+ QWebPage page2;
+ page2.setNetworkAccessManager(new TestNetworkManager(&page2));
+ page2.mainFrame()->setHtml("<html><head>"
+ "<meta http-equiv=\"refresh\"content=\"1;URL=qrc:///resources/index.html\">"
+ "</head><body><h1>Page redirect test with 1 sec timeout...</h1>"
+ "</body></html>");
+ page2.triggerAction(QWebPage::StopScheduledPageRefresh);
+ QTest::qWait(1500);
+ QCOMPARE(page2.mainFrame()->url().toString(), QLatin1String("about:blank"));
+}
+
+void tst_QWebPage::findText()
+{
+ m_view->setHtml(QString("<html><head></head><body><div>foo bar</div></body></html>"));
+ m_page->triggerAction(QWebPage::SelectAll);
+ QVERIFY(!m_page->selectedText().isEmpty());
+ m_page->findText("");
+ QVERIFY(m_page->selectedText().isEmpty());
+ QStringList words = (QStringList() << "foo" << "bar");
+ foreach (QString subString, words) {
+ m_page->findText(subString, QWebPage::FindWrapsAroundDocument);
+ QCOMPARE(m_page->selectedText(), subString);
+ m_page->findText("");
+ QVERIFY(m_page->selectedText().isEmpty());
+ }
+}
+
+struct ImageExtensionMap {
+ const char* extension;
+ const char* mimeType;
+};
+
+static const ImageExtensionMap extensionMap[] = {
+ { "bmp", "image/bmp" },
+ { "css", "text/css" },
+ { "gif", "image/gif" },
+ { "html", "text/html" },
+ { "htm", "text/html" },
+ { "ico", "image/x-icon" },
+ { "jpeg", "image/jpeg" },
+ { "jpg", "image/jpeg" },
+ { "js", "application/x-javascript" },
+ { "mng", "video/x-mng" },
+ { "pbm", "image/x-portable-bitmap" },
+ { "pgm", "image/x-portable-graymap" },
+ { "pdf", "application/pdf" },
+ { "png", "image/png" },
+ { "ppm", "image/x-portable-pixmap" },
+ { "rss", "application/rss+xml" },
+ { "svg", "image/svg+xml" },
+ { "text", "text/plain" },
+ { "tif", "image/tiff" },
+ { "tiff", "image/tiff" },
+ { "txt", "text/plain" },
+ { "xbm", "image/x-xbitmap" },
+ { "xml", "text/xml" },
+ { "xpm", "image/x-xpm" },
+ { "xsl", "text/xsl" },
+ { "xhtml", "application/xhtml+xml" },
+ { "wml", "text/vnd.wap.wml" },
+ { "wmlc", "application/vnd.wap.wmlc" },
+ { 0, 0 }
+};
+
+static QString getMimeTypeForExtension(const QString &ext)
+{
+ const ImageExtensionMap *e = extensionMap;
+ while (e->extension) {
+ if (ext.compare(QLatin1String(e->extension), Qt::CaseInsensitive) == 0)
+ return QLatin1String(e->mimeType);
+ ++e;
+ }
+
+ return QString();
+}
+
+void tst_QWebPage::supportedContentType()
+{
+ QStringList contentTypes;
+
+ // Add supported non image types...
+ contentTypes << "text/html" << "text/xml" << "text/xsl" << "text/plain" << "text/"
+ << "application/xml" << "application/xhtml+xml" << "application/vnd.wap.xhtml+xml"
+ << "application/rss+xml" << "application/atom+xml" << "application/json";
+
+ // Add supported image types...
+ Q_FOREACH(const QByteArray& imageType, QImageWriter::supportedImageFormats()) {
+ const QString mimeType = getMimeTypeForExtension(imageType);
+ if (!mimeType.isEmpty())
+ contentTypes << mimeType;
+ }
+
+ // Get the mime types supported by webkit...
+ const QStringList supportedContentTypes = m_page->supportedContentTypes();
+
+ Q_FOREACH(const QString& mimeType, contentTypes)
+ QVERIFY2(supportedContentTypes.contains(mimeType), QString("'%1' is not a supported content type!").arg(mimeType).toLatin1());
+
+ Q_FOREACH(const QString& mimeType, contentTypes)
+ QVERIFY2(m_page->supportsContentType(mimeType), QString("Cannot handle content types '%1'!").arg(mimeType).toLatin1());
+}
+
QTEST_MAIN(tst_QWebPage)
#include "tst_qwebpage.moc"