Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Unified Diff: content/renderer/dom_serializer_browsertest.cc

Issue 1373573002: ABANDONED: OOPIFs: Moving stitching of local paths from renderer to browser process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@page-serialization-recursive-begone
Patch Set: Rebasing... Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/common/frame_messages.h ('k') | content/renderer/render_frame_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/dom_serializer_browsertest.cc
diff --git a/content/renderer/dom_serializer_browsertest.cc b/content/renderer/dom_serializer_browsertest.cc
index 781fee0f3ce189ae07de2e3ae5c7b3e06a28a538..17097a693c9f9e5509f778e3177ce3b2f6aeb6c5 100644
--- a/content/renderer/dom_serializer_browsertest.cc
+++ b/content/renderer/dom_serializer_browsertest.cc
@@ -57,7 +57,7 @@ using blink::WebVector;
namespace content {
// Iterate recursively over sub-frames to find one with with a given url.
-WebFrame* FindSubFrameByURL(WebView* web_view, const GURL& url) {
+WebFrame* FindSubframeByURL(WebView* web_view, const GURL& url) {
if (!web_view->mainFrame())
return NULL;
@@ -159,8 +159,8 @@ class DomSerializerTests : public ContentBrowserTest,
public WebPageSerializerClient {
public:
DomSerializerTests()
- : serialized_(false),
- local_directory_name_(FILE_PATH_LITERAL("./dummy_files/")) {}
+ : got_end_of_frame_notification_(false),
+ local_directory_name_(FILE_PATH_LITERAL("./dummy_files/")) {}
void SetUpCommandLine(base::CommandLine* command_line) override {
command_line->AppendSwitch(switches::kSingleProcess);
@@ -175,51 +175,29 @@ class DomSerializerTests : public ContentBrowserTest,
shell()->web_contents()->GetRenderViewHost()->GetRoutingID();
}
- // DomSerializerDelegate.
- void didSerializeDataForFrame(const WebURL& frame_web_url,
- const WebCString& data,
- PageSerializationStatus status) override {
- GURL frame_url(frame_web_url);
- // If the all frames are finished saving, check all finish status
- 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;
- }
-
- // Check finish status of current frame.
- SerializationFinishStatusMap::iterator it =
- serialization_finish_status_.find(frame_url.spec());
- // New frame, set initial status as false.
- 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());
- // In process frame, finish status should be false.
- ASSERT_FALSE(it->second);
-
- // Add data to corresponding frame's content.
- serialized_frame_map_[frame_url.spec()] += data.data();
-
- // Current frame is completed saving, change the finish status.
- if (status == WebPageSerializerClient::CurrentFrameIsFinished)
- it->second = true;
+ void writeHtmlFragment(const WebCString& data) override {
+ serialization_output_ += data.data();
}
- bool HasSerializedFrame(const GURL& frame_url) {
- return serialized_frame_map_.find(frame_url.spec()) !=
- serialized_frame_map_.end();
+ void writeLocalPathForSubframe(const WebFrame& subframe) override {
+ // Tests in content/renderer/dom_serializer_browsertest.cc do not verify
+ // local paths in the serializer html (they are verified by
+ // chrome/browser/download/save_page_browsertest.cc). Therefore the body of
+ // writeLocalPathForSubframe can be empty below.
}
- const std::string& GetSerializedContentForFrame(
- const GURL& frame_url) {
- return serialized_frame_map_[frame_url.spec()];
+ void writeLocalPathForSavableResource(
+ const WebURL& savableResourceURL) override {
+ // Tests in content/renderer/dom_serializer_browsertest.cc do not verify
+ // local paths in the serializer html (they are verified by
+ // chrome/browser/download/save_page_browsertest.cc). Therefore the body of
+ // writeLocalPathForSavableResource can be empty below.
}
+ void endOfFrame() override { got_end_of_frame_notification_ = true; }
+
+ const std::string& GetSerializedContent() { return serialization_output_; }
+
RenderView* GetRenderView() {
return RenderView::FromRoutingID(render_view_routing_id_);
}
@@ -262,7 +240,7 @@ class DomSerializerTests : public ContentBrowserTest,
// Serialize DOM belonging to a frame with the specified |frame_url|.
void SerializeDomForURL(const GURL& frame_url) {
// Find corresponding WebFrame according to frame_url.
- WebFrame* web_frame = FindSubFrameByURL(GetWebView(), frame_url);
+ WebFrame* web_frame = FindSubframeByURL(GetWebView(), frame_url);
ASSERT_TRUE(web_frame != NULL);
WebVector<WebURL> links;
links.assign(&frame_url, 1);
@@ -271,27 +249,23 @@ class DomSerializerTests : public ContentBrowserTest,
WebVector<WebString> local_paths;
local_paths.assign(&file_path, 1);
// Start serializing DOM.
- bool result = WebPageSerializer::serialize(web_frame->toWebLocalFrame(),
- static_cast<WebPageSerializerClient*>(this),
- links,
- local_paths,
- local_directory_name_.AsUTF16Unsafe());
+ bool result = WebPageSerializer::serialize(
+ web_frame->toWebLocalFrame(),
+ static_cast<WebPageSerializerClient*>(this));
ASSERT_TRUE(result);
- ASSERT_TRUE(serialized_);
+ ASSERT_TRUE(got_end_of_frame_notification_);
}
void SerializeHTMLDOMWithDocTypeOnRenderer(const GURL& file_url) {
// Make sure original contents have document type.
- WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url);
+ WebFrame* web_frame = FindSubframeByURL(GetWebView(), file_url);
ASSERT_TRUE(web_frame != NULL);
WebDocument doc = web_frame->document();
ASSERT_TRUE(HasDocType(doc));
// Do serialization.
SerializeDomForURL(file_url);
// Load the serialized contents.
- ASSERT_TRUE(HasSerializedFrame(file_url));
- const std::string& serialized_contents =
- GetSerializedContentForFrame(file_url);
+ const std::string& serialized_contents = GetSerializedContent();
LoadContents(serialized_contents, file_url,
web_frame->document().encoding());
// Make sure serialized contents still have document type.
@@ -302,16 +276,14 @@ class DomSerializerTests : public ContentBrowserTest,
void SerializeHTMLDOMWithoutDocTypeOnRenderer(const GURL& file_url) {
// Make sure original contents do not have document type.
- WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url);
+ WebFrame* web_frame = FindSubframeByURL(GetWebView(), file_url);
ASSERT_TRUE(web_frame != NULL);
WebDocument doc = web_frame->document();
ASSERT_TRUE(!HasDocType(doc));
// Do serialization.
SerializeDomForURL(file_url);
// Load the serialized contents.
- ASSERT_TRUE(HasSerializedFrame(file_url));
- const std::string& serialized_contents =
- GetSerializedContentForFrame(file_url);
+ const std::string& serialized_contents = GetSerializedContent();
LoadContents(serialized_contents, file_url,
web_frame->document().encoding());
// Make sure serialized contents do not have document type.
@@ -325,9 +297,7 @@ class DomSerializerTests : public ContentBrowserTest,
// Do serialization.
SerializeDomForURL(xml_file_url);
// Compare the serialized contents with original contents.
- ASSERT_TRUE(HasSerializedFrame(xml_file_url));
- const std::string& serialized_contents =
- GetSerializedContentForFrame(xml_file_url);
+ const std::string& serialized_contents = GetSerializedContent();
ASSERT_EQ(original_contents, serialized_contents);
}
@@ -344,9 +314,7 @@ class DomSerializerTests : public ContentBrowserTest,
// Do serialization.
SerializeDomForURL(file_url);
// Make sure the serialized contents have MOTW ;
- ASSERT_TRUE(HasSerializedFrame(file_url));
- const std::string& serialized_contents =
- GetSerializedContentForFrame(file_url);
+ const std::string& serialized_contents = GetSerializedContent();
ASSERT_FALSE(std::string::npos ==
serialized_contents.find(motw_declaration));
}
@@ -354,7 +322,7 @@ class DomSerializerTests : public ContentBrowserTest,
void SerializeHTMLDOMWithNoMetaCharsetInOriginalDocOnRenderer(
const GURL& file_url) {
// Make sure there is no META charset declaration in original document.
- WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url);
+ WebFrame* web_frame = FindSubframeByURL(GetWebView(), file_url);
ASSERT_TRUE(web_frame != NULL);
WebDocument doc = web_frame->document();
ASSERT_TRUE(doc.isHTMLDocument());
@@ -371,9 +339,7 @@ class DomSerializerTests : public ContentBrowserTest,
SerializeDomForURL(file_url);
// Load the serialized contents.
- ASSERT_TRUE(HasSerializedFrame(file_url));
- const std::string& serialized_contents =
- GetSerializedContentForFrame(file_url);
+ const std::string& serialized_contents = GetSerializedContent();
LoadContents(serialized_contents, file_url,
web_frame->document().encoding());
// Make sure the first child of HEAD element is META which has charset
@@ -406,7 +372,7 @@ class DomSerializerTests : public ContentBrowserTest,
const GURL& file_url) {
// Make sure there are multiple META charset declarations in original
// document.
- WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url);
+ WebFrame* web_frame = FindSubframeByURL(GetWebView(), file_url);
ASSERT_TRUE(web_frame != NULL);
WebDocument doc = web_frame->document();
ASSERT_TRUE(doc.isHTMLDocument());
@@ -427,9 +393,7 @@ class DomSerializerTests : public ContentBrowserTest,
SerializeDomForURL(file_url);
// Load the serialized contents.
- ASSERT_TRUE(HasSerializedFrame(file_url));
- const std::string& serialized_contents =
- GetSerializedContentForFrame(file_url);
+ const std::string& serialized_contents = GetSerializedContent();
LoadContents(serialized_contents, file_url,
web_frame->document().encoding());
// Make sure only first child of HEAD element is META which has charset
@@ -472,7 +436,7 @@ class DomSerializerTests : public ContentBrowserTest,
LoadContents(original_contents, file_url, WebString());
// Get BODY's text content in DOM.
- WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url);
+ WebFrame* web_frame = FindSubframeByURL(GetWebView(), file_url);
ASSERT_TRUE(web_frame != NULL);
WebDocument doc = web_frame->document();
ASSERT_TRUE(doc.isHTMLDocument());
@@ -484,9 +448,7 @@ class DomSerializerTests : public ContentBrowserTest,
// Do serialization.
SerializeDomForURL(file_url);
// Compare the serialized contents with original contents.
- ASSERT_TRUE(HasSerializedFrame(file_url));
- const std::string& serialized_contents =
- GetSerializedContentForFrame(file_url);
+ const std::string& serialized_contents = GetSerializedContent();
// Compare the serialized contents with original contents to make sure
// they are same.
// Because we add MOTW when serializing DOM, so before comparison, we also
@@ -526,7 +488,7 @@ class DomSerializerTests : public ContentBrowserTest,
// Load the test contents.
LoadContents(original_contents, file_url, WebString());
// Get value of BODY's title attribute in DOM.
- WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url);
+ WebFrame* web_frame = FindSubframeByURL(GetWebView(), file_url);
ASSERT_TRUE(web_frame != NULL);
WebDocument doc = web_frame->document();
ASSERT_TRUE(doc.isHTMLDocument());
@@ -537,9 +499,7 @@ class DomSerializerTests : public ContentBrowserTest,
// Do serialization.
SerializeDomForURL(file_url);
// Compare the serialized contents with original contents.
- ASSERT_TRUE(HasSerializedFrame(file_url));
- const std::string& serialized_contents =
- GetSerializedContentForFrame(file_url);
+ const std::string& serialized_contents = GetSerializedContent();
// Compare the serialized contents with original contents to make sure
// they are same.
std::string original_str =
@@ -562,7 +522,7 @@ class DomSerializerTests : public ContentBrowserTest,
void SerializeHTMLDOMWithNonStandardEntitiesOnRenderer(const GURL& file_url) {
// Get value of BODY's title attribute in DOM.
- WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url);
+ WebFrame* web_frame = FindSubframeByURL(GetWebView(), file_url);
WebDocument doc = web_frame->document();
ASSERT_TRUE(doc.isHTMLDocument());
WebElement body_element = doc.body();
@@ -578,9 +538,7 @@ class DomSerializerTests : public ContentBrowserTest,
// Do serialization.
SerializeDomForURL(file_url);
// Check the serialized string.
- ASSERT_TRUE(HasSerializedFrame(file_url));
- const std::string& serialized_contents =
- GetSerializedContentForFrame(file_url);
+ const std::string& serialized_contents = GetSerializedContent();
// Confirm that the serialized string has no non-standard HTML entities.
ASSERT_EQ(std::string::npos, serialized_contents.find("&percnt;"));
ASSERT_EQ(std::string::npos, serialized_contents.find("&nsup;"));
@@ -596,7 +554,7 @@ class DomSerializerTests : public ContentBrowserTest,
// 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.
- WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url);
+ WebFrame* web_frame = FindSubframeByURL(GetWebView(), file_url);
ASSERT_TRUE(web_frame != NULL);
WebDocument doc = web_frame->document();
ASSERT_TRUE(doc.isHTMLDocument());
@@ -632,9 +590,7 @@ class DomSerializerTests : public ContentBrowserTest,
SerializeDomForURL(file_url);
// Load the serialized contents.
- ASSERT_TRUE(HasSerializedFrame(file_url));
- const std::string& serialized_contents =
- GetSerializedContentForFrame(file_url);
+ const std::string& serialized_contents = GetSerializedContent();
LoadContents(serialized_contents, file_url,
web_frame->document().encoding());
@@ -701,9 +657,7 @@ class DomSerializerTests : public ContentBrowserTest,
// Do serialization.
SerializeDomForURL(file_url);
// Make sure the serialized contents have META ;
- ASSERT_TRUE(HasSerializedFrame(file_url));
- const std::string& serialized_contents =
- GetSerializedContentForFrame(file_url);
+ const std::string& serialized_contents = GetSerializedContent();
// Reload serialized contents and make sure there is only one META tag.
LoadContents(serialized_contents, file_url,
@@ -737,7 +691,7 @@ class DomSerializerTests : public ContentBrowserTest,
void SubResourceForElementsInNonHTMLNamespaceOnRenderer(
const GURL& file_url) {
- WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url);
+ WebFrame* web_frame = FindSubframeByURL(GetWebView(), file_url);
ASSERT_TRUE(web_frame != NULL);
WebDocument doc = web_frame->document();
WebNode lastNodeInBody = doc.body().lastChild();
@@ -749,14 +703,12 @@ class DomSerializerTests : public ContentBrowserTest,
private:
int32 render_view_routing_id_;
- // Map frame_url to corresponding serialized_content.
- typedef base::hash_map<std::string, std::string> SerializedFrameContentMap;
- SerializedFrameContentMap serialized_frame_map_;
+ std::string serialization_output_;
// Map frame_url to corresponding status of serialization finish.
typedef base::hash_map<std::string, bool> SerializationFinishStatusMap;
SerializationFinishStatusMap serialization_finish_status_;
// Flag indicates whether the process of serializing DOM is finished or not.
- bool serialized_;
+ bool got_end_of_frame_notification_;
// The local_directory_name_ is dummy relative path of directory which
// contain all saved auxiliary files included all sub frames and resources.
const base::FilePath local_directory_name_;
« no previous file with comments | « content/common/frame_messages.h ('k') | content/renderer/render_frame_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698