| 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/contents/blimp_contents_impl.h" | 9 #include "blimp/client/core/contents/blimp_contents_impl.h" |
| 10 #include "blimp/client/core/render_widget/render_widget_feature.h" |
| 11 #include "blimp/client/support/compositor/mock_compositor_dependencies.h" |
| 9 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 14 |
| 12 namespace { | 15 namespace { |
| 13 const int kDummyTabId = 0; | 16 const int kDummyTabId = 0; |
| 14 } | 17 } |
| 15 | 18 |
| 16 namespace blimp { | 19 namespace blimp { |
| 17 namespace client { | 20 namespace client { |
| 18 | 21 |
| 19 namespace { | 22 namespace { |
| 20 | 23 |
| 21 class BlimpContentsObserverTest : public BlimpContentsObserver { | 24 class BlimpContentsObserverTest : public BlimpContentsObserver { |
| 22 public: | 25 public: |
| 23 explicit BlimpContentsObserverTest(BlimpContents* blimp_contents) | 26 explicit BlimpContentsObserverTest(BlimpContents* blimp_contents) |
| 24 : BlimpContentsObserver(blimp_contents) {} | 27 : BlimpContentsObserver(blimp_contents) {} |
| 25 | 28 |
| 26 MOCK_METHOD0(OnContentsDestroyed, void()); | 29 MOCK_METHOD0(OnContentsDestroyed, void()); |
| 27 | 30 |
| 28 private: | 31 private: |
| 29 DISALLOW_COPY_AND_ASSIGN(BlimpContentsObserverTest); | 32 DISALLOW_COPY_AND_ASSIGN(BlimpContentsObserverTest); |
| 30 }; | 33 }; |
| 31 | 34 |
| 32 TEST(BlimpContentsObserverUnittests, ObserverDies) { | 35 TEST(BlimpContentsObserverUnittests, ObserverDies) { |
| 33 BlimpContentsImpl contents(kDummyTabId, nullptr, nullptr, nullptr); | 36 RenderWidgetFeature render_widget_feature; |
| 37 BlimpCompositorDependencies compositor_deps( |
| 38 base::MakeUnique<MockCompositorDependencies>()); |
| 39 BlimpContentsImpl contents(kDummyTabId, &compositor_deps, nullptr, nullptr, |
| 40 &render_widget_feature, nullptr); |
| 34 | 41 |
| 35 std::unique_ptr<BlimpContentsObserver> observer = | 42 std::unique_ptr<BlimpContentsObserver> observer = |
| 36 base::MakeUnique<BlimpContentsObserverTest>(&contents); | 43 base::MakeUnique<BlimpContentsObserverTest>(&contents); |
| 37 BlimpContentsObserver* observer_ptr = observer.get(); | 44 BlimpContentsObserver* observer_ptr = observer.get(); |
| 38 EXPECT_TRUE(contents.HasObserver(observer_ptr)); | 45 EXPECT_TRUE(contents.HasObserver(observer_ptr)); |
| 39 observer.reset(); | 46 observer.reset(); |
| 40 | 47 |
| 41 EXPECT_FALSE(contents.HasObserver(observer_ptr)); | 48 EXPECT_FALSE(contents.HasObserver(observer_ptr)); |
| 42 } | 49 } |
| 43 | 50 |
| 44 TEST(BlimpContentsObserverUnittests, ContentsDies) { | 51 TEST(BlimpContentsObserverUnittests, ContentsDies) { |
| 45 std::unique_ptr<BlimpContentsObserverTest> observer; | 52 std::unique_ptr<BlimpContentsObserverTest> observer; |
| 46 | 53 RenderWidgetFeature render_widget_feature; |
| 54 BlimpCompositorDependencies compositor_deps( |
| 55 base::MakeUnique<MockCompositorDependencies>()); |
| 47 std::unique_ptr<BlimpContentsImpl> contents = | 56 std::unique_ptr<BlimpContentsImpl> contents = |
| 48 base::MakeUnique<BlimpContentsImpl>(kDummyTabId, nullptr, nullptr, | 57 base::MakeUnique<BlimpContentsImpl>(kDummyTabId, &compositor_deps, |
| 49 nullptr); | 58 nullptr, nullptr, |
| 59 &render_widget_feature, nullptr); |
| 50 observer.reset(new BlimpContentsObserverTest(contents.get())); | 60 observer.reset(new BlimpContentsObserverTest(contents.get())); |
| 51 EXPECT_CALL(*observer, OnContentsDestroyed()).Times(1); | 61 EXPECT_CALL(*observer, OnContentsDestroyed()).Times(1); |
| 52 EXPECT_EQ(observer->blimp_contents(), contents.get()); | 62 EXPECT_EQ(observer->blimp_contents(), contents.get()); |
| 53 contents.reset(); | 63 contents.reset(); |
| 54 | 64 |
| 55 EXPECT_EQ(observer->blimp_contents(), nullptr); | 65 EXPECT_EQ(observer->blimp_contents(), nullptr); |
| 56 } | 66 } |
| 57 | 67 |
| 58 } // namespace | 68 } // namespace |
| 59 | 69 |
| 60 } // namespace client | 70 } // namespace client |
| 61 } // namespace blimp | 71 } // namespace blimp |
| OLD | NEW |