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

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
« no previous file with comments | « mojo/services/window_manager/DEPS ('k') | mojo/services/window_manager/window_manager_app.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 void OpenWindowCallback(view_manager::Id* id,
36 base::RunLoop* run_loop,
37 view_manager::Id window_id) {
38 *id = window_id;
39 run_loop->Quit();
40 }
41
42 view_manager::Id OpenWindow(WindowManagerService* window_manager) {
43 base::RunLoop run_loop;
44 view_manager::Id id;
45 window_manager->OpenWindow(
46 base::Bind(&OpenWindowCallback, &id, &run_loop));
47 run_loop.Run();
48 return id;
49 }
50
51 class TestWindowManagerClient : public WindowManagerClient {
52 public:
53 explicit TestWindowManagerClient(base::RunLoop* run_loop)
54 : run_loop_(run_loop) {}
55 virtual ~TestWindowManagerClient() {}
56
57 private:
58 // Overridden from WindowManagerClient:
59 virtual void OnWindowManagerReady() MOJO_OVERRIDE {
60 run_loop_->Quit();
61 }
62 virtual void OnCaptureChanged(
63 view_manager::Id old_capture_node_id,
64 view_manager::Id new_capture_node_id) MOJO_OVERRIDE {}
65
66 base::RunLoop* run_loop_;
67
68 DISALLOW_COPY_AND_ASSIGN(TestWindowManagerClient);
69 };
70
71 } // namespace
72
73 class WindowManagerApiTest : public testing::Test {
74 public:
75 WindowManagerApiTest() {}
76 virtual ~WindowManagerApiTest() {}
77
78 protected:
79 WindowManagerServicePtr window_manager_;
80
81 private:
82 // Overridden from testing::Test:
83 virtual void SetUp() MOJO_OVERRIDE {
84 test_helper_.Init();
85 test_helper_.service_manager()->ConnectToService(
86 GURL("mojo:mojo_view_manager"),
87 &view_manager_init_);
88 ASSERT_TRUE(EmbedRoot(view_manager_init_.get(),
89 "mojo:mojo_core_window_manager"));
90 ConnectToWindowManager();
91 }
92 virtual void TearDown() MOJO_OVERRIDE {}
93
94 void ConnectToWindowManager() {
95 test_helper_.service_manager()->ConnectToService(
96 GURL("mojo:mojo_core_window_manager"),
97 &window_manager_);
98 base::RunLoop connect_loop;
99 window_manager_client_ = new TestWindowManagerClient(&connect_loop);
100 window_manager_.set_client(window_manager_client_);
101 connect_loop.Run();
102 }
103
104 base::MessageLoop loop_;
105 shell::ShellTestHelper test_helper_;
106 view_manager::ViewManagerInitServicePtr view_manager_init_;
107 TestWindowManagerClient* window_manager_client_;
108
109 DISALLOW_COPY_AND_ASSIGN(WindowManagerApiTest);
110 };
111
112 TEST_F(WindowManagerApiTest, OpenWindow) {
113 OpenWindow(window_manager_.get());
114 }
115
116 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/window_manager/DEPS ('k') | mojo/services/window_manager/window_manager_app.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698