on xenial help sign in
Fixed decoration issues in tests
ea4b6c6Nick Dedekind
qml/Stage/Stage.qml−7
@@ -745,13 +745,6 @@ FocusScope {
745 priv.updateMainAndSideStageIndexes()
745 priv.updateMainAndSideStageIndexes()
746 }
746 }
747
747
748− property int stage: ApplicationInfoInterface.MainStage
749− function saveStage(newStage) {
750− appDelegate.stage = newStage;
751− WindowStateStorage.saveStage(appId, newStage);
752− priv.updateMainAndSideStageIndexes()
753− }
754−
755 readonly property var surface: model.surface
748 readonly property var surface: model.surface
756 readonly property alias resizeArea: resizeArea
749 readonly property alias resizeArea: resizeArea
757 readonly property alias focusedSurface: decoratedWindow.focusedSurface
750 readonly property alias focusedSurface: decoratedWindow.focusedSurface
qml/Stage/WindowDecoration.qml+19−23
@@ -22,7 +22,7 @@ import "../Components"
22import "../Components/PanelState"
22import "../Components/PanelState"
23import "../ApplicationMenus"
23import "../ApplicationMenus"
24
24
25−Item {
25+MouseArea {
26 id: root
26 id: root
27
27
28 property Item target // appDelegate
28 property Item target // appDelegate
@@ -35,36 +35,25 @@ Item {
35
35
36 readonly property real buttonsWidth: buttons.width + row.spacing
36 readonly property real buttonsWidth: buttons.width + row.spacing
37
37
38+ acceptedButtons: Qt.AllButtons // prevent leaking unhandled mouse events
39+ hoverEnabled: true
40+
38 signal closeClicked()
41 signal closeClicked()
39 signal minimizeClicked()
42 signal minimizeClicked()
40 signal maximizeClicked()
43 signal maximizeClicked()
41 signal maximizeHorizontallyClicked()
44 signal maximizeHorizontallyClicked()
42 signal maximizeVerticallyClicked()
45 signal maximizeVerticallyClicked()
43
46
44− MouseArea {
47+ onClicked: mouse.accepted = true // propogated event
45− id: hoverArea
46− anchors.fill: parent
47−
48− acceptedButtons: Qt.AllButtons // prevent leaking unhandled mouse events
49− hoverEnabled: true
50−
51− onDoubleClicked: {
48+ onDoubleClicked: {
52− if (target.canBeMaximized && mouse.button == Qt.LeftButton) {
49+ if (target.canBeMaximized && mouse.button == Qt.LeftButton) {
53− root.maximizeClicked();
50+ 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
65 }
51 }
66 }
52 }
67
53
54+ // do not let unhandled wheel event pass thru the decoration
55+ onWheel: wheel.accepted = true;
56+
68 QtObject {
57 QtObject {
69 id: priv
58 id: priv
70 property var menuBar: menuBarLoader.item
59 property var menuBar: menuBarLoader.item
@@ -72,7 +61,14 @@ Item {
72 property bool shouldShowMenus: root.enableMenus &&
61 property bool shouldShowMenus: root.enableMenus &&
73 menuBar &&
62 menuBar &&
74 menuBar.valid &&
63 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
76 }
72 }
77
73
78 Rectangle {
74 Rectangle {
tests/qmltests/Stage/tst_DesktopStage.qml−43
@@ -96,13 +96,6 @@ Item {
96 mode: "windowed"
96 mode: "windowed"
97 }
97 }
98 }
98 }
99−
100− MouseArea {
101− id: clickThroughTester
102− anchors.fill: stageLoader.item
103− acceptedButtons: Qt.AllButtons
104− hoverEnabled: true
105− }
106 }
99 }
107
100
108 Rectangle {
101 Rectangle {
@@ -154,11 +147,6 @@ Item {
154 }
147 }
155 }
148 }
156
149
157− SignalSpy {
158− id: mouseEaterSpy
159− target: clickThroughTester
160− }
161−
162 UnityTestCase {
150 UnityTestCase {
163 id: testCase
151 id: testCase
164 name: "DesktopStage"
152 name: "DesktopStage"
@@ -197,8 +185,6 @@ Item {
197
185
198 stageLoader.active = true;
186 stageLoader.active = true;
199 tryCompare(stageLoader, "status", Loader.Ready);
187 tryCompare(stageLoader, "status", Loader.Ready);
200−
201− mouseEaterSpy.clear();
202 }
188 }
203
189
204 function waitUntilAppSurfaceShowsUp(surfaceId) {
190 function waitUntilAppSurfaceShowsUp(surfaceId) {
@@ -748,35 +734,6 @@ Item {
748 tryCompareFunction(function(){return posBefore == posAfter;}, data.button !== Qt.LeftButton ? true : false);
734 tryCompareFunction(function(){return posBefore == posAfter;}, data.button !== Qt.LeftButton ? true : false);
749 }
735 }
750
736
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−
780 // regression test for https://bugs.launchpad.net/ubuntu/+source/unity8/+bug/1627281
737 // regression test for https://bugs.launchpad.net/ubuntu/+source/unity8/+bug/1627281
781 function test_doubleTapToMaximizeWindow() {
738 function test_doubleTapToMaximizeWindow() {
782 var dialerAppDelegate = startApplication("dialer-app");
739 var dialerAppDelegate = startApplication("dialer-app");
tests/qmltests/Stage/tst_WindowDecoration.qml+82−15
@@ -49,6 +49,12 @@ Item {
49
49
50 ApplicationMenuDataLoader { id: menuData }
50 ApplicationMenuDataLoader { id: menuData }
51
51
52+ UnityMenuModel {
53+ id: menuBackend
54+ modelData: menuData.generateTestData(5, 3, 3, "menu")
55+ onActivated: log.text = "Activated " + action + "\n" + log.text
56+ }
57+
52 Rectangle {
58 Rectangle {
53 anchors {
59 anchors {
54 left: parent.left
60 left: parent.left
@@ -68,29 +74,45 @@ Item {
68 }
74 }
69 }
75 }
70
76
71− WindowDecoration {
77+ MouseArea {
72− id: decoration
78+ id: clickThroughTester
79+ anchors.fill: parent
80+ acceptedButtons: Qt.AllButtons
81+ hoverEnabled: true
82+ }
83+
84+ Loader {
85+ id: decorationLoader
73 anchors { left: parent.left; right: parent.right; top: parent.top }
86 anchors { left: parent.left; right: parent.right; top: parent.top }
74 anchors.margins: units.gu(1)
87 anchors.margins: units.gu(1)
75− target: root
76− title: "TestTitle - Doing something"
77− active: true
78 height: units.gu(3)
88 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− }
85
89
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+
86− onCloseClicked: { log.text = "Close\n" + log.text }
98+ onCloseClicked: { log.text = "Close\n" + log.text }
87− onMinimizeClicked: { log.text = "Minimize\n" + log.text }
99+ onMinimizeClicked: { log.text = "Minimize\n" + log.text }
88− onMaximizeClicked: { log.text = "Maximize\n" + log.text }
100+ onMaximizeClicked: { log.text = "Maximize\n" + log.text }
101+
102+ Component.onDestruction: {
103+ decorationLoader.itemDestroyed = true;
104+ }
105+ }
89 }
106 }
90
107
91 SignalSpy {
108 SignalSpy {
92 id: signalSpy
109 id: signalSpy
93− target: decoration
110+ target: decorationLoader.item
111+ }
112+
113+ SignalSpy {
114+ id: mouseEaterSpy
115+ target: clickThroughTester
94 }
116 }
95
117
96 UnityTestCase {
118 UnityTestCase {
@@ -98,9 +120,30 @@ Item {
98 name: "WindowDecoration"
120 name: "WindowDecoration"
99 when: windowShown
121 when: windowShown
100
122
123+ property Item decoration: decorationLoader.status === Loader.Ready ? decorationLoader.item : null
124+
101 function init() {
125 function init() {
126+ tryCompareFunction(function() { return decoration !== null }, true);
102 decoration.menu = menuBackend;
127 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+
103 signalSpy.clear();
145 signalSpy.clear();
146+ mouseEaterSpy.clear();
104 }
147 }
105
148
106 function test_windowControlButtons_data() {
149 function test_windowControlButtons_data() {
@@ -168,5 +211,29 @@ Item {
168 tryCompare(menuLoader, "opacity", 0);
211 tryCompare(menuLoader, "opacity", 0);
169 tryCompare(titleLabel, "opacity", 1);
212 tryCompare(titleLabel, "opacity", 1);
170 }
213 }
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+ }
171 }
238 }
172}
239}