613class ResizeSpy : public QObject {
614 Q_OBJECT
615public slots:
616 void receiveResize(int width, int height)
617 {
618 m_size = QSize(width, height);
619 emit resized();
620 }
621 QSize size() const { return m_size; }
622
623signals:
624 void resized();
625
626private:
627 QSize m_size;
628};
629
630void tst_QGraphicsWebView::windowResizeEvent()
631{
632 QGraphicsWebView* webView = new QGraphicsWebView();
633 ResizeSpy resizeSpy;
634 resizeSpy.setProperty("resizeCount", 0);
635
636 QString html = "<html><body><script>" \
637 " function onResize() { window.resizeSpy.receiveResize(window.innerWidth, window.innerHeight); }" \
638 " window.addEventListener('resize', onResize , false);" \
639 "</script></body></html>";
640
641 webView->page()->mainFrame()->setHtml(html);
642 webView->page()->mainFrame()->addToJavaScriptWindowObject("resizeSpy", &resizeSpy);
643
644 webView->setGeometry(QRect(0, 0, 1, 1));
645 QVERIFY(::waitForSignal(&resizeSpy, SIGNAL(resized()), 1000));
646 QVERIFY(resizeSpy.size() == QSize(1, 1));
647
648 // FIXME:
649 // The following issues are known and were left intentionally because it was decided that we should wait until
650 // the upstreaming work of the browser's branch is concluded before making any changes to the related code.
651
652 // This is where the properties innerWidth and innerHeight of the window object are actually changing.
653 webView->page()->setActualVisibleContentRect(QRect(10, 10, 10, 10));
654 QEXPECT_FAIL("", "setActualVisibleContentRect should trigger the resize event.", Continue);
655 QVERIFY(::waitForSignal(&resizeSpy, SIGNAL(resized()), 1000));
656
657 webView->setGeometry(QRect(0, 0, 100, 100));
658 QEXPECT_FAIL("", "QGraphicsWebView::setGeometry should not trigger the resize event if setActualVisibleContentRect was used.", Continue);
659 QVERIFY(!::waitForSignal(&resizeSpy, SIGNAL(resized()), 1000));
660
661 QVERIFY(resizeSpy.size() == QSize(10, 10));
662}
663