| 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/contents/blimp_contents_impl.h" | |
| 6 | |
| 7 #include "base/memory/ptr_util.h" | |
| 8 #include "base/message_loop/message_loop.h" | |
| 9 #include "base/run_loop.h" | |
| 10 #include "blimp/client/core/compositor/blimp_compositor_dependencies.h" | |
| 11 #include "blimp/client/core/contents/fake_navigation_feature.h" | |
| 12 #include "blimp/client/core/contents/ime_feature.h" | |
| 13 #include "blimp/client/core/contents/tab_control_feature.h" | |
| 14 #include "blimp/client/core/render_widget/render_widget_feature.h" | |
| 15 #include "blimp/client/public/contents/blimp_contents_observer.h" | |
| 16 #include "blimp/client/test/compositor/mock_compositor_dependencies.h" | |
| 17 #include "testing/gmock/include/gmock/gmock.h" | |
| 18 #include "testing/gtest/include/gtest/gtest.h" | |
| 19 #include "ui/gfx/native_widget_types.h" | |
| 20 | |
| 21 #if defined(OS_ANDROID) | |
| 22 #include "ui/android/window_android.h" | |
| 23 #endif // defined(OS_ANDROID) | |
| 24 | |
| 25 namespace blimp { | |
| 26 namespace client { | |
| 27 namespace { | |
| 28 | |
| 29 const char kExampleURL[] = "https://www.example.com/"; | |
| 30 const char kOtherExampleURL[] = "https://www.otherexample.com/"; | |
| 31 const int kDummyBlimpContentsId = 0; | |
| 32 | |
| 33 class MockBlimpContentsObserver : public BlimpContentsObserver { | |
| 34 public: | |
| 35 explicit MockBlimpContentsObserver(BlimpContents* blimp_contents) | |
| 36 : BlimpContentsObserver(blimp_contents) {} | |
| 37 ~MockBlimpContentsObserver() override = default; | |
| 38 | |
| 39 MOCK_METHOD0(OnNavigationStateChanged, void()); | |
| 40 | |
| 41 private: | |
| 42 DISALLOW_COPY_AND_ASSIGN(MockBlimpContentsObserver); | |
| 43 }; | |
| 44 | |
| 45 class MockTabControlFeature : public TabControlFeature { | |
| 46 public: | |
| 47 MockTabControlFeature() {} | |
| 48 ~MockTabControlFeature() override = default; | |
| 49 MOCK_METHOD2(SetSizeAndScale, void(const gfx::Size&, float)); | |
| 50 | |
| 51 private: | |
| 52 DISALLOW_COPY_AND_ASSIGN(MockTabControlFeature); | |
| 53 }; | |
| 54 | |
| 55 class BlimpContentsImplTest : public testing::Test { | |
| 56 public: | |
| 57 BlimpContentsImplTest() = default; | |
| 58 | |
| 59 #if defined(OS_ANDROID) | |
| 60 void SetUp() override { window_ = ui::WindowAndroid::CreateForTesting(); } | |
| 61 | |
| 62 void TearDown() override { window_->DestroyForTesting(); } | |
| 63 #endif // defined(OS_ANDROID) | |
| 64 | |
| 65 protected: | |
| 66 gfx::NativeWindow window_ = nullptr; | |
| 67 | |
| 68 private: | |
| 69 DISALLOW_COPY_AND_ASSIGN(BlimpContentsImplTest); | |
| 70 }; | |
| 71 | |
| 72 TEST_F(BlimpContentsImplTest, LoadURLAndNotifyObservers) { | |
| 73 base::MessageLoop loop; | |
| 74 ImeFeature ime_feature; | |
| 75 FakeNavigationFeature navigation_feature; | |
| 76 RenderWidgetFeature render_widget_feature; | |
| 77 BlimpCompositorDependencies compositor_deps( | |
| 78 base::MakeUnique<MockCompositorDependencies>()); | |
| 79 BlimpContentsImpl blimp_contents( | |
| 80 kDummyBlimpContentsId, window_, &compositor_deps, &ime_feature, | |
| 81 &navigation_feature, &render_widget_feature, nullptr); | |
| 82 | |
| 83 BlimpNavigationControllerImpl& navigation_controller = | |
| 84 blimp_contents.GetNavigationController(); | |
| 85 | |
| 86 testing::StrictMock<MockBlimpContentsObserver> observer1(&blimp_contents); | |
| 87 testing::StrictMock<MockBlimpContentsObserver> observer2(&blimp_contents); | |
| 88 | |
| 89 EXPECT_CALL(observer1, OnNavigationStateChanged()); | |
| 90 EXPECT_CALL(observer2, OnNavigationStateChanged()).Times(2); | |
| 91 | |
| 92 navigation_controller.LoadURL(GURL(kExampleURL)); | |
| 93 base::RunLoop().RunUntilIdle(); | |
| 94 | |
| 95 EXPECT_EQ(kExampleURL, navigation_controller.GetURL().spec()); | |
| 96 | |
| 97 // Observer should no longer receive callbacks. | |
| 98 blimp_contents.RemoveObserver(&observer1); | |
| 99 | |
| 100 navigation_controller.LoadURL(GURL(kOtherExampleURL)); | |
| 101 base::RunLoop().RunUntilIdle(); | |
| 102 | |
| 103 EXPECT_EQ(kOtherExampleURL, navigation_controller.GetURL().spec()); | |
| 104 } | |
| 105 | |
| 106 TEST_F(BlimpContentsImplTest, SetSizeAndScaleThroughTabControlFeature) { | |
| 107 int width = 10; | |
| 108 int height = 15; | |
| 109 float dp_to_px = 1.23f; | |
| 110 | |
| 111 ImeFeature ime_feature; | |
| 112 RenderWidgetFeature render_widget_feature; | |
| 113 MockTabControlFeature tab_control_feature; | |
| 114 base::MessageLoop loop; | |
| 115 BlimpCompositorDependencies compositor_deps( | |
| 116 base::MakeUnique<MockCompositorDependencies>()); | |
| 117 BlimpContentsImpl blimp_contents( | |
| 118 kDummyBlimpContentsId, window_, &compositor_deps, &ime_feature, nullptr, | |
| 119 &render_widget_feature, &tab_control_feature); | |
| 120 | |
| 121 EXPECT_CALL(tab_control_feature, | |
| 122 SetSizeAndScale(gfx::Size(width, height), dp_to_px)).Times(1); | |
| 123 | |
| 124 blimp_contents.SetSizeAndScale(gfx::Size(width, height), dp_to_px); | |
| 125 } | |
| 126 | |
| 127 } // namespace | |
| 128 } // namespace client | |
| 129 } // namespace blimp | |
| OLD | NEW |