on xenial help sign in
Fixed mouse navigation tests
commitb4f16f57bc4b85452d89a03fcb145309f84bdb1d authorNick Dedekind <nick.dedekind@canonical.com> dateMon 9 Jan 2017, 15:26 (10 years ago) parenta90cbc0
4 files changed+41−11
qml/ApplicationMenus/MenuBar.qml+7−2 qml/ApplicationMenus/MenuPopup.qml+5−4 tests/qmltests/ApplicationMenus/tst_MenuBar.qml+26−2 tests/qmltests/ApplicationMenus/tst_MenuPopup.qml+3−3
qml/ApplicationMenus/MenuBar.qml+7−2
@@ -188,12 +188,17 @@ Item {
188188 anchors.fill: parent
189189 hoverEnabled: d.currentItem
190190
191+ onEntered: {
192+ if (d.currentItem) {
193+ updateCurrentItemFromPosition(Qt.point(mouseX, mouseY))
194+ }
195+ }
191196 onPositionChanged: {
192197 if (d.currentItem) {
193− updateCurrentItemFromPosition(mouse)
198+ updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))
194199 }
195200 }
196− onClicked: updateCurrentItemFromPosition(mouse)
201+ onClicked: updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))
197202
198203 function updateCurrentItemFromPosition(point) {
199204 var pos = mapToItem(row, point.x, point.y);
qml/ApplicationMenus/MenuPopup.qml+5−4
@@ -183,11 +183,12 @@ UbuntuShape {
183183
184184 MouseArea {
185185 id: menuMouseArea
186− anchors.fill: parent
186+ anchors.fill: listView
187187 hoverEnabled: true
188− z: -1
189−
190− onPositionChanged: updateCurrentItemFromPosition(mouse)
188+ propagateComposedEvents: true // propogate events so we send clicks to children.
189+ z: 1 // on top so we override any other hovers
190+ onEntered: updateCurrentItemFromPosition(Qt.point(mouseX, mouseY))
191+ onPositionChanged: updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))
191192
192193 function updateCurrentItemFromPosition(point) {
193194 var pos = mapToItem(listView.contentItem, point.x, point.y);
tests/qmltests/ApplicationMenus/tst_MenuBar.qml+26−2
@@ -81,14 +81,38 @@ Item {
8181 name: "MenuBar"
8282 when: windowShown
8383
84− property bool clickNavigate: true
85−
8684 function init() {
8785 menuBar.dismiss();
8886 menuBackend.modelData = appMenuData.generateTestData(5,5,2,3,"menu")
8987 activatedSpy.clear();
9088 }
9189
90+ function test_mouseNavigation() {
91+ menuBackend.modelData = appMenuData.generateTestData(3,3,0,0,"menu");
92+ wait(50) // wait for row to build
93+ var priv = findInvisibleChild(menuBar, "d");
94+
95+ var menuItem0 = findChild(menuBar, "menuBar-item0"); verify(menuItem0);
96+ var menuItem1 = findChild(menuBar, "menuBar-item1"); verify(menuItem1);
97+ var menuItem2 = findChild(menuBar, "menuBar-item2"); verify(menuItem2);
98+
99+ menuItem0.show();
100+ compare(priv.currentItem, menuItem0, "CurrentItem should be set to item 0");
101+ compare(priv.currentItem.popupVisible, true, "Popup should be visible");
102+
103+ mouseMove(menuItem1, menuItem1.width/2, menuItem1.height/2);
104+ tryCompare(priv, "currentItem", menuItem1, undefined, "CurrentItem should have moved to item 1");
105+ compare(menuItem1.popupVisible, true, "Popup should be visible");
106+
107+ mouseMove(menuItem2, menuItem2.width/2, menuItem2.height/2);
108+ tryCompare(priv, "currentItem", menuItem2, undefined, "CurrentItem should have moved to item 2");
109+ compare(menuItem2.popupVisible, true, "Popup should be visible");
110+
111+ mouseMove(menuItem0, menuItem0.width/2, menuItem0.height/2);
112+ tryCompare(priv, "currentItem", menuItem0, undefined, "CurrentItem should have moved to item 0");
113+ compare(menuItem0.popupVisible, true, "Popup should be visible");
114+ }
115+
92116 function test_keyboardNavigation_RightKeySelectsNextMenuItem(data) {
93117 menuBackend.modelData = appMenuData.generateTestData(3,3,0,0,"menu");
94118 var priv = findInvisibleChild(menuBar, "d");
tests/qmltests/ApplicationMenus/tst_MenuPopup.qml+3−3
@@ -63,7 +63,7 @@ Item {
6363
6464 UnityTestCase {
6565 id: testCase
66− name: "MenuPage"
66+ name: "MenuPopup"
6767 when: windowShown
6868
6969 function init() {
@@ -105,14 +105,14 @@ Item {
105105 }
106106 }
107107
108− function test_clickNavigation_data() {
108+ function test_mouseNavigation_data() {
109109 return [
110110 { tag: "long", testData: appMenuData.generateTestData(4, 2, 1, 0, "menu", false) },
111111 { tag: "deep", testData: appMenuData.generateTestData(2, 4, 1, 0, "menu", false) }
112112 ]
113113 }
114114
115− function test_clickNavigation(data) {
115+ function test_mouseNavigation(data) {
116116 menuBackend.modelData = data.testData;
117117
118118 recurseMenuConstruction(data.testData, page);