Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <tuple> | 10 #include <tuple> |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 } | 176 } |
| 177 | 177 |
| 178 MockSearchBox* mock_search_box() { return &mock_search_box_; } | 178 MockSearchBox* mock_search_box() { return &mock_search_box_; } |
| 179 | 179 |
| 180 private: | 180 private: |
| 181 MockSearchIPCRouterDelegate delegate_; | 181 MockSearchIPCRouterDelegate delegate_; |
| 182 base::FieldTrialList field_trial_list_; | 182 base::FieldTrialList field_trial_list_; |
| 183 MockSearchBox mock_search_box_; | 183 MockSearchBox mock_search_box_; |
| 184 }; | 184 }; |
| 185 | 185 |
| 186 TEST_F(SearchIPCRouterTest, IgnoreMessagesFromNonInstantRenderers) { | |
| 187 NavigateAndCommitActiveTab(GURL("file://foo/bar")); | |
| 188 SetupMockDelegateAndPolicy(); | |
| 189 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(0); | |
| 190 content::WebContents* contents = web_contents(); | |
| 191 bool is_active_tab = IsActiveTab(contents); | |
| 192 EXPECT_TRUE(is_active_tab); | |
| 193 | |
| 194 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); | |
| 195 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(0); | |
| 196 | |
| 197 GetSearchIPCRouter().FocusOmnibox(GetSearchIPCRouterSeqNo(), | |
| 198 OMNIBOX_FOCUS_VISIBLE); | |
| 199 } | |
| 200 | |
| 201 TEST_F(SearchIPCRouterTest, ProcessFocusOmniboxMsg) { | 186 TEST_F(SearchIPCRouterTest, ProcessFocusOmniboxMsg) { |
| 202 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); | 187 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); |
| 203 SetupMockDelegateAndPolicy(); | 188 SetupMockDelegateAndPolicy(); |
| 204 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); | 189 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); |
| 205 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(1); | 190 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(1); |
| 206 | 191 |
| 207 content::WebContents* contents = web_contents(); | 192 content::WebContents* contents = web_contents(); |
| 208 bool is_active_tab = IsActiveTab(contents); | 193 bool is_active_tab = IsActiveTab(contents); |
| 209 EXPECT_TRUE(is_active_tab); | 194 EXPECT_TRUE(is_active_tab); |
| 210 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(1) | 195 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(1) |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 427 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); | 412 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); |
| 428 SetupMockDelegateAndPolicy(); | 413 SetupMockDelegateAndPolicy(); |
| 429 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); | 414 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); |
| 430 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(0); | 415 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(0); |
| 431 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(1) | 416 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(1) |
| 432 .WillOnce(testing::Return(false)); | 417 .WillOnce(testing::Return(false)); |
| 433 | 418 |
| 434 GetSearchIPCRouter().UndoAllMostVisitedDeletions(GetSearchIPCRouterSeqNo()); | 419 GetSearchIPCRouter().UndoAllMostVisitedDeletions(GetSearchIPCRouterSeqNo()); |
| 435 } | 420 } |
| 436 | 421 |
| 437 TEST_F(SearchIPCRouterTest, IgnoreMessageIfThePageIsNotActive) { | |
| 438 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); | |
| 439 SetupMockDelegateAndPolicy(); | |
| 440 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); | |
| 441 int page_seq_no = GetSearchIPCRouterSeqNo(); | |
| 442 | |
| 443 content::WebContents* contents = web_contents(); | |
| 444 bool is_active_tab = IsActiveTab(contents); | |
| 445 GURL item_url("www.foo.com"); | |
| 446 | |
| 447 // Navigate away from the NTP. Afterwards, all messages should be ignored. | |
|
Marc Treib
2017/02/13 09:35:57
It's not clear to me why it's safe to remove these
tibell
2017/02/19 23:18:45
Mojo being connection oriented helps us here. If w
Marc Treib
2017/02/20 10:14:52
That sounds reasonable (to the engineer who has no
| |
| 448 NavigateAndCommitActiveTab(item_url); | |
| 449 | |
| 450 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(0); | |
| 451 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(0); | |
| 452 GetSearchIPCRouter().DeleteMostVisitedItem(page_seq_no, item_url); | |
| 453 | |
| 454 EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(0); | |
| 455 EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(0); | |
| 456 GetSearchIPCRouter().UndoMostVisitedDeletion(page_seq_no, item_url); | |
| 457 | |
| 458 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(0); | |
| 459 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(0); | |
| 460 GetSearchIPCRouter().UndoAllMostVisitedDeletions(page_seq_no); | |
| 461 | |
| 462 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(0); | |
| 463 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(0); | |
| 464 GetSearchIPCRouter().FocusOmnibox(page_seq_no, OMNIBOX_FOCUS_VISIBLE); | |
| 465 | |
| 466 base::TimeDelta delta = base::TimeDelta::FromMilliseconds(123); | |
| 467 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_ALL_TILES_LOADED, delta)) | |
| 468 .Times(0); | |
| 469 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(0); | |
| 470 GetSearchIPCRouter().LogEvent(page_seq_no, NTP_ALL_TILES_LOADED, delta); | |
| 471 | |
| 472 base::string16 text; | |
| 473 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(0); | |
| 474 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(0); | |
| 475 GetSearchIPCRouter().PasteAndOpenDropdown(page_seq_no, text); | |
| 476 } | |
| 477 | |
| 478 TEST_F(SearchIPCRouterTest, ProcessPasteAndOpenDropdownMsg) { | 422 TEST_F(SearchIPCRouterTest, ProcessPasteAndOpenDropdownMsg) { |
| 479 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); | 423 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); |
| 480 SetupMockDelegateAndPolicy(); | 424 SetupMockDelegateAndPolicy(); |
| 481 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); | 425 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); |
| 482 | 426 |
| 483 content::WebContents* contents = web_contents(); | 427 content::WebContents* contents = web_contents(); |
| 484 bool is_active_tab = IsActiveTab(contents); | 428 bool is_active_tab = IsActiveTab(contents); |
| 485 EXPECT_TRUE(is_active_tab); | 429 EXPECT_TRUE(is_active_tab); |
| 486 | 430 |
| 487 base::string16 text; | 431 base::string16 text; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 638 TEST_F(SearchIPCRouterTest, DoNotSendSubmitMsg) { | 582 TEST_F(SearchIPCRouterTest, DoNotSendSubmitMsg) { |
| 639 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); | 583 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); |
| 640 SetupMockDelegateAndPolicy(); | 584 SetupMockDelegateAndPolicy(); |
| 641 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); | 585 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); |
| 642 EXPECT_CALL(*policy, ShouldSubmitQuery()).Times(1) | 586 EXPECT_CALL(*policy, ShouldSubmitQuery()).Times(1) |
| 643 .WillOnce(testing::Return(false)); | 587 .WillOnce(testing::Return(false)); |
| 644 | 588 |
| 645 EXPECT_CALL(*mock_search_box(), Submit(_, _)).Times(0); | 589 EXPECT_CALL(*mock_search_box(), Submit(_, _)).Times(0); |
| 646 GetSearchIPCRouter().Submit(base::string16(), EmbeddedSearchRequestParams()); | 590 GetSearchIPCRouter().Submit(base::string16(), EmbeddedSearchRequestParams()); |
| 647 } | 591 } |
| OLD | NEW |