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

Side by Side Diff: services/ui/demo/mus_demo_unittests.cc

Issue 2715533005: Make mus_demo_unittests work with multiple root windows (Closed)
Patch Set: Add a unit test for multiple windows. Created 3 years, 9 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/command_line.h" 6 #include "base/command_line.h"
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "services/service_manager/public/cpp/service_test.h" 9 #include "services/service_manager/public/cpp/service_test.h"
10 #include "services/ui/public/interfaces/constants.mojom.h" 10 #include "services/ui/public/interfaces/constants.mojom.h"
11 #include "services/ui/public/interfaces/window_server_test.mojom.h" 11 #include "services/ui/public/interfaces/window_server_test.mojom.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace ui { 14 namespace ui {
15 namespace demo { 15 namespace demo {
16 16
17 namespace { 17 namespace {
18 18
19 const char kTestAppName[] = "mus_demo_unittests"; 19 const char kTestAppName[] = "mus_demo_unittests";
20 20
21 void RunCallback(bool* success, const base::Closure& callback, bool result) { 21 void RunCallback(uint64_t* root_window_count,
22 *success = result; 22 const base::Closure& callback,
23 uint64_t result) {
24 *root_window_count = result;
23 callback.Run(); 25 callback.Run();
24 } 26 }
25 27
26 class MusDemoTest : public service_manager::test::ServiceTest { 28 class MusDemoTest : public service_manager::test::ServiceTest {
27 public: 29 public:
28 MusDemoTest() : service_manager::test::ServiceTest(kTestAppName) {} 30 MusDemoTest() : service_manager::test::ServiceTest(kTestAppName) {}
29 ~MusDemoTest() override {} 31 ~MusDemoTest() override {}
30 32
31 void SetUp() override { 33 void SetUp() override {
32 base::CommandLine::ForCurrentProcess()->AppendSwitch("use-test-config"); 34 base::CommandLine::ForCurrentProcess()->AppendSwitch("use-test-config");
33 ServiceTest::SetUp(); 35 ServiceTest::SetUp();
34 } 36 }
35 37
38 protected:
39 uint64_t StartDemoAndCountDrawnWindows() {
40 connector()->Connect("mus_demo");
41
42 ::ui::mojom::WindowServerTestPtr test_interface;
43 connector()->BindInterface(ui::mojom::kServiceName, &test_interface);
44
45 base::RunLoop run_loop;
46 uint64_t root_window_count = 0;
47 // TODO(kylechar): Fix WindowServer::CreateTreeForWindowManager so that the
48 // WindowTree has the correct name instead of an empty name.
49 // TODO(tonikitoo,fwang): Also fix the WindowTree name for MusDemoExternal.
50 test_interface->EnsureClientHasDrawnRootWindows(
51 "", // WindowTree name is empty.
52 base::Bind(&RunCallback, &root_window_count, run_loop.QuitClosure()));
53 run_loop.Run();
54
55 return root_window_count;
56 }
57
36 private: 58 private:
37 DISALLOW_COPY_AND_ASSIGN(MusDemoTest); 59 DISALLOW_COPY_AND_ASSIGN(MusDemoTest);
38 }; 60 };
39 61
40 } // namespace 62 } // namespace
41 63
42 TEST_F(MusDemoTest, CheckMusDemoDraws) { 64 TEST_F(MusDemoTest, CheckMusDemoDraws) {
43 connector()->Connect("mus_demo"); 65 EXPECT_EQ(1u, StartDemoAndCountDrawnWindows());
66 }
44 67
45 ::ui::mojom::WindowServerTestPtr test_interface; 68 #if defined(USE_OZONE) && !defined(OS_CHROMEOS)
46 connector()->BindInterface(ui::mojom::kServiceName, &test_interface); 69 TEST_F(MusDemoTest, CheckMusDemoMultipleWindows) {
47 70 uint64_t expected_root_window_count = 5;
48 base::RunLoop run_loop; 71 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
49 bool success = false; 72 "external-window-count", std::to_string(expected_root_window_count));
50 // TODO(kylechar): Fix WindowServer::CreateTreeForWindowManager so that the 73 EXPECT_EQ(expected_root_window_count, StartDemoAndCountDrawnWindows());
51 // WindowTree has the correct name instead of an empty name.
52 test_interface->EnsureClientHasDrawnWindow(
53 "", // WindowTree name is empty.
54 base::Bind(&RunCallback, &success, run_loop.QuitClosure()));
55 run_loop.Run();
56 EXPECT_TRUE(success);
57 } 74 }
75 #endif // defined(USE_OZONE) && !defined(OS_CHROMEOS)
58 76
59 } // namespace demo 77 } // namespace demo
60 } // namespace ui 78 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698