on 8a93021 help sign in
unity8/tests/qmltests/Panel/tst_MenuContent.qml
131 lines 4.1 kB history raw
1/*
2 * Copyright 2013-2014 Canonical Ltd.
3 *
4 * 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 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17import QtQuick 2.0
18import QtTest 1.0
19import Unity.Test 0.1 as UT
20import "../../../qml/Panel"
21import Unity.Indicators 0.1 as Indicators
23IndicatorTest {
24 id: root
25 width: units.gu(40)
26 height: units.gu(70)
28 // Dummy objects
29 Item { id: greeter }
30 Item { id: handle }
32 MenuContent {
33 id: menuContent
34 indicatorsModel: root.indicatorsModel
35 height: parent.height - 50
36 }
38 Rectangle {
39 color: "#bbbbbb"
41 height: 50
42 anchors {
43 top: menuContent.bottom
44 left: parent.left
45 right: parent.right
46 }
48 Text {
49 text: "Next Indicator"
50 anchors.fill: parent
51 horizontalAlignment: Text.AlignHCenter
52 verticalAlignment: Text.AlignVCenter
53 }
55 MouseArea {
56 anchors.fill: parent
57 onClicked: activate_next_content()
58 }
59 }
61 function activate_next_content()
62 {
63 if (menuContent.currentMenuIndex == -1)
64 activate_content(0);
65 else
66 activate_content((menuContent.currentMenuIndex + 1) % root.originalModelData.length)
67 }
69 function activate_content(index)
70 {
71 menuContent.currentMenuIndex = index;
72 }
74 function get_test_menu_objecName(index) {
75 return "indicator-fake" + (index + 1) + "-page";
76 }
78 property string testItemObjectName : ""
80 function current_item_equals_test_item() {
81 var currentItem = menu_content_test.findChild(menuContent, "indicatorsContentListView").currentItem
82 if (currentItem === null) {
83 console.log("current item undefined");
84 return false;
85 }
87 var testItem = menu_content_test.findChild(menuContent, testItemObjectName);
88 if (testItem === null) {
89 console.log("testItem " + testItemObjectName + " undefined");
90 return false;
91 }
93 return testItem === currentItem;
94 }
96 UT.UnityTestCase {
97 id: menu_content_test
98 name: "MenuContentTest"
99 when: windowShown
101 // Check that the correct menus are displayed for the requested item.
102 function test_show_menu() {
103 var menuCount = root.originalModelData.length;
104 verify(menuCount > 0, "Menu count should be greater than zero");
106 var listView = menu_content_test.findChild(menuContent, "indicatorsContentListView")
107 verify(listView !== null)
109 // Loop over twice to test jump between last and first.
110 for (var i = 0; i < menuCount*2; i++) {
111 var menuIndex = i%menuCount;
113 activate_content(menuIndex);
114 testItemObjectName = indicatorsModel.data(menuIndex, Indicators.IndicatorsModelRole.Identifier);
115 compare(listView.currentIndex, menuIndex, "Current tab index does not match selected tab index");
116 tryCompareFunction(current_item_equals_test_item, true);
117 }
118 }
120 // Tests QTBUG-30632 - asynchronous loader crashes when changing index quickly.
121 function test_multi_activate() {
122 var menuCount = root.originalModelData.length;
123 verify(menuCount > 0, "Menu count should be greater than zero");
125 for (var i = 0; i < 100; i++) {
126 activate_content(i % menuCount);
127 compare(menuContent.currentMenuIndex, i%menuCount);
128 }
129 }
130 }