OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/feature/navigation_feature.h" | 5 #include "blimp/client/feature/navigation_feature.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/message_loop/message_loop.h" |
11 #include "blimp/client/feature/mock_navigation_feature_delegate.h" | 12 #include "blimp/client/feature/mock_navigation_feature_delegate.h" |
12 #include "blimp/common/create_blimp_message.h" | 13 #include "blimp/common/create_blimp_message.h" |
13 #include "blimp/common/proto/blimp_message.pb.h" | 14 #include "blimp/common/proto/blimp_message.pb.h" |
| 15 #include "blimp/net/blimp_connection_details.h" |
14 #include "blimp/net/test_common.h" | 16 #include "blimp/net/test_common.h" |
15 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
16 #include "net/base/test_completion_callback.h" | 18 #include "net/base/test_completion_callback.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "third_party/skia/include/core/SkBitmap.h" | 21 #include "third_party/skia/include/core/SkBitmap.h" |
20 #include "url/gurl.h" | 22 #include "url/gurl.h" |
21 | 23 |
22 using testing::_; | 24 using testing::_; |
23 | 25 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 MATCHER_P(EqualsNavigateBack, tab_id, "") { | 65 MATCHER_P(EqualsNavigateBack, tab_id, "") { |
64 return arg.target_tab_id() == tab_id && | 66 return arg.target_tab_id() == tab_id && |
65 arg.navigation().type() == NavigationMessage::GO_BACK; | 67 arg.navigation().type() == NavigationMessage::GO_BACK; |
66 } | 68 } |
67 | 69 |
68 MATCHER_P(EqualsNavigateReload, tab_id, "") { | 70 MATCHER_P(EqualsNavigateReload, tab_id, "") { |
69 return arg.target_tab_id() == tab_id && | 71 return arg.target_tab_id() == tab_id && |
70 arg.navigation().type() == NavigationMessage::RELOAD; | 72 arg.navigation().type() == NavigationMessage::RELOAD; |
71 } | 73 } |
72 | 74 |
| 75 class MockNetworkActivityObserver : public NetworkActivityObserver { |
| 76 public: |
| 77 MockNetworkActivityObserver() : weak_factory_(this) {} |
| 78 |
| 79 void UpdateDebugInfo(int received, int sent, int commits) override {} |
| 80 |
| 81 base::WeakPtr<MockNetworkActivityObserver> GetWeakPtr() { |
| 82 return weak_factory_.GetWeakPtr(); |
| 83 } |
| 84 |
| 85 private: |
| 86 base::WeakPtrFactory<MockNetworkActivityObserver> weak_factory_; |
| 87 }; |
| 88 |
73 class NavigationFeatureTest : public testing::Test { | 89 class NavigationFeatureTest : public testing::Test { |
74 public: | 90 public: |
75 NavigationFeatureTest() : out_processor_(nullptr) {} | 91 NavigationFeatureTest() |
| 92 : out_processor_(nullptr), |
| 93 feature_(new BlimpConnectionDetails( |
| 94 MockNetworkActivityObserver().GetWeakPtr(), |
| 95 message_loop_.task_runner(), |
| 96 message_loop_.task_runner())) {} |
76 | 97 |
77 void SetUp() override { | 98 void SetUp() override { |
78 out_processor_ = new MockBlimpMessageProcessor(); | 99 out_processor_ = new MockBlimpMessageProcessor(); |
79 feature_.set_outgoing_message_processor(base::WrapUnique(out_processor_)); | 100 feature_.set_outgoing_message_processor(base::WrapUnique(out_processor_)); |
80 | 101 |
81 feature_.SetDelegate(1, &delegate1_); | 102 feature_.SetDelegate(1, &delegate1_); |
82 feature_.SetDelegate(2, &delegate2_); | 103 feature_.SetDelegate(2, &delegate2_); |
83 } | 104 } |
84 | 105 |
85 protected: | 106 protected: |
86 // This is a raw pointer to a class that is owned by the NavigationFeature. | 107 // This is a raw pointer to a class that is owned by the NavigationFeature. |
87 MockBlimpMessageProcessor* out_processor_; | 108 MockBlimpMessageProcessor* out_processor_; |
88 | 109 |
89 MockNavigationFeatureDelegate delegate1_; | 110 MockNavigationFeatureDelegate delegate1_; |
90 MockNavigationFeatureDelegate delegate2_; | 111 MockNavigationFeatureDelegate delegate2_; |
91 | 112 |
| 113 base::MessageLoop message_loop_; |
| 114 |
92 NavigationFeature feature_; | 115 NavigationFeature feature_; |
93 }; | 116 }; |
94 | 117 |
95 TEST_F(NavigationFeatureTest, DispatchesToCorrectDelegate) { | 118 TEST_F(NavigationFeatureTest, DispatchesToCorrectDelegate) { |
96 GURL url("https://www.google.com"); | 119 GURL url("https://www.google.com"); |
97 EXPECT_CALL(delegate1_, OnUrlChanged(1, url)).Times(1); | 120 EXPECT_CALL(delegate1_, OnUrlChanged(1, url)).Times(1); |
98 SendMockNavigationStateChangedMessage(&feature_, 1, &url, nullptr, nullptr); | 121 SendMockNavigationStateChangedMessage(&feature_, 1, &url, nullptr, nullptr); |
99 | 122 |
100 EXPECT_CALL(delegate2_, OnUrlChanged(2, url)).Times(1); | 123 EXPECT_CALL(delegate2_, OnUrlChanged(2, url)).Times(1); |
101 SendMockNavigationStateChangedMessage(&feature_, 2, &url, nullptr, nullptr); | 124 SendMockNavigationStateChangedMessage(&feature_, 2, &url, nullptr, nullptr); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 | 170 |
148 TEST_F(NavigationFeatureTest, TestNavigateReloadMessage) { | 171 TEST_F(NavigationFeatureTest, TestNavigateReloadMessage) { |
149 EXPECT_CALL(*out_processor_, | 172 EXPECT_CALL(*out_processor_, |
150 MockableProcessMessage(EqualsNavigateReload(1), _)) | 173 MockableProcessMessage(EqualsNavigateReload(1), _)) |
151 .Times(1); | 174 .Times(1); |
152 feature_.Reload(1); | 175 feature_.Reload(1); |
153 } | 176 } |
154 | 177 |
155 } // namespace client | 178 } // namespace client |
156 } // namespace blimp | 179 } // namespace blimp |
OLD | NEW |