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 "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
7 #include "blimp/client/core/contents/blimp_navigation_controller_delegate.h" | 7 #include "blimp/client/core/contents/blimp_navigation_controller_delegate.h" |
8 #include "blimp/client/core/contents/blimp_navigation_controller_impl.h" | 8 #include "blimp/client/core/contents/blimp_navigation_controller_impl.h" |
9 #include "blimp/client/core/contents/fake_navigation_feature.h" | 9 #include "blimp/client/core/contents/fake_navigation_feature.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 using testing::_; | 13 using testing::_; |
14 | 14 |
15 namespace blimp { | 15 namespace blimp { |
16 namespace client { | 16 namespace client { |
17 namespace { | 17 namespace { |
18 | 18 |
| 19 const int kDummyBlimpContentsId = 0; |
19 const GURL kExampleURL = GURL("https://www.example.com/"); | 20 const GURL kExampleURL = GURL("https://www.example.com/"); |
20 | 21 |
21 class MockBlimpNavigationControllerDelegate | 22 class MockBlimpNavigationControllerDelegate |
22 : public BlimpNavigationControllerDelegate { | 23 : public BlimpNavigationControllerDelegate { |
23 public: | 24 public: |
24 MockBlimpNavigationControllerDelegate() = default; | 25 MockBlimpNavigationControllerDelegate() = default; |
25 ~MockBlimpNavigationControllerDelegate() override = default; | 26 ~MockBlimpNavigationControllerDelegate() override = default; |
26 | 27 |
27 MOCK_METHOD0(OnNavigationStateChanged, void()); | 28 MOCK_METHOD0(OnNavigationStateChanged, void()); |
28 MOCK_METHOD1(OnLoadingStateChanged, void(bool loading)); | 29 MOCK_METHOD1(OnLoadingStateChanged, void(bool loading)); |
29 | 30 |
30 private: | 31 private: |
31 DISALLOW_COPY_AND_ASSIGN(MockBlimpNavigationControllerDelegate); | 32 DISALLOW_COPY_AND_ASSIGN(MockBlimpNavigationControllerDelegate); |
32 }; | 33 }; |
33 | 34 |
34 TEST(BlimpNavigationControllerImplTest, BackForwardNavigation) { | 35 TEST(BlimpNavigationControllerImplTest, BackForwardNavigation) { |
35 base::MessageLoop loop; | 36 base::MessageLoop loop; |
36 | 37 |
37 testing::StrictMock<MockBlimpNavigationControllerDelegate> delegate; | 38 testing::StrictMock<MockBlimpNavigationControllerDelegate> delegate; |
38 testing::StrictMock<FakeNavigationFeature> feature; | 39 testing::StrictMock<FakeNavigationFeature> feature; |
39 BlimpNavigationControllerImpl navigation_controller(&delegate, &feature); | 40 BlimpNavigationControllerImpl navigation_controller(kDummyBlimpContentsId, |
| 41 &delegate, &feature); |
40 feature.SetDelegate(1, &navigation_controller); | 42 feature.SetDelegate(1, &navigation_controller); |
41 | 43 |
42 EXPECT_CALL(delegate, OnNavigationStateChanged()); | 44 EXPECT_CALL(delegate, OnNavigationStateChanged()); |
43 | 45 |
44 navigation_controller.LoadURL(kExampleURL); | 46 navigation_controller.LoadURL(kExampleURL); |
45 base::RunLoop().RunUntilIdle(); | 47 base::RunLoop().RunUntilIdle(); |
46 EXPECT_EQ(kExampleURL, navigation_controller.GetURL()); | 48 EXPECT_EQ(kExampleURL, navigation_controller.GetURL()); |
47 | 49 |
48 EXPECT_CALL(feature, GoBack(_)); | 50 EXPECT_CALL(feature, GoBack(_)); |
49 EXPECT_CALL(feature, GoForward(_)); | 51 EXPECT_CALL(feature, GoForward(_)); |
50 EXPECT_CALL(feature, Reload(_)); | 52 EXPECT_CALL(feature, Reload(_)); |
51 | 53 |
52 navigation_controller.GoBack(); | 54 navigation_controller.GoBack(); |
53 navigation_controller.GoForward(); | 55 navigation_controller.GoForward(); |
54 navigation_controller.Reload(); | 56 navigation_controller.Reload(); |
55 | 57 |
56 base::RunLoop().RunUntilIdle(); | 58 base::RunLoop().RunUntilIdle(); |
57 } | 59 } |
58 | 60 |
59 TEST(BlimpNavigationControllerImplTest, Loading) { | 61 TEST(BlimpNavigationControllerImplTest, Loading) { |
60 testing::InSequence s; | 62 testing::InSequence s; |
61 base::MessageLoop loop; | 63 base::MessageLoop loop; |
62 | 64 |
63 testing::StrictMock<MockBlimpNavigationControllerDelegate> delegate; | 65 testing::StrictMock<MockBlimpNavigationControllerDelegate> delegate; |
64 testing::StrictMock<FakeNavigationFeature> feature; | 66 testing::StrictMock<FakeNavigationFeature> feature; |
65 BlimpNavigationControllerImpl navigation_controller(&delegate, &feature); | 67 BlimpNavigationControllerImpl navigation_controller(kDummyBlimpContentsId, |
| 68 &delegate, &feature); |
66 feature.SetDelegate(1, &navigation_controller); | 69 feature.SetDelegate(1, &navigation_controller); |
67 | 70 |
68 EXPECT_CALL(delegate, OnNavigationStateChanged()); | 71 EXPECT_CALL(delegate, OnNavigationStateChanged()); |
69 EXPECT_CALL(delegate, OnLoadingStateChanged(true)); | 72 EXPECT_CALL(delegate, OnLoadingStateChanged(true)); |
70 EXPECT_CALL(delegate, OnNavigationStateChanged()); | 73 EXPECT_CALL(delegate, OnNavigationStateChanged()); |
71 EXPECT_CALL(delegate, OnLoadingStateChanged(false)); | 74 EXPECT_CALL(delegate, OnLoadingStateChanged(false)); |
72 | 75 |
73 NavigationFeature::NavigationFeatureDelegate* feature_delegate = | 76 NavigationFeature::NavigationFeatureDelegate* feature_delegate = |
74 static_cast<NavigationFeature::NavigationFeatureDelegate*>( | 77 static_cast<NavigationFeature::NavigationFeatureDelegate*>( |
75 &navigation_controller); | 78 &navigation_controller); |
76 | 79 |
77 feature_delegate->OnLoadingChanged(1, true); | 80 feature_delegate->OnLoadingChanged(1, true); |
78 feature_delegate->OnLoadingChanged(1, false); | 81 feature_delegate->OnLoadingChanged(1, false); |
79 } | 82 } |
80 | 83 |
81 } // namespace | 84 } // namespace |
82 } // namespace client | 85 } // namespace client |
83 } // namespace blimp | 86 } // namespace blimp |
OLD | NEW |