Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1327)

Side by Side Diff: blimp/client/feature/navigation_feature_unittest.cc

Issue 2058263002: Tied up BlimpNavigationController to NavigationFeature (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blimp_core
Patch Set: Removed BlimpContentsTest.java Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "blimp/client/feature/navigation_feature.h"
6
7 #include <memory>
8
9 #include "base/logging.h"
10 #include "base/memory/ptr_util.h"
11 #include "blimp/client/feature/mock_navigation_feature_delegate.h"
12 #include "blimp/common/create_blimp_message.h"
13 #include "blimp/common/proto/blimp_message.pb.h"
14 #include "blimp/net/test_common.h"
15 #include "net/base/net_errors.h"
16 #include "net/base/test_completion_callback.h"
17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "third_party/skia/include/core/SkBitmap.h"
20 #include "url/gurl.h"
21
22 using testing::_;
23
24 namespace blimp {
25 namespace client {
26
27 void SendMockNavigationStateChangedMessage(BlimpMessageProcessor* processor,
28 int tab_id,
29 const GURL* url,
30 const std::string* title,
31 const bool* loading) {
32 NavigationMessage* navigation_message;
33 std::unique_ptr<BlimpMessage> message =
34 CreateBlimpMessage(&navigation_message, tab_id);
35 navigation_message->set_type(NavigationMessage::NAVIGATION_STATE_CHANGED);
36 NavigationStateChangeMessage* state =
37 navigation_message->mutable_navigation_state_changed();
38 if (url)
39 state->set_url(url->spec());
40
41 if (title)
42 state->set_title(*title);
43
44 if (loading)
45 state->set_loading(*loading);
46
47 net::TestCompletionCallback cb;
48 processor->ProcessMessage(std::move(message), cb.callback());
49 EXPECT_EQ(net::OK, cb.WaitForResult());
50 }
51
52 MATCHER_P2(EqualsNavigateToUrlText, tab_id, text, "") {
53 return arg.target_tab_id() == tab_id &&
54 arg.navigation().type() == NavigationMessage::LOAD_URL &&
55 arg.navigation().load_url().url() == text;
56 }
57
58 MATCHER_P(EqualsNavigateForward, tab_id, "") {
59 return arg.target_tab_id() == tab_id &&
60 arg.navigation().type() == NavigationMessage::GO_FORWARD;
61 }
62
63 MATCHER_P(EqualsNavigateBack, tab_id, "") {
64 return arg.target_tab_id() == tab_id &&
65 arg.navigation().type() == NavigationMessage::GO_BACK;
66 }
67
68 MATCHER_P(EqualsNavigateReload, tab_id, "") {
69 return arg.target_tab_id() == tab_id &&
70 arg.navigation().type() == NavigationMessage::RELOAD;
71 }
72
73 class NavigationFeatureTest : public testing::Test {
74 public:
75 NavigationFeatureTest() : out_processor_(nullptr) {}
76
77 void SetUp() override {
78 out_processor_ = new MockBlimpMessageProcessor();
79 feature_.set_outgoing_message_processor(base::WrapUnique(out_processor_));
80
81 feature_.SetDelegate(1, &delegate1_);
82 feature_.SetDelegate(2, &delegate2_);
83 }
84
85 protected:
86 // This is a raw pointer to a class that is owned by the NavigationFeature.
87 MockBlimpMessageProcessor* out_processor_;
88
89 MockNavigationFeatureDelegate delegate1_;
90 MockNavigationFeatureDelegate delegate2_;
91
92 NavigationFeature feature_;
93 };
94
95 TEST_F(NavigationFeatureTest, DispatchesToCorrectDelegate) {
96 GURL url("https://www.google.com");
97 EXPECT_CALL(delegate1_, OnUrlChanged(1, url)).Times(1);
98 SendMockNavigationStateChangedMessage(&feature_, 1, &url, nullptr, nullptr);
99
100 EXPECT_CALL(delegate2_, OnUrlChanged(2, url)).Times(1);
101 SendMockNavigationStateChangedMessage(&feature_, 2, &url, nullptr, nullptr);
102 }
103
104 TEST_F(NavigationFeatureTest, AllDelegateFieldsCalled) {
105 GURL url("https://www.google.com");
106 std::string title = "Google";
107 bool loading = true;
108
109 EXPECT_CALL(delegate1_, OnUrlChanged(1, url)).Times(1);
110 EXPECT_CALL(delegate1_, OnTitleChanged(1, title)).Times(1);
111 EXPECT_CALL(delegate1_, OnLoadingChanged(1, loading)).Times(1);
112 SendMockNavigationStateChangedMessage(&feature_, 1, &url, &title, &loading);
113 }
114
115 TEST_F(NavigationFeatureTest, PartialDelegateFieldsCalled) {
116 std::string title = "Google";
117 bool loading = true;
118
119 EXPECT_CALL(delegate1_, OnUrlChanged(_, _)).Times(0);
120 EXPECT_CALL(delegate1_, OnTitleChanged(1, title)).Times(1);
121 EXPECT_CALL(delegate1_, OnLoadingChanged(1, loading)).Times(1);
122 SendMockNavigationStateChangedMessage(&feature_, 1, nullptr, &title,
123 &loading);
124 }
125
126 TEST_F(NavigationFeatureTest, TestNavigateToUrlMessage) {
127 std::string text = "http://google.com/";
128
129 EXPECT_CALL(*out_processor_,
130 MockableProcessMessage(EqualsNavigateToUrlText(1, text), _))
131 .Times(1);
132 feature_.NavigateToUrlText(1, text);
133 }
134
135 TEST_F(NavigationFeatureTest, TestNavigateForwardMessage) {
136 EXPECT_CALL(*out_processor_,
137 MockableProcessMessage(EqualsNavigateForward(1), _))
138 .Times(1);
139 feature_.GoForward(1);
140 }
141
142 TEST_F(NavigationFeatureTest, TestNavigateBackMessage) {
143 EXPECT_CALL(*out_processor_, MockableProcessMessage(EqualsNavigateBack(1), _))
144 .Times(1);
145 feature_.GoBack(1);
146 }
147
148 TEST_F(NavigationFeatureTest, TestNavigateReloadMessage) {
149 EXPECT_CALL(*out_processor_,
150 MockableProcessMessage(EqualsNavigateReload(1), _))
151 .Times(1);
152 feature_.Reload(1);
153 }
154
155 } // namespace client
156 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698