From 63d50974f104f3626fee13c24251b91a6b3d046b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= <bjorn.nilsen@nokia.com>
Date: Thu, 4 Feb 2010 14:51:59 +0100
Subject: Stabilize tst_QGraphicsWidget::initialShow2 (new test)

---
 tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp
index 526486e..a7195c4 100644
--- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp
+++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp
@@ -2892,6 +2892,26 @@ void tst_QGraphicsWidget::initialShow2()
         void polishEvent() { update(); }
     };
 
+    // Don't let paint events triggered by the windowing system
+    // influence our test case. We're only interested in knowing
+    // whether a QGraphicsWidget generates an additional repaint
+    // on the inital show. Hence create a dummy scenario to find out
+    // how many repaints we should expect.
+    QGraphicsScene dummyScene(0, 0, 200, 200);
+    dummyScene.addItem(new QGraphicsRectItem(0, 0, 100, 100));
+
+    QGraphicsView *dummyView = new QGraphicsView(&dummyScene);
+    EventSpy paintSpy(dummyView->viewport(), QEvent::Paint);
+    dummyView->show();
+    // Not using QTest::qWaitForWindowShown(&view); on purpose, because there's
+    // a bug in qt_x11_wait_for_window_manager that prevents this test
+    // to pass. Denis is looking into it.
+    QTest::qWait(300);
+    const int expectedRepaintCount = paintSpy.count();
+    delete dummyView;
+    dummyView = 0;
+    QTest::qWait(200);
+
     MyGraphicsWidget *widget = new MyGraphicsWidget;
     widget->resize(100, 100);
 
@@ -2905,7 +2925,7 @@ void tst_QGraphicsWidget::initialShow2()
     // to pass. Denis is looking into it.
     QTest::qWait(300);
 
-    QCOMPARE(widget->repaints, 1);
+    QCOMPARE(widget->repaints, expectedRepaintCount);
 }
 
 void tst_QGraphicsWidget::QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems()
-- 
cgit v0.12