1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498
|
/*
* Copyright 2012 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.0
import QtTest 1.0
import Lomiri.Test 1.0
import Lomiri.Components 1.1
import Lomiri.Components.ListItems 1.0 as ListItem
Item {
id: main
width: units.gu(50); height: units.gu(100)
property bool hasOSK: false
Column {
TextArea {
id: textArea
SignalSpy {
id: signalSpy
target: parent
}
property int keyPressData
property int keyReleaseData
Keys.onPressed: keyPressData = event.key
Keys.onReleased: keyReleaseData = event.key
}
TextArea {
id: colorTest
color: colorTest.text.length < 4 ? "#0000ff" : "#00ff00"
}
TextEdit {
id: textEdit
}
ListItem.Empty {
id: listItem
height: 200
anchors.left: parent.left
anchors.right: parent.right
SignalSpy {
id: listItemSpy
signalName: "clicked"
target: listItem
}
TextArea {
id: input
anchors.fill: parent
Component.onCompleted: forceActiveFocus()
}
}
TextArea {
id: t1
objectName: "t1"
}
TextArea {
id: t2
objectName: "t2"
}
TextArea {
id: longText
text: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book."
}
}
LomiriTestCase {
name: "TextAreaAPI"
when: windowShown
function init() {
main.hasOSK = QuickUtils.inputMethodProvider !== ""
}
function cleanup() {
textArea.focus =
colorTest.focus =
textEdit.focus =
input.focus =
t1.focus =
t2.focus =
longText.focus = false;
longText.cursorPosition = 0;
var scroller = findChild(longText, "input_scroller");
scroller.contentY = 0;
scroller.contentX = 0;
textArea.text = "";
textArea.textFormat = TextEdit.PlainText;
input.textFormat = TextEdit.PlainText;
input.text = "";
input.cursorPosition = 0;
// empty event buffer
wait(200);
}
function test_activate() {
textArea.forceActiveFocus();
compare(textArea.activeFocus, true, "TextArea is active");
}
// TextEdit shared properties
function test_0_activeFocusOnPress() {
compare(textArea.activeFocusOnPress,textEdit.activeFocusOnPress,"TextArea.activeFocusOnPress is same as TextEdit.activeFocusOnPress")
}
function test_0_canPaste() {
compare(textArea.canPaste,textEdit.canPaste,"TextArea.canPaste is same as TextEdit.canPaste")
}
function test_0_canRedo() {
compare(textArea.canRedo,textEdit.canRedo,"TextArea.canRedo is same as TextEdit.canRedo")
}
function test_0_canUndo() {
compare(textArea.canUndo,textEdit.canUndo,"TextArea.canUndo is same as TextEdit.canUndo")
}
function test_0_cursorDelegate() {
verify(textArea.cursorDelegate === null, "TextArea.cursorDelegate is not null")
}
function test_0_cursorPosition() {
compare(textArea.cursorPosition,textEdit.cursorPosition,"TextArea.cursorPosition is same as TextEdit.cursorPosition")
}
function test_0_cursorRectangle() {
compare(textArea.cursorRectangle,textEdit.cursorRectangle,"TextArea.cursorRectangle is same as TextEdit.cursorRectangle")
}
function test_0_cursorVisible() {
compare(textArea.cursorVisible,textEdit.cursorVisible,"TextArea.cursorVisible is same as TextEdit.cursorVisible")
}
function test_0_effectiveHorizontalAlignment() {
compare(textArea.effectiveHorizontalAlignment,textEdit.effectiveHorizontalAlignment,"TextArea.effectiveHorizontalAlignment is same as TextEdit.effectiveHorizontalAlignment")
}
function test_0_font() {
compare(textArea.font,textEdit.font,"TextArea.font is same as TextEdit.font")
}
function test_0_horizontalAlignment() {
compare(textArea.horizontalAlignment,textEdit.horizontalAlignment,"TextArea.horizontalAlignment is same as TextEdit.horizontalAlignment")
}
function test_0_inputMethodComposing() {
compare(textArea.inputMethodComposing,textEdit.inputMethodComposing,"TextArea.inputMethodComposing is same as TextEdit.inputMethodComposing")
}
function test_0_inputMethodHints() {
compare(textArea.inputMethodHints,textEdit.inputMethodHints,"TextArea.inputMethodHints is same as TextEdit.inputMethodHints")
}
function test_0_length() {
compare(textArea.length,textEdit.length,"TextArea.length is same as TextEdit.length")
}
function test_0_lineCount() {
compare(textArea.lineCount,textEdit.lineCount,"TextArea.lineCount is same as TextEdit.lineCount")
}
function test_0_mouseSelectionMode() {
compare(textArea.mouseSelectionMode, TextEdit.SelectWords,"TextArea.mouseSelectionMode is SelectWords")
}
function test_0_persistentSelection() {
compare(textArea.persistentSelection,textEdit.persistentSelection,"TextArea.persistentSelection is same as TextEdit.persistentSelection")
}
function test_0_readOnly() {
compare(textArea.readOnly,textEdit.readOnly,"TextArea.readOnly is same as TextEdit.readOnly")
textArea.text = "ab";
textArea.cursorPosition = 1;
textArea.textFormat = TextEdit.PlainText;
keyClick(Qt.Key_Return);
compare("ab", textArea.text, "No split occurred in plain area");
textArea.textFormat = TextEdit.RichText;
keyClick(Qt.Key_Return);
compare(textArea.text.indexOf("<br />"), -1, "No split occurred in rich area");
}
function test_0_renderType() {
compare(textArea.renderType,textEdit.renderType,"TextArea.renderType is same as TextEdit.renderType")
}
function test_0_selectByMouse() {
compare(textArea.selectByMouse,true,"TextArea.selectByMouse is true")
}
function test_0_selectedText() {
compare(textArea.selectedText,textEdit.selectedText,"TextArea.selectedText is same as TextEdit.selectedText")
}
function test_0_selectionEnd() {
compare(textArea.selectionEnd,textEdit.selectionEnd,"TextArea.selectionEnd is same as TextEdit.selectionEnd")
}
function test_0_selectionStart() {
compare(textArea.selectionStart,textEdit.selectionStart,"TextArea.selectionStart is same as TextEdit.selectionStart")
}
function test_0_text() {
compare(textArea.text,textEdit.text,"TextArea.text is same as TextEdit.text")
}
function test_0_textFormat() {
compare(textArea.textFormat,textEdit.textFormat,"TextArea.textFormat is same as TextEdit.textFormat")
}
function test_0_verticalAlignment() {
compare(textArea.verticalAlignment,textEdit.verticalAlignment,"TextArea.verticalAlignment is same as TextEdit.verticalAlignment")
}
function test_0_wrapMode() {
compare(textArea.wrapMode,TextEdit.Wrap,"TextArea.wrapMode is TextEdit.Wrap")
}
// TextArea specific properties
function test_0_highlighted() {
compare(textArea.highlighted, textArea.focus, "highlighted is the same as focused");
}
function test_0_contentHeight() {
verify(textArea.contentHeight > 0, "contentHeight over 0 units on default")
var newValue = 200;
textArea.contentHeight = newValue;
compare(textArea.contentHeight,newValue,"set/get");
}
function test_0_contentWidth() {
var style = findChild(textArea, "textarea_style");
compare(textArea.contentWidth, units.gu(30) - 2 * style.frameSpacing, "contentWidth is the implicitWidth - 2 times the frame size on default")
var newValue = 200;
textArea.contentWidth = newValue;
compare(textArea.contentWidth,newValue,"set/get");
}
function test_placeholderText() {
compare(textArea.placeholderText,"","placeholderText is '' on default")
var newValue = "Hello Placeholder";
textArea.placeholderText = newValue;
compare(textArea.placeholderText,newValue,"set/get");
}
function test_autoSize() {
compare(textArea.autoSize,false,"TextArea.autoSize is set to false");
var newValue = true;
textArea.autoSize = newValue;
compare(textArea.autoSize, newValue,"set/get");
}
function test_0_baseUrl() {
expectFail("","TODO")
compare(textArea.baseUrl,"tst_textarea.qml","baseUrl is QML file instantiating the TextArea item on default")
}
function test_displayText() {
compare(textArea.displayText,"","displayText is '' on default")
var newValue = "Hello Display Text";
try {
textArea.displayText = newValue;
compare(false,true,"Unable to set value as it is read-only");
} catch (e) {
compare(true,true,"Unable to set value as it is read-only");
}
}
function test_0_popover() {
compare(textArea.popover, undefined, "Uses default popover");
}
function test_maximumLineCount() {
compare(textArea.maximumLineCount,5,"maximumLineCount is 0 on default")
var newValue = 10;
textArea.maximumLineCount = newValue;
compare(textArea.maximumLineCount,newValue,"set/get");
}
function test_0_visible() {
textArea.visible = false;
compare(textArea.activeFocus, false, "TextArea is inactive");
}
// functions
function test_copy() {
textArea.copy();
}
function test_cut() {
Clipboard.clear();
textArea.readOnly = false;
textArea.text = "test text";
textArea.cursorPosition = textArea.text.indexOf("text");
textArea.selectWord();
textArea.cut();
compare(textArea.text, "test ", "Text cut properly");
compare(Clipboard.data.text, "text", "Clipboard contains cut text");
// we should have the "text" only ones
var plainTextCount = 0;
for (var i in Clipboard.data.formats) {
if (Clipboard.data.formats[i] === "text/plain")
plainTextCount++;
}
compare(plainTextCount, 1, "Clipboard is correct");
}
function test_deselect() {
textArea.deselect();
}
function test_getFormattedText() {
textArea.getFormattedText(0,0);
}
function test_getText() {
textArea.getText(0,0);
}
function test_insert() {
textArea.insert(0,"Hello");
}
function test_isRightToLeft() {
textArea.isRightToLeft(0,0);
}
function test_moveCursorSelection() {
textArea.moveCursorSelection(0,0);
}
function test_paste() {
textArea.readOnly = false;
textArea.text = "test";
textArea.cursorPosition = textArea.text.length;
textArea.paste(" text");
compare(textArea.text, "test text", "Data pasted");
}
function test_positionAt() {
textArea.positionAt(0,1);
}
function test_positionToRectangle() {
textArea.positionToRectangle(0);
}
function test_redo() {
textArea.redo();
}
function test_remove() {
textArea.remove(0,0);
}
function test_select() {
textArea.select(0,0);
}
function test_selectAll() {
textArea.selectAll();
}
function test_selectWord() {
textArea.selectWord();
}
function test_undo() {
textArea.undo();
}
// signals
function test_linkActivated() {
signalSpy.signalName = "linkActivated";
compare(signalSpy.valid,true,"linkActivated signal exists")
}
// filters
function test_keyPressAndReleaseFilter() {
textArea.visible = true;
textArea.forceActiveFocus();
textArea.readOnly = false;
textArea.keyPressData = 0;
textArea.keyReleaseData = 0;
keyClick(Qt.Key_T, Qt.NoModifier, 100);
compare(textArea.keyPressData, Qt.Key_T, "Key press filtered");
compare(textArea.keyReleaseData, Qt.Key_T, "Key release filtered");
}
function test_TextAreaInListItem_EnterCaptured() {
input.forceActiveFocus();
input.textFormat = TextEdit.PlainText;
input.text = "";
keyClick(Qt.Key_T);
keyClick(Qt.Key_E);
keyClick(Qt.Key_S);
keyClick(Qt.Key_T);
keyClick(Qt.Key_Enter);
compare(input.text, "test\n", "Keys");
}
function test_TextAreaInListItem_EnterDoesNotProduceClick() {
input.forceActiveFocus();
input.textFormat = TextEdit.PlainText;
input.text = "";
listItemSpy.clear();
keyClick(Qt.Key_Enter);
tryCompare(listItemSpy, "count", 0, 100);
}
function test_colorCollisionOnDelegate() {
// fixes bug lp:1169601
colorTest.text = "abc";
compare(colorTest.color, "#0000ff", "Color when text length < 4");
colorTest.text = "abcd";
compare(colorTest.color, "#00ff00", "Color when text length >= 4");
}
function test_OneActiveFocus() {
t1.focus = true;
compare(t1.activeFocus, true, "T1 has activeFocus");
compare(t2.activeFocus, false, "T1 has activeFocus");
t2.focus = true;
compare(t1.activeFocus, false, "T1 has activeFocus");
compare(t2.activeFocus, true, "T1 has activeFocus");
}
function test_OSK_ShownWhenNextTextAreaIsFocused() {
if (!hasOSK)
expectFail("", "OSK can be tested only when present");
t1.focus = true;
compare(Qt.inputMethod.visible, true, "OSK is shown for the first TextArea");
t2.focus = true;
compare(Qt.inputMethod.visible, true, "OSK is shown for the second TextArea");
}
function test_RemoveOSKWhenFocusLost() {
if (!hasOSK)
expectFail("", "OSK can be tested only when present");
t1.focus = true;
compare(Qt.inputMethod.visible, true, "OSK is shown when TextArea gains focus");
t1.focus = false;
compare(Qt.inputMethod.visible, false, "OSK is hidden when TextArea looses focus");
}
function test_ReEnabledInput() {
textArea.forceActiveFocus();
textArea.enabled = false;
compare(textArea.enabled, false, "textArea is disabled");
compare(textArea.focus, true, "textArea is focused");
compare(textArea.activeFocus, false, "textArea is not active focus");
compare(Qt.inputMethod.visible, false, "OSK removed");
textArea.enabled = true;
compare(textArea.enabled, true, "textArea is enabled");
compare(textArea.focus, true, "textArea is focused");
compare(textArea.activeFocus, true, "textArea is active focus");
if (!hasOSK)
expectFail("", "OSK can be tested only when present");
compare(Qt.inputMethod.visible, true, "OSK shown");
}
function test_TextareaInListItem_RichTextEnterCaptured() {
textArea.text = "a<br />b";
textArea.textFormat = TextEdit.RichText;
input.forceActiveFocus();
input.textFormat = TextEdit.RichText;
input.text = "ab";
input.cursorPosition = 1;
keyClick(Qt.Key_Return);
compare(input.text, textArea.text, "Formatted text split");
}
}
}
|