2018-01-27 09:57:47 +01:00
|
|
|
/* ============================================================
|
|
|
|
* Falkon - Qt web browser
|
|
|
|
* Copyright (C) 2018 David Rosca <nowrep@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
|
|
|
#include "locationbartest.h"
|
2018-01-27 11:21:10 +01:00
|
|
|
#include "autotests.h"
|
2018-01-27 09:57:47 +01:00
|
|
|
#include "locationbar.h"
|
|
|
|
#include "searchenginesmanager.h"
|
|
|
|
#include "bookmarks.h"
|
|
|
|
#include "bookmarkitem.h"
|
2018-01-29 09:42:24 +01:00
|
|
|
#include "qzsettings.h"
|
2018-01-27 09:57:47 +01:00
|
|
|
|
|
|
|
static void removeBookmarks(BookmarkItem *parent)
|
|
|
|
{
|
|
|
|
for (BookmarkItem *child : parent->children()) {
|
|
|
|
mApp->bookmarks()->removeBookmark(child);
|
|
|
|
removeBookmarks(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocationBarTest::initTestCase()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocationBarTest::cleanupTestCase()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocationBarTest::init()
|
|
|
|
{
|
|
|
|
mApp->searchEnginesManager()->setAllEngines({});
|
|
|
|
removeBookmarks(mApp->bookmarks()->rootItem());
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocationBarTest::loadActionBasicTest()
|
|
|
|
{
|
|
|
|
LocationBar::LoadAction action;
|
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("http://kde.org"));
|
2018-01-27 09:57:47 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Url);
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(action.loadRequest.url(), QUrl(QSL("http://kde.org")));
|
2018-01-27 09:57:47 +01:00
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("kde.org"));
|
2018-01-27 09:57:47 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Url);
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(action.loadRequest.url(), QUrl(QSL("http://kde.org")));
|
2018-01-27 09:57:47 +01:00
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("localhost"));
|
2018-01-27 09:57:47 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Url);
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(action.loadRequest.url(), QUrl(QSL("http://localhost")));
|
2018-01-27 09:57:47 +01:00
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("localhost/test/path?x=2"));
|
2018-01-27 09:57:47 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Url);
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(action.loadRequest.url(), QUrl(QSL("http://localhost/test/path?x=2")));
|
2018-01-27 09:57:47 +01:00
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("host.com/test/path?x=2"));
|
2018-01-27 09:57:47 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Url);
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(action.loadRequest.url(), QUrl(QSL("http://host.com/test/path?x=2")));
|
2018-01-27 09:57:47 +01:00
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("not-url"));
|
2018-01-27 10:28:03 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Search);
|
2018-01-27 09:57:47 +01:00
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("not url with spaces"));
|
2018-01-27 10:28:03 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Search);
|
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("falkon:about"));
|
2018-01-27 09:57:47 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Url);
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(action.loadRequest.url(), QUrl(QSL("falkon:about")));
|
2018-01-27 09:57:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LocationBarTest::loadActionBookmarksTest()
|
|
|
|
{
|
2022-06-19 09:24:25 +02:00
|
|
|
auto* bookmark = new BookmarkItem(BookmarkItem::Url);
|
2023-11-20 23:35:11 +01:00
|
|
|
bookmark->setTitle(QSL("KDE Bookmark title"));
|
|
|
|
bookmark->setUrl(QUrl(QSL("http://kde.org")));
|
|
|
|
bookmark->setKeyword(QSL("kde-bookmark"));
|
2018-01-27 09:57:47 +01:00
|
|
|
mApp->bookmarks()->addBookmark(mApp->bookmarks()->unsortedFolder(), bookmark);
|
|
|
|
|
|
|
|
LocationBar::LoadAction action;
|
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("http://kde.org"));
|
2018-01-27 09:57:47 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Url);
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(action.loadRequest.url(), QUrl(QSL("http://kde.org")));
|
2018-01-27 09:57:47 +01:00
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("kde-bookmark-notkeyword"));
|
2018-01-27 10:28:03 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Search);
|
2018-01-27 09:57:47 +01:00
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("kde-bookmark"));
|
2018-01-27 09:57:47 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Bookmark);
|
|
|
|
QCOMPARE(action.bookmark, bookmark);
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(action.loadRequest.url(), QUrl(QSL("http://kde.org")));
|
2018-01-27 09:57:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LocationBarTest::loadActionSearchTest()
|
|
|
|
{
|
|
|
|
SearchEngine engine;
|
2023-11-20 23:35:11 +01:00
|
|
|
engine.name = QSL("Test Engine");
|
|
|
|
engine.url = QSL("http://test/%s");
|
|
|
|
engine.shortcut = QSL("t");
|
2018-01-27 09:57:47 +01:00
|
|
|
mApp->searchEnginesManager()->addEngine(engine);
|
2018-01-27 10:28:03 +01:00
|
|
|
mApp->searchEnginesManager()->setActiveEngine(engine);
|
2018-01-27 09:57:47 +01:00
|
|
|
|
|
|
|
LocationBar::LoadAction action;
|
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("search term"));
|
2018-01-27 09:57:47 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Search);
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(action.loadRequest.url(), QUrl(QSL("http://test/search%20term")));
|
2018-01-27 09:57:47 +01:00
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("t search term"));
|
2018-01-27 09:57:47 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Search);
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(action.loadRequest.url(), QUrl(QSL("http://test/search%20term")));
|
2018-01-27 09:57:47 +01:00
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL(" ttt-notsearch"));
|
2018-01-27 10:28:03 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Search);
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(action.loadRequest.url(), QUrl(QSL("http://test/ttt-notsearch")));
|
2018-01-27 09:57:47 +01:00
|
|
|
}
|
|
|
|
|
2018-01-27 10:40:36 +01:00
|
|
|
void LocationBarTest::loadAction_kdebug389491()
|
|
|
|
{
|
2018-01-27 12:31:39 +01:00
|
|
|
// "site:website.com searchterm" and "link:website.com" are loaded instead of searched
|
2018-01-27 10:40:36 +01:00
|
|
|
|
|
|
|
SearchEngine engine;
|
2023-11-20 23:35:11 +01:00
|
|
|
engine.name = QSL("Test Engine");
|
|
|
|
engine.url = QSL("http://test/%s");
|
|
|
|
engine.shortcut = QSL("t");
|
2018-01-27 10:40:36 +01:00
|
|
|
mApp->searchEnginesManager()->addEngine(engine);
|
|
|
|
mApp->searchEnginesManager()->setActiveEngine(engine);
|
|
|
|
|
|
|
|
LocationBar::LoadAction action;
|
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("site:website.com searchterm"));
|
2018-01-27 10:40:36 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Search);
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(action.loadRequest.url(), QUrl(QSL("http://test/site%3Awebsite.com%20searchterm")));
|
2018-01-27 10:40:36 +01:00
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("link:website.com"));
|
2018-01-27 12:31:39 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Search);
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(action.loadRequest.url(), QUrl(QSL("http://test/link%3Awebsite.com")));
|
2018-01-27 12:31:39 +01:00
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("http://website.com?search=searchterm and another"));
|
2018-01-27 10:40:36 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Url);
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(action.loadRequest.url(), QUrl(QSL("http://website.com?search=searchterm and another")));
|
2018-01-27 10:40:36 +01:00
|
|
|
}
|
|
|
|
|
2018-01-28 15:45:54 +01:00
|
|
|
void LocationBarTest::loadActionSpecialSchemesTest()
|
|
|
|
{
|
|
|
|
LocationBar::LoadAction action;
|
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("data:image/png;base64,xxxxx"));
|
2018-01-28 15:45:54 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Url);
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(action.loadRequest.url(), QUrl(QSL("data:image/png;base64,xxxxx")));
|
2018-01-28 15:45:54 +01:00
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("falkon:about"));
|
2018-01-28 15:45:54 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Url);
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(action.loadRequest.url(), QUrl(QSL("falkon:about")));
|
2018-01-28 15:45:54 +01:00
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("file:test.html"));
|
2018-01-28 15:45:54 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Url);
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(action.loadRequest.url(), QUrl(QSL("file:test.html")));
|
2018-01-28 15:45:54 +01:00
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("about:blank"));
|
2018-01-28 15:45:54 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Url);
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(action.loadRequest.url(), QUrl(QSL("about:blank")));
|
2018-01-29 22:18:01 +01:00
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("javascript:test"));
|
2018-01-29 22:18:01 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Url);
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(action.loadRequest.url(), QUrl(QSL("javascript:test")));
|
2018-01-29 22:18:01 +01:00
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("javascript:alert(' test ');"));
|
2018-01-29 22:18:01 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Url);
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(action.loadRequest.url(), QUrl(QSL("javascript:alert('%20test%20');")));
|
2018-01-28 15:45:54 +01:00
|
|
|
}
|
|
|
|
|
2018-01-29 09:42:24 +01:00
|
|
|
void LocationBarTest::loadAction_issue2578()
|
|
|
|
{
|
|
|
|
// typed text is not correctly transformed to QUrl when searchFromAddressBar is disabled
|
|
|
|
|
|
|
|
qzSettings->searchFromAddressBar = false;
|
|
|
|
|
|
|
|
LocationBar::LoadAction action;
|
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("github.com"));
|
2018-01-29 09:42:24 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Url);
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(action.loadRequest.url(), QUrl(QSL("http://github.com")));
|
2018-01-29 09:42:24 +01:00
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("github"));
|
2018-01-29 09:42:24 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Url);
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(action.loadRequest.url(), QUrl(QSL("http://github")));
|
2018-01-29 09:42:24 +01:00
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("github/test/path"));
|
2018-01-29 09:42:24 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Url);
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(action.loadRequest.url(), QUrl(QSL("http://github/test/path")));
|
2018-01-29 09:42:24 +01:00
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("localhost"));
|
2018-01-29 09:42:24 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Url);
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(action.loadRequest.url(), QUrl(QSL("http://localhost")));
|
2018-01-29 09:42:24 +01:00
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("localhost/test/path"));
|
2018-01-29 09:42:24 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Url);
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(action.loadRequest.url(), QUrl(QSL("http://localhost/test/path")));
|
2018-01-29 09:42:24 +01:00
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("github.com foo bar"));
|
2018-01-29 09:42:24 +01:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Invalid);
|
|
|
|
}
|
|
|
|
|
2018-03-28 18:54:26 +02:00
|
|
|
void LocationBarTest::loadAction_kdebug392445()
|
|
|
|
{
|
|
|
|
// %20 in url will make it incorrectly treat as web search
|
|
|
|
|
|
|
|
qzSettings->searchFromAddressBar = true;
|
|
|
|
|
|
|
|
LocationBar::LoadAction action;
|
|
|
|
|
2023-11-20 23:35:11 +01:00
|
|
|
action = LocationBar::loadAction(QSL("http://www.example.com/my%20beautiful%20page"));
|
2018-03-28 18:54:26 +02:00
|
|
|
QCOMPARE(action.type, LocationBar::LoadAction::Url);
|
2023-11-20 23:35:11 +01:00
|
|
|
QCOMPARE(action.loadRequest.url(), QUrl(QSL("http://www.example.com/my%20beautiful%20page")));
|
2018-03-28 18:54:26 +02:00
|
|
|
}
|
|
|
|
|
2018-01-27 11:21:10 +01:00
|
|
|
FALKONTEST_MAIN(LocationBarTest)
|