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

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

Issue 1049993002: Get mojo_shell building inside chromium checkout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix presubmit Created 5 years, 8 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
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 "base/run_loop.h"
7 #include "mojo/public/cpp/application/application_delegate.h"
8 #include "mojo/public/cpp/application/application_impl.h"
9 #include "mojo/public/cpp/application/application_test_base.h"
10 #include "mojo/public/cpp/application/service_provider_impl.h"
11 #include "mojo/public/cpp/system/macros.h"
12 #include "third_party/mojo_services/src/view_manager/public/cpp/view.h"
13 #include "third_party/mojo_services/src/view_manager/public/cpp/view_manager_cli ent_factory.h"
14 #include "third_party/mojo_services/src/view_manager/public/cpp/view_manager_del egate.h"
15 #include "third_party/mojo_services/src/window_manager/public/interfaces/window_ manager.mojom.h"
16
17 namespace mojo {
18 namespace {
19
20 // TestApplication's view is embedded by the window manager.
21 class TestApplication : public ApplicationDelegate, public ViewManagerDelegate {
22 public:
23 TestApplication() : root_(nullptr) {}
24 ~TestApplication() override {}
25
26 View* root() const { return root_; }
27
28 void set_embed_callback(const base::Closure& callback) {
29 embed_callback_ = callback;
30 }
31
32 private:
33 // ApplicationDelegate:
34 void Initialize(ApplicationImpl* app) override {
35 view_manager_client_factory_.reset(
36 new ViewManagerClientFactory(app->shell(), this));
37 }
38
39 bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
40 connection->AddService(view_manager_client_factory_.get());
41 return true;
42 }
43
44 // ViewManagerDelegate:
45 void OnEmbed(View* root,
46 InterfaceRequest<ServiceProvider> services,
47 ServiceProviderPtr exposed_services) override {
48 root_ = root;
49 embed_callback_.Run();
50 }
51 void OnViewManagerDisconnected(ViewManager* view_manager) override {}
52
53 View* root_;
54 base::Closure embed_callback_;
55 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_;
56
57 MOJO_DISALLOW_COPY_AND_ASSIGN(TestApplication);
58 };
59
60 class TestWindowManagerObserver : public WindowManagerObserver {
61 public:
62 explicit TestWindowManagerObserver(
63 InterfaceRequest<WindowManagerObserver> observer_request)
64 : binding_(this, observer_request.Pass()) {}
65 ~TestWindowManagerObserver() override {}
66
67 private:
68 // Overridden from WindowManagerClient:
69 void OnCaptureChanged(Id new_capture_node_id) override {}
70 void OnFocusChanged(Id focused_node_id) override {}
71 void OnActiveWindowChanged(Id active_window) override {}
72
73 Binding<WindowManagerObserver> binding_;
74
75 DISALLOW_COPY_AND_ASSIGN(TestWindowManagerObserver);
76 };
77
78 class WindowManagerApplicationTest : public test::ApplicationTestBase {
79 public:
80 WindowManagerApplicationTest() {}
81 ~WindowManagerApplicationTest() override {}
82
83 protected:
84 // ApplicationTestBase:
85 void SetUp() override {
86 ApplicationTestBase::SetUp();
87 application_impl()->ConnectToService("mojo:window_manager",
88 &window_manager_);
89 }
90 ApplicationDelegate* GetApplicationDelegate() override {
91 return &test_application_;
92 }
93
94 void EmbedApplicationWithURL(const std::string& url) {
95 window_manager_->Embed(url, nullptr, nullptr);
96
97 base::RunLoop run_loop;
98 test_application_.set_embed_callback(run_loop.QuitClosure());
99 run_loop.Run();
100 }
101
102 WindowManagerPtr window_manager_;
103 TestApplication test_application_;
104
105 private:
106 MOJO_DISALLOW_COPY_AND_ASSIGN(WindowManagerApplicationTest);
107 };
108
109 TEST_F(WindowManagerApplicationTest, Embed) {
110 EXPECT_EQ(nullptr, test_application_.root());
111 EmbedApplicationWithURL(application_impl()->url());
112 EXPECT_NE(nullptr, test_application_.root());
113 }
114
115 struct BoolCallback {
116 BoolCallback(bool* bool_value, base::RunLoop* run_loop)
117 : bool_value(bool_value), run_loop(run_loop) {}
118
119 void Run(bool value) const {
120 *bool_value = value;
121 run_loop->Quit();
122 }
123
124 bool* bool_value;
125 base::RunLoop* run_loop;
126 };
127
128 TEST_F(WindowManagerApplicationTest, SetCaptureFailsFromNonVM) {
129 EmbedApplicationWithURL(application_impl()->url());
130 bool callback_value = true;
131 base::RunLoop run_loop;
132 window_manager_->SetCapture(test_application_.root()->id(),
133 BoolCallback(&callback_value, &run_loop));
134 run_loop.Run();
135 // This call only succeeds for WindowManager connections from the ViewManager.
136 EXPECT_FALSE(callback_value);
137 }
138
139 TEST_F(WindowManagerApplicationTest, FocusWindowFailsFromNonVM) {
140 EmbedApplicationWithURL(application_impl()->url());
141 bool callback_value = true;
142 base::RunLoop run_loop;
143 window_manager_->FocusWindow(test_application_.root()->id(),
144 BoolCallback(&callback_value, &run_loop));
145 run_loop.Run();
146 // This call only succeeds for WindowManager connections from the ViewManager.
147 EXPECT_FALSE(callback_value);
148 }
149
150 TEST_F(WindowManagerApplicationTest, ActivateWindowFailsFromNonVM) {
151 EmbedApplicationWithURL(application_impl()->url());
152 bool callback_value = true;
153 base::RunLoop run_loop;
154 window_manager_->ActivateWindow(test_application_.root()->id(),
155 BoolCallback(&callback_value, &run_loop));
156 run_loop.Run();
157 // This call only succeeds for WindowManager connections from the ViewManager.
158 EXPECT_FALSE(callback_value);
159 }
160
161 struct FocusedAndActiveViewsCallback {
162 FocusedAndActiveViewsCallback(uint32* capture_view_id,
163 uint32* focused_view_id,
164 uint32* active_view_id,
165 base::RunLoop* run_loop)
166 : capture_view_id(capture_view_id),
167 focused_view_id(focused_view_id),
168 active_view_id(active_view_id),
169 run_loop(run_loop) {
170 }
171
172 void Run(uint32 capture, uint32 focused, uint32 active) const {
173 *capture_view_id = capture;
174 *focused_view_id = focused;
175 *active_view_id = active;
176 run_loop->Quit();
177 }
178
179 uint32* capture_view_id;
180 uint32* focused_view_id;
181 uint32* active_view_id;
182 base::RunLoop* run_loop;
183 };
184
185 TEST_F(WindowManagerApplicationTest, GetFocusedAndActiveViewsFailsWithoutFC) {
186 EmbedApplicationWithURL(application_impl()->url());
187 uint32 capture_view_id = -1;
188 uint32 focused_view_id = -1;
189 uint32 active_view_id = -1;
190 base::RunLoop run_loop;
191
192 WindowManagerObserverPtr observer;
193 scoped_ptr<TestWindowManagerObserver> window_manager_observer(
194 new TestWindowManagerObserver(GetProxy(&observer)));
195
196 window_manager_->GetFocusedAndActiveViews(
197 observer.Pass(),
198 FocusedAndActiveViewsCallback(&capture_view_id,
199 &focused_view_id,
200 &active_view_id,
201 &run_loop));
202 run_loop.Run();
203 // This call fails if the WindowManager does not have a FocusController.
204 EXPECT_EQ(0u, capture_view_id);
205 EXPECT_EQ(0u, focused_view_id);
206 EXPECT_EQ(0u, active_view_id);
207 }
208
209 // TODO(msw): Write tests exercising other WindowManager functionality.
210
211 } // namespace
212 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/window_manager/window_manager_app_win.cc ('k') | mojo/services/window_manager/window_manager_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698