Chromium Code Reviews| Index: blimp/client/core/contents/blimp_contents_impl_unittest.cc |
| diff --git a/blimp/client/core/contents/blimp_contents_impl_unittest.cc b/blimp/client/core/contents/blimp_contents_impl_unittest.cc |
| index 03132529690813afa33bd0e4797b8de48480e449..1761de37af3627ce542ec637d1c6bd2e258b5a60 100644 |
| --- a/blimp/client/core/contents/blimp_contents_impl_unittest.cc |
| +++ b/blimp/client/core/contents/blimp_contents_impl_unittest.cc |
| @@ -2,11 +2,13 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include <blimp/client/core/contents/fake_navigation_feature.h> |
| #include "blimp/client/core/contents/blimp_contents_impl.h" |
| #include "base/message_loop/message_loop.h" |
| #include "blimp/client/core/contents/blimp_contents_impl.h" |
| #include "blimp/client/public/contents/blimp_contents_observer.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| namespace blimp { |
| @@ -16,39 +18,40 @@ namespace { |
| const GURL kExampleURL = GURL("https://www.example.com/"); |
| const GURL kOtherExampleURL = GURL("https://www.otherexample.com/"); |
| -class TestBlimpContentsObserver : public BlimpContentsObserver { |
| +class MockBlimpContentsObserver : public BlimpContentsObserver { |
| public: |
| - TestBlimpContentsObserver() = default; |
| - ~TestBlimpContentsObserver() override = default; |
| + MockBlimpContentsObserver() = default; |
| + ~MockBlimpContentsObserver() override = default; |
| - void OnURLUpdated(const GURL& url) override { last_url_ = url; } |
| - |
| - GURL GetLastURL() { return last_url_; } |
| + MOCK_METHOD0(OnNavigationStateChanged, void()); |
| private: |
| - GURL last_url_; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(TestBlimpContentsObserver); |
| + DISALLOW_COPY_AND_ASSIGN(MockBlimpContentsObserver); |
| }; |
| TEST(BlimpContentsImplTest, Basic) { |
| base::MessageLoop loop; |
| BlimpContentsImpl blimp_contents; |
| + FakeNavigationFeature feature; |
| - BlimpNavigationController& navigation_controller = |
| + BlimpNavigationControllerImpl& navigation_controller = |
| blimp_contents.GetNavigationController(); |
| - TestBlimpContentsObserver observer1; |
| + MockBlimpContentsObserver observer1; |
| blimp_contents.AddObserver(&observer1); |
| - TestBlimpContentsObserver observer2; |
| + MockBlimpContentsObserver observer2; |
| blimp_contents.AddObserver(&observer2); |
| + feature.SetDelegate(1, &navigation_controller); |
|
Kevin M
2016/07/29 21:05:32
Can you move these right after "navigation_control
|
| + navigation_controller.SetNavigationFeatureForTesting(&feature); |
| + |
| + EXPECT_CALL(observer1, OnNavigationStateChanged()).Times(1); |
| + EXPECT_CALL(observer2, OnNavigationStateChanged()).Times(2); |
| + |
| navigation_controller.LoadURL(kExampleURL); |
| loop.RunUntilIdle(); |
| EXPECT_EQ(kExampleURL, navigation_controller.GetURL()); |
| - EXPECT_EQ(kExampleURL, observer1.GetLastURL()); |
| - EXPECT_EQ(kExampleURL, observer2.GetLastURL()); |
| // Observer should no longer receive callbacks. |
| blimp_contents.RemoveObserver(&observer1); |
| @@ -57,8 +60,6 @@ TEST(BlimpContentsImplTest, Basic) { |
| loop.RunUntilIdle(); |
| EXPECT_EQ(kOtherExampleURL, navigation_controller.GetURL()); |
| - EXPECT_EQ(kExampleURL, observer1.GetLastURL()); |
| - EXPECT_EQ(kOtherExampleURL, observer2.GetLastURL()); |
| } |
| } // namespace |