Changeset 99766 in webkit


Ignore:
Timestamp:
Nov 9, 2011, 3:13:59 PM (14 years ago)
Author:
jcivelli@chromium.org
Message:

Fix MHTML generation to use the QuotedPrintable encoding for text resources.
This was regressed when we added binary encoding support.
https://bugs.webkit.org/show_bug.cgi?id=71857

Reviewed by Adam Barth.

Source/WebCore:

  • loader/archive/mhtml/MHTMLArchive.cpp:

(WebCore::MHTMLArchive::generateMHTMLData):

Source/WebKit/chromium:

  • tests/WebPageNewSerializerTest.cpp:

(WebKit::LineReader::LineReader):
(WebKit::LineReader::getNextLine):
(WebKit::WebPageNewSerializeTest::setUpCSSTestPage):
(WebKit::TEST_F):

Location:
trunk/Source
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r99764 r99766  
     12011-11-09  Jay Civelli  <jcivelli@chromium.org>
     2
     3        Fix MHTML generation to use the QuotedPrintable encoding for text resources.
     4        This was regressed when we added binary encoding support.
     5        https://bugs.webkit.org/show_bug.cgi?id=71857
     6
     7        Reviewed by Adam Barth.
     8
     9        * loader/archive/mhtml/MHTMLArchive.cpp:
     10        (WebCore::MHTMLArchive::generateMHTMLData):
     11
    1122011-11-09  Kentaro Hara  <haraken@chromium.org>
    213
  • trunk/Source/WebCore/loader/archive/mhtml/MHTMLArchive.cpp

    r95901 r99766  
    179179        stringBuilder.append(resource.mimeType);
    180180
    181         const char* contentEncoding = useBinaryEncoding ? binary : base64;
     181        const char* contentEncoding = 0;
     182        if (useBinaryEncoding)
     183            contentEncoding = binary;
     184        else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(resource.mimeType) || MIMETypeRegistry::isSupportedNonImageMIMEType(resource.mimeType))
     185            contentEncoding = quotedPrintable;
     186        else
     187            contentEncoding = base64;
     188
    182189        stringBuilder.append("\r\nContent-Transfer-Encoding: ");
    183190        stringBuilder.append(contentEncoding);
  • trunk/Source/WebKit/chromium/ChangeLog

    r99726 r99766  
     12011-11-09  Jay Civelli  <jcivelli@chromium.org>
     2
     3        Fix MHTML generation to use the QuotedPrintable encoding for text resources.
     4        This was regressed when we added binary encoding support.
     5        https://bugs.webkit.org/show_bug.cgi?id=71857
     6
     7        Reviewed by Adam Barth.
     8
     9        * tests/WebPageNewSerializerTest.cpp:
     10        (WebKit::LineReader::LineReader):
     11        (WebKit::LineReader::getNextLine):
     12        (WebKit::WebPageNewSerializeTest::setUpCSSTestPage):
     13        (WebKit::TEST_F):
     14
    1152011-11-09  Henrik Grunell  <grunell@chromium.org>
    216
  • trunk/Source/WebKit/chromium/tests/WebPageNewSerializerTest.cpp

    r99661 r99766  
    5050namespace {
    5151
     52class LineReader {
     53public:
     54    LineReader(const std::string& text) : m_text(text), m_index(0) { }
     55    bool getNextLine(std::string* line)
     56    {
     57        line->clear();
     58        if (m_index >= m_text.length())
     59            return false;
     60
     61        size_t endOfLineIndex = m_text.find("\r\n", m_index);
     62        if (endOfLineIndex == std::string::npos) {
     63            *line = m_text.substr(m_index);
     64            m_index = m_text.length();
     65        } else {
     66            *line = m_text.substr(m_index, endOfLineIndex - m_index);
     67            m_index = endOfLineIndex + 2;
     68        }
     69        return true;
     70    }
     71
     72private:
     73    std::string m_text;
     74    size_t m_index;
     75};
     76
    5277class TestWebFrameClient : public WebFrameClient {
    5378public:
     
    96121        filePath.append(fileName.utf8());
    97122        webkit_support::RegisterMockedURL(url, response, WebString::fromUTF8(filePath));
     123    }
     124
     125    WebURL setUpCSSTestPage()
     126    {
     127        WebURL topFrameURL = GURL("http://www.test.com");
     128        registerMockedURLLoad(topFrameURL, WebString::fromUTF8("css_test_page.html"), htmlMimeType());
     129        registerMockedURLLoad(GURL("http://www.test.com/link_styles.css"), WebString::fromUTF8("link_styles.css"), cssMimeType());
     130        registerMockedURLLoad(GURL("http://www.test.com/import_style_from_link.css"), WebString::fromUTF8("import_style_from_link.css"), cssMimeType());
     131        registerMockedURLLoad(GURL("http://www.test.com/import_styles.css"), WebString::fromUTF8("import_styles.css"), cssMimeType());
     132        registerMockedURLLoad(GURL("http://www.test.com/red_background.png"), WebString::fromUTF8("red_background.png"), pngMimeType());
     133        registerMockedURLLoad(GURL("http://www.test.com/orange_background.png"), WebString::fromUTF8("orange_background.png"), pngMimeType());
     134        registerMockedURLLoad(GURL("http://www.test.com/yellow_background.png"), WebString::fromUTF8("yellow_background.png"), pngMimeType());
     135        registerMockedURLLoad(GURL("http://www.test.com/green_background.png"), WebString::fromUTF8("green_background.png"), pngMimeType());
     136        registerMockedURLLoad(GURL("http://www.test.com/blue_background.png"), WebString::fromUTF8("blue_background.png"), pngMimeType());
     137        registerMockedURLLoad(GURL("http://www.test.com/purple_background.png"), WebString::fromUTF8("purple_background.png"), pngMimeType());
     138        registerMockedURLLoad(GURL("http://www.test.com/ul-dot.png"), WebString::fromUTF8("ul-dot.png"), pngMimeType());
     139        registerMockedURLLoad(GURL("http://www.test.com/ol-dot.png"), WebString::fromUTF8("ol-dot.png"), pngMimeType());
     140        return topFrameURL;
    98141    }
    99142
     
    176219{
    177220    // Register the mocked frame and load it.
    178     WebURL topFrameURL = GURL("http://www.test.com");
    179     registerMockedURLLoad(topFrameURL, WebString::fromUTF8("css_test_page.html"), htmlMimeType());
    180     registerMockedURLLoad(GURL("http://www.test.com/link_styles.css"), WebString::fromUTF8("link_styles.css"), cssMimeType());
    181     registerMockedURLLoad(GURL("http://www.test.com/import_style_from_link.css"), WebString::fromUTF8("import_style_from_link.css"), cssMimeType());
    182     registerMockedURLLoad(GURL("http://www.test.com/import_styles.css"), WebString::fromUTF8("import_styles.css"), cssMimeType());
    183     registerMockedURLLoad(GURL("http://www.test.com/red_background.png"), WebString::fromUTF8("red_background.png"), pngMimeType());
    184     registerMockedURLLoad(GURL("http://www.test.com/orange_background.png"), WebString::fromUTF8("orange_background.png"), pngMimeType());
    185     registerMockedURLLoad(GURL("http://www.test.com/yellow_background.png"), WebString::fromUTF8("yellow_background.png"), pngMimeType());
    186     registerMockedURLLoad(GURL("http://www.test.com/green_background.png"), WebString::fromUTF8("green_background.png"), pngMimeType());
    187     registerMockedURLLoad(GURL("http://www.test.com/blue_background.png"), WebString::fromUTF8("blue_background.png"), pngMimeType());
    188     registerMockedURLLoad(GURL("http://www.test.com/purple_background.png"), WebString::fromUTF8("purple_background.png"), pngMimeType());
    189     registerMockedURLLoad(GURL("http://www.test.com/ul-dot.png"), WebString::fromUTF8("ul-dot.png"), pngMimeType());
    190     registerMockedURLLoad(GURL("http://www.test.com/ol-dot.png"), WebString::fromUTF8("ol-dot.png"), pngMimeType());
    191 
     221    WebURL topFrameURL = setUpCSSTestPage();
    192222    loadURLInTopFrame(topFrameURL);
    193223
     
    271301}
    272302
    273 }
     303TEST_F(WebPageNewSerializeTest, TestMHTMLEncoding)
     304{
     305    // Load a page with some CSS and some images.
     306    WebURL topFrameURL = setUpCSSTestPage();
     307    loadURLInTopFrame(topFrameURL);
     308
     309    WebCString mhtmlData = WebPageSerializer::serializeToMHTML(m_webView);
     310    ASSERT_FALSE(mhtmlData.isEmpty());
     311
     312    // Read the MHTML data line per line and do some pseudo-parsing to make sure the right encoding is used for the different sections.
     313    LineReader lineReader(mhtmlData);
     314    int sectionCheckedCount = 0;
     315    const char* expectedEncoding = 0;
     316    std::string line;
     317    while (lineReader.getNextLine(&line)) {
     318        if (!line.find("Content-Type:")) {
     319            ASSERT_FALSE(expectedEncoding);
     320            if (line.find("multipart/related;") != std::string::npos) {
     321                // Skip this one, it's part of the MHTML header.
     322                continue;
     323            }
     324            if (line.find("text/") != std::string::npos)
     325                expectedEncoding = "quoted-printable";
     326            else if (line.find("image/") != std::string::npos)
     327                expectedEncoding = "base64";
     328            else
     329                FAIL() << "Unexpected Content-Type: " << line;
     330            continue;
     331        }
     332        if (!line.find("Content-Transfer-Encoding:")) {
     333           ASSERT_TRUE(expectedEncoding);
     334           EXPECT_TRUE(line.find(expectedEncoding) != std::string::npos);
     335           expectedEncoding = 0;
     336           sectionCheckedCount++;
     337        }
     338    }
     339    EXPECT_EQ(12, sectionCheckedCount);
     340}
     341
     342}
Note: See TracChangeset for help on using the changeset viewer.