OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
6 #include "content/browser/browser_thread_impl.h" | 6 #include "content/browser/browser_thread_impl.h" |
7 #include "content/browser/mock_content_browser_client.h" | 7 #include "content/browser/mock_content_browser_client.h" |
8 #include "content/browser/renderer_host/test_render_view_host.h" | 8 #include "content/browser/renderer_host/test_render_view_host.h" |
9 #include "content/browser/site_instance_impl.h" | 9 #include "content/browser/site_instance_impl.h" |
10 #include "content/browser/tab_contents/navigation_controller_impl.h" | 10 #include "content/browser/tab_contents/navigation_controller_impl.h" |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 const GURL kDestUrl("http://www.google.com/"); | 262 const GURL kDestUrl("http://www.google.com/"); |
263 | 263 |
264 // Navigate our first tab to the new tab page and then to the destination. | 264 // Navigate our first tab to the new tab page and then to the destination. |
265 NavigateActiveAndCommit(kNtpUrl); | 265 NavigateActiveAndCommit(kNtpUrl); |
266 TestRenderViewHost* ntp_rvh = static_cast<TestRenderViewHost*>( | 266 TestRenderViewHost* ntp_rvh = static_cast<TestRenderViewHost*>( |
267 contents()->GetRenderManagerForTesting()->current_host()); | 267 contents()->GetRenderManagerForTesting()->current_host()); |
268 | 268 |
269 // Send an update title message and make sure it works. | 269 // Send an update title message and make sure it works. |
270 const string16 ntp_title = ASCIIToUTF16("NTP Title"); | 270 const string16 ntp_title = ASCIIToUTF16("NTP Title"); |
271 WebKit::WebTextDirection direction = WebKit::WebTextDirectionLeftToRight; | 271 WebKit::WebTextDirection direction = WebKit::WebTextDirectionLeftToRight; |
272 EXPECT_TRUE(ntp_rvh->TestOnMessageReceived( | 272 EXPECT_TRUE(ntp_rvh->OnMessageReceived( |
273 ViewHostMsg_UpdateTitle(rvh()->GetRoutingID(), 0, ntp_title, direction))); | 273 ViewHostMsg_UpdateTitle(rvh()->GetRoutingID(), 0, ntp_title, direction))); |
274 EXPECT_EQ(ntp_title, contents()->GetTitle()); | 274 EXPECT_EQ(ntp_title, contents()->GetTitle()); |
275 | 275 |
276 // Navigate to a cross-site URL. | 276 // Navigate to a cross-site URL. |
277 contents()->GetController().LoadURL( | 277 contents()->GetController().LoadURL( |
278 kDestUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, | 278 kDestUrl, content::Referrer(), content::PAGE_TRANSITION_LINK, |
279 std::string()); | 279 std::string()); |
280 EXPECT_TRUE(contents()->cross_navigation_pending()); | 280 EXPECT_TRUE(contents()->cross_navigation_pending()); |
281 TestRenderViewHost* dest_rvh = static_cast<TestRenderViewHost*>( | 281 TestRenderViewHost* dest_rvh = static_cast<TestRenderViewHost*>( |
282 contents()->GetRenderManagerForTesting()->pending_render_view_host()); | 282 contents()->GetRenderManagerForTesting()->pending_render_view_host()); |
283 ASSERT_TRUE(dest_rvh); | 283 ASSERT_TRUE(dest_rvh); |
284 EXPECT_NE(ntp_rvh, dest_rvh); | 284 EXPECT_NE(ntp_rvh, dest_rvh); |
285 | 285 |
286 // BeforeUnload finishes. | 286 // BeforeUnload finishes. |
287 ntp_rvh->SendShouldCloseACK(true); | 287 ntp_rvh->SendShouldCloseACK(true); |
288 | 288 |
289 // Assume SwapOutACK times out, so the dest_rvh proceeds and commits. | 289 // Assume SwapOutACK times out, so the dest_rvh proceeds and commits. |
290 dest_rvh->SendNavigate(101, kDestUrl); | 290 dest_rvh->SendNavigate(101, kDestUrl); |
291 | 291 |
292 // The new RVH should be able to update its title. | 292 // The new RVH should be able to update its title. |
293 const string16 dest_title = ASCIIToUTF16("Google"); | 293 const string16 dest_title = ASCIIToUTF16("Google"); |
294 EXPECT_TRUE(dest_rvh->TestOnMessageReceived( | 294 EXPECT_TRUE(dest_rvh->OnMessageReceived( |
295 ViewHostMsg_UpdateTitle(rvh()->GetRoutingID(), 101, dest_title, | 295 ViewHostMsg_UpdateTitle(rvh()->GetRoutingID(), 101, dest_title, |
296 direction))); | 296 direction))); |
297 EXPECT_EQ(dest_title, contents()->GetTitle()); | 297 EXPECT_EQ(dest_title, contents()->GetTitle()); |
298 | 298 |
299 // The old renderer, being slow, now updates the title. It should be filtered | 299 // The old renderer, being slow, now updates the title. It should be filtered |
300 // out and not take effect. | 300 // out and not take effect. |
301 EXPECT_TRUE(ntp_rvh->is_swapped_out()); | 301 EXPECT_TRUE(ntp_rvh->is_swapped_out()); |
302 EXPECT_TRUE(ntp_rvh->TestOnMessageReceived( | 302 EXPECT_TRUE(ntp_rvh->OnMessageReceived( |
303 ViewHostMsg_UpdateTitle(rvh()->GetRoutingID(), 0, ntp_title, direction))); | 303 ViewHostMsg_UpdateTitle(rvh()->GetRoutingID(), 0, ntp_title, direction))); |
304 EXPECT_EQ(dest_title, contents()->GetTitle()); | 304 EXPECT_EQ(dest_title, contents()->GetTitle()); |
305 | 305 |
306 // We cannot filter out synchronous IPC messages, because the renderer would | 306 // We cannot filter out synchronous IPC messages, because the renderer would |
307 // be left waiting for a reply. We pick RunBeforeUnloadConfirm as an example | 307 // be left waiting for a reply. We pick RunBeforeUnloadConfirm as an example |
308 // that can run easily within a unit test, and that needs to receive a reply | 308 // that can run easily within a unit test, and that needs to receive a reply |
309 // without showing an actual dialog. | 309 // without showing an actual dialog. |
310 MockRenderProcessHost* ntp_process_host = | 310 MockRenderProcessHost* ntp_process_host = |
311 static_cast<MockRenderProcessHost*>(ntp_rvh->GetProcess()); | 311 static_cast<MockRenderProcessHost*>(ntp_rvh->GetProcess()); |
312 ntp_process_host->sink().ClearMessages(); | 312 ntp_process_host->sink().ClearMessages(); |
313 const string16 msg = ASCIIToUTF16("Message"); | 313 const string16 msg = ASCIIToUTF16("Message"); |
314 bool result = false; | 314 bool result = false; |
315 string16 unused; | 315 string16 unused; |
316 ViewHostMsg_RunBeforeUnloadConfirm before_unload_msg( | 316 ViewHostMsg_RunBeforeUnloadConfirm before_unload_msg( |
317 rvh()->GetRoutingID(), kNtpUrl, msg, false, &result, &unused); | 317 rvh()->GetRoutingID(), kNtpUrl, msg, false, &result, &unused); |
318 // Enable pumping for check in BrowserMessageFilter::CheckCanDispatchOnUI. | 318 // Enable pumping for check in BrowserMessageFilter::CheckCanDispatchOnUI. |
319 before_unload_msg.EnableMessagePumping(); | 319 before_unload_msg.EnableMessagePumping(); |
320 EXPECT_TRUE(ntp_rvh->TestOnMessageReceived(before_unload_msg)); | 320 EXPECT_TRUE(ntp_rvh->OnMessageReceived(before_unload_msg)); |
321 EXPECT_TRUE(ntp_process_host->sink().GetUniqueMessageMatching(IPC_REPLY_ID)); | 321 EXPECT_TRUE(ntp_process_host->sink().GetUniqueMessageMatching(IPC_REPLY_ID)); |
322 | 322 |
323 // Also test RunJavaScriptMessage. | 323 // Also test RunJavaScriptMessage. |
324 ntp_process_host->sink().ClearMessages(); | 324 ntp_process_host->sink().ClearMessages(); |
325 ViewHostMsg_RunJavaScriptMessage js_msg( | 325 ViewHostMsg_RunJavaScriptMessage js_msg( |
326 rvh()->GetRoutingID(), msg, msg, kNtpUrl, | 326 rvh()->GetRoutingID(), msg, msg, kNtpUrl, |
327 ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM, &result, &unused); | 327 ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM, &result, &unused); |
328 js_msg.EnableMessagePumping(); | 328 js_msg.EnableMessagePumping(); |
329 EXPECT_TRUE(ntp_rvh->TestOnMessageReceived(js_msg)); | 329 EXPECT_TRUE(ntp_rvh->OnMessageReceived(js_msg)); |
330 EXPECT_TRUE(ntp_process_host->sink().GetUniqueMessageMatching(IPC_REPLY_ID)); | 330 EXPECT_TRUE(ntp_process_host->sink().GetUniqueMessageMatching(IPC_REPLY_ID)); |
331 } | 331 } |
332 | 332 |
333 // When there is an error with the specified page, renderer exits view-source | 333 // When there is an error with the specified page, renderer exits view-source |
334 // mode. See WebFrameImpl::DidFail(). We check by this test that | 334 // mode. See WebFrameImpl::DidFail(). We check by this test that |
335 // EnableViewSourceMode message is sent on every navigation regardless | 335 // EnableViewSourceMode message is sent on every navigation regardless |
336 // RenderView is being newly created or reused. | 336 // RenderView is being newly created or reused. |
337 TEST_F(RenderViewHostManagerTest, AlwaysSendEnableViewSourceMode) { | 337 TEST_F(RenderViewHostManagerTest, AlwaysSendEnableViewSourceMode) { |
338 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); | 338 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); |
339 const GURL kNtpUrl(chrome::kTestNewTabURL); | 339 const GURL kNtpUrl(chrome::kTestNewTabURL); |
340 const GURL kUrl("view-source:http://foo"); | 340 const GURL kUrl("view-source:http://foo"); |
341 | 341 |
342 // We have to navigate to some page at first since without this, the first | 342 // We have to navigate to some page at first since without this, the first |
343 // navigation will reuse the SiteInstance created by Init(), and the second | 343 // navigation will reuse the SiteInstance created by Init(), and the second |
344 // one will create a new SiteInstance. Because current_instance and | 344 // one will create a new SiteInstance. Because current_instance and |
345 // new_instance will be different, a new RenderViewHost will be created for | 345 // new_instance will be different, a new RenderViewHost will be created for |
346 // the second navigation. We have to avoid this in order to exercise the | 346 // the second navigation. We have to avoid this in order to exercise the |
347 // target code patch. | 347 // target code patch. |
348 NavigateActiveAndCommit(kNtpUrl); | 348 NavigateActiveAndCommit(kNtpUrl); |
349 | 349 |
350 // Navigate. | 350 // Navigate. |
351 controller().LoadURL( | 351 controller().LoadURL( |
352 kUrl, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 352 kUrl, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
353 // Simulate response from RenderView for FirePageBeforeUnload. | 353 // Simulate response from RenderView for FirePageBeforeUnload. |
354 test_rvh()->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK( | 354 test_rvh()->OnMessageReceived(ViewHostMsg_ShouldClose_ACK( |
355 rvh()->GetRoutingID(), true, base::TimeTicks(), base::TimeTicks())); | 355 rvh()->GetRoutingID(), true, base::TimeTicks(), base::TimeTicks())); |
356 ASSERT_TRUE(pending_rvh()); // New pending RenderViewHost will be created. | 356 ASSERT_TRUE(pending_rvh()); // New pending RenderViewHost will be created. |
357 RenderViewHost* last_rvh = pending_rvh(); | 357 RenderViewHost* last_rvh = pending_rvh(); |
358 int32 new_id = contents()->GetMaxPageIDForSiteInstance( | 358 int32 new_id = contents()->GetMaxPageIDForSiteInstance( |
359 active_rvh()->GetSiteInstance()) + 1; | 359 active_rvh()->GetSiteInstance()) + 1; |
360 pending_test_rvh()->SendNavigate(new_id, kUrl); | 360 pending_test_rvh()->SendNavigate(new_id, kUrl); |
361 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); | 361 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); |
362 ASSERT_TRUE(controller().GetLastCommittedEntry()); | 362 ASSERT_TRUE(controller().GetLastCommittedEntry()); |
363 EXPECT_TRUE(kUrl == controller().GetLastCommittedEntry()->GetURL()); | 363 EXPECT_TRUE(kUrl == controller().GetLastCommittedEntry()->GetURL()); |
364 EXPECT_FALSE(controller().GetPendingEntry()); | 364 EXPECT_FALSE(controller().GetPendingEntry()); |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 | 762 |
763 // We should be able to navigate forward. | 763 // We should be able to navigate forward. |
764 contents()->GetController().GoForward(); | 764 contents()->GetController().GoForward(); |
765 contents()->ProceedWithCrossSiteNavigation(); | 765 contents()->ProceedWithCrossSiteNavigation(); |
766 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); | 766 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); |
767 rvh2->SendNavigate(entry2->GetPageID(), entry2->GetURL()); | 767 rvh2->SendNavigate(entry2->GetPageID(), entry2->GetURL()); |
768 EXPECT_EQ(rvh2, rvh()); | 768 EXPECT_EQ(rvh2, rvh()); |
769 EXPECT_FALSE(rvh2->is_swapped_out()); | 769 EXPECT_FALSE(rvh2->is_swapped_out()); |
770 EXPECT_TRUE(rvh1->is_swapped_out()); | 770 EXPECT_TRUE(rvh1->is_swapped_out()); |
771 } | 771 } |
OLD | NEW |