Title: [118958] trunk/Source/WebKit/chromium
Revision
118958
Author
[email protected]
Date
2012-05-30 12:53:19 -0700 (Wed, 30 May 2012)

Log Message

[chromium] port webframe_unittest.cc to webkit_unit_tests
https://bugs.webkit.org/show_bug.cgi?id=87796

Reviewed by James Robinson.

Move WebFrameTest.GetContentAsPlainText and WebFrameTest.GetFullHtmlOfPage to webkit_unit_tests.

* tests/WebFrameTest.cpp:
(WebKit::TEST_F):
(WebKit): Add tests.

Modified Paths

Diff

Modified: trunk/Source/WebKit/chromium/ChangeLog (118957 => 118958)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-05-30 19:51:38 UTC (rev 118957)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-05-30 19:53:19 UTC (rev 118958)
@@ -1,3 +1,16 @@
+2012-05-30  Tony Chang  <[email protected]>
+
+        [chromium] port webframe_unittest.cc to webkit_unit_tests
+        https://bugs.webkit.org/show_bug.cgi?id=87796
+
+        Reviewed by James Robinson.
+
+        Move WebFrameTest.GetContentAsPlainText and WebFrameTest.GetFullHtmlOfPage to webkit_unit_tests.
+
+        * tests/WebFrameTest.cpp:
+        (WebKit::TEST_F):
+        (WebKit): Add tests.
+
 2012-05-30  Jochen Eisinger  <[email protected]>
 
         Match Firefox restrictions to window.blur and window.focus

Modified: trunk/Source/WebKit/chromium/tests/WebFrameTest.cpp (118957 => 118958)


--- trunk/Source/WebKit/chromium/tests/WebFrameTest.cpp	2012-05-30 19:51:38 UTC (rev 118957)
+++ trunk/Source/WebKit/chromium/tests/WebFrameTest.cpp	2012-05-30 19:53:19 UTC (rev 118958)
@@ -643,4 +643,85 @@
     webView->close();
 }
 
+TEST_F(WebFrameTest, GetContentAsPlainText)
+{
+    WebView* webView = FrameTestHelpers::createWebViewAndLoad("about:blank", true);
+    // We set the size because it impacts line wrapping, which changes the
+    // resulting text value.
+    webView->resize(WebSize(640, 480));
+    WebFrame* frame = webView->mainFrame();
+
+    // Generate a simple test case.
+    const char simpleSource[] = "<div>Foo bar</div><div></div>baz";
+    GURL testURL("about:blank");
+    frame->loadHTMLString(simpleSource, testURL);
+    webkit_support::RunAllPendingMessages();
+
+    // Make sure it comes out OK.
+    const std::string expected("Foo bar\nbaz");
+    WebString text = frame->contentAsText(std::numeric_limits<size_t>::max());
+    EXPECT_EQ(expected, std::string(text.utf8()));
+
+    // Try reading the same one with clipping of the text.
+    const int length = 5;
+    text = frame->contentAsText(length);
+    EXPECT_EQ(expected.substr(0, length), std::string(text.utf8()));
+
+    // Now do a new test with a subframe.
+    const char outerFrameSource[] = "Hello<iframe></iframe> world";
+    frame->loadHTMLString(outerFrameSource, testURL);
+    webkit_support::RunAllPendingMessages();
+
+    // Load something into the subframe.
+    WebFrame* subframe = frame->findChildByExpression(WebString::fromUTF8("/html/body/iframe"));
+    ASSERT_TRUE(subframe);
+    subframe->loadHTMLString("sub<p>text", testURL);
+    webkit_support::RunAllPendingMessages();
+
+    text = frame->contentAsText(std::numeric_limits<size_t>::max());
+    EXPECT_EQ("Hello world\n\nsub\ntext", std::string(text.utf8()));
+
+    // Get the frame text where the subframe separator falls on the boundary of
+    // what we'll take. There used to be a crash in this case.
+    text = frame->contentAsText(12);
+    EXPECT_EQ("Hello world", std::string(text.utf8()));
+
+    webView->close();
+}
+
+TEST_F(WebFrameTest, GetFullHtmlOfPage)
+{
+    WebView* webView = FrameTestHelpers::createWebViewAndLoad("about:blank", true);
+    WebFrame* frame = webView->mainFrame();
+
+    // Generate a simple test case.
+    const char simpleSource[] = "<p>Hello</p><p>World</p>";
+    GURL testURL("about:blank");
+    frame->loadHTMLString(simpleSource, testURL);
+    webkit_support::RunAllPendingMessages();
+
+    WebString text = frame->contentAsText(std::numeric_limits<size_t>::max());
+    EXPECT_EQ("Hello\n\nWorld", std::string(text.utf8()));
+
+    const std::string html = frame->contentAsMarkup().utf8();
+
+    // Load again with the output html.
+    frame->loadHTMLString(html, testURL);
+    webkit_support::RunAllPendingMessages();
+
+    EXPECT_EQ(html, std::string(frame->contentAsMarkup().utf8()));
+
+    text = frame->contentAsText(std::numeric_limits<size_t>::max());
+    EXPECT_EQ("Hello\n\nWorld", std::string(text.utf8()));
+
+    // Test selection check
+    EXPECT_FALSE(frame->hasSelection());
+    frame->executeCommand(WebString::fromUTF8("SelectAll"));
+    EXPECT_TRUE(frame->hasSelection());
+    frame->executeCommand(WebString::fromUTF8("Unselect"));
+    EXPECT_FALSE(frame->hasSelection());
+    WebString selectionHtml = frame->selectionAsMarkup();
+    EXPECT_TRUE(selectionHtml.isEmpty());
+}
+
 } // namespace
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to