OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "blimp/client/public/contents/blimp_contents_observer.h" | 5 #include "blimp/client/public/contents/blimp_contents_observer.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "blimp/client/core/compositor/blimp_compositor_dependencies.h" | 8 #include "blimp/client/core/compositor/blimp_compositor_dependencies.h" |
9 #include "blimp/client/core/contents/blimp_contents_impl.h" | 9 #include "blimp/client/core/contents/blimp_contents_impl.h" |
10 #include "blimp/client/core/contents/ime_feature.h" | 10 #include "blimp/client/core/contents/ime_feature.h" |
11 #include "blimp/client/core/render_widget/render_widget_feature.h" | 11 #include "blimp/client/core/render_widget/render_widget_feature.h" |
12 #include "blimp/client/support/compositor/mock_compositor_dependencies.h" | 12 #include "blimp/client/support/compositor/mock_compositor_dependencies.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "ui/gfx/native_widget_types.h" | 15 #include "ui/gfx/native_widget_types.h" |
16 | 16 |
17 #if defined(OS_ANDROID) | 17 #if defined(OS_ANDROID) |
18 #include "ui/android/window_android.h" | 18 #include "ui/android/window_android.h" |
19 #endif // defined(OS_ANDROID) | 19 #endif // defined(OS_ANDROID) |
20 | 20 |
21 namespace { | 21 namespace { |
22 const int kDummyTabId = 0; | 22 const int kDummyBlimpContentsId = 0; |
23 } | 23 } |
24 | 24 |
25 namespace blimp { | 25 namespace blimp { |
26 namespace client { | 26 namespace client { |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 class TestBlimpContentsObserver : public BlimpContentsObserver { | 30 class TestBlimpContentsObserver : public BlimpContentsObserver { |
31 public: | 31 public: |
32 explicit TestBlimpContentsObserver(BlimpContents* blimp_contents) | 32 explicit TestBlimpContentsObserver(BlimpContents* blimp_contents) |
(...skipping 20 matching lines...) Expand all Loading... |
53 | 53 |
54 private: | 54 private: |
55 DISALLOW_COPY_AND_ASSIGN(BlimpContentsObserverTest); | 55 DISALLOW_COPY_AND_ASSIGN(BlimpContentsObserverTest); |
56 }; | 56 }; |
57 | 57 |
58 TEST_F(BlimpContentsObserverTest, ObserverDies) { | 58 TEST_F(BlimpContentsObserverTest, ObserverDies) { |
59 ImeFeature ime_feature; | 59 ImeFeature ime_feature; |
60 RenderWidgetFeature render_widget_feature; | 60 RenderWidgetFeature render_widget_feature; |
61 BlimpCompositorDependencies compositor_deps( | 61 BlimpCompositorDependencies compositor_deps( |
62 base::MakeUnique<MockCompositorDependencies>()); | 62 base::MakeUnique<MockCompositorDependencies>()); |
63 BlimpContentsImpl contents(kDummyTabId, window_, &compositor_deps, | 63 BlimpContentsImpl contents(kDummyBlimpContentsId, window_, &compositor_deps, |
64 &ime_feature, nullptr, &render_widget_feature, | 64 &ime_feature, nullptr, &render_widget_feature, |
65 nullptr); | 65 nullptr); |
66 | 66 |
67 std::unique_ptr<BlimpContentsObserver> observer = | 67 std::unique_ptr<BlimpContentsObserver> observer = |
68 base::MakeUnique<TestBlimpContentsObserver>(&contents); | 68 base::MakeUnique<TestBlimpContentsObserver>(&contents); |
69 BlimpContentsObserver* observer_ptr = observer.get(); | 69 BlimpContentsObserver* observer_ptr = observer.get(); |
70 EXPECT_TRUE(contents.HasObserver(observer_ptr)); | 70 EXPECT_TRUE(contents.HasObserver(observer_ptr)); |
71 observer.reset(); | 71 observer.reset(); |
72 | 72 |
73 EXPECT_FALSE(contents.HasObserver(observer_ptr)); | 73 EXPECT_FALSE(contents.HasObserver(observer_ptr)); |
74 } | 74 } |
75 | 75 |
76 TEST_F(BlimpContentsObserverTest, ContentsDies) { | 76 TEST_F(BlimpContentsObserverTest, ContentsDies) { |
77 std::unique_ptr<TestBlimpContentsObserver> observer; | 77 std::unique_ptr<TestBlimpContentsObserver> observer; |
78 ImeFeature ime_feature; | 78 ImeFeature ime_feature; |
79 RenderWidgetFeature render_widget_feature; | 79 RenderWidgetFeature render_widget_feature; |
80 BlimpCompositorDependencies compositor_deps( | 80 BlimpCompositorDependencies compositor_deps( |
81 base::MakeUnique<MockCompositorDependencies>()); | 81 base::MakeUnique<MockCompositorDependencies>()); |
82 std::unique_ptr<BlimpContentsImpl> contents = | 82 std::unique_ptr<BlimpContentsImpl> contents = |
83 base::MakeUnique<BlimpContentsImpl>( | 83 base::MakeUnique<BlimpContentsImpl>( |
84 kDummyTabId, window_, &compositor_deps, &ime_feature, nullptr, | 84 kDummyBlimpContentsId, window_, &compositor_deps, &ime_feature, |
85 &render_widget_feature, nullptr); | 85 nullptr, &render_widget_feature, nullptr); |
86 observer.reset(new TestBlimpContentsObserver(contents.get())); | 86 observer.reset(new TestBlimpContentsObserver(contents.get())); |
87 EXPECT_CALL(*observer, OnContentsDestroyed()).Times(1); | 87 EXPECT_CALL(*observer, OnContentsDestroyed()).Times(1); |
88 EXPECT_EQ(observer->blimp_contents(), contents.get()); | 88 EXPECT_EQ(observer->blimp_contents(), contents.get()); |
89 contents.reset(); | 89 contents.reset(); |
90 | 90 |
91 EXPECT_EQ(observer->blimp_contents(), nullptr); | 91 EXPECT_EQ(observer->blimp_contents(), nullptr); |
92 } | 92 } |
93 | 93 |
94 } // namespace | 94 } // namespace |
95 | 95 |
96 } // namespace client | 96 } // namespace client |
97 } // namespace blimp | 97 } // namespace blimp |
OLD | NEW |