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

Unified Diff: Source/web/tests/MHTMLTest.cpp

Issue 68613003: Merges the two different page serializers (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Remove newline after XML decl Created 7 years 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 | « Source/web/WebPageSerializerImpl.cpp ('k') | Source/web/tests/PageSerializerTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/web/tests/MHTMLTest.cpp
diff --git a/Source/web/tests/MHTMLTest.cpp b/Source/web/tests/MHTMLTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..52d312da83e56ba7876f24e6b45898a5359d5183
--- /dev/null
+++ b/Source/web/tests/MHTMLTest.cpp
@@ -0,0 +1,169 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "config.h"
+
+#include "URLTestHelpers.h"
+#include "platform/SerializedResource.h"
+#include "platform/SharedBuffer.h"
+#include "platform/mhtml/MHTMLArchive.h"
+#include "public/platform/Platform.h"
+#include "public/platform/WebUnitTestSupport.h"
+#include <gtest/gtest.h>
+
+using namespace WebCore;
+using namespace blink;
+
+using blink::URLTestHelpers::toKURL;
+
+namespace {
+
+class LineReader {
+public:
+ LineReader(const std::string& text) : m_text(text), m_index(0) { }
+ bool getNextLine(std::string* line)
+ {
+ line->clear();
+ if (m_index >= m_text.length())
+ return false;
+
+ size_t endOfLineIndex = m_text.find("\r\n", m_index);
+ if (endOfLineIndex == std::string::npos) {
+ *line = m_text.substr(m_index);
+ m_index = m_text.length();
+ } else {
+ *line = m_text.substr(m_index, endOfLineIndex - m_index);
+ m_index = endOfLineIndex + 2;
+ }
+ return true;
+ }
+
+private:
+ std::string m_text;
+ size_t m_index;
+};
+
+
+class MHTMLTest : public testing::Test {
+public:
+ MHTMLTest()
+ {
+ m_filePath = Platform::current()->unitTestSupport()->webKitRootDir();
+ m_filePath.append("/Source/web/tests/data/mhtml/");
+ }
+
+protected:
+ virtual void SetUp()
+ {
+ }
+
+ virtual void TearDown()
+ {
+ }
+
+ void addResource(const char* url, const char* mime, PassRefPtr<SharedBuffer> data)
+ {
+ SerializedResource resource(toKURL(url), mime, data);
+ m_resources.append(resource);
+ }
+
+ void addResource(const char* url, const char* mime, const char* fileName)
+ {
+ addResource(url, mime, readFile(fileName));
+ }
+
+ void addTestResources()
+ {
+ addResource("http://www.test.com", "text/html", "css_test_page.html");
+ addResource("http://www.test.com/link_styles.css", "text/css", "link_styles.css");
+ addResource("http://www.test.com/import_style_from_link.css", "text/css", "import_style_from_link.css");
+ addResource("http://www.test.com/import_styles.css", "text/css", "import_styles.css");
+ addResource("http://www.test.com/red_background.png", "image/png", "red_background.png");
+ addResource("http://www.test.com/orange_background.png", "image/png", "orange_background.png");
+ addResource("http://www.test.com/yellow_background.png", "image/png", "yellow_background.png");
+ addResource("http://www.test.com/green_background.png", "image/png", "green_background.png");
+ addResource("http://www.test.com/blue_background.png", "image/png", "blue_background.png");
+ addResource("http://www.test.com/purple_background.png", "image/png", "purple_background.png");
+ addResource("http://www.test.com/ul-dot.png", "image/png", "ul-dot.png");
+ addResource("http://www.test.com/ol-dot.png", "image/png", "ol-dot.png");
+ }
+
+ PassRefPtr<SharedBuffer> serialize(const char *title, const char *mime, MHTMLArchive::EncodingPolicy encodingPolicy)
+ {
+ return MHTMLArchive::generateMHTMLData(m_resources, encodingPolicy, title, mime);
+ }
+
+
+private:
+
+ PassRefPtr<SharedBuffer> readFile(const char* fileName)
+ {
+ String filePath = m_filePath + fileName;
+ return Platform::current()->unitTestSupport()->readFromFile(filePath);
+ }
+
+ String m_filePath;
+ Vector<SerializedResource> m_resources;
+};
+
+TEST_F(MHTMLTest, FAILS_TestMHTMLEncoding)
+{
+ addTestResources();
+ RefPtr<SharedBuffer> data = serialize("Test Serialization", "text/html", MHTMLArchive::UseDefaultEncoding);
+
+ // Read the MHTML data line per line and do some pseudo-parsing to make sure the right encoding is used for the different sections.
+ LineReader lineReader(std::string(data->data()));
+ int sectionCheckedCount = 0;
+ const char* expectedEncoding = 0;
+ std::string line;
+ while (lineReader.getNextLine(&line)) {
+ if (!line.find("Content-Type:")) {
+ ASSERT_FALSE(expectedEncoding);
+ if (line.find("multipart/related;") != std::string::npos) {
+ // Skip this one, it's part of the MHTML header.
+ continue;
+ }
+ if (line.find("text/") != std::string::npos)
+ expectedEncoding = "quoted-printable";
+ else if (line.find("image/") != std::string::npos)
+ expectedEncoding = "base64";
+ else
+ FAIL() << "Unexpected Content-Type: " << line;
+ continue;
+ }
+ if (!line.find("Content-Transfer-Encoding:")) {
+ ASSERT_TRUE(expectedEncoding);
+ EXPECT_TRUE(line.find(expectedEncoding) != std::string::npos);
+ expectedEncoding = 0;
+ sectionCheckedCount++;
+ }
+ }
+ EXPECT_EQ(12, sectionCheckedCount);
+}
+}
« no previous file with comments | « Source/web/WebPageSerializerImpl.cpp ('k') | Source/web/tests/PageSerializerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698