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 2.7 0008 import QtQuick.Controls 2.0 0009 import QtQuick.Window 2.1 0010 import org.kde.kirigami 2.4 as Kirigami 0011 import QtTest 1.0 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 mainWindow.pageStack.push(randomPage) 0080 mainWindow.pageStack.push(randomPage) 0081 compare(mainWindow.pageStack.depth, 2) 0082 compare(mainWindow.pageStack.currentIndex, 1) 0083 compare(spyCurrentIndex.count, 3) 0084 spyActive.clear() 0085 mainWindow.requestActivate() 0086 spyCurrentIndex.clear() 0087 if (!mainWindow.active) 0088 spyActive.wait() 0089 verify(mainWindow.active) 0090 keyClick(Qt.Key_Left, Qt.AltModifier) 0091 0092 spyCurrentIndex.wait() 0093 0094 compare(mainWindow.pageStack.depth, 2) 0095 compare(mainWindow.pageStack.currentIndex, 0) 0096 compare(spyCurrentIndex.count, 1) 0097 mainWindow.pageStack.pop() 0098 compare(mainWindow.pageStack.depth, 1) 0099 } 0100 0101 property int destructions: 0 0102 Component { 0103 id: destroyedPage 0104 Kirigami.Page { 0105 id: page 0106 Rectangle { 0107 anchors.fill: parent 0108 color: "blue" 0109 Component.onDestruction: { 0110 testCase.destructions++ 0111 } 0112 } 0113 } 0114 } 0115 SignalSpy { 0116 id: spyDestructions 0117 target: testCase 0118 signalName: "destructionsChanged" 0119 } 0120 function test_clearPages() { 0121 mainWindow.pageStack.push(destroyedPage) 0122 mainWindow.pageStack.push(destroyedPage) 0123 mainWindow.pageStack.push(destroyedPage) 0124 compare(mainWindow.pageStack.depth, 3) 0125 mainWindow.pageStack.clear() 0126 0127 compare(mainWindow.pageStack.depth, 0) 0128 spyDestructions.wait() 0129 compare(testCase.destructions, 2) 0130 } 0131 }