OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 #include "public/platform/WebURLResponse.h" | 96 #include "public/platform/WebURLResponse.h" |
97 #include "public/platform/WebUnitTestSupport.h" | 97 #include "public/platform/WebUnitTestSupport.h" |
98 #include "public/web/WebCache.h" | 98 #include "public/web/WebCache.h" |
99 #include "public/web/WebConsoleMessage.h" | 99 #include "public/web/WebConsoleMessage.h" |
100 #include "public/web/WebDataSource.h" | 100 #include "public/web/WebDataSource.h" |
101 #include "public/web/WebDeviceEmulationParams.h" | 101 #include "public/web/WebDeviceEmulationParams.h" |
102 #include "public/web/WebDocument.h" | 102 #include "public/web/WebDocument.h" |
103 #include "public/web/WebFindOptions.h" | 103 #include "public/web/WebFindOptions.h" |
104 #include "public/web/WebFormElement.h" | 104 #include "public/web/WebFormElement.h" |
105 #include "public/web/WebFrameClient.h" | 105 #include "public/web/WebFrameClient.h" |
| 106 #include "public/web/WebFrameContentDumper.h" |
106 #include "public/web/WebFrameWidget.h" | 107 #include "public/web/WebFrameWidget.h" |
107 #include "public/web/WebHistoryItem.h" | 108 #include "public/web/WebHistoryItem.h" |
108 #include "public/web/WebPrintParams.h" | 109 #include "public/web/WebPrintParams.h" |
109 #include "public/web/WebRange.h" | 110 #include "public/web/WebRange.h" |
110 #include "public/web/WebRemoteFrame.h" | 111 #include "public/web/WebRemoteFrame.h" |
111 #include "public/web/WebScriptExecutionCallback.h" | 112 #include "public/web/WebScriptExecutionCallback.h" |
112 #include "public/web/WebScriptSource.h" | 113 #include "public/web/WebScriptSource.h" |
113 #include "public/web/WebSearchableFormData.h" | 114 #include "public/web/WebSearchableFormData.h" |
114 #include "public/web/WebSecurityPolicy.h" | 115 #include "public/web/WebSecurityPolicy.h" |
115 #include "public/web/WebSelection.h" | 116 #include "public/web/WebSelection.h" |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 { | 318 { |
318 registerMockedHttpURLLoad("iframes_test.html"); | 319 registerMockedHttpURLLoad("iframes_test.html"); |
319 registerMockedHttpURLLoad("visible_iframe.html"); | 320 registerMockedHttpURLLoad("visible_iframe.html"); |
320 registerMockedHttpURLLoad("invisible_iframe.html"); | 321 registerMockedHttpURLLoad("invisible_iframe.html"); |
321 registerMockedHttpURLLoad("zero_sized_iframe.html"); | 322 registerMockedHttpURLLoad("zero_sized_iframe.html"); |
322 | 323 |
323 FrameTestHelpers::WebViewHelper webViewHelper(this); | 324 FrameTestHelpers::WebViewHelper webViewHelper(this); |
324 webViewHelper.initializeAndLoad(m_baseURL + "iframes_test.html"); | 325 webViewHelper.initializeAndLoad(m_baseURL + "iframes_test.html"); |
325 | 326 |
326 // Now retrieve the frames text and test it only includes visible elements. | 327 // Now retrieve the frames text and test it only includes visible elements. |
327 std::string content = webViewHelper.webView()->mainFrame()->contentAsText(10
24).utf8(); | 328 std::string content = WebFrameContentDumper::dumpFrameTreeAsText(webViewHelp
er.webView()->mainFrame()->toWebLocalFrame(), 1024).utf8(); |
328 EXPECT_NE(std::string::npos, content.find(" visible paragraph")); | 329 EXPECT_NE(std::string::npos, content.find(" visible paragraph")); |
329 EXPECT_NE(std::string::npos, content.find(" visible iframe")); | 330 EXPECT_NE(std::string::npos, content.find(" visible iframe")); |
330 EXPECT_EQ(std::string::npos, content.find(" invisible pararaph")); | 331 EXPECT_EQ(std::string::npos, content.find(" invisible pararaph")); |
331 EXPECT_EQ(std::string::npos, content.find(" invisible iframe")); | 332 EXPECT_EQ(std::string::npos, content.find(" invisible iframe")); |
332 EXPECT_EQ(std::string::npos, content.find("iframe with zero size")); | 333 EXPECT_EQ(std::string::npos, content.find("iframe with zero size")); |
333 } | 334 } |
334 | 335 |
335 TEST_P(ParameterizedWebFrameTest, FrameForEnteredContext) | 336 TEST_P(ParameterizedWebFrameTest, FrameForEnteredContext) |
336 { | 337 { |
337 registerMockedHttpURLLoad("iframes_test.html"); | 338 registerMockedHttpURLLoad("iframes_test.html"); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 FrameTestHelpers::WebViewHelper webViewHelper(this); | 451 FrameTestHelpers::WebViewHelper webViewHelper(this); |
451 webViewHelper.initializeAndLoad(m_chromeURL + "history.html", true); | 452 webViewHelper.initializeAndLoad(m_chromeURL + "history.html", true); |
452 | 453 |
453 // Try to run JS against the chrome-style URL. | 454 // Try to run JS against the chrome-style URL. |
454 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), "javascrip
t:document.body.appendChild(document.createTextNode('Clobbered'))"); | 455 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), "javascrip
t:document.body.appendChild(document.createTextNode('Clobbered'))"); |
455 | 456 |
456 // Required to see any updates in contentAsText. | 457 // Required to see any updates in contentAsText. |
457 webViewHelper.webView()->updateAllLifecyclePhases(); | 458 webViewHelper.webView()->updateAllLifecyclePhases(); |
458 | 459 |
459 // Now retrieve the frame's text and ensure it was modified by running javas
cript. | 460 // Now retrieve the frame's text and ensure it was modified by running javas
cript. |
460 std::string content = webViewHelper.webView()->mainFrame()->contentAsText(10
24).utf8(); | 461 std::string content = WebFrameContentDumper::dumpFrameTreeAsText(webViewHelp
er.webView()->mainFrame()->toWebLocalFrame(), 1024).utf8(); |
461 EXPECT_NE(std::string::npos, content.find("Clobbered")); | 462 EXPECT_NE(std::string::npos, content.find("Clobbered")); |
462 } | 463 } |
463 | 464 |
464 TEST_P(ParameterizedWebFrameTest, ChromePageNoJavascript) | 465 TEST_P(ParameterizedWebFrameTest, ChromePageNoJavascript) |
465 { | 466 { |
466 registerMockedChromeURLLoad("history.html"); | 467 registerMockedChromeURLLoad("history.html"); |
467 | 468 |
468 /// Pass true to enable JavaScript. | 469 /// Pass true to enable JavaScript. |
469 FrameTestHelpers::WebViewHelper webViewHelper(this); | 470 FrameTestHelpers::WebViewHelper webViewHelper(this); |
470 webViewHelper.initializeAndLoad(m_chromeURL + "history.html", true); | 471 webViewHelper.initializeAndLoad(m_chromeURL + "history.html", true); |
471 | 472 |
472 // Try to run JS against the chrome-style URL after prohibiting it. | 473 // Try to run JS against the chrome-style URL after prohibiting it. |
473 WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs("chrome"); | 474 WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs("chrome"); |
474 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), "javascrip
t:document.body.appendChild(document.createTextNode('Clobbered'))"); | 475 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), "javascrip
t:document.body.appendChild(document.createTextNode('Clobbered'))"); |
475 | 476 |
476 // Required to see any updates in contentAsText. | 477 // Required to see any updates in contentAsText. |
477 webViewHelper.webView()->updateAllLifecyclePhases(); | 478 webViewHelper.webView()->updateAllLifecyclePhases(); |
478 | 479 |
479 // Now retrieve the frame's text and ensure it wasn't modified by running ja
vascript. | 480 // Now retrieve the frame's text and ensure it wasn't modified by running ja
vascript. |
480 std::string content = webViewHelper.webView()->mainFrame()->contentAsText(10
24).utf8(); | 481 std::string content = WebFrameContentDumper::dumpFrameTreeAsText(webViewHelp
er.webView()->mainFrame()->toWebLocalFrame(), 1024).utf8(); |
481 EXPECT_EQ(std::string::npos, content.find("Clobbered")); | 482 EXPECT_EQ(std::string::npos, content.find("Clobbered")); |
482 } | 483 } |
483 | 484 |
484 TEST_P(ParameterizedWebFrameTest, LocationSetHostWithMissingPort) | 485 TEST_P(ParameterizedWebFrameTest, LocationSetHostWithMissingPort) |
485 { | 486 { |
486 std::string fileName = "print-location-href.html"; | 487 std::string fileName = "print-location-href.html"; |
487 registerMockedHttpURLLoad(fileName); | 488 registerMockedHttpURLLoad(fileName); |
488 URLTestHelpers::registerMockedURLLoad(toKURL("http://internal.test:0/" + fil
eName), WebString::fromUTF8(fileName)); | 489 URLTestHelpers::registerMockedURLLoad(toKURL("http://internal.test:0/" + fil
eName), WebString::fromUTF8(fileName)); |
489 | 490 |
490 FrameTestHelpers::WebViewHelper webViewHelper(this); | 491 FrameTestHelpers::WebViewHelper webViewHelper(this); |
491 | 492 |
492 /// Pass true to enable JavaScript. | 493 /// Pass true to enable JavaScript. |
493 webViewHelper.initializeAndLoad(m_baseURL + fileName, true); | 494 webViewHelper.initializeAndLoad(m_baseURL + fileName, true); |
494 | 495 |
495 // Setting host to "hostname:" should be treated as "hostname:0". | 496 // Setting host to "hostname:" should be treated as "hostname:0". |
496 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), "javascrip
t:location.host = 'internal.test:'; void 0;"); | 497 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), "javascrip
t:location.host = 'internal.test:'; void 0;"); |
497 | 498 |
498 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), "javascrip
t:document.body.textContent = location.href; void 0;"); | 499 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), "javascrip
t:document.body.textContent = location.href; void 0;"); |
499 | 500 |
500 std::string content = webViewHelper.webView()->mainFrame()->contentAsText(10
24).utf8(); | 501 std::string content = WebFrameContentDumper::dumpFrameTreeAsText(webViewHelp
er.webView()->mainFrame()->toWebLocalFrame(), 1024).utf8(); |
501 EXPECT_EQ("http://internal.test:0/" + fileName, content); | 502 EXPECT_EQ("http://internal.test:0/" + fileName, content); |
502 } | 503 } |
503 | 504 |
504 TEST_P(ParameterizedWebFrameTest, LocationSetEmptyPort) | 505 TEST_P(ParameterizedWebFrameTest, LocationSetEmptyPort) |
505 { | 506 { |
506 std::string fileName = "print-location-href.html"; | 507 std::string fileName = "print-location-href.html"; |
507 registerMockedHttpURLLoad(fileName); | 508 registerMockedHttpURLLoad(fileName); |
508 URLTestHelpers::registerMockedURLLoad(toKURL("http://internal.test:0/" + fil
eName), WebString::fromUTF8(fileName)); | 509 URLTestHelpers::registerMockedURLLoad(toKURL("http://internal.test:0/" + fil
eName), WebString::fromUTF8(fileName)); |
509 | 510 |
510 FrameTestHelpers::WebViewHelper webViewHelper(this); | 511 FrameTestHelpers::WebViewHelper webViewHelper(this); |
511 | 512 |
512 /// Pass true to enable JavaScript. | 513 /// Pass true to enable JavaScript. |
513 webViewHelper.initializeAndLoad(m_baseURL + fileName, true); | 514 webViewHelper.initializeAndLoad(m_baseURL + fileName, true); |
514 | 515 |
515 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), "javascrip
t:location.port = ''; void 0;"); | 516 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), "javascrip
t:location.port = ''; void 0;"); |
516 | 517 |
517 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), "javascrip
t:document.body.textContent = location.href; void 0;"); | 518 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), "javascrip
t:document.body.textContent = location.href; void 0;"); |
518 | 519 |
519 std::string content = webViewHelper.webView()->mainFrame()->contentAsText(10
24).utf8(); | 520 std::string content = WebFrameContentDumper::dumpFrameTreeAsText(webViewHelp
er.webView()->mainFrame()->toWebLocalFrame(), 1024).utf8(); |
520 EXPECT_EQ("http://internal.test:0/" + fileName, content); | 521 EXPECT_EQ("http://internal.test:0/" + fileName, content); |
521 } | 522 } |
522 | 523 |
523 class EvaluateOnLoadWebFrameClient : public FrameTestHelpers::TestWebFrameClient
{ | 524 class EvaluateOnLoadWebFrameClient : public FrameTestHelpers::TestWebFrameClient
{ |
524 public: | 525 public: |
525 EvaluateOnLoadWebFrameClient() : m_executing(false), m_wasExecuted(false) {
} | 526 EvaluateOnLoadWebFrameClient() : m_executing(false), m_wasExecuted(false) {
} |
526 | 527 |
527 void didClearWindowObject(WebLocalFrame* frame) override | 528 void didClearWindowObject(WebLocalFrame* frame) override |
528 { | 529 { |
529 EXPECT_FALSE(m_executing); | 530 EXPECT_FALSE(m_executing); |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 webViewHelper.webView()->mainFrame()->dispatchMessageEventWithOriginCheck(co
rrectOrigin, message); | 830 webViewHelper.webView()->mainFrame()->dispatchMessageEventWithOriginCheck(co
rrectOrigin, message); |
830 | 831 |
831 // Send another message with incorrect origin. | 832 // Send another message with incorrect origin. |
832 WebSecurityOrigin incorrectOrigin(WebSecurityOrigin::create(toKURL(m_chromeU
RL))); | 833 WebSecurityOrigin incorrectOrigin(WebSecurityOrigin::create(toKURL(m_chromeU
RL))); |
833 webViewHelper.webView()->mainFrame()->dispatchMessageEventWithOriginCheck(in
correctOrigin, message); | 834 webViewHelper.webView()->mainFrame()->dispatchMessageEventWithOriginCheck(in
correctOrigin, message); |
834 | 835 |
835 // Required to see any updates in contentAsText. | 836 // Required to see any updates in contentAsText. |
836 webViewHelper.webView()->updateAllLifecyclePhases(); | 837 webViewHelper.webView()->updateAllLifecyclePhases(); |
837 | 838 |
838 // Verify that only the first addition is in the body of the page. | 839 // Verify that only the first addition is in the body of the page. |
839 std::string content = webViewHelper.webView()->mainFrame()->contentAsText(10
24).utf8(); | 840 std::string content = WebFrameContentDumper::dumpFrameTreeAsText(webViewHelp
er.webView()->mainFrame()->toWebLocalFrame(), 1024).utf8(); |
840 EXPECT_NE(std::string::npos, content.find("Message 1.")); | 841 EXPECT_NE(std::string::npos, content.find("Message 1.")); |
841 EXPECT_EQ(std::string::npos, content.find("Message 2.")); | 842 EXPECT_EQ(std::string::npos, content.find("Message 2.")); |
842 } | 843 } |
843 | 844 |
844 TEST_P(ParameterizedWebFrameTest, PostMessageThenDetach) | 845 TEST_P(ParameterizedWebFrameTest, PostMessageThenDetach) |
845 { | 846 { |
846 FrameTestHelpers::WebViewHelper webViewHelper(this); | 847 FrameTestHelpers::WebViewHelper webViewHelper(this); |
847 webViewHelper.initializeAndLoad("about:blank"); | 848 webViewHelper.initializeAndLoad("about:blank"); |
848 | 849 |
849 RefPtrWillBeRawPtr<LocalFrame> frame = toLocalFrame(webViewHelper.webViewImp
l()->page()->mainFrame()); | 850 RefPtrWillBeRawPtr<LocalFrame> frame = toLocalFrame(webViewHelper.webViewImp
l()->page()->mainFrame()); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1027 | 1028 |
1028 EXPECT_EQ(2, webViewHelper.webViewImpl()->page()->deviceScaleFactor()); | 1029 EXPECT_EQ(2, webViewHelper.webViewImpl()->page()->deviceScaleFactor()); |
1029 | 1030 |
1030 // Device scale factor should be independent of page scale. | 1031 // Device scale factor should be independent of page scale. |
1031 webViewHelper.webView()->setDefaultPageScaleLimits(1, 2); | 1032 webViewHelper.webView()->setDefaultPageScaleLimits(1, 2); |
1032 webViewHelper.webView()->setPageScaleFactor(0.5); | 1033 webViewHelper.webView()->setPageScaleFactor(0.5); |
1033 webViewHelper.webView()->updateAllLifecyclePhases(); | 1034 webViewHelper.webView()->updateAllLifecyclePhases(); |
1034 EXPECT_EQ(1, webViewHelper.webView()->pageScaleFactor()); | 1035 EXPECT_EQ(1, webViewHelper.webView()->pageScaleFactor()); |
1035 | 1036 |
1036 // Force the layout to happen before leaving the test. | 1037 // Force the layout to happen before leaving the test. |
1037 webViewHelper.webView()->mainFrame()->contentAsText(1024).utf8(); | 1038 WebFrameContentDumper::dumpFrameTreeAsText(webViewHelper.webView()->mainFram
e()->toWebLocalFrame(), 1024).utf8(); |
1038 } | 1039 } |
1039 | 1040 |
1040 TEST_P(ParameterizedWebFrameTest, FixedLayoutInitializeAtMinimumScale) | 1041 TEST_P(ParameterizedWebFrameTest, FixedLayoutInitializeAtMinimumScale) |
1041 { | 1042 { |
1042 registerMockedHttpURLLoad("fixed_layout.html"); | 1043 registerMockedHttpURLLoad("fixed_layout.html"); |
1043 | 1044 |
1044 FixedLayoutTestWebViewClient client; | 1045 FixedLayoutTestWebViewClient client; |
1045 client.m_screenInfo.deviceScaleFactor = 1; | 1046 client.m_screenInfo.deviceScaleFactor = 1; |
1046 int viewportWidth = 640; | 1047 int viewportWidth = 640; |
1047 int viewportHeight = 480; | 1048 int viewportHeight = 480; |
(...skipping 2576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3624 webViewHelper.resize(WebSize(640, 480)); | 3625 webViewHelper.resize(WebSize(640, 480)); |
3625 WebFrame* frame = webViewHelper.webView()->mainFrame(); | 3626 WebFrame* frame = webViewHelper.webView()->mainFrame(); |
3626 | 3627 |
3627 // Generate a simple test case. | 3628 // Generate a simple test case. |
3628 const char simpleSource[] = "<div>Foo bar</div><div></div>baz"; | 3629 const char simpleSource[] = "<div>Foo bar</div><div></div>baz"; |
3629 KURL testURL = toKURL("about:blank"); | 3630 KURL testURL = toKURL("about:blank"); |
3630 FrameTestHelpers::loadHTMLString(frame, simpleSource, testURL); | 3631 FrameTestHelpers::loadHTMLString(frame, simpleSource, testURL); |
3631 | 3632 |
3632 // Make sure it comes out OK. | 3633 // Make sure it comes out OK. |
3633 const std::string expected("Foo bar\nbaz"); | 3634 const std::string expected("Foo bar\nbaz"); |
3634 WebString text = frame->contentAsText(std::numeric_limits<size_t>::max()); | 3635 WebString text = WebFrameContentDumper::dumpFrameTreeAsText(frame->toWebLoca
lFrame(), std::numeric_limits<size_t>::max()); |
3635 EXPECT_EQ(expected, text.utf8()); | 3636 EXPECT_EQ(expected, text.utf8()); |
3636 | 3637 |
3637 // Try reading the same one with clipping of the text. | 3638 // Try reading the same one with clipping of the text. |
3638 const int length = 5; | 3639 const int length = 5; |
3639 text = frame->contentAsText(length); | 3640 text = WebFrameContentDumper::dumpFrameTreeAsText(frame->toWebLocalFrame(),
length); |
3640 EXPECT_EQ(expected.substr(0, length), text.utf8()); | 3641 EXPECT_EQ(expected.substr(0, length), text.utf8()); |
3641 | 3642 |
3642 // Now do a new test with a subframe. | 3643 // Now do a new test with a subframe. |
3643 const char outerFrameSource[] = "Hello<iframe></iframe> world"; | 3644 const char outerFrameSource[] = "Hello<iframe></iframe> world"; |
3644 FrameTestHelpers::loadHTMLString(frame, outerFrameSource, testURL); | 3645 FrameTestHelpers::loadHTMLString(frame, outerFrameSource, testURL); |
3645 | 3646 |
3646 // Load something into the subframe. | 3647 // Load something into the subframe. |
3647 WebFrame* subframe = frame->firstChild(); | 3648 WebFrame* subframe = frame->firstChild(); |
3648 ASSERT_TRUE(subframe); | 3649 ASSERT_TRUE(subframe); |
3649 FrameTestHelpers::loadHTMLString(subframe, "sub<p>text", testURL); | 3650 FrameTestHelpers::loadHTMLString(subframe, "sub<p>text", testURL); |
3650 | 3651 |
3651 text = frame->contentAsText(std::numeric_limits<size_t>::max()); | 3652 text = WebFrameContentDumper::dumpFrameTreeAsText(frame->toWebLocalFrame(),
std::numeric_limits<size_t>::max()); |
3652 EXPECT_EQ("Hello world\n\nsub\ntext", text.utf8()); | 3653 EXPECT_EQ("Hello world\n\nsub\ntext", text.utf8()); |
3653 | 3654 |
3654 // Get the frame text where the subframe separator falls on the boundary of | 3655 // Get the frame text where the subframe separator falls on the boundary of |
3655 // what we'll take. There used to be a crash in this case. | 3656 // what we'll take. There used to be a crash in this case. |
3656 text = frame->contentAsText(12); | 3657 text = WebFrameContentDumper::dumpFrameTreeAsText(frame->toWebLocalFrame(),
12); |
3657 EXPECT_EQ("Hello world", text.utf8()); | 3658 EXPECT_EQ("Hello world", text.utf8()); |
3658 } | 3659 } |
3659 | 3660 |
3660 TEST_P(ParameterizedWebFrameTest, GetFullHtmlOfPage) | 3661 TEST_P(ParameterizedWebFrameTest, GetFullHtmlOfPage) |
3661 { | 3662 { |
3662 FrameTestHelpers::WebViewHelper webViewHelper(this); | 3663 FrameTestHelpers::WebViewHelper webViewHelper(this); |
3663 webViewHelper.initializeAndLoad("about:blank", true); | 3664 webViewHelper.initializeAndLoad("about:blank", true); |
3664 WebFrame* frame = webViewHelper.webView()->mainFrame(); | 3665 WebFrame* frame = webViewHelper.webView()->mainFrame(); |
3665 | 3666 |
3666 // Generate a simple test case. | 3667 // Generate a simple test case. |
3667 const char simpleSource[] = "<p>Hello</p><p>World</p>"; | 3668 const char simpleSource[] = "<p>Hello</p><p>World</p>"; |
3668 KURL testURL = toKURL("about:blank"); | 3669 KURL testURL = toKURL("about:blank"); |
3669 FrameTestHelpers::loadHTMLString(frame, simpleSource, testURL); | 3670 FrameTestHelpers::loadHTMLString(frame, simpleSource, testURL); |
3670 | 3671 |
3671 WebString text = frame->contentAsText(std::numeric_limits<size_t>::max()); | 3672 WebString text = WebFrameContentDumper::dumpFrameTreeAsText(frame->toWebLoca
lFrame(), std::numeric_limits<size_t>::max()); |
3672 EXPECT_EQ("Hello\n\nWorld", text.utf8()); | 3673 EXPECT_EQ("Hello\n\nWorld", text.utf8()); |
3673 | 3674 |
3674 const std::string html = frame->contentAsMarkup().utf8(); | 3675 const std::string html = WebFrameContentDumper::dumpAsMarkup(frame->toWebLoc
alFrame()).utf8(); |
3675 | 3676 |
3676 // Load again with the output html. | 3677 // Load again with the output html. |
3677 FrameTestHelpers::loadHTMLString(frame, html, testURL); | 3678 FrameTestHelpers::loadHTMLString(frame, html, testURL); |
3678 | 3679 |
3679 EXPECT_EQ(html, frame->contentAsMarkup().utf8()); | 3680 EXPECT_EQ(html, WebFrameContentDumper::dumpAsMarkup(frame->toWebLocalFrame()
).utf8()); |
3680 | 3681 |
3681 text = frame->contentAsText(std::numeric_limits<size_t>::max()); | 3682 text = WebFrameContentDumper::dumpFrameTreeAsText(frame->toWebLocalFrame(),
std::numeric_limits<size_t>::max()); |
3682 EXPECT_EQ("Hello\n\nWorld", text.utf8()); | 3683 EXPECT_EQ("Hello\n\nWorld", text.utf8()); |
3683 | 3684 |
3684 // Test selection check | 3685 // Test selection check |
3685 EXPECT_FALSE(frame->hasSelection()); | 3686 EXPECT_FALSE(frame->hasSelection()); |
3686 frame->executeCommand(WebString::fromUTF8("SelectAll")); | 3687 frame->executeCommand(WebString::fromUTF8("SelectAll")); |
3687 EXPECT_TRUE(frame->hasSelection()); | 3688 EXPECT_TRUE(frame->hasSelection()); |
3688 frame->executeCommand(WebString::fromUTF8("Unselect")); | 3689 frame->executeCommand(WebString::fromUTF8("Unselect")); |
3689 EXPECT_FALSE(frame->hasSelection()); | 3690 EXPECT_FALSE(frame->hasSelection()); |
3690 WebString selectionHtml = frame->selectionAsMarkup(); | 3691 WebString selectionHtml = frame->selectionAsMarkup(); |
3691 EXPECT_TRUE(selectionHtml.isEmpty()); | 3692 EXPECT_TRUE(selectionHtml.isEmpty()); |
(...skipping 1347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5039 response.initialize(); | 5040 response.initialize(); |
5040 response.setURL(URLTestHelpers::toKURL(errorURL)); | 5041 response.setURL(URLTestHelpers::toKURL(errorURL)); |
5041 response.setMIMEType("text/html"); | 5042 response.setMIMEType("text/html"); |
5042 response.setHTTPStatusCode(500); | 5043 response.setHTTPStatusCode(500); |
5043 WebHistoryItem errorHistoryItem; | 5044 WebHistoryItem errorHistoryItem; |
5044 errorHistoryItem.initialize(); | 5045 errorHistoryItem.initialize(); |
5045 errorHistoryItem.setURLString(WebString::fromUTF8(errorURL.c_str(), errorURL
.length())); | 5046 errorHistoryItem.setURLString(WebString::fromUTF8(errorURL.c_str(), errorURL
.length())); |
5046 Platform::current()->unitTestSupport()->registerMockedErrorURL(URLTestHelper
s::toKURL(errorURL), response, error); | 5047 Platform::current()->unitTestSupport()->registerMockedErrorURL(URLTestHelper
s::toKURL(errorURL), response, error); |
5047 FrameTestHelpers::loadHistoryItem(frame, errorHistoryItem, WebHistoryDiffere
ntDocumentLoad, WebURLRequest::UseProtocolCachePolicy); | 5048 FrameTestHelpers::loadHistoryItem(frame, errorHistoryItem, WebHistoryDiffere
ntDocumentLoad, WebURLRequest::UseProtocolCachePolicy); |
5048 | 5049 |
5049 WebString text = frame->contentAsText(std::numeric_limits<size_t>::max()); | 5050 WebString text = WebFrameContentDumper::dumpFrameTreeAsText(frame->toWebLoca
lFrame(), std::numeric_limits<size_t>::max()); |
5050 EXPECT_EQ("This should appear", text.utf8()); | 5051 EXPECT_EQ("This should appear", text.utf8()); |
5051 EXPECT_TRUE(webFrameClient.commitCalled()); | 5052 EXPECT_TRUE(webFrameClient.commitCalled()); |
5052 } | 5053 } |
5053 | 5054 |
5054 class TestWillInsertBodyWebFrameClient : public FrameTestHelpers::TestWebFrameCl
ient { | 5055 class TestWillInsertBodyWebFrameClient : public FrameTestHelpers::TestWebFrameCl
ient { |
5055 public: | 5056 public: |
5056 TestWillInsertBodyWebFrameClient() : m_numBodies(0), m_didLoad(false) | 5057 TestWillInsertBodyWebFrameClient() : m_numBodies(0), m_didLoad(false) |
5057 { | 5058 { |
5058 } | 5059 } |
5059 | 5060 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5152 | 5153 |
5153 const int allTextBeginOffset = 0; | 5154 const int allTextBeginOffset = 0; |
5154 const int allTextLength = 11; | 5155 const int allTextLength = 11; |
5155 frame->selectRange(WebRange::fromDocumentRange(frame, allTextBeginOffset, al
lTextLength)); | 5156 frame->selectRange(WebRange::fromDocumentRange(frame, allTextBeginOffset, al
lTextLength)); |
5156 EphemeralRange selectionRange = frame->frame()->selection().selection().toNo
rmalizedEphemeralRange(); | 5157 EphemeralRange selectionRange = frame->frame()->selection().selection().toNo
rmalizedEphemeralRange(); |
5157 | 5158 |
5158 EXPECT_EQ(1, spellcheck.numberOfTimesChecked()); | 5159 EXPECT_EQ(1, spellcheck.numberOfTimesChecked()); |
5159 EXPECT_EQ(1U, document->markers().markersInRange(selectionRange, DocumentMar
ker::Spelling).size()); | 5160 EXPECT_EQ(1U, document->markers().markersInRange(selectionRange, DocumentMar
ker::Spelling).size()); |
5160 | 5161 |
5161 frame->replaceMisspelledRange("welcome"); | 5162 frame->replaceMisspelledRange("welcome"); |
5162 EXPECT_EQ("_welcome_.", frame->contentAsText(std::numeric_limits<size_t>::ma
x()).utf8()); | 5163 EXPECT_EQ("_welcome_.", WebFrameContentDumper::dumpFrameTreeAsText(frame->to
WebLocalFrame(), std::numeric_limits<size_t>::max()).utf8()); |
5163 } | 5164 } |
5164 | 5165 |
5165 TEST_P(ParameterizedWebFrameTest, RemoveSpellingMarkers) | 5166 TEST_P(ParameterizedWebFrameTest, RemoveSpellingMarkers) |
5166 { | 5167 { |
5167 registerMockedHttpURLLoad("spell.html"); | 5168 registerMockedHttpURLLoad("spell.html"); |
5168 FrameTestHelpers::WebViewHelper webViewHelper(this); | 5169 FrameTestHelpers::WebViewHelper webViewHelper(this); |
5169 webViewHelper.initializeAndLoad(m_baseURL + "spell.html"); | 5170 webViewHelper.initializeAndLoad(m_baseURL + "spell.html"); |
5170 SpellCheckClient spellcheck; | 5171 SpellCheckClient spellcheck; |
5171 webViewHelper.webView()->setSpellCheckClient(&spellcheck); | 5172 webViewHelper.webView()->setSpellCheckClient(&spellcheck); |
5172 | 5173 |
(...skipping 1794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6967 WebRemoteFrame* remoteFrame = WebRemoteFrame::create(WebTreeScopeType::Docum
ent, nullptr); | 6968 WebRemoteFrame* remoteFrame = WebRemoteFrame::create(WebTreeScopeType::Docum
ent, nullptr); |
6968 mainFrame()->swap(remoteFrame); | 6969 mainFrame()->swap(remoteFrame); |
6969 | 6970 |
6970 FrameTestHelpers::TestWebFrameClient client; | 6971 FrameTestHelpers::TestWebFrameClient client; |
6971 WebLocalFrame* localFrame = WebLocalFrame::createProvisional(&client, remote
Frame, WebSandboxFlags::None, WebFrameOwnerProperties()); | 6972 WebLocalFrame* localFrame = WebLocalFrame::createProvisional(&client, remote
Frame, WebSandboxFlags::None, WebFrameOwnerProperties()); |
6972 remoteFrame->swap(localFrame); | 6973 remoteFrame->swap(localFrame); |
6973 | 6974 |
6974 // Finally, make sure an embedder triggered load in the local frame swapped | 6975 // Finally, make sure an embedder triggered load in the local frame swapped |
6975 // back in works. | 6976 // back in works. |
6976 FrameTestHelpers::loadFrame(localFrame, m_baseURL + "subframe-hello.html"); | 6977 FrameTestHelpers::loadFrame(localFrame, m_baseURL + "subframe-hello.html"); |
6977 std::string content = localFrame->contentAsText(1024).utf8(); | 6978 std::string content = WebFrameContentDumper::dumpFrameTreeAsText(localFrame,
1024).utf8(); |
6978 EXPECT_EQ("hello", content); | 6979 EXPECT_EQ("hello", content); |
6979 | 6980 |
6980 // Manually reset to break WebViewHelper's dependency on the stack allocated | 6981 // Manually reset to break WebViewHelper's dependency on the stack allocated |
6981 // TestWebFrameClient. | 6982 // TestWebFrameClient. |
6982 reset(); | 6983 reset(); |
6983 remoteFrame->close(); | 6984 remoteFrame->close(); |
6984 } | 6985 } |
6985 | 6986 |
6986 TEST_F(WebFrameSwapTest, ValidateSizeOnRemoteToLocalMainFrameSwap) | 6987 TEST_F(WebFrameSwapTest, ValidateSizeOnRemoteToLocalMainFrameSwap) |
6987 { | 6988 { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7069 | 7070 |
7070 FrameTestHelpers::TestWebFrameClient client; | 7071 FrameTestHelpers::TestWebFrameClient client; |
7071 WebLocalFrame* localFrame = WebLocalFrame::createProvisional(&client, remote
Frame, WebSandboxFlags::None, WebFrameOwnerProperties()); | 7072 WebLocalFrame* localFrame = WebLocalFrame::createProvisional(&client, remote
Frame, WebSandboxFlags::None, WebFrameOwnerProperties()); |
7072 swapAndVerifyFirstChildConsistency("remote->local", mainFrame(), localFrame)
; | 7073 swapAndVerifyFirstChildConsistency("remote->local", mainFrame(), localFrame)
; |
7073 | 7074 |
7074 // FIXME: This almost certainly fires more load events on the iframe element | 7075 // FIXME: This almost certainly fires more load events on the iframe element |
7075 // than it should. | 7076 // than it should. |
7076 // Finally, make sure an embedder triggered load in the local frame swapped | 7077 // Finally, make sure an embedder triggered load in the local frame swapped |
7077 // back in works. | 7078 // back in works. |
7078 FrameTestHelpers::loadFrame(localFrame, m_baseURL + "subframe-hello.html"); | 7079 FrameTestHelpers::loadFrame(localFrame, m_baseURL + "subframe-hello.html"); |
7079 std::string content = localFrame->contentAsText(1024).utf8(); | 7080 std::string content = WebFrameContentDumper::dumpFrameTreeAsText(localFrame,
1024).utf8(); |
7080 EXPECT_EQ("hello", content); | 7081 EXPECT_EQ("hello", content); |
7081 | 7082 |
7082 // Manually reset to break WebViewHelper's dependency on the stack allocated | 7083 // Manually reset to break WebViewHelper's dependency on the stack allocated |
7083 // TestWebFrameClient. | 7084 // TestWebFrameClient. |
7084 reset(); | 7085 reset(); |
7085 remoteFrame->close(); | 7086 remoteFrame->close(); |
7086 } | 7087 } |
7087 | 7088 |
7088 void swapAndVerifyMiddleChildConsistency(const char* const message, WebFrame* pa
rent, WebFrame* newChild) | 7089 void swapAndVerifyMiddleChildConsistency(const char* const message, WebFrame* pa
rent, WebFrame* newChild) |
7089 { | 7090 { |
(...skipping 17 matching lines...) Expand all Loading... |
7107 | 7108 |
7108 FrameTestHelpers::TestWebFrameClient client; | 7109 FrameTestHelpers::TestWebFrameClient client; |
7109 WebLocalFrame* localFrame = WebLocalFrame::createProvisional(&client, remote
Frame, WebSandboxFlags::None, WebFrameOwnerProperties()); | 7110 WebLocalFrame* localFrame = WebLocalFrame::createProvisional(&client, remote
Frame, WebSandboxFlags::None, WebFrameOwnerProperties()); |
7110 swapAndVerifyMiddleChildConsistency("remote->local", mainFrame(), localFrame
); | 7111 swapAndVerifyMiddleChildConsistency("remote->local", mainFrame(), localFrame
); |
7111 | 7112 |
7112 // FIXME: This almost certainly fires more load events on the iframe element | 7113 // FIXME: This almost certainly fires more load events on the iframe element |
7113 // than it should. | 7114 // than it should. |
7114 // Finally, make sure an embedder triggered load in the local frame swapped | 7115 // Finally, make sure an embedder triggered load in the local frame swapped |
7115 // back in works. | 7116 // back in works. |
7116 FrameTestHelpers::loadFrame(localFrame, m_baseURL + "subframe-hello.html"); | 7117 FrameTestHelpers::loadFrame(localFrame, m_baseURL + "subframe-hello.html"); |
7117 std::string content = localFrame->contentAsText(1024).utf8(); | 7118 std::string content = WebFrameContentDumper::dumpFrameTreeAsText(localFrame,
1024).utf8(); |
7118 EXPECT_EQ("hello", content); | 7119 EXPECT_EQ("hello", content); |
7119 | 7120 |
7120 // Manually reset to break WebViewHelper's dependency on the stack allocated | 7121 // Manually reset to break WebViewHelper's dependency on the stack allocated |
7121 // TestWebFrameClient. | 7122 // TestWebFrameClient. |
7122 reset(); | 7123 reset(); |
7123 remoteFrame->close(); | 7124 remoteFrame->close(); |
7124 } | 7125 } |
7125 | 7126 |
7126 void swapAndVerifyLastChildConsistency(const char* const message, WebFrame* pare
nt, WebFrame* newChild) | 7127 void swapAndVerifyLastChildConsistency(const char* const message, WebFrame* pare
nt, WebFrame* newChild) |
7127 { | 7128 { |
(...skipping 14 matching lines...) Expand all Loading... |
7142 | 7143 |
7143 FrameTestHelpers::TestWebFrameClient client; | 7144 FrameTestHelpers::TestWebFrameClient client; |
7144 WebLocalFrame* localFrame = WebLocalFrame::createProvisional(&client, remote
Frame, WebSandboxFlags::None, WebFrameOwnerProperties()); | 7145 WebLocalFrame* localFrame = WebLocalFrame::createProvisional(&client, remote
Frame, WebSandboxFlags::None, WebFrameOwnerProperties()); |
7145 swapAndVerifyLastChildConsistency("remote->local", mainFrame(), localFrame); | 7146 swapAndVerifyLastChildConsistency("remote->local", mainFrame(), localFrame); |
7146 | 7147 |
7147 // FIXME: This almost certainly fires more load events on the iframe element | 7148 // FIXME: This almost certainly fires more load events on the iframe element |
7148 // than it should. | 7149 // than it should. |
7149 // Finally, make sure an embedder triggered load in the local frame swapped | 7150 // Finally, make sure an embedder triggered load in the local frame swapped |
7150 // back in works. | 7151 // back in works. |
7151 FrameTestHelpers::loadFrame(localFrame, m_baseURL + "subframe-hello.html"); | 7152 FrameTestHelpers::loadFrame(localFrame, m_baseURL + "subframe-hello.html"); |
7152 std::string content = localFrame->contentAsText(1024).utf8(); | 7153 std::string content = WebFrameContentDumper::dumpFrameTreeAsText(localFrame,
1024).utf8(); |
7153 EXPECT_EQ("hello", content); | 7154 EXPECT_EQ("hello", content); |
7154 | 7155 |
7155 // Manually reset to break WebViewHelper's dependency on the stack allocated | 7156 // Manually reset to break WebViewHelper's dependency on the stack allocated |
7156 // TestWebFrameClient. | 7157 // TestWebFrameClient. |
7157 reset(); | 7158 reset(); |
7158 remoteFrame->close(); | 7159 remoteFrame->close(); |
7159 } | 7160 } |
7160 | 7161 |
7161 void swapAndVerifySubframeConsistency(const char* const message, WebFrame* oldFr
ame, WebFrame* newFrame) | 7162 void swapAndVerifySubframeConsistency(const char* const message, WebFrame* oldFr
ame, WebFrame* newFrame) |
7162 { | 7163 { |
(...skipping 23 matching lines...) Expand all Loading... |
7186 | 7187 |
7187 FrameTestHelpers::TestWebFrameClient client; | 7188 FrameTestHelpers::TestWebFrameClient client; |
7188 WebLocalFrame* localFrame = WebLocalFrame::createProvisional(&client, remote
Frame, WebSandboxFlags::None, WebFrameOwnerProperties()); | 7189 WebLocalFrame* localFrame = WebLocalFrame::createProvisional(&client, remote
Frame, WebSandboxFlags::None, WebFrameOwnerProperties()); |
7189 swapAndVerifySubframeConsistency("remote->local", targetFrame, localFrame); | 7190 swapAndVerifySubframeConsistency("remote->local", targetFrame, localFrame); |
7190 | 7191 |
7191 // FIXME: This almost certainly fires more load events on the iframe element | 7192 // FIXME: This almost certainly fires more load events on the iframe element |
7192 // than it should. | 7193 // than it should. |
7193 // Finally, make sure an embedder triggered load in the local frame swapped | 7194 // Finally, make sure an embedder triggered load in the local frame swapped |
7194 // back in works. | 7195 // back in works. |
7195 FrameTestHelpers::loadFrame(localFrame, m_baseURL + "subframe-hello.html"); | 7196 FrameTestHelpers::loadFrame(localFrame, m_baseURL + "subframe-hello.html"); |
7196 std::string content = localFrame->contentAsText(1024).utf8(); | 7197 std::string content = WebFrameContentDumper::dumpFrameTreeAsText(localFrame,
1024).utf8(); |
7197 EXPECT_EQ("hello", content); | 7198 EXPECT_EQ("hello", content); |
7198 | 7199 |
7199 // Manually reset to break WebViewHelper's dependency on the stack allocated | 7200 // Manually reset to break WebViewHelper's dependency on the stack allocated |
7200 // TestWebFrameClient. | 7201 // TestWebFrameClient. |
7201 reset(); | 7202 reset(); |
7202 remoteFrame->close(); | 7203 remoteFrame->close(); |
7203 childRemoteFrame->close(); | 7204 childRemoteFrame->close(); |
7204 } | 7205 } |
7205 | 7206 |
7206 TEST_F(WebFrameSwapTest, SwapPreservesGlobalContext) | 7207 TEST_F(WebFrameSwapTest, SwapPreservesGlobalContext) |
(...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8406 } | 8407 } |
8407 | 8408 |
8408 TEST_F(WebFrameVisibilityChangeTest, RemoteFrameParentVisibilityChange) | 8409 TEST_F(WebFrameVisibilityChangeTest, RemoteFrameParentVisibilityChange) |
8409 { | 8410 { |
8410 swapLocalFrameToRemoteFrame(); | 8411 swapLocalFrameToRemoteFrame(); |
8411 executeScriptOnMainFrame(WebScriptSource("document.querySelector('iframe').p
arentElement.style.display = 'none';")); | 8412 executeScriptOnMainFrame(WebScriptSource("document.querySelector('iframe').p
arentElement.style.display = 'none';")); |
8412 EXPECT_FALSE(remoteFrameClient()->isVisible()); | 8413 EXPECT_FALSE(remoteFrameClient()->isVisible()); |
8413 } | 8414 } |
8414 | 8415 |
8415 } // namespace blink | 8416 } // namespace blink |
OLD | NEW |