 Chromium Code Reviews
 Chromium Code Reviews Issue 1949233002:
  Create a RegisterViewAssociate method in ViewManager  (Closed) 
  Base URL: https://github.com/domokit/mojo.git@master
    
  
    Issue 1949233002:
  Create a RegisterViewAssociate method in ViewManager  (Closed) 
  Base URL: https://github.com/domokit/mojo.git@master| OLD | NEW | 
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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_impl.h" | |
| 8 #include "mojo/public/cpp/application/application_test_base.h" | |
| 9 #include "mojo/public/cpp/application/connect.h" | |
| 10 #include "mojo/public/cpp/bindings/strong_binding.h" | |
| 11 #include "mojo/services/ui/views/interfaces/view_manager.mojom.h" | |
| 12 #include "mojo/services/ui/views/interfaces/views.mojom.h" | |
| 13 | |
| 14 namespace view_manager { | |
| 15 namespace { | |
| 16 | |
| 17 static const base::TimeDelta kDefaultMessageDelay = | |
| 
jeffbrown
2016/05/10 19:15:14
static is implied because this is in an anonymous
 
mikejurka
2016/05/10 23:17:24
Done.
 | |
| 18 base::TimeDelta::FromMilliseconds(20); | |
| 19 | |
| 20 void print(const std::string& str) { | |
| 21 std::cout << str << std::endl << std::flush; | |
| 
jeffbrown
2016/05/10 19:15:15
consider using LOG(INFO) from #include "base/loggi
 
mikejurka
2016/05/10 23:17:24
Done.
 | |
| 22 } | |
| 23 | |
| 24 class ViewAssociateMock : public mojo::ui::ViewAssociate { | |
| 
jeffbrown
2016/05/10 19:15:14
rename MockViewAssociate
 
mikejurka
2016/05/10 23:17:24
Done.
 | |
| 25 public: | |
| 26 ViewAssociateMock() {} | |
| 27 int num_times_connect_called_ = 0; | |
| 
jeffbrown
2016/05/10 19:15:15
order of members is methods, then fields, so this
 
mikejurka
2016/05/10 23:17:24
Done.
 | |
| 28 void Connect(mojo::InterfaceHandle<mojo::ui::ViewInspector> inspector, | |
| 29 const ConnectCallback& callback) override { | |
| 30 print("ViewAssociateMock::Connect"); | |
| 31 num_times_connect_called_++; | |
| 32 // callback_ = callback; | |
| 33 | |
| 34 auto info = mojo::ui::ViewAssociateInfo::New(); | |
| 35 callback.Run(info.Pass()); | |
| 36 } | |
| 37 void ConnectToViewService( | |
| 38 mojo::ui::ViewTokenPtr view_token, | |
| 39 const mojo::String& service_name, | |
| 40 mojo::ScopedMessagePipeHandle client_handle) override { | |
| 41 print("ViewAssociateMock::ConnectToViewService"); | |
| 42 } | |
| 43 void ConnectToViewTreeService( | |
| 44 mojo::ui::ViewTreeTokenPtr view_tree_token, | |
| 45 const mojo::String& service_name, | |
| 46 mojo::ScopedMessagePipeHandle client_handle) override { | |
| 47 print("ViewAssociateMock::ConnectToTreeViewService"); | |
| 48 } | |
| 49 }; | |
| 50 | |
| 51 class ViewManagerTest : public mojo::test::ApplicationTestBase, | |
| 52 public mojo::ui::ViewListener { | |
| 53 public: | |
| 54 ViewManagerTest() : view_listener_binding_(this), weak_factory_(this) {} | |
| 55 ~ViewManagerTest() override {} | |
| 56 | |
| 57 void SetUp() override { | |
| 58 mojo::test::ApplicationTestBase::SetUp(); | |
| 59 quit_message_loop_callback_ = base::Bind( | |
| 60 &ViewManagerTest::QuitMessageLoopCallback, weak_factory_.GetWeakPtr()); | |
| 61 } | |
| 62 | |
| 63 void QuitMessageLoopCallback() { | |
| 64 print("quit"); | |
| 65 base::MessageLoop::current()->Quit(); | |
| 66 } | |
| 67 | |
| 68 void KickMessageLoop() { | |
| 69 base::MessageLoop::current()->PostDelayedTask( | |
| 70 FROM_HERE, quit_message_loop_callback_, kDefaultMessageDelay); | |
| 71 print("post delayed"); | |
| 72 base::MessageLoop::current()->Run(); | |
| 73 } | |
| 74 | |
| 75 void OnPropertiesChanged( | |
| 76 uint32_t scene_version, | |
| 77 mojo::ui::ViewPropertiesPtr properties, | |
| 78 const OnPropertiesChangedCallback& callback) override { | |
| 79 print("on properties changed"); | |
| 80 } | |
| 81 | |
| 82 protected: | |
| 83 base::Closure quit_message_loop_callback_; | |
| 84 mojo::StrongBinding<mojo::ui::ViewListener> view_listener_binding_; | |
| 
jeffbrown
2016/05/10 19:15:15
use Binding here, not StrongBinding
I also recomm
 
mikejurka
2016/05/10 23:17:24
Done.
 | |
| 85 mojo::ui::ViewOwnerPtr client_view_owner_; | |
| 
jeffbrown
2016/05/10 19:15:15
I don't think this is used.
 
mikejurka
2016/05/10 23:17:24
Done.
 | |
| 86 // mojo::Binding<mojo::ui::ViewAssociate> view_associate_binding_; | |
| 87 base::WeakPtrFactory<ViewManagerTest> weak_factory_; | |
| 88 | |
| 89 private: | |
| 90 DISALLOW_COPY_AND_ASSIGN(ViewManagerTest); | |
| 91 }; | |
| 92 | |
| 93 TEST_F(ViewManagerTest, TrueIsTrue) { | |
| 94 EXPECT_TRUE(true); | |
| 95 } | |
| 96 | |
| 97 TEST_F(ViewManagerTest, TrueIsTrueAgain) { | |
| 98 EXPECT_TRUE(true); | |
| 99 } | |
| 100 | |
| 101 TEST_F(ViewManagerTest, CreateAViewManager) { | |
| 102 { | |
| 103 mojo::ui::ViewManagerPtr view_manager; | |
| 
jeffbrown
2016/05/10 19:15:15
Consider moving this block into Setup() and making
 | |
| 104 mojo::ConnectToService(application_impl()->shell(), | |
| 105 "mojo:view_manager_service", | |
| 106 GetProxy(&view_manager)); | |
| 107 | |
| 108 mojo::ui::ViewListenerPtr view_listener; | |
| 109 view_listener_binding_.Bind(mojo::GetProxy(&view_listener)); | |
| 110 | |
| 111 mojo::ui::ViewPtr view; | |
| 112 mojo::ui::ViewOwnerPtr client_view_owner; | |
| 113 view_manager->CreateView(mojo::GetProxy(&view), | |
| 114 GetProxy(&client_view_owner), view_listener.Pass(), | |
| 
jeffbrown
2016/05/10 19:15:14
mojo::GetProxy (not sure why this compiles since m
 
mikejurka
2016/05/10 23:17:24
Done.
 | |
| 115 "test_view"); | |
| 116 | |
| 117 // Create an interface handle for ViewAssociateMock and bind it | |
| 118 mojo::InterfaceHandle<mojo::ui::ViewAssociate> associate; | |
| 119 | |
| 120 ViewAssociateMock* view_associate_impl = new ViewAssociateMock(); | |
| 121 mojo::StrongBinding<mojo::ui::ViewAssociate> view_associate_binding( | |
| 
jeffbrown
2016/05/10 19:15:15
This almost but not quite does what you want.  Unf
 
jeffbrown
2016/05/10 19:54:21
Whoops, I meant:
mojo::Binding<mojo::ui::ViewAsso
 
mikejurka
2016/05/10 23:17:24
Acknowledged.
 
mikejurka
2016/05/10 23:17:24
Done.
 | |
| 122 view_associate_impl); | |
| 123 | |
| 124 view_associate_binding.Bind(GetProxy(&associate)); | |
| 125 | |
| 126 EXPECT_EQ(0, view_associate_impl->num_times_connect_called_); | |
| 127 view_manager->RegisterViewAssociate(associate.Pass(), "url"); | |
| 128 print("HERE3"); | |
| 129 KickMessageLoop(); | |
| 130 print("HERE4"); | |
| 131 EXPECT_EQ(1, view_associate_impl->num_times_connect_called_); | |
| 132 } | |
| 133 // KickMessageLoop(); | |
| 134 // print("HERE5"); | |
| 135 } | |
| 136 | |
| 137 } // | |
| 138 } // namespace view_manager | |
| OLD | NEW |