This source file includes following definitions.
- FindSubFrameByURL
- HasDocType
- IsMetaElement
- quit_closure_
- DidFinishLoad
- local_directory_name_
- SetUpCommandLine
- didSerializeDataForFrame
- HasSerializedFrame
- GetSerializedContentForFrame
- GetRenderView
- GetWebView
- GetMainFrame
- LoadContents
- SerializeDomForURL
- SerializeHTMLDOMWithDocTypeOnRenderer
- SerializeHTMLDOMWithoutDocTypeOnRenderer
- SerializeXMLDocWithBuiltInEntitiesOnRenderer
- SerializeHTMLDOMWithAddingMOTWOnRenderer
- SerializeHTMLDOMWithNoMetaCharsetInOriginalDocOnRenderer
- SerializeHTMLDOMWithMultipleMetaCharsetInOriginalDocOnRenderer
- SerializeHTMLDOMWithEntitiesInTextOnRenderer
- SerializeHTMLDOMWithEntitiesInAttributeValueOnRenderer
- SerializeHTMLDOMWithNonStandardEntitiesOnRenderer
- SerializeHTMLDOMWithBaseTagOnRenderer
- SerializeHTMLDOMWithEmptyHeadOnRenderer
- SerializeDocumentWithDownloadedIFrameOnRenderer
- SubResourceForElementsInNonHTMLNamespaceOnRenderer
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "base/bind.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/containers/hash_tables.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "content/public/common/content_switches.h"
#include "content/public/renderer/render_view.h"
#include "content/public/renderer/render_view_observer.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "content/renderer/savable_resources.h"
#include "content/shell/browser/shell.h"
#include "net/base/net_util.h"
#include "net/url_request/url_request_context.h"
#include "third_party/WebKit/public/platform/WebCString.h"
#include "third_party/WebKit/public/platform/WebData.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/WebURL.h"
#include "third_party/WebKit/public/platform/WebVector.h"
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebElement.h"
#include "third_party/WebKit/public/web/WebElementCollection.h"
#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebNode.h"
#include "third_party/WebKit/public/web/WebNodeList.h"
#include "third_party/WebKit/public/web/WebPageSerializer.h"
#include "third_party/WebKit/public/web/WebPageSerializerClient.h"
#include "third_party/WebKit/public/web/WebView.h"
using blink::WebCString;
using blink::WebData;
using blink::WebDocument;
using blink::WebElement;
using blink::WebElementCollection;
using blink::WebFrame;
using blink::WebNode;
using blink::WebNodeList;
using blink::WebPageSerializer;
using blink::WebPageSerializerClient;
using blink::WebString;
using blink::WebURL;
using blink::WebView;
using blink::WebVector;
namespace {
const int kRenderViewRoutingId = 2;
}
namespace content {
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->document().url()) == url)
return current_frame;
WebElementCollection all = current_frame->document().all();
for (WebElement element = all.firstItem();
!element.isNull(); element = all.nextItem()) {
if (!element.hasTagName("frame") && !element.hasTagName("iframe"))
continue;
WebFrame* sub_frame = WebFrame::fromFrameOwnerElement(element);
if (sub_frame)
stack.push_back(sub_frame);
}
}
return NULL;
}
bool HasDocType(const WebDocument& doc) {
WebNode node = doc.firstChild();
if (node.isNull())
return false;
return node.nodeType() == WebNode::DocumentTypeNode;
}
bool IsMetaElement(const WebNode& node, std::string& charset_info) {
if (!node.isElementNode())
return false;
const WebElement meta = node.toConst<WebElement>();
if (!meta.hasTagName("meta"))
return false;
charset_info.erase(0, charset_info.length());
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) {
charset_info.append("has-charset-declaration");
int remaining_length = content.length() - pos - 7;
if (!remaining_length)
return true;
int start_pos = pos + 7;
while (remaining_length--)
if (content[start_pos++] == L'=')
break;
while (remaining_length) {
if (content[start_pos] > 0x0020)
break;
++start_pos;
--remaining_length;
}
if (!remaining_length)
return true;
int end_pos = start_pos;
while (remaining_length--) {
if (content[end_pos] <= 0x0020 || content[end_pos] == L';')
break;
++end_pos;
}
charset_info = content.substr(start_pos, end_pos - start_pos);
return true;
}
}
return true;
}
class LoadObserver : public RenderViewObserver {
public:
LoadObserver(RenderView* render_view, const base::Closure& quit_closure)
: RenderViewObserver(render_view),
quit_closure_(quit_closure) {}
virtual void DidFinishLoad(blink::WebFrame* frame) OVERRIDE {
if (frame == render_view()->GetWebView()->mainFrame())
quit_closure_.Run();
}
private:
base::Closure quit_closure_;
};
class DomSerializerTests : public ContentBrowserTest,
public WebPageSerializerClient {
public:
DomSerializerTests()
: serialized_(false),
local_directory_name_(FILE_PATH_LITERAL("./dummy_files/")) {}
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
command_line->AppendSwitch(switches::kSingleProcess);
#if defined(OS_WIN)
command_line->AppendSwitch(switches::kDisableAcceleratedCompositing);
#endif
}
virtual void didSerializeDataForFrame(const WebURL& frame_web_url,
const WebCString& data,
PageSerializationStatus status) {
GURL frame_url(frame_web_url);
if (status == WebPageSerializerClient::AllFramesAreFinished) {
SerializationFinishStatusMap::iterator it =
serialization_finish_status_.begin();
for (; it != serialization_finish_status_.end(); ++it)
ASSERT_TRUE(it->second);
serialized_ = true;
return;
}
SerializationFinishStatusMap::iterator it =
serialization_finish_status_.find(frame_url.spec());
if (it == serialization_finish_status_.end())
serialization_finish_status_[frame_url.spec()] = false;
it = serialization_finish_status_.find(frame_url.spec());
ASSERT_TRUE(it != serialization_finish_status_.end());
ASSERT_FALSE(it->second);
serialized_frame_map_[frame_url.spec()] += data.data();
if (status == WebPageSerializerClient::CurrentFrameIsFinished)
it->second = true;
}
bool HasSerializedFrame(const GURL& frame_url) {
return serialized_frame_map_.find(frame_url.spec()) !=
serialized_frame_map_.end();
}
const std::string& GetSerializedContentForFrame(
const GURL& frame_url) {
return serialized_frame_map_[frame_url.spec()];
}
RenderView* GetRenderView() {
return RenderView::FromRoutingID(kRenderViewRoutingId);
}
WebView* GetWebView() {
return GetRenderView()->GetWebView();
}
WebFrame* GetMainFrame() {
return GetWebView()->mainFrame();
}
void LoadContents(const std::string& contents,
const GURL& base_url,
const WebString encoding_info) {
scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner;
LoadObserver observer(GetRenderView(), runner->QuitClosure());
if (encoding_info.isEmpty()) {
GetMainFrame()->loadHTMLString(contents, base_url);
} else {
WebData data(contents.data(), contents.length());
WebFrame* web_frame = GetMainFrame();
ASSERT_TRUE(web_frame != NULL);
web_frame->loadData(data, "text/html", encoding_info, base_url);
}
runner->Run();
}
void SerializeDomForURL(const GURL& page_url,
bool recursive_serialization) {
WebFrame* web_frame = FindSubFrameByURL(GetWebView(), page_url);
ASSERT_TRUE(web_frame != NULL);
WebVector<WebURL> links;
links.assign(&page_url, 1);
WebString file_path =
base::FilePath(FILE_PATH_LITERAL("c:\\dummy.htm")).AsUTF16Unsafe();
WebVector<WebString> local_paths;
local_paths.assign(&file_path, 1);
bool result = WebPageSerializer::serialize(web_frame,
recursive_serialization,
static_cast<WebPageSerializerClient*>(this),
links,
local_paths,
local_directory_name_.AsUTF16Unsafe());
ASSERT_TRUE(result);
ASSERT_TRUE(serialized_);
}
void SerializeHTMLDOMWithDocTypeOnRenderer(const GURL& file_url) {
WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url);
ASSERT_TRUE(web_frame != NULL);
WebDocument doc = web_frame->document();
ASSERT_TRUE(HasDocType(doc));
SerializeDomForURL(file_url, false);
ASSERT_TRUE(HasSerializedFrame(file_url));
const std::string& serialized_contents =
GetSerializedContentForFrame(file_url);
LoadContents(serialized_contents, file_url,
web_frame->document().encoding());
web_frame = GetMainFrame();
doc = web_frame->document();
ASSERT_TRUE(HasDocType(doc));
}
void SerializeHTMLDOMWithoutDocTypeOnRenderer(const GURL& file_url) {
WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url);
ASSERT_TRUE(web_frame != NULL);
WebDocument doc = web_frame->document();
ASSERT_TRUE(!HasDocType(doc));
SerializeDomForURL(file_url, false);
ASSERT_TRUE(HasSerializedFrame(file_url));
const std::string& serialized_contents =
GetSerializedContentForFrame(file_url);
LoadContents(serialized_contents, file_url,
web_frame->document().encoding());
web_frame = GetMainFrame();
doc = web_frame->document();
ASSERT_TRUE(!HasDocType(doc));
}
void SerializeXMLDocWithBuiltInEntitiesOnRenderer(
const GURL& xml_file_url, const std::string& original_contents) {
SerializeDomForURL(xml_file_url, false);
ASSERT_TRUE(HasSerializedFrame(xml_file_url));
const std::string& serialized_contents =
GetSerializedContentForFrame(xml_file_url);
ASSERT_EQ(original_contents, serialized_contents);
}
void SerializeHTMLDOMWithAddingMOTWOnRenderer(
const GURL& file_url, const std::string& original_contents) {
std::string motw_declaration =
WebPageSerializer::generateMarkOfTheWebDeclaration(file_url).utf8();
ASSERT_FALSE(motw_declaration.empty());
ASSERT_TRUE(std::string::npos == original_contents.find(motw_declaration));
SerializeDomForURL(file_url, false);
ASSERT_TRUE(HasSerializedFrame(file_url));
const std::string& serialized_contents =
GetSerializedContentForFrame(file_url);
ASSERT_FALSE(std::string::npos ==
serialized_contents.find(motw_declaration));
}
void SerializeHTMLDOMWithNoMetaCharsetInOriginalDocOnRenderer(
const GURL& file_url) {
WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url);
ASSERT_TRUE(web_frame != NULL);
WebDocument doc = web_frame->document();
ASSERT_TRUE(doc.isHTMLDocument());
WebElement head_element = doc.head();
ASSERT_TRUE(!head_element.isNull());
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());
}
SerializeDomForURL(file_url, false);
ASSERT_TRUE(HasSerializedFrame(file_url));
const std::string& serialized_contents =
GetSerializedContentForFrame(file_url);
LoadContents(serialized_contents, file_url,
web_frame->document().encoding());
web_frame = GetMainFrame();
ASSERT_TRUE(web_frame != 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());
std::string charset_info2;
ASSERT_TRUE(IsMetaElement(meta_node, charset_info2));
ASSERT_TRUE(!charset_info2.empty());
ASSERT_EQ(charset_info2,
std::string(web_frame->document().encoding().utf8()));
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());
}
}
void SerializeHTMLDOMWithMultipleMetaCharsetInOriginalDocOnRenderer(
const GURL& file_url) {
WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url);
ASSERT_TRUE(web_frame != NULL);
WebDocument doc = web_frame->document();
ASSERT_TRUE(doc.isHTMLDocument());
WebElement head_ele = doc.head();
ASSERT_TRUE(!head_ele.isNull());
int charset_declaration_count = 0;
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++;
}
ASSERT_TRUE(charset_declaration_count > 1);
SerializeDomForURL(file_url, false);
ASSERT_TRUE(HasSerializedFrame(file_url));
const std::string& serialized_contents =
GetSerializedContentForFrame(file_url);
LoadContents(serialized_contents, file_url,
web_frame->document().encoding());
web_frame = GetMainFrame();
ASSERT_TRUE(web_frame != 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());
std::string charset_info2;
ASSERT_TRUE(IsMetaElement(meta_node, charset_info2));
ASSERT_TRUE(!charset_info2.empty());
ASSERT_EQ(charset_info2,
std::string(web_frame->document().encoding().utf8()));
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());
}
}
void SerializeHTMLDOMWithEntitiesInTextOnRenderer() {
base::FilePath page_file_path = GetTestFilePath(
"dom_serializer", "dom_serializer/htmlentities_in_text.htm");
GURL file_url = net::FilePathToFileURL(page_file_path);
ASSERT_TRUE(file_url.SchemeIsFile());
static const char* const original_contents =
"<html><body>&<>\"\'</body></html>";
LoadContents(original_contents, file_url, WebString());
WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url);
ASSERT_TRUE(web_frame != NULL);
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()) ==
"&<>\"\'");
SerializeDomForURL(file_url, false);
ASSERT_TRUE(HasSerializedFrame(file_url));
const std::string& serialized_contents =
GetSerializedContentForFrame(file_url);
std::string original_str =
WebPageSerializer::generateMarkOfTheWebDeclaration(file_url).utf8();
original_str += original_contents;
if (!doc.head().isNull()) {
WebString encoding = web_frame->document().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 +=
WebPageSerializer::generateMetaCharsetDeclaration(encoding).utf8();
head_part += "</head>";
original_str.insert(pos, head_part);
}
ASSERT_EQ(original_str, serialized_contents);
}
void SerializeHTMLDOMWithEntitiesInAttributeValueOnRenderer() {
base::FilePath page_file_path = GetTestFilePath(
"dom_serializer", "dom_serializer/htmlentities_in_attribute_value.htm");
GURL file_url = net::FilePathToFileURL(page_file_path);
ASSERT_TRUE(file_url.SchemeIsFile());
static const char* const original_contents =
"<html><body title=\"&<>"'\"></body></html>";
LoadContents(original_contents, file_url, WebString());
WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url);
ASSERT_TRUE(web_frame != NULL);
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()) == "&<>\"\'");
SerializeDomForURL(file_url, false);
ASSERT_TRUE(HasSerializedFrame(file_url));
const std::string& serialized_contents =
GetSerializedContentForFrame(file_url);
std::string original_str =
WebPageSerializer::generateMarkOfTheWebDeclaration(file_url).utf8();
original_str += original_contents;
if (!doc.isNull()) {
WebString encoding = web_frame->document().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 +=
WebPageSerializer::generateMetaCharsetDeclaration(encoding).utf8();
head_part += "</head>";
original_str.insert(pos, head_part);
}
ASSERT_EQ(original_str, serialized_contents);
}
void SerializeHTMLDOMWithNonStandardEntitiesOnRenderer(const GURL& file_url) {
WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url);
WebDocument doc = web_frame->document();
ASSERT_TRUE(doc.isHTMLDocument());
WebElement body_element = doc.body();
static const wchar_t parsed_value[] = {
'%', 0x2285, 0x00b9, '\'', 0
};
WebString value = body_element.getAttribute("title");
ASSERT_TRUE(base::UTF16ToWide(value) == parsed_value);
ASSERT_TRUE(base::UTF16ToWide(body_element.innerText()) == parsed_value);
SerializeDomForURL(file_url, false);
ASSERT_TRUE(HasSerializedFrame(file_url));
const std::string& serialized_contents =
GetSerializedContentForFrame(file_url);
ASSERT_EQ(std::string::npos, serialized_contents.find("%"));
ASSERT_EQ(std::string::npos, serialized_contents.find("⊅"));
ASSERT_EQ(std::string::npos, serialized_contents.find("¹"));
ASSERT_EQ(std::string::npos, serialized_contents.find("'"));
}
void SerializeHTMLDOMWithBaseTagOnRenderer(const GURL& file_url,
const GURL& path_dir_url) {
const int kTotalBaseTagCountInTestFile = 2;
WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url);
ASSERT_TRUE(web_frame != NULL);
WebDocument doc = web_frame->document();
ASSERT_TRUE(doc.isHTMLDocument());
WebElementCollection all = doc.all();
int original_base_tag_count = 0;
for (WebElement element = all.firstItem(); !element.isNull();
element = all.nextItem()) {
if (element.hasTagName("base")) {
original_base_tag_count++;
} else {
WebString value = GetSubResourceLinkFromElement(element);
if (value.isNull() && element.hasTagName("a")) {
value = element.getAttribute("href");
if (value.isEmpty())
value = WebString();
}
if (!value.isNull()) {
GURL link(value.utf8());
ASSERT_TRUE(link.scheme().empty());
}
}
}
ASSERT_EQ(original_base_tag_count, kTotalBaseTagCountInTestFile);
GURL original_base_url(doc.baseURL());
ASSERT_NE(original_base_url, path_dir_url);
SerializeDomForURL(file_url, false);
ASSERT_TRUE(HasSerializedFrame(file_url));
const std::string& serialized_contents =
GetSerializedContentForFrame(file_url);
LoadContents(serialized_contents, file_url,
web_frame->document().encoding());
web_frame = GetMainFrame();
ASSERT_TRUE(web_frame != NULL);
doc = web_frame->document();
ASSERT_TRUE(doc.isHTMLDocument());
all = doc.all();
int new_base_tag_count = 0;
for (WebNode node = all.firstItem(); !node.isNull();
node = all.nextItem()) {
if (!node.isElementNode())
continue;
WebElement element = node.to<WebElement>();
if (element.hasTagName("base")) {
new_base_tag_count++;
} else {
WebString value = GetSubResourceLinkFromElement(element);
if (value.isNull() && element.hasTagName("a")) {
value = element.getAttribute("href");
if (value.isEmpty())
value = WebString();
}
if (!value.isNull()) {
GURL link(std::string(value.utf8()));
ASSERT_FALSE(link.scheme().empty());
}
}
}
ASSERT_EQ(new_base_tag_count, original_base_tag_count + 1);
GURL new_base_url(doc.baseURL());
ASSERT_EQ(new_base_url, path_dir_url);
}
void SerializeHTMLDOMWithEmptyHeadOnRenderer() {
base::FilePath page_file_path = GetTestFilePath(
"dom_serializer", "empty_head.htm");
GURL file_url = net::FilePathToFileURL(page_file_path);
ASSERT_TRUE(file_url.SchemeIsFile());
static const char* const empty_head_contents =
"<html><head></head><body>hello world</body></html>";
LoadContents(empty_head_contents, file_url, WebString());
WebFrame* web_frame = GetMainFrame();
ASSERT_TRUE(web_frame != NULL);
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);
SerializeDomForURL(file_url, false);
ASSERT_TRUE(HasSerializedFrame(file_url));
const std::string& serialized_contents =
GetSerializedContentForFrame(file_url);
LoadContents(serialized_contents, file_url,
web_frame->document().encoding());
web_frame = GetMainFrame();
ASSERT_TRUE(web_frame != 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());
std::string charset_info;
ASSERT_TRUE(IsMetaElement(meta_node, charset_info));
ASSERT_TRUE(!charset_info.empty());
ASSERT_EQ(charset_info,
std::string(web_frame->document().encoding().utf8()));
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");
}
void SerializeDocumentWithDownloadedIFrameOnRenderer(const GURL& file_url) {
SerializeDomForURL(file_url, true);
}
void SubResourceForElementsInNonHTMLNamespaceOnRenderer(
const GURL& file_url) {
WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url);
ASSERT_TRUE(web_frame != NULL);
WebDocument doc = web_frame->document();
WebNode lastNodeInBody = doc.body().lastChild();
ASSERT_EQ(WebNode::ElementNode, lastNodeInBody.nodeType());
WebString uri = GetSubResourceLinkFromElement(
lastNodeInBody.to<WebElement>());
EXPECT_TRUE(uri.isNull());
}
private:
typedef base::hash_map<std::string, std::string> SerializedFrameContentMap;
SerializedFrameContentMap serialized_frame_map_;
typedef base::hash_map<std::string, bool> SerializationFinishStatusMap;
SerializationFinishStatusMap serialization_finish_status_;
bool serialized_;
const base::FilePath local_directory_name_;
};
IN_PROC_BROWSER_TEST_F(DomSerializerTests, SerializeHTMLDOMWithDocType) {
base::FilePath page_file_path =
GetTestFilePath("dom_serializer", "youtube_1.htm");
GURL file_url = net::FilePathToFileURL(page_file_path);
ASSERT_TRUE(file_url.SchemeIsFile());
NavigateToURL(shell(), file_url);
PostTaskToInProcessRendererAndWait(
base::Bind(&DomSerializerTests::SerializeHTMLDOMWithDocTypeOnRenderer,
base::Unretained(this), file_url));
}
IN_PROC_BROWSER_TEST_F(DomSerializerTests, SerializeHTMLDOMWithoutDocType) {
base::FilePath page_file_path =
GetTestFilePath("dom_serializer", "youtube_2.htm");
GURL file_url = net::FilePathToFileURL(page_file_path);
ASSERT_TRUE(file_url.SchemeIsFile());
NavigateToURL(shell(), file_url);
PostTaskToInProcessRendererAndWait(
base::Bind(
&DomSerializerTests::SerializeHTMLDOMWithoutDocTypeOnRenderer,
base::Unretained(this), file_url));
}
IN_PROC_BROWSER_TEST_F(DomSerializerTests,
DISABLED_SerializeXMLDocWithBuiltInEntities) {
base::FilePath page_file_path =
GetTestFilePath("dom_serializer", "note.html");
base::FilePath xml_file_path = GetTestFilePath("dom_serializer", "note.xml");
std::string original_contents;
ASSERT_TRUE(base::ReadFileToString(xml_file_path, &original_contents));
GURL file_url = net::FilePathToFileURL(page_file_path);
GURL xml_file_url = net::FilePathToFileURL(xml_file_path);
ASSERT_TRUE(file_url.SchemeIsFile());
NavigateToURL(shell(), file_url);
PostTaskToInProcessRendererAndWait(
base::Bind(
&DomSerializerTests::SerializeXMLDocWithBuiltInEntitiesOnRenderer,
base::Unretained(this), xml_file_url, original_contents));
}
IN_PROC_BROWSER_TEST_F(DomSerializerTests, SerializeHTMLDOMWithAddingMOTW) {
base::FilePath page_file_path =
GetTestFilePath("dom_serializer", "youtube_2.htm");
std::string original_contents;
ASSERT_TRUE(base::ReadFileToString(page_file_path, &original_contents));
GURL file_url = net::FilePathToFileURL(page_file_path);
ASSERT_TRUE(file_url.SchemeIsFile());
NavigateToURL(shell(), file_url);
PostTaskToInProcessRendererAndWait(
base::Bind(
&DomSerializerTests::SerializeHTMLDOMWithAddingMOTWOnRenderer,
base::Unretained(this), file_url, original_contents));
}
IN_PROC_BROWSER_TEST_F(DomSerializerTests,
SerializeHTMLDOMWithNoMetaCharsetInOriginalDoc) {
base::FilePath page_file_path =
GetTestFilePath("dom_serializer", "youtube_1.htm");
GURL file_url = net::FilePathToFileURL(page_file_path);
ASSERT_TRUE(file_url.SchemeIsFile());
NavigateToURL(shell(), file_url);
PostTaskToInProcessRendererAndWait(
base::Bind(
&DomSerializerTests::
SerializeHTMLDOMWithNoMetaCharsetInOriginalDocOnRenderer,
base::Unretained(this), file_url));
}
IN_PROC_BROWSER_TEST_F(DomSerializerTests,
SerializeHTMLDOMWithMultipleMetaCharsetInOriginalDoc) {
base::FilePath page_file_path =
GetTestFilePath("dom_serializer", "youtube_2.htm");
GURL file_url = net::FilePathToFileURL(page_file_path);
ASSERT_TRUE(file_url.SchemeIsFile());
NavigateToURL(shell(), file_url);
PostTaskToInProcessRendererAndWait(
base::Bind(
&DomSerializerTests::
SerializeHTMLDOMWithMultipleMetaCharsetInOriginalDocOnRenderer,
base::Unretained(this), file_url));
}
IN_PROC_BROWSER_TEST_F(DomSerializerTests, SerializeHTMLDOMWithEntitiesInText) {
NavigateToURL(shell(), GetTestUrl(".", "simple_page.html"));
PostTaskToInProcessRendererAndWait(
base::Bind(
&DomSerializerTests::SerializeHTMLDOMWithEntitiesInTextOnRenderer,
base::Unretained(this)));
}
IN_PROC_BROWSER_TEST_F(DomSerializerTests,
DISABLED_SerializeHTMLDOMWithEntitiesInAttributeValue) {
NavigateToURL(shell(), GetTestUrl(".", "simple_page.html"));
PostTaskToInProcessRendererAndWait(
base::Bind(
&DomSerializerTests::
SerializeHTMLDOMWithEntitiesInAttributeValueOnRenderer,
base::Unretained(this)));
}
IN_PROC_BROWSER_TEST_F(DomSerializerTests,
SerializeHTMLDOMWithNonStandardEntities) {
base::FilePath page_file_path = GetTestFilePath(
"dom_serializer", "nonstandard_htmlentities.htm");
GURL file_url = net::FilePathToFileURL(page_file_path);
NavigateToURL(shell(), file_url);
PostTaskToInProcessRendererAndWait(
base::Bind(
&DomSerializerTests::
SerializeHTMLDOMWithNonStandardEntitiesOnRenderer,
base::Unretained(this), file_url));
}
IN_PROC_BROWSER_TEST_F(DomSerializerTests,
DISABLED_SerializeHTMLDOMWithBaseTag) {
base::FilePath page_file_path = GetTestFilePath(
"dom_serializer", "html_doc_has_base_tag.htm");
base::FilePath dir_name = page_file_path.DirName();
dir_name = dir_name.Append(
base::FilePath::StringType(base::FilePath::kSeparators[0], 1));
GURL path_dir_url = net::FilePathToFileURL(dir_name);
GURL file_url = net::FilePathToFileURL(page_file_path);
ASSERT_TRUE(file_url.SchemeIsFile());
NavigateToURL(shell(), file_url);
PostTaskToInProcessRendererAndWait(
base::Bind(
&DomSerializerTests::SerializeHTMLDOMWithBaseTagOnRenderer,
base::Unretained(this), file_url, path_dir_url));
}
IN_PROC_BROWSER_TEST_F(DomSerializerTests, SerializeHTMLDOMWithEmptyHead) {
NavigateToURL(shell(), GetTestUrl(".", "simple_page.html"));
PostTaskToInProcessRendererAndWait(
base::Bind(&DomSerializerTests::SerializeHTMLDOMWithEmptyHeadOnRenderer,
base::Unretained(this)));
}
IN_PROC_BROWSER_TEST_F(DomSerializerTests,
SerializeDocumentWithDownloadedIFrame) {
base::FilePath page_file_path = GetTestFilePath(
"dom_serializer", "iframe-src-is-exe.htm");
GURL file_url = net::FilePathToFileURL(page_file_path);
ASSERT_TRUE(file_url.SchemeIsFile());
NavigateToURL(shell(), file_url);
PostTaskToInProcessRendererAndWait(
base::Bind(
&DomSerializerTests::
SerializeDocumentWithDownloadedIFrameOnRenderer,
base::Unretained(this), file_url));
}
IN_PROC_BROWSER_TEST_F(DomSerializerTests,
SubResourceForElementsInNonHTMLNamespace) {
base::FilePath page_file_path = GetTestFilePath(
"dom_serializer", "non_html_namespace.htm");
GURL file_url = net::FilePathToFileURL(page_file_path);
NavigateToURL(shell(), file_url);
PostTaskToInProcessRendererAndWait(
base::Bind(
&DomSerializerTests::
SubResourceForElementsInNonHTMLNamespaceOnRenderer,
base::Unretained(this), file_url));
}
}