summaryrefslogtreecommitdiffstats
path: root/webkit/glue/dom_serializer_unittest.cc
diff options
context:
space:
mode:
authoryaar@chromium.org <yaar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-23 11:55:07 +0000
committeryaar@chromium.org <yaar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-23 11:55:07 +0000
commitd9ec5c0f2549db5a717834da1c30a9bf98dd86b7 (patch)
tree38d0def5964caf2d98cbfa168d045d8d0c02ec1d /webkit/glue/dom_serializer_unittest.cc
parentb1e69a58480cb3644dcb1fbdae3e8b8fcf487491 (diff)
downloadchromium_src-d9ec5c0f2549db5a717834da1c30a9bf98dd86b7.zip
chromium_src-d9ec5c0f2549db5a717834da1c30a9bf98dd86b7.tar.gz
chromium_src-d9ec5c0f2549db5a717834da1c30a9bf98dd86b7.tar.bz2
Chromium to use upstream WebPageSerializer instead of glue/DomSerializer.
See corresponding changes in webkit here: https://bugs.webkit.org/show_bug.cgi?id=31737 Review URL: http://codereview.chromium.org/434087 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35216 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/dom_serializer_unittest.cc')
-rw-r--r--webkit/glue/dom_serializer_unittest.cc557
1 files changed, 288 insertions, 269 deletions
diff --git a/webkit/glue/dom_serializer_unittest.cc b/webkit/glue/dom_serializer_unittest.cc
index f6c4bb75..da31347 100644
--- a/webkit/glue/dom_serializer_unittest.cc
+++ b/webkit/glue/dom_serializer_unittest.cc
@@ -2,60 +2,94 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "config.h"
-
#include "base/compiler_specific.h"
-
-MSVC_PUSH_WARNING_LEVEL(0);
-#include "Document.h"
-#include "DocumentType.h"
-#include "Element.h"
-#include "FrameLoader.h"
-#include "FrameView.h"
-#include "HTMLAllCollection.h"
-#include "HTMLHeadElement.h"
-#include "HTMLMetaElement.h"
-#include "HTMLNames.h"
-#include "KURL.h"
-#include "markup.h"
-#include "SharedBuffer.h"
-#include "SubstituteData.h"
-MSVC_POP_WARNING();
-#undef LOG
-
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/hash_tables.h"
#include "base/string_util.h"
#include "net/base/net_util.h"
#include "net/url_request/url_request_context.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
#include "third_party/WebKit/WebKit/chromium/public/WebData.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebElement.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebNodeCollection.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebPageSerializerClient.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
#include "webkit/glue/dom_operations.h"
-#include "webkit/glue/dom_operations_private.h"
-#include "webkit/glue/dom_serializer.h"
-#include "webkit/glue/dom_serializer_delegate.h"
-#include "webkit/glue/glue_util.h"
-#include "third_party/WebKit/WebKit/chromium/src/WebFrameImpl.h"
+#include "webkit/glue/webkit_glue.h"
#include "webkit/tools/test_shell/simple_resource_loader_bridge.h"
#include "webkit/tools/test_shell/test_shell_test.h"
-using WebKit::WebFrameImpl;
+using WebKit::WebCString;
+using WebKit::WebData;
+using WebKit::WebDocument;
+using WebKit::WebElement;
+using WebKit::WebFrame;
+using WebKit::WebNode;
+using WebKit::WebNodeCollection;
+using WebKit::WebNodeList;
+using WebKit::WebPageSerializer;
+using WebKit::WebPageSerializerClient;
+using WebKit::WebNode;
+using WebKit::WebString;
+using WebKit::WebURL;
+using WebKit::WebView;
+using WebKit::WebVector;
namespace {
+// Iterate recursively over sub-frames to find one with with a given url.
+WebFrame* FindSubFrameByURL(WebView* web_view, const GURL& url) {
+ if (!web_view->mainFrame())
+ return NULL;
+
+ std::vector<WebFrame*> stack;
+ stack.push_back(web_view->mainFrame());
+
+ while (!stack.empty()) {
+ WebFrame* current_frame = stack.back();
+ stack.pop_back();
+ if (GURL(current_frame->url()) == url)
+ return current_frame;
+ WebNodeCollection all = current_frame->document().all();
+ for (WebNode node = all.firstItem();
+ !node.isNull(); node = all.nextItem()) {
+ if (!node.isElementNode())
+ continue;
+ // Check frame tag and iframe tag
+ WebElement element = node.toElement<WebElement>();
+ if (!element.hasTagName("frame") && !element.hasTagName("iframe"))
+ continue;
+ WebFrame* sub_frame = WebFrame::fromFrameOwnerElement(element);
+ if (sub_frame)
+ stack.push_back(sub_frame);
+ }
+ }
+ return NULL;
+}
+
class DomSerializerTests : public TestShellTest,
- public webkit_glue::DomSerializerDelegate {
+ public WebPageSerializerClient {
public:
DomSerializerTests()
: local_directory_name_(FILE_PATH_LITERAL("./dummy_files/")) { }
// DomSerializerDelegate.
- void DidSerializeDataForFrame(const GURL& frame_url,
- const std::string& data, PageSavingSerializationStatus status) {
+ void didSerializeDataForFrame(const WebURL& frame_web_url,
+ const WebCString& data,
+ PageSerializationStatus status) {
+
+ GURL frame_url(frame_web_url);
// If the all frames are finished saving, check all finish status
- if (status == ALL_FRAMES_ARE_FINISHED) {
+ if (status == WebPageSerializerClient::AllFramesAreFinished) {
SerializationFinishStatusMap::iterator it =
serialization_finish_status_.begin();
for (; it != serialization_finish_status_.end(); ++it)
@@ -77,10 +111,10 @@ class DomSerializerTests : public TestShellTest,
ASSERT_FALSE(it->second);
// Add data to corresponding frame's content.
- serialized_frame_map_[frame_url.spec()] += data;
+ serialized_frame_map_[frame_url.spec()] += data.data();
// Current frame is completed saving, change the finish status.
- if (status == CURRENT_FRAME_IS_FINISHED)
+ if (status == WebPageSerializerClient::CurrentFrameIsFinished)
it->second = true;
}
@@ -106,27 +140,23 @@ class DomSerializerTests : public TestShellTest,
// the document.
void LoadContents(const std::string& contents,
const GURL& base_url,
- const WebCore::String encoding_info) {
+ const WebString encoding_info) {
test_shell_->ResetTestController();
// If input encoding is empty, use UTF-8 as default encoding.
if (encoding_info.isEmpty()) {
test_shell_->webView()->mainFrame()->loadHTMLString(contents, base_url);
} else {
+ WebData data(contents.data(), contents.length());
+
// Do not use WebFrame.LoadHTMLString because it assumes that input
// html contents use UTF-8 encoding.
// TODO(darin): This should use WebFrame::loadData.
- WebFrameImpl* web_frame =
- static_cast<WebFrameImpl*>(test_shell_->webView()->mainFrame());
+ WebFrame* web_frame =
+ test_shell_->webView()->mainFrame();
+
ASSERT_TRUE(web_frame != NULL);
- int len = static_cast<int>(contents.size());
- RefPtr<WebCore::SharedBuffer> buf(
- WebCore::SharedBuffer::create(contents.data(), len));
-
- WebCore::SubstituteData subst_data(
- buf, WebCore::String("text/html"), encoding_info, WebCore::KURL());
- WebCore::ResourceRequest request(webkit_glue::GURLToKURL(base_url),
- WebCore::CString());
- web_frame->frame()->loader()->load(request, subst_data, false);
+
+ web_frame->loadData(data, "text/html", encoding_info, base_url);
}
test_shell_->WaitTestFinished();
@@ -137,20 +167,24 @@ class DomSerializerTests : public TestShellTest,
// sub-frames.
void SerializeDomForURL(const GURL& page_url,
bool recursive_serialization) {
- // Find corresponding WebFrameImpl according to page_url.
- WebFrameImpl* web_frame =
- webkit_glue::GetWebFrameImplFromWebViewForSpecificURL(
- test_shell_->webView(), page_url);
+ // Find corresponding WebFrame according to page_url.
+ WebFrame* web_frame = FindSubFrameByURL(test_shell_->webView(),
+ page_url);
ASSERT_TRUE(web_frame != NULL);
// Add input file URl to links_.
- links_.push_back(page_url);
+ links_.assign(&page_url,1);
// Add dummy file path to local_path_.
- local_paths_.push_back(FilePath(FILE_PATH_LITERAL("c:\\dummy.htm")));
+ WebString file_path = webkit_glue::FilePathStringToWebString(
+ FILE_PATH_LITERAL("c:\\dummy.htm"));
+ local_paths_.assign(&file_path, 1);
// Start serializing DOM.
- webkit_glue::DomSerializer dom_serializer(web_frame,
- recursive_serialization, this, links_, local_paths_,
- local_directory_name_);
- ASSERT_TRUE(dom_serializer.SerializeDom());
+ bool result = WebPageSerializer::serialize(web_frame,
+ recursive_serialization,
+ static_cast<WebPageSerializerClient*>(this),
+ links_,
+ local_paths_,
+ webkit_glue::FilePathToWebString(local_directory_name_));
+ ASSERT_TRUE(result);
ASSERT_TRUE(serialized_);
}
@@ -164,10 +198,10 @@ class DomSerializerTests : public TestShellTest,
// Flag indicates whether the process of serializing DOM is finished or not.
bool serialized_;
// The links_ contain dummy original URLs of all saved links.
- std::vector<GURL> links_;
+ WebVector<WebURL> links_;
// The local_paths_ contain dummy corresponding local file paths of all saved
// links, which matched links_ one by one.
- std::vector<FilePath> local_paths_;
+ WebVector<WebString> local_paths_;
// The local_directory_name_ is dummy relative path of directory which
// contain all saved auxiliary files included all sub frames and resources.
const FilePath local_directory_name_;
@@ -184,55 +218,61 @@ class DomSerializerTests : public TestShellTest,
}
};
+// Helper function that test whether the first node in the doc is a doc type
+// node.
+bool HasDocType(const WebDocument& doc) {
+ WebNode node = doc.firstChild();
+ if (node.isNull())
+ return false;
+ return node.nodeType() == WebNode::DocumentTypeNode;
+}
+
// Helper function for checking whether input node is META tag. Return true
// means it is META element, otherwise return false. The parameter charset_info
// return actual charset info if the META tag has charset declaration.
-bool IsMetaElement(const WebCore::Node* node, WebCore::String* charset_info) {
- if (!node->isHTMLElement())
+bool IsMetaElement(const WebNode& node, std::string& charset_info) {
+ if (!node.isElementNode())
return false;
- if (!(static_cast<const WebCore::HTMLElement*>(node))->hasTagName(
- WebCore::HTMLNames::metaTag))
+ const WebElement meta = node.toConstElement<WebElement>();
+ if (!meta.hasTagName("meta"))
return false;
- charset_info->remove(0, charset_info->length());
- const WebCore::HTMLMetaElement* meta =
- static_cast<const WebCore::HTMLMetaElement*>(node);
+ charset_info.erase(0, charset_info.length());
// Check the META charset declaration.
- WebCore::String equiv = meta->httpEquiv();
- if (equalIgnoringCase(equiv, "content-type")) {
- WebCore::String content = meta->content();
- int pos = content.find("charset", 0, false);
+ WebString httpEquiv = meta.getAttribute("http-equiv");
+ if (LowerCaseEqualsASCII(httpEquiv, "content-type")) {
+ std::string content = meta.getAttribute("content").utf8();
+ int pos = content.find("charset", 0);
if (pos > -1) {
// Add a dummy charset declaration to charset_info, which indicates this
// META tag has charset declaration although we do not get correct value
// yet.
- charset_info->append("has-charset-declaration");
+ charset_info.append("has-charset-declaration");
int remaining_length = content.length() - pos - 7;
if (!remaining_length)
return true;
- const UChar* start_pos = content.characters() + pos + 7;
+ int start_pos = pos + 7;
// Find "=" symbol.
while (remaining_length--)
- if (*start_pos++ == L'=')
+ if (content[start_pos++] == L'=')
break;
// Skip beginning space.
while (remaining_length) {
- if (*start_pos > 0x0020)
+ if (content[start_pos] > 0x0020)
break;
++start_pos;
--remaining_length;
}
if (!remaining_length)
return true;
- const UChar* end_pos = start_pos;
+ int end_pos = start_pos;
// Now we find out the start point of charset info. Search the end point.
while (remaining_length--) {
- if (*end_pos <= 0x0020 || *end_pos == L';')
+ if (content[end_pos] <= 0x0020 || content[end_pos] == L';')
break;
++end_pos;
}
// Get actual charset info.
- *charset_info = WebCore::String(start_pos,
- static_cast<unsigned>(end_pos - start_pos));
+ charset_info = content.substr(start_pos, end_pos - start_pos);
return true;
}
}
@@ -250,12 +290,10 @@ TEST_F(DomSerializerTests, SerialzeHTMLDOMWithDocType) {
// Load the test file.
LoadPageFromURL(file_url);
// Make sure original contents have document type.
- WebFrameImpl* web_frame =
- webkit_glue::GetWebFrameImplFromWebViewForSpecificURL(
- test_shell_->webView(), file_url);
+ WebFrame* web_frame = FindSubFrameByURL(test_shell_->webView(), file_url);
ASSERT_TRUE(web_frame != NULL);
- WebCore::Document* doc = web_frame->frame()->document();
- ASSERT_TRUE(doc->doctype() != NULL);
+ WebDocument doc = web_frame->document();
+ ASSERT_TRUE(HasDocType(doc));
// Do serialization.
SerializeDomForURL(file_url, false);
// Load the serialized contents.
@@ -263,12 +301,11 @@ TEST_F(DomSerializerTests, SerialzeHTMLDOMWithDocType) {
const std::string& serialized_contents =
GetSerializedContentForFrame(file_url);
LoadContents(serialized_contents, file_url,
- web_frame->frame()->loader()->encoding());
+ web_frame->encoding());
// Make sure serialized contents still have document type.
- web_frame =
- static_cast<WebFrameImpl*>(test_shell_->webView()->mainFrame());
- doc = web_frame->frame()->document();
- ASSERT_TRUE(doc->doctype() != NULL);
+ web_frame = test_shell_->webView()->mainFrame();
+ doc = web_frame->document();
+ ASSERT_TRUE(HasDocType(doc));
}
// If original contents do not have document type, the serialized contents
@@ -282,12 +319,10 @@ TEST_F(DomSerializerTests, SerialzeHTMLDOMWithoutDocType) {
// Load the test file.
LoadPageFromURL(file_url);
// Make sure original contents do not have document type.
- WebFrameImpl* web_frame =
- webkit_glue::GetWebFrameImplFromWebViewForSpecificURL(
- test_shell_->webView(), file_url);
+ WebFrame* web_frame = FindSubFrameByURL(test_shell_->webView(), file_url);
ASSERT_TRUE(web_frame != NULL);
- WebCore::Document* doc = web_frame->frame()->document();
- ASSERT_TRUE(doc->doctype() == NULL);
+ WebDocument doc = web_frame->document();
+ ASSERT_TRUE(!HasDocType(doc));
// Do serialization.
SerializeDomForURL(file_url, false);
// Load the serialized contents.
@@ -295,12 +330,11 @@ TEST_F(DomSerializerTests, SerialzeHTMLDOMWithoutDocType) {
const std::string& serialized_contents =
GetSerializedContentForFrame(file_url);
LoadContents(serialized_contents, file_url,
- web_frame->frame()->loader()->encoding());
+ web_frame->encoding());
// Make sure serialized contents do not have document type.
- web_frame =
- static_cast<WebFrameImpl*>(test_shell_->webView()->mainFrame());
- doc = web_frame->frame()->document();
- ASSERT_TRUE(doc->doctype() == NULL);
+ web_frame = test_shell_->webView()->mainFrame();
+ doc = web_frame->document();
+ ASSERT_TRUE(!HasDocType(doc));
}
// Serialize XML document which has all 5 built-in entities. After
@@ -340,7 +374,7 @@ TEST_F(DomSerializerTests, SerialzeHTMLDOMWithAddingMOTW) {
ASSERT_TRUE(file_url.SchemeIsFile());
// Make sure original contents does not have MOTW;
std::string motw_declaration =
- webkit_glue::DomSerializer::GenerateMarkOfTheWebDeclaration(file_url);
+ WebPageSerializer::generateMarkOfTheWebDeclaration(file_url).utf8();
ASSERT_FALSE(motw_declaration.empty());
// The encoding of original contents is ISO-8859-1, so we convert the MOTW
// declaration to ASCII and search whether original contents has it or not.
@@ -373,21 +407,19 @@ TEST_F(DomSerializerTests, SerialzeHTMLDOMWithNoMetaCharsetInOriginalDoc) {
LoadPageFromURL(file_url);
// Make sure there is no META charset declaration in original document.
- WebFrameImpl* web_frame =
- webkit_glue::GetWebFrameImplFromWebViewForSpecificURL(
- test_shell_->webView(), file_url);
+ WebFrame* web_frame = FindSubFrameByURL(test_shell_->webView(), file_url);
ASSERT_TRUE(web_frame != NULL);
- WebCore::Document* doc = web_frame->frame()->document();
- ASSERT_TRUE(doc->isHTMLDocument());
- WebCore::HTMLHeadElement* head_ele = doc->head();
- ASSERT_TRUE(head_ele != NULL);
+ WebDocument doc = web_frame->document();
+ ASSERT_TRUE(doc.isHTMLDocument());
+ WebElement head_element = doc.head();
+ ASSERT_TRUE(!head_element.isNull());
// Go through all children of HEAD element.
- WebCore::String charset_info;
- for (const WebCore::Node *child = head_ele->firstChild(); child != NULL;
- child = child->nextSibling())
- if (IsMetaElement(child, &charset_info))
- ASSERT_TRUE(charset_info.isEmpty());
-
+ for (WebNode child = head_element.firstChild(); !child.isNull();
+ child = child.nextSibling()) {
+ std::string charset_info;
+ if (IsMetaElement(child, charset_info))
+ ASSERT_TRUE(charset_info.empty());
+ }
// Do serialization.
SerializeDomForURL(file_url, false);
@@ -396,28 +428,30 @@ TEST_F(DomSerializerTests, SerialzeHTMLDOMWithNoMetaCharsetInOriginalDoc) {
const std::string& serialized_contents =
GetSerializedContentForFrame(file_url);
LoadContents(serialized_contents, file_url,
- web_frame->frame()->loader()->encoding());
+ web_frame->encoding());
// Make sure the first child of HEAD element is META which has charset
// declaration in serialized contents.
- web_frame =
- static_cast<WebFrameImpl*>(test_shell_->webView()->mainFrame());
+ web_frame = test_shell_->webView()->mainFrame();
ASSERT_TRUE(web_frame != NULL);
- doc = web_frame->frame()->document();
- ASSERT_TRUE(doc->isHTMLDocument());
- head_ele = doc->head();
- ASSERT_TRUE(head_ele != NULL);
- WebCore::Node* meta_node = head_ele->firstChild();
- ASSERT_TRUE(meta_node != NULL);
+ doc = web_frame->document();
+ ASSERT_TRUE(doc.isHTMLDocument());
+ head_element = doc.head();
+ ASSERT_TRUE(!head_element.isNull());
+ WebNode meta_node = head_element.firstChild();
+ ASSERT_TRUE(!meta_node.isNull());
// Get meta charset info.
- ASSERT_TRUE(IsMetaElement(meta_node, &charset_info));
- ASSERT_TRUE(!charset_info.isEmpty());
- ASSERT_TRUE(charset_info == web_frame->frame()->loader()->encoding());
+ std::string charset_info2;
+ ASSERT_TRUE(IsMetaElement(meta_node, charset_info2));
+ ASSERT_TRUE(!charset_info2.empty());
+ ASSERT_TRUE(charset_info2 == std::string(web_frame->encoding().utf8()));
// Make sure no more additional META tags which have charset declaration.
- for (const WebCore::Node *child = meta_node->nextSibling(); child != NULL;
- child = child->nextSibling())
- if (IsMetaElement(child, &charset_info))
- ASSERT_TRUE(charset_info.isEmpty());
+ for (WebNode child = meta_node.nextSibling(); !child.isNull();
+ child = child.nextSibling()) {
+ std::string charset_info;
+ if (IsMetaElement(child, charset_info))
+ ASSERT_TRUE(charset_info.empty());
+ }
}
// When serializing DOM, if the original document has multiple META charset
@@ -437,24 +471,22 @@ TEST_F(DomSerializerTests,
// Make sure there are multiple META charset declarations in original
// document.
- WebFrameImpl* web_frame =
- webkit_glue::GetWebFrameImplFromWebViewForSpecificURL(
- test_shell_->webView(), file_url);
+ WebFrame* web_frame = FindSubFrameByURL(test_shell_->webView(), file_url);
ASSERT_TRUE(web_frame != NULL);
- WebCore::Document* doc = web_frame->frame()->document();
- ASSERT_TRUE(doc->isHTMLDocument());
- WebCore::HTMLHeadElement* head_ele = doc->head();
- ASSERT_TRUE(head_ele != NULL);
+ WebDocument doc = web_frame->document();
+ ASSERT_TRUE(doc.isHTMLDocument());
+ WebElement head_ele = doc.head();
+ ASSERT_TRUE(!head_ele.isNull());
// Go through all children of HEAD element.
int charset_declaration_count = 0;
- WebCore::String charset_info;
- for (const WebCore::Node *child = head_ele->firstChild(); child != NULL;
- child = child->nextSibling()) {
- if (IsMetaElement(child, &charset_info) && !charset_info.isEmpty())
+ for (WebNode child = head_ele.firstChild(); !child.isNull();
+ child = child.nextSibling()) {
+ std::string charset_info;
+ if (IsMetaElement(child, charset_info) && !charset_info.empty())
charset_declaration_count++;
}
// The original doc has more than META tags which have charset declaration.
- ASSERT(charset_declaration_count > 1);
+ ASSERT_TRUE(charset_declaration_count > 1);
// Do serialization.
SerializeDomForURL(file_url, false);
@@ -464,28 +496,30 @@ TEST_F(DomSerializerTests,
const std::string& serialized_contents =
GetSerializedContentForFrame(file_url);
LoadContents(serialized_contents, file_url,
- web_frame->frame()->loader()->encoding());
+ web_frame->encoding());
// Make sure only first child of HEAD element is META which has charset
// declaration in serialized contents.
- web_frame =
- static_cast<WebFrameImpl*>(test_shell_->webView()->mainFrame());
+ web_frame = test_shell_->webView()->mainFrame();
ASSERT_TRUE(web_frame != NULL);
- doc = web_frame->frame()->document();
- ASSERT_TRUE(doc->isHTMLDocument());
- head_ele = doc->head();
- ASSERT_TRUE(head_ele != NULL);
- WebCore::Node* meta_node = head_ele->firstChild();
- ASSERT_TRUE(meta_node != NULL);
+ doc = web_frame->document();
+ ASSERT_TRUE(doc.isHTMLDocument());
+ head_ele = doc.head();
+ ASSERT_TRUE(!head_ele.isNull());
+ WebNode meta_node = head_ele.firstChild();
+ ASSERT_TRUE(!meta_node.isNull());
// Get meta charset info.
- ASSERT_TRUE(IsMetaElement(meta_node, &charset_info));
- ASSERT_TRUE(!charset_info.isEmpty());
- ASSERT_TRUE(charset_info == web_frame->frame()->loader()->encoding());
+ std::string charset_info2;
+ ASSERT_TRUE(IsMetaElement(meta_node, charset_info2));
+ ASSERT_TRUE(!charset_info2.empty());
+ ASSERT_TRUE(charset_info2 == std::string(web_frame->encoding().utf8()));
// Make sure no more additional META tags which have charset declaration.
- for (const WebCore::Node *child = meta_node->nextSibling(); child != NULL;
- child = child->nextSibling())
- if (IsMetaElement(child, &charset_info))
- ASSERT_TRUE(charset_info.isEmpty());
+ for (WebNode child = meta_node.nextSibling(); !child.isNull();
+ child = child.nextSibling()) {
+ std::string charset_info;
+ if (IsMetaElement(child, charset_info))
+ ASSERT_TRUE(charset_info.empty());
+ }
}
// Test situation of html entities in text when serializing HTML DOM.
@@ -501,20 +535,19 @@ TEST_F(DomSerializerTests, SerialzeHTMLDOMWithEntitiesInText) {
static const char* const original_contents =
"<HTML><BODY>&amp;&lt;&gt;\"\'</BODY></HTML>";
// Load the test contents.
- LoadContents(original_contents, file_url, "");
+ LoadContents(original_contents, file_url, WebString());
// Get BODY's text content in DOM.
- WebFrameImpl* web_frame =
- webkit_glue::GetWebFrameImplFromWebViewForSpecificURL(
- test_shell_->webView(), file_url);
+ WebFrame* web_frame = FindSubFrameByURL(test_shell_->webView(), file_url);
ASSERT_TRUE(web_frame != NULL);
- WebCore::Document* doc = web_frame->frame()->document();
- ASSERT_TRUE(doc->isHTMLDocument());
- WebCore::HTMLElement* body_ele = doc->body();
- ASSERT_TRUE(body_ele != NULL);
- WebCore::Node* text_node = body_ele->firstChild();
- ASSERT_TRUE(text_node->isTextNode());
- ASSERT_TRUE(createMarkup(text_node) == "&amp;&lt;&gt;\"\'");
+ WebDocument doc = web_frame->document();
+ ASSERT_TRUE(doc.isHTMLDocument());
+ WebElement body_ele = doc.body();
+ ASSERT_TRUE(!body_ele.isNull());
+ WebNode text_node = body_ele.firstChild();
+ ASSERT_TRUE(text_node.isTextNode());
+ ASSERT_TRUE(std::string(text_node.createMarkup().utf8()) ==
+ "&amp;&lt;&gt;\"\'");
// Do serialization.
SerializeDomForURL(file_url, false);
// Compare the serialized contents with original contents.
@@ -526,22 +559,21 @@ TEST_F(DomSerializerTests, SerialzeHTMLDOMWithEntitiesInText) {
// Because we add MOTW when serializing DOM, so before comparison, we also
// need to add MOTW to original_contents.
std::string original_str =
- webkit_glue::DomSerializer::GenerateMarkOfTheWebDeclaration(file_url);
+ WebPageSerializer::generateMarkOfTheWebDeclaration(file_url).utf8();
original_str += original_contents;
// Since WebCore now inserts a new HEAD element if there is no HEAD element
// when creating BODY element. (Please see HTMLParser::bodyCreateErrorCheck.)
// We need to append the HEAD content and corresponding META content if we
// find WebCore-generated HEAD element.
- if (doc->head()) {
- WebCore::String encoding = web_frame->frame()->loader()->encoding();
+ if (!doc.head().isNull()) {
+ WebString encoding = web_frame->encoding();
std::string htmlTag("<HTML>");
std::string::size_type pos = original_str.find(htmlTag);
ASSERT_NE(std::string::npos, pos);
pos += htmlTag.length();
std::string head_part("<HEAD>");
- head_part += WideToASCII(
- webkit_glue::DomSerializer::GenerateMetaCharsetDeclaration(
- webkit_glue::StringToStdWString(encoding)));
+ head_part +=
+ WebPageSerializer::generateMetaCharsetDeclaration(encoding).utf8();
head_part += "</HEAD>";
original_str.insert(pos, head_part);
}
@@ -562,19 +594,16 @@ TEST_F(DomSerializerTests, SerialzeHTMLDOMWithEntitiesInAttributeValue) {
static const char* const original_contents =
"<HTML><BODY title=\"&amp;&lt;&gt;&quot;&#39;\"></BODY></HTML>";
// Load the test contents.
- LoadContents(original_contents, file_url, "");
+ LoadContents(original_contents, file_url, WebString());
// Get value of BODY's title attribute in DOM.
- WebFrameImpl* web_frame =
- webkit_glue::GetWebFrameImplFromWebViewForSpecificURL(
- test_shell_->webView(), file_url);
+ WebFrame* web_frame = FindSubFrameByURL(test_shell_->webView(), file_url);
ASSERT_TRUE(web_frame != NULL);
- WebCore::Document* doc = web_frame->frame()->document();
- ASSERT_TRUE(doc->isHTMLDocument());
- WebCore::HTMLElement* body_ele = doc->body();
- ASSERT_TRUE(body_ele != NULL);
- const WebCore::String& value = body_ele->getAttribute(
- WebCore::HTMLNames::titleAttr);
- ASSERT_TRUE(value == WebCore::String("&<>\"\'"));
+ WebDocument doc = web_frame->document();
+ ASSERT_TRUE(doc.isHTMLDocument());
+ WebElement body_ele = doc.body();
+ ASSERT_TRUE(!body_ele.isNull());
+ WebString value = body_ele.getAttribute("title");
+ ASSERT_TRUE(std::string(value.utf8()) == "&<>\"\'");
// Do serialization.
SerializeDomForURL(file_url, false);
// Compare the serialized contents with original contents.
@@ -584,18 +613,17 @@ TEST_F(DomSerializerTests, SerialzeHTMLDOMWithEntitiesInAttributeValue) {
// Compare the serialized contents with original contents to make sure
// they are same.
std::string original_str =
- webkit_glue::DomSerializer::GenerateMarkOfTheWebDeclaration(file_url);
+ WebPageSerializer::generateMarkOfTheWebDeclaration(file_url).utf8();
original_str += original_contents;
- if (doc->head()) {
- WebCore::String encoding = web_frame->frame()->loader()->encoding();
+ if (!doc.isNull()) {
+ WebString encoding = web_frame->encoding();
std::string htmlTag("<HTML>");
std::string::size_type pos = original_str.find(htmlTag);
ASSERT_NE(std::string::npos, pos);
pos += htmlTag.length();
std::string head_part("<HEAD>");
- head_part += WideToASCII(
- webkit_glue::DomSerializer::GenerateMetaCharsetDeclaration(
- webkit_glue::StringToStdWString(encoding)));
+ head_part +=
+ WebPageSerializer::generateMetaCharsetDeclaration(encoding).utf8();
head_part += "</HEAD>";
original_str.insert(pos, head_part);
}
@@ -612,23 +640,20 @@ TEST_F(DomSerializerTests, SerialzeHTMLDOMWithNonStandardEntities) {
LoadPageFromURL(file_url);
// Get value of BODY's title attribute in DOM.
- WebFrameImpl* web_frame =
- webkit_glue::GetWebFrameImplFromWebViewForSpecificURL(
- test_shell_->webView(), file_url);
- WebCore::Document* doc = web_frame->frame()->document();
- ASSERT_TRUE(doc->isHTMLDocument());
- WebCore::HTMLElement* body_ele = doc->body();
+ WebFrame* web_frame = FindSubFrameByURL(test_shell_->webView(), file_url);
+ WebDocument doc = web_frame->document();
+ ASSERT_TRUE(doc.isHTMLDocument());
+ WebElement body_element = doc.body();
// Unescaped string for "&percnt;&nsup;&supl;&apos;".
- static const UChar parsed_value[] = {
+ static const wchar_t parsed_value[] = {
'%', 0x2285, 0x00b9, '\'', 0
};
- const WebCore::String& value = body_ele->getAttribute(
- WebCore::HTMLNames::titleAttr);
- ASSERT_TRUE(value == WebCore::String(parsed_value));
+ WebString value = body_element.getAttribute("title");
+ ASSERT_TRUE(UTF16ToWide(value) == parsed_value);
// Check the BODY content.
- WebCore::Node* text_node = body_ele->firstChild();
- ASSERT_TRUE(text_node->isTextNode());
- ASSERT_TRUE(text_node->nodeValue() == WebCore::String(parsed_value));
+ WebNode text_node = body_element.firstChild();
+ ASSERT_TRUE(text_node.isTextNode());
+ ASSERT_TRUE(UTF16ToWide(text_node.nodeValue()) == parsed_value);
// Do serialization.
SerializeDomForURL(file_url, false);
@@ -667,34 +692,32 @@ TEST_F(DomSerializerTests, SerialzeHTMLDOMWithBaseTag) {
// Since for this test, we assume there is no savable sub-resource links for
// this test file, also all links are relative URLs in this test file, so we
// need to check those relative URLs and make sure document has BASE tag.
- WebFrameImpl* web_frame =
- webkit_glue::GetWebFrameImplFromWebViewForSpecificURL(
- test_shell_->webView(), file_url);
+ WebFrame* web_frame = FindSubFrameByURL(test_shell_->webView(), file_url);
ASSERT_TRUE(web_frame != NULL);
- WebCore::Document* doc = web_frame->frame()->document();
- ASSERT_TRUE(doc->isHTMLDocument());
+ WebDocument doc = web_frame->document();
+ ASSERT_TRUE(doc.isHTMLDocument());
// Go through all descent nodes.
- RefPtr<WebCore::HTMLAllCollection> all = doc->all();
+ WebNodeCollection all = doc.all();
int original_base_tag_count = 0;
- for (WebCore::Node* node = all->firstItem(); node != NULL;
- node = all->nextItem()) {
- if (!node->isHTMLElement())
+ for (WebNode node = all.firstItem(); !node.isNull();
+ node = all.nextItem()) {
+ if (!node.isElementNode())
continue;
- WebCore::Element* element = static_cast<WebCore::Element*>(node);
- if (element->hasTagName(WebCore::HTMLNames::baseTag)) {
+ WebElement element = node.toElement<WebElement>();
+ if (element.hasTagName("base")) {
original_base_tag_count++;
} else {
// Get link.
- const WebCore::AtomicString* value =
+ WebString value =
webkit_glue::GetSubResourceLinkFromElement(element);
- if (!value && element->hasTagName(WebCore::HTMLNames::aTag)) {
- value = &element->getAttribute(WebCore::HTMLNames::hrefAttr);
- if (value->isEmpty())
- value = NULL;
+ if (value.isNull() && element.hasTagName("a")) {
+ value = element.getAttribute("href");
+ if (value.isEmpty())
+ value = WebString();
}
// Each link is relative link.
- if (value) {
- GURL link(WideToUTF8(webkit_glue::StringToStdWString(value->string())));
+ if (!value.isNull()) {
+ GURL link(value.utf8());
ASSERT_TRUE(link.scheme().empty());
}
}
@@ -702,8 +725,7 @@ TEST_F(DomSerializerTests, SerialzeHTMLDOMWithBaseTag) {
ASSERT_EQ(original_base_tag_count, kTotalBaseTagCountInTestFile);
// Make sure in original document, the base URL is not equal with the
// |path_dir_url|.
- GURL original_base_url(
- WideToUTF8(webkit_glue::StringToStdWString(doc->baseURL())));
+ GURL original_base_url(doc.baseURL());
ASSERT_NE(original_base_url, path_dir_url);
// Do serialization.
@@ -714,37 +736,37 @@ TEST_F(DomSerializerTests, SerialzeHTMLDOMWithBaseTag) {
const std::string& serialized_contents =
GetSerializedContentForFrame(file_url);
LoadContents(serialized_contents, file_url,
- web_frame->frame()->loader()->encoding());
+ web_frame->encoding());
// Make sure all links are absolute URLs and doc there are some number of
// BASE tags in serialized HTML data. Each of those BASE tags have same base
// URL which is as same as URL of current test file.
- web_frame = static_cast<WebFrameImpl*>(test_shell_->webView()->mainFrame());
+ web_frame = test_shell_->webView()->mainFrame();
ASSERT_TRUE(web_frame != NULL);
- doc = web_frame->frame()->document();
- ASSERT_TRUE(doc->isHTMLDocument());
+ doc = web_frame->document();
+ ASSERT_TRUE(doc.isHTMLDocument());
// Go through all descent nodes.
- all = doc->all();
+ all = doc.all();
int new_base_tag_count = 0;
- for (WebCore::Node* node = all->firstItem(); node != NULL;
- node = all->nextItem()) {
- if (!node->isHTMLElement())
+ for (WebNode node = all.firstItem(); !node.isNull();
+ node = all.nextItem()) {
+ if (!node.isElementNode())
continue;
- WebCore::Element* element = static_cast<WebCore::Element*>(node);
- if (element->hasTagName(WebCore::HTMLNames::baseTag)) {
+ WebElement element = node.toElement<WebElement>();
+ if (element.hasTagName("base")) {
new_base_tag_count++;
} else {
// Get link.
- const WebCore::AtomicString* value =
+ WebString value =
webkit_glue::GetSubResourceLinkFromElement(element);
- if (!value && element->hasTagName(WebCore::HTMLNames::aTag)) {
- value = &element->getAttribute(WebCore::HTMLNames::hrefAttr);
- if (value->isEmpty())
- value = NULL;
+ if (value.isNull() && element.hasTagName("a")) {
+ value = element.getAttribute("href");
+ if (value.isEmpty())
+ value = WebString();
}
// Each link is absolute link.
- if (value) {
- GURL link(WideToUTF8(webkit_glue::StringToStdWString(value->string())));
+ if (!value.isNull()) {
+ GURL link(std::string(value.utf8()));
ASSERT_FALSE(link.scheme().empty());
}
}
@@ -752,8 +774,7 @@ TEST_F(DomSerializerTests, SerialzeHTMLDOMWithBaseTag) {
// We have one more added BASE tag which is generated by JavaScript.
ASSERT_EQ(new_base_tag_count, original_base_tag_count + 1);
// Make sure in new document, the base URL is equal with the |path_dir_url|.
- GURL new_base_url(
- webkit_glue::StringToStdString(doc->baseURL()));
+ GURL new_base_url(doc.baseURL());
ASSERT_EQ(new_base_url, path_dir_url);
}
@@ -768,18 +789,17 @@ TEST_F(DomSerializerTests, SerialzeHTMLDOMWithEmptyHead) {
// Load the test html content.
static const char* const empty_head_contents =
"<HTML><HEAD></HEAD><BODY>hello world</BODY></HTML>";
- LoadContents(empty_head_contents, file_url, "");
+ LoadContents(empty_head_contents, file_url, WebString());
// Make sure the head tag is empty.
- WebFrameImpl* web_frame =
- static_cast<WebFrameImpl*>(test_shell_->webView()->mainFrame());
+ WebFrame* web_frame = test_shell_->webView()->mainFrame();
ASSERT_TRUE(web_frame != NULL);
- WebCore::Document* doc = web_frame->frame()->document();
- ASSERT_TRUE(doc->isHTMLDocument());
- WebCore::HTMLHeadElement* head_ele = doc->head();
- ASSERT_TRUE(head_ele != NULL);
- WTF::PassRefPtr<WebCore::HTMLCollection> children = head_ele->children();
- ASSERT_TRUE(0 == children->length());
+ WebDocument doc = web_frame->document();
+ ASSERT_TRUE(doc.isHTMLDocument());
+ WebElement head_element = doc.head();
+ ASSERT_TRUE(!head_element.isNull());
+ ASSERT_TRUE(!head_element.hasChildNodes());
+ ASSERT_TRUE(head_element.childNodes().length() == 0);
// Do serialization.
SerializeDomForURL(file_url, false);
@@ -789,32 +809,31 @@ TEST_F(DomSerializerTests, SerialzeHTMLDOMWithEmptyHead) {
GetSerializedContentForFrame(file_url);
// Reload serialized contents and make sure there is only one META tag.
- LoadContents(serialized_contents, file_url,
- web_frame->frame()->loader()->encoding());
- web_frame = static_cast<WebFrameImpl*>(test_shell_->webView()->mainFrame());
+ LoadContents(serialized_contents, file_url, web_frame->encoding());
+ web_frame = test_shell_->webView()->mainFrame();
ASSERT_TRUE(web_frame != NULL);
- doc = web_frame->frame()->document();
- ASSERT_TRUE(doc->isHTMLDocument());
- head_ele = doc->head();
- ASSERT_TRUE(head_ele != NULL);
- children = head_ele->children();
- ASSERT_TRUE(1 == children->length());
- WebCore::Node* meta_node = head_ele->firstChild();
- ASSERT_TRUE(meta_node != NULL);
+ doc = web_frame->document();
+ ASSERT_TRUE(doc.isHTMLDocument());
+ head_element = doc.head();
+ ASSERT_TRUE(!head_element.isNull());
+ ASSERT_TRUE(head_element.hasChildNodes());
+ ASSERT_TRUE(head_element.childNodes().length() == 1);
+ WebNode meta_node = head_element.firstChild();
+ ASSERT_TRUE(!meta_node.isNull());
// Get meta charset info.
- WebCore::String charset_info;
- ASSERT_TRUE(IsMetaElement(meta_node, &charset_info));
- ASSERT_TRUE(!charset_info.isEmpty());
- ASSERT_TRUE(charset_info == web_frame->frame()->loader()->encoding());
+ std::string charset_info;
+ ASSERT_TRUE(IsMetaElement(meta_node, charset_info));
+ ASSERT_TRUE(!charset_info.empty());
+ ASSERT_TRUE(charset_info == std::string(web_frame->encoding().utf8()));
// Check the body's first node is text node and its contents are
// "hello world"
- WebCore::HTMLElement* body_ele = doc->body();
- ASSERT_TRUE(body_ele != NULL);
- WebCore::Node* text_node = body_ele->firstChild();
- ASSERT_TRUE(text_node->isTextNode());
- const WebCore::String& text_node_contents = text_node->nodeValue();
- ASSERT_TRUE(text_node_contents == WebCore::String("hello world"));
+ WebElement body_element = doc.body();
+ ASSERT_TRUE(!body_element.isNull());
+ WebNode text_node = body_element.firstChild();
+ ASSERT_TRUE(text_node.isTextNode());
+ WebString text_node_contents = text_node.nodeValue();
+ ASSERT_TRUE(std::string(text_node_contents.utf8()) == "hello world");
}
} // namespace