@@ -1,5 +1,6 @@
2 * Copyright 2013-2016 Canonical Ltd.
2 * Copyright 2013-2016 Canonical Ltd.
3+ * Copyright (C) 2021 UBports Foundation
4 * This program is free software; you can redistribute it and/or modify
5 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * it under the terms of the GNU General Public License as published by
@@ -421,5 +422,99 @@ StyledItem {
422 tryCompare(searchField, "focus", false);
423 tryCompare(searchField, "focus", false);
426+ function test_dragDistanceReset() {
427+ // Regression test: If the user dragged the Drawer open further than
428+ // necessary, dragging the Drawer closed would take an equal amount
429+ // of distance to start the animation as the original overshoot.
431+ var drawer = dragDrawerIntoView();
432+ var dragY = drawer.height / 2;
433+ // Drag the Drawer most of the way closed, then *way* open
434+ mousePress(root, drawer.width - units.gu(1), dragY);
435+ mouseMove(root, 10, dragY, 500);
436+ mouseMove(root, units.gu(100), dragY, 500);
437+ mouseRelease(root, units.gu(100), dragY);
439+ // Ensure the Drawer's margin changes correctly on the next drag closed
440+ mousePress(root, drawer.width - units.gu(1), dragY);
441+ mouseMove(root, 1, dragY);
442+ // If the Drawer's position is within 2gu of hidden, it's probably okay.
443+ tryVerify(function () {return drawer.x < -(drawer.width - units.gu(2))});
444+ // But it should not be completely hidden.
445+ tryCompare(drawer, "visible", true);
446+ mouseRelease(root, 1, dragY);
449+ function test_userCancellingExitWithSearch_data() {
451+ {tag: "drag all the way back to fullyOpen", fullyOpen: true, cursorPosition: 3, selectedText: ""},
452+ {tag: "do not drag all the way back to fullyOpen", fullyOpen: false, cursorPosition: 3, selectedText: ""},
453+ {tag: "move cursor and drag all the way back to fullyOpen", fullyOpen: true, cursorPosition: 2, selectionStart: 2, selectionEnd: 2, selectedText: ""},
454+ {tag: "move cursor and do not drag all the way back to fullyOpen", fullyOpen: false, cursorPosition: 2, selectionStart: 2, selectionEnd: 2, selectedText: ""},
455+ {tag: "select text and drag all the way back to fullyOpen", fullyOpen: true, cursorPosition: 2, selectionStart: 0, selectionEnd: 2, selectedText: "ca"},
456+ {tag: "select text and do not drag all the way back to fullyOpen", fullyOpen: false, cursorPosition: 2, selectionStart: 0, selectionEnd: 2, selectedText: "ca"}
460+ function test_userCancellingExitWithSearch(data) {
461+ // * If I open the Drawer, start searching, start closing the
462+ // drawer, then change my mind and cancel my closing gesture, my
464+ // * If I start searching, place my cursor at a different point in
465+ // the text field or select text, then start closing the Drawer:
466+ // - The keyboard text selection handles and copy/paste dialog
467+ // become invisible or move with the text box. Our keyboard
468+ // isn't quite fancy enough for the handles to move with the
469+ // search box, so we remove the search field's focus to remove
471+ // - If I cancel my Drawer close action, my search, cursor
472+ // position, and selection rectangles are retained.
473+ var drawer = dragDrawerIntoView();
474+ var searchField = drawer.searchTextField;
475+ var dragY = drawer.height / 2;
476+ if (data.fullyOpen) {
477+ var dragEndPointX = drawer.width + units.gu(20);
479+ var dragEndPointX = drawer.width - units.gu(10);
483+ tryCompare(searchField, "displayText", "cam");
484+ tryCompare(searchField, "focus", true);
486+ if (data.selectionStart !== undefined) {
487+ searchField.select(data.selectionStart, data.selectionEnd);
490+ // Simply clicking the drag handle shouldn't be enough to remove focus
491+ mousePress(root, drawer.width - units.gu(1), dragY);
492+ tryCompare(searchField, "focus", true);
494+ // The search field should not have focus during the drag so the
495+ // cursor or drag handles don't float in place.
496+ mouseMove(root, 10, dragY, 500);
497+ tryCompare(drawer, "fullyOpen", false);
498+ tryCompare(searchField, "focus", false);
499+ mouseMove(root, dragEndPointX, dragY, 500);
500+ tryCompare(drawer, "fullyOpen", data.fullyOpen);
502+ // The search field should not get focus back until the user lets go
503+ tryCompare(searchField, "focus", false);
504+ mouseRelease(root, dragEndPointX, dragY);
505+ // Wait for animations to stop so anything that results from them
508+ tryCompare(drawer, "fullyOpen", true);
509+ tryCompare(searchField, "displayText", "cam");
510+ tryCompare(searchField, "focus", true);
511+ tryCompare(searchField, "cursorPosition", data.cursorPosition);
512+ tryCompare(searchField, "selectedText", data.selectedText);
513+ if (data.selectionStart) {
514+ // The selected area should be the same as it was before the drag
515+ tryCompare(searchField, "selectionStart", data.selectionStart);
516+ tryCompare(searchField, "selectionEnd", data.selectionEnd);