OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/browser_url_handler.h" | 5 #include "chrome/browser/browser_url_handler.h" |
6 #include "chrome/browser/chrome_thread.h" | 6 #include "chrome/browser/chrome_thread.h" |
7 #include "chrome/browser/renderer_host/site_instance.h" | 7 #include "chrome/browser/renderer_host/site_instance.h" |
8 #include "chrome/browser/renderer_host/test/test_render_view_host.h" | 8 #include "chrome/browser/renderer_host/test/test_render_view_host.h" |
9 #include "chrome/browser/tab_contents/navigation_controller.h" | 9 #include "chrome/browser/tab_contents/navigation_controller.h" |
10 #include "chrome/browser/tab_contents/navigation_entry.h" | 10 #include "chrome/browser/tab_contents/navigation_entry.h" |
11 #include "chrome/browser/tab_contents/render_view_host_manager.h" | 11 #include "chrome/browser/tab_contents/render_view_host_manager.h" |
12 #include "chrome/browser/tab_contents/test_tab_contents.h" | 12 #include "chrome/browser/tab_contents/test_tab_contents.h" |
13 #include "chrome/common/render_messages.h" | 13 #include "chrome/common/render_messages.h" |
14 #include "chrome/common/render_messages_params.h" | |
15 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
16 #include "chrome/test/test_notification_tracker.h" | 15 #include "chrome/test/test_notification_tracker.h" |
17 #include "chrome/test/testing_profile.h" | 16 #include "chrome/test/testing_profile.h" |
18 #include "ipc/ipc_message.h" | 17 #include "ipc/ipc_message.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
20 | 19 |
21 class RenderViewHostManagerTest : public RenderViewHostTestHarness { | 20 class RenderViewHostManagerTest : public RenderViewHostTestHarness { |
22 public: | 21 public: |
23 void NavigateActiveAndCommit(const GURL& url) { | 22 void NavigateActiveAndCommit(const GURL& url) { |
24 // Note: we navigate the active RenderViewHost because previous navigations | 23 // Note: we navigate the active RenderViewHost because previous navigations |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 // Rewrite so it looks like chrome://about/memory | 288 // Rewrite so it looks like chrome://about/memory |
290 bool reverse_on_redirect = false; | 289 bool reverse_on_redirect = false; |
291 BrowserURLHandler::RewriteURLIfNecessary( | 290 BrowserURLHandler::RewriteURLIfNecessary( |
292 &about_url, profile_.get(), &reverse_on_redirect); | 291 &about_url, profile_.get(), &reverse_on_redirect); |
293 NavigationEntry about_entry(NULL /* instance */, -1 /* page_id */, about_url, | 292 NavigationEntry about_entry(NULL /* instance */, -1 /* page_id */, about_url, |
294 GURL() /* referrer */, string16() /* title */, | 293 GURL() /* referrer */, string16() /* title */, |
295 PageTransition::TYPED); | 294 PageTransition::TYPED); |
296 | 295 |
297 EXPECT_TRUE(ShouldSwapProcesses(&manager, &ntp_entry, &about_entry)); | 296 EXPECT_TRUE(ShouldSwapProcesses(&manager, &ntp_entry, &about_entry)); |
298 } | 297 } |
299 | |
300 // Tests that we don't end up in an inconsistent state if a page does a back and | |
301 // then reload. http://crbug.com/51680 | |
302 TEST_F(RenderViewHostManagerTest, PageDoesBackAndReload) { | |
303 GURL url1("http://www.google.com/"); | |
304 GURL url2("http://www.evil-site.com/"); | |
305 | |
306 // Navigate to a safe site, then an evil site. | |
307 contents()->NavigateAndCommit(url1); | |
308 RenderViewHost* host1 = contents()->render_view_host(); | |
309 contents()->NavigateAndCommit(url2); | |
310 RenderViewHost* host2 = contents()->render_view_host(); | |
311 // We should have got a new RVH for the evil site. | |
312 EXPECT_NE(host1, host2); | |
313 | |
314 // Casts the TabContents to a RenderViewHostDelegate::BrowserIntegration so we | |
315 // can call GoToEntryAtOffset which is private. | |
316 RenderViewHostDelegate::BrowserIntegration* rvh_delegate = | |
317 static_cast<RenderViewHostDelegate::BrowserIntegration*>(contents()); | |
318 | |
319 // Now let's simulate the evil page calling history.back(). | |
320 rvh_delegate->GoToEntryAtOffset(-1); | |
321 // The pending RVH should be the one for the Google. | |
322 EXPECT_EQ(host1, contents()->render_manager()->pending_render_view_host()); | |
323 | |
324 // Before that RVH has committed, the evil page reloads itself. | |
325 ViewHostMsg_FrameNavigate_Params params; | |
326 params.page_id = 1; | |
327 params.url = url2; | |
328 params.transition = PageTransition::CLIENT_REDIRECT; | |
329 params.should_update_history = false; | |
330 params.gesture = NavigationGestureAuto; | |
331 params.was_within_same_page = false; | |
332 params.is_post = false; | |
333 contents()->TestDidNavigate(host2, params); | |
334 | |
335 // That should have cancelled the pending RVH, and the evil RVH should be the | |
336 // current one. | |
337 EXPECT_TRUE(contents()->render_manager()->pending_render_view_host() == NULL); | |
338 EXPECT_EQ(host2, contents()->render_manager()->current_host()); | |
339 | |
340 // Also we should not have a pending navigation entry. | |
341 NavigationEntry* entry = contents()->controller().GetActiveEntry(); | |
342 ASSERT_TRUE(entry != NULL); | |
343 EXPECT_EQ(url2, entry->url()); | |
344 } | |
OLD | NEW |