" " " ""); view.resize(400, 100); // Call setFocus before show to work around http://bugreports.qt.nokia.com/browse/QTBUG-14762 view.setFocus(); view.show(); QTest::qWaitForWindowShown(&view); view.activateWindow(); QTRY_VERIFY(view.hasFocus()); // open the popup by clicking. check if focus is on the popup const QWebElement webCombo = view.page()->mainFrame()->documentElement().findFirst(QLatin1String("select[name=select]")); QTest::mouseClick(&view, Qt::LeftButton, 0, webCombo.geometry().center()); QObject* webpopup = firstChildByClassName(&view, "QComboBox"); QComboBox* combo = qobject_cast(webpopup); QVERIFY(combo != 0); QTRY_VERIFY(!view.hasFocus() && combo->view()->hasFocus()); // Focus should be on the popup // hide the popup and check if focus is on the page combo->hidePopup(); QTRY_VERIFY(view.hasFocus()); // Focus should be back on the WebView } #endif void tst_QWebFrame::inputFieldFocus() { QWebView view; view.setHtml(""); view.resize(400, 100); view.show(); QTest::qWaitForWindowShown(&view); view.activateWindow(); view.setFocus(); QTRY_VERIFY(view.hasFocus()); // double the flashing time, should at least blink once already int delay = qApp->cursorFlashTime() * 2; // focus the lineedit and check if it blinks bool autoSipEnabled = qApp->autoSipEnabled(); qApp->setAutoSipEnabled(false); const QWebElement inputElement = view.page()->mainFrame()->documentElement().findFirst(QLatin1String("input[type=text]")); QTest::mouseClick(&view, Qt::LeftButton, 0, inputElement.geometry().center()); m_inputFieldsTestView = &view; view.installEventFilter( this ); QTest::qWait(delay); QVERIFY2(m_inputFieldTestPaintCount >= 3, "The input field should have a blinking caret"); qApp->setAutoSipEnabled(autoSipEnabled); } void tst_QWebFrame::hitTestContent() { QString html("

A paragraph




link text"); QWebPage page; QWebFrame* frame = page.mainFrame(); frame->setHtml(html); page.setViewportSize(QSize(200, 0)); //no height so link is not visible const QWebElement linkElement = frame->documentElement().findFirst(QLatin1String("a#link")); QWebHitTestResult result = frame->hitTestContent(linkElement.geometry().center()); QCOMPARE(result.linkText(), QString("link text")); QWebElement link = result.linkElement(); QCOMPARE(link.attribute("target"), QString("_foo")); } void tst_QWebFrame::jsByteArray() { QByteArray ba("hello world"); m_myObject->setByteArrayProperty(ba); // read-only property QCOMPARE(m_myObject->byteArrayProperty(), ba); QString type; QVariant v = evalJSV("myObject.byteArrayProperty"); QCOMPARE(int(v.type()), int(QVariant::ByteArray)); QCOMPARE(v.toByteArray(), ba); } void tst_QWebFrame::ownership() { // test ownership { QPointer ptr = new QObject(); QVERIFY(ptr != 0); { QWebPage page; QWebFrame* frame = page.mainFrame(); frame->addToJavaScriptWindowObject("test", ptr, QScriptEngine::ScriptOwnership); } QVERIFY(ptr == 0); } { QPointer ptr = new QObject(); QVERIFY(ptr != 0); QObject* before = ptr; { QWebPage page; QWebFrame* frame = page.mainFrame(); frame->addToJavaScriptWindowObject("test", ptr, QScriptEngine::QtOwnership); } QVERIFY(ptr == before); delete ptr; } { QObject* parent = new QObject(); QObject* child = new QObject(parent); QWebPage page; QWebFrame* frame = page.mainFrame(); frame->addToJavaScriptWindowObject("test", child, QScriptEngine::QtOwnership); QVariant v = frame->evaluateJavaScript("test"); QCOMPARE(qvariant_cast(v), child); delete parent; v = frame->evaluateJavaScript("test"); QCOMPARE(qvariant_cast(v), (QObject *)0); } { QPointer ptr = new QObject(); QVERIFY(ptr != 0); { QWebPage page; QWebFrame* frame = page.mainFrame(); frame->addToJavaScriptWindowObject("test", ptr, QScriptEngine::AutoOwnership); } // no parent, so it should be like ScriptOwnership QVERIFY(ptr == 0); } { QObject* parent = new QObject(); QPointer child = new QObject(parent); QVERIFY(child != 0); { QWebPage page; QWebFrame* frame = page.mainFrame(); frame->addToJavaScriptWindowObject("test", child, QScriptEngine::AutoOwnership); } // has parent, so it should be like QtOwnership QVERIFY(child != 0); delete parent; } } void tst_QWebFrame::nullValue() { QVariant v = m_view->page()->mainFrame()->evaluateJavaScript("null"); QVERIFY(v.isNull()); } void tst_QWebFrame::baseUrl_data() { QTest::addColumn("html"); QTest::addColumn("loadUrl"); QTest::addColumn("url"); QTest::addColumn("baseUrl"); QTest::newRow("null") << QString() << QUrl() << QUrl("about:blank") << QUrl("about:blank"); QTest::newRow("foo") << QString() << QUrl("http://foobar.baz/") << QUrl("http://foobar.baz/") << QUrl("http://foobar.baz/"); QString html = "" "" "" "" ""; QTest::newRow("customBaseUrl") << html << QUrl("http://foobar.baz/") << QUrl("http://foobar.baz/") << QUrl("http://foobaz.bar/"); } void tst_QWebFrame::baseUrl() { QFETCH(QString, html); QFETCH(QUrl, loadUrl); QFETCH(QUrl, url); QFETCH(QUrl, baseUrl); m_page->mainFrame()->setHtml(html, loadUrl); QCOMPARE(m_page->mainFrame()->url(), url); QCOMPARE(m_page->mainFrame()->baseUrl(), baseUrl); } void tst_QWebFrame::hasSetFocus() { QString html("

top

" \ "