@@ -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}