Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: mojo/services/window_manager/window_manager_api_unittest.cc

Issue 396563002: Window Manager service.. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/bind.h"
6 #include "mojo/service_manager/service_manager.h"
7 #include "mojo/services/public/cpp/view_manager/types.h"
8 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
9 #include "mojo/services/public/interfaces/window_manager/window_manager.mojom.h"
10 #include "mojo/shell/shell_test_helper.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace mojo {
14 namespace {
15
16 // Callback from EmbedRoot(). |result| is the result of the
17 // Embed() call and |run_loop| the nested RunLoop.
18 void ResultCallback(bool* result_cache, base::RunLoop* run_loop, bool result) {
19 *result_cache = result;
20 run_loop->Quit();
21 }
22
23 // Responsible for establishing the initial ViewManagerService connection.
24 // Blocks until result is determined.
25 bool EmbedRoot(view_manager::ViewManagerInitService* view_manager_init,
26 const std::string& url) {
27 bool result = false;
28 base::RunLoop run_loop;
29 view_manager_init->EmbedRoot(url,
30 base::Bind(&ResultCallback, &result, &run_loop));
31 run_loop.Run();
32 return result;
33 }
34
35 bool SetCapture(WindowManagerService* window_manager, view_manager::Id node) {
36 bool result = false;
37 base::RunLoop run_loop;
38 window_manager->SetCapture(node,
39 base::Bind(&ResultCallback, &result, &run_loop));
40 run_loop.Run();
41 return result;
42 }
43
44 void OpenWindowCallback(view_manager::Id* id,
45 base::RunLoop* run_loop,
46 view_manager::Id window_id) {
47 *id = window_id;
48 run_loop->Quit();
49 }
50
51 view_manager::Id OpenWindow(WindowManagerService* window_manager) {
52 base::RunLoop run_loop;
53 view_manager::Id id;
54 window_manager->OpenWindow(
55 base::Bind(&OpenWindowCallback, &id, &run_loop));
56 run_loop.Run();
57 return id;
58 }
59
60 class TestWindowManagerClient : public WindowManagerClient {
61 public:
62 explicit TestWindowManagerClient(base::RunLoop* run_loop)
63 : run_loop_(run_loop) {}
64 virtual ~TestWindowManagerClient() {}
65
66 private:
67 // Overridden from WindowManagerClient:
68 virtual void OnWindowManagerReady() MOJO_OVERRIDE {
69 run_loop_->Quit();
70 }
71 virtual void OnCaptureChanged(
72 view_manager::Id old_capture_node_id,
73 view_manager::Id new_capture_node_id) MOJO_OVERRIDE {}
74
75 base::RunLoop* run_loop_;
76
77 DISALLOW_COPY_AND_ASSIGN(TestWindowManagerClient);
78 };
79
80 } // namespace
81
82 class WindowManagerApiTest : public testing::Test {
83 public:
84 WindowManagerApiTest() {}
85 virtual ~WindowManagerApiTest() {}
86
87 protected:
88 WindowManagerServicePtr window_manager_;
89
90 private:
91 // Overridden from testing::Test:
92 virtual void SetUp() MOJO_OVERRIDE {
93 test_helper_.Init();
94 test_helper_.service_manager()->ConnectToService(
95 GURL("mojo:mojo_view_manager"),
96 &view_manager_init_);
97 ASSERT_TRUE(EmbedRoot(view_manager_init_.get(),
98 "mojo:mojo_core_window_manager"));
99 ConnectToWindowManager();
100 }
101 virtual void TearDown() MOJO_OVERRIDE {}
102
103 void ConnectToWindowManager() {
104 test_helper_.service_manager()->ConnectToService(
105 GURL("mojo:mojo_core_window_manager"),
106 &window_manager_);
107 base::RunLoop connect_loop;
108 window_manager_client_ = new TestWindowManagerClient(&connect_loop);
109 window_manager_.set_client(window_manager_client_);
110 connect_loop.Run();
111 }
112
113 base::MessageLoop loop_;
114 shell::ShellTestHelper test_helper_;
115 view_manager::ViewManagerInitServicePtr view_manager_init_;
116 TestWindowManagerClient* window_manager_client_;
117
118 DISALLOW_COPY_AND_ASSIGN(WindowManagerApiTest);
119 };
120
121 TEST_F(WindowManagerApiTest, OpenWindow) {
122 OpenWindow(window_manager_.get());
123 }
124
125 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698