]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/tests/dolphinviewtest_allviewmodes.cpp
Make dolphinviewtest_columns more stable.
[dolphin.git] / src / tests / dolphinviewtest_allviewmodes.cpp
index 3eb78c0d256430146644f269454d063c7585ac91..45f4cb56b902118aaa5f8cf19efafed9831d374e 100644 (file)
@@ -37,6 +37,13 @@ DolphinViewTest_AllViewModes::DolphinViewTest_AllViewModes() {
 }
 
 void DolphinViewTest_AllViewModes::init() {
+    if (mode() == DolphinView::ColumnView) {
+        // In Columns View mode, we need to create a new DolphinView after each
+        // test to make the file-related tests after the first one pass.
+        // TODO: Try to find out if there is a hidden bug in the Columns View that causes this.
+        delete m_view;
+        m_view = new DolphinView(KUrl(m_path), 0);
+    }
     m_view->setMode(mode());
     QVERIFY(verifyCorrectViewMode());
     m_view->resize(200, 300);
@@ -143,13 +150,6 @@ void DolphinViewTest_AllViewModes::testViewPropertySettings()
     m_view->setShowHiddenFiles(false);
     QVERIFY(!m_view->showHiddenFiles());
 
-    if (mode() == DolphinView::ColumnView) {
-        // If the columns view is used, the view is empty before calling qApp->sendPostedEvents.
-        // It seems that some event needs to be processed to see the items in the view.
-        // TODO: Find out why this is needed for the columns view, but not for the other view modes.
-        qApp->sendPostedEvents();
-    }
-
     /** Check that the sort order is correct for different kinds of settings */
 
     // Sort by Name, ascending
@@ -217,14 +217,25 @@ void DolphinViewTest_AllViewModes::testViewPropertySettings()
  * testKeyboardFocus() checks whether a view grabs the keyboard focus.
  *
  * A view may never grab the keyboard focus itself and must respect the focus-state
- * when switching the view mode.
+ * when switching the view mode, see
+ *
+ * https://bugs.kde.org/show_bug.cgi?id=261147
  */
 
 void DolphinViewTest_AllViewModes::testKeyboardFocus()
 {
     const DolphinView::Mode mode = m_view->mode();
 
+    // Move keyboard focus to another widget. To see that this is needed, run only this test,
+    // i.e., pass 'testKeyboardFocus' as a parameter on the command line.
+    QWidget widget;
+    widget.show();
+    QTest::qWaitForWindowShown(&widget);
+    widget.setFocus();
+
     QVERIFY(!m_view->hasFocus());
+
+    // Switch view modes and verify that the view does not get the focus back
     for (int i = 0; i <= DolphinView::MaxModeEnum; ++i) {
         m_view->setMode(static_cast<DolphinView::Mode>(i));
         QVERIFY(!m_view->hasFocus());