OLD | NEW |
---|---|
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 Loading... | |
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 WTF::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 WTF::String getSerializedData(const char* url, const char* mimeType = 0) | |
166 { | |
167 const SerializedResource* resource = getResource(url, mimeType); | |
168 if (resource) { | |
169 return WTF::String(resource->data->data()); | |
170 } | |
171 return WTF::String(); | |
abarth-chromium
2013/08/22 17:13:44
No need for WTF::
Also, no need for { and }
| |
156 } | 172 } |
157 | 173 |
158 WebViewImpl* m_webViewImpl; | 174 WebViewImpl* m_webViewImpl; |
159 | 175 |
160 private: | 176 private: |
161 TestWebFrameClient m_webFrameClient; | 177 TestWebFrameClient m_webFrameClient; |
162 WebString m_folder; | 178 WebString m_folder; |
163 KURL m_baseUrl; | 179 KURL m_baseUrl; |
164 Vector<SerializedResource> m_resources; | 180 Vector<SerializedResource> m_resources; |
165 }; | 181 }; |
166 | 182 |
167 | 183 |
168 TEST_F(PageSerializerTest, InputImage) | 184 TEST_F(PageSerializerTest, InputImage) |
169 { | 185 { |
170 setBaseFolder("pageserializer/input-image/"); | 186 setBaseFolder("pageserializer/input-image/"); |
171 | 187 |
172 registerURL("input-image.html", "text/html"); | 188 registerURL("input-image.html", "text/html"); |
173 registerURL("button.png", "image/png"); | 189 registerURL("button.png", "image/png"); |
174 registerErrorURL("non-existing-button.png", 404); | 190 registerErrorURL("non-existing-button.png", 404); |
175 | 191 |
176 serialize("input-image.html"); | 192 serialize("input-image.html"); |
177 | 193 |
178 EXPECT_TRUE(isSerialized("button.png", "image/png")); | 194 EXPECT_TRUE(isSerialized("button.png", "image/png")); |
179 EXPECT_FALSE(isSerialized("non-existing-button.png", "image/png")); | 195 EXPECT_FALSE(isSerialized("non-existing-button.png", "image/png")); |
180 } | 196 } |
181 | 197 |
198 TEST_F(PageSerializerTest, XMLDeclaration) | |
199 { | |
200 setBaseFolder("pageserializer/xmldecl/"); | |
abarth-chromium
2013/08/22 17:13:44
Why do these need separate folders? They seem to
Tiger
2013/08/26 12:39:22
There is no need for them to be in a sub folder. I
| |
201 | |
202 registerURL("xmldecl.xml", "text/xml"); | |
203 serialize("xmldecl.xml"); | |
204 | |
205 WTF::String expectedStart("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); | |
206 EXPECT_TRUE(getSerializedData("xmldecl.xml").startsWith(expectedStart)); | |
182 } | 207 } |
208 | |
209 TEST_F(PageSerializerTest, DTD) | |
210 { | |
211 setBaseFolder("pageserializer/dtd/"); | |
212 | |
213 registerURL("dtd.html", "text/html"); | |
214 serialize("dtd.html"); | |
215 | |
216 WTF::String expectedStart("<!DOCTYPE html>"); | |
abarth-chromium
2013/08/22 17:13:44
No need for WTF::
| |
217 EXPECT_TRUE(getSerializedData("dtd.html").startsWith(expectedStart)); | |
218 } | |
219 | |
220 } | |
OLD | NEW |