Warning, /frameworks/kirigami/autotests/tst_pagerow.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2016 Aleix Pol Gonzalez <aleixpol@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 import QtQuick 0008 import QtQuick.Controls 0009 import QtQuick.Window 0010 import org.kde.kirigami as Kirigami 0011 import QtTest 0012 0013 TestCase { 0014 id: testCase 0015 width: 400 0016 height: 400 0017 name: "GoBack" 0018 0019 function applicationWindow() { return mainWindow; } 0020 0021 Kirigami.ApplicationWindow { 0022 id: mainWindow 0023 width: 480 0024 height: 360 0025 pageStack.initialPage: Kirigami.Page { 0026 Rectangle { 0027 anchors.fill: parent 0028 color: "green" 0029 } 0030 } 0031 } 0032 0033 Component { 0034 id: randomPage 0035 Kirigami.Page { 0036 Rectangle { 0037 anchors.fill: parent 0038 color: "red" 0039 } 0040 } 0041 } 0042 0043 SignalSpy { 0044 id: spyCurrentIndex 0045 target: mainWindow.pageStack 0046 signalName: "currentIndexChanged" 0047 } 0048 0049 SignalSpy { 0050 id: spyActive 0051 target: mainWindow 0052 signalName: "activeChanged" 0053 } 0054 0055 function initTestCase() { 0056 mainWindow.show() 0057 } 0058 0059 function cleanupTestCase() { 0060 mainWindow.close() 0061 } 0062 0063 function init() { 0064 mainWindow.pageStack.clear() 0065 spyActive.clear() 0066 spyCurrentIndex.clear() 0067 } 0068 0069 function test_pop() { 0070 compare(mainWindow.pageStack.depth, 0) 0071 mainWindow.pageStack.push(randomPage) 0072 compare(mainWindow.pageStack.depth, 1) 0073 mainWindow.pageStack.pop() 0074 compare(mainWindow.pageStack.depth, 0) 0075 } 0076 0077 function test_goBack() { 0078 compare(mainWindow.pageStack.depth, 0) 0079 compare(mainWindow.pageStack.currentIndex, -1) 0080 0081 let page = mainWindow.pageStack.push(randomPage) 0082 print(page) 0083 tryCompare(spyCurrentIndex, "count", 1) 0084 compare(mainWindow.pageStack.depth, 1) 0085 compare(mainWindow.pageStack.currentIndex, 0) 0086 0087 page = mainWindow.pageStack.push(randomPage) 0088 print(page) 0089 tryCompare(spyCurrentIndex, "count", 2) 0090 compare(mainWindow.pageStack.depth, 2) 0091 0092 compare(mainWindow.pageStack.depth, 2) 0093 compare(mainWindow.pageStack.currentIndex, 1) 0094 0095 spyActive.clear() 0096 mainWindow.requestActivate() 0097 spyCurrentIndex.clear() 0098 if (!mainWindow.active) 0099 spyActive.wait() 0100 verify(mainWindow.active) 0101 keyClick(Qt.Key_Left, Qt.AltModifier) 0102 0103 spyCurrentIndex.wait() 0104 0105 compare(mainWindow.pageStack.depth, 2) 0106 compare(mainWindow.pageStack.currentIndex, 0) 0107 compare(spyCurrentIndex.count, 1) 0108 mainWindow.pageStack.pop() 0109 compare(mainWindow.pageStack.depth, 1) 0110 } 0111 0112 function test_pushForgettingHistory() { 0113 let page = mainWindow.pageStack.push(randomPage) 0114 page.title = "P1" 0115 tryCompare(spyCurrentIndex, "count", 1) 0116 page = mainWindow.pageStack.push(randomPage) 0117 page.title = "P2" 0118 tryCompare(spyCurrentIndex, "count", 2) 0119 page = mainWindow.pageStack.push(randomPage) 0120 page.title = "P3" 0121 tryCompare(spyCurrentIndex, "count", 3) 0122 0123 compare(mainWindow.pageStack.depth, 3) 0124 compare(mainWindow.pageStack.currentIndex, 2) 0125 mainWindow.pageStack.currentIndex = 0 0126 page = mainWindow.pageStack.push(randomPage) 0127 compare(mainWindow.pageStack.depth, 2) 0128 compare(mainWindow.pageStack.items[0].title, "P1") 0129 // This is the newly pushed page, everything else went away 0130 compare(mainWindow.pageStack.items[1].title, "") 0131 compare(mainWindow.pageStack.items[1], page) 0132 } 0133 0134 property int destructions: 0 0135 Component { 0136 id: destroyedPage 0137 Kirigami.Page { 0138 id: page 0139 Rectangle { 0140 anchors.fill: parent 0141 color: "blue" 0142 Component.onDestruction: { 0143 testCase.destructions++ 0144 } 0145 } 0146 } 0147 } 0148 SignalSpy { 0149 id: spyDestructions 0150 target: testCase 0151 signalName: "destructionsChanged" 0152 } 0153 function test_clearPages() { 0154 mainWindow.pageStack.push(destroyedPage) 0155 mainWindow.pageStack.push(destroyedPage) 0156 mainWindow.pageStack.push(destroyedPage) 0157 compare(mainWindow.pageStack.depth, 3) 0158 mainWindow.pageStack.clear() 0159 0160 compare(mainWindow.pageStack.depth, 0) 0161 spyDestructions.wait() 0162 compare(testCase.destructions, 3) 0163 } 0164 }