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

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

Issue 410533002: Merge 278958 "Discard ChromeViewHostMsg_SearchBox* IPCs if they ..." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1985/src
Patch Set: Created 6 years, 5 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
« no previous file with comments | « chrome/browser/ui/search/search_ipc_router_policy_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
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());
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 void OnMessageReceived(const IPC::Message& message) { 182 void OnMessageReceived(const IPC::Message& message) {
183 GetSearchIPCRouter().OnMessageReceived(message); 183 bool should_handle_message =
184 chrome::IsRenderedInInstantProcess(web_contents(), profile());
185 bool handled = GetSearchIPCRouter().OnMessageReceived(message);
186 ASSERT_EQ(should_handle_message, handled);
184 } 187 }
185 188
186 bool IsActiveTab(content::WebContents* contents) { 189 bool IsActiveTab(content::WebContents* contents) {
187 return GetSearchTabHelper(contents)->ipc_router().is_active_tab_; 190 return GetSearchTabHelper(contents)->ipc_router().is_active_tab_;
188 } 191 }
189 192
190 private: 193 private:
191 MockSearchIPCRouterDelegate delegate_; 194 MockSearchIPCRouterDelegate delegate_;
192 base::FieldTrialList field_trial_list_; 195 base::FieldTrialList field_trial_list_;
193 }; 196 };
194 197
198 TEST_F(SearchIPCRouterTest, IgnoreMessagesFromNonInstantRenderers) {
199 NavigateAndCommitActiveTab(GURL("file://foo/bar"));
200 SetupMockDelegateAndPolicy();
201 GURL destination_url("www.foo.com");
202 EXPECT_CALL(*mock_delegate(), NavigateToURL(destination_url, CURRENT_TAB,
203 true)).Times(0);
204 content::WebContents* contents = web_contents();
205 bool is_active_tab = IsActiveTab(contents);
206 EXPECT_TRUE(is_active_tab);
207
208 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
209 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(0);
210
211 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_SearchBoxNavigate(
212 contents->GetRoutingID(),
213 contents->GetController().GetVisibleEntry()->GetPageID(),
214 destination_url, CURRENT_TAB, true));
215 OnMessageReceived(*message);
216 }
217
195 TEST_F(SearchIPCRouterTest, ProcessVoiceSearchSupportMsg) { 218 TEST_F(SearchIPCRouterTest, ProcessVoiceSearchSupportMsg) {
196 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 219 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
197 SetupMockDelegateAndPolicy(); 220 SetupMockDelegateAndPolicy();
198 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 221 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
199 EXPECT_CALL(*mock_delegate(), OnSetVoiceSearchSupport(true)).Times(1); 222 EXPECT_CALL(*mock_delegate(), OnSetVoiceSearchSupport(true)).Times(1);
200 EXPECT_CALL(*(policy), ShouldProcessSetVoiceSearchSupport()).Times(1) 223 EXPECT_CALL(*(policy), ShouldProcessSetVoiceSearchSupport()).Times(1)
201 .WillOnce(testing::Return(true)); 224 .WillOnce(testing::Return(true));
202 225
203 content::WebContents* contents = web_contents(); 226 content::WebContents* contents = web_contents();
204 scoped_ptr<IPC::Message> message( 227 scoped_ptr<IPC::Message> message(
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 EXPECT_FALSE(IsActiveTab(contents)); 301 EXPECT_FALSE(IsActiveTab(contents));
279 302
280 // Activate the first tab. 303 // Activate the first tab.
281 browser()->tab_strip_model()->ActivateTabAt(1, false); 304 browser()->tab_strip_model()->ActivateTabAt(1, false);
282 EXPECT_EQ(browser()->tab_strip_model()->active_index(), 305 EXPECT_EQ(browser()->tab_strip_model()->active_index(),
283 browser()->tab_strip_model()->GetIndexOfWebContents(contents)); 306 browser()->tab_strip_model()->GetIndexOfWebContents(contents));
284 EXPECT_TRUE(IsActiveTab(contents)); 307 EXPECT_TRUE(IsActiveTab(contents));
285 } 308 }
286 309
287 TEST_F(SearchIPCRouterTest, ProcessNavigateToURLMsg) { 310 TEST_F(SearchIPCRouterTest, ProcessNavigateToURLMsg) {
288 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 311 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
289 SetupMockDelegateAndPolicy(); 312 SetupMockDelegateAndPolicy();
290 GURL destination_url("www.foo.com"); 313 GURL destination_url("www.foo.com");
291 EXPECT_CALL(*mock_delegate(), NavigateToURL(destination_url, CURRENT_TAB, 314 EXPECT_CALL(*mock_delegate(), NavigateToURL(destination_url, CURRENT_TAB,
292 true)).Times(1); 315 true)).Times(1);
293 content::WebContents* contents = web_contents(); 316 content::WebContents* contents = web_contents();
294 bool is_active_tab = IsActiveTab(contents); 317 bool is_active_tab = IsActiveTab(contents);
295 EXPECT_TRUE(is_active_tab); 318 EXPECT_TRUE(is_active_tab);
296 319
297 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 320 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
298 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(1) 321 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(1)
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 943 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
921 SetupMockDelegateAndPolicy(); 944 SetupMockDelegateAndPolicy();
922 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 945 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
923 EXPECT_CALL(*policy, ShouldSendToggleVoiceSearch()).Times(1) 946 EXPECT_CALL(*policy, ShouldSendToggleVoiceSearch()).Times(1)
924 .WillOnce(testing::Return(false)); 947 .WillOnce(testing::Return(false));
925 948
926 process()->sink().ClearMessages(); 949 process()->sink().ClearMessages();
927 GetSearchIPCRouter().ToggleVoiceSearch(); 950 GetSearchIPCRouter().ToggleVoiceSearch();
928 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxToggleVoiceSearch::ID)); 951 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxToggleVoiceSearch::ID));
929 } 952 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/search_ipc_router_policy_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698