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

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

Issue 17303003: InstantExtended: hook up InstantTab in incognito. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile errors. Created 7 years, 6 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/instant_page.cc ('k') | chrome/browser/ui/search/instant_tab.h » ('j') | 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/instant_page.h" 5 #include "chrome/browser/ui/search/instant_page.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 WindowOpenDisposition disposition, 55 WindowOpenDisposition disposition,
56 bool is_search_type)); 56 bool is_search_type));
57 MOCK_METHOD1(DeleteMostVisitedItem, void(const GURL& url)); 57 MOCK_METHOD1(DeleteMostVisitedItem, void(const GURL& url));
58 MOCK_METHOD1(UndoMostVisitedDeletion, void(const GURL& url)); 58 MOCK_METHOD1(UndoMostVisitedDeletion, void(const GURL& url));
59 MOCK_METHOD0(UndoAllMostVisitedDeletions, void()); 59 MOCK_METHOD0(UndoAllMostVisitedDeletions, void());
60 MOCK_METHOD1(InstantPageLoadFailed, void(content::WebContents* contents)); 60 MOCK_METHOD1(InstantPageLoadFailed, void(content::WebContents* contents));
61 }; 61 };
62 62
63 class FakePage : public InstantPage { 63 class FakePage : public InstantPage {
64 public: 64 public:
65 FakePage(Delegate* delegate, const std::string& instant_url); 65 FakePage(Delegate* delegate, const std::string& instant_url,
66 bool is_incognito);
66 virtual ~FakePage(); 67 virtual ~FakePage();
67 68
68 // InstantPage overrride. 69 // InstantPage overrride.
69 virtual bool ShouldProcessDeleteMostVisitedItem() OVERRIDE; 70 virtual bool ShouldProcessDeleteMostVisitedItem() OVERRIDE;
70 virtual bool ShouldProcessUndoMostVisitedDeletion() OVERRIDE; 71 virtual bool ShouldProcessUndoMostVisitedDeletion() OVERRIDE;
71 virtual bool ShouldProcessUndoAllMostVisitedDeletions() OVERRIDE; 72 virtual bool ShouldProcessUndoAllMostVisitedDeletions() OVERRIDE;
72 73
73 void set_should_handle_messages(bool should_handle_messages); 74 void set_should_handle_messages(bool should_handle_messages);
74 75
75 using InstantPage::SetContents; 76 using InstantPage::SetContents;
76 77
77 private: 78 private:
78 // Initialized to true to handle the messages sent by the renderer. 79 // Initialized to true to handle the messages sent by the renderer.
79 bool should_handle_messages_; 80 bool should_handle_messages_;
80 81
81 DISALLOW_COPY_AND_ASSIGN(FakePage); 82 DISALLOW_COPY_AND_ASSIGN(FakePage);
82 }; 83 };
83 84
84 FakePage::FakePage(Delegate* delegate, const std::string& instant_url) 85 FakePage::FakePage(Delegate* delegate, const std::string& instant_url,
85 : InstantPage(delegate, instant_url), 86 bool is_incognito)
87 : InstantPage(delegate, instant_url, is_incognito),
86 should_handle_messages_(true) { 88 should_handle_messages_(true) {
87 } 89 }
88 90
89 FakePage::~FakePage() { 91 FakePage::~FakePage() {
90 } 92 }
91 93
92 void FakePage::set_should_handle_messages(bool should_handle_messages) { 94 void FakePage::set_should_handle_messages(bool should_handle_messages) {
93 should_handle_messages_ = should_handle_messages; 95 should_handle_messages_ = should_handle_messages;
94 } 96 }
95 97
96 bool FakePage::ShouldProcessDeleteMostVisitedItem() { 98 bool FakePage::ShouldProcessDeleteMostVisitedItem() {
97 return should_handle_messages_; 99 return should_handle_messages_;
98 } 100 }
99 101
100 bool FakePage::ShouldProcessUndoMostVisitedDeletion() { 102 bool FakePage::ShouldProcessUndoMostVisitedDeletion() {
101 return should_handle_messages_; 103 return should_handle_messages_;
102 } 104 }
103 105
104 bool FakePage::ShouldProcessUndoAllMostVisitedDeletions() { 106 bool FakePage::ShouldProcessUndoAllMostVisitedDeletions() {
105 return should_handle_messages_; 107 return should_handle_messages_;
106 } 108 }
107 109
108 } // namespace 110 } // namespace
109 111
110 class InstantPageTest : public ChromeRenderViewHostTestHarness { 112 class InstantPageTest : public ChromeRenderViewHostTestHarness {
111 public: 113 public:
112 virtual void SetUp() OVERRIDE; 114 virtual void SetUp() OVERRIDE;
113 115
116 bool MessageWasSent(uint32 id) {
117 return process()->sink().GetFirstMessageMatching(id) != NULL;
118 }
119
114 scoped_ptr<FakePage> page; 120 scoped_ptr<FakePage> page;
115 FakePageDelegate delegate; 121 FakePageDelegate delegate;
116 }; 122 };
117 123
118 void InstantPageTest::SetUp() { 124 void InstantPageTest::SetUp() {
119 CommandLine::ForCurrentProcess()->AppendSwitch( 125 CommandLine::ForCurrentProcess()->AppendSwitch(
120 switches::kEnableInstantExtendedAPI); 126 switches::kEnableInstantExtendedAPI);
121 ChromeRenderViewHostTestHarness::SetUp(); 127 ChromeRenderViewHostTestHarness::SetUp();
122 SearchTabHelper::CreateForWebContents(web_contents()); 128 SearchTabHelper::CreateForWebContents(web_contents());
123 } 129 }
124 130
125 TEST_F(InstantPageTest, IsLocal) { 131 TEST_F(InstantPageTest, IsLocal) {
126 page.reset(new FakePage(&delegate, "")); 132 page.reset(new FakePage(&delegate, "", false));
127 EXPECT_FALSE(page->supports_instant()); 133 EXPECT_FALSE(page->supports_instant());
128 EXPECT_FALSE(page->IsLocal()); 134 EXPECT_FALSE(page->IsLocal());
129 page->SetContents(web_contents()); 135 page->SetContents(web_contents());
130 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); 136 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
131 EXPECT_TRUE(page->IsLocal()); 137 EXPECT_TRUE(page->IsLocal());
132 NavigateAndCommit(GURL("http://example.com")); 138 NavigateAndCommit(GURL("http://example.com"));
133 EXPECT_FALSE(page->IsLocal()); 139 EXPECT_FALSE(page->IsLocal());
134 NavigateAndCommit(GURL(chrome::kChromeSearchLocalGoogleNtpUrl)); 140 NavigateAndCommit(GURL(chrome::kChromeSearchLocalGoogleNtpUrl));
135 EXPECT_TRUE(page->IsLocal()); 141 EXPECT_TRUE(page->IsLocal());
136 } 142 }
137 143
138 TEST_F(InstantPageTest, DetermineIfPageSupportsInstant_Local) { 144 TEST_F(InstantPageTest, DetermineIfPageSupportsInstant_Local) {
139 page.reset(new FakePage(&delegate, "")); 145 page.reset(new FakePage(&delegate, "", false));
140 EXPECT_FALSE(page->supports_instant()); 146 EXPECT_FALSE(page->supports_instant());
141 page->SetContents(web_contents()); 147 page->SetContents(web_contents());
142 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); 148 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
143 EXPECT_TRUE(page->IsLocal()); 149 EXPECT_TRUE(page->IsLocal());
144 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true)) 150 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true))
145 .Times(1); 151 .Times(1);
146 SearchTabHelper::FromWebContents(web_contents())-> 152 SearchTabHelper::FromWebContents(web_contents())->
147 DetermineIfPageSupportsInstant(); 153 DetermineIfPageSupportsInstant();
148 EXPECT_TRUE(page->supports_instant()); 154 EXPECT_TRUE(page->supports_instant());
149 } 155 }
150 156
151 TEST_F(InstantPageTest, DetermineIfPageSupportsInstant_NonLocal) { 157 TEST_F(InstantPageTest, DetermineIfPageSupportsInstant_NonLocal) {
152 page.reset(new FakePage(&delegate, "")); 158 page.reset(new FakePage(&delegate, "", false));
153 EXPECT_FALSE(page->supports_instant()); 159 EXPECT_FALSE(page->supports_instant());
154 page->SetContents(web_contents()); 160 page->SetContents(web_contents());
155 NavigateAndCommit(GURL("chrome-search://foo/bar")); 161 NavigateAndCommit(GURL("chrome-search://foo/bar"));
156 EXPECT_FALSE(page->IsLocal()); 162 EXPECT_FALSE(page->IsLocal());
157 process()->sink().ClearMessages(); 163 process()->sink().ClearMessages();
158 SearchTabHelper::FromWebContents(web_contents())-> 164 SearchTabHelper::FromWebContents(web_contents())->
159 DetermineIfPageSupportsInstant(); 165 DetermineIfPageSupportsInstant();
160 const IPC::Message* message = process()->sink().GetFirstMessageMatching( 166 const IPC::Message* message = process()->sink().GetFirstMessageMatching(
161 ChromeViewMsg_DetermineIfPageSupportsInstant::ID); 167 ChromeViewMsg_DetermineIfPageSupportsInstant::ID);
162 ASSERT_TRUE(message != NULL); 168 ASSERT_TRUE(message != NULL);
163 EXPECT_EQ(web_contents()->GetRoutingID(), message->routing_id()); 169 EXPECT_EQ(web_contents()->GetRoutingID(), message->routing_id());
164 } 170 }
165 171
166 TEST_F(InstantPageTest, DispatchRequestToDeleteMostVisitedItem) { 172 TEST_F(InstantPageTest, DispatchRequestToDeleteMostVisitedItem) {
167 page.reset(new FakePage(&delegate, "")); 173 page.reset(new FakePage(&delegate, "", false));
168 page->SetContents(web_contents()); 174 page->SetContents(web_contents());
169 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); 175 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
170 GURL item_url("www.foo.com"); 176 GURL item_url("www.foo.com");
171 int page_id = web_contents()->GetController().GetActiveEntry()->GetPageID(); 177 int page_id = web_contents()->GetController().GetActiveEntry()->GetPageID();
172 EXPECT_CALL(delegate, DeleteMostVisitedItem(item_url)).Times(1); 178 EXPECT_CALL(delegate, DeleteMostVisitedItem(item_url)).Times(1);
173 EXPECT_TRUE(page->OnMessageReceived( 179 EXPECT_TRUE(page->OnMessageReceived(
174 ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(rvh()->GetRoutingID(), 180 ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(rvh()->GetRoutingID(),
175 page_id, item_url))); 181 page_id, item_url)));
176 } 182 }
177 183
178 TEST_F(InstantPageTest, DispatchRequestToUndoMostVisitedDeletion) { 184 TEST_F(InstantPageTest, DispatchRequestToUndoMostVisitedDeletion) {
179 page.reset(new FakePage(&delegate, "")); 185 page.reset(new FakePage(&delegate, "", false));
180 page->SetContents(web_contents()); 186 page->SetContents(web_contents());
181 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); 187 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
182 GURL item_url("www.foo.com"); 188 GURL item_url("www.foo.com");
183 int page_id = web_contents()->GetController().GetActiveEntry()->GetPageID(); 189 int page_id = web_contents()->GetController().GetActiveEntry()->GetPageID();
184 EXPECT_CALL(delegate, UndoMostVisitedDeletion(item_url)).Times(1); 190 EXPECT_CALL(delegate, UndoMostVisitedDeletion(item_url)).Times(1);
185 EXPECT_TRUE(page->OnMessageReceived( 191 EXPECT_TRUE(page->OnMessageReceived(
186 ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(rvh()->GetRoutingID(), 192 ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(rvh()->GetRoutingID(),
187 page_id, item_url))); 193 page_id, item_url)));
188 } 194 }
189 195
190 TEST_F(InstantPageTest, DispatchRequestToUndoAllMostVisitedDeletions) { 196 TEST_F(InstantPageTest, DispatchRequestToUndoAllMostVisitedDeletions) {
191 page.reset(new FakePage(&delegate, "")); 197 page.reset(new FakePage(&delegate, "", false));
192 page->SetContents(web_contents()); 198 page->SetContents(web_contents());
193 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); 199 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
194 int page_id = web_contents()->GetController().GetActiveEntry()->GetPageID(); 200 int page_id = web_contents()->GetController().GetActiveEntry()->GetPageID();
195 EXPECT_CALL(delegate, UndoAllMostVisitedDeletions()).Times(1); 201 EXPECT_CALL(delegate, UndoAllMostVisitedDeletions()).Times(1);
196 EXPECT_TRUE(page->OnMessageReceived( 202 EXPECT_TRUE(page->OnMessageReceived(
197 ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions( 203 ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions(
198 rvh()->GetRoutingID(), page_id))); 204 rvh()->GetRoutingID(), page_id)));
199 } 205 }
200 206
207 TEST_F(InstantPageTest, IgnoreMessageReceivedFromIncognitoPage) {
208 page.reset(new FakePage(&delegate, "", true));
209 page->SetContents(web_contents());
210 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
211 GURL item_url("www.foo.com");
212 int page_id = web_contents()->GetController().GetActiveEntry()->GetPageID();
213
214 EXPECT_CALL(delegate, DeleteMostVisitedItem(item_url)).Times(0);
215 EXPECT_FALSE(page->OnMessageReceived(
216 ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(rvh()->GetRoutingID(),
217 page_id,
218 item_url)));
219
220 EXPECT_CALL(delegate, UndoMostVisitedDeletion(item_url)).Times(0);
221 EXPECT_FALSE(page->OnMessageReceived(
222 ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(rvh()->GetRoutingID(),
223 page_id,
224 item_url)));
225
226 EXPECT_CALL(delegate, UndoAllMostVisitedDeletions()).Times(0);
227 EXPECT_FALSE(page->OnMessageReceived(
228 ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions(
229 rvh()->GetRoutingID(), page_id)));
230 }
231
201 TEST_F(InstantPageTest, IgnoreMessageIfThePageIsNotActive) { 232 TEST_F(InstantPageTest, IgnoreMessageIfThePageIsNotActive) {
202 page.reset(new FakePage(&delegate, "")); 233 page.reset(new FakePage(&delegate, "", false));
203 page->SetContents(web_contents()); 234 page->SetContents(web_contents());
204 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); 235 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
205 GURL item_url("www.foo.com"); 236 GURL item_url("www.foo.com");
206 int inactive_page_id = 1999; 237 int inactive_page_id = 1999;
207 238
208 EXPECT_CALL(delegate, DeleteMostVisitedItem(item_url)).Times(0); 239 EXPECT_CALL(delegate, DeleteMostVisitedItem(item_url)).Times(0);
209 EXPECT_TRUE(page->OnMessageReceived( 240 EXPECT_TRUE(page->OnMessageReceived(
210 ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(rvh()->GetRoutingID(), 241 ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(rvh()->GetRoutingID(),
211 inactive_page_id, 242 inactive_page_id,
212 item_url))); 243 item_url)));
213 244
214 EXPECT_CALL(delegate, UndoMostVisitedDeletion(item_url)).Times(0); 245 EXPECT_CALL(delegate, UndoMostVisitedDeletion(item_url)).Times(0);
215 EXPECT_TRUE(page->OnMessageReceived( 246 EXPECT_TRUE(page->OnMessageReceived(
216 ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(rvh()->GetRoutingID(), 247 ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(rvh()->GetRoutingID(),
217 inactive_page_id, 248 inactive_page_id,
218 item_url))); 249 item_url)));
219 250
220 EXPECT_CALL(delegate, UndoAllMostVisitedDeletions()).Times(0); 251 EXPECT_CALL(delegate, UndoAllMostVisitedDeletions()).Times(0);
221 EXPECT_TRUE(page->OnMessageReceived( 252 EXPECT_TRUE(page->OnMessageReceived(
222 ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions( 253 ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions(
223 rvh()->GetRoutingID(), inactive_page_id))); 254 rvh()->GetRoutingID(), inactive_page_id)));
224 } 255 }
225 256
226 TEST_F(InstantPageTest, IgnoreMessageReceivedFromThePage) { 257 TEST_F(InstantPageTest, IgnoreMessageReceivedFromThePage) {
227 page.reset(new FakePage(&delegate, "")); 258 page.reset(new FakePage(&delegate, "", false));
228 page->SetContents(web_contents()); 259 page->SetContents(web_contents());
229 260
230 // Ignore the messages received from the page. 261 // Ignore the messages received from the page.
231 page->set_should_handle_messages(false); 262 page->set_should_handle_messages(false);
232 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); 263 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
233 GURL item_url("www.foo.com"); 264 GURL item_url("www.foo.com");
234 int page_id = web_contents()->GetController().GetActiveEntry()->GetPageID(); 265 int page_id = web_contents()->GetController().GetActiveEntry()->GetPageID();
235 266
236 EXPECT_CALL(delegate, DeleteMostVisitedItem(item_url)).Times(0); 267 EXPECT_CALL(delegate, DeleteMostVisitedItem(item_url)).Times(0);
237 EXPECT_TRUE(page->OnMessageReceived( 268 EXPECT_TRUE(page->OnMessageReceived(
238 ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(rvh()->GetRoutingID(), 269 ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(rvh()->GetRoutingID(),
239 page_id, item_url))); 270 page_id, item_url)));
240 271
241 EXPECT_CALL(delegate, UndoMostVisitedDeletion(item_url)).Times(0); 272 EXPECT_CALL(delegate, UndoMostVisitedDeletion(item_url)).Times(0);
242 EXPECT_TRUE(page->OnMessageReceived( 273 EXPECT_TRUE(page->OnMessageReceived(
243 ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(rvh()->GetRoutingID(), 274 ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(rvh()->GetRoutingID(),
244 page_id, item_url))); 275 page_id, item_url)));
245 276
246 EXPECT_CALL(delegate, UndoAllMostVisitedDeletions()).Times(0); 277 EXPECT_CALL(delegate, UndoAllMostVisitedDeletions()).Times(0);
247 EXPECT_TRUE(page->OnMessageReceived( 278 EXPECT_TRUE(page->OnMessageReceived(
248 ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions( 279 ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions(
249 rvh()->GetRoutingID(), page_id))); 280 rvh()->GetRoutingID(), page_id)));
250 } 281 }
251 282
252 TEST_F(InstantPageTest, PageURLDoesntBelongToInstantRenderer) { 283 TEST_F(InstantPageTest, PageURLDoesntBelongToInstantRenderer) {
253 page.reset(new FakePage(&delegate, "")); 284 page.reset(new FakePage(&delegate, "", false));
254 EXPECT_FALSE(page->supports_instant()); 285 EXPECT_FALSE(page->supports_instant());
255 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); 286 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
256 page->SetContents(web_contents()); 287 page->SetContents(web_contents());
257 288
258 // Navigate to a page URL that doesn't belong to Instant renderer. 289 // Navigate to a page URL that doesn't belong to Instant renderer.
259 // SearchTabHelper::DeterminerIfPageSupportsInstant() should return 290 // SearchTabHelper::DeterminerIfPageSupportsInstant() should return
260 // immediately without dispatching any message to the renderer. 291 // immediately without dispatching any message to the renderer.
261 NavigateAndCommit(GURL("http://www.example.com")); 292 NavigateAndCommit(GURL("http://www.example.com"));
262 EXPECT_FALSE(page->IsLocal()); 293 EXPECT_FALSE(page->IsLocal());
263 process()->sink().ClearMessages(); 294 process()->sink().ClearMessages();
264 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), false)) 295 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), false))
265 .Times(1); 296 .Times(1);
266 297
267 SearchTabHelper::FromWebContents(web_contents())-> 298 SearchTabHelper::FromWebContents(web_contents())->
268 DetermineIfPageSupportsInstant(); 299 DetermineIfPageSupportsInstant();
269 const IPC::Message* message = process()->sink().GetFirstMessageMatching( 300 const IPC::Message* message = process()->sink().GetFirstMessageMatching(
270 ChromeViewMsg_DetermineIfPageSupportsInstant::ID); 301 ChromeViewMsg_DetermineIfPageSupportsInstant::ID);
271 ASSERT_TRUE(message == NULL); 302 ASSERT_TRUE(message == NULL);
272 EXPECT_FALSE(page->supports_instant()); 303 EXPECT_FALSE(page->supports_instant());
273 } 304 }
274 305
275 // Test to verify that ChromeViewMsg_DetermineIfPageSupportsInstant message 306 // Test to verify that ChromeViewMsg_DetermineIfPageSupportsInstant message
276 // reply handler updates the instant support state in InstantPage. 307 // reply handler updates the instant support state in InstantPage.
277 TEST_F(InstantPageTest, PageSupportsInstant) { 308 TEST_F(InstantPageTest, PageSupportsInstant) {
278 page.reset(new FakePage(&delegate, "")); 309 page.reset(new FakePage(&delegate, "", false));
279 EXPECT_FALSE(page->supports_instant()); 310 EXPECT_FALSE(page->supports_instant());
280 page->SetContents(web_contents()); 311 page->SetContents(web_contents());
281 NavigateAndCommit(GURL("chrome-search://foo/bar")); 312 NavigateAndCommit(GURL("chrome-search://foo/bar"));
282 process()->sink().ClearMessages(); 313 process()->sink().ClearMessages();
283 SearchTabHelper::FromWebContents(web_contents())-> 314 SearchTabHelper::FromWebContents(web_contents())->
284 DetermineIfPageSupportsInstant(); 315 DetermineIfPageSupportsInstant();
285 const IPC::Message* message = process()->sink().GetFirstMessageMatching( 316 const IPC::Message* message = process()->sink().GetFirstMessageMatching(
286 ChromeViewMsg_DetermineIfPageSupportsInstant::ID); 317 ChromeViewMsg_DetermineIfPageSupportsInstant::ID);
287 ASSERT_TRUE(message != NULL); 318 ASSERT_TRUE(message != NULL);
288 EXPECT_EQ(web_contents()->GetRoutingID(), message->routing_id()); 319 EXPECT_EQ(web_contents()->GetRoutingID(), message->routing_id());
289 320
290 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true)) 321 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true))
291 .Times(1); 322 .Times(1);
292 323
293 // Assume the page supports instant. Invoke the message reply handler to make 324 // Assume the page supports instant. Invoke the message reply handler to make
294 // sure the InstantPage is notified about the instant support state. 325 // sure the InstantPage is notified about the instant support state.
295 const content::NavigationEntry* entry = 326 const content::NavigationEntry* entry =
296 web_contents()->GetController().GetActiveEntry(); 327 web_contents()->GetController().GetActiveEntry();
297 EXPECT_TRUE(entry); 328 EXPECT_TRUE(entry);
298 SearchTabHelper::FromWebContents(web_contents())-> 329 SearchTabHelper::FromWebContents(web_contents())->
299 OnInstantSupportDetermined(entry->GetPageID(), true); 330 OnInstantSupportDetermined(entry->GetPageID(), true);
300 EXPECT_TRUE(page->supports_instant()); 331 EXPECT_TRUE(page->supports_instant());
301 } 332 }
333
334 TEST_F(InstantPageTest, AppropriateMessagesSentToIncognitoPages) {
335 page.reset(new FakePage(&delegate, "", true));
336 page->SetContents(web_contents());
337 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
338 process()->sink().ClearMessages();
339
340 // Incognito pages should get these messages.
341 page->sender()->Submit(string16());
342 EXPECT_TRUE(MessageWasSent(ChromeViewMsg_SearchBoxSubmit::ID));
343 page->sender()->SetOmniboxBounds(gfx::Rect());
344 EXPECT_TRUE(MessageWasSent(ChromeViewMsg_SearchBoxMarginChange::ID));
345
346 // Incognito pages should not get any others.
347 page->sender()->Update(string16(), 0, 0, false);
348 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxChange::ID));
349
350 page->sender()->Cancel(string16());
351 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxCancel::ID));
352
353 page->sender()->SetPopupBounds(gfx::Rect());
354 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxPopupResize::ID));
355
356 page->sender()->SetFontInformation(string16(), 0);
357 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxFontInformation::ID));
358
359 page->sender()->SendAutocompleteResults(
360 std::vector<InstantAutocompleteResult>());
361 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxAutocompleteResults::ID));
362
363 page->sender()->UpOrDownKeyPressed(0);
364 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxUpOrDownKeyPressed::ID));
365
366 page->sender()->EscKeyPressed();
367 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxEscKeyPressed::ID));
368
369 page->sender()->CancelSelection(string16(), 0, 0, false);
370 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxCancelSelection::ID));
371
372 page->sender()->SendThemeBackgroundInfo(ThemeBackgroundInfo());
373 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxThemeChanged::ID));
374
375 page->sender()->SetDisplayInstantResults(false);
376 EXPECT_FALSE(MessageWasSent(
377 ChromeViewMsg_SearchBoxSetDisplayInstantResults::ID));
378
379 page->sender()->FocusChanged(
380 OMNIBOX_FOCUS_NONE, OMNIBOX_FOCUS_CHANGE_EXPLICIT);
381 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxFocusChanged::ID));
382
383 page->sender()->SetInputInProgress(false);
384 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxSetInputInProgress::ID));
385
386 page->sender()->SendMostVisitedItems(std::vector<InstantMostVisitedItem>());
387 EXPECT_FALSE(MessageWasSent(
388 ChromeViewMsg_SearchBoxMostVisitedItemsChanged::ID));
389
390 page->sender()->ToggleVoiceSearch();
391 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxToggleVoiceSearch::ID));
392 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/instant_page.cc ('k') | chrome/browser/ui/search/instant_tab.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698