| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <memory> | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/command_line.h" | |
| 9 #include "base/run_loop.h" | |
| 10 #include "components/mus/public/interfaces/window_server_test.mojom.h" | |
| 11 #include "mash/shelf/public/interfaces/shelf.mojom.h" | |
| 12 #include "mojo/public/cpp/bindings/associated_binding.h" | |
| 13 #include "services/shell/public/cpp/shell_test.h" | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 class TestShelfObserver : public mash::shelf::mojom::ShelfObserver { | |
| 18 public: | |
| 19 explicit TestShelfObserver(mash::shelf::mojom::ShelfControllerPtr* shelf) | |
| 20 : observer_binding_(this) { | |
| 21 mash::shelf::mojom::ShelfObserverAssociatedPtrInfo ptr_info; | |
| 22 observer_binding_.Bind(&ptr_info, shelf->associated_group()); | |
| 23 (*shelf)->AddObserver(std::move(ptr_info)); | |
| 24 } | |
| 25 | |
| 26 ~TestShelfObserver() override {} | |
| 27 | |
| 28 mash::shelf::mojom::Alignment alignment() const { return alignment_; } | |
| 29 mash::shelf::mojom::AutoHideBehavior auto_hide() const { return auto_hide_; } | |
| 30 | |
| 31 void WaitForIncomingMethodCalls(size_t expected_calls) { | |
| 32 DCHECK_EQ(0u, expected_calls_); | |
| 33 expected_calls_ = expected_calls; | |
| 34 DCHECK(!run_loop_ || !run_loop_->running()); | |
| 35 run_loop_.reset(new base::RunLoop()); | |
| 36 run_loop_->Run(); | |
| 37 } | |
| 38 | |
| 39 private: | |
| 40 void OnMethodCall() { | |
| 41 DCHECK_LT(0u, expected_calls_); | |
| 42 DCHECK(run_loop_->running()); | |
| 43 expected_calls_--; | |
| 44 if (expected_calls_ == 0u) | |
| 45 run_loop_->Quit(); | |
| 46 } | |
| 47 | |
| 48 // mash::shelf::mojom::ShelfObserver: | |
| 49 void OnAlignmentChanged(mash::shelf::mojom::Alignment alignment) override { | |
| 50 alignment_ = alignment; | |
| 51 OnMethodCall(); | |
| 52 } | |
| 53 void OnAutoHideBehaviorChanged( | |
| 54 mash::shelf::mojom::AutoHideBehavior auto_hide) override { | |
| 55 auto_hide_ = auto_hide; | |
| 56 OnMethodCall(); | |
| 57 } | |
| 58 | |
| 59 mojo::AssociatedBinding<mash::shelf::mojom::ShelfObserver> observer_binding_; | |
| 60 | |
| 61 mash::shelf::mojom::Alignment alignment_ = | |
| 62 mash::shelf::mojom::Alignment::BOTTOM; | |
| 63 mash::shelf::mojom::AutoHideBehavior auto_hide_ = | |
| 64 mash::shelf::mojom::AutoHideBehavior::NEVER; | |
| 65 | |
| 66 size_t expected_calls_ = 0u; | |
| 67 std::unique_ptr<base::RunLoop> run_loop_; | |
| 68 | |
| 69 DISALLOW_COPY_AND_ASSIGN(TestShelfObserver); | |
| 70 }; | |
| 71 | |
| 72 } // namespace | |
| 73 | |
| 74 namespace ash { | |
| 75 namespace sysui { | |
| 76 | |
| 77 void RunCallback(bool* success, const base::Closure& callback, bool result) { | |
| 78 *success = result; | |
| 79 callback.Run(); | |
| 80 } | |
| 81 | |
| 82 class ShelfDelegateMusTest : public shell::test::ShellTest { | |
| 83 public: | |
| 84 ShelfDelegateMusTest() : ShellTest("exe:mash_unittests") {} | |
| 85 ~ShelfDelegateMusTest() override {} | |
| 86 | |
| 87 private: | |
| 88 void SetUp() override { | |
| 89 base::CommandLine::ForCurrentProcess()->AppendSwitch("use-test-config"); | |
| 90 ShellTest::SetUp(); | |
| 91 } | |
| 92 | |
| 93 DISALLOW_COPY_AND_ASSIGN(ShelfDelegateMusTest); | |
| 94 }; | |
| 95 | |
| 96 TEST_F(ShelfDelegateMusTest, AshSysUIHasDrawnWindow) { | |
| 97 // mash_session embeds ash_sysui, which paints the shelf. | |
| 98 connector()->Connect("mojo:mash_session"); | |
| 99 mus::mojom::WindowServerTestPtr test_interface; | |
| 100 connector()->ConnectToInterface("mojo:mus", &test_interface); | |
| 101 base::RunLoop run_loop; | |
| 102 bool drawn = false; | |
| 103 test_interface->EnsureClientHasDrawnWindow( | |
| 104 "mojo:ash_sysui", | |
| 105 base::Bind(&RunCallback, &drawn, run_loop.QuitClosure())); | |
| 106 run_loop.Run(); | |
| 107 EXPECT_TRUE(drawn); | |
| 108 } | |
| 109 | |
| 110 TEST_F(ShelfDelegateMusTest, ShelfControllerAndObserverBasic) { | |
| 111 connector()->Connect("mojo:mash_session"); | |
| 112 mash::shelf::mojom::ShelfControllerPtr shelf_controller; | |
| 113 connector()->ConnectToInterface("mojo:ash_sysui", &shelf_controller); | |
| 114 | |
| 115 // Adding the observer should fire state initialization function calls. | |
| 116 TestShelfObserver observer(&shelf_controller); | |
| 117 observer.WaitForIncomingMethodCalls(2u); | |
| 118 EXPECT_EQ(mash::shelf::mojom::Alignment::BOTTOM, observer.alignment()); | |
| 119 EXPECT_EQ(mash::shelf::mojom::AutoHideBehavior::NEVER, observer.auto_hide()); | |
| 120 | |
| 121 shelf_controller->SetAlignment(mash::shelf::mojom::Alignment::LEFT); | |
| 122 observer.WaitForIncomingMethodCalls(1u); | |
| 123 EXPECT_EQ(mash::shelf::mojom::Alignment::LEFT, observer.alignment()); | |
| 124 | |
| 125 shelf_controller->SetAutoHideBehavior( | |
| 126 mash::shelf::mojom::AutoHideBehavior::ALWAYS); | |
| 127 observer.WaitForIncomingMethodCalls(1u); | |
| 128 EXPECT_EQ(mash::shelf::mojom::AutoHideBehavior::ALWAYS, observer.auto_hide()); | |
| 129 } | |
| 130 | |
| 131 } // namespace sysui | |
| 132 } // namespace ash | |
| OLD | NEW |