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

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

Issue 292123015: Remove WebContents::IsActiveEntry from Instant Extended and from WebContents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: style 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
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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 content::WebContents* web_contents) { 131 content::WebContents* web_contents) {
132 EXPECT_NE(static_cast<content::WebContents*>(NULL), web_contents); 132 EXPECT_NE(static_cast<content::WebContents*>(NULL), web_contents);
133 return SearchTabHelper::FromWebContents(web_contents); 133 return SearchTabHelper::FromWebContents(web_contents);
134 } 134 }
135 135
136 void SetupMockDelegateAndPolicy() { 136 void SetupMockDelegateAndPolicy() {
137 content::WebContents* contents = web_contents(); 137 content::WebContents* contents = web_contents();
138 ASSERT_NE(static_cast<content::WebContents*>(NULL), contents); 138 ASSERT_NE(static_cast<content::WebContents*>(NULL), contents);
139 SearchTabHelper* search_tab_helper = GetSearchTabHelper(contents); 139 SearchTabHelper* search_tab_helper = GetSearchTabHelper(contents);
140 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); 140 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper);
141 search_tab_helper->ipc_router().set_delegate(mock_delegate()); 141 search_tab_helper->ipc_router().set_delegate_for_testing(mock_delegate());
142 search_tab_helper->ipc_router().set_policy( 142 search_tab_helper->ipc_router().set_policy_for_testing(
143 make_scoped_ptr(new MockSearchIPCRouterPolicy) 143 make_scoped_ptr(new MockSearchIPCRouterPolicy)
144 .PassAs<SearchIPCRouter::Policy>()); 144 .PassAs<SearchIPCRouter::Policy>());
145 } 145 }
146 146
147 bool MessageWasSent(uint32 id) { 147 bool MessageWasSent(uint32 id) {
148 return process()->sink().GetFirstMessageMatching(id) != NULL; 148 return process()->sink().GetFirstMessageMatching(id) != NULL;
149 } 149 }
150 150
151 void VerifyDisplayInstantResultsMsg(bool expected_param_value) { 151 void VerifyDisplayInstantResultsMsg(bool expected_param_value) {
152 SetupMockDelegateAndPolicy(); 152 SetupMockDelegateAndPolicy();
(...skipping 12 matching lines...) Expand all
165 } 165 }
166 166
167 MockSearchIPCRouterDelegate* mock_delegate() { return &delegate_; } 167 MockSearchIPCRouterDelegate* mock_delegate() { return &delegate_; }
168 168
169 MockSearchIPCRouterPolicy* GetSearchIPCRouterPolicy() { 169 MockSearchIPCRouterPolicy* GetSearchIPCRouterPolicy() {
170 content::WebContents* contents = web_contents(); 170 content::WebContents* contents = web_contents();
171 EXPECT_NE(static_cast<content::WebContents*>(NULL), contents); 171 EXPECT_NE(static_cast<content::WebContents*>(NULL), contents);
172 SearchTabHelper* search_tab_helper = GetSearchTabHelper(contents); 172 SearchTabHelper* search_tab_helper = GetSearchTabHelper(contents);
173 EXPECT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); 173 EXPECT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper);
174 return static_cast<MockSearchIPCRouterPolicy*>( 174 return static_cast<MockSearchIPCRouterPolicy*>(
175 search_tab_helper->ipc_router().policy()); 175 search_tab_helper->ipc_router().policy_for_testing());
176 } 176 }
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() {
183 return GetSearchIPCRouter().page_seq_no_for_testing();
184 }
185
182 void OnMessageReceived(const IPC::Message& message) { 186 void OnMessageReceived(const IPC::Message& message) {
183 GetSearchIPCRouter().OnMessageReceived(message); 187 GetSearchIPCRouter().OnMessageReceived(message);
184 } 188 }
185 189
186 bool IsActiveTab(content::WebContents* contents) { 190 bool IsActiveTab(content::WebContents* contents) {
187 return GetSearchTabHelper(contents)->ipc_router().is_active_tab_; 191 return GetSearchTabHelper(contents)->ipc_router().is_active_tab_;
188 } 192 }
189 193
190 private: 194 private:
191 MockSearchIPCRouterDelegate delegate_; 195 MockSearchIPCRouterDelegate delegate_;
192 base::FieldTrialList field_trial_list_; 196 base::FieldTrialList field_trial_list_;
193 }; 197 };
194 198
195 TEST_F(SearchIPCRouterTest, ProcessVoiceSearchSupportMsg) { 199 TEST_F(SearchIPCRouterTest, ProcessVoiceSearchSupportMsg) {
196 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 200 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
197 SetupMockDelegateAndPolicy(); 201 SetupMockDelegateAndPolicy();
198 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 202 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
199 EXPECT_CALL(*mock_delegate(), OnSetVoiceSearchSupport(true)).Times(1); 203 EXPECT_CALL(*mock_delegate(), OnSetVoiceSearchSupport(true)).Times(1);
200 EXPECT_CALL(*(policy), ShouldProcessSetVoiceSearchSupport()).Times(1) 204 EXPECT_CALL(*(policy), ShouldProcessSetVoiceSearchSupport()).Times(1)
201 .WillOnce(testing::Return(true)); 205 .WillOnce(testing::Return(true));
202 206
203 content::WebContents* contents = web_contents(); 207 content::WebContents* contents = web_contents();
204 scoped_ptr<IPC::Message> message( 208 scoped_ptr<IPC::Message> message(
205 new ChromeViewHostMsg_SetVoiceSearchSupported( 209 new ChromeViewHostMsg_SetVoiceSearchSupported(
206 contents->GetRoutingID(), 210 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), true));
207 contents->GetController().GetVisibleEntry()->GetPageID(),
208 true));
209 OnMessageReceived(*message); 211 OnMessageReceived(*message);
210 } 212 }
211 213
212 TEST_F(SearchIPCRouterTest, IgnoreVoiceSearchSupportMsg) { 214 TEST_F(SearchIPCRouterTest, IgnoreVoiceSearchSupportMsg) {
213 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 215 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
214 EXPECT_CALL(*mock_delegate(), OnSetVoiceSearchSupport(true)).Times(0); 216 EXPECT_CALL(*mock_delegate(), OnSetVoiceSearchSupport(true)).Times(0);
215 SetupMockDelegateAndPolicy(); 217 SetupMockDelegateAndPolicy();
216 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 218 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
217 EXPECT_CALL(*policy, ShouldProcessSetVoiceSearchSupport()).Times(1) 219 EXPECT_CALL(*policy, ShouldProcessSetVoiceSearchSupport()).Times(1)
218 .WillOnce(testing::Return(false)); 220 .WillOnce(testing::Return(false));
219 221
220 content::WebContents* contents = web_contents(); 222 content::WebContents* contents = web_contents();
221 scoped_ptr<IPC::Message> message( 223 scoped_ptr<IPC::Message> message(
222 new ChromeViewHostMsg_SetVoiceSearchSupported( 224 new ChromeViewHostMsg_SetVoiceSearchSupported(
223 contents->GetRoutingID(), 225 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), true));
224 contents->GetController().GetVisibleEntry()->GetPageID(),
225 true));
226 OnMessageReceived(*message); 226 OnMessageReceived(*message);
227 } 227 }
228 228
229 TEST_F(SearchIPCRouterTest, ProcessFocusOmniboxMsg) { 229 TEST_F(SearchIPCRouterTest, ProcessFocusOmniboxMsg) {
230 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 230 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
231 SetupMockDelegateAndPolicy(); 231 SetupMockDelegateAndPolicy();
232 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 232 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
233 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(1); 233 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(1);
234 234
235 content::WebContents* contents = web_contents(); 235 content::WebContents* contents = web_contents();
236 bool is_active_tab = IsActiveTab(contents); 236 bool is_active_tab = IsActiveTab(contents);
237 EXPECT_TRUE(is_active_tab); 237 EXPECT_TRUE(is_active_tab);
238 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(1) 238 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(1)
239 .WillOnce(testing::Return(true)); 239 .WillOnce(testing::Return(true));
240 240
241 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_FocusOmnibox( 241 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_FocusOmnibox(
242 contents->GetRoutingID(), 242 contents->GetRoutingID(),
243 contents->GetController().GetVisibleEntry()->GetPageID(), 243 GetSearchIPCRouterSeqNo(),
244 OMNIBOX_FOCUS_VISIBLE)); 244 OMNIBOX_FOCUS_VISIBLE));
245 OnMessageReceived(*message); 245 OnMessageReceived(*message);
246 } 246 }
247 247
248 TEST_F(SearchIPCRouterTest, IgnoreFocusOmniboxMsg) { 248 TEST_F(SearchIPCRouterTest, IgnoreFocusOmniboxMsg) {
249 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 249 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
250 SetupMockDelegateAndPolicy(); 250 SetupMockDelegateAndPolicy();
251 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 251 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
252 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(0); 252 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(0);
253 253
254 content::WebContents* contents = web_contents(); 254 content::WebContents* contents = web_contents();
255 bool is_active_tab = IsActiveTab(contents); 255 bool is_active_tab = IsActiveTab(contents);
256 EXPECT_TRUE(is_active_tab); 256 EXPECT_TRUE(is_active_tab);
257 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(1) 257 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(1)
258 .WillOnce(testing::Return(false)); 258 .WillOnce(testing::Return(false));
259 259
260 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_FocusOmnibox( 260 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_FocusOmnibox(
261 contents->GetRoutingID(), 261 contents->GetRoutingID(),
262 contents->GetController().GetVisibleEntry()->GetPageID(), 262 GetSearchIPCRouterSeqNo(),
263 OMNIBOX_FOCUS_VISIBLE)); 263 OMNIBOX_FOCUS_VISIBLE));
264 OnMessageReceived(*message); 264 OnMessageReceived(*message);
265 } 265 }
266 266
267 TEST_F(SearchIPCRouterTest, HandleTabChangedEvents) { 267 TEST_F(SearchIPCRouterTest, HandleTabChangedEvents) {
268 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 268 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
269 content::WebContents* contents = web_contents(); 269 content::WebContents* contents = web_contents();
270 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents(contents)); 270 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents(contents));
271 EXPECT_TRUE(IsActiveTab(contents)); 271 EXPECT_TRUE(IsActiveTab(contents));
272 272
(...skipping 20 matching lines...) Expand all
293 content::WebContents* contents = web_contents(); 293 content::WebContents* contents = web_contents();
294 bool is_active_tab = IsActiveTab(contents); 294 bool is_active_tab = IsActiveTab(contents);
295 EXPECT_TRUE(is_active_tab); 295 EXPECT_TRUE(is_active_tab);
296 296
297 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 297 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
298 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(1) 298 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(1)
299 .WillOnce(testing::Return(true)); 299 .WillOnce(testing::Return(true));
300 300
301 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_SearchBoxNavigate( 301 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_SearchBoxNavigate(
302 contents->GetRoutingID(), 302 contents->GetRoutingID(),
303 contents->GetController().GetVisibleEntry()->GetPageID(), 303 GetSearchIPCRouterSeqNo(),
304 destination_url, CURRENT_TAB, true)); 304 destination_url, CURRENT_TAB, true));
305 OnMessageReceived(*message); 305 OnMessageReceived(*message);
306 } 306 }
307 307
308 TEST_F(SearchIPCRouterTest, IgnoreNavigateToURLMsg) { 308 TEST_F(SearchIPCRouterTest, IgnoreNavigateToURLMsg) {
309 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 309 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
310 SetupMockDelegateAndPolicy(); 310 SetupMockDelegateAndPolicy();
311 GURL destination_url("www.foo.com"); 311 GURL destination_url("www.foo.com");
312 EXPECT_CALL(*mock_delegate(), NavigateToURL(destination_url, CURRENT_TAB, 312 EXPECT_CALL(*mock_delegate(), NavigateToURL(destination_url, CURRENT_TAB,
313 true)).Times(0); 313 true)).Times(0);
314 content::WebContents* contents = web_contents(); 314 content::WebContents* contents = web_contents();
315 bool is_active_tab = IsActiveTab(contents); 315 bool is_active_tab = IsActiveTab(contents);
316 EXPECT_TRUE(is_active_tab); 316 EXPECT_TRUE(is_active_tab);
317 317
318 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 318 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
319 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(1) 319 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(1)
320 .WillOnce(testing::Return(false)); 320 .WillOnce(testing::Return(false));
321 321
322 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_SearchBoxNavigate( 322 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_SearchBoxNavigate(
323 contents->GetRoutingID(), 323 contents->GetRoutingID(),
324 contents->GetController().GetVisibleEntry()->GetPageID(), 324 GetSearchIPCRouterSeqNo(),
325 destination_url, CURRENT_TAB, true)); 325 destination_url, CURRENT_TAB, true));
326 OnMessageReceived(*message); 326 OnMessageReceived(*message);
327 } 327 }
328 328
329 TEST_F(SearchIPCRouterTest, ProcessLogEventMsg) { 329 TEST_F(SearchIPCRouterTest, ProcessLogEventMsg) {
330 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 330 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
331 SetupMockDelegateAndPolicy(); 331 SetupMockDelegateAndPolicy();
332 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 332 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
333 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_MOUSEOVER)).Times(1); 333 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_MOUSEOVER)).Times(1);
334 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1) 334 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1)
335 .WillOnce(testing::Return(true)); 335 .WillOnce(testing::Return(true));
336 336
337 content::WebContents* contents = web_contents(); 337 content::WebContents* contents = web_contents();
338 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_LogEvent( 338 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_LogEvent(
339 contents->GetRoutingID(), 339 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(),
340 contents->GetController().GetVisibleEntry()->GetPageID(),
341 NTP_MOUSEOVER)); 340 NTP_MOUSEOVER));
342 OnMessageReceived(*message); 341 OnMessageReceived(*message);
343 } 342 }
344 343
345 TEST_F(SearchIPCRouterTest, IgnoreLogEventMsg) { 344 TEST_F(SearchIPCRouterTest, IgnoreLogEventMsg) {
346 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 345 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
347 SetupMockDelegateAndPolicy(); 346 SetupMockDelegateAndPolicy();
348 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 347 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
349 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_MOUSEOVER)).Times(0); 348 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_MOUSEOVER)).Times(0);
350 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1) 349 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1)
351 .WillOnce(testing::Return(false)); 350 .WillOnce(testing::Return(false));
352 351
353 content::WebContents* contents = web_contents(); 352 content::WebContents* contents = web_contents();
354 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_LogEvent( 353 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_LogEvent(
355 contents->GetRoutingID(), 354 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(),
356 contents->GetController().GetVisibleEntry()->GetPageID(),
357 NTP_MOUSEOVER)); 355 NTP_MOUSEOVER));
358 OnMessageReceived(*message); 356 OnMessageReceived(*message);
359 } 357 }
360 358
361 TEST_F(SearchIPCRouterTest, ProcessLogMostVisitedImpressionMsg) { 359 TEST_F(SearchIPCRouterTest, ProcessLogMostVisitedImpressionMsg) {
362 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 360 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
363 SetupMockDelegateAndPolicy(); 361 SetupMockDelegateAndPolicy();
364 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 362 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
365 EXPECT_CALL(*mock_delegate(), 363 EXPECT_CALL(*mock_delegate(),
366 OnLogMostVisitedImpression(3, base::ASCIIToUTF16("Server"))).Times(1); 364 OnLogMostVisitedImpression(3, base::ASCIIToUTF16("Server"))).Times(1);
367 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1) 365 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1)
368 .WillOnce(testing::Return(true)); 366 .WillOnce(testing::Return(true));
369 367
370 content::WebContents* contents = web_contents(); 368 content::WebContents* contents = web_contents();
371 scoped_ptr<IPC::Message> message( 369 scoped_ptr<IPC::Message> message(
372 new ChromeViewHostMsg_LogMostVisitedImpression( 370 new ChromeViewHostMsg_LogMostVisitedImpression(
373 contents->GetRoutingID(), 371 contents->GetRoutingID(),
374 contents->GetController().GetVisibleEntry()->GetPageID(), 372 GetSearchIPCRouterSeqNo(),
375 3, 373 3,
376 base::ASCIIToUTF16("Server"))); 374 base::ASCIIToUTF16("Server")));
377 OnMessageReceived(*message); 375 OnMessageReceived(*message);
378 } 376 }
379 377
380 TEST_F(SearchIPCRouterTest, ProcessLogMostVisitedNavigationMsg) { 378 TEST_F(SearchIPCRouterTest, ProcessLogMostVisitedNavigationMsg) {
381 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 379 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
382 SetupMockDelegateAndPolicy(); 380 SetupMockDelegateAndPolicy();
383 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 381 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
384 EXPECT_CALL(*mock_delegate(), 382 EXPECT_CALL(*mock_delegate(),
385 OnLogMostVisitedNavigation(3, base::ASCIIToUTF16("Server"))).Times(1); 383 OnLogMostVisitedNavigation(3, base::ASCIIToUTF16("Server"))).Times(1);
386 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1) 384 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1)
387 .WillOnce(testing::Return(true)); 385 .WillOnce(testing::Return(true));
388 386
389 content::WebContents* contents = web_contents(); 387 content::WebContents* contents = web_contents();
390 scoped_ptr<IPC::Message> message( 388 scoped_ptr<IPC::Message> message(
391 new ChromeViewHostMsg_LogMostVisitedNavigation( 389 new ChromeViewHostMsg_LogMostVisitedNavigation(
392 contents->GetRoutingID(), 390 contents->GetRoutingID(),
393 contents->GetController().GetVisibleEntry()->GetPageID(), 391 GetSearchIPCRouterSeqNo(),
394 3, 392 3,
395 base::ASCIIToUTF16("Server"))); 393 base::ASCIIToUTF16("Server")));
396 OnMessageReceived(*message); 394 OnMessageReceived(*message);
397 } 395 }
398 396
399 TEST_F(SearchIPCRouterTest, ProcessChromeIdentityCheckMsg) { 397 TEST_F(SearchIPCRouterTest, ProcessChromeIdentityCheckMsg) {
400 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 398 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
401 SetupMockDelegateAndPolicy(); 399 SetupMockDelegateAndPolicy();
402 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 400 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
403 const base::string16 test_identity = base::ASCIIToUTF16("foo@bar.com"); 401 const base::string16 test_identity = base::ASCIIToUTF16("foo@bar.com");
404 EXPECT_CALL(*mock_delegate(), OnChromeIdentityCheck(test_identity)).Times(1); 402 EXPECT_CALL(*mock_delegate(), OnChromeIdentityCheck(test_identity)).Times(1);
405 EXPECT_CALL(*policy, ShouldProcessChromeIdentityCheck()).Times(1) 403 EXPECT_CALL(*policy, ShouldProcessChromeIdentityCheck()).Times(1)
406 .WillOnce(testing::Return(true)); 404 .WillOnce(testing::Return(true));
407 405
408 content::WebContents* contents = web_contents(); 406 content::WebContents* contents = web_contents();
409 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_ChromeIdentityCheck( 407 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_ChromeIdentityCheck(
410 contents->GetRoutingID(), 408 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), test_identity));
411 contents->GetController().GetVisibleEntry()->GetPageID(),
412 test_identity));
413 OnMessageReceived(*message); 409 OnMessageReceived(*message);
414 } 410 }
415 411
416 TEST_F(SearchIPCRouterTest, IgnoreChromeIdentityCheckMsg) { 412 TEST_F(SearchIPCRouterTest, IgnoreChromeIdentityCheckMsg) {
417 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 413 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
418 SetupMockDelegateAndPolicy(); 414 SetupMockDelegateAndPolicy();
419 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 415 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
420 416
421 const base::string16 test_identity = base::ASCIIToUTF16("foo@bar.com"); 417 const base::string16 test_identity = base::ASCIIToUTF16("foo@bar.com");
422 EXPECT_CALL(*mock_delegate(), OnChromeIdentityCheck(test_identity)).Times(0); 418 EXPECT_CALL(*mock_delegate(), OnChromeIdentityCheck(test_identity)).Times(0);
423 EXPECT_CALL(*policy, ShouldProcessChromeIdentityCheck()).Times(1) 419 EXPECT_CALL(*policy, ShouldProcessChromeIdentityCheck()).Times(1)
424 .WillOnce(testing::Return(false)); 420 .WillOnce(testing::Return(false));
425 421
426 content::WebContents* contents = web_contents(); 422 content::WebContents* contents = web_contents();
427 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_ChromeIdentityCheck( 423 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_ChromeIdentityCheck(
428 contents->GetRoutingID(), 424 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), test_identity));
429 contents->GetController().GetVisibleEntry()->GetPageID(),
430 test_identity));
431 OnMessageReceived(*message); 425 OnMessageReceived(*message);
432 } 426 }
433 427
434 TEST_F(SearchIPCRouterTest, ProcessDeleteMostVisitedItemMsg) { 428 TEST_F(SearchIPCRouterTest, ProcessDeleteMostVisitedItemMsg) {
435 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 429 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
436 SetupMockDelegateAndPolicy(); 430 SetupMockDelegateAndPolicy();
437 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 431 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
438 GURL item_url("www.foo.com"); 432 GURL item_url("www.foo.com");
439 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(1); 433 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(1);
440 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(1) 434 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(1)
441 .WillOnce(testing::Return(true)); 435 .WillOnce(testing::Return(true));
442 436
443 content::WebContents* contents = web_contents(); 437 content::WebContents* contents = web_contents();
444 scoped_ptr<IPC::Message> message( 438 scoped_ptr<IPC::Message> message(
445 new ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem( 439 new ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(
446 contents->GetRoutingID(), 440 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), item_url));
447 contents->GetController().GetVisibleEntry()->GetPageID(),
448 item_url));
449 OnMessageReceived(*message); 441 OnMessageReceived(*message);
450 } 442 }
451 443
452 TEST_F(SearchIPCRouterTest, IgnoreDeleteMostVisitedItemMsg) { 444 TEST_F(SearchIPCRouterTest, IgnoreDeleteMostVisitedItemMsg) {
453 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 445 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
454 SetupMockDelegateAndPolicy(); 446 SetupMockDelegateAndPolicy();
455 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 447 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
456 GURL item_url("www.foo.com"); 448 GURL item_url("www.foo.com");
457 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(0); 449 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(0);
458 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(1) 450 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(1)
459 .WillOnce(testing::Return(false)); 451 .WillOnce(testing::Return(false));
460 452
461 content::WebContents* contents = web_contents(); 453 content::WebContents* contents = web_contents();
462 scoped_ptr<IPC::Message> message( 454 scoped_ptr<IPC::Message> message(
463 new ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem( 455 new ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(
464 contents->GetRoutingID(), 456 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), item_url));
465 contents->GetController().GetVisibleEntry()->GetPageID(),
466 item_url));
467 OnMessageReceived(*message); 457 OnMessageReceived(*message);
468 } 458 }
469 459
470 TEST_F(SearchIPCRouterTest, ProcessUndoMostVisitedDeletionMsg) { 460 TEST_F(SearchIPCRouterTest, ProcessUndoMostVisitedDeletionMsg) {
471 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 461 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
472 SetupMockDelegateAndPolicy(); 462 SetupMockDelegateAndPolicy();
473 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 463 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
474 GURL item_url("www.foo.com"); 464 GURL item_url("www.foo.com");
475 EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(1); 465 EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(1);
476 EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(1) 466 EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(1)
477 .WillOnce(testing::Return(true)); 467 .WillOnce(testing::Return(true));
478 468
479 content::WebContents* contents = web_contents(); 469 content::WebContents* contents = web_contents();
480 scoped_ptr<IPC::Message> message( 470 scoped_ptr<IPC::Message> message(
481 new ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion( 471 new ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(
482 contents->GetRoutingID(), 472 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), item_url));
483 contents->GetController().GetVisibleEntry()->GetPageID(),
484 item_url));
485 OnMessageReceived(*message); 473 OnMessageReceived(*message);
486 } 474 }
487 475
488 TEST_F(SearchIPCRouterTest, IgnoreUndoMostVisitedDeletionMsg) { 476 TEST_F(SearchIPCRouterTest, IgnoreUndoMostVisitedDeletionMsg) {
489 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 477 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
490 SetupMockDelegateAndPolicy(); 478 SetupMockDelegateAndPolicy();
491 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 479 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
492 GURL item_url("www.foo.com"); 480 GURL item_url("www.foo.com");
493 EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(0); 481 EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(0);
494 EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(1) 482 EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(1)
495 .WillOnce(testing::Return(false)); 483 .WillOnce(testing::Return(false));
496 484
497 content::WebContents* contents = web_contents(); 485 content::WebContents* contents = web_contents();
498 scoped_ptr<IPC::Message> message( 486 scoped_ptr<IPC::Message> message(
499 new ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion( 487 new ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(
500 contents->GetRoutingID(), 488 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), item_url));
501 contents->GetController().GetVisibleEntry()->GetPageID(),
502 item_url));
503 OnMessageReceived(*message); 489 OnMessageReceived(*message);
504 } 490 }
505 491
506 TEST_F(SearchIPCRouterTest, ProcessUndoAllMostVisitedDeletionsMsg) { 492 TEST_F(SearchIPCRouterTest, ProcessUndoAllMostVisitedDeletionsMsg) {
507 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 493 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
508 SetupMockDelegateAndPolicy(); 494 SetupMockDelegateAndPolicy();
509 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 495 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
510 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(1); 496 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(1);
511 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(1) 497 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(1)
512 .WillOnce(testing::Return(true)); 498 .WillOnce(testing::Return(true));
513 499
514 content::WebContents* contents = web_contents(); 500 content::WebContents* contents = web_contents();
515 scoped_ptr<IPC::Message> message( 501 scoped_ptr<IPC::Message> message(
516 new ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions( 502 new ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions(
517 contents->GetRoutingID(), 503 contents->GetRoutingID(), GetSearchIPCRouterSeqNo()));
518 contents->GetController().GetVisibleEntry()->GetPageID()));
519 OnMessageReceived(*message); 504 OnMessageReceived(*message);
520 } 505 }
521 506
522 TEST_F(SearchIPCRouterTest, IgnoreUndoAllMostVisitedDeletionsMsg) { 507 TEST_F(SearchIPCRouterTest, IgnoreUndoAllMostVisitedDeletionsMsg) {
523 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 508 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
524 SetupMockDelegateAndPolicy(); 509 SetupMockDelegateAndPolicy();
525 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 510 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
526 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(0); 511 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(0);
527 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(1) 512 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(1)
528 .WillOnce(testing::Return(false)); 513 .WillOnce(testing::Return(false));
529 514
530 content::WebContents* contents = web_contents(); 515 content::WebContents* contents = web_contents();
531 scoped_ptr<IPC::Message> message( 516 scoped_ptr<IPC::Message> message(
532 new ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions( 517 new ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions(
533 contents->GetRoutingID(), 518 contents->GetRoutingID(), GetSearchIPCRouterSeqNo()));
534 contents->GetController().GetVisibleEntry()->GetPageID()));
535 OnMessageReceived(*message); 519 OnMessageReceived(*message);
536 } 520 }
537 521
538 TEST_F(SearchIPCRouterTest, IgnoreMessageIfThePageIsNotActive) { 522 TEST_F(SearchIPCRouterTest, IgnoreMessageIfThePageIsNotActive) {
539 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 523 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
540 SetupMockDelegateAndPolicy(); 524 SetupMockDelegateAndPolicy();
541 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 525 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
526 int page_seq_no = GetSearchIPCRouterSeqNo();
542 527
543 content::WebContents* contents = web_contents(); 528 content::WebContents* contents = web_contents();
544 bool is_active_tab = IsActiveTab(contents); 529 bool is_active_tab = IsActiveTab(contents);
545 int invalid_page_id = 1000;
546 GURL item_url("www.foo.com"); 530 GURL item_url("www.foo.com");
547 EXPECT_CALL(*mock_delegate(), NavigateToURL(item_url, CURRENT_TAB, 531 EXPECT_CALL(*mock_delegate(), NavigateToURL(item_url, CURRENT_TAB,
548 true)).Times(0); 532 true)).Times(0);
533 // At this point, in a real test, the navigation would cause the
534 // SearchIPCRouter's page sequence to advance. In this test it doesn't, so
535 // we'll decrement the sequence number on this side to simulate it.
536 --page_seq_no;
549 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(0); 537 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(0);
550 538
551 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_SearchBoxNavigate( 539 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_SearchBoxNavigate(
552 contents->GetRoutingID(), invalid_page_id, item_url, CURRENT_TAB, 540 contents->GetRoutingID(), page_seq_no, item_url,
553 true)); 541 CURRENT_TAB, true));
554 OnMessageReceived(*message); 542 OnMessageReceived(*message);
555 543
556 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(0); 544 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(0);
557 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(0); 545 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(0);
558 message.reset(new ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem( 546 message.reset(new ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(
559 contents->GetRoutingID(), invalid_page_id, item_url)); 547 contents->GetRoutingID(), page_seq_no, item_url));
560 OnMessageReceived(*message); 548 OnMessageReceived(*message);
561 549
562 EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(0); 550 EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(0);
563 EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(0); 551 EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(0);
564 message.reset(new ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion( 552 message.reset(new ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(
565 contents->GetRoutingID(), invalid_page_id, item_url)); 553 contents->GetRoutingID(), page_seq_no, item_url));
566 OnMessageReceived(*message); 554 OnMessageReceived(*message);
567 555
568 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(0); 556 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(0);
569 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(0); 557 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(0);
570 message.reset(new ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions( 558 message.reset(new ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions(
571 contents->GetRoutingID(), invalid_page_id)); 559 contents->GetRoutingID(), page_seq_no));
572 OnMessageReceived(*message); 560 OnMessageReceived(*message);
573 561
574 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(0); 562 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(0);
575 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(0); 563 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(0);
576 message.reset(new ChromeViewHostMsg_FocusOmnibox( 564 message.reset(new ChromeViewHostMsg_FocusOmnibox(
577 contents->GetRoutingID(), invalid_page_id, OMNIBOX_FOCUS_VISIBLE)); 565 contents->GetRoutingID(), page_seq_no,
566 OMNIBOX_FOCUS_VISIBLE));
578 OnMessageReceived(*message); 567 OnMessageReceived(*message);
579 568
580 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_MOUSEOVER)).Times(0); 569 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_MOUSEOVER)).Times(0);
581 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(0); 570 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(0);
582 message.reset(new ChromeViewHostMsg_LogEvent(contents->GetRoutingID(), 571 message.reset(new ChromeViewHostMsg_LogEvent(contents->GetRoutingID(),
583 invalid_page_id, NTP_MOUSEOVER)); 572 page_seq_no,
573 NTP_MOUSEOVER));
584 OnMessageReceived(*message); 574 OnMessageReceived(*message);
585 575
586 base::string16 text; 576 base::string16 text;
587 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(0); 577 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(0);
588 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(0); 578 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(0);
589 message.reset(new ChromeViewHostMsg_PasteAndOpenDropdown( 579 message.reset(new ChromeViewHostMsg_PasteAndOpenDropdown(
590 contents->GetRoutingID(), invalid_page_id, text)); 580 contents->GetRoutingID(), page_seq_no, text));
591 OnMessageReceived(*message); 581 OnMessageReceived(*message);
592 } 582 }
593 583
594 TEST_F(SearchIPCRouterTest, ProcessPasteAndOpenDropdownMsg) { 584 TEST_F(SearchIPCRouterTest, ProcessPasteAndOpenDropdownMsg) {
595 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 585 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
596 SetupMockDelegateAndPolicy(); 586 SetupMockDelegateAndPolicy();
597 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 587 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
598 588
599 content::WebContents* contents = web_contents(); 589 content::WebContents* contents = web_contents();
600 bool is_active_tab = IsActiveTab(contents); 590 bool is_active_tab = IsActiveTab(contents);
601 EXPECT_TRUE(is_active_tab); 591 EXPECT_TRUE(is_active_tab);
602 592
603 base::string16 text; 593 base::string16 text;
604 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(1); 594 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(1);
605 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(1) 595 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(1)
606 .WillOnce(testing::Return(true)); 596 .WillOnce(testing::Return(true));
607 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_PasteAndOpenDropdown( 597 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_PasteAndOpenDropdown(
608 contents->GetRoutingID(), 598 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), text));
609 contents->GetController().GetVisibleEntry()->GetPageID(), text));
610 OnMessageReceived(*message); 599 OnMessageReceived(*message);
611 } 600 }
612 601
613 TEST_F(SearchIPCRouterTest, IgnorePasteAndOpenDropdownMsg) { 602 TEST_F(SearchIPCRouterTest, IgnorePasteAndOpenDropdownMsg) {
614 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 603 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
615 SetupMockDelegateAndPolicy(); 604 SetupMockDelegateAndPolicy();
616 base::string16 text; 605 base::string16 text;
617 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(0); 606 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(0);
618 607
619 content::WebContents* contents = web_contents(); 608 content::WebContents* contents = web_contents();
620 bool is_active_tab = IsActiveTab(contents); 609 bool is_active_tab = IsActiveTab(contents);
621 EXPECT_TRUE(is_active_tab); 610 EXPECT_TRUE(is_active_tab);
622 611
623 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 612 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
624 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(1) 613 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(1)
625 .WillOnce(testing::Return(false)); 614 .WillOnce(testing::Return(false));
626 615
627 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_PasteAndOpenDropdown( 616 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_PasteAndOpenDropdown(
628 contents->GetRoutingID(), 617 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), text));
629 contents->GetController().GetVisibleEntry()->GetPageID(), text));
630 OnMessageReceived(*message); 618 OnMessageReceived(*message);
631 } 619 }
632 620
633 TEST_F(SearchIPCRouterTest, SendSetPromoInformationMsg) { 621 TEST_F(SearchIPCRouterTest, SendSetPromoInformationMsg) {
634 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 622 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
635 SetupMockDelegateAndPolicy(); 623 SetupMockDelegateAndPolicy();
636 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 624 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
637 EXPECT_CALL(*policy, ShouldSendSetPromoInformation()).Times(1) 625 EXPECT_CALL(*policy, ShouldSendSetPromoInformation()).Times(1)
638 .WillOnce(testing::Return(true)); 626 .WillOnce(testing::Return(true));
639 627
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 908 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
921 SetupMockDelegateAndPolicy(); 909 SetupMockDelegateAndPolicy();
922 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 910 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
923 EXPECT_CALL(*policy, ShouldSendToggleVoiceSearch()).Times(1) 911 EXPECT_CALL(*policy, ShouldSendToggleVoiceSearch()).Times(1)
924 .WillOnce(testing::Return(false)); 912 .WillOnce(testing::Return(false));
925 913
926 process()->sink().ClearMessages(); 914 process()->sink().ClearMessages();
927 GetSearchIPCRouter().ToggleVoiceSearch(); 915 GetSearchIPCRouter().ToggleVoiceSearch();
928 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxToggleVoiceSearch::ID)); 916 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxToggleVoiceSearch::ID));
929 } 917 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/search_ipc_router_policy_unittest.cc ('k') | chrome/browser/ui/search/search_tab_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698