MCPcopy Create free account
hub / github.com/KDE/okular / testPopUpMenuEx

Method testPopUpMenuEx

autotests/jsfunctionstest.cpp:399–440  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

397}
398
399void JSFunctionsTest::testPopUpMenuEx()
400{
401 QScopedPointer<PopupMenuHelper> popupMenuHelper;
402
403 Okular::ScriptAction *action = new Okular::ScriptAction(
404 Okular::JavaScript,
405 QStringLiteral("ret = app.popUpMenuEx( {cName:\"Fruits\", oSubMenu:[{cName:\"Apples\", bMarked:false},{cName:\"Oranges\", bMarked:true}]}, {cName:\"-\"},{cName:\"Beans\", bEnabled:false},{cName:\"Corn\", bEnabled:true} )"));
406
407 popupMenuHelper.reset(new PopupMenuHelper());
408 m_document->processAction(action);
409 QVERIFY(popupMenuHelper->menuFound());
410
411 QJsonArray expected = {
412 QJsonArray {
413 QJsonValue {QStringLiteral("Fruits")},
414 QJsonValue {QStringLiteral("Apples")},
415 QJsonValue {QStringLiteral("Oranges")},
416 },
417 QJsonValue {QStringLiteral("-")},
418 QJsonValue {QStringLiteral("Beans")},
419 QJsonValue {QStringLiteral("Corn")},
420 };
421
422 QString expectedString = QString::fromUtf8(QJsonDocument(expected).toJson());
423 QString resultString = QString::fromUtf8(QJsonDocument(popupMenuHelper->menuTree()).toJson());
424 QString description = QStringLiteral("Expected:\n") + expectedString + QStringLiteral("But got:\n") + resultString;
425 QVERIFY2(expected == popupMenuHelper->menuTree(), description.toUtf8().constData());
426
427 delete action;
428
429 // Test infinite recursion
430 action = new Okular::ScriptAction(Okular::JavaScript, QStringLiteral("\
431 var recursiveMenu = {\"cName\": \"Devil menu\"};\n\
432 recursiveMenu.oSubMenu = [ recursiveMenu ];\n\
433 ret = app.popUpMenuEx( recursiveMenu );"));
434
435 popupMenuHelper.reset(new PopupMenuHelper());
436 m_document->processAction(action);
437 QVERIFY(popupMenuHelper->menuFound());
438 // Must not crash
439 delete action;
440}
441
442/** @brief Checks a single JS action against an expected result
443 *

Callers

nothing calls this directly

Calls 3

menuFoundMethod · 0.80
resetMethod · 0.45
processActionMethod · 0.45

Tested by

no test coverage detected