~albaguirre/mir/backport-fixes-to-0.11

« back to all changes in this revision

Viewing changes to tests/acceptance-tests/test_client_surface_visibility.cpp

  • Committer: Tarmac
  • Author(s): Alan Griffiths
  • Date: 2015-01-28 20:21:34 UTC
  • mfrom: (2257.1.31 mir3)
  • Revision ID: tarmac-20150128202134-dn97lf8gwk0xcqbc
shell, frontend: Provide a mir::shell::Shell customization point.

Approved by PS Jenkins bot, Kevin DuBois, Alexandros Frantzis.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright © 2014 Canonical Ltd.
 
2
 * Copyright © 2014-2015 Canonical Ltd.
3
3
 *
4
4
 * This program is free software: you can redistribute it and/or modify it
5
5
 * under the terms of the GNU General Public License version 3,
20
20
 
21
21
#include "mir_toolkit/mir_client_library.h"
22
22
 
 
23
#include "mir/scene/session.h"
23
24
#include "mir/scene/surface.h"
24
 
#include "mir/shell/surface_coordinator_wrapper.h"
 
25
#include "mir/scene/surface_coordinator.h"
 
26
#include "mir/shell/shell_wrapper.h"
25
27
 
26
28
#include "mir_test_framework/connected_client_with_a_surface.h"
27
29
#include "mir_test/wait_condition.h"
32
34
#include <gtest/gtest.h>
33
35
#include <gmock/gmock.h>
34
36
 
 
37
namespace mf = mir::frontend;
35
38
namespace mtf = mir_test_framework;
36
39
namespace mt = mir::test;
37
40
namespace ms = mir::scene;
41
44
 
42
45
namespace
43
46
{
44
 
class StoringSurfaceCoordinator : public msh::SurfaceCoordinatorWrapper
 
47
class StoringShell : public msh::ShellWrapper
45
48
{
46
49
public:
47
 
    using msh::SurfaceCoordinatorWrapper::SurfaceCoordinatorWrapper;
 
50
    StoringShell(
 
51
        std::shared_ptr<msh::Shell> const& wrapped,
 
52
        std::shared_ptr<ms::SurfaceCoordinator> const surface_coordinator) :
 
53
        msh::ShellWrapper{wrapped},
 
54
        surface_coordinator{surface_coordinator}
 
55
    {}
48
56
 
49
 
    std::shared_ptr<ms::Surface> add_surface(
50
 
        ms::SurfaceCreationParameters const& params,
51
 
        ms::Session* session) override
 
57
    mf::SurfaceId create_surface(
 
58
        std::shared_ptr<ms::Session> const& session,
 
59
        ms::SurfaceCreationParameters const& params) override
52
60
    {
53
 
        auto const surface = msh::SurfaceCoordinatorWrapper::add_surface(params, session);
54
 
        surfaces.push_back(surface);
 
61
        auto const surface = msh::ShellWrapper::create_surface(session, params);
 
62
        surfaces.push_back(session->surface(surface));
55
63
        return surface;
56
64
    }
57
65
 
60
68
        return surfaces[index].lock();
61
69
    }
62
70
 
63
 
    void raise(std::weak_ptr<ms::Surface> const& /*surface*/) override
 
71
    void handle_surface_created(std::shared_ptr<ms::Session> const& /*session*/) override
64
72
    {
65
 
         // We get some racy "raise" requests from the DefaultFocusManagement
 
73
         // We get some racy "raise" requests from the DefaultShell
66
74
         // so we ignore any raise requests that we don't issue ourselves
67
75
    }
68
76
 
69
77
    void raise(int index)
70
78
    {
71
 
         msh::SurfaceCoordinatorWrapper::raise(surface(index));
 
79
        surface_coordinator->raise(surface(index));
72
80
    }
73
81
 
74
82
private:
 
83
    std::shared_ptr<ms::SurfaceCoordinator> const surface_coordinator;
75
84
    std::vector<std::weak_ptr<ms::Surface>> surfaces;
76
85
 
77
86
};
99
108
 
100
109
    void SetUp() override
101
110
    {
102
 
        server.wrap_surface_coordinator([&]
103
 
            (std::shared_ptr<ms::SurfaceCoordinator> const& wrapped)
 
111
        server.wrap_shell([&](std::shared_ptr<msh::Shell> const& wrapped)
104
112
            {
105
 
                auto const result = std::make_shared<StoringSurfaceCoordinator>(wrapped);
106
 
                storing_surface_coordinator = result;
 
113
                auto const result = std::make_shared<StoringShell>(wrapped, server.the_surface_coordinator());
 
114
                shell = result;
107
115
                return result;
108
116
            });
109
117
 
136
144
    
137
145
        mir_surface_spec_release(spec);
138
146
 
139
 
        storing_surface_coordinator.lock()->raise(1);
 
147
        shell.lock()->raise(1);
140
148
 
141
149
        mir_surface_swap_buffers_sync(second_surface);
142
150
    }
143
151
 
144
152
    std::shared_ptr<ms::Surface> server_surface(size_t index)
145
153
    {
146
 
        return storing_surface_coordinator.lock()->surface(index);
 
154
        return shell.lock()->surface(index);
147
155
    }
148
156
 
149
157
    void move_surface_off_screen()
158
166
 
159
167
    void raise_surface_on_top()
160
168
    {
161
 
        storing_surface_coordinator.lock()->raise(0);
 
169
        shell.lock()->raise(0);
162
170
    }
163
171
 
164
172
    void expect_surface_visibility_event_after(
186
194
 
187
195
    MirSurface* second_surface = nullptr;
188
196
    testing::NiceMock<MockVisibilityCallback> mock_visibility_callback;
189
 
    std::weak_ptr<StoringSurfaceCoordinator> storing_surface_coordinator;
 
197
    std::weak_ptr<StoringShell> shell;
190
198
};
191
199
 
192
200
}