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/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 | 359 |
360 TEST_F(RenderViewImplTest, DecideNavigationPolicy) { | 360 TEST_F(RenderViewImplTest, DecideNavigationPolicy) { |
361 WebUITestWebUIControllerFactory factory; | 361 WebUITestWebUIControllerFactory factory; |
362 WebUIControllerFactory::RegisterFactory(&factory); | 362 WebUIControllerFactory::RegisterFactory(&factory); |
363 | 363 |
364 DocumentState state; | 364 DocumentState state; |
365 state.set_navigation_state(NavigationState::CreateContentInitiated()); | 365 state.set_navigation_state(NavigationState::CreateContentInitiated()); |
366 | 366 |
367 // Navigations to normal HTTP URLs can be handled locally. | 367 // Navigations to normal HTTP URLs can be handled locally. |
368 blink::WebURLRequest request(GURL("http://foo.com")); | 368 blink::WebURLRequest request(GURL("http://foo.com")); |
| 369 blink::WebFrameClient::NavigationPolicyInfo policy_info(request); |
| 370 policy_info.frame = GetMainFrame(); |
| 371 policy_info.extraData = &state; |
| 372 policy_info.navigationType = blink::WebNavigationTypeLinkClicked; |
| 373 policy_info.defaultPolicy = blink::WebNavigationPolicyCurrentTab; |
369 blink::WebNavigationPolicy policy = frame()->decidePolicyForNavigation( | 374 blink::WebNavigationPolicy policy = frame()->decidePolicyForNavigation( |
370 GetMainFrame(), | 375 policy_info); |
371 &state, | |
372 request, | |
373 blink::WebNavigationTypeLinkClicked, | |
374 blink::WebNavigationPolicyCurrentTab, | |
375 false); | |
376 EXPECT_EQ(blink::WebNavigationPolicyCurrentTab, policy); | 376 EXPECT_EQ(blink::WebNavigationPolicyCurrentTab, policy); |
377 | 377 |
378 // Verify that form posts to WebUI URLs will be sent to the browser process. | 378 // Verify that form posts to WebUI URLs will be sent to the browser process. |
379 blink::WebURLRequest form_request(GURL("chrome://foo")); | 379 blink::WebURLRequest form_request(GURL("chrome://foo")); |
| 380 blink::WebFrameClient::NavigationPolicyInfo form_policy_info(form_request); |
| 381 form_policy_info.frame = GetMainFrame(); |
| 382 form_policy_info.extraData = &state; |
| 383 form_policy_info.navigationType = blink::WebNavigationTypeFormSubmitted; |
| 384 form_policy_info.defaultPolicy = blink::WebNavigationPolicyCurrentTab; |
380 form_request.setHTTPMethod("POST"); | 385 form_request.setHTTPMethod("POST"); |
381 policy = frame()->decidePolicyForNavigation( | 386 policy = frame()->decidePolicyForNavigation(form_policy_info); |
382 GetMainFrame(), | |
383 &state, | |
384 form_request, | |
385 blink::WebNavigationTypeFormSubmitted, | |
386 blink::WebNavigationPolicyCurrentTab, | |
387 false); | |
388 EXPECT_EQ(blink::WebNavigationPolicyIgnore, policy); | 387 EXPECT_EQ(blink::WebNavigationPolicyIgnore, policy); |
389 | 388 |
390 // Verify that popup links to WebUI URLs also are sent to browser. | 389 // Verify that popup links to WebUI URLs also are sent to browser. |
391 blink::WebURLRequest popup_request(GURL("chrome://foo")); | 390 blink::WebURLRequest popup_request(GURL("chrome://foo")); |
392 policy = frame()->decidePolicyForNavigation( | 391 blink::WebFrameClient::NavigationPolicyInfo popup_policy_info(popup_request); |
393 GetMainFrame(), | 392 popup_policy_info.frame = GetMainFrame(); |
394 &state, | 393 popup_policy_info.extraData = &state; |
395 popup_request, | 394 popup_policy_info.navigationType = blink::WebNavigationTypeLinkClicked; |
396 blink::WebNavigationTypeLinkClicked, | 395 popup_policy_info.defaultPolicy = blink::WebNavigationPolicyNewForegroundTab; |
397 blink::WebNavigationPolicyNewForegroundTab, | 396 policy = frame()->decidePolicyForNavigation(popup_policy_info); |
398 false); | |
399 EXPECT_EQ(blink::WebNavigationPolicyIgnore, policy); | 397 EXPECT_EQ(blink::WebNavigationPolicyIgnore, policy); |
400 } | 398 } |
401 | 399 |
402 TEST_F(RenderViewImplTest, DecideNavigationPolicyHandlesAllTopLevel) { | 400 TEST_F(RenderViewImplTest, DecideNavigationPolicyHandlesAllTopLevel) { |
403 DocumentState state; | 401 DocumentState state; |
404 state.set_navigation_state(NavigationState::CreateContentInitiated()); | 402 state.set_navigation_state(NavigationState::CreateContentInitiated()); |
405 | 403 |
406 RendererPreferences prefs = view()->renderer_preferences(); | 404 RendererPreferences prefs = view()->renderer_preferences(); |
407 prefs.browser_handles_all_top_level_requests = true; | 405 prefs.browser_handles_all_top_level_requests = true; |
408 view()->OnSetRendererPrefs(prefs); | 406 view()->OnSetRendererPrefs(prefs); |
409 | 407 |
410 const blink::WebNavigationType kNavTypes[] = { | 408 const blink::WebNavigationType kNavTypes[] = { |
411 blink::WebNavigationTypeLinkClicked, | 409 blink::WebNavigationTypeLinkClicked, |
412 blink::WebNavigationTypeFormSubmitted, | 410 blink::WebNavigationTypeFormSubmitted, |
413 blink::WebNavigationTypeBackForward, | 411 blink::WebNavigationTypeBackForward, |
414 blink::WebNavigationTypeReload, | 412 blink::WebNavigationTypeReload, |
415 blink::WebNavigationTypeFormResubmitted, | 413 blink::WebNavigationTypeFormResubmitted, |
416 blink::WebNavigationTypeOther, | 414 blink::WebNavigationTypeOther, |
417 }; | 415 }; |
418 | 416 |
419 blink::WebURLRequest request(GURL("http://foo.com")); | 417 blink::WebURLRequest request(GURL("http://foo.com")); |
| 418 blink::WebFrameClient::NavigationPolicyInfo policy_info(request); |
| 419 policy_info.frame = GetMainFrame(); |
| 420 policy_info.extraData = &state; |
| 421 policy_info.defaultPolicy = blink::WebNavigationPolicyCurrentTab; |
| 422 |
420 for (size_t i = 0; i < arraysize(kNavTypes); ++i) { | 423 for (size_t i = 0; i < arraysize(kNavTypes); ++i) { |
| 424 policy_info.navigationType = kNavTypes[i]; |
| 425 |
421 blink::WebNavigationPolicy policy = frame()->decidePolicyForNavigation( | 426 blink::WebNavigationPolicy policy = frame()->decidePolicyForNavigation( |
422 GetMainFrame(), | 427 policy_info); |
423 &state, | |
424 request, | |
425 kNavTypes[i], | |
426 blink::WebNavigationPolicyCurrentTab, | |
427 false); | |
428 EXPECT_EQ(blink::WebNavigationPolicyIgnore, policy); | 428 EXPECT_EQ(blink::WebNavigationPolicyIgnore, policy); |
429 } | 429 } |
430 } | 430 } |
431 | 431 |
432 TEST_F(RenderViewImplTest, DecideNavigationPolicyForWebUI) { | 432 TEST_F(RenderViewImplTest, DecideNavigationPolicyForWebUI) { |
433 // Enable bindings to simulate a WebUI view. | 433 // Enable bindings to simulate a WebUI view. |
434 view()->OnAllowBindings(BINDINGS_POLICY_WEB_UI); | 434 view()->OnAllowBindings(BINDINGS_POLICY_WEB_UI); |
435 | 435 |
436 DocumentState state; | 436 DocumentState state; |
437 state.set_navigation_state(NavigationState::CreateContentInitiated()); | 437 state.set_navigation_state(NavigationState::CreateContentInitiated()); |
438 | 438 |
439 // Navigations to normal HTTP URLs will be sent to browser process. | 439 // Navigations to normal HTTP URLs will be sent to browser process. |
440 blink::WebURLRequest request(GURL("http://foo.com")); | 440 blink::WebURLRequest request(GURL("http://foo.com")); |
| 441 blink::WebFrameClient::NavigationPolicyInfo policy_info(request); |
| 442 policy_info.frame = GetMainFrame(); |
| 443 policy_info.extraData = &state; |
| 444 policy_info.navigationType = blink::WebNavigationTypeLinkClicked; |
| 445 policy_info.defaultPolicy = blink::WebNavigationPolicyCurrentTab; |
| 446 |
441 blink::WebNavigationPolicy policy = frame()->decidePolicyForNavigation( | 447 blink::WebNavigationPolicy policy = frame()->decidePolicyForNavigation( |
442 GetMainFrame(), | 448 policy_info); |
443 &state, | |
444 request, | |
445 blink::WebNavigationTypeLinkClicked, | |
446 blink::WebNavigationPolicyCurrentTab, | |
447 false); | |
448 EXPECT_EQ(blink::WebNavigationPolicyIgnore, policy); | 449 EXPECT_EQ(blink::WebNavigationPolicyIgnore, policy); |
449 | 450 |
450 // Navigations to WebUI URLs will also be sent to browser process. | 451 // Navigations to WebUI URLs will also be sent to browser process. |
451 blink::WebURLRequest webui_request(GURL("chrome://foo")); | 452 blink::WebURLRequest webui_request(GURL("chrome://foo")); |
452 policy = frame()->decidePolicyForNavigation( | 453 blink::WebFrameClient::NavigationPolicyInfo webui_policy_info(webui_request); |
453 GetMainFrame(), | 454 webui_policy_info.frame = GetMainFrame(); |
454 &state, | 455 webui_policy_info.extraData = &state; |
455 webui_request, | 456 webui_policy_info.navigationType = blink::WebNavigationTypeLinkClicked; |
456 blink::WebNavigationTypeLinkClicked, | 457 webui_policy_info.defaultPolicy = blink::WebNavigationPolicyCurrentTab; |
457 blink::WebNavigationPolicyCurrentTab, | 458 policy = frame()->decidePolicyForNavigation(webui_policy_info); |
458 false); | |
459 EXPECT_EQ(blink::WebNavigationPolicyIgnore, policy); | 459 EXPECT_EQ(blink::WebNavigationPolicyIgnore, policy); |
460 | 460 |
461 // Verify that form posts to data URLs will be sent to the browser process. | 461 // Verify that form posts to data URLs will be sent to the browser process. |
462 blink::WebURLRequest data_request(GURL("data:text/html,foo")); | 462 blink::WebURLRequest data_request(GURL("data:text/html,foo")); |
| 463 blink::WebFrameClient::NavigationPolicyInfo data_policy_info(data_request); |
| 464 data_policy_info.frame = GetMainFrame(); |
| 465 data_policy_info.extraData = &state; |
| 466 data_policy_info.navigationType = blink::WebNavigationTypeFormSubmitted; |
| 467 data_policy_info.defaultPolicy = blink::WebNavigationPolicyCurrentTab; |
463 data_request.setHTTPMethod("POST"); | 468 data_request.setHTTPMethod("POST"); |
464 policy = frame()->decidePolicyForNavigation( | 469 policy = frame()->decidePolicyForNavigation(data_policy_info); |
465 GetMainFrame(), | |
466 &state, | |
467 data_request, | |
468 blink::WebNavigationTypeFormSubmitted, | |
469 blink::WebNavigationPolicyCurrentTab, | |
470 false); | |
471 EXPECT_EQ(blink::WebNavigationPolicyIgnore, policy); | 470 EXPECT_EQ(blink::WebNavigationPolicyIgnore, policy); |
472 | 471 |
473 // Verify that a popup that creates a view first and then navigates to a | 472 // Verify that a popup that creates a view first and then navigates to a |
474 // normal HTTP URL will be sent to the browser process, even though the | 473 // normal HTTP URL will be sent to the browser process, even though the |
475 // new view does not have any enabled_bindings_. | 474 // new view does not have any enabled_bindings_. |
476 blink::WebURLRequest popup_request(GURL("http://foo.com")); | 475 blink::WebURLRequest popup_request(GURL("http://foo.com")); |
477 blink::WebView* new_web_view = view()->createView( | 476 blink::WebView* new_web_view = view()->createView( |
478 GetMainFrame(), popup_request, blink::WebWindowFeatures(), "foo", | 477 GetMainFrame(), popup_request, blink::WebWindowFeatures(), "foo", |
479 blink::WebNavigationPolicyNewForegroundTab, false); | 478 blink::WebNavigationPolicyNewForegroundTab, false); |
480 RenderViewImpl* new_view = RenderViewImpl::FromWebView(new_web_view); | 479 RenderViewImpl* new_view = RenderViewImpl::FromWebView(new_web_view); |
| 480 blink::WebFrameClient::NavigationPolicyInfo popup_policy_info(popup_request); |
| 481 popup_policy_info.frame = new_web_view->mainFrame()->toWebLocalFrame(); |
| 482 popup_policy_info.extraData = &state; |
| 483 popup_policy_info.navigationType = blink::WebNavigationTypeLinkClicked; |
| 484 popup_policy_info.defaultPolicy = blink::WebNavigationPolicyNewForegroundTab; |
481 policy = static_cast<RenderFrameImpl*>(new_view->GetMainRenderFrame())-> | 485 policy = static_cast<RenderFrameImpl*>(new_view->GetMainRenderFrame())-> |
482 decidePolicyForNavigation( | 486 decidePolicyForNavigation(popup_policy_info); |
483 new_web_view->mainFrame()->toWebLocalFrame(), | |
484 &state, | |
485 popup_request, | |
486 blink::WebNavigationTypeLinkClicked, | |
487 blink::WebNavigationPolicyNewForegroundTab, | |
488 false); | |
489 EXPECT_EQ(blink::WebNavigationPolicyIgnore, policy); | 487 EXPECT_EQ(blink::WebNavigationPolicyIgnore, policy); |
490 | 488 |
491 // Clean up after the new view so we don't leak it. | 489 // Clean up after the new view so we don't leak it. |
492 new_view->Close(); | 490 new_view->Close(); |
493 new_view->Release(); | 491 new_view->Release(); |
494 } | 492 } |
495 | 493 |
496 // Ensure the RenderViewImpl sends an ACK to a SwapOut request, even if it is | 494 // Ensure the RenderViewImpl sends an ACK to a SwapOut request, even if it is |
497 // already swapped out. http://crbug.com/93427. | 495 // already swapped out. http://crbug.com/93427. |
498 TEST_F(RenderViewImplTest, SendSwapOutACK) { | 496 TEST_F(RenderViewImplTest, SendSwapOutACK) { |
(...skipping 1933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2432 ProcessPendingMessages(); | 2430 ProcessPendingMessages(); |
2433 base::Time after_navigation = | 2431 base::Time after_navigation = |
2434 base::Time::Now() + base::TimeDelta::FromDays(1); | 2432 base::Time::Now() + base::TimeDelta::FromDays(1); |
2435 | 2433 |
2436 base::Time late_nav_reported_start = | 2434 base::Time late_nav_reported_start = |
2437 base::Time::FromDoubleT(GetMainFrame()->performance().navigationStart()); | 2435 base::Time::FromDoubleT(GetMainFrame()->performance().navigationStart()); |
2438 EXPECT_LE(late_nav_reported_start, after_navigation); | 2436 EXPECT_LE(late_nav_reported_start, after_navigation); |
2439 } | 2437 } |
2440 | 2438 |
2441 } // namespace content | 2439 } // namespace content |
OLD | NEW |