tests/auto/qlineedit/tst_qlineedit.cpp
changeset 7 f7bc934e204c
parent 3 41300fa6a67c
child 23 89e065397ea6
equal deleted inserted replaced
3:41300fa6a67c 7:f7bc934e204c
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the test suite of the Qt Toolkit.
     7 ** This file is part of the test suite of the Qt Toolkit.
     8 **
     8 **
   269     void task241436_passwordEchoOnEditRestoreEchoMode();
   269     void task241436_passwordEchoOnEditRestoreEchoMode();
   270     void task248948_redoRemovedSelection();
   270     void task248948_redoRemovedSelection();
   271     void taskQTBUG_4401_enterKeyClearsPassword();
   271     void taskQTBUG_4401_enterKeyClearsPassword();
   272     void taskQTBUG_4679_moveToStartEndOfBlock();
   272     void taskQTBUG_4679_moveToStartEndOfBlock();
   273     void taskQTBUG_4679_selectToStartEndOfBlock();
   273     void taskQTBUG_4679_selectToStartEndOfBlock();
       
   274     void taskQTBUG_7395_readOnlyShortcut();
   274 
   275 
   275 protected slots:
   276 protected slots:
   276 #ifdef QT3_SUPPORT
   277 #ifdef QT3_SUPPORT
   277     void lostFocus();
   278     void lostFocus();
   278 #endif
   279 #endif
  3452     QCompleter completer(completions);
  3453     QCompleter completer(completions);
  3453     completer.setCaseSensitivity(Qt::CaseInsensitive);
  3454     completer.setCaseSensitivity(Qt::CaseInsensitive);
  3454     completer.setCompletionMode(QCompleter::InlineCompletion);
  3455     completer.setCompletionMode(QCompleter::InlineCompletion);
  3455     lineEdit.setCompleter(&completer);
  3456     lineEdit.setCompleter(&completer);
  3456     lineEdit.show();
  3457     lineEdit.show();
  3457 #ifdef Q_WS_X11
  3458     QTest::qWaitForWindowShown(&lineEdit);
  3458     // to be safe and avoid failing setFocus with window managers
  3459     QApplication::setActiveWindow(&lineEdit);
  3459     qt_x11_wait_for_window_manager(&lineEdit);
       
  3460 #endif
       
  3461     lineEdit.setFocus();
  3460     lineEdit.setFocus();
  3462     QTRY_VERIFY(lineEdit.hasFocus());
  3461     QTRY_VERIFY(lineEdit.hasFocus());
  3463     QTest::keyPress(&lineEdit, 'a');
  3462     QTest::keyPress(&lineEdit, 'a');
  3464     QTest::keyPress(&lineEdit, Qt::Key_Return);
  3463     QTest::keyPress(&lineEdit, Qt::Key_Return);
  3465     QCOMPARE(lineEdit.text(), completion);
  3464     QCOMPARE(lineEdit.text(), completion);
  3636     QVERIFY(testWidget->hasSelectedText());
  3635     QVERIFY(testWidget->hasSelectedText());
  3637     QCOMPARE(testWidget->selectedText(), text.mid(5));
  3636     QCOMPARE(testWidget->selectedText(), text.mid(5));
  3638 #endif // Q_OS_MAC
  3637 #endif // Q_OS_MAC
  3639 }
  3638 }
  3640 
  3639 
       
  3640 void tst_QLineEdit::taskQTBUG_7395_readOnlyShortcut()
       
  3641 {
       
  3642     //ReadOnly QLineEdit should not intercept shortcut.
       
  3643     QLineEdit le;
       
  3644     le.setReadOnly(true);
       
  3645 
       
  3646     QAction action(QString::fromLatin1("hello"), &le);
       
  3647     action.setShortcut(QString::fromLatin1("p"));
       
  3648     QSignalSpy spy(&action, SIGNAL(triggered()));
       
  3649     le.addAction(&action);
       
  3650 
       
  3651     le.show();
       
  3652     QTest::qWaitForWindowShown(&le);
       
  3653     QApplication::setActiveWindow(&le);
       
  3654     le.setFocus();
       
  3655     QTRY_VERIFY(le.hasFocus());
       
  3656 
       
  3657     QTest::keyClick(0, Qt::Key_P);
       
  3658     QCOMPARE(spy.count(), 1);
       
  3659 }
       
  3660 
  3641 QTEST_MAIN(tst_QLineEdit)
  3661 QTEST_MAIN(tst_QLineEdit)
  3642 #include "tst_qlineedit.moc"
  3662 #include "tst_qlineedit.moc"