Chromium Code Reviews| 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/fake_navigation_feature.h> | |
| 5 #include "blimp/client/core/contents/blimp_contents_impl.h" | 6 #include "blimp/client/core/contents/blimp_contents_impl.h" |
| 6 | 7 |
| 7 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 8 #include "blimp/client/core/contents/blimp_contents_impl.h" | 9 #include "blimp/client/core/contents/blimp_contents_impl.h" |
| 9 #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" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 13 |
| 12 namespace blimp { | 14 namespace blimp { |
| 13 namespace client { | 15 namespace client { |
| 14 namespace { | 16 namespace { |
| 15 | 17 |
| 16 const GURL kExampleURL = GURL("https://www.example.com/"); | 18 const GURL kExampleURL = GURL("https://www.example.com/"); |
| 17 const GURL kOtherExampleURL = GURL("https://www.otherexample.com/"); | 19 const GURL kOtherExampleURL = GURL("https://www.otherexample.com/"); |
| 18 | 20 |
| 19 class TestBlimpContentsObserver : public BlimpContentsObserver { | 21 class MockBlimpContentsObserver : public BlimpContentsObserver { |
| 20 public: | 22 public: |
| 21 TestBlimpContentsObserver() = default; | 23 MockBlimpContentsObserver() = default; |
| 22 ~TestBlimpContentsObserver() override = default; | 24 ~MockBlimpContentsObserver() override = default; |
| 23 | 25 |
| 24 void OnURLUpdated(const GURL& url) override { last_url_ = url; } | 26 MOCK_METHOD0(OnNavigationStateChanged, void()); |
| 25 | |
| 26 GURL GetLastURL() { return last_url_; } | |
| 27 | 27 |
| 28 private: | 28 private: |
| 29 GURL last_url_; | 29 DISALLOW_COPY_AND_ASSIGN(MockBlimpContentsObserver); |
| 30 | |
| 31 DISALLOW_COPY_AND_ASSIGN(TestBlimpContentsObserver); | |
| 32 }; | 30 }; |
| 33 | 31 |
| 34 TEST(BlimpContentsImplTest, Basic) { | 32 TEST(BlimpContentsImplTest, Basic) { |
| 35 base::MessageLoop loop; | 33 base::MessageLoop loop; |
| 36 BlimpContentsImpl blimp_contents; | 34 BlimpContentsImpl blimp_contents; |
| 35 FakeNavigationFeature feature; | |
| 37 | 36 |
| 38 BlimpNavigationController& navigation_controller = | 37 BlimpNavigationControllerImpl& navigation_controller = |
| 39 blimp_contents.GetNavigationController(); | 38 blimp_contents.GetNavigationController(); |
| 40 | 39 |
| 41 TestBlimpContentsObserver observer1; | 40 MockBlimpContentsObserver observer1; |
| 42 blimp_contents.AddObserver(&observer1); | 41 blimp_contents.AddObserver(&observer1); |
| 43 TestBlimpContentsObserver observer2; | 42 MockBlimpContentsObserver observer2; |
| 44 blimp_contents.AddObserver(&observer2); | 43 blimp_contents.AddObserver(&observer2); |
| 45 | 44 |
| 45 feature.SetDelegate(1, &navigation_controller); | |
|
Kevin M
2016/07/29 21:05:32
Can you move these right after "navigation_control
| |
| 46 navigation_controller.SetNavigationFeatureForTesting(&feature); | |
| 47 | |
| 48 EXPECT_CALL(observer1, OnNavigationStateChanged()).Times(1); | |
| 49 EXPECT_CALL(observer2, OnNavigationStateChanged()).Times(2); | |
| 50 | |
| 46 navigation_controller.LoadURL(kExampleURL); | 51 navigation_controller.LoadURL(kExampleURL); |
| 47 loop.RunUntilIdle(); | 52 loop.RunUntilIdle(); |
| 48 | 53 |
| 49 EXPECT_EQ(kExampleURL, navigation_controller.GetURL()); | 54 EXPECT_EQ(kExampleURL, navigation_controller.GetURL()); |
| 50 EXPECT_EQ(kExampleURL, observer1.GetLastURL()); | |
| 51 EXPECT_EQ(kExampleURL, observer2.GetLastURL()); | |
| 52 | 55 |
| 53 // Observer should no longer receive callbacks. | 56 // Observer should no longer receive callbacks. |
| 54 blimp_contents.RemoveObserver(&observer1); | 57 blimp_contents.RemoveObserver(&observer1); |
| 55 | 58 |
| 56 navigation_controller.LoadURL(kOtherExampleURL); | 59 navigation_controller.LoadURL(kOtherExampleURL); |
| 57 loop.RunUntilIdle(); | 60 loop.RunUntilIdle(); |
| 58 | 61 |
| 59 EXPECT_EQ(kOtherExampleURL, navigation_controller.GetURL()); | 62 EXPECT_EQ(kOtherExampleURL, navigation_controller.GetURL()); |
| 60 EXPECT_EQ(kExampleURL, observer1.GetLastURL()); | |
| 61 EXPECT_EQ(kOtherExampleURL, observer2.GetLastURL()); | |
| 62 } | 63 } |
| 63 | 64 |
| 64 } // namespace | 65 } // namespace |
| 65 } // namespace client | 66 } // namespace client |
| 66 } // namespace blimp | 67 } // namespace blimp |
| OLD | NEW |