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

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

Issue 22292008: Add 8bit Content-Transfer-Encoding support for reading MHTML files (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 4 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
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..24de74d1265025a5e6a0ea90988806780479894d
--- /dev/null
+++ b/Source/web/tests/MHTMLTest.cpp
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2013, Opera Software ASA. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. Neither the name of Opera Software ASA 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 HOLDER 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 "core/loader/archive/ArchiveResource.h"
+#include "core/loader/archive/MHTMLArchive.h"
+#include "core/loader/archive/MHTMLParser.h"
+#include "core/platform/FileSystem.h"
+#include "core/platform/SharedBuffer.h"
+#include "public/platform/Platform.h"
+#include "public/platform/WebString.h"
+#include "public/platform/WebUnitTestSupport.h"
+#include "wtf/Vector.h"
+
+#include <gtest/gtest.h>
+
+using namespace WebCore;
+using namespace WebKit;
+
+namespace {
+
+class MHTMLTest : public testing::Test {
+
abarth-chromium 2013/08/07 18:12:27 We usually skip this blank line
+protected:
+
+ static String getFileRoot()
+ {
+ String filePath = Platform::current()->unitTestSupport()->webKitRootDir();
+ filePath.append("/Source/web/tests/data/mhtml/");
+ return filePath;
+ }
+
+ static PassRefPtr<SharedBuffer> readFile(const char* fileName)
abarth-chromium 2013/08/07 18:12:27 This function looks copy/pasted from readFile in W
+ {
+ String filePath = getFileRoot();
+ filePath.append(fileName);
+
+ long long fileSize;
+ if (!getFileSize(filePath, fileSize))
+ return 0;
+
+ PlatformFileHandle handle = openFile(filePath, OpenForRead);
+ int fileLength = static_cast<int>(fileSize);
+ Vector<char> buffer(fileLength);
+ readFromFile(handle, buffer.data(), fileLength);
+ closeFile(handle);
+ return SharedBuffer::adoptVector(buffer);
+ }
+
+
abarth-chromium 2013/08/07 18:12:27 You've got an extra blank line here.
+ static PassRefPtr<MHTMLArchive> loadMHTMLArchive(const char* filename)
+ {
+ RefPtr<SharedBuffer> data = readFile(filename);
+ if (data.get()) {
abarth-chromium 2013/08/07 18:12:27 There's no need to call .get() here. RefPtr has a
+ MHTMLParser parser = MHTMLParser(data.get());
+ return parser.parseArchive();
+ }
+ return 0;
+ }
+};
+
+
+TEST_F(MHTMLTest, 8BitTransferEncoding)
+{
+ RefPtr<MHTMLArchive> archive = loadMHTMLArchive("8bit-transfer-encoding.mhtml");
abarth-chromium 2013/08/07 18:12:27 Rather than writing a unit test for this change, y
+ ASSERT_TRUE(archive.get());
+
+ ArchiveResource* main = archive->mainResource();
+ ASSERT_EQ(main->mimeType(), "text/html");
+ ASSERT_EQ(main->textEncoding(), "utf-8");
+ ASSERT_EQ(archive->subresources().size(), 0u);
+}
+
+}
« no previous file with comments | « Source/core/platform/network/MIMEHeader.cpp ('k') | Source/web/tests/data/mhtml/8bit-transfer-encoding.mhtml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698