File indexing completed on 2024-05-05 04:59:55
0001 /* This file is part of KDE 0002 SPDX-FileCopyrightText: 2007 David Faure <faure@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #undef QT_NO_CAST_FROM_ASCII 0008 0009 #include "konqpopupmenutest.h" 0010 #include "libkonq_utils.h" 0011 0012 #include <kconfiggroup.h> 0013 #include <kbookmarkmanager.h> 0014 #include <KSharedConfig> 0015 #include <knewfilemenu.h> 0016 #include <kfileitemlistproperties.h> 0017 0018 #include <QTest> 0019 #include <QDebug> 0020 #include <QDir> 0021 #include <QUrl> 0022 #include <QStandardPaths> 0023 #include <QFile> 0024 #include <QTextStream> 0025 #include <QActionGroup> 0026 0027 QTEST_MAIN(KonqPopupMenuTest) 0028 0029 KonqPopupMenuTest::KonqPopupMenuTest() 0030 : m_actionCollection(this) 0031 { 0032 m_appFlags = KonqPopupMenu::NoPlugins; 0033 } 0034 0035 static QStringList extractActionNames(QMenu &menu) 0036 { 0037 menu.aboutToShow(); // signals are now public in Qt5, how convenient :-) 0038 0039 QString lastObjectName; 0040 QStringList ret; 0041 bool lastIsSeparator = false; 0042 for (const QAction *action: menu.actions()) { 0043 if (action->isSeparator()) { 0044 if (!lastIsSeparator) { // Qt gets rid of duplicate separators, so we should too 0045 ret.append(QStringLiteral("separator")); 0046 } 0047 lastIsSeparator = true; 0048 } else { 0049 lastIsSeparator = false; 0050 //qDebug() << action->objectName() << action->metaObject()->className() << action->text(); 0051 const QString objectName = action->objectName(); 0052 if (objectName.isEmpty()) { 0053 if (action->menu()) { // if this fails, then we have an unnamed action somewhere... 0054 ret.append(QStringLiteral("submenu")); 0055 } else { 0056 ret.append("UNNAMED " + action->text()); 0057 } 0058 } else { 0059 if (objectName == QLatin1String("menuaction") // a single service-menu action, or a service-menu submenu: skip; too variable. 0060 || objectName == QLatin1String("actions_submenu")) { 0061 } else if (objectName == QLatin1String("openWith_submenu")) { 0062 ret.append(QStringLiteral("openwith")); 0063 } else if (objectName == QLatin1String("openwith_browse") && lastObjectName == QLatin1String("openwith")) { 0064 // We had "open with foo" followed by openwith_browse, all is well. 0065 // The expected lists only say "openwith" so that they work in both cases 0066 // -> skip the browse action. 0067 } else { 0068 ret.append(objectName); 0069 } 0070 } 0071 } 0072 lastObjectName = action->objectName(); 0073 } 0074 return ret; 0075 0076 } 0077 0078 void KonqPopupMenuTest::initTestCase() 0079 { 0080 QStandardPaths::setTestModeEnabled(true); 0081 0082 KSharedConfig::Ptr dolphin = KSharedConfig::openConfig(QStringLiteral("dolphinrc")); 0083 KConfigGroup(dolphin, "General").writeEntry("ShowCopyMoveMenu", true); 0084 0085 m_thisDirectoryItem = KFileItem(QUrl::fromLocalFile(QDir::currentPath()), QStringLiteral("inode/directory"), S_IFDIR + 0777); 0086 0087 //Create a Makefile. It's simpler to just create a new file than to rely on the path of an existing file 0088 const QString makefileDir = QDir::tempPath() + QStringLiteral("/konqueror-tests/"); 0089 if (!QDir().exists(makefileDir)) { 0090 QDir().mkpath(makefileDir); 0091 m_deleteMakefileDir = true; 0092 } 0093 m_makefilePath = makefileDir + "/Makefile"; 0094 // qDebug() << "Creating" << m_makefilePath; 0095 QFile mf(m_makefilePath); 0096 mf.open(QFile::WriteOnly); 0097 QTextStream ts(&mf); 0098 ts << "main.o : main.c\n\tcc -c main.c\n"; 0099 mf.close(); 0100 QVERIFY2(QFile::exists(m_makefilePath), qPrintable(m_makefilePath)); 0101 0102 m_fileItem = KFileItem(QUrl::fromLocalFile(m_makefilePath), QStringLiteral("text/x-makefile"), S_IFREG + 0660); 0103 m_linkItem = KFileItem(QUrl::fromLocalFile(QStringLiteral("http://www.kde.org/foo")), QStringLiteral("text/html"), S_IFREG + 0660); 0104 m_subDirItem = KFileItem(QUrl::fromLocalFile(QDir::currentPath() + "/CMakeFiles"), QStringLiteral("inode/directory"), S_IFDIR + 0755); 0105 m_cut = KStandardAction::cut(nullptr, nullptr, this); 0106 m_actionCollection.addAction(QStringLiteral("cut"), m_cut); 0107 m_copy = KStandardAction::copy(nullptr, nullptr, this); 0108 m_actionCollection.addAction(QStringLiteral("copy"), m_copy); 0109 m_paste = KStandardAction::paste(nullptr, nullptr, this); 0110 m_actionCollection.addAction(QStringLiteral("paste"), m_paste); 0111 m_pasteTo = KStandardAction::paste(nullptr, nullptr, this); 0112 m_actionCollection.addAction(QStringLiteral("pasteto"), m_pasteTo); 0113 m_properties = new QAction(this); 0114 m_actionCollection.addAction(QStringLiteral("properties"), m_properties); 0115 0116 m_tabHandlingActions = new QActionGroup(this); 0117 m_newWindow = new QAction(m_tabHandlingActions); 0118 m_actionCollection.addAction(QStringLiteral("openInNewWindow"), m_newWindow); 0119 m_newTab = new QAction(m_tabHandlingActions); 0120 m_actionCollection.addAction(QStringLiteral("openInNewTab"), m_newTab); 0121 QAction *separator = new QAction(m_tabHandlingActions); 0122 separator->setSeparator(true); 0123 QCOMPARE(m_tabHandlingActions->actions().count(), 3); 0124 0125 m_previewActions = new QActionGroup(this); 0126 m_preview1 = new QAction(m_previewActions); 0127 m_actionCollection.addAction(QStringLiteral("preview1"), m_preview1); 0128 m_preview2 = new QAction(m_previewActions); 0129 m_actionCollection.addAction(QStringLiteral("preview2"), m_preview2); 0130 0131 m_fileEditActions = new QActionGroup(this); 0132 m_rename = new QAction(m_fileEditActions); 0133 m_actionCollection.addAction(QStringLiteral("rename"), m_rename); 0134 m_trash = new QAction(m_fileEditActions); 0135 m_actionCollection.addAction(QStringLiteral("trash"), m_trash); 0136 0137 m_htmlEditActions = new QActionGroup(this); 0138 // TODO use m_htmlEditActions like in khtml (see khtml_popupmenu.rc) 0139 0140 m_linkActions = new QActionGroup(this); 0141 QAction *saveLinkAs = new QAction(m_linkActions); 0142 m_actionCollection.addAction(QStringLiteral("savelinkas"), saveLinkAs); 0143 QAction *copyLinkLocation = new QAction(m_linkActions); 0144 m_actionCollection.addAction(QStringLiteral("copylinklocation"), copyLinkLocation); 0145 // TODO there's a whole bunch of things for frames, and for images, see khtml_popupmenu.rc 0146 0147 m_partActions = new QActionGroup(this); 0148 separator = new QAction(m_partActions); 0149 separator->setSeparator(true); 0150 m_partActions->addAction(separator); // we better start with a separator 0151 QAction *viewDocumentSource = new QAction(m_partActions); 0152 m_actionCollection.addAction(QStringLiteral("viewDocumentSource"), viewDocumentSource); 0153 0154 m_newMenu = new KNewFileMenu(nullptr); 0155 0156 // Check if extractActionNames works 0157 QMenu popup; 0158 popup.addAction(m_rename); 0159 QMenu *subMenu = new QMenu(&popup); 0160 popup.addMenu(subMenu); 0161 subMenu->addAction(m_trash); 0162 QStringList actions = extractActionNames(popup); 0163 // qDebug() << actions; 0164 QCOMPARE(actions, QStringList({"rename", "submenu"})); 0165 } 0166 0167 void KonqPopupMenuTest::cleanupTestCase() 0168 { 0169 QFileInfo info(m_makefilePath); 0170 QDir dir = info.dir(); 0171 QFile::remove(m_makefilePath); 0172 if (m_deleteMakefileDir) { 0173 QDir().rmdir(dir.path()); 0174 } 0175 } 0176 0177 void KonqPopupMenuTest::testFile() 0178 { 0179 KFileItemList itemList; 0180 itemList << m_fileItem; 0181 QUrl viewUrl = QUrl::fromLocalFile(QDir::currentPath()); 0182 const KonqPopupMenu::Flags flags = m_appFlags 0183 | KonqPopupMenu::ShowProperties 0184 | KonqPopupMenu::ShowUrlOperations; 0185 KonqPopupMenu::ActionGroupMap actionGroups; 0186 actionGroups.insert(KonqPopupMenu::TabHandlingActions, m_tabHandlingActions->actions()); 0187 actionGroups.insert(KonqPopupMenu::EditActions, m_fileEditActions->actions()); 0188 actionGroups.insert(KonqPopupMenu::PreviewActions, QList<QAction *>() << m_preview1); 0189 0190 KonqPopupMenu popup(itemList, viewUrl, m_actionCollection, flags, 0191 nullptr /*parent*/); 0192 popup.setNewFileMenu(m_newMenu); 0193 popup.setActionGroups(actionGroups); 0194 0195 QStringList actions = extractActionNames(popup); 0196 actions.removeAll(QStringLiteral("services_submenu")); 0197 0198 // Be tolerant with openwith, it could be there once or twice 0199 if (actions.count(QStringLiteral("openwith")) == 2) { 0200 actions.removeOne(QStringLiteral("openwith")); 0201 } 0202 // qDebug() << actions; 0203 QStringList expectedActions { 0204 QStringLiteral("openInNewWindow"), 0205 QStringLiteral("openInNewTab"), 0206 QStringLiteral("separator") , 0207 QStringLiteral("cut"), 0208 QStringLiteral("copy"), 0209 QStringLiteral("rename"), 0210 QStringLiteral("trash") , 0211 QStringLiteral("openwith") , 0212 QStringLiteral("separator") , 0213 QStringLiteral("preview1") , 0214 QStringLiteral("separator") 0215 }; 0216 0217 // These are provided by Dolphin and depend on its configuration. 0218 // If actions contains copyTo_submenu, it means they exist, so add them 0219 if (actions.contains("copyTo_submenu")) { 0220 QStringList extraActions { 0221 QStringLiteral("copyTo_submenu"), 0222 QStringLiteral("moveTo_submenu"), 0223 QStringLiteral("separator") 0224 }; 0225 expectedActions.append(extraActions); 0226 } 0227 0228 expectedActions << QStringLiteral("properties"); 0229 // qDebug() << "Expected:" << expectedActions; 0230 0231 QCOMPARE(actions, expectedActions); 0232 } 0233 0234 void KonqPopupMenuTest::testFileInReadOnlyDirectory() 0235 { 0236 const KFileItem item(QUrl::fromLocalFile(QStringLiteral("/etc/passwd"))); 0237 KFileItemList itemList; 0238 itemList << item; 0239 0240 KFileItemListProperties capabilities(itemList); 0241 QVERIFY(!capabilities.supportsMoving()); 0242 0243 QUrl viewUrl = QUrl::fromLocalFile(QStringLiteral("/etc")); 0244 const KonqPopupMenu::Flags flags = m_appFlags 0245 | KonqPopupMenu::ShowProperties 0246 | KonqPopupMenu::ShowUrlOperations; 0247 KonqPopupMenu::ActionGroupMap actionGroups; 0248 actionGroups.insert(KonqPopupMenu::TabHandlingActions, m_tabHandlingActions->actions()); 0249 // DolphinPart doesn't add rename/trash when supportsMoving is false 0250 // Maybe we should test dolphinpart directly :) 0251 //actionGroups.insert(KonqPopupMenu::EditActions, m_fileEditActions->actions()); 0252 actionGroups.insert(KonqPopupMenu::PreviewActions, QList<QAction *>() << m_preview1); 0253 0254 KonqPopupMenu popup(itemList, viewUrl, m_actionCollection, flags); 0255 popup.setNewFileMenu(m_newMenu); 0256 popup.setActionGroups(actionGroups); 0257 0258 QStringList actions = extractActionNames(popup); 0259 actions.removeAll(QStringLiteral("services_submenu")); 0260 // Be tolerant with openwith, it could be there once or twice 0261 if (actions.count(QStringLiteral("openwith")) == 2) { 0262 actions.removeOne(QStringLiteral("openwith")); 0263 } 0264 // qDebug() << actions; 0265 0266 QStringList expectedActions { 0267 QStringLiteral("openInNewWindow"), 0268 QStringLiteral("openInNewTab"), 0269 QStringLiteral("separator"), 0270 QStringLiteral("copy"), 0271 QStringLiteral("openwith"), 0272 QStringLiteral("separator"), 0273 QStringLiteral("preview1"), 0274 QStringLiteral("separator"), 0275 }; 0276 // copyTo_submenu is provided by Dolphin and depends on its configuration. 0277 if (actions.contains(QStringLiteral("copyTo_submenu"))) { 0278 expectedActions.append({QStringLiteral("copyTo_submenu"), QStringLiteral("separator")}); 0279 } 0280 expectedActions << QStringLiteral("properties"); 0281 // qDebug() << "Expected:" << expectedActions; 0282 0283 QCOMPARE(actions, expectedActions); 0284 } 0285 0286 void KonqPopupMenuTest::testFilePreviewSubMenu() 0287 { 0288 // Same as testFile, but this time the "preview" action group has more than one action 0289 KFileItemList itemList; 0290 itemList << m_fileItem; 0291 QUrl viewUrl = QUrl::fromLocalFile(QDir::currentPath()); 0292 const KonqPopupMenu::Flags flags = m_appFlags 0293 | KonqPopupMenu::ShowProperties 0294 | KonqPopupMenu::ShowUrlOperations; 0295 KonqPopupMenu::ActionGroupMap actionGroups; 0296 actionGroups.insert(KonqPopupMenu::TabHandlingActions, m_tabHandlingActions->actions()); 0297 actionGroups.insert(KonqPopupMenu::EditActions, m_fileEditActions->actions()); 0298 actionGroups.insert(KonqPopupMenu::PreviewActions, m_previewActions->actions()); 0299 0300 KonqPopupMenu popup(itemList, viewUrl, m_actionCollection, flags); 0301 popup.setNewFileMenu(m_newMenu); 0302 popup.setActionGroups(actionGroups); 0303 0304 QStringList actions = extractActionNames(popup); 0305 actions.removeAll(QStringLiteral("services_submenu")); 0306 // Be tolerant with openwith, it could be there once or twice 0307 if (actions.count(QStringLiteral("openwith")) == 2) { 0308 actions.removeOne(QStringLiteral("openwith")); 0309 } 0310 // qDebug() << actions; 0311 0312 QStringList expectedActions { 0313 QStringLiteral("openInNewWindow"), 0314 QStringLiteral("openInNewTab"), 0315 QStringLiteral("separator"), 0316 QStringLiteral("cut"), 0317 QStringLiteral("copy"), 0318 QStringLiteral("rename"), 0319 QStringLiteral("trash"), 0320 QStringLiteral("openwith"), 0321 QStringLiteral("separator"), 0322 QStringLiteral("preview_submenu"), 0323 QStringLiteral("separator") 0324 }; 0325 if (actions.contains("copyTo_submenu")) { 0326 QStringList extraActions { 0327 QStringLiteral("copyTo_submenu"), 0328 QStringLiteral("moveTo_submenu"), 0329 QStringLiteral("separator") 0330 }; 0331 expectedActions.append(extraActions); 0332 } 0333 expectedActions.append({QStringLiteral("properties")}); 0334 // qDebug() << "Expected:" << expectedActions; 0335 0336 QCOMPARE(actions, expectedActions); 0337 } 0338 0339 void KonqPopupMenuTest::testSubDirectory() 0340 { 0341 KFileItemList itemList; 0342 itemList << m_subDirItem; 0343 QUrl viewUrl = QUrl::fromLocalFile(QDir::currentPath()); 0344 0345 const KonqPopupMenu::Flags flags = m_appFlags 0346 | KonqPopupMenu::ShowProperties 0347 | KonqPopupMenu::ShowUrlOperations; 0348 KonqPopupMenu::ActionGroupMap actionGroups; 0349 actionGroups.insert(KonqPopupMenu::TabHandlingActions, m_tabHandlingActions->actions()); 0350 actionGroups.insert(KonqPopupMenu::EditActions, m_fileEditActions->actions()); 0351 actionGroups.insert(KonqPopupMenu::PreviewActions, m_previewActions->actions()); 0352 0353 KonqPopupMenu popup(itemList, viewUrl, m_actionCollection, flags); 0354 popup.setNewFileMenu(m_newMenu); 0355 popup.setActionGroups(actionGroups); 0356 QStringList actions = extractActionNames(popup); 0357 actions.removeAll(QStringLiteral("services_submenu")); 0358 // qDebug() << actions; 0359 QStringList expectedActions{ 0360 QStringLiteral("openInNewWindow"), 0361 QStringLiteral("openInNewTab"), 0362 QStringLiteral("separator"), 0363 QStringLiteral("cut"), 0364 QStringLiteral("copy"), 0365 QStringLiteral("rename"), 0366 QStringLiteral("trash"), 0367 QStringLiteral("openwith"), 0368 QStringLiteral("separator"), 0369 QStringLiteral("preview_submenu"), 0370 // It seems it has been moved to a submenu 0371 // QStringLiteral("open-terminal-here"), 0372 QStringLiteral("separator") 0373 }; 0374 0375 // These are provided by Dolphin and depend on its configuration. 0376 // If actions contains copyTo_submenu, it means they exist, so add them 0377 if (actions.contains("copyTo_submenu")) { 0378 QStringList extraActions { 0379 QStringLiteral("copyTo_submenu"), 0380 QStringLiteral("moveTo_submenu"), 0381 QStringLiteral("separator") 0382 }; 0383 expectedActions.append(extraActions); 0384 } 0385 expectedActions << QStringLiteral("properties"); 0386 // qDebug() << "Expected:" << expectedActions; 0387 QCOMPARE(actions, expectedActions); 0388 } 0389 0390 void KonqPopupMenuTest::testViewDirectory() 0391 { 0392 KFileItemList itemList; 0393 itemList << m_thisDirectoryItem; 0394 QUrl viewUrl = m_thisDirectoryItem.url(); 0395 const KonqPopupMenu::Flags flags = m_appFlags | 0396 KonqPopupMenu::ShowCreateDirectory | 0397 KonqPopupMenu::ShowUrlOperations | 0398 KonqPopupMenu::ShowProperties; 0399 // KonqMainWindow says: doTabHandling = !openedForViewURL && ... So we don't add tabhandling here 0400 KonqPopupMenu::ActionGroupMap actionGroups; 0401 actionGroups.insert(KonqPopupMenu::PreviewActions, m_previewActions->actions()); 0402 0403 KonqPopupMenu popup(itemList, viewUrl, m_actionCollection, flags); 0404 popup.setNewFileMenu(m_newMenu); 0405 popup.setActionGroups(actionGroups); 0406 0407 QStringList actions = extractActionNames(popup); 0408 actions.removeAll(QStringLiteral("services_submenu")); 0409 // qDebug() << actions; 0410 QStringList expectedActions { 0411 QStringLiteral("newmenu"), 0412 QStringLiteral("separator") , 0413 QStringLiteral("paste") , 0414 QStringLiteral("openwith") , 0415 QStringLiteral("separator") , 0416 QStringLiteral("preview_submenu"), 0417 // It seems it has been moved to a submenu 0418 // QStringLiteral("open-terminal-here"), 0419 QStringLiteral("separator") 0420 }; 0421 // These are provided by Dolphin and depend on its configuration. 0422 // If actions contains copyTo_submenu, it means they exist, so add them 0423 if (actions.contains("copyTo_submenu")) { 0424 QStringList extraActions { 0425 QStringLiteral("copyTo_submenu"), 0426 QStringLiteral("moveTo_submenu"), 0427 QStringLiteral("separator") 0428 }; 0429 expectedActions.append(extraActions); 0430 } 0431 expectedActions << QStringLiteral("properties"); 0432 // qDebug() << "Expected:" << expectedActions; 0433 QCOMPARE(actions, expectedActions); 0434 } 0435 0436 void KonqPopupMenuTest::testViewReadOnlyDirectory() 0437 { 0438 KFileItem rootItem(QUrl::fromLocalFile(QDir::rootPath()), QStringLiteral("inode/directory"), KFileItem::Unknown); 0439 KFileItemList itemList; 0440 itemList << rootItem; 0441 QUrl viewUrl = rootItem.url(); 0442 const KonqPopupMenu::Flags flags = m_appFlags | 0443 KonqPopupMenu::ShowCreateDirectory | 0444 KonqPopupMenu::ShowUrlOperations | 0445 KonqPopupMenu::ShowProperties; 0446 // KonqMainWindow says: doTabHandling = !openedForViewURL && ... So we don't add tabhandling here 0447 KonqPopupMenu::ActionGroupMap actionGroups; 0448 actionGroups.insert(KonqPopupMenu::PreviewActions, m_previewActions->actions()); 0449 0450 KonqPopupMenu popup(itemList, viewUrl, m_actionCollection, flags); 0451 popup.setNewFileMenu(m_newMenu); 0452 popup.setActionGroups(actionGroups); 0453 0454 QStringList actions = extractActionNames(popup); 0455 actions.removeAll(QStringLiteral("services_submenu")); 0456 // qDebug() << actions; 0457 QStringList expectedActions { 0458 // "paste" // no paste since readonly 0459 QStringLiteral("openwith"), 0460 QStringLiteral("separator"), 0461 QStringLiteral("preview_submenu"), 0462 // It seems it has been moved to a submenu 0463 // QStringLiteral("open-terminal-here"), 0464 QStringLiteral("separator"), 0465 }; 0466 0467 // This is provided by Dolphin and depends on its configuration. 0468 // If actions contains copyTo_submenu, it means they exist, so add them 0469 if (actions.contains("copyTo_submenu")) { 0470 QStringList extraActions { 0471 QStringLiteral("copyTo_submenu"), 0472 // no moveTo_submenu, since readonly , 0473 QStringLiteral("separator") 0474 }; 0475 expectedActions.append(extraActions); 0476 expectedActions << QStringLiteral("properties"); 0477 } 0478 // qDebug() << "Expected:" << expectedActions; 0479 QCOMPARE(actions, expectedActions); 0480 } 0481 0482 void KonqPopupMenuTest::testHtmlLink() 0483 { 0484 KFileItemList itemList; 0485 itemList << m_linkItem; 0486 QUrl viewUrl(QStringLiteral("http://www.kde.org")); 0487 const KonqPopupMenu::Flags flags = m_appFlags 0488 | KonqPopupMenu::ShowBookmark 0489 | KonqPopupMenu::IsLink; 0490 KonqPopupMenu::ActionGroupMap actionGroups; 0491 actionGroups.insert(KonqPopupMenu::TabHandlingActions, m_tabHandlingActions->actions()); 0492 actionGroups.insert(KonqPopupMenu::EditActions, m_htmlEditActions->actions()); 0493 actionGroups.insert(KonqPopupMenu::PreviewActions, m_previewActions->actions()); 0494 actionGroups.insert(KonqPopupMenu::LinkActions, m_linkActions->actions()); 0495 actionGroups.insert(KonqPopupMenu::CustomActions, m_partActions->actions()); 0496 KonqPopupMenu popup(itemList, viewUrl, m_actionCollection, flags); 0497 popup.setNewFileMenu(m_newMenu); 0498 popup.setActionGroups(actionGroups); 0499 popup.setBookmarkManager(Konq::userBookmarksManager()); 0500 0501 QStringList actions = extractActionNames(popup); 0502 // Be tolerant with openwith, it could be there once or twice 0503 if (actions.count(QStringLiteral("openwith")) == 2) { 0504 actions.removeOne(QStringLiteral("openwith")); 0505 } 0506 // qDebug() << actions; 0507 0508 QStringList expectedActions { 0509 QStringLiteral("openInNewWindow"), 0510 QStringLiteral("openInNewTab"), 0511 QStringLiteral("separator") , 0512 QStringLiteral("bookmark_add"), 0513 QStringLiteral("savelinkas"), 0514 QStringLiteral("copylinklocation"), 0515 QStringLiteral("openwith"), 0516 QStringLiteral("separator"), 0517 QStringLiteral("preview_submenu"), 0518 QStringLiteral("services_submenu"), 0519 QStringLiteral("separator"), 0520 QStringLiteral("viewDocumentSource") 0521 }; 0522 // qDebug() << "Expected:" << expectedActions; 0523 0524 QCOMPARE(actions, expectedActions); 0525 } 0526 0527 void KonqPopupMenuTest::testHtmlPage() 0528 { 0529 KFileItemList itemList; 0530 itemList << m_linkItem; 0531 QUrl viewUrl = m_linkItem.url(); 0532 0533 const KonqPopupMenu::Flags flags = m_appFlags 0534 | KonqPopupMenu::ShowBookmark; 0535 KonqPopupMenu::ActionGroupMap actionGroups; 0536 // KonqMainWindow says: doTabHandling = !openedForViewURL && ... So we don't add tabhandling here 0537 // TODO we could just move that logic to KonqPopupMenu... 0538 //actionGroups.insert(KonqPopupMenu::TabHandlingActions, m_tabHandlingActions->actions()); 0539 actionGroups.insert(KonqPopupMenu::EditActions, m_htmlEditActions->actions()); 0540 actionGroups.insert(KonqPopupMenu::PreviewActions, m_previewActions->actions()); 0541 //actionGroups.insert(KonqPopupMenu::LinkActions, m_linkActions->actions()); 0542 QAction *security = new QAction(m_partActions); 0543 m_actionCollection.addAction(QStringLiteral("security"), security); 0544 QAction *setEncoding = new QAction(m_partActions); 0545 m_actionCollection.addAction(QStringLiteral("setEncoding"), setEncoding); 0546 actionGroups.insert(KonqPopupMenu::CustomActions, m_partActions->actions()); 0547 0548 KonqPopupMenu popup(itemList, viewUrl, m_actionCollection, flags); 0549 popup.setNewFileMenu(m_newMenu); 0550 popup.setActionGroups(actionGroups); 0551 popup.setBookmarkManager(Konq::userBookmarksManager()); 0552 0553 QStringList actions = extractActionNames(popup); 0554 // Be tolerant with openwith, it could be there once or twice 0555 if (actions.count(QStringLiteral("openwith")) == 2) { 0556 actions.removeOne(QStringLiteral("openwith")); 0557 } 0558 // qDebug() << actions; 0559 0560 QStringList expectedActions { 0561 QStringLiteral("bookmark_add"), 0562 QStringLiteral("openwith"), 0563 QStringLiteral("separator"), 0564 QStringLiteral("preview_submenu"), 0565 QStringLiteral("services_submenu"), 0566 QStringLiteral("separator"), 0567 // TODO "stopanimations", 0568 QStringLiteral("viewDocumentSource"), 0569 QStringLiteral("security"), 0570 QStringLiteral("setEncoding") 0571 }; 0572 // qDebug() << "Expected:" << expectedActions; 0573 0574 QCOMPARE(actions, expectedActions); 0575 } 0576 0577 // TODO test ShowBookmark. Probably the same logic? 0578 // TODO separate filemanager and webbrowser bookmark managers, too (share file bookmarks with file dialog) 0579 0580 // TODO test text selection actions in khtml 0581 0582 // TODO trash:/ tests 0583 0584 // TODO test NoDeletion part flag