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

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

Issue 2410693002: Add a few more edge cases to CSS serialization test. (Closed)
Patch Set: Adds image link to data URL CSS contents. Created 4 years, 2 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); 72 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs();
73 WebCache::clear(); 73 WebCache::clear();
74 } 74 }
75 75
76 void setBaseFolder(const char* folder) { 76 void setBaseFolder(const char* folder) {
77 m_folder = WebString::fromUTF8(folder); 77 m_folder = WebString::fromUTF8(folder);
78 } 78 }
79 79
80 void setRewriteURLFolder(const char* folder) { m_rewriteFolder = folder; } 80 void setRewriteURLFolder(const char* folder) { m_rewriteFolder = folder; }
81 81
82 void registerURL(const KURL& url, const char* file, const char* mimeType) {
83 registerMockedURLLoad(url, WebString::fromUTF8(file), m_folder,
84 WebString::fromUTF8(mimeType));
85 }
86
82 void registerURL(const char* url, const char* file, const char* mimeType) { 87 void registerURL(const char* url, const char* file, const char* mimeType) {
83 registerMockedURLLoad(KURL(m_baseUrl, url), WebString::fromUTF8(file), 88 registerURL(KURL(m_baseUrl, url), file, mimeType);
84 m_folder, WebString::fromUTF8(mimeType));
85 } 89 }
86 90
87 void registerURL(const char* file, const char* mimeType) { 91 void registerURL(const char* file, const char* mimeType) {
88 registerURL(file, file, mimeType); 92 registerURL(file, file, mimeType);
89 } 93 }
90 94
91 void registerErrorURL(const char* file, int statusCode) { 95 void registerErrorURL(const char* file, int statusCode) {
92 WebURLError error; 96 WebURLError error;
93 error.reason = 0xdead + statusCode; 97 error.reason = 0xdead + statusCode;
94 error.domain = "FrameSerializerTest"; 98 error.domain = "FrameSerializerTest";
95 99
96 WebURLResponse response; 100 WebURLResponse response;
97 response.setMIMEType("text/html"); 101 response.setMIMEType("text/html");
98 response.setHTTPStatusCode(statusCode); 102 response.setHTTPStatusCode(statusCode);
99 103
100 Platform::current()->getURLLoaderMockFactory()->registerErrorURL( 104 Platform::current()->getURLLoaderMockFactory()->registerErrorURL(
101 KURL(m_baseUrl, file), response, error); 105 KURL(m_baseUrl, file), response, error);
102 } 106 }
103 107
104 void registerRewriteURL(const char* fromURL, const char* toURL) { 108 void registerRewriteURL(const char* fromURL, const char* toURL) {
105 m_rewriteURLs.add(fromURL, toURL); 109 m_rewriteURLs.add(fromURL, toURL);
106 } 110 }
107 111
112 void registerSkipURL(const char* url) {
113 m_skipURLs.append(KURL(m_baseUrl, url));
114 }
115
108 void serialize(const char* url) { 116 void serialize(const char* url) {
109 FrameTestHelpers::loadFrame(m_helper.webView()->mainFrame(), 117 FrameTestHelpers::loadFrame(m_helper.webView()->mainFrame(),
110 KURL(m_baseUrl, url).getString().utf8().data()); 118 KURL(m_baseUrl, url).getString().utf8().data());
111 FrameSerializer serializer(m_resources, *this); 119 FrameSerializer serializer(m_resources, *this);
112 Frame* frame = m_helper.webView()->mainFrameImpl()->frame(); 120 Frame* frame = m_helper.webView()->mainFrameImpl()->frame();
113 for (; frame; frame = frame->tree().traverseNext()) { 121 for (; frame; frame = frame->tree().traverseNext()) {
114 // This is safe, because tests do not do cross-site navigation 122 // This is safe, because tests do not do cross-site navigation
115 // (and therefore don't have remote frames). 123 // (and therefore don't have remote frames).
116 serializer.serializeFrame(*toLocalFrame(frame)); 124 serializer.serializeFrame(*toLocalFrame(frame));
117 } 125 }
118 } 126 }
119 127
120 Vector<SerializedResource>& getResources() { return m_resources; } 128 Vector<SerializedResource>& getResources() { return m_resources; }
121 129
122 const SerializedResource* getResource(const char* urlString, 130 const SerializedResource* getResource(const KURL& url, const char* mimeType) {
123 const char* mimeType) {
124 const KURL url(m_baseUrl, urlString);
125 String mime(mimeType); 131 String mime(mimeType);
126 for (size_t i = 0; i < m_resources.size(); ++i) { 132 for (size_t i = 0; i < m_resources.size(); ++i) {
127 const SerializedResource& resource = m_resources[i]; 133 const SerializedResource& resource = m_resources[i];
128 if (resource.url == url && !resource.data->isEmpty() && 134 if (resource.url == url && !resource.data->isEmpty() &&
129 (mime.isNull() || equalIgnoringASCIICase(resource.mimeType, mime))) 135 (mime.isNull() || equalIgnoringASCIICase(resource.mimeType, mime)))
130 return &resource; 136 return &resource;
131 } 137 }
132 return nullptr; 138 return nullptr;
133 } 139 }
134 140
141 const SerializedResource* getResource(const char* urlString,
142 const char* mimeType) {
143 const KURL url(m_baseUrl, urlString);
144 return getResource(url, mimeType);
145 }
146
135 bool isSerialized(const char* url, const char* mimeType = 0) { 147 bool isSerialized(const char* url, const char* mimeType = 0) {
136 return getResource(url, mimeType); 148 return getResource(url, mimeType);
137 } 149 }
138 150
139 String getSerializedData(const char* url, const char* mimeType = 0) { 151 String getSerializedData(const char* url, const char* mimeType = 0) {
140 const SerializedResource* resource = getResource(url, mimeType); 152 const SerializedResource* resource = getResource(url, mimeType);
141 if (resource) 153 if (resource)
142 return String(resource->data->data(), resource->data->size()); 154 return String(resource->data->data(), resource->data->size());
143 return String(); 155 return String();
144 } 156 }
(...skipping 19 matching lines...) Expand all
164 return false; 176 return false;
165 177
166 StringBuilder uriBuilder; 178 StringBuilder uriBuilder;
167 uriBuilder.append(m_rewriteFolder); 179 uriBuilder.append(m_rewriteFolder);
168 uriBuilder.append('/'); 180 uriBuilder.append('/');
169 uriBuilder.append(m_rewriteURLs.get(completeURL)); 181 uriBuilder.append(m_rewriteURLs.get(completeURL));
170 rewrittenLink = uriBuilder.toString(); 182 rewrittenLink = uriBuilder.toString();
171 return true; 183 return true;
172 } 184 }
173 185
186 bool shouldSkipResourceWithURL(const KURL& url) {
187 return m_skipURLs.contains(url);
188 }
189
174 FrameTestHelpers::WebViewHelper m_helper; 190 FrameTestHelpers::WebViewHelper m_helper;
175 WebString m_folder; 191 WebString m_folder;
176 KURL m_baseUrl; 192 KURL m_baseUrl;
177 Vector<SerializedResource> m_resources; 193 Vector<SerializedResource> m_resources;
178 HashMap<String, String> m_rewriteURLs; 194 HashMap<String, String> m_rewriteURLs;
195 Vector<String> m_skipURLs;
179 String m_rewriteFolder; 196 String m_rewriteFolder;
180 }; 197 };
181 198
182 TEST_F(FrameSerializerTest, HTMLElements) { 199 TEST_F(FrameSerializerTest, HTMLElements) {
183 setBaseFolder("frameserializer/elements/"); 200 setBaseFolder("frameserializer/elements/");
184 201
185 registerURL("elements.html", "text/html"); 202 registerURL("elements.html", "text/html");
186 registerURL("style.css", "style.css", "text/css"); 203 registerURL("style.css", "style.css", "text/css");
187 registerURL("copyright.html", "empty.txt", "text/html"); 204 registerURL("copyright.html", "empty.txt", "text/html");
188 registerURL("script.js", "empty.txt", "text/javascript"); 205 registerURL("script.js", "empty.txt", "text/javascript");
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 registerURL("orange_background.png", "image.png", "image/png"); 346 registerURL("orange_background.png", "image.png", "image/png");
330 registerURL("yellow_background.png", "image.png", "image/png"); 347 registerURL("yellow_background.png", "image.png", "image/png");
331 registerURL("green_background.png", "image.png", "image/png"); 348 registerURL("green_background.png", "image.png", "image/png");
332 registerURL("blue_background.png", "image.png", "image/png"); 349 registerURL("blue_background.png", "image.png", "image/png");
333 registerURL("purple_background.png", "image.png", "image/png"); 350 registerURL("purple_background.png", "image.png", "image/png");
334 registerURL("pink_background.png", "image.png", "image/png"); 351 registerURL("pink_background.png", "image.png", "image/png");
335 registerURL("brown_background.png", "image.png", "image/png"); 352 registerURL("brown_background.png", "image.png", "image/png");
336 registerURL("ul-dot.png", "image.png", "image/png"); 353 registerURL("ul-dot.png", "image.png", "image/png");
337 registerURL("ol-dot.png", "image.png", "image/png"); 354 registerURL("ol-dot.png", "image.png", "image/png");
338 355
356 const KURL imageUrlFromDataUrl(toKURL("http://www.dataurl.com"),
357 "fuchsia_background.png");
358 registerURL(imageUrlFromDataUrl, "image.png", "image/png");
359
360 registerURL("included_in_another_frame.css", "text/css");
361 registerSkipURL("included_in_another_frame.css");
362
339 serialize("css_test_page.html"); 363 serialize("css_test_page.html");
340 364
341 EXPECT_EQ(15U, getResources().size()); 365 EXPECT_EQ(16U, getResources().size());
342 366
343 EXPECT_FALSE(isSerialized("do_not_serialize.png", "image/png")); 367 EXPECT_FALSE(isSerialized("do_not_serialize.png", "image/png"));
368 EXPECT_FALSE(isSerialized("included_in_another_frame.css", "text/css"));
344 369
345 EXPECT_TRUE(isSerialized("css_test_page.html", "text/html")); 370 EXPECT_TRUE(isSerialized("css_test_page.html", "text/html"));
346 EXPECT_TRUE(isSerialized("link_styles.css", "text/css")); 371 EXPECT_TRUE(isSerialized("link_styles.css", "text/css"));
347 EXPECT_TRUE(isSerialized("encoding.css", "text/css")); 372 EXPECT_TRUE(isSerialized("encoding.css", "text/css"));
348 EXPECT_TRUE(isSerialized("import_styles.css", "text/css")); 373 EXPECT_TRUE(isSerialized("import_styles.css", "text/css"));
349 EXPECT_TRUE(isSerialized("import_style_from_link.css", "text/css")); 374 EXPECT_TRUE(isSerialized("import_style_from_link.css", "text/css"));
350 EXPECT_TRUE(isSerialized("red_background.png", "image/png")); 375 EXPECT_TRUE(isSerialized("red_background.png", "image/png"));
351 EXPECT_TRUE(isSerialized("orange_background.png", "image/png")); 376 EXPECT_TRUE(isSerialized("orange_background.png", "image/png"));
352 EXPECT_TRUE(isSerialized("yellow_background.png", "image/png")); 377 EXPECT_TRUE(isSerialized("yellow_background.png", "image/png"));
353 EXPECT_TRUE(isSerialized("green_background.png", "image/png")); 378 EXPECT_TRUE(isSerialized("green_background.png", "image/png"));
354 EXPECT_TRUE(isSerialized("blue_background.png", "image/png")); 379 EXPECT_TRUE(isSerialized("blue_background.png", "image/png"));
355 EXPECT_TRUE(isSerialized("purple_background.png", "image/png")); 380 EXPECT_TRUE(isSerialized("purple_background.png", "image/png"));
356 EXPECT_TRUE(isSerialized("pink_background.png", "image/png")); 381 EXPECT_TRUE(isSerialized("pink_background.png", "image/png"));
357 EXPECT_TRUE(isSerialized("brown_background.png", "image/png")); 382 EXPECT_TRUE(isSerialized("brown_background.png", "image/png"));
358 EXPECT_TRUE(isSerialized("ul-dot.png", "image/png")); 383 EXPECT_TRUE(isSerialized("ul-dot.png", "image/png"));
359 EXPECT_TRUE(isSerialized("ol-dot.png", "image/png")); 384 EXPECT_TRUE(isSerialized("ol-dot.png", "image/png"));
360 385
386 EXPECT_TRUE(getResource(imageUrlFromDataUrl, "image/png"));
387
361 // Ensure encodings are specified. 388 // Ensure encodings are specified.
362 EXPECT_TRUE( 389 EXPECT_TRUE(
363 getSerializedData("link_styles.css", "text/css").startsWith("@charset")); 390 getSerializedData("link_styles.css", "text/css").startsWith("@charset"));
364 EXPECT_TRUE(getSerializedData("import_styles.css", "text/css") 391 EXPECT_TRUE(getSerializedData("import_styles.css", "text/css")
365 .startsWith("@charset")); 392 .startsWith("@charset"));
366 EXPECT_TRUE(getSerializedData("import_style_from_link.css", "text/css") 393 EXPECT_TRUE(getSerializedData("import_style_from_link.css", "text/css")
367 .startsWith("@charset")); 394 .startsWith("@charset"));
368 EXPECT_TRUE(getSerializedData("encoding.css", "text/css") 395 EXPECT_TRUE(getSerializedData("encoding.css", "text/css")
369 .startsWith("@charset \"euc-kr\";")); 396 .startsWith("@charset \"euc-kr\";"));
370 397
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 KURL(ParsedURLString, "http://foo.com?--"))); 553 KURL(ParsedURLString, "http://foo.com?--")));
527 EXPECT_EQ("saved from url=(0020)http://foo.com/#-%2D", 554 EXPECT_EQ("saved from url=(0020)http://foo.com/#-%2D",
528 FrameSerializer::markOfTheWebDeclaration( 555 FrameSerializer::markOfTheWebDeclaration(
529 KURL(ParsedURLString, "http://foo.com#--"))); 556 KURL(ParsedURLString, "http://foo.com#--")));
530 EXPECT_EQ("saved from url=(0026)http://foo.com/#bar-%2Dbaz", 557 EXPECT_EQ("saved from url=(0026)http://foo.com/#bar-%2Dbaz",
531 FrameSerializer::markOfTheWebDeclaration( 558 FrameSerializer::markOfTheWebDeclaration(
532 KURL(ParsedURLString, "http://foo.com#bar--baz"))); 559 KURL(ParsedURLString, "http://foo.com#bar--baz")));
533 } 560 }
534 561
535 } // namespace blink 562 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698