summaryrefslogtreecommitdiffstats
path: root/mash/wm/window_manager_apptest.cc
blob: 8f9b0f01fb4a67233274b2af5635c86f7e46b010 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <stdint.h>
#include <utility>

#include "base/bind.h"
#include "base/macros.h"
#include "components/mus/public/cpp/window.h"
#include "components/mus/public/cpp/window_tree_connection.h"
#include "components/mus/public/cpp/window_tree_delegate.h"
#include "components/mus/public/interfaces/window_manager.mojom.h"
#include "components/mus/public/interfaces/window_tree.mojom.h"
#include "mojo/application/public/cpp/application_impl.h"
#include "mojo/application/public/cpp/application_test_base.h"

namespace mash {
namespace wm {

class WindowManagerAppTest : public mojo::test::ApplicationTestBase,
                             public mus::WindowTreeDelegate {
 public:
  WindowManagerAppTest() {}
  ~WindowManagerAppTest() override {}

 protected:
  void ConnectToWindowManager(mus::mojom::WindowManagerPtr* window_manager) {
    application_impl()->ConnectToService("mojo:desktop_wm", window_manager);
  }

  mus::Window* OpenWindow(mus::mojom::WindowManager* window_manager) {
    mus::mojom::WindowTreeClientPtr window_tree_client;
    mojo::InterfaceRequest<mus::mojom::WindowTreeClient>
        window_tree_client_request = GetProxy(&window_tree_client);
    mojo::Map<mojo::String, mojo::Array<uint8_t>> properties;
    properties.mark_non_null();
    window_manager->OpenWindow(std::move(window_tree_client),
                               std::move(properties));
    mus::WindowTreeConnection* connection = mus::WindowTreeConnection::Create(
        this, std::move(window_tree_client_request),
        mus::WindowTreeConnection::CreateType::WAIT_FOR_EMBED);
    return *connection->GetRoots().begin();
  }

 private:
  // mus::WindowTreeDelegate:
  void OnEmbed(mus::Window* root) override {}
  void OnConnectionLost(mus::WindowTreeConnection* connection) override {}

  DISALLOW_COPY_AND_ASSIGN(WindowManagerAppTest);
};

TEST_F(WindowManagerAppTest, OpenWindow) {
  mus::mojom::WindowManagerPtr connection;
  ConnectToWindowManager(&connection);

  ASSERT_TRUE(OpenWindow(connection.get()));
}

}  // namespace wm
}  // namespace mash