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

Side by Side Diff: Source/web/tests/PageSerializerTest.cpp

Issue 22926011: Add doctype declarations when using PageSerializer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Review fixes Created 7 years, 3 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
« no previous file with comments | « Source/core/page/PageSerializer.cpp ('k') | Source/web/tests/data/pageserializer/dtd/dtd.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 136
137 PageSerializer serializer(&m_resources); 137 PageSerializer serializer(&m_resources);
138 serializer.serialize(m_webViewImpl->mainFrameImpl()->frame()->page()); 138 serializer.serialize(m_webViewImpl->mainFrameImpl()->frame()->page());
139 } 139 }
140 140
141 Vector<SerializedResource>& getResources() 141 Vector<SerializedResource>& getResources()
142 { 142 {
143 return m_resources; 143 return m_resources;
144 } 144 }
145 145
146 bool isSerialized(const char* url, const char* mimeType) 146
147 const SerializedResource* getResource(const char* url, const char* mimeType)
147 { 148 {
148 KURL kURL = KURL(m_baseUrl, url); 149 KURL kURL = KURL(m_baseUrl, url);
149 WTF::String mime(mimeType); 150 String mime(mimeType);
150 for (size_t i = 0; i < m_resources.size(); ++i) { 151 for (size_t i = 0; i < m_resources.size(); ++i) {
151 const SerializedResource& resource = m_resources[i]; 152 const SerializedResource& resource = m_resources[i];
152 if (resource.url == kURL && !resource.data->isEmpty() && equalIgnori ngCase(resource.mimeType, mime)) 153 if (resource.url == kURL && !resource.data->isEmpty()
153 return true; 154 && (mime.isNull() || equalIgnoringCase(resource.mimeType, mime)) )
155 return &resource;
154 } 156 }
155 return false; 157 return 0;
158 }
159
160 bool isSerialized(const char* url, const char* mimeType = 0)
161 {
162 return getResource(url, mimeType);
163 }
164
165 String getSerializedData(const char* url, const char* mimeType = 0)
166 {
167 const SerializedResource* resource = getResource(url, mimeType);
168 if (resource)
169 return String(resource->data->data());
170 return String();
156 } 171 }
157 172
158 WebViewImpl* m_webViewImpl; 173 WebViewImpl* m_webViewImpl;
159 174
160 private: 175 private:
161 TestWebFrameClient m_webFrameClient; 176 TestWebFrameClient m_webFrameClient;
162 WebString m_folder; 177 WebString m_folder;
163 KURL m_baseUrl; 178 KURL m_baseUrl;
164 Vector<SerializedResource> m_resources; 179 Vector<SerializedResource> m_resources;
165 }; 180 };
166 181
167 182
168 TEST_F(PageSerializerTest, InputImage) 183 TEST_F(PageSerializerTest, InputImage)
169 { 184 {
170 setBaseFolder("pageserializer/input-image/"); 185 setBaseFolder("pageserializer/input-image/");
171 186
172 registerURL("input-image.html", "text/html"); 187 registerURL("input-image.html", "text/html");
173 registerURL("button.png", "image/png"); 188 registerURL("button.png", "image/png");
174 registerErrorURL("non-existing-button.png", 404); 189 registerErrorURL("non-existing-button.png", 404);
175 190
176 serialize("input-image.html"); 191 serialize("input-image.html");
177 192
178 EXPECT_TRUE(isSerialized("button.png", "image/png")); 193 EXPECT_TRUE(isSerialized("button.png", "image/png"));
179 EXPECT_FALSE(isSerialized("non-existing-button.png", "image/png")); 194 EXPECT_FALSE(isSerialized("non-existing-button.png", "image/png"));
180 } 195 }
181 196
197 TEST_F(PageSerializerTest, XMLDeclaration)
198 {
199 setBaseFolder("pageserializer/xmldecl/");
200
201 registerURL("xmldecl.xml", "text/xml");
202 serialize("xmldecl.xml");
203
204 String expectedStart("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
205 EXPECT_TRUE(getSerializedData("xmldecl.xml").startsWith(expectedStart));
182 } 206 }
207
208 TEST_F(PageSerializerTest, DTD)
209 {
210 setBaseFolder("pageserializer/dtd/");
211
212 registerURL("dtd.html", "text/html");
213 serialize("dtd.html");
214
215 String expectedStart("<!DOCTYPE html>");
216 EXPECT_TRUE(getSerializedData("dtd.html").startsWith(expectedStart));
217 }
218
219 }
OLDNEW
« no previous file with comments | « Source/core/page/PageSerializer.cpp ('k') | Source/web/tests/data/pageserializer/dtd/dtd.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698