| 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/render_widget/render_widget_feature.h" |  10 #include "blimp/client/core/render_widget/render_widget_feature.h" | 
|  11 #include "blimp/client/support/compositor/mock_compositor_dependencies.h" |  11 #include "blimp/client/support/compositor/mock_compositor_dependencies.h" | 
|  12 #include "testing/gmock/include/gmock/gmock.h" |  12 #include "testing/gmock/include/gmock/gmock.h" | 
|  13 #include "testing/gtest/include/gtest/gtest.h" |  13 #include "testing/gtest/include/gtest/gtest.h" | 
 |  14 #include "ui/gfx/native_widget_types.h" | 
 |  15  | 
 |  16 #if defined(OS_ANDROID) | 
 |  17 #include "ui/android/window_android.h" | 
 |  18 #endif  // defined(OS_ANDROID) | 
|  14  |  19  | 
|  15 namespace { |  20 namespace { | 
|  16 const int kDummyTabId = 0; |  21 const int kDummyTabId = 0; | 
|  17 } |  22 } | 
|  18  |  23  | 
|  19 namespace blimp { |  24 namespace blimp { | 
|  20 namespace client { |  25 namespace client { | 
|  21  |  26  | 
|  22 namespace { |  27 namespace { | 
|  23  |  28  | 
|  24 class BlimpContentsObserverTest : public BlimpContentsObserver { |  29 class TestBlimpContentsObserver : public BlimpContentsObserver { | 
|  25  public: |  30  public: | 
|  26   explicit BlimpContentsObserverTest(BlimpContents* blimp_contents) |  31   explicit TestBlimpContentsObserver(BlimpContents* blimp_contents) | 
|  27       : BlimpContentsObserver(blimp_contents) {} |  32       : BlimpContentsObserver(blimp_contents) {} | 
|  28  |  33  | 
|  29   MOCK_METHOD0(OnContentsDestroyed, void()); |  34   MOCK_METHOD0(OnContentsDestroyed, void()); | 
|  30  |  35  | 
|  31  private: |  36  private: | 
 |  37   DISALLOW_COPY_AND_ASSIGN(TestBlimpContentsObserver); | 
 |  38 }; | 
 |  39  | 
 |  40 class BlimpContentsObserverTest : public testing::Test { | 
 |  41  public: | 
 |  42   BlimpContentsObserverTest() = default; | 
 |  43  | 
 |  44 #if defined(OS_ANDROID) | 
 |  45   void SetUp() override { window_ = ui::WindowAndroid::CreateForTesting(); } | 
 |  46  | 
 |  47   void TearDown() override { window_->DestroyForTesting(); } | 
 |  48 #endif  // defined(OS_ANDROID) | 
 |  49  | 
 |  50  protected: | 
 |  51   gfx::NativeWindow window_ = nullptr; | 
 |  52  | 
 |  53  private: | 
|  32   DISALLOW_COPY_AND_ASSIGN(BlimpContentsObserverTest); |  54   DISALLOW_COPY_AND_ASSIGN(BlimpContentsObserverTest); | 
|  33 }; |  55 }; | 
|  34  |  56  | 
|  35 TEST(BlimpContentsObserverUnittests, ObserverDies) { |  57 TEST_F(BlimpContentsObserverTest, ObserverDies) { | 
|  36   RenderWidgetFeature render_widget_feature; |  58   RenderWidgetFeature render_widget_feature; | 
|  37   BlimpCompositorDependencies compositor_deps( |  59   BlimpCompositorDependencies compositor_deps( | 
|  38       base::MakeUnique<MockCompositorDependencies>()); |  60       base::MakeUnique<MockCompositorDependencies>()); | 
|  39   BlimpContentsImpl contents(kDummyTabId, &compositor_deps, nullptr, nullptr, |  61   BlimpContentsImpl contents(kDummyTabId, window_, &compositor_deps, nullptr, | 
|  40                              &render_widget_feature, nullptr); |  62                              nullptr, &render_widget_feature, nullptr); | 
|  41  |  63  | 
|  42   std::unique_ptr<BlimpContentsObserver> observer = |  64   std::unique_ptr<BlimpContentsObserver> observer = | 
|  43       base::MakeUnique<BlimpContentsObserverTest>(&contents); |  65       base::MakeUnique<TestBlimpContentsObserver>(&contents); | 
|  44   BlimpContentsObserver* observer_ptr = observer.get(); |  66   BlimpContentsObserver* observer_ptr = observer.get(); | 
|  45   EXPECT_TRUE(contents.HasObserver(observer_ptr)); |  67   EXPECT_TRUE(contents.HasObserver(observer_ptr)); | 
|  46   observer.reset(); |  68   observer.reset(); | 
|  47  |  69  | 
|  48   EXPECT_FALSE(contents.HasObserver(observer_ptr)); |  70   EXPECT_FALSE(contents.HasObserver(observer_ptr)); | 
|  49 } |  71 } | 
|  50  |  72  | 
|  51 TEST(BlimpContentsObserverUnittests, ContentsDies) { |  73 TEST_F(BlimpContentsObserverTest, ContentsDies) { | 
|  52   std::unique_ptr<BlimpContentsObserverTest> observer; |  74   std::unique_ptr<TestBlimpContentsObserver> observer; | 
|  53   RenderWidgetFeature render_widget_feature; |  75   RenderWidgetFeature render_widget_feature; | 
|  54   BlimpCompositorDependencies compositor_deps( |  76   BlimpCompositorDependencies compositor_deps( | 
|  55       base::MakeUnique<MockCompositorDependencies>()); |  77       base::MakeUnique<MockCompositorDependencies>()); | 
|  56   std::unique_ptr<BlimpContentsImpl> contents = |  78   std::unique_ptr<BlimpContentsImpl> contents = | 
|  57       base::MakeUnique<BlimpContentsImpl>(kDummyTabId, &compositor_deps, |  79       base::MakeUnique<BlimpContentsImpl>(kDummyTabId, window_, | 
|  58                                           nullptr, nullptr, |  80                                           &compositor_deps, nullptr, nullptr, | 
|  59                                           &render_widget_feature, nullptr); |  81                                           &render_widget_feature, nullptr); | 
|  60   observer.reset(new BlimpContentsObserverTest(contents.get())); |  82   observer.reset(new TestBlimpContentsObserver(contents.get())); | 
|  61   EXPECT_CALL(*observer, OnContentsDestroyed()).Times(1); |  83   EXPECT_CALL(*observer, OnContentsDestroyed()).Times(1); | 
|  62   EXPECT_EQ(observer->blimp_contents(), contents.get()); |  84   EXPECT_EQ(observer->blimp_contents(), contents.get()); | 
|  63   contents.reset(); |  85   contents.reset(); | 
|  64  |  86  | 
|  65   EXPECT_EQ(observer->blimp_contents(), nullptr); |  87   EXPECT_EQ(observer->blimp_contents(), nullptr); | 
|  66 } |  88 } | 
|  67  |  89  | 
|  68 }  // namespace |  90 }  // namespace | 
|  69  |  91  | 
|  70 }  // namespace client |  92 }  // namespace client | 
|  71 }  // namespace blimp |  93 }  // namespace blimp | 
| OLD | NEW |