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" |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 TEST_F(RenderViewImplTest, DecideNavigationPolicy) { | 314 TEST_F(RenderViewImplTest, DecideNavigationPolicy) { |
315 WebUITestWebUIControllerFactory factory; | 315 WebUITestWebUIControllerFactory factory; |
316 WebUIControllerFactory::RegisterFactory(&factory); | 316 WebUIControllerFactory::RegisterFactory(&factory); |
317 | 317 |
318 // Navigations to normal HTTP URLs can be handled locally. | 318 // Navigations to normal HTTP URLs can be handled locally. |
319 WebKit::WebURLRequest request(GURL("http://foo.com")); | 319 WebKit::WebURLRequest request(GURL("http://foo.com")); |
320 WebKit::WebNavigationPolicy policy = view()->decidePolicyForNavigation( | 320 WebKit::WebNavigationPolicy policy = view()->decidePolicyForNavigation( |
321 GetMainFrame(), | 321 GetMainFrame(), |
322 request, | 322 request, |
323 WebKit::WebNavigationTypeLinkClicked, | 323 WebKit::WebNavigationTypeLinkClicked, |
324 WebKit::WebNode(), | |
325 WebKit::WebNavigationPolicyCurrentTab, | 324 WebKit::WebNavigationPolicyCurrentTab, |
326 false); | 325 false); |
327 EXPECT_EQ(WebKit::WebNavigationPolicyCurrentTab, policy); | 326 EXPECT_EQ(WebKit::WebNavigationPolicyCurrentTab, policy); |
328 | 327 |
329 // Verify that form posts to WebUI URLs will be sent to the browser process. | 328 // Verify that form posts to WebUI URLs will be sent to the browser process. |
330 WebKit::WebURLRequest form_request(GURL("chrome://foo")); | 329 WebKit::WebURLRequest form_request(GURL("chrome://foo")); |
331 form_request.setHTTPMethod("POST"); | 330 form_request.setHTTPMethod("POST"); |
332 policy = view()->decidePolicyForNavigation( | 331 policy = view()->decidePolicyForNavigation( |
333 GetMainFrame(), | 332 GetMainFrame(), |
334 form_request, | 333 form_request, |
335 WebKit::WebNavigationTypeFormSubmitted, | 334 WebKit::WebNavigationTypeFormSubmitted, |
336 WebKit::WebNode(), | |
337 WebKit::WebNavigationPolicyCurrentTab, | 335 WebKit::WebNavigationPolicyCurrentTab, |
338 false); | 336 false); |
339 EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy); | 337 EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy); |
340 | 338 |
341 // Verify that popup links to WebUI URLs also are sent to browser. | 339 // Verify that popup links to WebUI URLs also are sent to browser. |
342 WebKit::WebURLRequest popup_request(GURL("chrome://foo")); | 340 WebKit::WebURLRequest popup_request(GURL("chrome://foo")); |
343 policy = view()->decidePolicyForNavigation( | 341 policy = view()->decidePolicyForNavigation( |
344 GetMainFrame(), | 342 GetMainFrame(), |
345 popup_request, | 343 popup_request, |
346 WebKit::WebNavigationTypeLinkClicked, | 344 WebKit::WebNavigationTypeLinkClicked, |
347 WebKit::WebNode(), | |
348 WebKit::WebNavigationPolicyNewForegroundTab, | 345 WebKit::WebNavigationPolicyNewForegroundTab, |
349 false); | 346 false); |
350 EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy); | 347 EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy); |
351 } | 348 } |
352 | 349 |
353 TEST_F(RenderViewImplTest, DecideNavigationPolicyForWebUI) { | 350 TEST_F(RenderViewImplTest, DecideNavigationPolicyForWebUI) { |
354 // Enable bindings to simulate a WebUI view. | 351 // Enable bindings to simulate a WebUI view. |
355 view()->OnAllowBindings(BINDINGS_POLICY_WEB_UI); | 352 view()->OnAllowBindings(BINDINGS_POLICY_WEB_UI); |
356 | 353 |
357 // Navigations to normal HTTP URLs will be sent to browser process. | 354 // Navigations to normal HTTP URLs will be sent to browser process. |
358 WebKit::WebURLRequest request(GURL("http://foo.com")); | 355 WebKit::WebURLRequest request(GURL("http://foo.com")); |
359 WebKit::WebNavigationPolicy policy = view()->decidePolicyForNavigation( | 356 WebKit::WebNavigationPolicy policy = view()->decidePolicyForNavigation( |
360 GetMainFrame(), | 357 GetMainFrame(), |
361 request, | 358 request, |
362 WebKit::WebNavigationTypeLinkClicked, | 359 WebKit::WebNavigationTypeLinkClicked, |
363 WebKit::WebNode(), | |
364 WebKit::WebNavigationPolicyCurrentTab, | 360 WebKit::WebNavigationPolicyCurrentTab, |
365 false); | 361 false); |
366 EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy); | 362 EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy); |
367 | 363 |
368 // Navigations to WebUI URLs will also be sent to browser process. | 364 // Navigations to WebUI URLs will also be sent to browser process. |
369 WebKit::WebURLRequest webui_request(GURL("chrome://foo")); | 365 WebKit::WebURLRequest webui_request(GURL("chrome://foo")); |
370 policy = view()->decidePolicyForNavigation( | 366 policy = view()->decidePolicyForNavigation( |
371 GetMainFrame(), | 367 GetMainFrame(), |
372 webui_request, | 368 webui_request, |
373 WebKit::WebNavigationTypeLinkClicked, | 369 WebKit::WebNavigationTypeLinkClicked, |
374 WebKit::WebNode(), | |
375 WebKit::WebNavigationPolicyCurrentTab, | 370 WebKit::WebNavigationPolicyCurrentTab, |
376 false); | 371 false); |
377 EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy); | 372 EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy); |
378 | 373 |
379 // Verify that form posts to data URLs will be sent to the browser process. | 374 // Verify that form posts to data URLs will be sent to the browser process. |
380 WebKit::WebURLRequest data_request(GURL("data:text/html,foo")); | 375 WebKit::WebURLRequest data_request(GURL("data:text/html,foo")); |
381 data_request.setHTTPMethod("POST"); | 376 data_request.setHTTPMethod("POST"); |
382 policy = view()->decidePolicyForNavigation( | 377 policy = view()->decidePolicyForNavigation( |
383 GetMainFrame(), | 378 GetMainFrame(), |
384 data_request, | 379 data_request, |
385 WebKit::WebNavigationTypeFormSubmitted, | 380 WebKit::WebNavigationTypeFormSubmitted, |
386 WebKit::WebNode(), | |
387 WebKit::WebNavigationPolicyCurrentTab, | 381 WebKit::WebNavigationPolicyCurrentTab, |
388 false); | 382 false); |
389 EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy); | 383 EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy); |
390 | 384 |
391 // Verify that a popup that creates a view first and then navigates to a | 385 // Verify that a popup that creates a view first and then navigates to a |
392 // normal HTTP URL will be sent to the browser process, even though the | 386 // normal HTTP URL will be sent to the browser process, even though the |
393 // new view does not have any enabled_bindings_. | 387 // new view does not have any enabled_bindings_. |
394 WebKit::WebURLRequest popup_request(GURL("http://foo.com")); | 388 WebKit::WebURLRequest popup_request(GURL("http://foo.com")); |
395 WebKit::WebView* new_web_view = view()->createView( | 389 WebKit::WebView* new_web_view = view()->createView( |
396 GetMainFrame(), popup_request, WebKit::WebWindowFeatures(), "foo", | 390 GetMainFrame(), popup_request, WebKit::WebWindowFeatures(), "foo", |
397 WebKit::WebNavigationPolicyNewForegroundTab); | 391 WebKit::WebNavigationPolicyNewForegroundTab); |
398 RenderViewImpl* new_view = RenderViewImpl::FromWebView(new_web_view); | 392 RenderViewImpl* new_view = RenderViewImpl::FromWebView(new_web_view); |
399 policy = new_view->decidePolicyForNavigation( | 393 policy = new_view->decidePolicyForNavigation( |
400 new_web_view->mainFrame(), | 394 new_web_view->mainFrame(), |
401 popup_request, | 395 popup_request, |
402 WebKit::WebNavigationTypeLinkClicked, | 396 WebKit::WebNavigationTypeLinkClicked, |
403 WebKit::WebNode(), | |
404 WebKit::WebNavigationPolicyNewForegroundTab, | 397 WebKit::WebNavigationPolicyNewForegroundTab, |
405 false); | 398 false); |
406 EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy); | 399 EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy); |
407 | 400 |
408 // Clean up after the new view so we don't leak it. | 401 // Clean up after the new view so we don't leak it. |
409 new_view->Close(); | 402 new_view->Close(); |
410 new_view->Release(); | 403 new_view->Release(); |
411 } | 404 } |
412 | 405 |
413 // Ensure the RenderViewImpl sends an ACK to a SwapOut request, even if it is | 406 // Ensure the RenderViewImpl sends an ACK to a SwapOut request, even if it is |
(...skipping 1402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1816 | 1809 |
1817 // Copy the document content to std::wstring and compare with the | 1810 // Copy the document content to std::wstring and compare with the |
1818 // expected result. | 1811 // expected result. |
1819 const int kMaxOutputCharacters = 256; | 1812 const int kMaxOutputCharacters = 256; |
1820 std::wstring output = UTF16ToWideHack( | 1813 std::wstring output = UTF16ToWideHack( |
1821 GetMainFrame()->contentAsText(kMaxOutputCharacters)); | 1814 GetMainFrame()->contentAsText(kMaxOutputCharacters)); |
1822 EXPECT_EQ(output, L"hello \n\nworld"); | 1815 EXPECT_EQ(output, L"hello \n\nworld"); |
1823 } | 1816 } |
1824 | 1817 |
1825 } // namespace content | 1818 } // namespace content |
OLD | NEW |