| 1 |
// SPDX-License-Identifier: GPL-3.0-or-later |
| 2 |
|
| 3 |
#include "test_utils.h" |
| 4 |
#include "tests.h" |
| 5 |
#include "tests_common.h" |
| 6 |
|
| 7 |
#include "common/mimetypes.h" |
| 8 |
|
| 9 |
void CoreTests::createTabDialog() |
| 10 |
{ |
| 11 |
const auto tab1 = testTab(1); |
| 12 |
KEYS( |
| 13 |
clipboardBrowserId << "CTRL+T" |
| 14 |
<< tabDialogLineEditId << ":" + tab1 << "ENTER"); |
| 15 |
TEST_SELECTED(tab1 + "\n"); |
| 16 |
} |
| 17 |
|
| 18 |
void CoreTests::showHideAboutDialog() |
| 19 |
{ |
| 20 |
const auto aboutShortcut = keyNameFor(QKeySequence::QKeySequence::WhatsThis); |
| 21 |
KEYS(clipboardBrowserId << aboutShortcut << aboutDialogId); |
| 22 |
KEYS(aboutDialogId << "ESCAPE" << clipboardBrowserId); |
| 23 |
} |
| 24 |
|
| 25 |
void CoreTests::showHideClipboardDialog() |
| 26 |
{ |
| 27 |
TEST( m_test->setClipboard("TEST", "test-format") ); |
| 28 |
KEYS(clipboardBrowserId << "CTRL+SHIFT+C" << clipboardDialogId); |
| 29 |
|
| 30 |
KEYS(clipboardDialogId << "DOWN" << "HOME" << clipboardDialogFormatListId); |
| 31 |
|
| 32 |
KEYS(clipboardDialogFormatListId << keyNameFor(QKeySequence::Copy)); |
| 33 |
#ifdef Q_OS_WIN |
| 34 |
WAIT_FOR_CLIPBOARD("application/x-qt-windows-mime;value=\"test-format\""); |
| 35 |
#else |
| 36 |
WAIT_FOR_CLIPBOARD("test-format"); |
| 37 |
#endif |
| 38 |
|
| 39 |
KEYS(clipboardDialogId << "ESCAPE" << clipboardBrowserId); |
| 40 |
} |
| 41 |
|
| 42 |
void CoreTests::showHideItemDialog() |
| 43 |
{ |
| 44 |
RUN("write" << "test-format" << "TEST", ""); |
| 45 |
RUN("selectItems" << "0", "true\n"); |
| 46 |
|
| 47 |
KEYS(clipboardBrowserId << "F4" << clipboardDialogId); |
| 48 |
|
| 49 |
KEYS(clipboardDialogId << "DOWN" << clipboardDialogFormatListId); |
| 50 |
KEYS(clipboardDialogFormatListId << keyNameFor(QKeySequence::Copy)); |
| 51 |
WAIT_FOR_CLIPBOARD("test-format"); |
| 52 |
|
| 53 |
KEYS(clipboardDialogFormatListId << "DOWN"); |
| 54 |
KEYS(clipboardDialogFormatListId << keyNameFor(QKeySequence::Copy)); |
| 55 |
WAIT_FOR_CLIPBOARD("test-format"); |
| 56 |
|
| 57 |
KEYS(clipboardDialogId << "ESCAPE" << clipboardBrowserId); |
| 58 |
} |
| 59 |
|
| 60 |
void CoreTests::showHideLogDialog() |
| 61 |
{ |
| 62 |
KEYS(clipboardBrowserId << "F12" << logDialogId); |
| 63 |
|
| 64 |
KEYS(logDialogId << "CTRL+A" << "CTRL+C" << logDialogId); |
| 65 |
const QByteArray expectedLog = "Starting callback: onStart"; |
| 66 |
TEST( m_test->verifyClipboard(expectedLog, mimeHtml, false) ); |
| 67 |
|
| 68 |
KEYS(logDialogId << "ESCAPE" << clipboardBrowserId); |
| 69 |
} |
| 70 |
|
| 71 |
void CoreTests::showHideActionHandlerDialog() |
| 72 |
{ |
| 73 |
KEYS(clipboardBrowserId << "CTRL+SHIFT+Z" << actionHandlerDialogId); |
| 74 |
|
| 75 |
KEYS(actionHandlerFilterId << ":onstart" << "TAB" << actionHandlerTableId); |
| 76 |
|
| 77 |
KEYS(actionHandlerTableId << "RIGHT" << "CTRL+C"); |
| 78 |
WAIT_FOR_CLIPBOARD("copyq onStart"); |
| 79 |
|
| 80 |
KEYS(actionHandlerDialogId << "ESCAPE" << clipboardBrowserId); |
| 81 |
} |
| 82 |
|
| 83 |
void CoreTests::shortcutDialogAddShortcut() |
| 84 |
{ |
| 85 |
#ifdef Q_OS_MAC |
| 86 |
SKIP("Mnemonic for focusing shortcut button doesn't work on OS X"); |
| 87 |
#endif |
| 88 |
|
| 89 |
RUN("setCommands([{name: 'test', inMenu: true, cmd: 'copyq add OK'}])", ""); |
| 90 |
RUN("commands()[0].shortcuts", ""); |
| 91 |
|
| 92 |
KEYS(clipboardBrowserId << "F6" << commandDialogId); |
| 93 |
KEYS(commandDialogId << "ALT+S" << shortcutButtonId); |
| 94 |
KEYS(shortcutButtonId << "Space" << shortcutDialogId); |
| 95 |
KEYS(shortcutDialogId << "CTRL+F1" << shortcutButtonId); |
| 96 |
|
| 97 |
KEYS(commandDialogId << "ESCAPE" << commandDialogSaveButtonId); |
| 98 |
KEYS(commandDialogSaveButtonId << "Enter" << clipboardBrowserId); |
| 99 |
RUN("commands()[0].shortcuts", "ctrl+f1\n"); |
| 100 |
} |
| 101 |
|
| 102 |
void CoreTests::shortcutDialogAddTwoShortcuts() |
| 103 |
{ |
| 104 |
#ifdef Q_OS_MAC |
| 105 |
SKIP("Mnemonic for focusing shortcut button doesn't work on OS X"); |
| 106 |
#endif |
| 107 |
|
| 108 |
RUN("setCommands([{name: 'test', inMenu: true, shortcuts: ['ctrl+f1'], cmd: 'copyq add OK'}])", ""); |
| 109 |
RUN("commands()[0].shortcuts", "ctrl+f1\n"); |
| 110 |
|
| 111 |
KEYS(clipboardBrowserId << "F6" << commandDialogId); |
| 112 |
KEYS(commandDialogId << "ALT+S" << shortcutButtonId); |
| 113 |
|
| 114 |
KEYS(shortcutButtonId << "TAB" << shortcutButtonId); |
| 115 |
KEYS(shortcutButtonId << "Space" << shortcutDialogId); |
| 116 |
KEYS(shortcutDialogId << "F1" << shortcutButtonId); |
| 117 |
|
| 118 |
KEYS(shortcutButtonId << "Space" << shortcutDialogId); |
| 119 |
KEYS(shortcutDialogId << "F2" << shortcutButtonId); |
| 120 |
|
| 121 |
KEYS(commandDialogId << "ESCAPE" << commandDialogSaveButtonId); |
| 122 |
KEYS(commandDialogSaveButtonId << "Enter" << clipboardBrowserId); |
| 123 |
RUN("commands()[0].shortcuts", "ctrl+f1\nf1\nf2\n"); |
| 124 |
} |
| 125 |
|
| 126 |
void CoreTests::shortcutDialogChangeShortcut() |
| 127 |
{ |
| 128 |
#ifdef Q_OS_MAC |
| 129 |
SKIP("Mnemonic for focusing shortcut button doesn't work on OS X"); |
| 130 |
#endif |
| 131 |
|
| 132 |
RUN("setCommands([{name: 'test', inMenu: true, shortcuts: ['f1','f2','f3'], cmd: 'copyq add OK'}])", ""); |
| 133 |
RUN("commands()[0].shortcuts", "f1\nf2\nf3\n"); |
| 134 |
|
| 135 |
KEYS(clipboardBrowserId << "F6" << commandDialogId); |
| 136 |
KEYS(commandDialogId << "ALT+S" << shortcutButtonId); |
| 137 |
KEYS(commandDialogId << "TAB" << shortcutButtonId); |
| 138 |
KEYS(shortcutButtonId << "Space" << shortcutDialogId); |
| 139 |
KEYS(shortcutDialogId << "F4" << shortcutButtonId); |
| 140 |
|
| 141 |
KEYS(commandDialogId << "ESCAPE" << commandDialogSaveButtonId); |
| 142 |
KEYS(commandDialogSaveButtonId << "Enter" << clipboardBrowserId); |
| 143 |
RUN("commands()[0].shortcuts", "f1\nf4\nf3\n"); |
| 144 |
} |
| 145 |
|
| 146 |
void CoreTests::shortcutDialogSameShortcut() |
| 147 |
{ |
| 148 |
#ifdef Q_OS_MAC |
| 149 |
SKIP("Mnemonic for focusing shortcut button doesn't work on OS X"); |
| 150 |
#endif |
| 151 |
|
| 152 |
RUN("setCommands([{name: 'test', inMenu: true, shortcuts: ['ctrl+f1'], cmd: 'copyq add OK'}])", ""); |
| 153 |
RUN("commands()[0].shortcuts", "ctrl+f1\n"); |
| 154 |
|
| 155 |
KEYS(clipboardBrowserId << "F6" << commandDialogId); |
| 156 |
KEYS(commandDialogId << "ALT+S" << shortcutButtonId); |
| 157 |
KEYS(shortcutButtonId << "TAB" << shortcutButtonId); |
| 158 |
KEYS(shortcutButtonId << "Space" << shortcutDialogId); |
| 159 |
KEYS(shortcutDialogId << "CTRL+F1" << shortcutButtonId); |
| 160 |
|
| 161 |
KEYS(commandDialogId << "ESCAPE" << clipboardBrowserId); |
| 162 |
RUN("commands()[0].shortcuts", "ctrl+f1\n"); |
| 163 |
} |
| 164 |
|
| 165 |
void CoreTests::shortcutDialogCancel() |
| 166 |
{ |
| 167 |
#ifdef Q_OS_MAC |
| 168 |
SKIP("Mnemonic for focusing shortcut button doesn't work on OS X"); |
| 169 |
#endif |
| 170 |
|
| 171 |
RUN("setCommands([{name: 'test', inMenu: true, shortcuts: ['ctrl+f1'], cmd: 'copyq add OK'}])", ""); |
| 172 |
RUN("commands()[0].shortcuts", "ctrl+f1\n"); |
| 173 |
|
| 174 |
KEYS(clipboardBrowserId << "F6" << commandDialogId); |
| 175 |
KEYS(commandDialogId << "ALT+S" << shortcutButtonId); |
| 176 |
KEYS(commandDialogId << "TAB" << shortcutButtonId); |
| 177 |
KEYS(shortcutButtonId << "Space" << shortcutDialogId); |
| 178 |
KEYS(shortcutDialogId << "TAB" << "focus:ShortcutDialog"); |
| 179 |
KEYS("ESCAPE" << shortcutButtonId); |
| 180 |
|
| 181 |
KEYS(commandDialogId << "ESCAPE" << clipboardBrowserId); |
| 182 |
RUN("commands()[0].shortcuts", "ctrl+f1\n"); |
| 183 |
} |
| 184 |
|
| 185 |
void CoreTests::actionDialogCancel() |
| 186 |
{ |
| 187 |
const auto script = R"( |
| 188 |
setCommands([{ |
| 189 |
name: 'test', |
| 190 |
inMenu: true, |
| 191 |
shortcuts: ['ctrl+f1'], |
| 192 |
wait: true, |
| 193 |
cmd: 'copyq settings test SHOULD_NOT_BE_SET' |
| 194 |
}]) |
| 195 |
)"; |
| 196 |
RUN(script, ""); |
| 197 |
|
| 198 |
KEYS(clipboardBrowserId << "CTRL+F1" << actionDialogId); |
| 199 |
KEYS(actionDialogId << "ESCAPE" << clipboardBrowserId); |
| 200 |
RUN("settings" << "test", ""); |
| 201 |
} |
| 202 |
|
| 203 |
void CoreTests::actionDialogAccept() |
| 204 |
{ |
| 205 |
const auto script = R"( |
| 206 |
setCommands([{ |
| 207 |
name: 'test', |
| 208 |
inMenu: true, |
| 209 |
shortcuts: ['ctrl+f1'], |
| 210 |
wait: true, |
| 211 |
cmd: 'copyq settings test SHOULD_BE_SET' |
| 212 |
}]) |
| 213 |
)"; |
| 214 |
RUN(script, ""); |
| 215 |
|
| 216 |
KEYS(clipboardBrowserId << "CTRL+F1" << actionDialogId); |
| 217 |
// Can't focus configuration checkboxes on OS X |
| 218 |
#ifdef Q_OS_MAC |
| 219 |
KEYS(actionDialogId << "BACKTAB" << "ENTER" << clipboardBrowserId); |
| 220 |
#else |
| 221 |
KEYS(actionDialogId << "ENTER" << clipboardBrowserId); |
| 222 |
#endif |
| 223 |
WAIT_ON_OUTPUT("settings" << "test", "SHOULD_BE_SET"); |
| 224 |
} |
| 225 |
|
| 226 |
void CoreTests::actionDialogSelectionInputOutput() |
| 227 |
{ |
| 228 |
const auto script = R"( |
| 229 |
setCommands([{ |
| 230 |
name: 'test', |
| 231 |
inMenu: true, |
| 232 |
shortcuts: ['ctrl+f1'], |
| 233 |
wait: true, |
| 234 |
input: 'text/plain', |
| 235 |
output: 'text/plain', |
| 236 |
cmd: ` |
| 237 |
copyq settings test %1 |
| 238 |
copyq input |
| 239 |
` |
| 240 |
}]) |
| 241 |
)"; |
| 242 |
RUN(script, ""); |
| 243 |
|
| 244 |
const auto tab = testTab(1); |
| 245 |
const auto args = Args("tab") << tab; |
| 246 |
RUN(args << "add" << "C" << "B" << "A", ""); |
| 247 |
RUN("setCurrentTab" << tab, ""); |
| 248 |
RUN(args << "selectItems" << "0" << "2", "true\n"); |
| 249 |
|
| 250 |
KEYS(clipboardBrowserId << "CTRL+F1" << actionDialogId); |
| 251 |
// Can't focus configuration checkboxes on OS X |
| 252 |
#ifdef Q_OS_MAC |
| 253 |
KEYS(actionDialogId << "BACKTAB" << "ENTER" << clipboardBrowserId); |
| 254 |
#else |
| 255 |
KEYS(actionDialogId << "ENTER" << clipboardBrowserId); |
| 256 |
#endif |
| 257 |
WAIT_ON_OUTPUT("settings" << "test", "A\nC"); |
| 258 |
WAIT_ON_OUTPUT(args << "read" << "0", "A\nC"); |
| 259 |
} |
| 260 |
|
| 261 |
void CoreTests::exitConfirm() |
| 262 |
{ |
| 263 |
KEYS(clipboardBrowserId << "CTRL+Q" << confirmExitDialogId); |
| 264 |
KEYS(confirmExitDialogId << "ENTER"); |
| 265 |
TEST( m_test->waitForServerToStop() ); |
| 266 |
} |
| 267 |
|
| 268 |
void CoreTests::exitNoConfirm() |
| 269 |
{ |
| 270 |
RUN("config" << "confirm_exit" << "false", "false\n"); |
| 271 |
KEYS(clipboardBrowserId << "CTRL+Q"); |
| 272 |
TEST( m_test->waitForServerToStop() ); |
| 273 |
} |
| 274 |
|
| 275 |
void CoreTests::exitStopCommands() |
| 276 |
{ |
| 277 |
RUN("config" << "confirm_exit" << "false", "false\n"); |
| 278 |
m_test->ignoreErrors(QRegularExpression("Exit code: 10")); |
| 279 |
RUN("action" << "copyq sleep 999999", ""); |
| 280 |
KEYS(clipboardBrowserId << "CTRL+Q"); |
| 281 |
KEYS(runningCommandsExitDialogId); |
| 282 |
// Ignore status here since the client will be interrupted |
| 283 |
run(Args("plugins.itemtests.keys('ENTER')")); |
| 284 |
TEST( m_test->waitForServerToStop() ); |
| 285 |
} |
| 286 |
|
| 287 |
|
| 288 |
void CoreTests::terminateActionRequestTerminate() |
| 289 |
{ |
| 290 |
SKIP_ON_ENV("COPYQ_TESTS_SKIP_BASH"); |
| 291 |
|
| 292 |
// Action whose process writes a sentinel on SIGTERM, then exits cleanly. |
| 293 |
// Use 'settings' to avoid shell-quoting issues with tab names. |
| 294 |
// Use 'sleep &; wait' so bash's trap handler fires immediately on SIGTERM |
| 295 |
// (a foreground sleep would block trap dispatch until sleep exits). |
| 296 |
const auto cmd = R"( |
| 297 |
bash: |
| 298 |
copyq() { "$COPYQ" "$@"; } |
| 299 |
trap "copyq settings term_test TERMINATED" TERM |
| 300 |
copyq settings term_test READY |
| 301 |
sleep 999 & wait |
| 302 |
)"; |
| 303 |
m_test->ignoreErrors(QRegularExpression("Terminating action|Exit code|Failed to notify")); |
| 304 |
RUN("action" << cmd << "", ""); |
| 305 |
|
| 306 |
// Wait for the action's process to be running. |
| 307 |
WAIT_ON_OUTPUT("settings" << "term_test", "READY"); |
| 308 |
|
| 309 |
// Open Process Manager, filter to our action, select it, Terminate. |
| 310 |
KEYS(clipboardBrowserId << "CTRL+SHIFT+Z" << actionHandlerDialogId); |
| 311 |
KEYS(actionHandlerFilterId << ":sleep" << "TAB" << actionHandlerTableId); |
| 312 |
KEYS(actionHandlerTableId << "CTRL+A"); |
| 313 |
KEYS(actionHandlerTableId << "mouse|CLICK|terminateButton"); |
| 314 |
KEYS(actionHandlerDialogId << "ESCAPE" << clipboardBrowserId); |
| 315 |
|
| 316 |
// The SIGTERM handler fires, writing "TERMINATED". |
| 317 |
WAIT_ON_OUTPUT("settings" << "term_test", "TERMINATED"); |
| 318 |
} |
| 319 |
|
| 320 |
void CoreTests::terminateActionRequestKill() |
| 321 |
{ |
| 322 |
SKIP_ON_ENV("COPYQ_TESTS_SKIP_BASH"); |
| 323 |
|
| 324 |
// Action that ignores SIGTERM -- only SIGKILL can stop it. |
| 325 |
const auto cmd = R"( |
| 326 |
bash: |
| 327 |
copyq() { "$COPYQ" "$@"; } |
| 328 |
trap "" TERM |
| 329 |
copyq settings kill_test READY |
| 330 |
sleep 999 & wait |
| 331 |
)"; |
| 332 |
// Expect warnings and non-zero exit from SIGKILL. |
| 333 |
m_test->ignoreErrors(QRegularExpression( |
| 334 |
"Process crashed|Exit code|Terminating action|Killing action|Failed to notify")); |
| 335 |
RUN("action" << cmd << "", ""); |
| 336 |
RUN("config" << "terminate_action_timeout_ms" << "100", "100\n"); |
| 337 |
|
| 338 |
// Wait for the action's process to be running. |
| 339 |
WAIT_ON_OUTPUT("settings" << "kill_test", "READY"); |
| 340 |
|
| 341 |
// Open Process Manager, filter to our action, select it and Terminate. |
| 342 |
KEYS(clipboardBrowserId << "CTRL+SHIFT+Z" << actionHandlerDialogId); |
| 343 |
KEYS(actionHandlerFilterId << ":sleep" << "TAB" << actionHandlerTableId); |
| 344 |
|
| 345 |
KEYS(actionHandlerTableId << "CTRL+A"); |
| 346 |
KEYS(actionHandlerTableId + QStringLiteral(".*{Running}.*")); |
| 347 |
|
| 348 |
KEYS(actionHandlerTableId << "mouse|CLICK|terminateButton"); |
| 349 |
QTest::qWait(500); |
| 350 |
|
| 351 |
KEYS("mouse|CLICK|tableView"); |
| 352 |
KEYS(actionHandlerTableId << "CTRL+A"); |
| 353 |
KEYS(actionHandlerTableId + QStringLiteral(".*{Error}.*{Error: Process crashed}")); |
| 354 |
} |