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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 |
73 class NavigationFeatureTest : public testing::Test { | 75 class NavigationFeatureTest : public testing::Test { |
74 public: | 76 public: |
75 NavigationFeatureTest() : out_processor_(nullptr) {} | 77 NavigationFeatureTest() |
Khushal
2016/05/18 00:23:00
Would be nice to have a test to make sure the expe
| |
78 : out_processor_(nullptr), | |
79 feature_(new BlimpConnectionDetails(message_loop_.task_runner(), | |
80 message_loop_.task_runner())) {} | |
76 | 81 |
77 void SetUp() override { | 82 void SetUp() override { |
78 out_processor_ = new MockBlimpMessageProcessor(); | 83 out_processor_ = new MockBlimpMessageProcessor(); |
79 feature_.set_outgoing_message_processor(base::WrapUnique(out_processor_)); | 84 feature_.set_outgoing_message_processor(base::WrapUnique(out_processor_)); |
80 | 85 |
81 feature_.SetDelegate(1, &delegate1_); | 86 feature_.SetDelegate(1, &delegate1_); |
82 feature_.SetDelegate(2, &delegate2_); | 87 feature_.SetDelegate(2, &delegate2_); |
83 } | 88 } |
84 | 89 |
85 protected: | 90 protected: |
86 // This is a raw pointer to a class that is owned by the NavigationFeature. | 91 // This is a raw pointer to a class that is owned by the NavigationFeature. |
87 MockBlimpMessageProcessor* out_processor_; | 92 MockBlimpMessageProcessor* out_processor_; |
88 | 93 |
89 MockNavigationFeatureDelegate delegate1_; | 94 MockNavigationFeatureDelegate delegate1_; |
90 MockNavigationFeatureDelegate delegate2_; | 95 MockNavigationFeatureDelegate delegate2_; |
91 | 96 |
97 base::MessageLoop message_loop_; | |
98 | |
92 NavigationFeature feature_; | 99 NavigationFeature feature_; |
93 }; | 100 }; |
94 | 101 |
95 TEST_F(NavigationFeatureTest, DispatchesToCorrectDelegate) { | 102 TEST_F(NavigationFeatureTest, DispatchesToCorrectDelegate) { |
96 GURL url("https://www.google.com"); | 103 GURL url("https://www.google.com"); |
97 EXPECT_CALL(delegate1_, OnUrlChanged(1, url)).Times(1); | 104 EXPECT_CALL(delegate1_, OnUrlChanged(1, url)).Times(1); |
98 SendMockNavigationStateChangedMessage(&feature_, 1, &url, nullptr, nullptr); | 105 SendMockNavigationStateChangedMessage(&feature_, 1, &url, nullptr, nullptr); |
99 | 106 |
100 EXPECT_CALL(delegate2_, OnUrlChanged(2, url)).Times(1); | 107 EXPECT_CALL(delegate2_, OnUrlChanged(2, url)).Times(1); |
101 SendMockNavigationStateChangedMessage(&feature_, 2, &url, nullptr, nullptr); | 108 SendMockNavigationStateChangedMessage(&feature_, 2, &url, nullptr, nullptr); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 | 154 |
148 TEST_F(NavigationFeatureTest, TestNavigateReloadMessage) { | 155 TEST_F(NavigationFeatureTest, TestNavigateReloadMessage) { |
149 EXPECT_CALL(*out_processor_, | 156 EXPECT_CALL(*out_processor_, |
150 MockableProcessMessage(EqualsNavigateReload(1), _)) | 157 MockableProcessMessage(EqualsNavigateReload(1), _)) |
151 .Times(1); | 158 .Times(1); |
152 feature_.Reload(1); | 159 feature_.Reload(1); |
153 } | 160 } |
154 | 161 |
155 } // namespace client | 162 } // namespace client |
156 } // namespace blimp | 163 } // namespace blimp |
OLD | NEW |