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

Side by Side Diff: chrome/browser/tab_contents/render_view_host_manager_unittest.cc

Issue 3346005: Don't create pending entries when a navigation is initiated by the page. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Created 10 years, 3 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
OLDNEW
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"
14 #include "chrome/common/url_constants.h" 15 #include "chrome/common/url_constants.h"
15 #include "chrome/test/test_notification_tracker.h" 16 #include "chrome/test/test_notification_tracker.h"
16 #include "chrome/test/testing_profile.h" 17 #include "chrome/test/testing_profile.h"
17 #include "ipc/ipc_message.h" 18 #include "ipc/ipc_message.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 20
20 class RenderViewHostManagerTest : public RenderViewHostTestHarness { 21 class RenderViewHostManagerTest : public RenderViewHostTestHarness {
21 public: 22 public:
22 void NavigateActiveAndCommit(const GURL& url) { 23 void NavigateActiveAndCommit(const GURL& url) {
23 // Note: we navigate the active RenderViewHost because previous navigations 24 // Note: we navigate the active RenderViewHost because previous navigations
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 // Rewrite so it looks like chrome://about/memory 289 // Rewrite so it looks like chrome://about/memory
289 bool reverse_on_redirect = false; 290 bool reverse_on_redirect = false;
290 BrowserURLHandler::RewriteURLIfNecessary( 291 BrowserURLHandler::RewriteURLIfNecessary(
291 &about_url, profile_.get(), &reverse_on_redirect); 292 &about_url, profile_.get(), &reverse_on_redirect);
292 NavigationEntry about_entry(NULL /* instance */, -1 /* page_id */, about_url, 293 NavigationEntry about_entry(NULL /* instance */, -1 /* page_id */, about_url,
293 GURL() /* referrer */, string16() /* title */, 294 GURL() /* referrer */, string16() /* title */,
294 PageTransition::TYPED); 295 PageTransition::TYPED);
295 296
296 EXPECT_TRUE(ShouldSwapProcesses(&manager, &ntp_entry, &about_entry)); 297 EXPECT_TRUE(ShouldSwapProcesses(&manager, &ntp_entry, &about_entry));
297 } 298 }
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 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/navigation_controller_unittest.cc ('k') | chrome/browser/tab_contents/tab_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698