on xenial help sign in
Mock fixes & test fixes
commit8cd3b338e4e1aa5cffdc793f3ff7f8801d23d964 authorNick Dedekind <nick.dedekind@canonical.com> dateThu 30 Mar 2017, 11:38 (10 years ago) parent9eb2692
10 files changed+67−40
plugins/WindowManager/TopLevelWindowModel.cpp+17−22 plugins/WindowManager/TopLevelWindowModel.h+1−3 tests/mocks/Unity/Application/SurfaceManager.cpp+25−10 tests/mocks/Unity/Application/SurfaceManager.h+2−3 tests/mocks/WindowManager/WindowManagementPolicy.cpp+14 tests/mocks/WindowManager/WindowManagementPolicy.h+2 tests/qmltests/ApplicationMenuDataLoader.qml+2−2 tests/qmltests/Stage/tst_PhoneStage.qml+1 tests/qmltests/Stage/tst_TabletStage.qml+2 tests/utils/modules/Unity/Test/UnityTestCase.qml+1
plugins/WindowManager/TopLevelWindowModel.cpp+17−22
@@ -120,14 +120,10 @@ void TopLevelWindowModel::setSurfaceManager(unityapi::SurfaceManagerInterface *s
120120 m_surfaceManager = surfaceManager;
121121
122122 if (m_surfaceManager) {
123+ connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesAddedToWorkspace, this, &TopLevelWindowModel::onSurfacesAddedToWorkspace);
123124 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesRaised, this, &TopLevelWindowModel::onSurfacesRaised);
124125 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::modificationsStarted, this, &TopLevelWindowModel::onModificationsStarted);
125126 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::modificationsEnded, this, &TopLevelWindowModel::onModificationsEnded);
126−
127− connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesAddedToWorkspace,
128− this, &TopLevelWindowModel::onSurfacesAddedToWorkspace);
129− connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesAboutToBeRemovedFromWorkspace,
130− this, &TopLevelWindowModel::onSurfacesAboutToBeRemovedFromWorkspace);
131127 }
132128
133129 refreshWindows();
@@ -382,7 +378,10 @@ void TopLevelWindowModel::onSurfacesAddedToWorkspace(const std::shared_ptr<miral
382378 const QVector<unity::shell::application::MirSurfaceInterface*> surfaces)
383379{
384380 if (!m_workspace || !m_applicationManager) return;
385− if (workspace != m_workspace->workspace()) return;
381+ if (workspace != m_workspace->workspace()) {
382+ removeSurfaces(surfaces);
383+ return;
384+ }
386385
387386 Q_FOREACH(auto surface, surfaces) {
388387 if (m_allSurfaces.contains(surface)) continue;
@@ -426,11 +425,8 @@ void TopLevelWindowModel::onSurfacesAddedToWorkspace(const std::shared_ptr<miral
426425 }
427426}
428427
429−void TopLevelWindowModel::onSurfacesAboutToBeRemovedFromWorkspace(const std::shared_ptr<miral::Workspace> &workspace,
430− const QVector<unity::shell::application::MirSurfaceInterface *> surfaces)
428+void TopLevelWindowModel::removeSurfaces(const QVector<unity::shell::application::MirSurfaceInterface *> surfaces)
431429{
432− if (!m_workspace || workspace != m_workspace->workspace()) return;
433−
434430 int start = -1;
435431 int end = -1;
436432 for (auto iter = surfaces.constBegin(); iter != surfaces.constEnd();) {
@@ -440,7 +436,7 @@ void TopLevelWindowModel::onSurfacesAboutToBeRemovedFromWorkspace(const std::sha
440436 // Do removals in adjacent blocks.
441437 start = end = indexOf(surface);
442438 if (start == -1) {
443− // probably a child surface
439+ // could be a child surface
444440 m_allSurfaces.remove(surface);
445441 continue;
446442 }
@@ -538,6 +534,15 @@ void TopLevelWindowModel::setInputMethodWindow(Window *window)
538534void TopLevelWindowModel::removeInputMethodWindow()
539535{
540536 if (m_inputMethodWindow) {
537+ auto surface = m_inputMethodWindow->surface();
538+ if (surface) {
539+ m_allSurfaces.remove(surface);
540+ }
541+ if (m_focusedWindow == m_inputMethodWindow) {
542+ setFocusedWindow(nullptr);
543+ m_focusedWindowCleared = false;
544+ }
545+
541546 delete m_inputMethodWindow;
542547 m_inputMethodWindow = nullptr;
543548 Q_EMIT inputMethodSurfaceChanged(nullptr);
@@ -549,7 +554,7 @@ void TopLevelWindowModel::onSurfacesRaised(const QVector<unityapi::MirSurfaceInt
549554 DEBUG_MSG << "(" << surfaces << ")";
550555 const int raiseCount = surfaces.size();
551556 for (int i = 0; i < raiseCount; i++) {
552− int fromIndex = findIndexOf(surfaces[i]);
557+ int fromIndex = indexOf(surfaces[i]);
553558 if (fromIndex != -1) {
554559 move(fromIndex, 0);
555560 }
@@ -576,16 +581,6 @@ QVariant TopLevelWindowModel::data(const QModelIndex& index, int role) const
576581 }
577582}
578583
579−int TopLevelWindowModel::findIndexOf(const unityapi::MirSurfaceInterface *surface) const
580−{
581− for (int i=0; i<m_windowModel.count(); i++) {
582− if (m_windowModel[i].window->surface() == surface) {
583− return i;
584− }
585− }
586− return -1;
587−}
588−
589584int TopLevelWindowModel::generateId()
590585{
591586 int id = m_nextId;
plugins/WindowManager/TopLevelWindowModel.h+1−3
@@ -174,8 +174,6 @@ Q_SIGNALS:
174174private Q_SLOTS:
175175 void onSurfacesAddedToWorkspace(const std::shared_ptr<miral::Workspace>& workspace,
176176 const QVector<unity::shell::application::MirSurfaceInterface*> surfaces);
177− void onSurfacesAboutToBeRemovedFromWorkspace(const std::shared_ptr<miral::Workspace>& workspace,
178− const QVector<unity::shell::application::MirSurfaceInterface*> surfaces);
179177 void onSurfacesRaised(const QVector<unity::shell::application::MirSurfaceInterface*> &surfaces);
180178
181179 void onModificationsStarted();
@@ -192,9 +190,9 @@ private:
192190 void setInputMethodWindow(Window *window);
193191 void setFocusedWindow(Window *window);
194192 void removeInputMethodWindow();
195− int findIndexOf(const unity::shell::application::MirSurfaceInterface *surface) const;
196193 void deleteAt(int index);
197194 void removeAt(int index);
195+ void removeSurfaces(const QVector<unity::shell::application::MirSurfaceInterface *> surfaces);
198196
199197 void addApplication(unity::shell::application::ApplicationInfoInterface *application);
200198 void removeApplication(unity::shell::application::ApplicationInfoInterface *application);
tests/mocks/Unity/Application/SurfaceManager.cpp+25−10
@@ -73,9 +73,7 @@ SurfaceManager::~SurfaceManager()
7373{
7474 DEBUG_MSG("");
7575
76− if (m_virtualKeyboard) {
77− m_virtualKeyboard->setLive(false);
78− }
76+ releaseInputMethodSurface();
7977
8078 Q_ASSERT(m_instance == this);
8179 m_instance = nullptr;
@@ -148,13 +146,14 @@ void SurfaceManager::registerSurface(MirSurface *surface)
148146 this->onStateRequested(surface, state);
149147 });
150148
151− const QString persistentId = surface->persistentId();
152149 connect(surface, &QObject::destroyed, this, [=]() {
153− WindowWrapper key = m_surfaceToWindow.take(surface);
154− m_windowToSurface.remove(key);
155− this->onSurfaceDestroyed(surface, persistentId);
150+ auto iter = m_surfaceToWindow.find(surface);
151+ if (iter != m_surfaceToWindow.end()) {
152+ WindowWrapper key = m_surfaceToWindow.value(surface);
153+ WindowManagementPolicy::instance()->removeWindow(key.window);
154+ this->onSurfaceDestroyed(surface);
155+ }
156156 });
157−
158157}
159158
160159void SurfaceManager::notifySurfaceCreated(unityapi::MirSurfaceInterface *surface)
@@ -321,9 +320,17 @@ void SurfaceManager::onStateRequested(MirSurface *surface, Mir::State state)
321320 DEBUG_MSG("("<<surface<<","<<state<<") ended");
322321}
323322
324−void SurfaceManager::onSurfaceDestroyed(MirSurface *surface, const QString& persistentId)
323+void SurfaceManager::onSurfaceDestroyed(MirSurface *surface)
325324{
326325 m_surfaces.removeAll(surface);
326+
327+ auto iter = m_surfaceToWindow.find(surface);
328+ if (iter != m_surfaceToWindow.end()) {
329+ WindowWrapper key = iter.value();
330+ m_windowToSurface.remove(key);
331+ m_surfaceToWindow.erase(iter);
332+ }
333+
327334 if (m_focusedSurface == surface) {
328335 m_focusedSurface = nullptr;
329336
@@ -335,7 +342,7 @@ void SurfaceManager::onSurfaceDestroyed(MirSurface *surface, const QString& pers
335342 m_underModification = false;
336343 Q_EMIT modificationsEnded();
337344 }
338− Q_EMIT surfaceDestroyed(persistentId);
345+ Q_EMIT surfaceRemoved(surface);
339346}
340347
341348void SurfaceManager::focusFirstAvailableSurface()
@@ -371,3 +378,11 @@ void SurfaceManager::createInputMethodSurface()
371378 WindowManagementPolicy::instance()->addWindow(m_surfaceToWindow[m_virtualKeyboard].window);
372379 }
373380}
381+
382+void SurfaceManager::releaseInputMethodSurface()
383+{
384+ if (m_virtualKeyboard) {
385+ m_virtualKeyboard->setLive(false);
386+ m_virtualKeyboard = nullptr;
387+ }
388+}
tests/mocks/Unity/Application/SurfaceManager.h+2−3
@@ -91,10 +91,9 @@ public:
9191
9292public Q_SLOTS:
9393 void createInputMethodSurface();
94+ void releaseInputMethodSurface();
9495
9596Q_SIGNALS:
96− void surfaceDestroyed(const QString& persistentSurfaceId);
97−
9897 void newSurfaceMinimumWidthChanged(int value);
9998 void newSurfaceMaximumWidthChanged(int value);
10099 void newSurfaceMinimumHeightChanged(int value);
@@ -104,7 +103,7 @@ Q_SIGNALS:
104103
105104private Q_SLOTS:
106105 void onStateRequested(MirSurface *surface, Mir::State state);
107− void onSurfaceDestroyed(MirSurface *surface, const QString& persistentId);
106+ void onSurfaceDestroyed(MirSurface *surface);
108107
109108private:
110109 void doRaise(unity::shell::application::MirSurfaceInterface *surface);
tests/mocks/WindowManager/WindowManagementPolicy.cpp+14
@@ -73,6 +73,20 @@ void WindowManagementPolicy::addWindow(const miral::Window &window)
7373 }
7474}
7575
76+void WindowManagementPolicy::removeWindow(const miral::Window &window)
77+{
78+ WorkspaceWindows::iterator i = m_windows.begin();
79+ while (i != m_windows.end()) {
80+ if (i.value() == window) {
81+ Q_EMIT windowsAboutToBeRemovedFromWorkspace(i.key(), { window });
82+ i = m_windows.erase(i);
83+ } else {
84+ ++i;
85+ }
86+ }
87+ Q_EMIT windowRemoved(window);
88+}
89+
7690void WindowManagementPolicy::forEachWindowInWorkspace(const std::shared_ptr<miral::Workspace> &workspace, const std::function<void(const miral::Window &)> &callback)
7791{
7892 WorkspaceWindows::iterator i = m_windows.find(workspace);
tests/mocks/WindowManager/WindowManagementPolicy.h+2
@@ -48,6 +48,7 @@ public:
4848 void setActiveWorkspace(const std::shared_ptr<miral::Workspace> &workspace) override;
4949
5050 void addWindow(const miral::Window& window);
51+ void removeWindow(const miral::Window& window);
5152
5253 void forEachWindowInWorkspace(std::shared_ptr<miral::Workspace> const &workspace,
5354 std::function<void(miral::Window const&)> const &callback);
@@ -59,6 +60,7 @@ public:
5960
6061Q_SIGNALS:
6162 void windowAdded(const miral::Window& window);
63+ void windowRemoved(const miral::Window& window);
6264 void windowsAddedToWorkspace(const std::shared_ptr<miral::Workspace> &workspace, const std::vector<miral::Window> &windows);
6365 void windowsAboutToBeRemovedFromWorkspace(const std::shared_ptr<miral::Workspace> &workspace, const std::vector<miral::Window> &windows);
6466
tests/qmltests/ApplicationMenuDataLoader.qml+2−2
@@ -30,8 +30,8 @@ Object {
3030 ApplicationMenuRegistry.RegisterSurfaceMenu(surface.persistentId, fakeMenuPath, fakeMenuPath, ":1");
3131 Indicators.UnityMenuModelCache.setCachedModelData(fakeMenuPath, generateTestData(4, 3, 2, 3, "menu"));
3232 }
33− onSurfaceDestroyed: {
34− ApplicationMenuRegistry.UnregisterSurfaceMenu(persistentSurfaceId, "/app");
33+ onSurfaceRemoved: {
34+ ApplicationMenuRegistry.UnregisterSurfaceMenu(surface.persistentId, "/app");
3535 }
3636 }
3737
tests/qmltests/Stage/tst_PhoneStage.qml+1
@@ -555,6 +555,7 @@ Item {
555555 performEdgeSwipeToShowAppSpread();
556556
557557 var appDelegate = findChild(stage, "appDelegate_" + webbrowserSurfaceId);
558+ verify(appDelegate);
558559 var dragArea = findChild(appDelegate, "dragArea");
559560 verify(dragArea);
560561 tryCompare(dragArea, "closeable", true);
tests/qmltests/Stage/tst_TabletStage.qml+2
@@ -26,6 +26,7 @@ import WindowManager 1.0
2626import ".."
2727import "../../../qml/Stage"
2828import "../../../qml/Components"
29+import "../../../qml/Components/PanelState"
2930
3031Rectangle {
3132 id: root
@@ -57,6 +58,7 @@ Rectangle {
5758 mode: "stagedWithSideStage"
5859 applicationManager: ApplicationManager
5960 topLevelSurfaceList: root.topLevelSurfaceList
61+ panelState: PanelState {}
6062
6163 Component.onCompleted: {
6264 print("starting dash")
tests/utils/modules/Unity/Test/UnityTestCase.qml+1
@@ -654,5 +654,6 @@ TestCase {
654654 tryCompare(application, "state", ApplicationInfo.Stopped);
655655 }
656656 compare(ApplicationManager.count, 0);
657+ SurfaceManager.releaseInputMethodSurface();
657658 }
658659}