File indexing completed on 2024-04-21 04:57:52

0001 /* This file is part of the KDE project
0002     SPDX-FileCopyrightText: 2008 David Faure <faure@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include <qtest_gui.h>
0008 #include <QSignalSpy>
0009 #include <konqmainwindow.h>
0010 #include <konqview.h>
0011 
0012 class KonqViewTest : public QObject
0013 {
0014     Q_OBJECT
0015 
0016 private Q_SLOTS:
0017     void initTestCase()
0018     {
0019         QStandardPaths::setTestModeEnabled(true);
0020     }
0021 
0022     void textThenHtml()
0023     {
0024         // This is test for the bug "embed katepart and then type a website URL -> loaded into katepart"
0025         // i.e. KonqView::changePart(), KonqView::ensureViewSupports()
0026 
0027         KonqMainWindow mainWindow;
0028         // we specify the mimetype so that we don't have to wait for a KonqRun
0029         KonqOpenURLRequest req; req.forceAutoEmbed = true;
0030         mainWindow.openUrl(nullptr, QUrl(QStringLiteral("data:text/plain, Hello World")), QStringLiteral("text/plain"), req);
0031         KonqView *view = mainWindow.currentView();
0032         QVERIFY(view);
0033         QVERIFY(view->part());
0034         QSignalSpy spyCompleted(view, SIGNAL(viewCompleted(KonqView*)));
0035         QVERIFY(spyCompleted.wait(10000));
0036         QCOMPARE(view->serviceType(), QString("text/plain"));
0037         const QString firstService = view->service().pluginId();
0038         qDebug() << firstService;
0039         QVERIFY(view->supportsMimeType("text/html")); // it does, since that's a mimetype subclass
0040 
0041         // Now open HTML, as if we typed a URL in the location bar.
0042         KonqOpenURLRequest req2; req2.typedUrl = QStringLiteral("http://www.kde.org");
0043         mainWindow.openUrl(nullptr, QUrl(QStringLiteral("data:text/html, <p>Hello World</p>")), QStringLiteral("text/html"), req2);
0044         qDebug() << view->service().pluginId();
0045         QVERIFY(view->service().pluginId() != firstService);
0046     }
0047 
0048 };
0049 
0050 QTEST_MAIN(KonqViewTest)
0051 
0052 #include "konqviewtest.moc"