| 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/browser/ui/search/search_ipc_router_policy_impl.h" | 8 #include "chrome/browser/ui/search/search_ipc_router_policy_impl.h" |
| 9 #include "chrome/browser/ui/search/search_tab_helper.h" | 9 #include "chrome/browser/ui/search/search_tab_helper.h" |
| 10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 ChromeRenderViewHostTestHarness::SetUp(); | 21 ChromeRenderViewHostTestHarness::SetUp(); |
| 22 SearchTabHelper::CreateForWebContents(web_contents()); | 22 SearchTabHelper::CreateForWebContents(web_contents()); |
| 23 } | 23 } |
| 24 }; | 24 }; |
| 25 | 25 |
| 26 TEST_F(SearchIPCRouterPolicyTest, ProcessVoiceSearchSupportMsg) { | 26 TEST_F(SearchIPCRouterPolicyTest, ProcessVoiceSearchSupportMsg) { |
| 27 NavigateAndCommit(GURL("chrome-search://foo/bar")); | 27 NavigateAndCommit(GURL("chrome-search://foo/bar")); |
| 28 SearchTabHelper* search_tab_helper = | 28 SearchTabHelper* search_tab_helper = |
| 29 SearchTabHelper::FromWebContents(web_contents()); | 29 SearchTabHelper::FromWebContents(web_contents()); |
| 30 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); | 30 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
| 31 ASSERT_TRUE(search_tab_helper->ipc_router().policy()-> | 31 EXPECT_TRUE(search_tab_helper->ipc_router().policy()-> |
| 32 ShouldProcessSetVoiceSearchSupport()); | 32 ShouldProcessSetVoiceSearchSupport()); |
| 33 } | 33 } |
| 34 | 34 |
| 35 TEST_F(SearchIPCRouterPolicyTest, SendSetDisplayInstantResults) { | 35 TEST_F(SearchIPCRouterPolicyTest, SendSetDisplayInstantResults) { |
| 36 NavigateAndCommit(GURL("chrome-search://foo/bar")); | 36 NavigateAndCommit(GURL("chrome-search://foo/bar")); |
| 37 SearchTabHelper* search_tab_helper = | 37 SearchTabHelper* search_tab_helper = |
| 38 SearchTabHelper::FromWebContents(web_contents()); | 38 SearchTabHelper::FromWebContents(web_contents()); |
| 39 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); | 39 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
| 40 ASSERT_TRUE(search_tab_helper->ipc_router().policy()-> | 40 EXPECT_TRUE(search_tab_helper->ipc_router().policy()-> |
| 41 ShouldSendSetDisplayInstantResults()); | 41 ShouldSendSetDisplayInstantResults()); |
| 42 } | 42 } |
| 43 | 43 |
| 44 TEST_F(SearchIPCRouterPolicyTest, | 44 TEST_F(SearchIPCRouterPolicyTest, SendSetSuggestionToPrefetch) { |
| 45 DoNotSetDisplayInstantResultsForIncognitoPage) { | |
| 46 NavigateAndCommit(GURL("chrome-search://foo/bar")); | 45 NavigateAndCommit(GURL("chrome-search://foo/bar")); |
| 47 SearchTabHelper* search_tab_helper = | 46 SearchTabHelper* search_tab_helper = |
| 48 SearchTabHelper::FromWebContents(web_contents()); | 47 SearchTabHelper::FromWebContents(web_contents()); |
| 48 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
| 49 EXPECT_TRUE(search_tab_helper->ipc_router().policy()-> |
| 50 ShouldSendSetSuggestionToPrefetch()); |
| 51 } |
| 52 |
| 53 TEST_F(SearchIPCRouterPolicyTest, |
| 54 DoNotSendSetMessagesForIncognitoPage) { |
| 55 NavigateAndCommit(GURL("chrome-search://foo/bar")); |
| 56 SearchTabHelper* search_tab_helper = |
| 57 SearchTabHelper::FromWebContents(web_contents()); |
| 49 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); | 58 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
| 50 SearchIPCRouterPolicyImpl* policy = | 59 SearchIPCRouterPolicyImpl* policy = |
| 51 static_cast<SearchIPCRouterPolicyImpl*>( | 60 static_cast<SearchIPCRouterPolicyImpl*>( |
| 52 search_tab_helper->ipc_router().policy()); | 61 search_tab_helper->ipc_router().policy()); |
| 53 policy->set_is_incognito(true); | 62 policy->set_is_incognito(true); |
| 54 ASSERT_FALSE(search_tab_helper->ipc_router().policy()-> | 63 |
| 64 EXPECT_FALSE(search_tab_helper->ipc_router().policy()-> |
| 65 ShouldSendSetSuggestionToPrefetch()); |
| 66 EXPECT_FALSE(search_tab_helper->ipc_router().policy()-> |
| 55 ShouldSendSetDisplayInstantResults()); | 67 ShouldSendSetDisplayInstantResults()); |
| 56 } | 68 } |
| 57 | 69 |
| 58 TEST_F(SearchIPCRouterPolicyTest, SendMostVisitedItems) { | 70 TEST_F(SearchIPCRouterPolicyTest, SendMostVisitedItems) { |
| 59 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); | 71 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); |
| 60 SearchTabHelper* search_tab_helper = | 72 SearchTabHelper* search_tab_helper = |
| 61 SearchTabHelper::FromWebContents(web_contents()); | 73 SearchTabHelper::FromWebContents(web_contents()); |
| 62 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); | 74 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
| 63 ASSERT_TRUE(search_tab_helper->ipc_router().policy()-> | 75 EXPECT_TRUE(search_tab_helper->ipc_router().policy()-> |
| 64 ShouldSendMostVisitedItems()); | 76 ShouldSendMostVisitedItems()); |
| 65 } | 77 } |
| 66 | 78 |
| 67 TEST_F(SearchIPCRouterPolicyTest, DoNotSendMostVisitedItems) { | 79 TEST_F(SearchIPCRouterPolicyTest, DoNotSendMostVisitedItems) { |
| 68 // Send most visited items only if the current tab is an Instant NTP. | 80 // Send most visited items only if the current tab is an Instant NTP. |
| 69 NavigateAndCommit(GURL("chrome-search://foo/bar")); | 81 NavigateAndCommit(GURL("chrome-search://foo/bar")); |
| 70 SearchTabHelper* search_tab_helper = | 82 SearchTabHelper* search_tab_helper = |
| 71 SearchTabHelper::FromWebContents(web_contents()); | 83 SearchTabHelper::FromWebContents(web_contents()); |
| 72 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); | 84 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
| 73 ASSERT_FALSE(search_tab_helper->ipc_router().policy()-> | 85 EXPECT_FALSE(search_tab_helper->ipc_router().policy()-> |
| 74 ShouldSendMostVisitedItems()); | 86 ShouldSendMostVisitedItems()); |
| 75 } | 87 } |
| 76 | 88 |
| 77 TEST_F(SearchIPCRouterPolicyTest, DoNotSendMostVisitedItemsForIncognitoPage) { | 89 TEST_F(SearchIPCRouterPolicyTest, DoNotSendMostVisitedItemsForIncognitoPage) { |
| 78 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); | 90 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); |
| 79 SearchTabHelper* search_tab_helper = | 91 SearchTabHelper* search_tab_helper = |
| 80 SearchTabHelper::FromWebContents(web_contents()); | 92 SearchTabHelper::FromWebContents(web_contents()); |
| 81 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); | 93 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
| 82 SearchIPCRouterPolicyImpl* policy = | 94 SearchIPCRouterPolicyImpl* policy = |
| 83 static_cast<SearchIPCRouterPolicyImpl*>( | 95 static_cast<SearchIPCRouterPolicyImpl*>( |
| 84 search_tab_helper->ipc_router().policy()); | 96 search_tab_helper->ipc_router().policy()); |
| 85 policy->set_is_incognito(true); | 97 policy->set_is_incognito(true); |
| 86 ASSERT_FALSE(search_tab_helper->ipc_router().policy()-> | 98 EXPECT_FALSE(search_tab_helper->ipc_router().policy()-> |
| 87 ShouldSendMostVisitedItems()); | 99 ShouldSendMostVisitedItems()); |
| 88 } | 100 } |
| 89 | 101 |
| 90 TEST_F(SearchIPCRouterPolicyTest, SendThemeBackgroundInfo) { | 102 TEST_F(SearchIPCRouterPolicyTest, SendThemeBackgroundInfo) { |
| 91 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); | 103 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); |
| 92 SearchTabHelper* search_tab_helper = | 104 SearchTabHelper* search_tab_helper = |
| 93 SearchTabHelper::FromWebContents(web_contents()); | 105 SearchTabHelper::FromWebContents(web_contents()); |
| 94 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); | 106 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
| 95 ASSERT_TRUE(search_tab_helper->ipc_router().policy()-> | 107 EXPECT_TRUE(search_tab_helper->ipc_router().policy()-> |
| 96 ShouldSendThemeBackgroundInfo()); | 108 ShouldSendThemeBackgroundInfo()); |
| 97 } | 109 } |
| 98 | 110 |
| 99 TEST_F(SearchIPCRouterPolicyTest, DoNotSendThemeBackgroundInfo) { | 111 TEST_F(SearchIPCRouterPolicyTest, DoNotSendThemeBackgroundInfo) { |
| 100 // Send theme background information only if the current tab is an | 112 // Send theme background information only if the current tab is an |
| 101 // Instant NTP. | 113 // Instant NTP. |
| 102 NavigateAndCommit(GURL("chrome-search://foo/bar")); | 114 NavigateAndCommit(GURL("chrome-search://foo/bar")); |
| 103 SearchTabHelper* search_tab_helper = | 115 SearchTabHelper* search_tab_helper = |
| 104 SearchTabHelper::FromWebContents(web_contents()); | 116 SearchTabHelper::FromWebContents(web_contents()); |
| 105 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); | 117 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
| 106 ASSERT_FALSE(search_tab_helper->ipc_router().policy()-> | 118 EXPECT_FALSE(search_tab_helper->ipc_router().policy()-> |
| 107 ShouldSendThemeBackgroundInfo()); | 119 ShouldSendThemeBackgroundInfo()); |
| 108 } | 120 } |
| 109 | 121 |
| 110 TEST_F(SearchIPCRouterPolicyTest, | 122 TEST_F(SearchIPCRouterPolicyTest, |
| 111 DoNotSendThemeBackgroundInfoForIncognitoPage) { | 123 DoNotSendThemeBackgroundInfoForIncognitoPage) { |
| 112 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); | 124 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); |
| 113 SearchTabHelper* search_tab_helper = | 125 SearchTabHelper* search_tab_helper = |
| 114 SearchTabHelper::FromWebContents(web_contents()); | 126 SearchTabHelper::FromWebContents(web_contents()); |
| 115 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); | 127 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
| 116 SearchIPCRouterPolicyImpl* policy = | 128 SearchIPCRouterPolicyImpl* policy = |
| 117 static_cast<SearchIPCRouterPolicyImpl*>( | 129 static_cast<SearchIPCRouterPolicyImpl*>( |
| 118 search_tab_helper->ipc_router().policy()); | 130 search_tab_helper->ipc_router().policy()); |
| 119 policy->set_is_incognito(true); | 131 policy->set_is_incognito(true); |
| 120 ASSERT_FALSE(search_tab_helper->ipc_router().policy()-> | 132 EXPECT_FALSE(search_tab_helper->ipc_router().policy()-> |
| 121 ShouldSendThemeBackgroundInfo()); | 133 ShouldSendThemeBackgroundInfo()); |
| 122 } | 134 } |
| OLD | NEW |