Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2013, Opera Software ASA. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * | |
| 8 * 1. Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | |
| 11 * notice, this list of conditions and the following disclaimer in the | |
| 12 * documentation and/or other materials provided with the distribution. | |
| 13 * 3. Neither the name of Opera Software ASA nor the names of its | |
| 14 * contributors may be used to endorse or promote products derived | |
| 15 * from this software without specific prior written permission. | |
| 16 * | |
| 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
| 20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
| 21 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
| 22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
| 24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
| 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
| 26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | |
| 28 * OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #include "config.h" | |
| 32 | |
| 33 #include "core/loader/archive/ArchiveResource.h" | |
| 34 #include "core/loader/archive/MHTMLArchive.h" | |
| 35 #include "core/loader/archive/MHTMLParser.h" | |
| 36 #include "core/platform/FileSystem.h" | |
| 37 #include "core/platform/SharedBuffer.h" | |
| 38 #include "public/platform/Platform.h" | |
| 39 #include "public/platform/WebString.h" | |
| 40 #include "public/platform/WebUnitTestSupport.h" | |
| 41 #include "wtf/Vector.h" | |
| 42 | |
| 43 #include <gtest/gtest.h> | |
| 44 | |
| 45 using namespace WebCore; | |
| 46 using namespace WebKit; | |
| 47 | |
| 48 namespace { | |
| 49 | |
| 50 class MHTMLTest : public testing::Test { | |
| 51 | |
|
abarth-chromium
2013/08/07 18:12:27
We usually skip this blank line
| |
| 52 protected: | |
| 53 | |
| 54 static String getFileRoot() | |
| 55 { | |
| 56 String filePath = Platform::current()->unitTestSupport()->webKitRootDir( ); | |
| 57 filePath.append("/Source/web/tests/data/mhtml/"); | |
| 58 return filePath; | |
| 59 } | |
| 60 | |
| 61 static PassRefPtr<SharedBuffer> readFile(const char* fileName) | |
|
abarth-chromium
2013/08/07 18:12:27
This function looks copy/pasted from readFile in W
| |
| 62 { | |
| 63 String filePath = getFileRoot(); | |
| 64 filePath.append(fileName); | |
| 65 | |
| 66 long long fileSize; | |
| 67 if (!getFileSize(filePath, fileSize)) | |
| 68 return 0; | |
| 69 | |
| 70 PlatformFileHandle handle = openFile(filePath, OpenForRead); | |
| 71 int fileLength = static_cast<int>(fileSize); | |
| 72 Vector<char> buffer(fileLength); | |
| 73 readFromFile(handle, buffer.data(), fileLength); | |
| 74 closeFile(handle); | |
| 75 return SharedBuffer::adoptVector(buffer); | |
| 76 } | |
| 77 | |
| 78 | |
|
abarth-chromium
2013/08/07 18:12:27
You've got an extra blank line here.
| |
| 79 static PassRefPtr<MHTMLArchive> loadMHTMLArchive(const char* filename) | |
| 80 { | |
| 81 RefPtr<SharedBuffer> data = readFile(filename); | |
| 82 if (data.get()) { | |
|
abarth-chromium
2013/08/07 18:12:27
There's no need to call .get() here. RefPtr has a
| |
| 83 MHTMLParser parser = MHTMLParser(data.get()); | |
| 84 return parser.parseArchive(); | |
| 85 } | |
| 86 return 0; | |
| 87 } | |
| 88 }; | |
| 89 | |
| 90 | |
| 91 TEST_F(MHTMLTest, 8BitTransferEncoding) | |
| 92 { | |
| 93 RefPtr<MHTMLArchive> archive = loadMHTMLArchive("8bit-transfer-encoding.mhtm l"); | |
|
abarth-chromium
2013/08/07 18:12:27
Rather than writing a unit test for this change, y
| |
| 94 ASSERT_TRUE(archive.get()); | |
| 95 | |
| 96 ArchiveResource* main = archive->mainResource(); | |
| 97 ASSERT_EQ(main->mimeType(), "text/html"); | |
| 98 ASSERT_EQ(main->textEncoding(), "utf-8"); | |
| 99 ASSERT_EQ(archive->subresources().size(), 0u); | |
| 100 } | |
| 101 | |
| 102 } | |
| OLD | NEW |