Chromium Code Reviews| 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 "mojo/public/cpp/application/application_impl.h" | |
| 6 #include "mojo/public/cpp/application/connect.h" | |
| 7 #include "mojo/services/ui/views/interfaces/view_manager.mojom.h" | |
| 8 #include "mojo/services/ui/views/interfaces/views.mojom.h" | |
| 9 #include "services/ui/view_manager/tests/mock_view_associate.h" | |
| 10 #include "services/ui/view_manager/tests/view_manager_test_base.h" | |
| 11 | |
| 12 namespace view_manager { | |
| 13 namespace test { | |
| 14 | |
| 15 class MockViewListener : public mojo::ui::ViewListener { | |
| 16 public: | |
| 17 MockViewListener() {} | |
| 18 ~MockViewListener() override {} | |
| 19 | |
| 20 void OnPropertiesChanged( | |
| 21 uint32_t scene_version, | |
| 22 mojo::ui::ViewPropertiesPtr properties, | |
| 23 const OnPropertiesChangedCallback& callback) override {} | |
| 24 }; | |
| 25 | |
| 26 class ViewManagerTest : public ViewManagerTestBase { | |
| 27 public: | |
| 28 ViewManagerTest() {} | |
| 29 ~ViewManagerTest() override {} | |
| 30 | |
| 31 void SetUp() override { | |
| 32 ViewManagerTestBase::SetUp(); | |
| 33 | |
| 34 // Connect to view manager | |
| 35 mojo::ConnectToService(application_impl()->shell(), | |
| 36 "mojo:view_manager_service", | |
| 37 mojo::GetProxy(&view_manager_)); | |
| 38 } | |
| 39 | |
| 40 protected: | |
| 41 mojo::ui::ViewManagerPtr view_manager_; | |
| 42 | |
| 43 private: | |
| 44 DISALLOW_COPY_AND_ASSIGN(ViewManagerTest); | |
| 45 }; | |
| 46 | |
| 47 TEST_F(ViewManagerTest, CreateAViewManagerAndView) { | |
| 48 // Create and bind a mock view listener | |
| 49 mojo::ui::ViewListenerPtr view_listener; | |
| 50 MockViewListener mock_view_listener; | |
| 51 mojo::Binding<mojo::ui::ViewListener> view_listener_binding( | |
| 52 &mock_view_listener, mojo::GetProxy(&view_listener)); | |
| 53 | |
| 54 // Create a view | |
| 55 mojo::ui::ViewPtr view; | |
| 56 mojo::ui::ViewOwnerPtr client_view_owner; | |
| 57 view_manager_->CreateView(mojo::GetProxy(&view), | |
| 58 mojo::GetProxy(&client_view_owner), | |
| 59 view_listener.Pass(), "test_view"); | |
| 60 | |
| 61 // Call View::GetToken. Check that you get the callback. | |
| 62 int view_token_callback_invokecount = 0; | |
| 63 auto view_token_callback = [&view_token_callback_invokecount]( | |
| 64 mojo::ui::ViewTokenPtr token) { view_token_callback_invokecount++; }; | |
| 65 | |
| 66 EXPECT_EQ(0, view_token_callback_invokecount); | |
| 67 view->GetToken(view_token_callback); | |
| 68 | |
| 69 KICK_MESSAGE_LOOP_WHILE(view_token_callback_invokecount != 1); | |
| 70 | |
| 71 EXPECT_EQ(1, view_token_callback_invokecount); | |
| 72 } | |
| 73 | |
| 74 TEST_F(ViewManagerTest, ConnectAMockViewAssociate) { | |
| 75 // Create and bind a MockViewAssociate | |
| 76 mojo::InterfaceHandle<mojo::ui::ViewAssociate> associate; | |
| 77 MockViewAssociate mock_view_associate; | |
| 78 mojo::Binding<mojo::ui::ViewAssociate> view_associate_binding( | |
| 79 &mock_view_associate, mojo::GetProxy(&associate)); | |
| 80 | |
| 81 // Call ViewManager::RegisterViewAssociate. MockViewAssociate::Connect | |
| 82 // should be called back | |
| 83 EXPECT_EQ(0, mock_view_associate.connect_invokecount); | |
| 84 view_manager_->RegisterViewAssociate(associate.Pass()); | |
| 85 | |
| 86 KICK_MESSAGE_LOOP_WHILE(mock_view_associate.connect_invokecount != 1); | |
| 87 | |
| 88 EXPECT_EQ(1, mock_view_associate.connect_invokecount); | |
|
jeffbrown
2016/05/11 23:44:16
Would be good to test that we can actually retriev
| |
| 89 } | |
| 90 | |
| 91 } // namespace test | |
| 92 } // namespace view_manager | |
| OLD | NEW |