| 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 "blimp/client/core/contents/blimp_contents_impl.h" | |
| 9 #include "blimp/client/core/contents/fake_navigation_feature.h" | 8 #include "blimp/client/core/contents/fake_navigation_feature.h" |
| 9 #include "blimp/client/core/contents/tab_control_feature.h" |
| 10 #include "blimp/client/public/contents/blimp_contents_observer.h" | 10 #include "blimp/client/public/contents/blimp_contents_observer.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 namespace blimp { | 14 namespace blimp { |
| 15 namespace client { | 15 namespace client { |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 const char kExampleURL[] = "https://www.example.com/"; | 18 const char kExampleURL[] = "https://www.example.com/"; |
| 19 const char kOtherExampleURL[] = "https://www.otherexample.com/"; | 19 const char kOtherExampleURL[] = "https://www.otherexample.com/"; |
| 20 const int kDummyTabId = 0; | 20 const int kDummyTabId = 0; |
| 21 | 21 |
| 22 class MockBlimpContentsObserver : public BlimpContentsObserver { | 22 class MockBlimpContentsObserver : public BlimpContentsObserver { |
| 23 public: | 23 public: |
| 24 explicit MockBlimpContentsObserver(BlimpContents* blimp_contents) | 24 explicit MockBlimpContentsObserver(BlimpContents* blimp_contents) |
| 25 : BlimpContentsObserver(blimp_contents) {} | 25 : BlimpContentsObserver(blimp_contents) {} |
| 26 ~MockBlimpContentsObserver() override = default; | 26 ~MockBlimpContentsObserver() override = default; |
| 27 | 27 |
| 28 MOCK_METHOD0(OnNavigationStateChanged, void()); | 28 MOCK_METHOD0(OnNavigationStateChanged, void()); |
| 29 | 29 |
| 30 private: | 30 private: |
| 31 DISALLOW_COPY_AND_ASSIGN(MockBlimpContentsObserver); | 31 DISALLOW_COPY_AND_ASSIGN(MockBlimpContentsObserver); |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 class MockTabControlFeature : public TabControlFeature { |
| 35 public: |
| 36 MockTabControlFeature() {} |
| 37 ~MockTabControlFeature() override = default; |
| 38 MOCK_METHOD2(SetSizeAndScale, void(const gfx::Size&, float)); |
| 39 |
| 40 private: |
| 41 DISALLOW_COPY_AND_ASSIGN(MockTabControlFeature); |
| 42 }; |
| 43 |
| 34 TEST(BlimpContentsImplTest, LoadURLAndNotifyObservers) { | 44 TEST(BlimpContentsImplTest, LoadURLAndNotifyObservers) { |
| 35 base::MessageLoop loop; | 45 base::MessageLoop loop; |
| 36 BlimpContentsImpl blimp_contents(kDummyTabId); | 46 BlimpContentsImpl blimp_contents(kDummyTabId, nullptr); |
| 37 | 47 |
| 38 BlimpNavigationControllerImpl& navigation_controller = | 48 BlimpNavigationControllerImpl& navigation_controller = |
| 39 blimp_contents.GetNavigationController(); | 49 blimp_contents.GetNavigationController(); |
| 40 FakeNavigationFeature feature; | 50 FakeNavigationFeature feature; |
| 41 feature.SetDelegate(1, &navigation_controller); | 51 feature.SetDelegate(1, &navigation_controller); |
| 42 navigation_controller.SetNavigationFeatureForTesting(&feature); | 52 navigation_controller.SetNavigationFeatureForTesting(&feature); |
| 43 | 53 |
| 44 testing::StrictMock<MockBlimpContentsObserver> observer1(&blimp_contents); | 54 testing::StrictMock<MockBlimpContentsObserver> observer1(&blimp_contents); |
| 45 testing::StrictMock<MockBlimpContentsObserver> observer2(&blimp_contents); | 55 testing::StrictMock<MockBlimpContentsObserver> observer2(&blimp_contents); |
| 46 | 56 |
| 47 EXPECT_CALL(observer1, OnNavigationStateChanged()); | 57 EXPECT_CALL(observer1, OnNavigationStateChanged()); |
| 48 EXPECT_CALL(observer2, OnNavigationStateChanged()).Times(2); | 58 EXPECT_CALL(observer2, OnNavigationStateChanged()).Times(2); |
| 49 | 59 |
| 50 navigation_controller.LoadURL(GURL(kExampleURL)); | 60 navigation_controller.LoadURL(GURL(kExampleURL)); |
| 51 loop.RunUntilIdle(); | 61 loop.RunUntilIdle(); |
| 52 | 62 |
| 53 EXPECT_EQ(kExampleURL, navigation_controller.GetURL().spec()); | 63 EXPECT_EQ(kExampleURL, navigation_controller.GetURL().spec()); |
| 54 | 64 |
| 55 // Observer should no longer receive callbacks. | 65 // Observer should no longer receive callbacks. |
| 56 blimp_contents.RemoveObserver(&observer1); | 66 blimp_contents.RemoveObserver(&observer1); |
| 57 | 67 |
| 58 navigation_controller.LoadURL(GURL(kOtherExampleURL)); | 68 navigation_controller.LoadURL(GURL(kOtherExampleURL)); |
| 59 loop.RunUntilIdle(); | 69 loop.RunUntilIdle(); |
| 60 | 70 |
| 61 EXPECT_EQ(kOtherExampleURL, navigation_controller.GetURL().spec()); | 71 EXPECT_EQ(kOtherExampleURL, navigation_controller.GetURL().spec()); |
| 62 } | 72 } |
| 63 | 73 |
| 74 TEST(BlimpContentsImplTest, SetSizeAndScaleThroughTabControlFeature) { |
| 75 int width = 10; |
| 76 int height = 15; |
| 77 float dp_to_px = 1.23f; |
| 78 |
| 79 MockTabControlFeature tab_control_feature; |
| 80 base::MessageLoop loop; |
| 81 BlimpContentsImpl blimp_contents(kDummyTabId, &tab_control_feature); |
| 82 |
| 83 EXPECT_CALL(tab_control_feature, |
| 84 SetSizeAndScale(gfx::Size(width, height), dp_to_px)).Times(1); |
| 85 |
| 86 blimp_contents.SetSizeAndScale(gfx::Size(width, height), dp_to_px); |
| 87 } |
| 88 |
| 64 } // namespace | 89 } // namespace |
| 65 } // namespace client | 90 } // namespace client |
| 66 } // namespace blimp | 91 } // namespace blimp |
| OLD | NEW |