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 | 6 |
7 #include "base/shared_memory.h" | 7 #include "base/shared_memory.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "content/common/view_messages.h" | 10 #include "content/common/view_messages.h" |
11 #include "content/public/browser/native_web_keyboard_event.h" | 11 #include "content/public/browser/native_web_keyboard_event.h" |
12 #include "content/public/browser/web_ui_controller_factory.h" | 12 #include "content/public/browser/web_ui_controller_factory.h" |
13 #include "content/public/common/bindings_policy.h" | 13 #include "content/public/common/bindings_policy.h" |
14 #include "content/public/common/url_constants.h" | 14 #include "content/public/common/url_constants.h" |
| 15 #include "content/public/renderer/document_state.h" |
| 16 #include "content/public/renderer/navigation_state.h" |
15 #include "content/public/test/render_view_test.h" | 17 #include "content/public/test/render_view_test.h" |
16 #include "content/renderer/render_view_impl.h" | 18 #include "content/renderer/render_view_impl.h" |
17 #include "content/shell/shell_content_browser_client.h" | 19 #include "content/shell/shell_content_browser_client.h" |
18 #include "content/shell/shell_content_client.h" | 20 #include "content/shell/shell_content_client.h" |
19 #include "content/test/mock_keyboard.h" | 21 #include "content/test/mock_keyboard.h" |
20 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "third_party/WebKit/Source/Platform/chromium/public/WebData.h" | 24 #include "third_party/WebKit/Source/Platform/chromium/public/WebData.h" |
23 #include "third_party/WebKit/Source/Platform/chromium/public/WebHTTPBody.h" | 25 #include "third_party/WebKit/Source/Platform/chromium/public/WebHTTPBody.h" |
24 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | 26 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 EXPECT_TRUE(successful); | 310 EXPECT_TRUE(successful); |
309 EXPECT_EQ(WebKit::WebHTTPBody::Element::TypeData, element.type); | 311 EXPECT_EQ(WebKit::WebHTTPBody::Element::TypeData, element.type); |
310 EXPECT_EQ(length, element.data.size()); | 312 EXPECT_EQ(length, element.data.size()); |
311 EXPECT_EQ(0, memcmp(raw_data, element.data.data(), length)); | 313 EXPECT_EQ(0, memcmp(raw_data, element.data.data(), length)); |
312 } | 314 } |
313 | 315 |
314 TEST_F(RenderViewImplTest, DecideNavigationPolicy) { | 316 TEST_F(RenderViewImplTest, DecideNavigationPolicy) { |
315 WebUITestWebUIControllerFactory factory; | 317 WebUITestWebUIControllerFactory factory; |
316 WebUIControllerFactory::RegisterFactory(&factory); | 318 WebUIControllerFactory::RegisterFactory(&factory); |
317 | 319 |
| 320 DocumentState state; |
| 321 state.set_navigation_state(NavigationState::CreateContentInitiated()); |
| 322 |
318 // Navigations to normal HTTP URLs can be handled locally. | 323 // Navigations to normal HTTP URLs can be handled locally. |
319 WebKit::WebURLRequest request(GURL("http://foo.com")); | 324 WebKit::WebURLRequest request(GURL("http://foo.com")); |
320 WebKit::WebNavigationPolicy policy = view()->decidePolicyForNavigation( | 325 WebKit::WebNavigationPolicy policy = view()->decidePolicyForNavigation( |
321 GetMainFrame(), | 326 GetMainFrame(), |
| 327 &state, |
322 request, | 328 request, |
323 WebKit::WebNavigationTypeLinkClicked, | 329 WebKit::WebNavigationTypeLinkClicked, |
324 WebKit::WebNavigationPolicyCurrentTab, | 330 WebKit::WebNavigationPolicyCurrentTab, |
325 false); | 331 false); |
326 EXPECT_EQ(WebKit::WebNavigationPolicyCurrentTab, policy); | 332 EXPECT_EQ(WebKit::WebNavigationPolicyCurrentTab, policy); |
327 | 333 |
328 // Verify that form posts to WebUI URLs will be sent to the browser process. | 334 // Verify that form posts to WebUI URLs will be sent to the browser process. |
329 WebKit::WebURLRequest form_request(GURL("chrome://foo")); | 335 WebKit::WebURLRequest form_request(GURL("chrome://foo")); |
330 form_request.setHTTPMethod("POST"); | 336 form_request.setHTTPMethod("POST"); |
331 policy = view()->decidePolicyForNavigation( | 337 policy = view()->decidePolicyForNavigation( |
332 GetMainFrame(), | 338 GetMainFrame(), |
| 339 &state, |
333 form_request, | 340 form_request, |
334 WebKit::WebNavigationTypeFormSubmitted, | 341 WebKit::WebNavigationTypeFormSubmitted, |
335 WebKit::WebNavigationPolicyCurrentTab, | 342 WebKit::WebNavigationPolicyCurrentTab, |
336 false); | 343 false); |
337 EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy); | 344 EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy); |
338 | 345 |
339 // Verify that popup links to WebUI URLs also are sent to browser. | 346 // Verify that popup links to WebUI URLs also are sent to browser. |
340 WebKit::WebURLRequest popup_request(GURL("chrome://foo")); | 347 WebKit::WebURLRequest popup_request(GURL("chrome://foo")); |
341 policy = view()->decidePolicyForNavigation( | 348 policy = view()->decidePolicyForNavigation( |
342 GetMainFrame(), | 349 GetMainFrame(), |
| 350 &state, |
343 popup_request, | 351 popup_request, |
344 WebKit::WebNavigationTypeLinkClicked, | 352 WebKit::WebNavigationTypeLinkClicked, |
345 WebKit::WebNavigationPolicyNewForegroundTab, | 353 WebKit::WebNavigationPolicyNewForegroundTab, |
346 false); | 354 false); |
347 EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy); | 355 EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy); |
348 } | 356 } |
349 | 357 |
350 TEST_F(RenderViewImplTest, DecideNavigationPolicyForWebUI) { | 358 TEST_F(RenderViewImplTest, DecideNavigationPolicyForWebUI) { |
351 // Enable bindings to simulate a WebUI view. | 359 // Enable bindings to simulate a WebUI view. |
352 view()->OnAllowBindings(BINDINGS_POLICY_WEB_UI); | 360 view()->OnAllowBindings(BINDINGS_POLICY_WEB_UI); |
353 | 361 |
| 362 DocumentState state; |
| 363 state.set_navigation_state(NavigationState::CreateContentInitiated()); |
| 364 |
354 // Navigations to normal HTTP URLs will be sent to browser process. | 365 // Navigations to normal HTTP URLs will be sent to browser process. |
355 WebKit::WebURLRequest request(GURL("http://foo.com")); | 366 WebKit::WebURLRequest request(GURL("http://foo.com")); |
356 WebKit::WebNavigationPolicy policy = view()->decidePolicyForNavigation( | 367 WebKit::WebNavigationPolicy policy = view()->decidePolicyForNavigation( |
357 GetMainFrame(), | 368 GetMainFrame(), |
| 369 &state, |
358 request, | 370 request, |
359 WebKit::WebNavigationTypeLinkClicked, | 371 WebKit::WebNavigationTypeLinkClicked, |
360 WebKit::WebNavigationPolicyCurrentTab, | 372 WebKit::WebNavigationPolicyCurrentTab, |
361 false); | 373 false); |
362 EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy); | 374 EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy); |
363 | 375 |
364 // Navigations to WebUI URLs will also be sent to browser process. | 376 // Navigations to WebUI URLs will also be sent to browser process. |
365 WebKit::WebURLRequest webui_request(GURL("chrome://foo")); | 377 WebKit::WebURLRequest webui_request(GURL("chrome://foo")); |
366 policy = view()->decidePolicyForNavigation( | 378 policy = view()->decidePolicyForNavigation( |
367 GetMainFrame(), | 379 GetMainFrame(), |
| 380 &state, |
368 webui_request, | 381 webui_request, |
369 WebKit::WebNavigationTypeLinkClicked, | 382 WebKit::WebNavigationTypeLinkClicked, |
370 WebKit::WebNavigationPolicyCurrentTab, | 383 WebKit::WebNavigationPolicyCurrentTab, |
371 false); | 384 false); |
372 EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy); | 385 EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy); |
373 | 386 |
374 // Verify that form posts to data URLs will be sent to the browser process. | 387 // Verify that form posts to data URLs will be sent to the browser process. |
375 WebKit::WebURLRequest data_request(GURL("data:text/html,foo")); | 388 WebKit::WebURLRequest data_request(GURL("data:text/html,foo")); |
376 data_request.setHTTPMethod("POST"); | 389 data_request.setHTTPMethod("POST"); |
377 policy = view()->decidePolicyForNavigation( | 390 policy = view()->decidePolicyForNavigation( |
378 GetMainFrame(), | 391 GetMainFrame(), |
| 392 &state, |
379 data_request, | 393 data_request, |
380 WebKit::WebNavigationTypeFormSubmitted, | 394 WebKit::WebNavigationTypeFormSubmitted, |
381 WebKit::WebNavigationPolicyCurrentTab, | 395 WebKit::WebNavigationPolicyCurrentTab, |
382 false); | 396 false); |
383 EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy); | 397 EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy); |
384 | 398 |
385 // Verify that a popup that creates a view first and then navigates to a | 399 // Verify that a popup that creates a view first and then navigates to a |
386 // normal HTTP URL will be sent to the browser process, even though the | 400 // normal HTTP URL will be sent to the browser process, even though the |
387 // new view does not have any enabled_bindings_. | 401 // new view does not have any enabled_bindings_. |
388 WebKit::WebURLRequest popup_request(GURL("http://foo.com")); | 402 WebKit::WebURLRequest popup_request(GURL("http://foo.com")); |
389 WebKit::WebView* new_web_view = view()->createView( | 403 WebKit::WebView* new_web_view = view()->createView( |
390 GetMainFrame(), popup_request, WebKit::WebWindowFeatures(), "foo", | 404 GetMainFrame(), popup_request, WebKit::WebWindowFeatures(), "foo", |
391 WebKit::WebNavigationPolicyNewForegroundTab); | 405 WebKit::WebNavigationPolicyNewForegroundTab); |
392 RenderViewImpl* new_view = RenderViewImpl::FromWebView(new_web_view); | 406 RenderViewImpl* new_view = RenderViewImpl::FromWebView(new_web_view); |
393 policy = new_view->decidePolicyForNavigation( | 407 policy = new_view->decidePolicyForNavigation( |
394 new_web_view->mainFrame(), | 408 new_web_view->mainFrame(), |
| 409 &state, |
395 popup_request, | 410 popup_request, |
396 WebKit::WebNavigationTypeLinkClicked, | 411 WebKit::WebNavigationTypeLinkClicked, |
397 WebKit::WebNavigationPolicyNewForegroundTab, | 412 WebKit::WebNavigationPolicyNewForegroundTab, |
398 false); | 413 false); |
399 EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy); | 414 EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy); |
400 | 415 |
401 // Clean up after the new view so we don't leak it. | 416 // Clean up after the new view so we don't leak it. |
402 new_view->Close(); | 417 new_view->Close(); |
403 new_view->Release(); | 418 new_view->Release(); |
404 } | 419 } |
(...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1381 } | 1396 } |
1382 | 1397 |
1383 // Crashy, http://crbug.com/53247. | 1398 // Crashy, http://crbug.com/53247. |
1384 TEST_F(RenderViewImplTest, DISABLED_DidFailProvisionalLoadWithErrorForError) { | 1399 TEST_F(RenderViewImplTest, DISABLED_DidFailProvisionalLoadWithErrorForError) { |
1385 GetMainFrame()->enableViewSourceMode(true); | 1400 GetMainFrame()->enableViewSourceMode(true); |
1386 WebURLError error; | 1401 WebURLError error; |
1387 error.domain = WebString::fromUTF8(net::kErrorDomain); | 1402 error.domain = WebString::fromUTF8(net::kErrorDomain); |
1388 error.reason = net::ERR_FILE_NOT_FOUND; | 1403 error.reason = net::ERR_FILE_NOT_FOUND; |
1389 error.unreachableURL = GURL("http://foo"); | 1404 error.unreachableURL = GURL("http://foo"); |
1390 WebFrame* web_frame = GetMainFrame(); | 1405 WebFrame* web_frame = GetMainFrame(); |
| 1406 |
| 1407 // Start a load that will reach provisional state synchronously, |
| 1408 // but won't complete synchronously. |
| 1409 ViewMsg_Navigate_Params params; |
| 1410 params.page_id = -1; |
| 1411 params.navigation_type = ViewMsg_Navigate_Type::NORMAL; |
| 1412 params.url = GURL("data:text/html,test data"); |
| 1413 view()->OnNavigate(params); |
| 1414 |
1391 // An error occurred. | 1415 // An error occurred. |
1392 view()->didFailProvisionalLoad(web_frame, error); | 1416 view()->didFailProvisionalLoad(web_frame, error); |
1393 // Frame should exit view-source mode. | 1417 // Frame should exit view-source mode. |
1394 EXPECT_FALSE(web_frame->isViewSourceModeEnabled()); | 1418 EXPECT_FALSE(web_frame->isViewSourceModeEnabled()); |
1395 } | 1419 } |
1396 | 1420 |
1397 TEST_F(RenderViewImplTest, DidFailProvisionalLoadWithErrorForCancellation) { | 1421 TEST_F(RenderViewImplTest, DidFailProvisionalLoadWithErrorForCancellation) { |
1398 GetMainFrame()->enableViewSourceMode(true); | 1422 GetMainFrame()->enableViewSourceMode(true); |
1399 WebURLError error; | 1423 WebURLError error; |
1400 error.domain = WebString::fromUTF8(net::kErrorDomain); | 1424 error.domain = WebString::fromUTF8(net::kErrorDomain); |
1401 error.reason = net::ERR_ABORTED; | 1425 error.reason = net::ERR_ABORTED; |
1402 error.unreachableURL = GURL("http://foo"); | 1426 error.unreachableURL = GURL("http://foo"); |
1403 WebFrame* web_frame = GetMainFrame(); | 1427 WebFrame* web_frame = GetMainFrame(); |
| 1428 |
| 1429 // Start a load that will reach provisional state synchronously, |
| 1430 // but won't complete synchronously. |
| 1431 ViewMsg_Navigate_Params params; |
| 1432 params.page_id = -1; |
| 1433 params.navigation_type = ViewMsg_Navigate_Type::NORMAL; |
| 1434 params.url = GURL("data:text/html,test data"); |
| 1435 view()->OnNavigate(params); |
| 1436 |
1404 // A cancellation occurred. | 1437 // A cancellation occurred. |
1405 view()->didFailProvisionalLoad(web_frame, error); | 1438 view()->didFailProvisionalLoad(web_frame, error); |
1406 // Frame should stay in view-source mode. | 1439 // Frame should stay in view-source mode. |
1407 EXPECT_TRUE(web_frame->isViewSourceModeEnabled()); | 1440 EXPECT_TRUE(web_frame->isViewSourceModeEnabled()); |
1408 } | 1441 } |
1409 | 1442 |
1410 // Regression test for http://crbug.com/41562 | 1443 // Regression test for http://crbug.com/41562 |
1411 TEST_F(RenderViewImplTest, UpdateTargetURLWithInvalidURL) { | 1444 TEST_F(RenderViewImplTest, UpdateTargetURLWithInvalidURL) { |
1412 const GURL invalid_gurl("http://"); | 1445 const GURL invalid_gurl("http://"); |
1413 view()->setMouseOverURL(WebKit::WebURL(invalid_gurl)); | 1446 view()->setMouseOverURL(WebKit::WebURL(invalid_gurl)); |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1809 | 1842 |
1810 // Copy the document content to std::wstring and compare with the | 1843 // Copy the document content to std::wstring and compare with the |
1811 // expected result. | 1844 // expected result. |
1812 const int kMaxOutputCharacters = 256; | 1845 const int kMaxOutputCharacters = 256; |
1813 std::wstring output = UTF16ToWideHack( | 1846 std::wstring output = UTF16ToWideHack( |
1814 GetMainFrame()->contentAsText(kMaxOutputCharacters)); | 1847 GetMainFrame()->contentAsText(kMaxOutputCharacters)); |
1815 EXPECT_EQ(output, L"hello \n\nworld"); | 1848 EXPECT_EQ(output, L"hello \n\nworld"); |
1816 } | 1849 } |
1817 | 1850 |
1818 } // namespace content | 1851 } // namespace content |
OLD | NEW |