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

Side by Side Diff: third_party/WebKit/Source/web/tests/FrameSerializerTest.cpp

Issue 2605413002: MHTML generation: discard serialized resources by the measure they are encoded. (Closed)
Patch Set: Created 3 years, 11 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013, Opera Software ASA. All rights reserved. 2 * Copyright (c) 2013, Opera Software ASA. 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 30 matching lines...) Expand all
41 #include "public/platform/WebURLLoaderMockFactory.h" 41 #include "public/platform/WebURLLoaderMockFactory.h"
42 #include "public/platform/WebURLRequest.h" 42 #include "public/platform/WebURLRequest.h"
43 #include "public/platform/WebURLResponse.h" 43 #include "public/platform/WebURLResponse.h"
44 #include "public/web/WebCache.h" 44 #include "public/web/WebCache.h"
45 #include "public/web/WebSettings.h" 45 #include "public/web/WebSettings.h"
46 #include "testing/gtest/include/gtest/gtest.h" 46 #include "testing/gtest/include/gtest/gtest.h"
47 #include "web/WebLocalFrameImpl.h" 47 #include "web/WebLocalFrameImpl.h"
48 #include "web/WebViewImpl.h" 48 #include "web/WebViewImpl.h"
49 #include "web/tests/FrameTestHelpers.h" 49 #include "web/tests/FrameTestHelpers.h"
50 #include "wtf/Assertions.h" 50 #include "wtf/Assertions.h"
51 #include "wtf/Deque.h"
51 #include "wtf/Vector.h" 52 #include "wtf/Vector.h"
52 53
53 using blink::URLTestHelpers::toKURL; 54 using blink::URLTestHelpers::toKURL;
54 using blink::URLTestHelpers::registerMockedURLLoad; 55 using blink::URLTestHelpers::registerMockedURLLoad;
55 56
56 namespace blink { 57 namespace blink {
57 58
58 class FrameSerializerTest : public testing::Test, 59 class FrameSerializerTest : public testing::Test,
59 public FrameSerializer::Delegate { 60 public FrameSerializer::Delegate {
60 public: 61 public:
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 KURL(m_baseUrl, url).getString().utf8().data()); 119 KURL(m_baseUrl, url).getString().utf8().data());
119 FrameSerializer serializer(m_resources, *this); 120 FrameSerializer serializer(m_resources, *this);
120 Frame* frame = m_helper.webView()->mainFrameImpl()->frame(); 121 Frame* frame = m_helper.webView()->mainFrameImpl()->frame();
121 for (; frame; frame = frame->tree().traverseNext()) { 122 for (; frame; frame = frame->tree().traverseNext()) {
122 // This is safe, because tests do not do cross-site navigation 123 // This is safe, because tests do not do cross-site navigation
123 // (and therefore don't have remote frames). 124 // (and therefore don't have remote frames).
124 serializer.serializeFrame(*toLocalFrame(frame)); 125 serializer.serializeFrame(*toLocalFrame(frame));
125 } 126 }
126 } 127 }
127 128
128 Vector<SerializedResource>& getResources() { return m_resources; } 129 Deque<SerializedResource>& getResources() { return m_resources; }
129 130
130 const SerializedResource* getResource(const KURL& url, const char* mimeType) { 131 const SerializedResource* getResource(const KURL& url, const char* mimeType) {
131 String mime(mimeType); 132 String mime(mimeType);
132 for (size_t i = 0; i < m_resources.size(); ++i) { 133 for (const SerializedResource& resource : m_resources) {
133 const SerializedResource& resource = m_resources[i];
134 if (resource.url == url && !resource.data->isEmpty() && 134 if (resource.url == url && !resource.data->isEmpty() &&
135 (mime.isNull() || equalIgnoringASCIICase(resource.mimeType, mime))) 135 (mime.isNull() || equalIgnoringASCIICase(resource.mimeType, mime)))
136 return &resource; 136 return &resource;
137 } 137 }
138 return nullptr; 138 return nullptr;
139 } 139 }
140 140
141 const SerializedResource* getResource(const char* urlString, 141 const SerializedResource* getResource(const char* urlString,
142 const char* mimeType) { 142 const char* mimeType) {
143 const KURL url(m_baseUrl, urlString); 143 const KURL url(m_baseUrl, urlString);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 return true; 183 return true;
184 } 184 }
185 185
186 bool shouldSkipResourceWithURL(const KURL& url) { 186 bool shouldSkipResourceWithURL(const KURL& url) {
187 return m_skipURLs.contains(url); 187 return m_skipURLs.contains(url);
188 } 188 }
189 189
190 FrameTestHelpers::WebViewHelper m_helper; 190 FrameTestHelpers::WebViewHelper m_helper;
191 WebString m_folder; 191 WebString m_folder;
192 KURL m_baseUrl; 192 KURL m_baseUrl;
193 Vector<SerializedResource> m_resources; 193 Deque<SerializedResource> m_resources;
194 HashMap<String, String> m_rewriteURLs; 194 HashMap<String, String> m_rewriteURLs;
195 Vector<String> m_skipURLs; 195 Vector<String> m_skipURLs;
196 String m_rewriteFolder; 196 String m_rewriteFolder;
197 }; 197 };
198 198
199 TEST_F(FrameSerializerTest, HTMLElements) { 199 TEST_F(FrameSerializerTest, HTMLElements) {
200 setBaseFolder("frameserializer/elements/"); 200 setBaseFolder("frameserializer/elements/");
201 201
202 registerURL("elements.html", "text/html"); 202 registerURL("elements.html", "text/html");
203 registerURL("style.css", "style.css", "text/css"); 203 registerURL("style.css", "style.css", "text/css");
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 KURL(ParsedURLString, "http://foo.com?--"))); 553 KURL(ParsedURLString, "http://foo.com?--")));
554 EXPECT_EQ("saved from url=(0020)http://foo.com/#-%2D", 554 EXPECT_EQ("saved from url=(0020)http://foo.com/#-%2D",
555 FrameSerializer::markOfTheWebDeclaration( 555 FrameSerializer::markOfTheWebDeclaration(
556 KURL(ParsedURLString, "http://foo.com#--"))); 556 KURL(ParsedURLString, "http://foo.com#--")));
557 EXPECT_EQ("saved from url=(0026)http://foo.com/#bar-%2Dbaz", 557 EXPECT_EQ("saved from url=(0026)http://foo.com/#bar-%2Dbaz",
558 FrameSerializer::markOfTheWebDeclaration( 558 FrameSerializer::markOfTheWebDeclaration(
559 KURL(ParsedURLString, "http://foo.com#bar--baz"))); 559 KURL(ParsedURLString, "http://foo.com#bar--baz")));
560 } 560 }
561 561
562 } // namespace blink 562 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698