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