| 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 <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 MOCK_METHOD0(ShouldProcessDeleteMostVisitedItem, bool()); | 73 MOCK_METHOD0(ShouldProcessDeleteMostVisitedItem, bool()); |
| 74 MOCK_METHOD0(ShouldProcessUndoMostVisitedDeletion, bool()); | 74 MOCK_METHOD0(ShouldProcessUndoMostVisitedDeletion, bool()); |
| 75 MOCK_METHOD0(ShouldProcessUndoAllMostVisitedDeletions, bool()); | 75 MOCK_METHOD0(ShouldProcessUndoAllMostVisitedDeletions, bool()); |
| 76 MOCK_METHOD0(ShouldProcessLogEvent, bool()); | 76 MOCK_METHOD0(ShouldProcessLogEvent, bool()); |
| 77 MOCK_METHOD1(ShouldProcessPasteIntoOmnibox, bool(bool)); | 77 MOCK_METHOD1(ShouldProcessPasteIntoOmnibox, bool(bool)); |
| 78 MOCK_METHOD0(ShouldProcessChromeIdentityCheck, bool()); | 78 MOCK_METHOD0(ShouldProcessChromeIdentityCheck, bool()); |
| 79 MOCK_METHOD0(ShouldProcessHistorySyncCheck, bool()); | 79 MOCK_METHOD0(ShouldProcessHistorySyncCheck, bool()); |
| 80 MOCK_METHOD0(ShouldSendSetPromoInformation, bool()); | 80 MOCK_METHOD0(ShouldSendSetPromoInformation, bool()); |
| 81 MOCK_METHOD0(ShouldSendSetDisplayInstantResults, bool()); | 81 MOCK_METHOD0(ShouldSendSetDisplayInstantResults, bool()); |
| 82 MOCK_METHOD0(ShouldSendSetSuggestionToPrefetch, bool()); | 82 MOCK_METHOD0(ShouldSendSetSuggestionToPrefetch, bool()); |
| 83 MOCK_METHOD0(ShouldSendSetOmniboxStartMargin, bool()); | |
| 84 MOCK_METHOD1(ShouldSendSetInputInProgress, bool(bool)); | 83 MOCK_METHOD1(ShouldSendSetInputInProgress, bool(bool)); |
| 85 MOCK_METHOD0(ShouldSendOmniboxFocusChanged, bool()); | 84 MOCK_METHOD0(ShouldSendOmniboxFocusChanged, bool()); |
| 86 MOCK_METHOD0(ShouldSendMostVisitedItems, bool()); | 85 MOCK_METHOD0(ShouldSendMostVisitedItems, bool()); |
| 87 MOCK_METHOD0(ShouldSendThemeBackgroundInfo, bool()); | 86 MOCK_METHOD0(ShouldSendThemeBackgroundInfo, bool()); |
| 88 MOCK_METHOD0(ShouldSubmitQuery, bool()); | 87 MOCK_METHOD0(ShouldSubmitQuery, bool()); |
| 89 }; | 88 }; |
| 90 | 89 |
| 91 } // namespace | 90 } // namespace |
| 92 | 91 |
| 93 class SearchIPCRouterTest : public BrowserWithTestWindowTest { | 92 class SearchIPCRouterTest : public BrowserWithTestWindowTest { |
| 94 public: | 93 public: |
| 95 SearchIPCRouterTest() : field_trial_list_(NULL) {} | 94 SearchIPCRouterTest() : field_trial_list_(NULL) {} |
| 96 | 95 |
| 97 void SetUp() override { | 96 void SetUp() override { |
| 98 BrowserWithTestWindowTest::SetUp(); | 97 BrowserWithTestWindowTest::SetUp(); |
| 99 AddTab(browser(), GURL("chrome://blank")); | 98 AddTab(browser(), GURL("chrome://blank")); |
| 100 SearchTabHelper::CreateForWebContents(web_contents()); | 99 SearchTabHelper::CreateForWebContents(web_contents()); |
| 101 | 100 |
| 102 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 101 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 103 profile(), | 102 profile(), |
| 104 &TemplateURLServiceFactory::BuildInstanceFor); | 103 &TemplateURLServiceFactory::BuildInstanceFor); |
| 105 TemplateURLService* template_url_service = | 104 TemplateURLService* template_url_service = |
| 106 TemplateURLServiceFactory::GetForProfile(profile()); | 105 TemplateURLServiceFactory::GetForProfile(profile()); |
| 107 search_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); | 106 search_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); |
| 108 | 107 |
| 109 TemplateURLData data; | 108 TemplateURLData data; |
| 110 data.SetShortName(base::ASCIIToUTF16("foo.com")); | 109 data.SetShortName(base::ASCIIToUTF16("foo.com")); |
| 111 data.SetURL("http://foo.com/url?bar={searchTerms}"); | 110 data.SetURL("http://foo.com/url?bar={searchTerms}"); |
| 112 data.instant_url = "http://foo.com/instant?" | 111 data.instant_url = "http://foo.com/instant?foo=foo#foo=foo&espv"; |
| 113 "{google:omniboxStartMarginParameter}foo=foo#foo=foo&espv"; | |
| 114 data.new_tab_url = "https://foo.com/newtab?espv"; | 112 data.new_tab_url = "https://foo.com/newtab?espv"; |
| 115 data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}"); | 113 data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}"); |
| 116 data.search_terms_replacement_key = "espv"; | 114 data.search_terms_replacement_key = "espv"; |
| 117 | 115 |
| 118 TemplateURL* template_url = new TemplateURL(data); | 116 TemplateURL* template_url = new TemplateURL(data); |
| 119 // Takes ownership of |template_url|. | 117 // Takes ownership of |template_url|. |
| 120 template_url_service->Add(template_url); | 118 template_url_service->Add(template_url); |
| 121 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); | 119 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); |
| 122 process()->sink().ClearMessages(); | 120 process()->sink().ClearMessages(); |
| 123 } | 121 } |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 EXPECT_CALL(*policy, ShouldSendSetSuggestionToPrefetch()).Times(1) | 691 EXPECT_CALL(*policy, ShouldSendSetSuggestionToPrefetch()).Times(1) |
| 694 .WillOnce(testing::Return(false)); | 692 .WillOnce(testing::Return(false)); |
| 695 | 693 |
| 696 process()->sink().ClearMessages(); | 694 process()->sink().ClearMessages(); |
| 697 content::WebContents* contents = web_contents(); | 695 content::WebContents* contents = web_contents(); |
| 698 GetSearchTabHelper(contents)->SetSuggestionToPrefetch(InstantSuggestion()); | 696 GetSearchTabHelper(contents)->SetSuggestionToPrefetch(InstantSuggestion()); |
| 699 EXPECT_FALSE(MessageWasSent( | 697 EXPECT_FALSE(MessageWasSent( |
| 700 ChromeViewMsg_SearchBoxSetSuggestionToPrefetch::ID)); | 698 ChromeViewMsg_SearchBoxSetSuggestionToPrefetch::ID)); |
| 701 } | 699 } |
| 702 | 700 |
| 703 TEST_F(SearchIPCRouterTest, SendSetOmniboxStartMargin) { | |
| 704 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); | |
| 705 SetupMockDelegateAndPolicy(); | |
| 706 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); | |
| 707 EXPECT_CALL(*policy, ShouldSendSetOmniboxStartMargin()).Times(1) | |
| 708 .WillOnce(testing::Return(true)); | |
| 709 | |
| 710 process()->sink().ClearMessages(); | |
| 711 GetSearchIPCRouter().SetOmniboxStartMargin(92); | |
| 712 EXPECT_TRUE(MessageWasSent(ChromeViewMsg_SearchBoxMarginChange::ID)); | |
| 713 } | |
| 714 | |
| 715 TEST_F(SearchIPCRouterTest, DoNotSendSetOmniboxStartMargin) { | |
| 716 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); | |
| 717 SetupMockDelegateAndPolicy(); | |
| 718 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); | |
| 719 EXPECT_CALL(*policy, ShouldSendSetOmniboxStartMargin()).Times(1) | |
| 720 .WillOnce(testing::Return(false)); | |
| 721 | |
| 722 process()->sink().ClearMessages(); | |
| 723 GetSearchIPCRouter().SetOmniboxStartMargin(92); | |
| 724 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxMarginChange::ID)); | |
| 725 } | |
| 726 | |
| 727 TEST_F(SearchIPCRouterTest, SendOmniboxFocusChange) { | 701 TEST_F(SearchIPCRouterTest, SendOmniboxFocusChange) { |
| 728 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); | 702 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); |
| 729 SetupMockDelegateAndPolicy(); | 703 SetupMockDelegateAndPolicy(); |
| 730 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); | 704 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); |
| 731 EXPECT_CALL(*policy, ShouldSendOmniboxFocusChanged()).Times(1) | 705 EXPECT_CALL(*policy, ShouldSendOmniboxFocusChanged()).Times(1) |
| 732 .WillOnce(testing::Return(true)); | 706 .WillOnce(testing::Return(true)); |
| 733 | 707 |
| 734 process()->sink().ClearMessages(); | 708 process()->sink().ClearMessages(); |
| 735 GetSearchIPCRouter().OmniboxFocusChanged(OMNIBOX_FOCUS_NONE, | 709 GetSearchIPCRouter().OmniboxFocusChanged(OMNIBOX_FOCUS_NONE, |
| 736 OMNIBOX_FOCUS_CHANGE_EXPLICIT); | 710 OMNIBOX_FOCUS_CHANGE_EXPLICIT); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 | 831 |
| 858 // Construct a series of synthetic messages for each valid IPC message type, | 832 // Construct a series of synthetic messages for each valid IPC message type, |
| 859 // ensuring the router ignores them all. | 833 // ensuring the router ignores them all. |
| 860 for (int i = 0; i < LastIPCMsgStart; ++i) { | 834 for (int i = 0; i < LastIPCMsgStart; ++i) { |
| 861 const int message_id = i << 16; | 835 const int message_id = i << 16; |
| 862 ASSERT_EQ(IPC_MESSAGE_ID_CLASS(message_id), i); | 836 ASSERT_EQ(IPC_MESSAGE_ID_CLASS(message_id), i); |
| 863 IPC::Message msg(routing_id, message_id, IPC::Message::PRIORITY_LOW); | 837 IPC::Message msg(routing_id, message_id, IPC::Message::PRIORITY_LOW); |
| 864 EXPECT_FALSE(OnSpuriousMessageReceived(msg)) << i; | 838 EXPECT_FALSE(OnSpuriousMessageReceived(msg)) << i; |
| 865 } | 839 } |
| 866 } | 840 } |
| OLD | NEW |