Index: services/ui/view_manager/tests/view_manager_test.cc |
diff --git a/services/ui/view_manager/tests/view_manager_test.cc b/services/ui/view_manager/tests/view_manager_test.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..023281b52d69e071887528f9e8a3e51aebca93a3 |
--- /dev/null |
+++ b/services/ui/view_manager/tests/view_manager_test.cc |
@@ -0,0 +1,138 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/bind.h" |
+#include "base/run_loop.h" |
+#include "mojo/public/cpp/application/application_impl.h" |
+#include "mojo/public/cpp/application/application_test_base.h" |
+#include "mojo/public/cpp/application/connect.h" |
+#include "mojo/public/cpp/bindings/strong_binding.h" |
+#include "mojo/services/ui/views/interfaces/view_manager.mojom.h" |
+#include "mojo/services/ui/views/interfaces/views.mojom.h" |
+ |
+namespace view_manager { |
+namespace { |
+ |
+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.
|
+ base::TimeDelta::FromMilliseconds(20); |
+ |
+void print(const std::string& str) { |
+ 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.
|
+} |
+ |
+class ViewAssociateMock : public mojo::ui::ViewAssociate { |
jeffbrown
2016/05/10 19:15:14
rename MockViewAssociate
mikejurka
2016/05/10 23:17:24
Done.
|
+ public: |
+ ViewAssociateMock() {} |
+ 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.
|
+ void Connect(mojo::InterfaceHandle<mojo::ui::ViewInspector> inspector, |
+ const ConnectCallback& callback) override { |
+ print("ViewAssociateMock::Connect"); |
+ num_times_connect_called_++; |
+ // callback_ = callback; |
+ |
+ auto info = mojo::ui::ViewAssociateInfo::New(); |
+ callback.Run(info.Pass()); |
+ } |
+ void ConnectToViewService( |
+ mojo::ui::ViewTokenPtr view_token, |
+ const mojo::String& service_name, |
+ mojo::ScopedMessagePipeHandle client_handle) override { |
+ print("ViewAssociateMock::ConnectToViewService"); |
+ } |
+ void ConnectToViewTreeService( |
+ mojo::ui::ViewTreeTokenPtr view_tree_token, |
+ const mojo::String& service_name, |
+ mojo::ScopedMessagePipeHandle client_handle) override { |
+ print("ViewAssociateMock::ConnectToTreeViewService"); |
+ } |
+}; |
+ |
+class ViewManagerTest : public mojo::test::ApplicationTestBase, |
+ public mojo::ui::ViewListener { |
+ public: |
+ ViewManagerTest() : view_listener_binding_(this), weak_factory_(this) {} |
+ ~ViewManagerTest() override {} |
+ |
+ void SetUp() override { |
+ mojo::test::ApplicationTestBase::SetUp(); |
+ quit_message_loop_callback_ = base::Bind( |
+ &ViewManagerTest::QuitMessageLoopCallback, weak_factory_.GetWeakPtr()); |
+ } |
+ |
+ void QuitMessageLoopCallback() { |
+ print("quit"); |
+ base::MessageLoop::current()->Quit(); |
+ } |
+ |
+ void KickMessageLoop() { |
+ base::MessageLoop::current()->PostDelayedTask( |
+ FROM_HERE, quit_message_loop_callback_, kDefaultMessageDelay); |
+ print("post delayed"); |
+ base::MessageLoop::current()->Run(); |
+ } |
+ |
+ void OnPropertiesChanged( |
+ uint32_t scene_version, |
+ mojo::ui::ViewPropertiesPtr properties, |
+ const OnPropertiesChangedCallback& callback) override { |
+ print("on properties changed"); |
+ } |
+ |
+ protected: |
+ base::Closure quit_message_loop_callback_; |
+ 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.
|
+ 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.
|
+ // mojo::Binding<mojo::ui::ViewAssociate> view_associate_binding_; |
+ base::WeakPtrFactory<ViewManagerTest> weak_factory_; |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(ViewManagerTest); |
+}; |
+ |
+TEST_F(ViewManagerTest, TrueIsTrue) { |
+ EXPECT_TRUE(true); |
+} |
+ |
+TEST_F(ViewManagerTest, TrueIsTrueAgain) { |
+ EXPECT_TRUE(true); |
+} |
+ |
+TEST_F(ViewManagerTest, CreateAViewManager) { |
+ { |
+ mojo::ui::ViewManagerPtr view_manager; |
jeffbrown
2016/05/10 19:15:15
Consider moving this block into Setup() and making
|
+ mojo::ConnectToService(application_impl()->shell(), |
+ "mojo:view_manager_service", |
+ GetProxy(&view_manager)); |
+ |
+ mojo::ui::ViewListenerPtr view_listener; |
+ view_listener_binding_.Bind(mojo::GetProxy(&view_listener)); |
+ |
+ mojo::ui::ViewPtr view; |
+ mojo::ui::ViewOwnerPtr client_view_owner; |
+ view_manager->CreateView(mojo::GetProxy(&view), |
+ 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.
|
+ "test_view"); |
+ |
+ // Create an interface handle for ViewAssociateMock and bind it |
+ mojo::InterfaceHandle<mojo::ui::ViewAssociate> associate; |
+ |
+ ViewAssociateMock* view_associate_impl = new ViewAssociateMock(); |
+ 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.
|
+ view_associate_impl); |
+ |
+ view_associate_binding.Bind(GetProxy(&associate)); |
+ |
+ EXPECT_EQ(0, view_associate_impl->num_times_connect_called_); |
+ view_manager->RegisterViewAssociate(associate.Pass(), "url"); |
+ print("HERE3"); |
+ KickMessageLoop(); |
+ print("HERE4"); |
+ EXPECT_EQ(1, view_associate_impl->num_times_connect_called_); |
+ } |
+ // KickMessageLoop(); |
+ // print("HERE5"); |
+} |
+ |
+} // |
+} // namespace view_manager |