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

Side by Side Diff: chrome/browser/ui/search/search_ipc_router_unittest.cc

Issue 342323008: Discard ChromeViewHostMsg_SearchBox* IPCs if they not sent from an Instant process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added tests Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/search/search_ipc_router_policy_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/ui/search/search_ipc_router.h" 5 #include "chrome/browser/ui/search/search_ipc_router.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 177
178 SearchIPCRouter& GetSearchIPCRouter() { 178 SearchIPCRouter& GetSearchIPCRouter() {
179 return GetSearchTabHelper(web_contents())->ipc_router(); 179 return GetSearchTabHelper(web_contents())->ipc_router();
180 } 180 }
181 181
182 int GetSearchIPCRouterSeqNo() { 182 int GetSearchIPCRouterSeqNo() {
183 return GetSearchIPCRouter().page_seq_no_for_testing(); 183 return GetSearchIPCRouter().page_seq_no_for_testing();
184 } 184 }
185 185
186 void OnMessageReceived(const IPC::Message& message) { 186 void OnMessageReceived(const IPC::Message& message) {
187 GetSearchIPCRouter().OnMessageReceived(message); 187 bool should_handle_message =
188 chrome::IsRenderedInInstantProcess(web_contents(), profile());
189 bool handled = GetSearchIPCRouter().OnMessageReceived(message);
190 EXPECT_EQ(should_handle_message, handled);
nasko 2014/06/20 21:27:42 nit: I'd make that an ASSERT, as it is never expec
kmadhusu 2014/06/20 21:33:54 Done.
188 } 191 }
189 192
190 bool IsActiveTab(content::WebContents* contents) { 193 bool IsActiveTab(content::WebContents* contents) {
191 return GetSearchTabHelper(contents)->ipc_router().is_active_tab_; 194 return GetSearchTabHelper(contents)->ipc_router().is_active_tab_;
192 } 195 }
193 196
194 private: 197 private:
195 MockSearchIPCRouterDelegate delegate_; 198 MockSearchIPCRouterDelegate delegate_;
196 base::FieldTrialList field_trial_list_; 199 base::FieldTrialList field_trial_list_;
197 }; 200 };
198 201
202 TEST_F(SearchIPCRouterTest, IgnoreMessagesFromNonInstantRenderers) {
203 NavigateAndCommitActiveTab(GURL("file://foo/bar"));
204 SetupMockDelegateAndPolicy();
205 GURL destination_url("www.foo.com");
206 EXPECT_CALL(*mock_delegate(), NavigateToURL(destination_url, CURRENT_TAB,
207 true)).Times(0);
208 content::WebContents* contents = web_contents();
209 bool is_active_tab = IsActiveTab(contents);
210 EXPECT_TRUE(is_active_tab);
211
212 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
213 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(0);
214
215 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_SearchBoxNavigate(
216 contents->GetRoutingID(),
217 GetSearchIPCRouterSeqNo(),
218 destination_url, CURRENT_TAB, true));
219 OnMessageReceived(*message);
nasko 2014/06/20 21:18:02 How does the test pass/fail here?
kmadhusu 2014/06/20 21:20:28 Test will pass. We expect SearchIPCRouter::OnMessa
nasko 2014/06/20 21:27:42 Ok, it passes due to the expectations of no calls
kmadhusu 2014/06/20 21:33:54 Ack.
220 }
221
199 TEST_F(SearchIPCRouterTest, ProcessVoiceSearchSupportMsg) { 222 TEST_F(SearchIPCRouterTest, ProcessVoiceSearchSupportMsg) {
200 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 223 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
201 SetupMockDelegateAndPolicy(); 224 SetupMockDelegateAndPolicy();
202 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 225 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
203 EXPECT_CALL(*mock_delegate(), OnSetVoiceSearchSupport(true)).Times(1); 226 EXPECT_CALL(*mock_delegate(), OnSetVoiceSearchSupport(true)).Times(1);
204 EXPECT_CALL(*(policy), ShouldProcessSetVoiceSearchSupport()).Times(1) 227 EXPECT_CALL(*(policy), ShouldProcessSetVoiceSearchSupport()).Times(1)
205 .WillOnce(testing::Return(true)); 228 .WillOnce(testing::Return(true));
206 229
207 content::WebContents* contents = web_contents(); 230 content::WebContents* contents = web_contents();
208 scoped_ptr<IPC::Message> message( 231 scoped_ptr<IPC::Message> message(
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 EXPECT_FALSE(IsActiveTab(contents)); 301 EXPECT_FALSE(IsActiveTab(contents));
279 302
280 // Activate the first tab. 303 // Activate the first tab.
281 browser()->tab_strip_model()->ActivateTabAt(1, false); 304 browser()->tab_strip_model()->ActivateTabAt(1, false);
282 EXPECT_EQ(browser()->tab_strip_model()->active_index(), 305 EXPECT_EQ(browser()->tab_strip_model()->active_index(),
283 browser()->tab_strip_model()->GetIndexOfWebContents(contents)); 306 browser()->tab_strip_model()->GetIndexOfWebContents(contents));
284 EXPECT_TRUE(IsActiveTab(contents)); 307 EXPECT_TRUE(IsActiveTab(contents));
285 } 308 }
286 309
287 TEST_F(SearchIPCRouterTest, ProcessNavigateToURLMsg) { 310 TEST_F(SearchIPCRouterTest, ProcessNavigateToURLMsg) {
288 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 311 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
289 SetupMockDelegateAndPolicy(); 312 SetupMockDelegateAndPolicy();
290 GURL destination_url("www.foo.com"); 313 GURL destination_url("www.foo.com");
291 EXPECT_CALL(*mock_delegate(), NavigateToURL(destination_url, CURRENT_TAB, 314 EXPECT_CALL(*mock_delegate(), NavigateToURL(destination_url, CURRENT_TAB,
292 true)).Times(1); 315 true)).Times(1);
293 content::WebContents* contents = web_contents(); 316 content::WebContents* contents = web_contents();
294 bool is_active_tab = IsActiveTab(contents); 317 bool is_active_tab = IsActiveTab(contents);
295 EXPECT_TRUE(is_active_tab); 318 EXPECT_TRUE(is_active_tab);
296 319
297 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 320 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
298 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(1) 321 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(1)
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 931 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
909 SetupMockDelegateAndPolicy(); 932 SetupMockDelegateAndPolicy();
910 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 933 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
911 EXPECT_CALL(*policy, ShouldSendToggleVoiceSearch()).Times(1) 934 EXPECT_CALL(*policy, ShouldSendToggleVoiceSearch()).Times(1)
912 .WillOnce(testing::Return(false)); 935 .WillOnce(testing::Return(false));
913 936
914 process()->sink().ClearMessages(); 937 process()->sink().ClearMessages();
915 GetSearchIPCRouter().ToggleVoiceSearch(); 938 GetSearchIPCRouter().ToggleVoiceSearch();
916 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxToggleVoiceSearch::ID)); 939 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxToggleVoiceSearch::ID));
917 } 940 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/search_ipc_router_policy_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698