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/logging.h" | 5 #include "base/logging.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "content/browser/renderer_host/render_view_host_impl.h" | 7 #include "content/browser/renderer_host/render_view_host_impl.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/web_contents/interstitial_page_impl.h" | 10 #include "content/browser/web_contents/interstitial_page_impl.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "content/public/common/content_constants.h" | 23 #include "content/public/common/content_constants.h" |
24 #include "content/public/common/url_constants.h" | 24 #include "content/public/common/url_constants.h" |
25 #include "content/public/test/mock_render_process_host.h" | 25 #include "content/public/test/mock_render_process_host.h" |
26 #include "content/public/test/test_browser_thread.h" | 26 #include "content/public/test/test_browser_thread.h" |
27 #include "content/test/test_content_browser_client.h" | 27 #include "content/test/test_content_browser_client.h" |
28 #include "content/test/test_content_client.h" | 28 #include "content/test/test_content_client.h" |
29 #include "googleurl/src/url_util.h" | 29 #include "googleurl/src/url_util.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
31 #include "webkit/glue/webkit_glue.h" | 31 #include "webkit/glue/webkit_glue.h" |
32 | 32 |
33 using content::BrowserContext; | 33 namespace content { |
34 using content::BrowserThread; | |
35 using content::InterstitialPage; | |
36 using content::MockRenderProcessHost; | |
37 using content::NavigationEntry; | |
38 using content::NavigationEntryImpl; | |
39 using content::PasswordForm; | |
40 using content::SiteInstance; | |
41 using content::RenderViewHost; | |
42 using content::RenderViewHostImplTestHarness; | |
43 using content::TestBrowserThread; | |
44 using content::TestRenderViewHost; | |
45 using content::TestWebContents; | |
46 using content::WebContents; | |
47 using content::WebUI; | |
48 using content::WebUIController; | |
49 | |
50 namespace { | 34 namespace { |
51 | 35 |
52 class WebContentsImplTestWebUIControllerFactory | 36 class WebContentsImplTestWebUIControllerFactory |
53 : public content::WebUIControllerFactory { | 37 : public WebUIControllerFactory { |
54 public: | 38 public: |
55 virtual WebUIController* CreateWebUIControllerForURL( | 39 virtual WebUIController* CreateWebUIControllerForURL( |
56 content::WebUI* web_ui, const GURL& url) const OVERRIDE { | 40 WebUI* web_ui, const GURL& url) const OVERRIDE { |
57 if (!content::GetContentClient()->HasWebUIScheme(url)) | 41 if (!GetContentClient()->HasWebUIScheme(url)) |
58 return NULL; | 42 return NULL; |
59 | 43 |
60 return new WebUIController(web_ui); | 44 return new WebUIController(web_ui); |
61 } | 45 } |
62 | 46 |
63 virtual WebUI::TypeID GetWebUIType(BrowserContext* browser_context, | 47 virtual WebUI::TypeID GetWebUIType(BrowserContext* browser_context, |
64 const GURL& url) const OVERRIDE { | 48 const GURL& url) const OVERRIDE { |
65 return WebUI::kNoWebUI; | 49 return WebUI::kNoWebUI; |
66 } | 50 } |
67 | 51 |
68 virtual bool UseWebUIForURL(BrowserContext* browser_context, | 52 virtual bool UseWebUIForURL(BrowserContext* browser_context, |
69 const GURL& url) const OVERRIDE { | 53 const GURL& url) const OVERRIDE { |
70 return content::GetContentClient()->HasWebUIScheme(url); | 54 return GetContentClient()->HasWebUIScheme(url); |
71 } | 55 } |
72 | 56 |
73 virtual bool UseWebUIBindingsForURL(BrowserContext* browser_context, | 57 virtual bool UseWebUIBindingsForURL(BrowserContext* browser_context, |
74 const GURL& url) const OVERRIDE { | 58 const GURL& url) const OVERRIDE { |
75 return content::GetContentClient()->HasWebUIScheme(url); | 59 return GetContentClient()->HasWebUIScheme(url); |
76 } | 60 } |
77 | 61 |
78 virtual bool IsURLAcceptableForWebUI( | 62 virtual bool IsURLAcceptableForWebUI( |
79 BrowserContext* browser_context, | 63 BrowserContext* browser_context, |
80 const GURL& url, | 64 const GURL& url, |
81 bool data_urls_allowed) const { | 65 bool data_urls_allowed) const { |
82 return content::GetContentClient()->HasWebUIScheme(url); | 66 return GetContentClient()->HasWebUIScheme(url); |
83 } | 67 } |
84 }; | 68 }; |
85 | 69 |
86 class WebContentsImplTestContentClient : public TestContentClient { | 70 class WebContentsImplTestContentClient : public TestContentClient { |
87 public: | 71 public: |
88 WebContentsImplTestContentClient() { | 72 WebContentsImplTestContentClient() { |
89 } | 73 } |
90 | 74 |
91 virtual bool HasWebUIScheme(const GURL& url) const OVERRIDE { | 75 virtual bool HasWebUIScheme(const GURL& url) const OVERRIDE { |
92 return url.SchemeIs("webcontentsimpltest"); | 76 return url.SchemeIs("webcontentsimpltest"); |
93 } | 77 } |
94 }; | 78 }; |
95 | 79 |
96 class WebContentsImplTestBrowserClient | 80 class WebContentsImplTestBrowserClient : public TestContentBrowserClient { |
97 : public content::TestContentBrowserClient { | |
98 public: | 81 public: |
99 WebContentsImplTestBrowserClient() { | 82 WebContentsImplTestBrowserClient() { |
100 } | 83 } |
101 | 84 |
102 virtual content::WebUIControllerFactory* | 85 virtual WebUIControllerFactory* GetWebUIControllerFactory() OVERRIDE { |
103 GetWebUIControllerFactory() OVERRIDE { | |
104 return &factory_; | 86 return &factory_; |
105 } | 87 } |
106 | 88 |
107 private: | 89 private: |
108 WebContentsImplTestWebUIControllerFactory factory_; | 90 WebContentsImplTestWebUIControllerFactory factory_; |
109 }; | 91 }; |
110 | 92 |
111 class TestInterstitialPage; | 93 class TestInterstitialPage; |
112 | 94 |
113 class TestInterstitialPageDelegate : public content::InterstitialPageDelegate { | 95 class TestInterstitialPageDelegate : public InterstitialPageDelegate { |
114 public: | 96 public: |
115 TestInterstitialPageDelegate(TestInterstitialPage* interstitial_page) | 97 TestInterstitialPageDelegate(TestInterstitialPage* interstitial_page) |
116 : interstitial_page_(interstitial_page) {} | 98 : interstitial_page_(interstitial_page) {} |
117 virtual void CommandReceived(const std::string& command) OVERRIDE; | 99 virtual void CommandReceived(const std::string& command) OVERRIDE; |
118 virtual std::string GetHTMLContents() OVERRIDE { return std::string(); } | 100 virtual std::string GetHTMLContents() OVERRIDE { return std::string(); } |
119 virtual void OnDontProceed() OVERRIDE; | 101 virtual void OnDontProceed() OVERRIDE; |
120 virtual void OnProceed() OVERRIDE; | 102 virtual void OnProceed() OVERRIDE; |
121 private: | 103 private: |
122 TestInterstitialPage* interstitial_page_; | 104 TestInterstitialPage* interstitial_page_; |
123 }; | 105 }; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 return command_received_count_; | 166 return command_received_count_; |
185 } | 167 } |
186 | 168 |
187 void TestDomOperationResponse(const std::string& json_string) { | 169 void TestDomOperationResponse(const std::string& json_string) { |
188 if (enabled()) | 170 if (enabled()) |
189 CommandReceived(); | 171 CommandReceived(); |
190 } | 172 } |
191 | 173 |
192 void TestDidNavigate(int page_id, const GURL& url) { | 174 void TestDidNavigate(int page_id, const GURL& url) { |
193 ViewHostMsg_FrameNavigate_Params params; | 175 ViewHostMsg_FrameNavigate_Params params; |
194 InitNavigateParams(¶ms, page_id, url, content::PAGE_TRANSITION_TYPED); | 176 InitNavigateParams(¶ms, page_id, url, PAGE_TRANSITION_TYPED); |
195 DidNavigate(GetRenderViewHostForTesting(), params); | 177 DidNavigate(GetRenderViewHostForTesting(), params); |
196 } | 178 } |
197 | 179 |
198 void TestRenderViewGone(base::TerminationStatus status, int error_code) { | 180 void TestRenderViewGone(base::TerminationStatus status, int error_code) { |
199 RenderViewGone(GetRenderViewHostForTesting(), status, error_code); | 181 RenderViewGone(GetRenderViewHostForTesting(), status, error_code); |
200 } | 182 } |
201 | 183 |
202 bool is_showing() const { | 184 bool is_showing() const { |
203 return static_cast<content::TestRenderWidgetHostView*>( | 185 return static_cast<TestRenderWidgetHostView*>( |
204 GetRenderViewHostForTesting()->GetView())->is_showing(); | 186 GetRenderViewHostForTesting()->GetView())->is_showing(); |
205 } | 187 } |
206 | 188 |
207 void ClearStates() { | 189 void ClearStates() { |
208 state_ = NULL; | 190 state_ = NULL; |
209 deleted_ = NULL; | 191 deleted_ = NULL; |
210 delegate_ = NULL; | 192 delegate_ = NULL; |
211 } | 193 } |
212 | 194 |
213 void CommandReceived() { | 195 void CommandReceived() { |
214 command_received_count_++; | 196 command_received_count_++; |
215 } | 197 } |
216 | 198 |
217 void set_delegate(Delegate* delegate) { | 199 void set_delegate(Delegate* delegate) { |
218 delegate_ = delegate; | 200 delegate_ = delegate; |
219 } | 201 } |
220 | 202 |
221 protected: | 203 protected: |
222 virtual content::RenderViewHost* CreateRenderViewHost() OVERRIDE { | 204 virtual RenderViewHost* CreateRenderViewHost() OVERRIDE { |
223 return new TestRenderViewHost( | 205 return new TestRenderViewHost( |
224 SiteInstance::Create(web_contents()->GetBrowserContext()), | 206 SiteInstance::Create(web_contents()->GetBrowserContext()), |
225 this, this, MSG_ROUTING_NONE, false); | 207 this, this, MSG_ROUTING_NONE, false); |
226 } | 208 } |
227 | 209 |
228 virtual content::WebContentsView* CreateWebContentsView() OVERRIDE { | 210 virtual WebContentsView* CreateWebContentsView() OVERRIDE { |
229 return NULL; | 211 return NULL; |
230 } | 212 } |
231 | 213 |
232 private: | 214 private: |
233 InterstitialState* state_; | 215 InterstitialState* state_; |
234 bool* deleted_; | 216 bool* deleted_; |
235 int command_received_count_; | 217 int command_received_count_; |
236 Delegate* delegate_; | 218 Delegate* delegate_; |
237 }; | 219 }; |
238 | 220 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 file_user_blocking_thread_( | 261 file_user_blocking_thread_( |
280 BrowserThread::FILE_USER_BLOCKING, &message_loop_), | 262 BrowserThread::FILE_USER_BLOCKING, &message_loop_), |
281 io_thread_(BrowserThread::IO, &message_loop_) { | 263 io_thread_(BrowserThread::IO, &message_loop_) { |
282 } | 264 } |
283 | 265 |
284 virtual void SetUp() { | 266 virtual void SetUp() { |
285 // These tests treat webcontentsimpltest as a privileged WebUI scheme. | 267 // These tests treat webcontentsimpltest as a privileged WebUI scheme. |
286 // We must register it similarly to kChromeUIScheme. | 268 // We must register it similarly to kChromeUIScheme. |
287 url_util::AddStandardScheme("webcontentsimpltest"); | 269 url_util::AddStandardScheme("webcontentsimpltest"); |
288 | 270 |
289 old_client_ = content::GetContentClient(); | 271 old_client_ = GetContentClient(); |
290 old_browser_client_ = content::GetContentClient()->browser(); | 272 old_browser_client_ = GetContentClient()->browser(); |
291 content::SetContentClient(&client_); | 273 SetContentClient(&client_); |
292 content::GetContentClient()->set_browser_for_testing(&browser_client_); | 274 GetContentClient()->set_browser_for_testing(&browser_client_); |
293 RenderViewHostImplTestHarness::SetUp(); | 275 RenderViewHostImplTestHarness::SetUp(); |
294 } | 276 } |
295 | 277 |
296 virtual void TearDown() { | 278 virtual void TearDown() { |
297 content::GetContentClient()->set_browser_for_testing(old_browser_client_); | 279 GetContentClient()->set_browser_for_testing(old_browser_client_); |
298 content::SetContentClient(old_client_); | 280 SetContentClient(old_client_); |
299 RenderViewHostImplTestHarness::TearDown(); | 281 RenderViewHostImplTestHarness::TearDown(); |
300 } | 282 } |
301 | 283 |
302 private: | 284 private: |
303 WebContentsImplTestContentClient client_; | 285 WebContentsImplTestContentClient client_; |
304 WebContentsImplTestBrowserClient browser_client_; | 286 WebContentsImplTestBrowserClient browser_client_; |
305 content::ContentClient* old_client_; | 287 ContentClient* old_client_; |
306 content::ContentBrowserClient* old_browser_client_; | 288 ContentBrowserClient* old_browser_client_; |
307 TestBrowserThread ui_thread_; | 289 TestBrowserThread ui_thread_; |
308 TestBrowserThread file_user_blocking_thread_; | 290 TestBrowserThread file_user_blocking_thread_; |
309 TestBrowserThread io_thread_; | 291 TestBrowserThread io_thread_; |
310 }; | 292 }; |
311 | 293 |
312 } // namespace | 294 } // namespace |
313 | 295 |
314 // Test to make sure that title updates get stripped of whitespace. | 296 // Test to make sure that title updates get stripped of whitespace. |
315 TEST_F(WebContentsImplTest, UpdateTitle) { | 297 TEST_F(WebContentsImplTest, UpdateTitle) { |
316 NavigationControllerImpl& cont = | 298 NavigationControllerImpl& cont = |
317 static_cast<NavigationControllerImpl&>(controller()); | 299 static_cast<NavigationControllerImpl&>(controller()); |
318 ViewHostMsg_FrameNavigate_Params params; | 300 ViewHostMsg_FrameNavigate_Params params; |
319 InitNavigateParams(¶ms, 0, GURL(chrome::kAboutBlankURL), | 301 InitNavigateParams(¶ms, 0, GURL(chrome::kAboutBlankURL), |
320 content::PAGE_TRANSITION_TYPED); | 302 PAGE_TRANSITION_TYPED); |
321 | 303 |
322 content::LoadCommittedDetails details; | 304 LoadCommittedDetails details; |
323 cont.RendererDidNavigate(params, &details); | 305 cont.RendererDidNavigate(params, &details); |
324 | 306 |
325 contents()->UpdateTitle(rvh(), 0, ASCIIToUTF16(" Lots O' Whitespace\n"), | 307 contents()->UpdateTitle(rvh(), 0, ASCIIToUTF16(" Lots O' Whitespace\n"), |
326 base::i18n::LEFT_TO_RIGHT); | 308 base::i18n::LEFT_TO_RIGHT); |
327 EXPECT_EQ(ASCIIToUTF16("Lots O' Whitespace"), contents()->GetTitle()); | 309 EXPECT_EQ(ASCIIToUTF16("Lots O' Whitespace"), contents()->GetTitle()); |
328 } | 310 } |
329 | 311 |
330 // Test view source mode for a webui page. | 312 // Test view source mode for a webui page. |
331 TEST_F(WebContentsImplTest, NTPViewSource) { | 313 TEST_F(WebContentsImplTest, NTPViewSource) { |
332 NavigationControllerImpl& cont = | 314 NavigationControllerImpl& cont = |
333 static_cast<NavigationControllerImpl&>(controller()); | 315 static_cast<NavigationControllerImpl&>(controller()); |
334 const char kUrl[] = "view-source:webcontentsimpltest://blah"; | 316 const char kUrl[] = "view-source:webcontentsimpltest://blah"; |
335 const GURL kGURL(kUrl); | 317 const GURL kGURL(kUrl); |
336 | 318 |
337 process()->sink().ClearMessages(); | 319 process()->sink().ClearMessages(); |
338 | 320 |
339 cont.LoadURL( | 321 cont.LoadURL( |
340 kGURL, content::Referrer(), content::PAGE_TRANSITION_TYPED, | 322 kGURL, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
341 std::string()); | |
342 rvh()->GetDelegate()->RenderViewCreated(rvh()); | 323 rvh()->GetDelegate()->RenderViewCreated(rvh()); |
343 // Did we get the expected message? | 324 // Did we get the expected message? |
344 EXPECT_TRUE(process()->sink().GetFirstMessageMatching( | 325 EXPECT_TRUE(process()->sink().GetFirstMessageMatching( |
345 ViewMsg_EnableViewSourceMode::ID)); | 326 ViewMsg_EnableViewSourceMode::ID)); |
346 | 327 |
347 ViewHostMsg_FrameNavigate_Params params; | 328 ViewHostMsg_FrameNavigate_Params params; |
348 InitNavigateParams(¶ms, 0, kGURL, content::PAGE_TRANSITION_TYPED); | 329 InitNavigateParams(¶ms, 0, kGURL, PAGE_TRANSITION_TYPED); |
349 content::LoadCommittedDetails details; | 330 LoadCommittedDetails details; |
350 cont.RendererDidNavigate(params, &details); | 331 cont.RendererDidNavigate(params, &details); |
351 // Also check title and url. | 332 // Also check title and url. |
352 EXPECT_EQ(ASCIIToUTF16(kUrl), contents()->GetTitle()); | 333 EXPECT_EQ(ASCIIToUTF16(kUrl), contents()->GetTitle()); |
353 } | 334 } |
354 | 335 |
355 // Test to ensure UpdateMaxPageID is working properly. | 336 // Test to ensure UpdateMaxPageID is working properly. |
356 TEST_F(WebContentsImplTest, UpdateMaxPageID) { | 337 TEST_F(WebContentsImplTest, UpdateMaxPageID) { |
357 SiteInstance* instance1 = contents()->GetSiteInstance(); | 338 SiteInstance* instance1 = contents()->GetSiteInstance(); |
358 scoped_refptr<SiteInstance> instance2(SiteInstance::Create(NULL)); | 339 scoped_refptr<SiteInstance> instance2(SiteInstance::Create(NULL)); |
359 | 340 |
(...skipping 17 matching lines...) Expand all Loading... |
377 | 358 |
378 // Test simple same-SiteInstance navigation. | 359 // Test simple same-SiteInstance navigation. |
379 TEST_F(WebContentsImplTest, SimpleNavigation) { | 360 TEST_F(WebContentsImplTest, SimpleNavigation) { |
380 TestRenderViewHost* orig_rvh = test_rvh(); | 361 TestRenderViewHost* orig_rvh = test_rvh(); |
381 SiteInstance* instance1 = contents()->GetSiteInstance(); | 362 SiteInstance* instance1 = contents()->GetSiteInstance(); |
382 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); | 363 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); |
383 | 364 |
384 // Navigate to URL | 365 // Navigate to URL |
385 const GURL url("http://www.google.com"); | 366 const GURL url("http://www.google.com"); |
386 controller().LoadURL( | 367 controller().LoadURL( |
387 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 368 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
388 EXPECT_FALSE(contents()->cross_navigation_pending()); | 369 EXPECT_FALSE(contents()->cross_navigation_pending()); |
389 EXPECT_EQ(instance1, orig_rvh->GetSiteInstance()); | 370 EXPECT_EQ(instance1, orig_rvh->GetSiteInstance()); |
390 // Controller's pending entry will have a NULL site instance until we assign | 371 // Controller's pending entry will have a NULL site instance until we assign |
391 // it in DidNavigate. | 372 // it in DidNavigate. |
392 EXPECT_TRUE( | 373 EXPECT_TRUE( |
393 NavigationEntryImpl::FromNavigationEntry(controller().GetActiveEntry())-> | 374 NavigationEntryImpl::FromNavigationEntry(controller().GetActiveEntry())-> |
394 site_instance() == NULL); | 375 site_instance() == NULL); |
395 | 376 |
396 // DidNavigate from the page | 377 // DidNavigate from the page |
397 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); | 378 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
398 EXPECT_FALSE(contents()->cross_navigation_pending()); | 379 EXPECT_FALSE(contents()->cross_navigation_pending()); |
399 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 380 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
400 EXPECT_EQ(instance1, orig_rvh->GetSiteInstance()); | 381 EXPECT_EQ(instance1, orig_rvh->GetSiteInstance()); |
401 // Controller's entry should now have the SiteInstance, or else we won't be | 382 // Controller's entry should now have the SiteInstance, or else we won't be |
402 // able to find it later. | 383 // able to find it later. |
403 EXPECT_EQ( | 384 EXPECT_EQ( |
404 instance1, | 385 instance1, |
405 NavigationEntryImpl::FromNavigationEntry(controller().GetActiveEntry())-> | 386 NavigationEntryImpl::FromNavigationEntry(controller().GetActiveEntry())-> |
406 site_instance()); | 387 site_instance()); |
407 } | 388 } |
408 | 389 |
409 // Test that we reject NavigateToEntry if the url is over content::kMaxURLChars. | 390 // Test that we reject NavigateToEntry if the url is over kMaxURLChars. |
410 TEST_F(WebContentsImplTest, NavigateToExcessivelyLongURL) { | 391 TEST_F(WebContentsImplTest, NavigateToExcessivelyLongURL) { |
411 // Construct a URL that's kMaxURLChars + 1 long of all 'a's. | 392 // Construct a URL that's kMaxURLChars + 1 long of all 'a's. |
412 const GURL url(std::string("http://example.org/").append( | 393 const GURL url(std::string("http://example.org/").append( |
413 content::kMaxURLChars + 1, 'a')); | 394 kMaxURLChars + 1, 'a')); |
414 | 395 |
415 controller().LoadURL( | 396 controller().LoadURL( |
416 url, content::Referrer(), content::PAGE_TRANSITION_GENERATED, | 397 url, Referrer(), PAGE_TRANSITION_GENERATED, std::string()); |
417 std::string()); | |
418 EXPECT_TRUE(controller().GetActiveEntry() == NULL); | 398 EXPECT_TRUE(controller().GetActiveEntry() == NULL); |
419 } | 399 } |
420 | 400 |
421 // Test that navigating across a site boundary creates a new RenderViewHost | 401 // Test that navigating across a site boundary creates a new RenderViewHost |
422 // with a new SiteInstance. Going back should do the same. | 402 // with a new SiteInstance. Going back should do the same. |
423 TEST_F(WebContentsImplTest, CrossSiteBoundaries) { | 403 TEST_F(WebContentsImplTest, CrossSiteBoundaries) { |
424 contents()->transition_cross_site = true; | 404 contents()->transition_cross_site = true; |
425 TestRenderViewHost* orig_rvh = test_rvh(); | 405 TestRenderViewHost* orig_rvh = test_rvh(); |
426 int orig_rvh_delete_count = 0; | 406 int orig_rvh_delete_count = 0; |
427 orig_rvh->set_delete_counter(&orig_rvh_delete_count); | 407 orig_rvh->set_delete_counter(&orig_rvh_delete_count); |
428 SiteInstance* instance1 = contents()->GetSiteInstance(); | 408 SiteInstance* instance1 = contents()->GetSiteInstance(); |
429 | 409 |
430 // Navigate to URL. First URL should use first RenderViewHost. | 410 // Navigate to URL. First URL should use first RenderViewHost. |
431 const GURL url("http://www.google.com"); | 411 const GURL url("http://www.google.com"); |
432 controller().LoadURL( | 412 controller().LoadURL( |
433 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 413 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
434 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); | 414 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
435 | 415 |
436 EXPECT_FALSE(contents()->cross_navigation_pending()); | 416 EXPECT_FALSE(contents()->cross_navigation_pending()); |
437 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 417 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
438 | 418 |
439 // Navigate to new site | 419 // Navigate to new site |
440 const GURL url2("http://www.yahoo.com"); | 420 const GURL url2("http://www.yahoo.com"); |
441 controller().LoadURL( | 421 controller().LoadURL( |
442 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 422 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
443 EXPECT_TRUE(contents()->cross_navigation_pending()); | 423 EXPECT_TRUE(contents()->cross_navigation_pending()); |
444 TestRenderViewHost* pending_rvh = | 424 TestRenderViewHost* pending_rvh = |
445 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); | 425 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); |
446 int pending_rvh_delete_count = 0; | 426 int pending_rvh_delete_count = 0; |
447 pending_rvh->set_delete_counter(&pending_rvh_delete_count); | 427 pending_rvh->set_delete_counter(&pending_rvh_delete_count); |
448 | 428 |
449 // Navigations should be suspended in pending_rvh until ShouldCloseACK. | 429 // Navigations should be suspended in pending_rvh until ShouldCloseACK. |
450 EXPECT_TRUE(pending_rvh->are_navigations_suspended()); | 430 EXPECT_TRUE(pending_rvh->are_navigations_suspended()); |
451 orig_rvh->SendShouldCloseACK(true); | 431 orig_rvh->SendShouldCloseACK(true); |
452 EXPECT_FALSE(pending_rvh->are_navigations_suspended()); | 432 EXPECT_FALSE(pending_rvh->are_navigations_suspended()); |
453 | 433 |
454 // DidNavigate from the pending page | 434 // DidNavigate from the pending page |
455 contents()->TestDidNavigate( | 435 contents()->TestDidNavigate( |
456 pending_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); | 436 pending_rvh, 1, url2, PAGE_TRANSITION_TYPED); |
457 SiteInstance* instance2 = contents()->GetSiteInstance(); | 437 SiteInstance* instance2 = contents()->GetSiteInstance(); |
458 | 438 |
459 EXPECT_FALSE(contents()->cross_navigation_pending()); | 439 EXPECT_FALSE(contents()->cross_navigation_pending()); |
460 EXPECT_EQ(pending_rvh, contents()->GetRenderViewHost()); | 440 EXPECT_EQ(pending_rvh, contents()->GetRenderViewHost()); |
461 EXPECT_NE(instance1, instance2); | 441 EXPECT_NE(instance1, instance2); |
462 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); | 442 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); |
463 // We keep the original RVH around, swapped out. | 443 // We keep the original RVH around, swapped out. |
464 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsSwappedOut(orig_rvh)); | 444 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsSwappedOut(orig_rvh)); |
465 EXPECT_EQ(orig_rvh_delete_count, 0); | 445 EXPECT_EQ(orig_rvh_delete_count, 0); |
466 | 446 |
467 // Going back should switch SiteInstances again. The first SiteInstance is | 447 // Going back should switch SiteInstances again. The first SiteInstance is |
468 // stored in the NavigationEntry, so it should be the same as at the start. | 448 // stored in the NavigationEntry, so it should be the same as at the start. |
469 // We should use the same RVH as before, swapping it back in. | 449 // We should use the same RVH as before, swapping it back in. |
470 controller().GoBack(); | 450 controller().GoBack(); |
471 TestRenderViewHost* goback_rvh = | 451 TestRenderViewHost* goback_rvh = |
472 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); | 452 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); |
473 EXPECT_EQ(orig_rvh, goback_rvh); | 453 EXPECT_EQ(orig_rvh, goback_rvh); |
474 EXPECT_TRUE(contents()->cross_navigation_pending()); | 454 EXPECT_TRUE(contents()->cross_navigation_pending()); |
475 | 455 |
476 // Navigations should be suspended in goback_rvh until ShouldCloseACK. | 456 // Navigations should be suspended in goback_rvh until ShouldCloseACK. |
477 EXPECT_TRUE(goback_rvh->are_navigations_suspended()); | 457 EXPECT_TRUE(goback_rvh->are_navigations_suspended()); |
478 pending_rvh->SendShouldCloseACK(true); | 458 pending_rvh->SendShouldCloseACK(true); |
479 EXPECT_FALSE(goback_rvh->are_navigations_suspended()); | 459 EXPECT_FALSE(goback_rvh->are_navigations_suspended()); |
480 | 460 |
481 // DidNavigate from the back action | 461 // DidNavigate from the back action |
482 contents()->TestDidNavigate( | 462 contents()->TestDidNavigate( |
483 goback_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); | 463 goback_rvh, 1, url2, PAGE_TRANSITION_TYPED); |
484 EXPECT_FALSE(contents()->cross_navigation_pending()); | 464 EXPECT_FALSE(contents()->cross_navigation_pending()); |
485 EXPECT_EQ(goback_rvh, contents()->GetRenderViewHost()); | 465 EXPECT_EQ(goback_rvh, contents()->GetRenderViewHost()); |
486 EXPECT_EQ(instance1, contents()->GetSiteInstance()); | 466 EXPECT_EQ(instance1, contents()->GetSiteInstance()); |
487 // The pending RVH should now be swapped out, not deleted. | 467 // The pending RVH should now be swapped out, not deleted. |
488 EXPECT_TRUE(contents()->GetRenderManagerForTesting()-> | 468 EXPECT_TRUE(contents()->GetRenderManagerForTesting()-> |
489 IsSwappedOut(pending_rvh)); | 469 IsSwappedOut(pending_rvh)); |
490 EXPECT_EQ(pending_rvh_delete_count, 0); | 470 EXPECT_EQ(pending_rvh_delete_count, 0); |
491 | 471 |
492 // Close contents and ensure RVHs are deleted. | 472 // Close contents and ensure RVHs are deleted. |
493 DeleteContents(); | 473 DeleteContents(); |
494 EXPECT_EQ(orig_rvh_delete_count, 1); | 474 EXPECT_EQ(orig_rvh_delete_count, 1); |
495 EXPECT_EQ(pending_rvh_delete_count, 1); | 475 EXPECT_EQ(pending_rvh_delete_count, 1); |
496 } | 476 } |
497 | 477 |
498 // Test that navigating across a site boundary after a crash creates a new | 478 // Test that navigating across a site boundary after a crash creates a new |
499 // RVH without requiring a cross-site transition (i.e., PENDING state). | 479 // RVH without requiring a cross-site transition (i.e., PENDING state). |
500 TEST_F(WebContentsImplTest, CrossSiteBoundariesAfterCrash) { | 480 TEST_F(WebContentsImplTest, CrossSiteBoundariesAfterCrash) { |
501 contents()->transition_cross_site = true; | 481 contents()->transition_cross_site = true; |
502 TestRenderViewHost* orig_rvh = test_rvh(); | 482 TestRenderViewHost* orig_rvh = test_rvh(); |
503 int orig_rvh_delete_count = 0; | 483 int orig_rvh_delete_count = 0; |
504 orig_rvh->set_delete_counter(&orig_rvh_delete_count); | 484 orig_rvh->set_delete_counter(&orig_rvh_delete_count); |
505 SiteInstance* instance1 = contents()->GetSiteInstance(); | 485 SiteInstance* instance1 = contents()->GetSiteInstance(); |
506 | 486 |
507 // Navigate to URL. First URL should use first RenderViewHost. | 487 // Navigate to URL. First URL should use first RenderViewHost. |
508 const GURL url("http://www.google.com"); | 488 const GURL url("http://www.google.com"); |
509 controller().LoadURL( | 489 controller().LoadURL( |
510 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 490 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
511 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); | 491 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
512 | 492 |
513 EXPECT_FALSE(contents()->cross_navigation_pending()); | 493 EXPECT_FALSE(contents()->cross_navigation_pending()); |
514 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 494 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
515 | 495 |
516 // Crash the renderer. | 496 // Crash the renderer. |
517 orig_rvh->set_render_view_created(false); | 497 orig_rvh->set_render_view_created(false); |
518 | 498 |
519 // Navigate to new site. We should not go into PENDING. | 499 // Navigate to new site. We should not go into PENDING. |
520 const GURL url2("http://www.yahoo.com"); | 500 const GURL url2("http://www.yahoo.com"); |
521 controller().LoadURL( | 501 controller().LoadURL( |
522 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 502 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
523 RenderViewHost* new_rvh = rvh(); | 503 RenderViewHost* new_rvh = rvh(); |
524 EXPECT_FALSE(contents()->cross_navigation_pending()); | 504 EXPECT_FALSE(contents()->cross_navigation_pending()); |
525 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); | 505 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); |
526 EXPECT_NE(orig_rvh, new_rvh); | 506 EXPECT_NE(orig_rvh, new_rvh); |
527 EXPECT_EQ(orig_rvh_delete_count, 1); | 507 EXPECT_EQ(orig_rvh_delete_count, 1); |
528 | 508 |
529 // DidNavigate from the new page | 509 // DidNavigate from the new page |
530 contents()->TestDidNavigate(new_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); | 510 contents()->TestDidNavigate(new_rvh, 1, url2, PAGE_TRANSITION_TYPED); |
531 SiteInstance* instance2 = contents()->GetSiteInstance(); | 511 SiteInstance* instance2 = contents()->GetSiteInstance(); |
532 | 512 |
533 EXPECT_FALSE(contents()->cross_navigation_pending()); | 513 EXPECT_FALSE(contents()->cross_navigation_pending()); |
534 EXPECT_EQ(new_rvh, rvh()); | 514 EXPECT_EQ(new_rvh, rvh()); |
535 EXPECT_NE(instance1, instance2); | 515 EXPECT_NE(instance1, instance2); |
536 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); | 516 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); |
537 | 517 |
538 // Close contents and ensure RVHs are deleted. | 518 // Close contents and ensure RVHs are deleted. |
539 DeleteContents(); | 519 DeleteContents(); |
540 EXPECT_EQ(orig_rvh_delete_count, 1); | 520 EXPECT_EQ(orig_rvh_delete_count, 1); |
541 } | 521 } |
542 | 522 |
543 // Test that opening a new contents in the same SiteInstance and then navigating | 523 // Test that opening a new contents in the same SiteInstance and then navigating |
544 // both contentses to a new site will place both contentses in a single | 524 // both contentses to a new site will place both contentses in a single |
545 // SiteInstance. | 525 // SiteInstance. |
546 TEST_F(WebContentsImplTest, NavigateTwoTabsCrossSite) { | 526 TEST_F(WebContentsImplTest, NavigateTwoTabsCrossSite) { |
547 contents()->transition_cross_site = true; | 527 contents()->transition_cross_site = true; |
548 TestRenderViewHost* orig_rvh = test_rvh(); | 528 TestRenderViewHost* orig_rvh = test_rvh(); |
549 SiteInstance* instance1 = contents()->GetSiteInstance(); | 529 SiteInstance* instance1 = contents()->GetSiteInstance(); |
550 | 530 |
551 // Navigate to URL. First URL should use first RenderViewHost. | 531 // Navigate to URL. First URL should use first RenderViewHost. |
552 const GURL url("http://www.google.com"); | 532 const GURL url("http://www.google.com"); |
553 controller().LoadURL( | 533 controller().LoadURL( |
554 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 534 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
555 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); | 535 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
556 | 536 |
557 // Open a new contents with the same SiteInstance, navigated to the same site. | 537 // Open a new contents with the same SiteInstance, navigated to the same site. |
558 scoped_ptr<TestWebContents> contents2( | 538 scoped_ptr<TestWebContents> contents2( |
559 TestWebContents::Create(browser_context_.get(), instance1)); | 539 TestWebContents::Create(browser_context_.get(), instance1)); |
560 contents2->transition_cross_site = true; | 540 contents2->transition_cross_site = true; |
561 contents2->GetController().LoadURL(url, content::Referrer(), | 541 contents2->GetController().LoadURL(url, Referrer(), |
562 content::PAGE_TRANSITION_TYPED, | 542 PAGE_TRANSITION_TYPED, |
563 std::string()); | 543 std::string()); |
564 // Need this page id to be 2 since the site instance is the same (which is the | 544 // Need this page id to be 2 since the site instance is the same (which is the |
565 // scope of page IDs) and we want to consider this a new page. | 545 // scope of page IDs) and we want to consider this a new page. |
566 contents2->TestDidNavigate( | 546 contents2->TestDidNavigate( |
567 contents2->GetRenderViewHost(), 2, url, content::PAGE_TRANSITION_TYPED); | 547 contents2->GetRenderViewHost(), 2, url, PAGE_TRANSITION_TYPED); |
568 | 548 |
569 // Navigate first contents to a new site. | 549 // Navigate first contents to a new site. |
570 const GURL url2a("http://www.yahoo.com"); | 550 const GURL url2a("http://www.yahoo.com"); |
571 controller().LoadURL( | 551 controller().LoadURL( |
572 url2a, content::Referrer(), content::PAGE_TRANSITION_TYPED, | 552 url2a, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
573 std::string()); | |
574 orig_rvh->SendShouldCloseACK(true); | 553 orig_rvh->SendShouldCloseACK(true); |
575 TestRenderViewHost* pending_rvh_a = | 554 TestRenderViewHost* pending_rvh_a = |
576 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); | 555 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); |
577 contents()->TestDidNavigate( | 556 contents()->TestDidNavigate( |
578 pending_rvh_a, 1, url2a, content::PAGE_TRANSITION_TYPED); | 557 pending_rvh_a, 1, url2a, PAGE_TRANSITION_TYPED); |
579 SiteInstance* instance2a = contents()->GetSiteInstance(); | 558 SiteInstance* instance2a = contents()->GetSiteInstance(); |
580 EXPECT_NE(instance1, instance2a); | 559 EXPECT_NE(instance1, instance2a); |
581 | 560 |
582 // Navigate second contents to the same site as the first tab. | 561 // Navigate second contents to the same site as the first tab. |
583 const GURL url2b("http://mail.yahoo.com"); | 562 const GURL url2b("http://mail.yahoo.com"); |
584 contents2->GetController().LoadURL(url2b, content::Referrer(), | 563 contents2->GetController().LoadURL(url2b, Referrer(), |
585 content::PAGE_TRANSITION_TYPED, | 564 PAGE_TRANSITION_TYPED, |
586 std::string()); | 565 std::string()); |
587 TestRenderViewHost* rvh2 = | 566 TestRenderViewHost* rvh2 = |
588 static_cast<TestRenderViewHost*>(contents2->GetRenderViewHost()); | 567 static_cast<TestRenderViewHost*>(contents2->GetRenderViewHost()); |
589 rvh2->SendShouldCloseACK(true); | 568 rvh2->SendShouldCloseACK(true); |
590 TestRenderViewHost* pending_rvh_b = | 569 TestRenderViewHost* pending_rvh_b = |
591 static_cast<TestRenderViewHost*>(contents2->GetPendingRenderViewHost()); | 570 static_cast<TestRenderViewHost*>(contents2->GetPendingRenderViewHost()); |
592 EXPECT_TRUE(pending_rvh_b != NULL); | 571 EXPECT_TRUE(pending_rvh_b != NULL); |
593 EXPECT_TRUE(contents2->cross_navigation_pending()); | 572 EXPECT_TRUE(contents2->cross_navigation_pending()); |
594 | 573 |
595 // NOTE(creis): We used to be in danger of showing a crash page here if the | 574 // NOTE(creis): We used to be in danger of showing a crash page here if the |
596 // second contents hadn't navigated somewhere first (bug 1145430). That case | 575 // second contents hadn't navigated somewhere first (bug 1145430). That case |
597 // is now covered by the CrossSiteBoundariesAfterCrash test. | 576 // is now covered by the CrossSiteBoundariesAfterCrash test. |
598 contents2->TestDidNavigate( | 577 contents2->TestDidNavigate( |
599 pending_rvh_b, 2, url2b, content::PAGE_TRANSITION_TYPED); | 578 pending_rvh_b, 2, url2b, PAGE_TRANSITION_TYPED); |
600 SiteInstance* instance2b = contents2->GetSiteInstance(); | 579 SiteInstance* instance2b = contents2->GetSiteInstance(); |
601 EXPECT_NE(instance1, instance2b); | 580 EXPECT_NE(instance1, instance2b); |
602 | 581 |
603 // Both contentses should now be in the same SiteInstance. | 582 // Both contentses should now be in the same SiteInstance. |
604 EXPECT_EQ(instance2a, instance2b); | 583 EXPECT_EQ(instance2a, instance2b); |
605 } | 584 } |
606 | 585 |
607 // Tests that WebContentsImpl uses the current URL, not the SiteInstance's site, | 586 // Tests that WebContentsImpl uses the current URL, not the SiteInstance's site, |
608 // to determine whether a navigation is cross-site. | 587 // to determine whether a navigation is cross-site. |
609 TEST_F(WebContentsImplTest, CrossSiteComparesAgainstCurrentPage) { | 588 TEST_F(WebContentsImplTest, CrossSiteComparesAgainstCurrentPage) { |
610 contents()->transition_cross_site = true; | 589 contents()->transition_cross_site = true; |
611 RenderViewHost* orig_rvh = rvh(); | 590 RenderViewHost* orig_rvh = rvh(); |
612 SiteInstance* instance1 = contents()->GetSiteInstance(); | 591 SiteInstance* instance1 = contents()->GetSiteInstance(); |
613 | 592 |
614 // Navigate to URL. | 593 // Navigate to URL. |
615 const GURL url("http://www.google.com"); | 594 const GURL url("http://www.google.com"); |
616 controller().LoadURL( | 595 controller().LoadURL( |
617 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 596 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
618 contents()->TestDidNavigate( | 597 contents()->TestDidNavigate( |
619 orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); | 598 orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
620 | 599 |
621 // Open a related contents to a second site. | 600 // Open a related contents to a second site. |
622 scoped_ptr<TestWebContents> contents2( | 601 scoped_ptr<TestWebContents> contents2( |
623 TestWebContents::Create(browser_context_.get(), instance1)); | 602 TestWebContents::Create(browser_context_.get(), instance1)); |
624 contents2->transition_cross_site = true; | 603 contents2->transition_cross_site = true; |
625 const GURL url2("http://www.yahoo.com"); | 604 const GURL url2("http://www.yahoo.com"); |
626 contents2->GetController().LoadURL(url2, content::Referrer(), | 605 contents2->GetController().LoadURL(url2, Referrer(), |
627 content::PAGE_TRANSITION_TYPED, | 606 PAGE_TRANSITION_TYPED, |
628 std::string()); | 607 std::string()); |
629 // The first RVH in contents2 isn't live yet, so we shortcut the cross site | 608 // The first RVH in contents2 isn't live yet, so we shortcut the cross site |
630 // pending. | 609 // pending. |
631 TestRenderViewHost* rvh2 = static_cast<TestRenderViewHost*>( | 610 TestRenderViewHost* rvh2 = static_cast<TestRenderViewHost*>( |
632 contents2->GetRenderViewHost()); | 611 contents2->GetRenderViewHost()); |
633 EXPECT_FALSE(contents2->cross_navigation_pending()); | 612 EXPECT_FALSE(contents2->cross_navigation_pending()); |
634 contents2->TestDidNavigate(rvh2, 2, url2, content::PAGE_TRANSITION_TYPED); | 613 contents2->TestDidNavigate(rvh2, 2, url2, PAGE_TRANSITION_TYPED); |
635 SiteInstance* instance2 = contents2->GetSiteInstance(); | 614 SiteInstance* instance2 = contents2->GetSiteInstance(); |
636 EXPECT_NE(instance1, instance2); | 615 EXPECT_NE(instance1, instance2); |
637 EXPECT_FALSE(contents2->cross_navigation_pending()); | 616 EXPECT_FALSE(contents2->cross_navigation_pending()); |
638 | 617 |
639 // Simulate a link click in first contents to second site. Doesn't switch | 618 // Simulate a link click in first contents to second site. Doesn't switch |
640 // SiteInstances, because we don't intercept WebKit navigations. | 619 // SiteInstances, because we don't intercept WebKit navigations. |
641 contents()->TestDidNavigate( | 620 contents()->TestDidNavigate( |
642 orig_rvh, 2, url2, content::PAGE_TRANSITION_TYPED); | 621 orig_rvh, 2, url2, PAGE_TRANSITION_TYPED); |
643 SiteInstance* instance3 = contents()->GetSiteInstance(); | 622 SiteInstance* instance3 = contents()->GetSiteInstance(); |
644 EXPECT_EQ(instance1, instance3); | 623 EXPECT_EQ(instance1, instance3); |
645 EXPECT_FALSE(contents()->cross_navigation_pending()); | 624 EXPECT_FALSE(contents()->cross_navigation_pending()); |
646 | 625 |
647 // Navigate to the new site. Doesn't switch SiteInstancees, because we | 626 // Navigate to the new site. Doesn't switch SiteInstancees, because we |
648 // compare against the current URL, not the SiteInstance's site. | 627 // compare against the current URL, not the SiteInstance's site. |
649 const GURL url3("http://mail.yahoo.com"); | 628 const GURL url3("http://mail.yahoo.com"); |
650 controller().LoadURL( | 629 controller().LoadURL( |
651 url3, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 630 url3, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
652 EXPECT_FALSE(contents()->cross_navigation_pending()); | 631 EXPECT_FALSE(contents()->cross_navigation_pending()); |
653 contents()->TestDidNavigate( | 632 contents()->TestDidNavigate( |
654 orig_rvh, 3, url3, content::PAGE_TRANSITION_TYPED); | 633 orig_rvh, 3, url3, PAGE_TRANSITION_TYPED); |
655 SiteInstance* instance4 = contents()->GetSiteInstance(); | 634 SiteInstance* instance4 = contents()->GetSiteInstance(); |
656 EXPECT_EQ(instance1, instance4); | 635 EXPECT_EQ(instance1, instance4); |
657 } | 636 } |
658 | 637 |
659 // Test that the onbeforeunload and onunload handlers run when navigating | 638 // Test that the onbeforeunload and onunload handlers run when navigating |
660 // across site boundaries. | 639 // across site boundaries. |
661 TEST_F(WebContentsImplTest, CrossSiteUnloadHandlers) { | 640 TEST_F(WebContentsImplTest, CrossSiteUnloadHandlers) { |
662 contents()->transition_cross_site = true; | 641 contents()->transition_cross_site = true; |
663 TestRenderViewHost* orig_rvh = test_rvh(); | 642 TestRenderViewHost* orig_rvh = test_rvh(); |
664 SiteInstance* instance1 = contents()->GetSiteInstance(); | 643 SiteInstance* instance1 = contents()->GetSiteInstance(); |
665 | 644 |
666 // Navigate to URL. First URL should use first RenderViewHost. | 645 // Navigate to URL. First URL should use first RenderViewHost. |
667 const GURL url("http://www.google.com"); | 646 const GURL url("http://www.google.com"); |
668 controller().LoadURL( | 647 controller().LoadURL( |
669 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 648 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
670 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); | 649 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
671 EXPECT_FALSE(contents()->cross_navigation_pending()); | 650 EXPECT_FALSE(contents()->cross_navigation_pending()); |
672 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 651 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
673 | 652 |
674 // Navigate to new site, but simulate an onbeforeunload denial. | 653 // Navigate to new site, but simulate an onbeforeunload denial. |
675 const GURL url2("http://www.yahoo.com"); | 654 const GURL url2("http://www.yahoo.com"); |
676 controller().LoadURL( | 655 controller().LoadURL( |
677 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 656 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
678 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 657 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
679 orig_rvh->OnMessageReceived(ViewHostMsg_ShouldClose_ACK( | 658 orig_rvh->OnMessageReceived(ViewHostMsg_ShouldClose_ACK( |
680 0, false, base::TimeTicks(), base::TimeTicks())); | 659 0, false, base::TimeTicks(), base::TimeTicks())); |
681 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 660 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
682 EXPECT_FALSE(contents()->cross_navigation_pending()); | 661 EXPECT_FALSE(contents()->cross_navigation_pending()); |
683 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 662 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
684 | 663 |
685 // Navigate again, but simulate an onbeforeunload approval. | 664 // Navigate again, but simulate an onbeforeunload approval. |
686 controller().LoadURL( | 665 controller().LoadURL( |
687 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 666 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
688 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 667 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
689 orig_rvh->OnMessageReceived(ViewHostMsg_ShouldClose_ACK( | 668 orig_rvh->OnMessageReceived(ViewHostMsg_ShouldClose_ACK( |
690 0, true, base::TimeTicks(), base::TimeTicks())); | 669 0, true, base::TimeTicks(), base::TimeTicks())); |
691 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 670 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
692 EXPECT_TRUE(contents()->cross_navigation_pending()); | 671 EXPECT_TRUE(contents()->cross_navigation_pending()); |
693 TestRenderViewHost* pending_rvh = static_cast<TestRenderViewHost*>( | 672 TestRenderViewHost* pending_rvh = static_cast<TestRenderViewHost*>( |
694 contents()->GetPendingRenderViewHost()); | 673 contents()->GetPendingRenderViewHost()); |
695 | 674 |
696 // We won't hear DidNavigate until the onunload handler has finished running. | 675 // We won't hear DidNavigate until the onunload handler has finished running. |
697 // (No way to simulate that here, but it involves a call from RDH to | 676 // (No way to simulate that here, but it involves a call from RDH to |
698 // WebContentsImpl::OnCrossSiteResponse.) | 677 // WebContentsImpl::OnCrossSiteResponse.) |
699 | 678 |
700 // DidNavigate from the pending page | 679 // DidNavigate from the pending page |
701 contents()->TestDidNavigate( | 680 contents()->TestDidNavigate( |
702 pending_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); | 681 pending_rvh, 1, url2, PAGE_TRANSITION_TYPED); |
703 SiteInstance* instance2 = contents()->GetSiteInstance(); | 682 SiteInstance* instance2 = contents()->GetSiteInstance(); |
704 EXPECT_FALSE(contents()->cross_navigation_pending()); | 683 EXPECT_FALSE(contents()->cross_navigation_pending()); |
705 EXPECT_EQ(pending_rvh, rvh()); | 684 EXPECT_EQ(pending_rvh, rvh()); |
706 EXPECT_NE(instance1, instance2); | 685 EXPECT_NE(instance1, instance2); |
707 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); | 686 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); |
708 } | 687 } |
709 | 688 |
710 // Test that during a slow cross-site navigation, the original renderer can | 689 // Test that during a slow cross-site navigation, the original renderer can |
711 // navigate to a different URL and have it displayed, canceling the slow | 690 // navigate to a different URL and have it displayed, canceling the slow |
712 // navigation. | 691 // navigation. |
713 TEST_F(WebContentsImplTest, CrossSiteNavigationPreempted) { | 692 TEST_F(WebContentsImplTest, CrossSiteNavigationPreempted) { |
714 contents()->transition_cross_site = true; | 693 contents()->transition_cross_site = true; |
715 TestRenderViewHost* orig_rvh = test_rvh(); | 694 TestRenderViewHost* orig_rvh = test_rvh(); |
716 SiteInstance* instance1 = contents()->GetSiteInstance(); | 695 SiteInstance* instance1 = contents()->GetSiteInstance(); |
717 | 696 |
718 // Navigate to URL. First URL should use first RenderViewHost. | 697 // Navigate to URL. First URL should use first RenderViewHost. |
719 const GURL url("http://www.google.com"); | 698 const GURL url("http://www.google.com"); |
720 controller().LoadURL( | 699 controller().LoadURL( |
721 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 700 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
722 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); | 701 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
723 EXPECT_FALSE(contents()->cross_navigation_pending()); | 702 EXPECT_FALSE(contents()->cross_navigation_pending()); |
724 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 703 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
725 | 704 |
726 // Navigate to new site, simulating an onbeforeunload approval. | 705 // Navigate to new site, simulating an onbeforeunload approval. |
727 const GURL url2("http://www.yahoo.com"); | 706 const GURL url2("http://www.yahoo.com"); |
728 controller().LoadURL( | 707 controller().LoadURL( |
729 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 708 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
730 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 709 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
731 orig_rvh->OnMessageReceived(ViewHostMsg_ShouldClose_ACK( | 710 orig_rvh->OnMessageReceived(ViewHostMsg_ShouldClose_ACK( |
732 0, true, base::TimeTicks(), base::TimeTicks())); | 711 0, true, base::TimeTicks(), base::TimeTicks())); |
733 EXPECT_TRUE(contents()->cross_navigation_pending()); | 712 EXPECT_TRUE(contents()->cross_navigation_pending()); |
734 | 713 |
735 // Suppose the original renderer navigates before the new one is ready. | 714 // Suppose the original renderer navigates before the new one is ready. |
736 orig_rvh->SendNavigate(2, GURL("http://www.google.com/foo")); | 715 orig_rvh->SendNavigate(2, GURL("http://www.google.com/foo")); |
737 | 716 |
738 // Verify that the pending navigation is cancelled. | 717 // Verify that the pending navigation is cancelled. |
739 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 718 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
740 SiteInstance* instance2 = contents()->GetSiteInstance(); | 719 SiteInstance* instance2 = contents()->GetSiteInstance(); |
741 EXPECT_FALSE(contents()->cross_navigation_pending()); | 720 EXPECT_FALSE(contents()->cross_navigation_pending()); |
742 EXPECT_EQ(orig_rvh, rvh()); | 721 EXPECT_EQ(orig_rvh, rvh()); |
743 EXPECT_EQ(instance1, instance2); | 722 EXPECT_EQ(instance1, instance2); |
744 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); | 723 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); |
745 } | 724 } |
746 | 725 |
747 TEST_F(WebContentsImplTest, CrossSiteNavigationBackPreempted) { | 726 TEST_F(WebContentsImplTest, CrossSiteNavigationBackPreempted) { |
748 contents()->transition_cross_site = true; | 727 contents()->transition_cross_site = true; |
749 | 728 |
750 // Start with a web ui page, which gets a new RVH with WebUI bindings. | 729 // Start with a web ui page, which gets a new RVH with WebUI bindings. |
751 const GURL url1("webcontentsimpltest://blah"); | 730 const GURL url1("webcontentsimpltest://blah"); |
752 controller().LoadURL( | 731 controller().LoadURL( |
753 url1, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 732 url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
754 TestRenderViewHost* ntp_rvh = test_rvh(); | 733 TestRenderViewHost* ntp_rvh = test_rvh(); |
755 contents()->TestDidNavigate(ntp_rvh, 1, url1, content::PAGE_TRANSITION_TYPED); | 734 contents()->TestDidNavigate(ntp_rvh, 1, url1, PAGE_TRANSITION_TYPED); |
756 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); | 735 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); |
757 SiteInstance* instance1 = contents()->GetSiteInstance(); | 736 SiteInstance* instance1 = contents()->GetSiteInstance(); |
758 | 737 |
759 EXPECT_FALSE(contents()->cross_navigation_pending()); | 738 EXPECT_FALSE(contents()->cross_navigation_pending()); |
760 EXPECT_EQ(ntp_rvh, contents()->GetRenderViewHost()); | 739 EXPECT_EQ(ntp_rvh, contents()->GetRenderViewHost()); |
761 EXPECT_EQ(url1, entry1->GetURL()); | 740 EXPECT_EQ(url1, entry1->GetURL()); |
762 EXPECT_EQ(instance1, | 741 EXPECT_EQ(instance1, |
763 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance()); | 742 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance()); |
764 EXPECT_TRUE(ntp_rvh->GetEnabledBindings() & content::BINDINGS_POLICY_WEB_UI); | 743 EXPECT_TRUE(ntp_rvh->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
765 | 744 |
766 // Navigate to new site. | 745 // Navigate to new site. |
767 const GURL url2("http://www.google.com"); | 746 const GURL url2("http://www.google.com"); |
768 controller().LoadURL( | 747 controller().LoadURL( |
769 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 748 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
770 EXPECT_TRUE(contents()->cross_navigation_pending()); | 749 EXPECT_TRUE(contents()->cross_navigation_pending()); |
771 TestRenderViewHost* google_rvh = | 750 TestRenderViewHost* google_rvh = |
772 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); | 751 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); |
773 | 752 |
774 // Simulate beforeunload approval. | 753 // Simulate beforeunload approval. |
775 EXPECT_TRUE(ntp_rvh->is_waiting_for_beforeunload_ack()); | 754 EXPECT_TRUE(ntp_rvh->is_waiting_for_beforeunload_ack()); |
776 ntp_rvh->OnMessageReceived(ViewHostMsg_ShouldClose_ACK( | 755 ntp_rvh->OnMessageReceived(ViewHostMsg_ShouldClose_ACK( |
777 0, true, base::TimeTicks(), base::TimeTicks())); | 756 0, true, base::TimeTicks(), base::TimeTicks())); |
778 | 757 |
779 // DidNavigate from the pending page. | 758 // DidNavigate from the pending page. |
780 contents()->TestDidNavigate( | 759 contents()->TestDidNavigate( |
781 google_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); | 760 google_rvh, 1, url2, PAGE_TRANSITION_TYPED); |
782 NavigationEntry* entry2 = controller().GetLastCommittedEntry(); | 761 NavigationEntry* entry2 = controller().GetLastCommittedEntry(); |
783 SiteInstance* instance2 = contents()->GetSiteInstance(); | 762 SiteInstance* instance2 = contents()->GetSiteInstance(); |
784 | 763 |
785 EXPECT_FALSE(contents()->cross_navigation_pending()); | 764 EXPECT_FALSE(contents()->cross_navigation_pending()); |
786 EXPECT_EQ(google_rvh, contents()->GetRenderViewHost()); | 765 EXPECT_EQ(google_rvh, contents()->GetRenderViewHost()); |
787 EXPECT_NE(instance1, instance2); | 766 EXPECT_NE(instance1, instance2); |
788 EXPECT_FALSE(contents()->GetPendingRenderViewHost()); | 767 EXPECT_FALSE(contents()->GetPendingRenderViewHost()); |
789 EXPECT_EQ(url2, entry2->GetURL()); | 768 EXPECT_EQ(url2, entry2->GetURL()); |
790 EXPECT_EQ(instance2, | 769 EXPECT_EQ(instance2, |
791 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance()); | 770 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance()); |
792 EXPECT_FALSE(google_rvh->GetEnabledBindings() & | 771 EXPECT_FALSE(google_rvh->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
793 content::BINDINGS_POLICY_WEB_UI); | |
794 | 772 |
795 // Navigate to third page on same site. | 773 // Navigate to third page on same site. |
796 const GURL url3("http://news.google.com"); | 774 const GURL url3("http://news.google.com"); |
797 controller().LoadURL( | 775 controller().LoadURL( |
798 url3, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 776 url3, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
799 EXPECT_FALSE(contents()->cross_navigation_pending()); | 777 EXPECT_FALSE(contents()->cross_navigation_pending()); |
800 contents()->TestDidNavigate( | 778 contents()->TestDidNavigate( |
801 google_rvh, 2, url3, content::PAGE_TRANSITION_TYPED); | 779 google_rvh, 2, url3, PAGE_TRANSITION_TYPED); |
802 NavigationEntry* entry3 = controller().GetLastCommittedEntry(); | 780 NavigationEntry* entry3 = controller().GetLastCommittedEntry(); |
803 SiteInstance* instance3 = contents()->GetSiteInstance(); | 781 SiteInstance* instance3 = contents()->GetSiteInstance(); |
804 | 782 |
805 EXPECT_FALSE(contents()->cross_navigation_pending()); | 783 EXPECT_FALSE(contents()->cross_navigation_pending()); |
806 EXPECT_EQ(google_rvh, contents()->GetRenderViewHost()); | 784 EXPECT_EQ(google_rvh, contents()->GetRenderViewHost()); |
807 EXPECT_EQ(instance2, instance3); | 785 EXPECT_EQ(instance2, instance3); |
808 EXPECT_FALSE(contents()->GetPendingRenderViewHost()); | 786 EXPECT_FALSE(contents()->GetPendingRenderViewHost()); |
809 EXPECT_EQ(url3, entry3->GetURL()); | 787 EXPECT_EQ(url3, entry3->GetURL()); |
810 EXPECT_EQ(instance3, | 788 EXPECT_EQ(instance3, |
811 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance()); | 789 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance()); |
812 | 790 |
813 // Go back within the site. | 791 // Go back within the site. |
814 controller().GoBack(); | 792 controller().GoBack(); |
815 EXPECT_FALSE(contents()->cross_navigation_pending()); | 793 EXPECT_FALSE(contents()->cross_navigation_pending()); |
816 EXPECT_EQ(entry2, controller().GetPendingEntry()); | 794 EXPECT_EQ(entry2, controller().GetPendingEntry()); |
817 | 795 |
818 // Before that commits, go back again. | 796 // Before that commits, go back again. |
819 controller().GoBack(); | 797 controller().GoBack(); |
820 EXPECT_TRUE(contents()->cross_navigation_pending()); | 798 EXPECT_TRUE(contents()->cross_navigation_pending()); |
821 EXPECT_TRUE(contents()->GetPendingRenderViewHost()); | 799 EXPECT_TRUE(contents()->GetPendingRenderViewHost()); |
822 EXPECT_EQ(entry1, controller().GetPendingEntry()); | 800 EXPECT_EQ(entry1, controller().GetPendingEntry()); |
823 | 801 |
824 // Simulate beforeunload approval. | 802 // Simulate beforeunload approval. |
825 EXPECT_TRUE(google_rvh->is_waiting_for_beforeunload_ack()); | 803 EXPECT_TRUE(google_rvh->is_waiting_for_beforeunload_ack()); |
826 google_rvh->OnMessageReceived(ViewHostMsg_ShouldClose_ACK( | 804 google_rvh->OnMessageReceived(ViewHostMsg_ShouldClose_ACK( |
827 0, true, base::TimeTicks(), base::TimeTicks())); | 805 0, true, base::TimeTicks(), base::TimeTicks())); |
828 | 806 |
829 // DidNavigate from the first back. This aborts the second back's pending RVH. | 807 // DidNavigate from the first back. This aborts the second back's pending RVH. |
830 contents()->TestDidNavigate( | 808 contents()->TestDidNavigate(google_rvh, 1, url2, PAGE_TRANSITION_TYPED); |
831 google_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); | |
832 | 809 |
833 // We should commit this page and forget about the second back. | 810 // We should commit this page and forget about the second back. |
834 EXPECT_FALSE(contents()->cross_navigation_pending()); | 811 EXPECT_FALSE(contents()->cross_navigation_pending()); |
835 EXPECT_FALSE(controller().GetPendingEntry()); | 812 EXPECT_FALSE(controller().GetPendingEntry()); |
836 EXPECT_EQ(google_rvh, contents()->GetRenderViewHost()); | 813 EXPECT_EQ(google_rvh, contents()->GetRenderViewHost()); |
837 EXPECT_EQ(url2, controller().GetLastCommittedEntry()->GetURL()); | 814 EXPECT_EQ(url2, controller().GetLastCommittedEntry()->GetURL()); |
838 | 815 |
839 // We should not have corrupted the NTP entry. | 816 // We should not have corrupted the NTP entry. |
840 EXPECT_EQ(instance3, | 817 EXPECT_EQ(instance3, |
841 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance()); | 818 NavigationEntryImpl::FromNavigationEntry(entry3)->site_instance()); |
842 EXPECT_EQ(instance2, | 819 EXPECT_EQ(instance2, |
843 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance()); | 820 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance()); |
844 EXPECT_EQ(instance1, | 821 EXPECT_EQ(instance1, |
845 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance()); | 822 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance()); |
846 EXPECT_EQ(url1, entry1->GetURL()); | 823 EXPECT_EQ(url1, entry1->GetURL()); |
847 } | 824 } |
848 | 825 |
849 // Test that during a slow cross-site navigation, a sub-frame navigation in the | 826 // Test that during a slow cross-site navigation, a sub-frame navigation in the |
850 // original renderer will not cancel the slow navigation (bug 42029). | 827 // original renderer will not cancel the slow navigation (bug 42029). |
851 TEST_F(WebContentsImplTest, CrossSiteNavigationNotPreemptedByFrame) { | 828 TEST_F(WebContentsImplTest, CrossSiteNavigationNotPreemptedByFrame) { |
852 contents()->transition_cross_site = true; | 829 contents()->transition_cross_site = true; |
853 TestRenderViewHost* orig_rvh = test_rvh(); | 830 TestRenderViewHost* orig_rvh = test_rvh(); |
854 | 831 |
855 // Navigate to URL. First URL should use first RenderViewHost. | 832 // Navigate to URL. First URL should use first RenderViewHost. |
856 const GURL url("http://www.google.com"); | 833 const GURL url("http://www.google.com"); |
857 controller().LoadURL( | 834 controller().LoadURL( |
858 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 835 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
859 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); | 836 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
860 EXPECT_FALSE(contents()->cross_navigation_pending()); | 837 EXPECT_FALSE(contents()->cross_navigation_pending()); |
861 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 838 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
862 | 839 |
863 // Start navigating to new site. | 840 // Start navigating to new site. |
864 const GURL url2("http://www.yahoo.com"); | 841 const GURL url2("http://www.yahoo.com"); |
865 controller().LoadURL( | 842 controller().LoadURL( |
866 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 843 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
867 | 844 |
868 // Simulate a sub-frame navigation arriving and ensure the RVH is still | 845 // Simulate a sub-frame navigation arriving and ensure the RVH is still |
869 // waiting for a before unload response. | 846 // waiting for a before unload response. |
870 orig_rvh->SendNavigateWithTransition(1, GURL("http://google.com/frame"), | 847 orig_rvh->SendNavigateWithTransition(1, GURL("http://google.com/frame"), |
871 content::PAGE_TRANSITION_AUTO_SUBFRAME); | 848 PAGE_TRANSITION_AUTO_SUBFRAME); |
872 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 849 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
873 | 850 |
874 // Now simulate the onbeforeunload approval and verify the navigation is | 851 // Now simulate the onbeforeunload approval and verify the navigation is |
875 // not canceled. | 852 // not canceled. |
876 orig_rvh->OnMessageReceived(ViewHostMsg_ShouldClose_ACK( | 853 orig_rvh->OnMessageReceived(ViewHostMsg_ShouldClose_ACK( |
877 0, true, base::TimeTicks(), base::TimeTicks())); | 854 0, true, base::TimeTicks(), base::TimeTicks())); |
878 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 855 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
879 EXPECT_TRUE(contents()->cross_navigation_pending()); | 856 EXPECT_TRUE(contents()->cross_navigation_pending()); |
880 } | 857 } |
881 | 858 |
882 // Test that a cross-site navigation is not preempted if the previous | 859 // Test that a cross-site navigation is not preempted if the previous |
883 // renderer sends a FrameNavigate message just before being told to stop. | 860 // renderer sends a FrameNavigate message just before being told to stop. |
884 // We should only preempt the cross-site navigation if the previous renderer | 861 // We should only preempt the cross-site navigation if the previous renderer |
885 // has started a new navigation. See http://crbug.com/79176. | 862 // has started a new navigation. See http://crbug.com/79176. |
886 TEST_F(WebContentsImplTest, CrossSiteNotPreemptedDuringBeforeUnload) { | 863 TEST_F(WebContentsImplTest, CrossSiteNotPreemptedDuringBeforeUnload) { |
887 contents()->transition_cross_site = true; | 864 contents()->transition_cross_site = true; |
888 | 865 |
889 // Navigate to NTP URL. | 866 // Navigate to NTP URL. |
890 const GURL url("webcontentsimpltest://blah"); | 867 const GURL url("webcontentsimpltest://blah"); |
891 controller().LoadURL( | 868 controller().LoadURL( |
892 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 869 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
893 TestRenderViewHost* orig_rvh = test_rvh(); | 870 TestRenderViewHost* orig_rvh = test_rvh(); |
894 EXPECT_FALSE(contents()->cross_navigation_pending()); | 871 EXPECT_FALSE(contents()->cross_navigation_pending()); |
895 | 872 |
896 // Navigate to new site, with the beforeunload request in flight. | 873 // Navigate to new site, with the beforeunload request in flight. |
897 const GURL url2("http://www.yahoo.com"); | 874 const GURL url2("http://www.yahoo.com"); |
898 controller().LoadURL( | 875 controller().LoadURL( |
899 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 876 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
900 TestRenderViewHost* pending_rvh = | 877 TestRenderViewHost* pending_rvh = |
901 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); | 878 static_cast<TestRenderViewHost*>(contents()->GetPendingRenderViewHost()); |
902 EXPECT_TRUE(contents()->cross_navigation_pending()); | 879 EXPECT_TRUE(contents()->cross_navigation_pending()); |
903 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 880 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
904 | 881 |
905 // Suppose the first navigation tries to commit now, with a | 882 // Suppose the first navigation tries to commit now, with a |
906 // ViewMsg_Stop in flight. This should not cancel the pending navigation, | 883 // ViewMsg_Stop in flight. This should not cancel the pending navigation, |
907 // but it should act as if the beforeunload ack arrived. | 884 // but it should act as if the beforeunload ack arrived. |
908 orig_rvh->SendNavigate(1, GURL("webcontentsimpltest://blah")); | 885 orig_rvh->SendNavigate(1, GURL("webcontentsimpltest://blah")); |
909 EXPECT_TRUE(contents()->cross_navigation_pending()); | 886 EXPECT_TRUE(contents()->cross_navigation_pending()); |
910 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 887 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
911 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 888 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
912 | 889 |
913 // The pending navigation should be able to commit successfully. | 890 // The pending navigation should be able to commit successfully. |
914 contents()->TestDidNavigate( | 891 contents()->TestDidNavigate(pending_rvh, 1, url2, PAGE_TRANSITION_TYPED); |
915 pending_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); | |
916 EXPECT_FALSE(contents()->cross_navigation_pending()); | 892 EXPECT_FALSE(contents()->cross_navigation_pending()); |
917 EXPECT_EQ(pending_rvh, contents()->GetRenderViewHost()); | 893 EXPECT_EQ(pending_rvh, contents()->GetRenderViewHost()); |
918 } | 894 } |
919 | 895 |
920 // Test that the original renderer cannot preempt a cross-site navigation once | 896 // Test that the original renderer cannot preempt a cross-site navigation once |
921 // the unload request has been made. At this point, the cross-site navigation | 897 // the unload request has been made. At this point, the cross-site navigation |
922 // is almost ready to be displayed, and the original renderer is only given a | 898 // is almost ready to be displayed, and the original renderer is only given a |
923 // short chance to run an unload handler. Prevents regression of bug 23942. | 899 // short chance to run an unload handler. Prevents regression of bug 23942. |
924 TEST_F(WebContentsImplTest, CrossSiteCantPreemptAfterUnload) { | 900 TEST_F(WebContentsImplTest, CrossSiteCantPreemptAfterUnload) { |
925 contents()->transition_cross_site = true; | 901 contents()->transition_cross_site = true; |
926 TestRenderViewHost* orig_rvh = test_rvh(); | 902 TestRenderViewHost* orig_rvh = test_rvh(); |
927 SiteInstance* instance1 = contents()->GetSiteInstance(); | 903 SiteInstance* instance1 = contents()->GetSiteInstance(); |
928 | 904 |
929 // Navigate to URL. First URL should use first RenderViewHost. | 905 // Navigate to URL. First URL should use first RenderViewHost. |
930 const GURL url("http://www.google.com"); | 906 const GURL url("http://www.google.com"); |
931 controller().LoadURL( | 907 controller().LoadURL( |
932 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 908 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
933 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); | 909 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
934 EXPECT_FALSE(contents()->cross_navigation_pending()); | 910 EXPECT_FALSE(contents()->cross_navigation_pending()); |
935 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 911 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
936 | 912 |
937 // Navigate to new site, simulating an onbeforeunload approval. | 913 // Navigate to new site, simulating an onbeforeunload approval. |
938 const GURL url2("http://www.yahoo.com"); | 914 const GURL url2("http://www.yahoo.com"); |
939 controller().LoadURL( | 915 controller().LoadURL( |
940 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 916 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
941 orig_rvh->OnMessageReceived(ViewHostMsg_ShouldClose_ACK( | 917 orig_rvh->OnMessageReceived(ViewHostMsg_ShouldClose_ACK( |
942 0, true, base::TimeTicks(), base::TimeTicks())); | 918 0, true, base::TimeTicks(), base::TimeTicks())); |
943 EXPECT_TRUE(contents()->cross_navigation_pending()); | 919 EXPECT_TRUE(contents()->cross_navigation_pending()); |
944 TestRenderViewHost* pending_rvh = static_cast<TestRenderViewHost*>( | 920 TestRenderViewHost* pending_rvh = static_cast<TestRenderViewHost*>( |
945 contents()->GetPendingRenderViewHost()); | 921 contents()->GetPendingRenderViewHost()); |
946 | 922 |
947 // Simulate the pending renderer's response, which leads to an unload request | 923 // Simulate the pending renderer's response, which leads to an unload request |
948 // being sent to orig_rvh. | 924 // being sent to orig_rvh. |
949 contents()->GetRenderManagerForTesting()->OnCrossSiteResponse(0, 0); | 925 contents()->GetRenderManagerForTesting()->OnCrossSiteResponse(0, 0); |
950 | 926 |
951 // Suppose the original renderer navigates now, while the unload request is in | 927 // Suppose the original renderer navigates now, while the unload request is in |
952 // flight. We should ignore it, wait for the unload ack, and let the pending | 928 // flight. We should ignore it, wait for the unload ack, and let the pending |
953 // request continue. Otherwise, the contents may close spontaneously or stop | 929 // request continue. Otherwise, the contents may close spontaneously or stop |
954 // responding to navigation requests. (See bug 23942.) | 930 // responding to navigation requests. (See bug 23942.) |
955 ViewHostMsg_FrameNavigate_Params params1a; | 931 ViewHostMsg_FrameNavigate_Params params1a; |
956 InitNavigateParams(¶ms1a, 2, GURL("http://www.google.com/foo"), | 932 InitNavigateParams(¶ms1a, 2, GURL("http://www.google.com/foo"), |
957 content::PAGE_TRANSITION_TYPED); | 933 PAGE_TRANSITION_TYPED); |
958 orig_rvh->SendNavigate(2, GURL("http://www.google.com/foo")); | 934 orig_rvh->SendNavigate(2, GURL("http://www.google.com/foo")); |
959 | 935 |
960 // Verify that the pending navigation is still in progress. | 936 // Verify that the pending navigation is still in progress. |
961 EXPECT_TRUE(contents()->cross_navigation_pending()); | 937 EXPECT_TRUE(contents()->cross_navigation_pending()); |
962 EXPECT_TRUE(contents()->GetPendingRenderViewHost() != NULL); | 938 EXPECT_TRUE(contents()->GetPendingRenderViewHost() != NULL); |
963 | 939 |
964 // DidNavigate from the pending page should commit it. | 940 // DidNavigate from the pending page should commit it. |
965 contents()->TestDidNavigate( | 941 contents()->TestDidNavigate( |
966 pending_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); | 942 pending_rvh, 1, url2, PAGE_TRANSITION_TYPED); |
967 SiteInstance* instance2 = contents()->GetSiteInstance(); | 943 SiteInstance* instance2 = contents()->GetSiteInstance(); |
968 EXPECT_FALSE(contents()->cross_navigation_pending()); | 944 EXPECT_FALSE(contents()->cross_navigation_pending()); |
969 EXPECT_EQ(pending_rvh, rvh()); | 945 EXPECT_EQ(pending_rvh, rvh()); |
970 EXPECT_NE(instance1, instance2); | 946 EXPECT_NE(instance1, instance2); |
971 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); | 947 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); |
972 } | 948 } |
973 | 949 |
974 // Test that a cross-site navigation that doesn't commit after the unload | 950 // Test that a cross-site navigation that doesn't commit after the unload |
975 // handler doesn't leave the contents in a stuck state. http://crbug.com/88562 | 951 // handler doesn't leave the contents in a stuck state. http://crbug.com/88562 |
976 TEST_F(WebContentsImplTest, CrossSiteNavigationCanceled) { | 952 TEST_F(WebContentsImplTest, CrossSiteNavigationCanceled) { |
977 contents()->transition_cross_site = true; | 953 contents()->transition_cross_site = true; |
978 TestRenderViewHost* orig_rvh = test_rvh(); | 954 TestRenderViewHost* orig_rvh = test_rvh(); |
979 SiteInstance* instance1 = contents()->GetSiteInstance(); | 955 SiteInstance* instance1 = contents()->GetSiteInstance(); |
980 | 956 |
981 // Navigate to URL. First URL should use first RenderViewHost. | 957 // Navigate to URL. First URL should use first RenderViewHost. |
982 const GURL url("http://www.google.com"); | 958 const GURL url("http://www.google.com"); |
983 controller().LoadURL( | 959 controller().LoadURL( |
984 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 960 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
985 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); | 961 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
986 EXPECT_FALSE(contents()->cross_navigation_pending()); | 962 EXPECT_FALSE(contents()->cross_navigation_pending()); |
987 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 963 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
988 | 964 |
989 // Navigate to new site, simulating an onbeforeunload approval. | 965 // Navigate to new site, simulating an onbeforeunload approval. |
990 const GURL url2("http://www.yahoo.com"); | 966 const GURL url2("http://www.yahoo.com"); |
991 controller().LoadURL( | 967 controller().LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
992 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | |
993 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); | 968 EXPECT_TRUE(orig_rvh->is_waiting_for_beforeunload_ack()); |
994 orig_rvh->OnMessageReceived(ViewHostMsg_ShouldClose_ACK( | 969 orig_rvh->OnMessageReceived(ViewHostMsg_ShouldClose_ACK( |
995 0, true, base::TimeTicks(), base::TimeTicks())); | 970 0, true, base::TimeTicks(), base::TimeTicks())); |
996 EXPECT_TRUE(contents()->cross_navigation_pending()); | 971 EXPECT_TRUE(contents()->cross_navigation_pending()); |
997 | 972 |
998 // Simulate swap out message when the response arrives. | 973 // Simulate swap out message when the response arrives. |
999 orig_rvh->set_is_swapped_out(true); | 974 orig_rvh->set_is_swapped_out(true); |
1000 | 975 |
1001 // Suppose the navigation doesn't get a chance to commit, and the user | 976 // Suppose the navigation doesn't get a chance to commit, and the user |
1002 // navigates in the current RVH's SiteInstance. | 977 // navigates in the current RVH's SiteInstance. |
1003 controller().LoadURL( | 978 controller().LoadURL(url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1004 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | |
1005 | 979 |
1006 // Verify that the pending navigation is cancelled and the renderer is no | 980 // Verify that the pending navigation is cancelled and the renderer is no |
1007 // longer swapped out. | 981 // longer swapped out. |
1008 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); | 982 EXPECT_FALSE(orig_rvh->is_waiting_for_beforeunload_ack()); |
1009 SiteInstance* instance2 = contents()->GetSiteInstance(); | 983 SiteInstance* instance2 = contents()->GetSiteInstance(); |
1010 EXPECT_FALSE(contents()->cross_navigation_pending()); | 984 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1011 EXPECT_EQ(orig_rvh, rvh()); | 985 EXPECT_EQ(orig_rvh, rvh()); |
1012 EXPECT_FALSE(orig_rvh->is_swapped_out()); | 986 EXPECT_FALSE(orig_rvh->is_swapped_out()); |
1013 EXPECT_EQ(instance1, instance2); | 987 EXPECT_EQ(instance1, instance2); |
1014 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); | 988 EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); |
1015 } | 989 } |
1016 | 990 |
1017 // Test that NavigationEntries have the correct content state after going | 991 // Test that NavigationEntries have the correct content state after going |
1018 // forward and back. Prevents regression for bug 1116137. | 992 // forward and back. Prevents regression for bug 1116137. |
1019 TEST_F(WebContentsImplTest, NavigationEntryContentState) { | 993 TEST_F(WebContentsImplTest, NavigationEntryContentState) { |
1020 TestRenderViewHost* orig_rvh = test_rvh(); | 994 TestRenderViewHost* orig_rvh = test_rvh(); |
1021 | 995 |
1022 // Navigate to URL. There should be no committed entry yet. | 996 // Navigate to URL. There should be no committed entry yet. |
1023 const GURL url("http://www.google.com"); | 997 const GURL url("http://www.google.com"); |
1024 controller().LoadURL( | 998 controller().LoadURL(url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1025 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | |
1026 NavigationEntry* entry = controller().GetLastCommittedEntry(); | 999 NavigationEntry* entry = controller().GetLastCommittedEntry(); |
1027 EXPECT_TRUE(entry == NULL); | 1000 EXPECT_TRUE(entry == NULL); |
1028 | 1001 |
1029 // Committed entry should have content state after DidNavigate. | 1002 // Committed entry should have content state after DidNavigate. |
1030 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); | 1003 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
1031 entry = controller().GetLastCommittedEntry(); | 1004 entry = controller().GetLastCommittedEntry(); |
1032 EXPECT_FALSE(entry->GetContentState().empty()); | 1005 EXPECT_FALSE(entry->GetContentState().empty()); |
1033 | 1006 |
1034 // Navigate to same site. | 1007 // Navigate to same site. |
1035 const GURL url2("http://images.google.com"); | 1008 const GURL url2("http://images.google.com"); |
1036 controller().LoadURL( | 1009 controller().LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1037 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | |
1038 entry = controller().GetLastCommittedEntry(); | 1010 entry = controller().GetLastCommittedEntry(); |
1039 EXPECT_FALSE(entry->GetContentState().empty()); | 1011 EXPECT_FALSE(entry->GetContentState().empty()); |
1040 | 1012 |
1041 // Committed entry should have content state after DidNavigate. | 1013 // Committed entry should have content state after DidNavigate. |
1042 contents()->TestDidNavigate( | 1014 contents()->TestDidNavigate(orig_rvh, 2, url2, PAGE_TRANSITION_TYPED); |
1043 orig_rvh, 2, url2, content::PAGE_TRANSITION_TYPED); | |
1044 entry = controller().GetLastCommittedEntry(); | 1015 entry = controller().GetLastCommittedEntry(); |
1045 EXPECT_FALSE(entry->GetContentState().empty()); | 1016 EXPECT_FALSE(entry->GetContentState().empty()); |
1046 | 1017 |
1047 // Now go back. Committed entry should still have content state. | 1018 // Now go back. Committed entry should still have content state. |
1048 controller().GoBack(); | 1019 controller().GoBack(); |
1049 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); | 1020 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
1050 entry = controller().GetLastCommittedEntry(); | 1021 entry = controller().GetLastCommittedEntry(); |
1051 EXPECT_FALSE(entry->GetContentState().empty()); | 1022 EXPECT_FALSE(entry->GetContentState().empty()); |
1052 } | 1023 } |
1053 | 1024 |
1054 // Test that NavigationEntries have the correct content state and SiteInstance | 1025 // Test that NavigationEntries have the correct content state and SiteInstance |
1055 // state after opening a new window to about:blank. Prevents regression for | 1026 // state after opening a new window to about:blank. Prevents regression for |
1056 // bugs b/1116137 and http://crbug.com/111975. | 1027 // bugs b/1116137 and http://crbug.com/111975. |
1057 TEST_F(WebContentsImplTest, NavigationEntryContentStateNewWindow) { | 1028 TEST_F(WebContentsImplTest, NavigationEntryContentStateNewWindow) { |
1058 TestRenderViewHost* orig_rvh = test_rvh(); | 1029 TestRenderViewHost* orig_rvh = test_rvh(); |
1059 | 1030 |
1060 // When opening a new window, it is navigated to about:blank internally. | 1031 // When opening a new window, it is navigated to about:blank internally. |
1061 // Currently, this results in two DidNavigate events. | 1032 // Currently, this results in two DidNavigate events. |
1062 const GURL url(chrome::kAboutBlankURL); | 1033 const GURL url(chrome::kAboutBlankURL); |
1063 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); | 1034 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
1064 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); | 1035 contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); |
1065 | 1036 |
1066 // Should have a content state here. | 1037 // Should have a content state here. |
1067 NavigationEntry* entry = controller().GetLastCommittedEntry(); | 1038 NavigationEntry* entry = controller().GetLastCommittedEntry(); |
1068 EXPECT_FALSE(entry->GetContentState().empty()); | 1039 EXPECT_FALSE(entry->GetContentState().empty()); |
1069 | 1040 |
1070 // The SiteInstance should be available for other navigations to use. | 1041 // The SiteInstance should be available for other navigations to use. |
1071 NavigationEntryImpl* entry_impl = | 1042 NavigationEntryImpl* entry_impl = |
1072 NavigationEntryImpl::FromNavigationEntry(entry); | 1043 NavigationEntryImpl::FromNavigationEntry(entry); |
1073 EXPECT_FALSE(entry_impl->site_instance()->HasSite()); | 1044 EXPECT_FALSE(entry_impl->site_instance()->HasSite()); |
1074 int32 site_instance_id = entry_impl->site_instance()->GetId(); | 1045 int32 site_instance_id = entry_impl->site_instance()->GetId(); |
1075 | 1046 |
1076 // Navigating to a normal page should not cause a process swap. | 1047 // Navigating to a normal page should not cause a process swap. |
1077 const GURL new_url("http://www.google.com"); | 1048 const GURL new_url("http://www.google.com"); |
1078 controller().LoadURL(new_url, content::Referrer(), | 1049 controller().LoadURL(new_url, Referrer(), |
1079 content::PAGE_TRANSITION_TYPED, std::string()); | 1050 PAGE_TRANSITION_TYPED, std::string()); |
1080 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1051 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1081 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); | 1052 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); |
1082 contents()->TestDidNavigate(orig_rvh, 1, new_url, | 1053 contents()->TestDidNavigate(orig_rvh, 1, new_url, PAGE_TRANSITION_TYPED); |
1083 content::PAGE_TRANSITION_TYPED); | |
1084 NavigationEntryImpl* entry_impl2 = NavigationEntryImpl::FromNavigationEntry( | 1054 NavigationEntryImpl* entry_impl2 = NavigationEntryImpl::FromNavigationEntry( |
1085 controller().GetLastCommittedEntry()); | 1055 controller().GetLastCommittedEntry()); |
1086 EXPECT_EQ(site_instance_id, entry_impl2->site_instance()->GetId()); | 1056 EXPECT_EQ(site_instance_id, entry_impl2->site_instance()->GetId()); |
1087 EXPECT_TRUE(entry_impl2->site_instance()->HasSite()); | 1057 EXPECT_TRUE(entry_impl2->site_instance()->HasSite()); |
1088 } | 1058 } |
1089 | 1059 |
1090 //////////////////////////////////////////////////////////////////////////////// | 1060 //////////////////////////////////////////////////////////////////////////////// |
1091 // Interstitial Tests | 1061 // Interstitial Tests |
1092 //////////////////////////////////////////////////////////////////////////////// | 1062 //////////////////////////////////////////////////////////////////////////////// |
1093 | 1063 |
1094 // Test navigating to a page (with the navigation initiated from the browser, | 1064 // Test navigating to a page (with the navigation initiated from the browser, |
1095 // as when a URL is typed in the location bar) that shows an interstitial and | 1065 // as when a URL is typed in the location bar) that shows an interstitial and |
1096 // creates a new navigation entry, then hiding it without proceeding. | 1066 // creates a new navigation entry, then hiding it without proceeding. |
1097 TEST_F(WebContentsImplTest, | 1067 TEST_F(WebContentsImplTest, |
1098 ShowInterstitialFromBrowserWithNewNavigationDontProceed) { | 1068 ShowInterstitialFromBrowserWithNewNavigationDontProceed) { |
1099 // Navigate to a page. | 1069 // Navigate to a page. |
1100 GURL url1("http://www.google.com"); | 1070 GURL url1("http://www.google.com"); |
1101 test_rvh()->SendNavigate(1, url1); | 1071 test_rvh()->SendNavigate(1, url1); |
1102 EXPECT_EQ(1, controller().GetEntryCount()); | 1072 EXPECT_EQ(1, controller().GetEntryCount()); |
1103 | 1073 |
1104 // Initiate a browser navigation that will trigger the interstitial | 1074 // Initiate a browser navigation that will trigger the interstitial |
1105 controller().LoadURL(GURL("http://www.evil.com"), content::Referrer(), | 1075 controller().LoadURL(GURL("http://www.evil.com"), Referrer(), |
1106 content::PAGE_TRANSITION_TYPED, std::string()); | 1076 PAGE_TRANSITION_TYPED, std::string()); |
1107 | 1077 |
1108 // Show an interstitial. | 1078 // Show an interstitial. |
1109 TestInterstitialPage::InterstitialState state = | 1079 TestInterstitialPage::InterstitialState state = |
1110 TestInterstitialPage::UNDECIDED; | 1080 TestInterstitialPage::UNDECIDED; |
1111 bool deleted = false; | 1081 bool deleted = false; |
1112 GURL url2("http://interstitial"); | 1082 GURL url2("http://interstitial"); |
1113 TestInterstitialPage* interstitial = | 1083 TestInterstitialPage* interstitial = |
1114 new TestInterstitialPage(contents(), true, url2, &state, &deleted); | 1084 new TestInterstitialPage(contents(), true, url2, &state, &deleted); |
1115 TestInterstitialPageStateGuard state_guard(interstitial); | 1085 TestInterstitialPageStateGuard state_guard(interstitial); |
1116 interstitial->Show(); | 1086 interstitial->Show(); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1232 // as when a URL is typed in the location bar) that shows an interstitial and | 1202 // as when a URL is typed in the location bar) that shows an interstitial and |
1233 // creates a new navigation entry, then proceeding. | 1203 // creates a new navigation entry, then proceeding. |
1234 TEST_F(WebContentsImplTest, | 1204 TEST_F(WebContentsImplTest, |
1235 ShowInterstitialFromBrowserNewNavigationProceed) { | 1205 ShowInterstitialFromBrowserNewNavigationProceed) { |
1236 // Navigate to a page. | 1206 // Navigate to a page. |
1237 GURL url1("http://www.google.com"); | 1207 GURL url1("http://www.google.com"); |
1238 test_rvh()->SendNavigate(1, url1); | 1208 test_rvh()->SendNavigate(1, url1); |
1239 EXPECT_EQ(1, controller().GetEntryCount()); | 1209 EXPECT_EQ(1, controller().GetEntryCount()); |
1240 | 1210 |
1241 // Initiate a browser navigation that will trigger the interstitial | 1211 // Initiate a browser navigation that will trigger the interstitial |
1242 controller().LoadURL(GURL("http://www.evil.com"), content::Referrer(), | 1212 controller().LoadURL(GURL("http://www.evil.com"), Referrer(), |
1243 content::PAGE_TRANSITION_TYPED, std::string()); | 1213 PAGE_TRANSITION_TYPED, std::string()); |
1244 | 1214 |
1245 // Show an interstitial. | 1215 // Show an interstitial. |
1246 TestInterstitialPage::InterstitialState state = | 1216 TestInterstitialPage::InterstitialState state = |
1247 TestInterstitialPage::UNDECIDED; | 1217 TestInterstitialPage::UNDECIDED; |
1248 bool deleted = false; | 1218 bool deleted = false; |
1249 GURL url2("http://interstitial"); | 1219 GURL url2("http://interstitial"); |
1250 TestInterstitialPage* interstitial = | 1220 TestInterstitialPage* interstitial = |
1251 new TestInterstitialPage(contents(), true, url2, &state, &deleted); | 1221 new TestInterstitialPage(contents(), true, url2, &state, &deleted); |
1252 TestInterstitialPageStateGuard state_guard(interstitial); | 1222 TestInterstitialPageStateGuard state_guard(interstitial); |
1253 interstitial->Show(); | 1223 interstitial->Show(); |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1676 GURL interstitial_url("http://interstitial"); | 1646 GURL interstitial_url("http://interstitial"); |
1677 TestInterstitialPage* interstitial = | 1647 TestInterstitialPage* interstitial = |
1678 new TestInterstitialPage(contents(), true, interstitial_url, | 1648 new TestInterstitialPage(contents(), true, interstitial_url, |
1679 &state, &deleted); | 1649 &state, &deleted); |
1680 TestInterstitialPageStateGuard state_guard(interstitial); | 1650 TestInterstitialPageStateGuard state_guard(interstitial); |
1681 interstitial->Show(); | 1651 interstitial->Show(); |
1682 | 1652 |
1683 // Let's simulate a navigation initiated from the browser before the | 1653 // Let's simulate a navigation initiated from the browser before the |
1684 // interstitial finishes loading. | 1654 // interstitial finishes loading. |
1685 const GURL url("http://www.google.com"); | 1655 const GURL url("http://www.google.com"); |
1686 controller().LoadURL( | 1656 controller().LoadURL(url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1687 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | |
1688 ASSERT_FALSE(deleted); | 1657 ASSERT_FALSE(deleted); |
1689 EXPECT_FALSE(interstitial->is_showing()); | 1658 EXPECT_FALSE(interstitial->is_showing()); |
1690 | 1659 |
1691 // Now let's make the interstitial navigation commit. | 1660 // Now let's make the interstitial navigation commit. |
1692 interstitial->TestDidNavigate(1, interstitial_url); | 1661 interstitial->TestDidNavigate(1, interstitial_url); |
1693 | 1662 |
1694 // After it loaded the interstitial should be gone. | 1663 // After it loaded the interstitial should be gone. |
1695 EXPECT_TRUE(deleted); | 1664 EXPECT_TRUE(deleted); |
1696 EXPECT_EQ(TestInterstitialPage::CANCELED, state); | 1665 EXPECT_EQ(TestInterstitialPage::CANCELED, state); |
1697 } | 1666 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1768 | 1737 |
1769 // Tests that showing an interstitial as a result of a browser initiated | 1738 // Tests that showing an interstitial as a result of a browser initiated |
1770 // navigation while an interstitial is showing does not remove the pending | 1739 // navigation while an interstitial is showing does not remove the pending |
1771 // entry (see http://crbug.com/9791). | 1740 // entry (see http://crbug.com/9791). |
1772 TEST_F(WebContentsImplTest, NewInterstitialDoesNotCancelPendingEntry) { | 1741 TEST_F(WebContentsImplTest, NewInterstitialDoesNotCancelPendingEntry) { |
1773 const char kUrl[] = "http://www.badguys.com/"; | 1742 const char kUrl[] = "http://www.badguys.com/"; |
1774 const GURL kGURL(kUrl); | 1743 const GURL kGURL(kUrl); |
1775 | 1744 |
1776 // Start a navigation to a page | 1745 // Start a navigation to a page |
1777 contents()->GetController().LoadURL( | 1746 contents()->GetController().LoadURL( |
1778 kGURL, content::Referrer(), content::PAGE_TRANSITION_TYPED, | 1747 kGURL, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1779 std::string()); | |
1780 | 1748 |
1781 // Simulate that navigation triggering an interstitial. | 1749 // Simulate that navigation triggering an interstitial. |
1782 TestInterstitialPage::InterstitialState state = | 1750 TestInterstitialPage::InterstitialState state = |
1783 TestInterstitialPage::UNDECIDED; | 1751 TestInterstitialPage::UNDECIDED; |
1784 bool deleted = false; | 1752 bool deleted = false; |
1785 TestInterstitialPage* interstitial = | 1753 TestInterstitialPage* interstitial = |
1786 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted); | 1754 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted); |
1787 TestInterstitialPageStateGuard state_guard(interstitial); | 1755 TestInterstitialPageStateGuard state_guard(interstitial); |
1788 interstitial->Show(); | 1756 interstitial->Show(); |
1789 interstitial->TestDidNavigate(1, kGURL); | 1757 interstitial->TestDidNavigate(1, kGURL); |
1790 | 1758 |
1791 // Initiate a new navigation from the browser that also triggers an | 1759 // Initiate a new navigation from the browser that also triggers an |
1792 // interstitial. | 1760 // interstitial. |
1793 contents()->GetController().LoadURL( | 1761 contents()->GetController().LoadURL( |
1794 kGURL, content::Referrer(), content::PAGE_TRANSITION_TYPED, | 1762 kGURL, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1795 std::string()); | |
1796 TestInterstitialPage::InterstitialState state2 = | 1763 TestInterstitialPage::InterstitialState state2 = |
1797 TestInterstitialPage::UNDECIDED; | 1764 TestInterstitialPage::UNDECIDED; |
1798 bool deleted2 = false; | 1765 bool deleted2 = false; |
1799 TestInterstitialPage* interstitial2 = | 1766 TestInterstitialPage* interstitial2 = |
1800 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted); | 1767 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted); |
1801 TestInterstitialPageStateGuard state_guard2(interstitial2); | 1768 TestInterstitialPageStateGuard state_guard2(interstitial2); |
1802 interstitial2->Show(); | 1769 interstitial2->Show(); |
1803 interstitial2->TestDidNavigate(1, kGURL); | 1770 interstitial2->TestDidNavigate(1, kGURL); |
1804 | 1771 |
1805 // Make sure we still have an entry. | 1772 // Make sure we still have an entry. |
1806 NavigationEntry* entry = contents()->GetController().GetPendingEntry(); | 1773 NavigationEntry* entry = contents()->GetController().GetPendingEntry(); |
1807 ASSERT_TRUE(entry); | 1774 ASSERT_TRUE(entry); |
1808 EXPECT_EQ(kUrl, entry->GetURL().spec()); | 1775 EXPECT_EQ(kUrl, entry->GetURL().spec()); |
1809 | 1776 |
1810 // And that the first interstitial is gone, but not the second. | 1777 // And that the first interstitial is gone, but not the second. |
1811 EXPECT_TRUE(deleted); | 1778 EXPECT_TRUE(deleted); |
1812 EXPECT_EQ(TestInterstitialPage::CANCELED, state); | 1779 EXPECT_EQ(TestInterstitialPage::CANCELED, state); |
1813 EXPECT_FALSE(deleted2); | 1780 EXPECT_FALSE(deleted2); |
1814 EXPECT_EQ(TestInterstitialPage::UNDECIDED, state2); | 1781 EXPECT_EQ(TestInterstitialPage::UNDECIDED, state2); |
1815 } | 1782 } |
1816 | 1783 |
1817 // Tests that Javascript messages are not shown while an interstitial is | 1784 // Tests that Javascript messages are not shown while an interstitial is |
1818 // showing. | 1785 // showing. |
1819 TEST_F(WebContentsImplTest, NoJSMessageOnInterstitials) { | 1786 TEST_F(WebContentsImplTest, NoJSMessageOnInterstitials) { |
1820 const char kUrl[] = "http://www.badguys.com/"; | 1787 const char kUrl[] = "http://www.badguys.com/"; |
1821 const GURL kGURL(kUrl); | 1788 const GURL kGURL(kUrl); |
1822 | 1789 |
1823 // Start a navigation to a page | 1790 // Start a navigation to a page |
1824 contents()->GetController().LoadURL( | 1791 contents()->GetController().LoadURL( |
1825 kGURL, content::Referrer(), content::PAGE_TRANSITION_TYPED, | 1792 kGURL, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1826 std::string()); | |
1827 // DidNavigate from the page | 1793 // DidNavigate from the page |
1828 contents()->TestDidNavigate(rvh(), 1, kGURL, content::PAGE_TRANSITION_TYPED); | 1794 contents()->TestDidNavigate(rvh(), 1, kGURL, PAGE_TRANSITION_TYPED); |
1829 | 1795 |
1830 // Simulate showing an interstitial while the page is showing. | 1796 // Simulate showing an interstitial while the page is showing. |
1831 TestInterstitialPage::InterstitialState state = | 1797 TestInterstitialPage::InterstitialState state = |
1832 TestInterstitialPage::UNDECIDED; | 1798 TestInterstitialPage::UNDECIDED; |
1833 bool deleted = false; | 1799 bool deleted = false; |
1834 TestInterstitialPage* interstitial = | 1800 TestInterstitialPage* interstitial = |
1835 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted); | 1801 new TestInterstitialPage(contents(), true, kGURL, &state, &deleted); |
1836 TestInterstitialPageStateGuard state_guard(interstitial); | 1802 TestInterstitialPageStateGuard state_guard(interstitial); |
1837 interstitial->Show(); | 1803 interstitial->Show(); |
1838 interstitial->TestDidNavigate(1, kGURL); | 1804 interstitial->TestDidNavigate(1, kGURL); |
1839 | 1805 |
1840 // While the interstitial is showing, let's simulate the hidden page | 1806 // While the interstitial is showing, let's simulate the hidden page |
1841 // attempting to show a JS message. | 1807 // attempting to show a JS message. |
1842 IPC::Message* dummy_message = new IPC::Message; | 1808 IPC::Message* dummy_message = new IPC::Message; |
1843 bool did_suppress_message = false; | 1809 bool did_suppress_message = false; |
1844 contents()->RunJavaScriptMessage(contents()->GetRenderViewHost(), | 1810 contents()->RunJavaScriptMessage(contents()->GetRenderViewHost(), |
1845 ASCIIToUTF16("This is an informative message"), ASCIIToUTF16("OK"), | 1811 ASCIIToUTF16("This is an informative message"), ASCIIToUTF16("OK"), |
1846 kGURL, content::JAVASCRIPT_MESSAGE_TYPE_ALERT, dummy_message, | 1812 kGURL, JAVASCRIPT_MESSAGE_TYPE_ALERT, dummy_message, |
1847 &did_suppress_message); | 1813 &did_suppress_message); |
1848 EXPECT_TRUE(did_suppress_message); | 1814 EXPECT_TRUE(did_suppress_message); |
1849 } | 1815 } |
1850 | 1816 |
1851 // Makes sure that if the source passed to CopyStateFromAndPrune has an | 1817 // Makes sure that if the source passed to CopyStateFromAndPrune has an |
1852 // interstitial it isn't copied over to the destination. | 1818 // interstitial it isn't copied over to the destination. |
1853 TEST_F(WebContentsImplTest, CopyStateFromAndPruneSourceInterstitial) { | 1819 TEST_F(WebContentsImplTest, CopyStateFromAndPruneSourceInterstitial) { |
1854 // Navigate to a page. | 1820 // Navigate to a page. |
1855 GURL url1("http://www.google.com"); | 1821 GURL url1("http://www.google.com"); |
1856 test_rvh()->SendNavigate(1, url1); | 1822 test_rvh()->SendNavigate(1, url1); |
1857 EXPECT_EQ(1, controller().GetEntryCount()); | 1823 EXPECT_EQ(1, controller().GetEntryCount()); |
1858 | 1824 |
1859 // Initiate a browser navigation that will trigger the interstitial | 1825 // Initiate a browser navigation that will trigger the interstitial |
1860 controller().LoadURL(GURL("http://www.evil.com"), content::Referrer(), | 1826 controller().LoadURL(GURL("http://www.evil.com"), Referrer(), |
1861 content::PAGE_TRANSITION_TYPED, std::string()); | 1827 PAGE_TRANSITION_TYPED, std::string()); |
1862 | 1828 |
1863 // Show an interstitial. | 1829 // Show an interstitial. |
1864 TestInterstitialPage::InterstitialState state = | 1830 TestInterstitialPage::InterstitialState state = |
1865 TestInterstitialPage::UNDECIDED; | 1831 TestInterstitialPage::UNDECIDED; |
1866 bool deleted = false; | 1832 bool deleted = false; |
1867 GURL url2("http://interstitial"); | 1833 GURL url2("http://interstitial"); |
1868 TestInterstitialPage* interstitial = | 1834 TestInterstitialPage* interstitial = |
1869 new TestInterstitialPage(contents(), true, url2, &state, &deleted); | 1835 new TestInterstitialPage(contents(), true, url2, &state, &deleted); |
1870 TestInterstitialPageStateGuard state_guard(interstitial); | 1836 TestInterstitialPageStateGuard state_guard(interstitial); |
1871 interstitial->Show(); | 1837 interstitial->Show(); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1939 // It should have a transient entry. | 1905 // It should have a transient entry. |
1940 EXPECT_TRUE(other_controller.GetTransientEntry()); | 1906 EXPECT_TRUE(other_controller.GetTransientEntry()); |
1941 | 1907 |
1942 // And the interstitial should be showing. | 1908 // And the interstitial should be showing. |
1943 EXPECT_TRUE(other_contents->ShowingInterstitialPage()); | 1909 EXPECT_TRUE(other_contents->ShowingInterstitialPage()); |
1944 | 1910 |
1945 // And the interstitial should do a reload on don't proceed. | 1911 // And the interstitial should do a reload on don't proceed. |
1946 EXPECT_TRUE(static_cast<InterstitialPageImpl*>( | 1912 EXPECT_TRUE(static_cast<InterstitialPageImpl*>( |
1947 other_contents->GetInterstitialPage())->reload_on_dont_proceed()); | 1913 other_contents->GetInterstitialPage())->reload_on_dont_proceed()); |
1948 } | 1914 } |
| 1915 |
| 1916 } // namespace content |
OLD | NEW |