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

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

Issue 8253002: Move PageTransition into content namespace. While I'm touching all these files, I've also updated... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/test/base/chrome_render_view_host_test_harness.h" 5 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
6 #include "chrome/test/base/testing_profile.h" 6 #include "chrome/test/base/testing_profile.h"
7 #include "content/browser/browser_thread.h" 7 #include "content/browser/browser_thread.h"
8 #include "content/browser/browser_url_handler.h" 8 #include "content/browser/browser_url_handler.h"
9 #include "content/browser/site_instance.h" 9 #include "content/browser/site_instance.h"
10 #include "content/browser/tab_contents/navigation_controller.h" 10 #include "content/browser/tab_contents/navigation_controller.h"
11 #include "content/browser/tab_contents/navigation_entry.h" 11 #include "content/browser/tab_contents/navigation_entry.h"
12 #include "content/browser/tab_contents/render_view_host_manager.h" 12 #include "content/browser/tab_contents/render_view_host_manager.h"
13 #include "content/browser/tab_contents/test_tab_contents.h" 13 #include "content/browser/tab_contents/test_tab_contents.h"
14 #include "content/common/notification_details.h" 14 #include "content/common/notification_details.h"
15 #include "content/common/notification_source.h" 15 #include "content/common/notification_source.h"
16 #include "content/common/page_transition_types.h"
17 #include "content/common/test_url_constants.h" 16 #include "content/common/test_url_constants.h"
18 #include "content/common/view_messages.h" 17 #include "content/common/view_messages.h"
18 #include "content/public/common/page_transition_types.h"
19 #include "content/test/test_notification_tracker.h" 19 #include "content/test/test_notification_tracker.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "webkit/glue/webkit_glue.h" 21 #include "webkit/glue/webkit_glue.h"
22 22
23 class RenderViewHostManagerTest : public ChromeRenderViewHostTestHarness { 23 class RenderViewHostManagerTest : public ChromeRenderViewHostTestHarness {
24 public: 24 public:
25 void NavigateActiveAndCommit(const GURL& url) { 25 void NavigateActiveAndCommit(const GURL& url) {
26 // Note: we navigate the active RenderViewHost because previous navigations 26 // Note: we navigate the active RenderViewHost because previous navigations
27 // won't have committed yet, so NavigateAndCommit does the wrong thing 27 // won't have committed yet, so NavigateAndCommit does the wrong thing
28 // for us. 28 // for us.
29 controller().LoadURL(url, GURL(), PageTransition::LINK, std::string()); 29 controller().LoadURL(
30 url, GURL(), content::PAGE_TRANSITION_LINK, std::string());
30 TestRenderViewHost* old_rvh = rvh(); 31 TestRenderViewHost* old_rvh = rvh();
31 32
32 // Simulate the ShouldClose_ACK that is received from the current renderer 33 // Simulate the ShouldClose_ACK that is received from the current renderer
33 // for a cross-site navigation. 34 // for a cross-site navigation.
34 if (old_rvh != active_rvh()) 35 if (old_rvh != active_rvh())
35 old_rvh->SendShouldCloseACK(true); 36 old_rvh->SendShouldCloseACK(true);
36 37
37 // Commit the navigation. 38 // Commit the navigation.
38 active_rvh()->SendNavigate( 39 active_rvh()->SendNavigate(
39 static_cast<MockRenderProcessHost*>(active_rvh()->process())-> 40 static_cast<MockRenderProcessHost*>(active_rvh()->process())->
(...skipping 25 matching lines...) Expand all
65 // Navigate our first tab to the new tab page and then to the destination. 66 // Navigate our first tab to the new tab page and then to the destination.
66 NavigateActiveAndCommit(kNtpUrl); 67 NavigateActiveAndCommit(kNtpUrl);
67 NavigateActiveAndCommit(kDestUrl); 68 NavigateActiveAndCommit(kDestUrl);
68 69
69 // Make a second tab. 70 // Make a second tab.
70 TestTabContents contents2(profile(), NULL); 71 TestTabContents contents2(profile(), NULL);
71 72
72 // Load the two URLs in the second tab. Note that the first navigation creates 73 // Load the two URLs in the second tab. Note that the first navigation creates
73 // a RVH that's not pending (since there is no cross-site transition), so 74 // a RVH that's not pending (since there is no cross-site transition), so
74 // we use the committed one. 75 // we use the committed one.
75 contents2.controller().LoadURL(kNtpUrl, GURL(), PageTransition::LINK, 76 contents2.controller().LoadURL(
76 std::string()); 77 kNtpUrl, GURL(), content::PAGE_TRANSITION_LINK, std::string());
77 TestRenderViewHost* ntp_rvh2 = static_cast<TestRenderViewHost*>( 78 TestRenderViewHost* ntp_rvh2 = static_cast<TestRenderViewHost*>(
78 contents2.render_manager_for_testing()->current_host()); 79 contents2.render_manager_for_testing()->current_host());
79 EXPECT_FALSE(contents2.cross_navigation_pending()); 80 EXPECT_FALSE(contents2.cross_navigation_pending());
80 ntp_rvh2->SendNavigate(100, kNtpUrl); 81 ntp_rvh2->SendNavigate(100, kNtpUrl);
81 82
82 // The second one is the opposite, creating a cross-site transition and 83 // The second one is the opposite, creating a cross-site transition and
83 // requiring a beforeunload ack. 84 // requiring a beforeunload ack.
84 contents2.controller().LoadURL(kDestUrl, GURL(), PageTransition::LINK, 85 contents2.controller().LoadURL(
85 std::string()); 86 kDestUrl, GURL(), content::PAGE_TRANSITION_LINK, std::string());
86 EXPECT_TRUE(contents2.cross_navigation_pending()); 87 EXPECT_TRUE(contents2.cross_navigation_pending());
87 TestRenderViewHost* dest_rvh2 = static_cast<TestRenderViewHost*>( 88 TestRenderViewHost* dest_rvh2 = static_cast<TestRenderViewHost*>(
88 contents2.render_manager_for_testing()->pending_render_view_host()); 89 contents2.render_manager_for_testing()->pending_render_view_host());
89 ASSERT_TRUE(dest_rvh2); 90 ASSERT_TRUE(dest_rvh2);
90 ntp_rvh2->SendShouldCloseACK(true); 91 ntp_rvh2->SendShouldCloseACK(true);
91 dest_rvh2->SendNavigate(101, kDestUrl); 92 dest_rvh2->SendNavigate(101, kDestUrl);
92 ntp_rvh2->OnSwapOutACK(); 93 ntp_rvh2->OnSwapOutACK();
93 94
94 // The two RVH's should be different in every way. 95 // The two RVH's should be different in every way.
95 EXPECT_NE(active_rvh()->process(), dest_rvh2->process()); 96 EXPECT_NE(active_rvh()->process(), dest_rvh2->process());
96 EXPECT_NE(active_rvh()->site_instance(), dest_rvh2->site_instance()); 97 EXPECT_NE(active_rvh()->site_instance(), dest_rvh2->site_instance());
97 EXPECT_NE(active_rvh()->site_instance()->browsing_instance(), 98 EXPECT_NE(active_rvh()->site_instance()->browsing_instance(),
98 dest_rvh2->site_instance()->browsing_instance()); 99 dest_rvh2->site_instance()->browsing_instance());
99 100
100 // Navigate both to the new tab page, and verify that they share a 101 // Navigate both to the new tab page, and verify that they share a
101 // SiteInstance. 102 // SiteInstance.
102 NavigateActiveAndCommit(kNtpUrl); 103 NavigateActiveAndCommit(kNtpUrl);
103 104
104 contents2.controller().LoadURL(kNtpUrl, GURL(), PageTransition::LINK, 105 contents2.controller().LoadURL(
105 std::string()); 106 kNtpUrl, GURL(), content::PAGE_TRANSITION_LINK, std::string());
106 dest_rvh2->SendShouldCloseACK(true); 107 dest_rvh2->SendShouldCloseACK(true);
107 static_cast<TestRenderViewHost*>(contents2.render_manager_for_testing()-> 108 static_cast<TestRenderViewHost*>(contents2.render_manager_for_testing()->
108 pending_render_view_host())->SendNavigate(102, kNtpUrl); 109 pending_render_view_host())->SendNavigate(102, kNtpUrl);
109 dest_rvh2->OnSwapOutACK(); 110 dest_rvh2->OnSwapOutACK();
110 111
111 EXPECT_EQ(active_rvh()->site_instance(), 112 EXPECT_EQ(active_rvh()->site_instance(),
112 contents2.render_view_host()->site_instance()); 113 contents2.render_view_host()->site_instance());
113 } 114 }
114 115
115 // When there is an error with the specified page, renderer exits view-source 116 // When there is an error with the specified page, renderer exits view-source
116 // mode. See WebFrameImpl::DidFail(). We check by this test that 117 // mode. See WebFrameImpl::DidFail(). We check by this test that
117 // EnableViewSourceMode message is sent on every navigation regardless 118 // EnableViewSourceMode message is sent on every navigation regardless
118 // RenderView is being newly created or reused. 119 // RenderView is being newly created or reused.
119 TEST_F(RenderViewHostManagerTest, AlwaysSendEnableViewSourceMode) { 120 TEST_F(RenderViewHostManagerTest, AlwaysSendEnableViewSourceMode) {
120 BrowserThread ui_thread(BrowserThread::UI, MessageLoop::current()); 121 BrowserThread ui_thread(BrowserThread::UI, MessageLoop::current());
121 const GURL kNtpUrl(chrome::kTestNewTabURL); 122 const GURL kNtpUrl(chrome::kTestNewTabURL);
122 const GURL kUrl("view-source:http://foo"); 123 const GURL kUrl("view-source:http://foo");
123 124
124 // We have to navigate to some page at first since without this, the first 125 // We have to navigate to some page at first since without this, the first
125 // navigation will reuse the SiteInstance created by Init(), and the second 126 // navigation will reuse the SiteInstance created by Init(), and the second
126 // one will create a new SiteInstance. Because current_instance and 127 // one will create a new SiteInstance. Because current_instance and
127 // new_instance will be different, a new RenderViewHost will be created for 128 // new_instance will be different, a new RenderViewHost will be created for
128 // the second navigation. We have to avoid this in order to exercise the 129 // the second navigation. We have to avoid this in order to exercise the
129 // target code patch. 130 // target code patch.
130 NavigateActiveAndCommit(kNtpUrl); 131 NavigateActiveAndCommit(kNtpUrl);
131 132
132 // Navigate. 133 // Navigate.
133 controller().LoadURL(kUrl, GURL() /* referer */, PageTransition::TYPED, 134 controller().LoadURL(
134 std::string()); 135 kUrl, GURL(), content::PAGE_TRANSITION_TYPED, std::string());
135 // Simulate response from RenderView for FirePageBeforeUnload. 136 // Simulate response from RenderView for FirePageBeforeUnload.
136 rvh()->TestOnMessageReceived( 137 rvh()->TestOnMessageReceived(
137 ViewHostMsg_ShouldClose_ACK(rvh()->routing_id(), true)); 138 ViewHostMsg_ShouldClose_ACK(rvh()->routing_id(), true));
138 ASSERT_TRUE(pending_rvh()); // New pending RenderViewHost will be created. 139 ASSERT_TRUE(pending_rvh()); // New pending RenderViewHost will be created.
139 RenderViewHost* last_rvh = pending_rvh(); 140 RenderViewHost* last_rvh = pending_rvh();
140 int new_id = static_cast<MockRenderProcessHost*>(pending_rvh()->process())-> 141 int new_id = static_cast<MockRenderProcessHost*>(pending_rvh()->process())->
141 max_page_id() + 1; 142 max_page_id() + 1;
142 pending_rvh()->SendNavigate(new_id, kUrl); 143 pending_rvh()->SendNavigate(new_id, kUrl);
143 EXPECT_EQ(controller().last_committed_entry_index(), 1); 144 EXPECT_EQ(controller().last_committed_entry_index(), 1);
144 ASSERT_TRUE(controller().GetLastCommittedEntry()); 145 ASSERT_TRUE(controller().GetLastCommittedEntry());
145 EXPECT_TRUE(kUrl == controller().GetLastCommittedEntry()->url()); 146 EXPECT_TRUE(kUrl == controller().GetLastCommittedEntry()->url());
146 EXPECT_FALSE(controller().pending_entry()); 147 EXPECT_FALSE(controller().pending_entry());
147 // Because we're using TestTabContents and TestRenderViewHost in this 148 // Because we're using TestTabContents and TestRenderViewHost in this
148 // unittest, no one calls TabContents::RenderViewCreated(). So, we see no 149 // unittest, no one calls TabContents::RenderViewCreated(). So, we see no
149 // EnableViewSourceMode message, here. 150 // EnableViewSourceMode message, here.
150 151
151 // Clear queued messages before load. 152 // Clear queued messages before load.
152 process()->sink().ClearMessages(); 153 process()->sink().ClearMessages();
153 // Navigate, again. 154 // Navigate, again.
154 controller().LoadURL(kUrl, GURL() /* referer */, PageTransition::TYPED, 155 controller().LoadURL(
155 std::string()); 156 kUrl, GURL(), content::PAGE_TRANSITION_TYPED, std::string());
156 // The same RenderViewHost should be reused. 157 // The same RenderViewHost should be reused.
157 EXPECT_FALSE(pending_rvh()); 158 EXPECT_FALSE(pending_rvh());
158 EXPECT_TRUE(last_rvh == rvh()); 159 EXPECT_TRUE(last_rvh == rvh());
159 rvh()->SendNavigate(new_id, kUrl); // The same page_id returned. 160 rvh()->SendNavigate(new_id, kUrl); // The same page_id returned.
160 EXPECT_EQ(controller().last_committed_entry_index(), 1); 161 EXPECT_EQ(controller().last_committed_entry_index(), 1);
161 EXPECT_FALSE(controller().pending_entry()); 162 EXPECT_FALSE(controller().pending_entry());
162 // New message should be sent out to make sure to enter view-source mode. 163 // New message should be sent out to make sure to enter view-source mode.
163 EXPECT_TRUE(process()->sink().GetUniqueMessageMatching( 164 EXPECT_TRUE(process()->sink().GetUniqueMessageMatching(
164 ViewMsg_EnableViewSourceMode::ID)); 165 ViewMsg_EnableViewSourceMode::ID));
165 } 166 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 RenderViewHostManager manager(&tab_contents, &tab_contents); 199 RenderViewHostManager manager(&tab_contents, &tab_contents);
199 200
200 manager.Init(profile(), instance, MSG_ROUTING_NONE); 201 manager.Init(profile(), instance, MSG_ROUTING_NONE);
201 202
202 RenderViewHost* host; 203 RenderViewHost* host;
203 204
204 // 1) The first navigation. -------------------------- 205 // 1) The first navigation. --------------------------
205 const GURL kUrl1("http://www.google.com/"); 206 const GURL kUrl1("http://www.google.com/");
206 NavigationEntry entry1(NULL /* instance */, -1 /* page_id */, kUrl1, 207 NavigationEntry entry1(NULL /* instance */, -1 /* page_id */, kUrl1,
207 GURL() /* referrer */, string16() /* title */, 208 GURL() /* referrer */, string16() /* title */,
208 PageTransition::TYPED); 209 content::PAGE_TRANSITION_TYPED);
209 host = manager.Navigate(entry1); 210 host = manager.Navigate(entry1);
210 211
211 // The RenderViewHost created in Init will be reused. 212 // The RenderViewHost created in Init will be reused.
212 EXPECT_TRUE(host == manager.current_host()); 213 EXPECT_TRUE(host == manager.current_host());
213 EXPECT_FALSE(manager.pending_render_view_host()); 214 EXPECT_FALSE(manager.pending_render_view_host());
214 215
215 // Commit. 216 // Commit.
216 manager.DidNavigateMainFrame(host); 217 manager.DidNavigateMainFrame(host);
217 // Commit to SiteInstance should be delayed until RenderView commit. 218 // Commit to SiteInstance should be delayed until RenderView commit.
218 EXPECT_TRUE(host == manager.current_host()); 219 EXPECT_TRUE(host == manager.current_host());
219 ASSERT_TRUE(host); 220 ASSERT_TRUE(host);
220 EXPECT_FALSE(host->site_instance()->has_site()); 221 EXPECT_FALSE(host->site_instance()->has_site());
221 host->site_instance()->SetSite(kUrl1); 222 host->site_instance()->SetSite(kUrl1);
222 223
223 // 2) Navigate to next site. ------------------------- 224 // 2) Navigate to next site. -------------------------
224 const GURL kUrl2("http://www.google.com/foo"); 225 const GURL kUrl2("http://www.google.com/foo");
225 NavigationEntry entry2(NULL /* instance */, -1 /* page_id */, kUrl2, 226 NavigationEntry entry2(NULL /* instance */, -1 /* page_id */, kUrl2,
226 kUrl1 /* referrer */, string16() /* title */, 227 kUrl1 /* referrer */, string16() /* title */,
227 PageTransition::LINK); 228 content::PAGE_TRANSITION_LINK);
228 host = manager.Navigate(entry2); 229 host = manager.Navigate(entry2);
229 230
230 // The RenderViewHost created in Init will be reused. 231 // The RenderViewHost created in Init will be reused.
231 EXPECT_TRUE(host == manager.current_host()); 232 EXPECT_TRUE(host == manager.current_host());
232 EXPECT_FALSE(manager.pending_render_view_host()); 233 EXPECT_FALSE(manager.pending_render_view_host());
233 234
234 // Commit. 235 // Commit.
235 manager.DidNavigateMainFrame(host); 236 manager.DidNavigateMainFrame(host);
236 EXPECT_TRUE(host == manager.current_host()); 237 EXPECT_TRUE(host == manager.current_host());
237 ASSERT_TRUE(host); 238 ASSERT_TRUE(host);
238 EXPECT_TRUE(host->site_instance()->has_site()); 239 EXPECT_TRUE(host->site_instance()->has_site());
239 240
240 // 3) Cross-site navigate to next site. -------------- 241 // 3) Cross-site navigate to next site. --------------
241 const GURL kUrl3("http://webkit.org/"); 242 const GURL kUrl3("http://webkit.org/");
242 NavigationEntry entry3(NULL /* instance */, -1 /* page_id */, kUrl3, 243 NavigationEntry entry3(NULL /* instance */, -1 /* page_id */, kUrl3,
243 kUrl2 /* referrer */, string16() /* title */, 244 kUrl2 /* referrer */, string16() /* title */,
244 PageTransition::LINK); 245 content::PAGE_TRANSITION_LINK);
245 host = manager.Navigate(entry3); 246 host = manager.Navigate(entry3);
246 247
247 // A new RenderViewHost should be created. 248 // A new RenderViewHost should be created.
248 EXPECT_TRUE(manager.pending_render_view_host()); 249 EXPECT_TRUE(manager.pending_render_view_host());
249 ASSERT_EQ(host, manager.pending_render_view_host()); 250 ASSERT_EQ(host, manager.pending_render_view_host());
250 251
251 notifications.Reset(); 252 notifications.Reset();
252 253
253 // Commit. 254 // Commit.
254 manager.DidNavigateMainFrame(manager.pending_render_view_host()); 255 manager.DidNavigateMainFrame(manager.pending_render_view_host());
(...skipping 14 matching lines...) Expand all
269 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile()); 270 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile());
270 271
271 TestTabContents tab_contents(profile(), instance); 272 TestTabContents tab_contents(profile(), instance);
272 RenderViewHostManager manager(&tab_contents, &tab_contents); 273 RenderViewHostManager manager(&tab_contents, &tab_contents);
273 274
274 manager.Init(profile(), instance, MSG_ROUTING_NONE); 275 manager.Init(profile(), instance, MSG_ROUTING_NONE);
275 276
276 const GURL kUrl(chrome::kTestNewTabURL); 277 const GURL kUrl(chrome::kTestNewTabURL);
277 NavigationEntry entry(NULL /* instance */, -1 /* page_id */, kUrl, 278 NavigationEntry entry(NULL /* instance */, -1 /* page_id */, kUrl,
278 GURL() /* referrer */, string16() /* title */, 279 GURL() /* referrer */, string16() /* title */,
279 PageTransition::TYPED); 280 content::PAGE_TRANSITION_TYPED);
280 RenderViewHost* host = manager.Navigate(entry); 281 RenderViewHost* host = manager.Navigate(entry);
281 282
282 EXPECT_TRUE(host); 283 EXPECT_TRUE(host);
283 EXPECT_TRUE(host == manager.current_host()); 284 EXPECT_TRUE(host == manager.current_host());
284 EXPECT_FALSE(manager.pending_render_view_host()); 285 EXPECT_FALSE(manager.pending_render_view_host());
285 286
286 // It's important that the site instance get set on the Web UI page as soon 287 // It's important that the site instance get set on the Web UI page as soon
287 // as the navigation starts, rather than lazily after it commits, so we don't 288 // as the navigation starts, rather than lazily after it commits, so we don't
288 // try to re-use the SiteInstance/process for non DOM-UI things that may 289 // try to re-use the SiteInstance/process for non DOM-UI things that may
289 // get loaded in between. 290 // get loaded in between.
(...skipping 17 matching lines...) Expand all
307 BrowserThread thread(BrowserThread::UI, &message_loop_); 308 BrowserThread thread(BrowserThread::UI, &message_loop_);
308 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile()); 309 SiteInstance* instance = SiteInstance::CreateSiteInstance(profile());
309 TestTabContents tab_contents(profile(), instance); 310 TestTabContents tab_contents(profile(), instance);
310 RenderViewHostManager manager(&tab_contents, &tab_contents); 311 RenderViewHostManager manager(&tab_contents, &tab_contents);
311 manager.Init(profile(), instance, MSG_ROUTING_NONE); 312 manager.Init(profile(), instance, MSG_ROUTING_NONE);
312 313
313 // NTP is a Web UI page. 314 // NTP is a Web UI page.
314 const GURL kNtpUrl(chrome::kTestNewTabURL); 315 const GURL kNtpUrl(chrome::kTestNewTabURL);
315 NavigationEntry ntp_entry(NULL /* instance */, -1 /* page_id */, kNtpUrl, 316 NavigationEntry ntp_entry(NULL /* instance */, -1 /* page_id */, kNtpUrl,
316 GURL() /* referrer */, string16() /* title */, 317 GURL() /* referrer */, string16() /* title */,
317 PageTransition::TYPED); 318 content::PAGE_TRANSITION_TYPED);
318 319
319 // about: URLs are not Web UI pages. 320 // about: URLs are not Web UI pages.
320 GURL about_url(chrome::kTestMemoryURL); 321 GURL about_url(chrome::kTestMemoryURL);
321 // Rewrite so it looks like chrome://about/memory 322 // Rewrite so it looks like chrome://about/memory
322 bool reverse_on_redirect = false; 323 bool reverse_on_redirect = false;
323 BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( 324 BrowserURLHandler::GetInstance()->RewriteURLIfNecessary(
324 &about_url, profile(), &reverse_on_redirect); 325 &about_url, profile(), &reverse_on_redirect);
325 NavigationEntry about_entry(NULL /* instance */, -1 /* page_id */, about_url, 326 NavigationEntry about_entry(NULL /* instance */, -1 /* page_id */, about_url,
326 GURL() /* referrer */, string16() /* title */, 327 GURL() /* referrer */, string16() /* title */,
327 PageTransition::TYPED); 328 content::PAGE_TRANSITION_TYPED);
328 329
329 EXPECT_TRUE(ShouldSwapProcesses(&manager, &ntp_entry, &about_entry)); 330 EXPECT_TRUE(ShouldSwapProcesses(&manager, &ntp_entry, &about_entry));
330 } 331 }
331 332
332 // Tests that we don't end up in an inconsistent state if a page does a back and 333 // Tests that we don't end up in an inconsistent state if a page does a back and
333 // then reload. http://crbug.com/51680 334 // then reload. http://crbug.com/51680
334 TEST_F(RenderViewHostManagerTest, PageDoesBackAndReload) { 335 TEST_F(RenderViewHostManagerTest, PageDoesBackAndReload) {
335 const GURL kUrl1("http://www.google.com/"); 336 const GURL kUrl1("http://www.google.com/");
336 const GURL kUrl2("http://www.evil-site.com/"); 337 const GURL kUrl2("http://www.evil-site.com/");
337 338
(...skipping 10 matching lines...) Expand all
348 // We should have a new pending RVH. 349 // We should have a new pending RVH.
349 // Note that in this case, the navigation has not committed, so evil_rvh will 350 // Note that in this case, the navigation has not committed, so evil_rvh will
350 // not be deleted yet. 351 // not be deleted yet.
351 EXPECT_NE(evil_rvh, contents()->render_manager_for_testing()-> 352 EXPECT_NE(evil_rvh, contents()->render_manager_for_testing()->
352 pending_render_view_host()); 353 pending_render_view_host());
353 354
354 // Before that RVH has committed, the evil page reloads itself. 355 // Before that RVH has committed, the evil page reloads itself.
355 ViewHostMsg_FrameNavigate_Params params; 356 ViewHostMsg_FrameNavigate_Params params;
356 params.page_id = 1; 357 params.page_id = 1;
357 params.url = kUrl2; 358 params.url = kUrl2;
358 params.transition = PageTransition::CLIENT_REDIRECT; 359 params.transition = content::PAGE_TRANSITION_CLIENT_REDIRECT;
359 params.should_update_history = false; 360 params.should_update_history = false;
360 params.gesture = NavigationGestureAuto; 361 params.gesture = NavigationGestureAuto;
361 params.was_within_same_page = false; 362 params.was_within_same_page = false;
362 params.is_post = false; 363 params.is_post = false;
363 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(kUrl2)); 364 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(kUrl2));
364 contents()->TestDidNavigate(evil_rvh, params); 365 contents()->TestDidNavigate(evil_rvh, params);
365 366
366 // That should have cancelled the pending RVH, and the evil RVH should be the 367 // That should have cancelled the pending RVH, and the evil RVH should be the
367 // current one. 368 // current one.
368 EXPECT_TRUE(contents()->render_manager_for_testing()-> 369 EXPECT_TRUE(contents()->render_manager_for_testing()->
369 pending_render_view_host() == NULL); 370 pending_render_view_host() == NULL);
370 EXPECT_EQ(evil_rvh, contents()->render_manager_for_testing()->current_host()); 371 EXPECT_EQ(evil_rvh, contents()->render_manager_for_testing()->current_host());
371 372
372 // Also we should not have a pending navigation entry. 373 // Also we should not have a pending navigation entry.
373 NavigationEntry* entry = contents()->controller().GetActiveEntry(); 374 NavigationEntry* entry = contents()->controller().GetActiveEntry();
374 ASSERT_TRUE(entry != NULL); 375 ASSERT_TRUE(entry != NULL);
375 EXPECT_EQ(kUrl2, entry->url()); 376 EXPECT_EQ(kUrl2, entry->url());
376 } 377 }
OLDNEW
« no previous file with comments | « content/browser/tab_contents/render_view_host_manager.cc ('k') | content/browser/tab_contents/tab_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698