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