diff --git a/src/commands.hxx b/src/commands.hxx index 3d1c965..6529964 100644 --- a/src/commands.hxx +++ b/src/commands.hxx @@ -1397,6 +1397,40 @@ class Timeout: public Command { }; +class Certificate: public Command { + public: + QString tag() const { + return ""; + } + QString description() const { + return + "certificate " + "\n\n" + "Load a CA certificate that will be accepted on SSL connections."; + } + QString command() const { + return ""; + } + std::shared_ptr parse(Script*, QString args, + QStringList&, int) { + std::shared_ptr cmd(new (Certificate)); + cmd->_filename = args.trimmed(); + return cmd; + } + bool execute(Script* script, QWebFrame*) { + Logger log(this, script); + QString filename(script->replacevars(_filename)); + QFile cacertfile(filename); + if (!cacertfile.exists()) throw FileNotFound(filename); + QSslCertificate cacert(&cacertfile); + if (cacert.isNull()) throw NotACertificate(filename); + QSslSocket::addDefaultCaCertificate(cacert); + return true; + } + private: + QString _filename; +}; + /* Template: class : public Command { public: diff --git a/src/exceptions.hxx b/src/exceptions.hxx index fc5fe5d..0c8e521 100644 --- a/src/exceptions.hxx +++ b/src/exceptions.hxx @@ -107,6 +107,13 @@ class FileNotFound: public TestFailed { FileNotFound(QString arg): TestFailed("file not found: "+arg) {} }; +class NotACertificate: public TestFailed { + public: + NotACertificate(QString arg): + TestFailed("file is not a certificate: "+arg) { + } +}; + class NotUnattended: public TestFailed { public: NotUnattended(): TestFailed("web page is not in unattended test mode") {} diff --git a/src/testgui.hxx b/src/testgui.hxx index 6dfed67..82efcc8 100644 --- a/src/testgui.hxx +++ b/src/testgui.hxx @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -49,7 +50,7 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI { void on__load_clicked() { enterText(true); if (_record->isChecked()) - _testscript->appendPlainText("load "+_url->text()); + appendCommand("load "+_url->text()); _web->load(_url->text()); } void on__abort_clicked() { @@ -109,6 +110,7 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI { } void on__actionClear_triggered() { _testscript->clear(); + _log->clear(); _filename.clear(); _actionSave->setEnabled(false); _actionRevertToSaved->setEnabled(false); @@ -171,7 +173,7 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI { void on__web_linkClicked(const QUrl& url) { enterText(true); if (_record->isChecked()) - _testscript->appendPlainText("load "+url.url()); + appendCommand("load "+url.url()); } void on__web_loadProgress(int progress) { enterText(true); @@ -180,7 +182,7 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI { void on__web_loadStarted() { enterText(true); if (_record->isChecked()) - _testscript->appendPlainText("expect loadStarted"); + appendCommand("expect loadStarted"); _progress->setValue(0); _urlStack->setCurrentIndex(PROGRESS_VIEW); } @@ -193,7 +195,7 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI { void on__web_urlChanged(const QUrl& url) { enterText(true); if (_record->isChecked()) - _testscript->appendPlainText("expect urlChanged "+url.url()); + appendCommand("expect urlChanged "+url.url()); } void on__web_selectionChanged() { _source->setPlainText(_web->hasSelection() @@ -203,7 +205,7 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI { void on__web_loadFinished(bool ok) { enterText(true); if (_record->isChecked()) - _testscript->appendPlainText("expect loadFinished " + appendCommand("expect loadFinished " +QString(ok?"true":"false")); _urlStack->setCurrentIndex(URL_VIEW); on__web_selectionChanged(); @@ -222,7 +224,7 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI { void uploadFile(QString filename) { enterText(true); if (_record->isChecked()) - _testscript->appendPlainText("upload "+filename); + appendCommand("upload "+filename); } void unsupportedContent(QNetworkReply* reply) { if (!_record->isChecked()) return; @@ -245,10 +247,19 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI { } void downloadRequested(const QNetworkRequest&) { if (_record->isChecked()) - _testscript->appendPlainText("download2"); + appendCommand("download2"); } - void logging(QString txt) { + void logging(const QString& txt) { _log->appendPlainText(txt); + QScrollBar *vb(_log->verticalScrollBar()); + if (!vb) return; + vb->setValue(vb->maximum()); + } + void appendCommand(const QString& txt) { + _testscript->appendPlainText(txt); + QScrollBar *vb(_testscript->verticalScrollBar()); + if (!vb) return; + vb->setValue(vb->maximum()); } protected: void closeEvent(QCloseEvent* event) { @@ -301,16 +312,16 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI { .match(selected)); if (mooCombo.hasMatch()) { // special treatment for moo tools combobox (e.g. used in joomla) - _testscript->appendPlainText("click "+mooCombo.captured(1)+">a"); - _testscript->appendPlainText("sleep 1"); + appendCommand("click "+mooCombo.captured(1)+">a"); + appendCommand("sleep 1"); } else if (mooComboItem.hasMatch()) { // special treatment for item in moo tools combobox - _testscript->appendPlainText + appendCommand ("click li.active-result[data-option-array-index=\"" +element.attribute("data-option-array-index")+"\"]"); - _testscript->appendPlainText("sleep 1"); + appendCommand("sleep 1"); } else { - _testscript->appendPlainText("click "+selected); + appendCommand("click "+selected); } } } break; @@ -425,8 +436,8 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI { } void store(const QString& selector, QString code) { if (_record->isChecked()) - _testscript->appendPlainText("do "+selector+"\n " - +code.replace("\n", "\\n")); + appendCommand("do "+selector+"\n " + +code.replace("\n", "\\n")); } void execute(const QString& selector, const QString& code) { store(selector, code);