| 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 "blimp/client/core/render_widget/blimp_document.h" | |
| 6 | |
| 7 #include "base/memory/ptr_util.h" | |
| 8 #include "base/message_loop/message_loop.h" | |
| 9 #include "blimp/client/core/compositor/blimp_compositor_dependencies.h" | |
| 10 #include "blimp/client/core/compositor/blob_image_serialization_processor.h" | |
| 11 #include "blimp/client/core/input/blimp_input_manager.h" | |
| 12 #include "blimp/client/core/render_widget/blimp_document_manager.h" | |
| 13 #include "blimp/client/core/render_widget/mock_render_widget_feature.h" | |
| 14 #include "blimp/client/test/compositor/mock_compositor_dependencies.h" | |
| 15 #include "testing/gmock/include/gmock/gmock.h" | |
| 16 #include "testing/gtest/include/gtest/gtest.h" | |
| 17 | |
| 18 using testing::_; | |
| 19 | |
| 20 namespace blimp { | |
| 21 namespace client { | |
| 22 namespace { | |
| 23 | |
| 24 const int kDefaultContentId = 1; | |
| 25 const int kDefaultDocumentId = 1; | |
| 26 | |
| 27 class MockBlimpDocumentManager : public BlimpDocumentManager { | |
| 28 public: | |
| 29 explicit MockBlimpDocumentManager( | |
| 30 RenderWidgetFeature* render_widget_feature, | |
| 31 BlimpCompositorDependencies* compositor_dependencies) | |
| 32 : BlimpDocumentManager(kDefaultContentId, | |
| 33 render_widget_feature, | |
| 34 compositor_dependencies) {} | |
| 35 | |
| 36 MOCK_METHOD2(SendWebGestureEvent, | |
| 37 void(const int, const blink::WebGestureEvent&)); | |
| 38 MOCK_METHOD2(SendCompositorMessage, | |
| 39 void(const int, const cc::proto::CompositorMessage&)); | |
| 40 }; | |
| 41 | |
| 42 class BlimpDocumentTest : public testing::Test { | |
| 43 public: | |
| 44 void SetUp() override { | |
| 45 compositor_dependencies_ = base::MakeUnique<BlimpCompositorDependencies>( | |
| 46 base::MakeUnique<MockCompositorDependencies>()); | |
| 47 | |
| 48 render_widget_feature_ = base::MakeUnique<MockRenderWidgetFeature>(); | |
| 49 document_manager_ = base::MakeUnique<MockBlimpDocumentManager>( | |
| 50 render_widget_feature_.get(), compositor_dependencies_.get()); | |
| 51 } | |
| 52 | |
| 53 void TearDown() override { | |
| 54 document_manager_.reset(); | |
| 55 compositor_dependencies_.reset(); | |
| 56 render_widget_feature_.reset(); | |
| 57 } | |
| 58 | |
| 59 base::MessageLoop loop_; | |
| 60 BlobImageSerializationProcessor blob_image_serialization_processor_; | |
| 61 std::unique_ptr<MockBlimpDocumentManager> document_manager_; | |
| 62 std::unique_ptr<BlimpCompositorDependencies> compositor_dependencies_; | |
| 63 std::unique_ptr<MockRenderWidgetFeature> render_widget_feature_; | |
| 64 }; | |
| 65 | |
| 66 TEST_F(BlimpDocumentTest, Constructor) { | |
| 67 BlimpDocument doc(kDefaultDocumentId, compositor_dependencies_.get(), | |
| 68 document_manager_.get()); | |
| 69 EXPECT_EQ(doc.document_id(), kDefaultDocumentId); | |
| 70 EXPECT_NE(doc.GetCompositor(), nullptr); | |
| 71 } | |
| 72 | |
| 73 TEST_F(BlimpDocumentTest, ForwardMessagesToManager) { | |
| 74 BlimpDocument doc(kDefaultDocumentId, compositor_dependencies_.get(), | |
| 75 document_manager_.get()); | |
| 76 EXPECT_CALL(*document_manager_, SendCompositorMessage(_, _)).Times(1); | |
| 77 EXPECT_CALL(*document_manager_, SendWebGestureEvent(_, _)).Times(1); | |
| 78 | |
| 79 // When sending messages to the engine, ensure the messages are forwarded | |
| 80 // to the document manager. | |
| 81 BlimpCompositorClient* compositor_client = | |
| 82 static_cast<BlimpCompositorClient*>(&doc); | |
| 83 cc::proto::CompositorMessage fake_message; | |
| 84 compositor_client->SendCompositorMessage(fake_message); | |
| 85 | |
| 86 BlimpInputManagerClient* input_manager_client = | |
| 87 static_cast<BlimpInputManagerClient*>(&doc); | |
| 88 blink::WebGestureEvent fake_gesture; | |
| 89 input_manager_client->SendWebGestureEvent(fake_gesture); | |
| 90 } | |
| 91 | |
| 92 } // namespace | |
| 93 } // namespace client | |
| 94 } // namespace blimp | |
| OLD | NEW |