| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "public/platform/WebURL.h" | 44 #include "public/platform/WebURL.h" |
| 45 #include "public/platform/WebURLRequest.h" | 45 #include "public/platform/WebURLRequest.h" |
| 46 #include "public/platform/WebURLResponse.h" | 46 #include "public/platform/WebURLResponse.h" |
| 47 #include "public/platform/WebUnitTestSupport.h" | 47 #include "public/platform/WebUnitTestSupport.h" |
| 48 #include "public/web/WebDocument.h" | 48 #include "public/web/WebDocument.h" |
| 49 #include "public/web/WebFrame.h" | 49 #include "public/web/WebFrame.h" |
| 50 #include "public/web/WebView.h" | 50 #include "public/web/WebView.h" |
| 51 #include "web/tests/FrameTestHelpers.h" | 51 #include "web/tests/FrameTestHelpers.h" |
| 52 #include <gtest/gtest.h> | 52 #include <gtest/gtest.h> |
| 53 | 53 |
| 54 using namespace blink; | |
| 55 | |
| 56 using blink::URLTestHelpers::toKURL; | 54 using blink::URLTestHelpers::toKURL; |
| 57 | 55 |
| 58 namespace { | 56 namespace blink { |
| 59 | 57 |
| 60 class LineReader { | 58 class LineReader { |
| 61 public: | 59 public: |
| 62 LineReader(const std::string& text) : m_text(text), m_index(0) { } | 60 LineReader(const std::string& text) : m_text(text), m_index(0) { } |
| 63 bool getNextLine(std::string* line) | 61 bool getNextLine(std::string* line) |
| 64 { | 62 { |
| 65 line->clear(); | 63 line->clear(); |
| 66 if (m_index >= m_text.length()) | 64 if (m_index >= m_text.length()) |
| 67 return false; | 65 return false; |
| 68 | 66 |
| 69 size_t endOfLineIndex = m_text.find("\r\n", m_index); | 67 size_t endOfLineIndex = m_text.find("\r\n", m_index); |
| 70 if (endOfLineIndex == std::string::npos) { | 68 if (endOfLineIndex == std::string::npos) { |
| 71 *line = m_text.substr(m_index); | 69 *line = m_text.substr(m_index); |
| 72 m_index = m_text.length(); | 70 m_index = m_text.length(); |
| 73 return true; | 71 return true; |
| 74 } | 72 } |
| 75 | 73 |
| 76 *line = m_text.substr(m_index, endOfLineIndex - m_index); | 74 *line = m_text.substr(m_index, endOfLineIndex - m_index); |
| 77 m_index = endOfLineIndex + 2; | 75 m_index = endOfLineIndex + 2; |
| 78 return true; | 76 return true; |
| 79 } | 77 } |
| 80 | 78 |
| 81 private: | 79 private: |
| 82 std::string m_text; | 80 std::string m_text; |
| 83 size_t m_index; | 81 size_t m_index; |
| 84 }; | 82 }; |
| 85 | 83 |
| 86 using blink::URLTestHelpers::toKURL; | |
| 87 using namespace blink; | |
| 88 | |
| 89 class MHTMLTest : public testing::Test { | 84 class MHTMLTest : public testing::Test { |
| 90 public: | 85 public: |
| 91 MHTMLTest() | 86 MHTMLTest() |
| 92 { | 87 { |
| 93 m_filePath = Platform::current()->unitTestSupport()->webKitRootDir(); | 88 m_filePath = Platform::current()->unitTestSupport()->webKitRootDir(); |
| 94 m_filePath.append("/Source/web/tests/data/mhtml/"); | 89 m_filePath.append("/Source/web/tests/data/mhtml/"); |
| 95 } | 90 } |
| 96 | 91 |
| 97 protected: | 92 protected: |
| 98 virtual void SetUp() | 93 void SetUp() override |
| 99 { | 94 { |
| 100 m_helper.initialize(); | 95 m_helper.initialize(); |
| 101 } | 96 } |
| 102 | 97 |
| 103 virtual void TearDown() | 98 void TearDown() override |
| 104 { | 99 { |
| 105 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | 100 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); |
| 106 } | 101 } |
| 107 | 102 |
| 108 void registerMockedURLLoad(const std::string& url, const WebString& fileName
) | 103 void registerMockedURLLoad(const std::string& url, const WebString& fileName
) |
| 109 { | 104 { |
| 110 URLTestHelpers::registerMockedURLLoad(toKURL(url), fileName, WebString::
fromUTF8("mhtml/"), WebString::fromUTF8("text/html")); | 105 URLTestHelpers::registerMockedURLLoad(toKURL(url), fileName, WebString::
fromUTF8("mhtml/"), WebString::fromUTF8("text/html")); |
| 111 } | 106 } |
| 112 | 107 |
| 113 void loadURLInTopFrame(const WebURL& url) | 108 void loadURLInTopFrame(const WebURL& url) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 143 addResource("http://www.test.com/purple_background.png", "image/png", "p
urple_background.png"); | 138 addResource("http://www.test.com/purple_background.png", "image/png", "p
urple_background.png"); |
| 144 addResource("http://www.test.com/ul-dot.png", "image/png", "ul-dot.png")
; | 139 addResource("http://www.test.com/ul-dot.png", "image/png", "ul-dot.png")
; |
| 145 addResource("http://www.test.com/ol-dot.png", "image/png", "ol-dot.png")
; | 140 addResource("http://www.test.com/ol-dot.png", "image/png", "ol-dot.png")
; |
| 146 } | 141 } |
| 147 | 142 |
| 148 PassRefPtr<SharedBuffer> serialize(const char *title, const char *mime, MHT
MLArchive::EncodingPolicy encodingPolicy) | 143 PassRefPtr<SharedBuffer> serialize(const char *title, const char *mime, MHT
MLArchive::EncodingPolicy encodingPolicy) |
| 149 { | 144 { |
| 150 return MHTMLArchive::generateMHTMLData(m_resources, encodingPolicy, titl
e, mime); | 145 return MHTMLArchive::generateMHTMLData(m_resources, encodingPolicy, titl
e, mime); |
| 151 } | 146 } |
| 152 | 147 |
| 153 | |
| 154 | |
| 155 private: | 148 private: |
| 156 PassRefPtr<SharedBuffer> readFile(const char* fileName) | 149 PassRefPtr<SharedBuffer> readFile(const char* fileName) |
| 157 { | 150 { |
| 158 String filePath = m_filePath + fileName; | 151 String filePath = m_filePath + fileName; |
| 159 return Platform::current()->unitTestSupport()->readFromFile(filePath); | 152 return Platform::current()->unitTestSupport()->readFromFile(filePath); |
| 160 } | 153 } |
| 161 | 154 |
| 162 String m_filePath; | 155 String m_filePath; |
| 163 Vector<SerializedResource> m_resources; | 156 Vector<SerializedResource> m_resources; |
| 164 FrameTestHelpers::WebViewHelper m_helper; | 157 FrameTestHelpers::WebViewHelper m_helper; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 } | 206 } |
| 214 if (line.compare(0, 26, "Content-Transfer-Encoding:") == 0) { | 207 if (line.compare(0, 26, "Content-Transfer-Encoding:") == 0) { |
| 215 ASSERT_TRUE(expectedEncoding); | 208 ASSERT_TRUE(expectedEncoding); |
| 216 EXPECT_NE(line.find(expectedEncoding), std::string::npos); | 209 EXPECT_NE(line.find(expectedEncoding), std::string::npos); |
| 217 expectedEncoding = 0; | 210 expectedEncoding = 0; |
| 218 sectionCheckedCount++; | 211 sectionCheckedCount++; |
| 219 } | 212 } |
| 220 } | 213 } |
| 221 EXPECT_EQ(12, sectionCheckedCount); | 214 EXPECT_EQ(12, sectionCheckedCount); |
| 222 } | 215 } |
| 223 } | 216 |
| 217 } // namespace blink |
| OLD | NEW |