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