OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/memory/scoped_vector.h" | 6 #include "base/memory/scoped_vector.h" |
7 #include "mojo/public/cpp/application/application_delegate.h" | 7 #include "mojo/public/cpp/application/application_delegate.h" |
8 #include "mojo/public/cpp/application/application_impl.h" | 8 #include "mojo/public/cpp/application/application_impl.h" |
9 #include "mojo/service_manager/service_manager.h" | 9 #include "mojo/service_manager/service_manager.h" |
10 #include "mojo/services/public/cpp/view_manager/node.h" | 10 #include "mojo/services/public/cpp/view_manager/node.h" |
11 #include "mojo/services/public/cpp/view_manager/types.h" | 11 #include "mojo/services/public/cpp/view_manager/types.h" |
12 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 12 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
13 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 13 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
14 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" | 14 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" |
15 #include "mojo/services/public/interfaces/window_manager/window_manager.mojom.h" | 15 #include "mojo/services/public/interfaces/window_manager/window_manager.mojom.h" |
16 #include "mojo/shell/shell_test_helper.h" | 16 #include "mojo/shell/shell_test_helper.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 | 18 |
19 namespace mojo { | 19 namespace mojo { |
20 namespace { | 20 namespace { |
21 | 21 |
22 const char kTestServiceURL[] = "mojo:test_url"; | 22 const char kTestServiceURL[] = "mojo:test_url"; |
23 | 23 |
24 void EmptyResultCallback(bool result) {} | 24 void EmptyResultCallback(bool result) {} |
25 | 25 |
26 // Callback from EmbedRoot(). |result| is the result of the | 26 // Callback from Embed(). |result| is the result of the Embed() call and |
27 // Embed() call and |run_loop| the nested RunLoop. | 27 // |run_loop| the nested RunLoop. |
28 void ResultCallback(bool* result_cache, base::RunLoop* run_loop, bool result) { | 28 void ResultCallback(bool* result_cache, base::RunLoop* run_loop, bool result) { |
29 *result_cache = result; | 29 *result_cache = result; |
30 run_loop->Quit(); | 30 run_loop->Quit(); |
31 } | 31 } |
32 | 32 |
33 // Responsible for establishing the initial ViewManagerService connection. | 33 // Responsible for establishing the initial ViewManagerService connection. |
34 // Blocks until result is determined. | 34 // Blocks until result is determined. |
35 bool EmbedRoot(view_manager::ViewManagerInitService* view_manager_init, | 35 bool InitEmbed(view_manager::ViewManagerInitService* view_manager_init, |
36 const std::string& url) { | 36 const std::string& url) { |
37 bool result = false; | 37 bool result = false; |
38 base::RunLoop run_loop; | 38 base::RunLoop run_loop; |
39 view_manager_init->EmbedRoot(url, | 39 view_manager_init->Embed(url, |
40 base::Bind(&ResultCallback, &result, &run_loop)); | 40 base::Bind(&ResultCallback, &result, &run_loop)); |
41 run_loop.Run(); | 41 run_loop.Run(); |
42 return result; | 42 return result; |
43 } | 43 } |
44 | 44 |
45 void OpenWindowCallback(view_manager::Id* id, | 45 void OpenWindowCallback(view_manager::Id* id, |
46 base::RunLoop* run_loop, | 46 base::RunLoop* run_loop, |
47 view_manager::Id window_id) { | 47 view_manager::Id window_id) { |
48 *id = window_id; | 48 *id = window_id; |
49 run_loop->Quit(); | 49 run_loop->Quit(); |
50 } | 50 } |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 virtual void SetUp() MOJO_OVERRIDE { | 210 virtual void SetUp() MOJO_OVERRIDE { |
211 test_helper_.Init(); | 211 test_helper_.Init(); |
212 test_helper_.SetLoaderForURL( | 212 test_helper_.SetLoaderForURL( |
213 scoped_ptr<ServiceLoader>(new TestServiceLoader( | 213 scoped_ptr<ServiceLoader>(new TestServiceLoader( |
214 base::Bind(&WindowManagerApiTest::OnRootAdded, | 214 base::Bind(&WindowManagerApiTest::OnRootAdded, |
215 base::Unretained(this)))), | 215 base::Unretained(this)))), |
216 GURL(kTestServiceURL)); | 216 GURL(kTestServiceURL)); |
217 test_helper_.service_manager()->ConnectToService( | 217 test_helper_.service_manager()->ConnectToService( |
218 GURL("mojo:mojo_view_manager"), | 218 GURL("mojo:mojo_view_manager"), |
219 &view_manager_init_); | 219 &view_manager_init_); |
220 ASSERT_TRUE(EmbedRoot(view_manager_init_.get(), | 220 ASSERT_TRUE(InitEmbed(view_manager_init_.get(), |
221 "mojo:mojo_core_window_manager")); | 221 "mojo:mojo_core_window_manager")); |
222 ConnectToWindowManager(); | 222 ConnectToWindowManager(); |
223 } | 223 } |
224 virtual void TearDown() MOJO_OVERRIDE {} | 224 virtual void TearDown() MOJO_OVERRIDE {} |
225 | 225 |
226 void ConnectToWindowManager() { | 226 void ConnectToWindowManager() { |
227 test_helper_.service_manager()->ConnectToService( | 227 test_helper_.service_manager()->ConnectToService( |
228 GURL("mojo:mojo_core_window_manager"), | 228 GURL("mojo:mojo_core_window_manager"), |
229 &window_manager_); | 229 &window_manager_); |
230 base::RunLoop connect_loop; | 230 base::RunLoop connect_loop; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 | 292 |
293 view_manager::Id second_window = OpenWindow(window_manager_.get()); | 293 view_manager::Id second_window = OpenWindow(window_manager_.get()); |
294 window_manager_->ActivateWindow(second_window, | 294 window_manager_->ActivateWindow(second_window, |
295 base::Bind(&EmptyResultCallback)); | 295 base::Bind(&EmptyResultCallback)); |
296 ids = WaitForActiveWindowChange(); | 296 ids = WaitForActiveWindowChange(); |
297 EXPECT_EQ(ids.first, first_window); | 297 EXPECT_EQ(ids.first, first_window); |
298 EXPECT_EQ(ids.second, second_window); | 298 EXPECT_EQ(ids.second, second_window); |
299 } | 299 } |
300 | 300 |
301 } // namespace mojo | 301 } // namespace mojo |
OLD | NEW |