on xenial help sign in
Fixed decoration issues in tests
commitea4b6c6ad8915948af084f3edf58a2cb6a3b9138 authorNick Dedekind <nick.dedekind@canonical.com> dateFri 28 Oct 2016, 17:27 (10 years ago) parent2fe1152
4 files changed+101−88
qml/Stage/Stage.qml−7 qml/Stage/WindowDecoration.qml+19−23 tests/qmltests/Stage/tst_DesktopStage.qml−43 tests/qmltests/Stage/tst_WindowDecoration.qml+82−15
qml/Stage/Stage.qml−7
@@ -745,13 +745,6 @@ FocusScope {
745745 priv.updateMainAndSideStageIndexes()
746746 }
747747
748− property int stage: ApplicationInfoInterface.MainStage
749− function saveStage(newStage) {
750− appDelegate.stage = newStage;
751− WindowStateStorage.saveStage(appId, newStage);
752− priv.updateMainAndSideStageIndexes()
753− }
754−
755748 readonly property var surface: model.surface
756749 readonly property alias resizeArea: resizeArea
757750 readonly property alias focusedSurface: decoratedWindow.focusedSurface
qml/Stage/WindowDecoration.qml+19−23
@@ -22,7 +22,7 @@ import "../Components"
2222import "../Components/PanelState"
2323import "../ApplicationMenus"
2424
25−Item {
25+MouseArea {
2626 id: root
2727
2828 property Item target // appDelegate
@@ -35,36 +35,25 @@ Item {
3535
3636 readonly property real buttonsWidth: buttons.width + row.spacing
3737
38+ acceptedButtons: Qt.AllButtons // prevent leaking unhandled mouse events
39+ hoverEnabled: true
40+
3841 signal closeClicked()
3942 signal minimizeClicked()
4043 signal maximizeClicked()
4144 signal maximizeHorizontallyClicked()
4245 signal maximizeVerticallyClicked()
4346
44− MouseArea {
45− id: hoverArea
46− anchors.fill: parent
47−
48− acceptedButtons: Qt.AllButtons // prevent leaking unhandled mouse events
49− hoverEnabled: true
50−
51− onDoubleClicked: {
52− if (target.canBeMaximized && mouse.button == Qt.LeftButton) {
53− root.maximizeClicked();
54− }
55− }
56−
57− // do not let unhandled wheel event pass thru the decoration
58− onWheel: wheel.accepted = true;
59−
60− // We dont want touch events to fall through to parent,
61− // otherwise the containsMouse will not work.
62− MouseArea {
63− anchors.fill: parent
64− propagateComposedEvents: true
47+ onClicked: mouse.accepted = true // propogated event
48+ onDoubleClicked: {
49+ if (target.canBeMaximized && mouse.button == Qt.LeftButton) {
50+ root.maximizeClicked();
6551 }
6652 }
6753
54+ // do not let unhandled wheel event pass thru the decoration
55+ onWheel: wheel.accepted = true;
56+
6857 QtObject {
6958 id: priv
7059 property var menuBar: menuBarLoader.item
@@ -72,7 +61,14 @@ Item {
7261 property bool shouldShowMenus: root.enableMenus &&
7362 menuBar &&
7463 menuBar.valid &&
75− (menuBar.showRequested || hoverArea.containsMouse)
64+ (menuBar.showRequested || root.containsMouse)
65+ }
66+
67+ // We dont want touch events to fall through to parent,
68+ // otherwise the containsMouse will not work.
69+ MouseArea {
70+ anchors.fill: parent
71+ propagateComposedEvents: true
7672 }
7773
7874 Rectangle {
tests/qmltests/Stage/tst_DesktopStage.qml−43
@@ -96,13 +96,6 @@ Item {
9696 mode: "windowed"
9797 }
9898 }
99−
100− MouseArea {
101− id: clickThroughTester
102− anchors.fill: stageLoader.item
103− acceptedButtons: Qt.AllButtons
104− hoverEnabled: true
105− }
10699 }
107100
108101 Rectangle {
@@ -154,11 +147,6 @@ Item {
154147 }
155148 }
156149
157− SignalSpy {
158− id: mouseEaterSpy
159− target: clickThroughTester
160− }
161−
162150 UnityTestCase {
163151 id: testCase
164152 name: "DesktopStage"
@@ -197,8 +185,6 @@ Item {
197185
198186 stageLoader.active = true;
199187 tryCompare(stageLoader, "status", Loader.Ready);
200−
201− mouseEaterSpy.clear();
202188 }
203189
204190 function waitUntilAppSurfaceShowsUp(surfaceId) {
@@ -748,35 +734,6 @@ Item {
748734 tryCompareFunction(function(){return posBefore == posAfter;}, data.button !== Qt.LeftButton ? true : false);
749735 }
750736
751− function test_eatWindowDecorationMouseEvents_data() {
752− return [
753− {tag: "left mouse click", signalName: "clicked", button: Qt.LeftButton },
754− {tag: "right mouse click", signalName: "clicked", button: Qt.RightButton },
755− {tag: "middle mouse click", signalName: "clicked", button: Qt.MiddleButton },
756− {tag: "mouse wheel", signalName: "wheel", button: Qt.MiddleButton },
757− {tag: "double click (RMB)", signalName: "doubleClicked", button: Qt.RightButton },
758− ]
759− }
760−
761− function test_eatWindowDecorationMouseEvents(data) {
762− var dialerAppDelegate = startApplication("dialer-app");
763− verify(dialerAppDelegate);
764− var decoration = findChild(dialerAppDelegate, "appWindowDecoration");
765− verify(decoration);
766−
767− mouseEaterSpy.signalName = data.signalName;
768− if (data.signalName === "wheel") {
769− mouseWheel(decoration, decoration.width/2, decoration.height/2, 20, 20);
770− } else if (data.signalName === "clicked") {
771− mouseClick(decoration, decoration.width/2, decoration.height/2, data.button);
772− } else {
773− mouseDoubleClick(decoration, decoration.width/2, decoration.height/2, data.button);
774− tryCompare(dialerAppDelegate, "maximized", false);
775− }
776−
777− tryCompare(mouseEaterSpy, "count", 0);
778− }
779−
780737 // regression test for https://bugs.launchpad.net/ubuntu/+source/unity8/+bug/1627281
781738 function test_doubleTapToMaximizeWindow() {
782739 var dialerAppDelegate = startApplication("dialer-app");
tests/qmltests/Stage/tst_WindowDecoration.qml+82−15
@@ -49,6 +49,12 @@ Item {
4949
5050 ApplicationMenuDataLoader { id: menuData }
5151
52+ UnityMenuModel {
53+ id: menuBackend
54+ modelData: menuData.generateTestData(5, 3, 3, "menu")
55+ onActivated: log.text = "Activated " + action + "\n" + log.text
56+ }
57+
5258 Rectangle {
5359 anchors {
5460 left: parent.left
@@ -68,29 +74,45 @@ Item {
6874 }
6975 }
7076
71− WindowDecoration {
72− id: decoration
77+ MouseArea {
78+ id: clickThroughTester
79+ anchors.fill: parent
80+ acceptedButtons: Qt.AllButtons
81+ hoverEnabled: true
82+ }
83+
84+ Loader {
85+ id: decorationLoader
7386 anchors { left: parent.left; right: parent.right; top: parent.top }
7487 anchors.margins: units.gu(1)
75− target: root
76− title: "TestTitle - Doing something"
77− active: true
7888 height: units.gu(3)
79− menu: menuBackend
80− UnityMenuModel {
81− id: menuBackend
82− modelData: menuData.generateTestData(5, 3, 3, "menu")
83− onActivated: log.text = "Activated " + action + "\n" + log.text
84− }
8589
86− onCloseClicked: { log.text = "Close\n" + log.text }
87− onMinimizeClicked: { log.text = "Minimize\n" + log.text }
88− onMaximizeClicked: { log.text = "Maximize\n" + log.text }
90+ property bool itemDestroyed: false
91+ sourceComponent: WindowDecoration {
92+ anchors.fill: parent
93+ target: root
94+ title: "TestTitle - Doing something"
95+ active: true
96+ menu: menuBackend
97+
98+ onCloseClicked: { log.text = "Close\n" + log.text }
99+ onMinimizeClicked: { log.text = "Minimize\n" + log.text }
100+ onMaximizeClicked: { log.text = "Maximize\n" + log.text }
101+
102+ Component.onDestruction: {
103+ decorationLoader.itemDestroyed = true;
104+ }
105+ }
89106 }
90107
91108 SignalSpy {
92109 id: signalSpy
93− target: decoration
110+ target: decorationLoader.item
111+ }
112+
113+ SignalSpy {
114+ id: mouseEaterSpy
115+ target: clickThroughTester
94116 }
95117
96118 UnityTestCase {
@@ -98,9 +120,30 @@ Item {
98120 name: "WindowDecoration"
99121 when: windowShown
100122
123+ property Item decoration: decorationLoader.status === Loader.Ready ? decorationLoader.item : null
124+
101125 function init() {
126+ tryCompareFunction(function() { return decoration !== null }, true);
102127 decoration.menu = menuBackend;
128+ }
129+
130+ function cleanup() {
131+ decorationLoader.itemDestroyed = false;
132+ decorationLoader.active = false;
133+
134+ tryCompare(decorationLoader, "status", Loader.Null);
135+ tryCompare(decorationLoader, "item", null);
136+ // Loader.status might be Loader.Null and Loader.item might be null but the Loader
137+ // actually took place. Likely because Loader waits until the next event loop
138+ // iteration to do its work. So to ensure the reload, we will wait until the
139+ // Shell instance gets destroyed.
140+ tryCompare(decorationLoader, "itemDestroyed", true);
141+
142+ decorationLoader.active = true;
143+ tryCompare(decorationLoader, "status", Loader.Ready);
144+
103145 signalSpy.clear();
146+ mouseEaterSpy.clear();
104147 }
105148
106149 function test_windowControlButtons_data() {
@@ -168,5 +211,29 @@ Item {
168211 tryCompare(menuLoader, "opacity", 0);
169212 tryCompare(titleLabel, "opacity", 1);
170213 }
214+
215+ function test_eatMouseEvents_data() {
216+ return [
217+ {tag: "left mouse click", signalName: "clicked", button: Qt.LeftButton },
218+ {tag: "right mouse click", signalName: "clicked", button: Qt.RightButton },
219+ {tag: "middle mouse click", signalName: "clicked", button: Qt.MiddleButton },
220+ {tag: "mouse wheel", signalName: "wheel", button: Qt.MiddleButton },
221+ {tag: "double click (LMB)", signalName: "doubleClicked", button: Qt.LeftButton },
222+ {tag: "double click (RMB)", signalName: "doubleClicked", button: Qt.RightButton },
223+ ]
224+ }
225+
226+ function test_eatMouseEvents(data) {
227+ mouseEaterSpy.signalName = data.signalName;
228+ if (data.signalName === "wheel") {
229+ mouseWheel(decoration, decoration.width/2, decoration.height/2, 20, 20);
230+ } else if (data.signalName === "clicked") {
231+ mouseClick(decoration, decoration.width/2, decoration.height/2, data.button);
232+ } else {
233+ mouseDoubleClick(decoration, decoration.width/2, decoration.height/2, data.button);
234+ }
235+
236+ tryCompare(mouseEaterSpy, "count", 0);
237+ }
171238 }
172239}