on abe56ae help sign in
unity8/tests/plugins/WindowManager/tst_TopLevelWindowModel.cpp
142 lines 5.0 kB history raw
1/*
2 * Copyright (C) 2017 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 */
17#include <QtTest/QtTest>
19// WindowManager plugin
20#include <TopLevelWindowModel.h>
21#include <Window.h>
22#include <WindowManagerObjects.h>
23#include <Workspace.h>
24#include <WorkspaceManager.h>
26#include "UnityApplicationMocks.h"
27#include "wmpolicyinterface.h"
30class tst_TopLevelWindowModel : public QObject
32 Q_OBJECT
34private Q_SLOTS:
35 void init(); // called right before each and every test function is executed
36 void cleanup(); // called right after each and every test function is executed
38 void singleSurfaceStartsHidden();
39 void secondSurfaceIsHidden();
41private:
42 Workspace* workspace{nullptr};
43 ApplicationManager *applicationManager{nullptr};
44 SurfaceManager *surfaceManager{nullptr};
45 TopLevelWindowModel *topLevelWindowModel{nullptr};
46};
48void tst_TopLevelWindowModel::init()
50 wmPolicyInterface = new WindowManagementPolicy();
52 applicationManager = new ApplicationManager;
53 surfaceManager = new SurfaceManager;
54 WindowManagerObjects::instance()->setApplicationManager(applicationManager);
55 WindowManagerObjects::instance()->setSurfaceManager(surfaceManager);
57 workspace = WorkspaceManager::instance()->createWorkspace();
58 topLevelWindowModel = workspace->windowModel();
61void tst_TopLevelWindowModel::cleanup()
63 delete workspace;
64 workspace = nullptr;
66 delete surfaceManager;
67 surfaceManager = nullptr;
69 delete applicationManager;
70 applicationManager = nullptr;
72 delete wmPolicyInterface;
73 wmPolicyInterface = nullptr;
76void tst_TopLevelWindowModel::singleSurfaceStartsHidden()
78 QCOMPARE(topLevelWindowModel->rowCount(), 0);
80 auto application = static_cast<Application*>(applicationManager->startApplication(QString("hello-world"), QStringList()));
82 QCOMPARE(topLevelWindowModel->rowCount(), 1);
83 QCOMPARE((void*)topLevelWindowModel->windowAt(0)->surface(), (void*)nullptr);
85 auto surface = new MirSurface;
86 surface->m_state = Mir::HiddenState;
87 application->m_surfaceList.addSurface(surface);
88 Q_EMIT surfaceManager->surfacesAddedToWorkspace(workspace->workspace(), {surface});
90 QCOMPARE(topLevelWindowModel->rowCount(), 1);
91 // not showing the surface as it's still hidden
92 QCOMPARE((void*)topLevelWindowModel->windowAt(0)->surface(), (void*)nullptr);
94 surface->requestState(Mir::RestoredState);
96 QCOMPARE(topLevelWindowModel->rowCount(), 1);
97 // Now that the surface is no longer hidden, TopLevelWindowModel should expose it.
98 QCOMPARE((void*)topLevelWindowModel->windowAt(0)->surface(), (void*)surface);
101void tst_TopLevelWindowModel::secondSurfaceIsHidden()
103 QCOMPARE(topLevelWindowModel->rowCount(), 0);
105 auto application = static_cast<Application*>(applicationManager->startApplication(QString("hello-world"), QStringList()));
107 QCOMPARE(topLevelWindowModel->rowCount(), 1);
108 QCOMPARE((void*)topLevelWindowModel->windowAt(0)->surface(), (void*)nullptr);
110 auto firstSurface = new MirSurface;
111 application->m_surfaceList.addSurface(firstSurface);
112 Q_EMIT surfaceManager->surfacesAddedToWorkspace(workspace->workspace(), {firstSurface});
114 QCOMPARE(topLevelWindowModel->rowCount(), 1);
115 QCOMPARE((void*)topLevelWindowModel->windowAt(0)->surface(), (void*)firstSurface);
117 auto secondSurface = new MirSurface;
118 secondSurface->m_state = Mir::HiddenState;
119 application->m_surfaceList.addSurface(secondSurface);
120 Q_EMIT surfaceManager->surfacesAddedToWorkspace(workspace->workspace(), {secondSurface});
122 // still only the first surface is exposed by TopLevelWindowModel
123 QCOMPARE(topLevelWindowModel->rowCount(), 1);
124 QCOMPARE((void*)topLevelWindowModel->windowAt(0)->surface(), (void*)firstSurface);
126 secondSurface->requestState(Mir::RestoredState);
128 // now the second surface finally shows up
129 QCOMPARE(topLevelWindowModel->rowCount(), 2);
130 QCOMPARE((void*)topLevelWindowModel->windowAt(0)->surface(), (void*)secondSurface);
131 QCOMPARE((void*)topLevelWindowModel->windowAt(1)->surface(), (void*)firstSurface);
133 secondSurface->requestState(Mir::HiddenState);
135 // and it's gone again
136 QCOMPARE(topLevelWindowModel->rowCount(), 1);
137 QCOMPARE((void*)topLevelWindowModel->windowAt(0)->surface(), (void*)firstSurface);
140QTEST_MAIN(tst_TopLevelWindowModel)
142#include "tst_TopLevelWindowModel.moc"