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

Side by Side Diff: third_party/WebKit/LayoutTests/fast/js/resources/image-preload-helper.js

Issue 1363233003: Make sure <url>s are being serialized according to spec (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix interpolation tests Created 5 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 // This is used by several tests to help get images reliably preloaded. 1 // This is used by several tests to help get images reliably preloaded.
2 2
3 // Given a node, loads all urls specified in style declarations 3 // Given a node, loads all urls specified in style declarations
4 // attached to the node or it's decendants. 4 // attached to the node or it's decendants.
5 // imageCount specifies the number of images we expect to find (to try to add so me 5 // imageCount specifies the number of images we expect to find (to try to add so me
6 // protection against brittleness due to imperfect url parsing, since other miss ing a preload 6 // protection against brittleness due to imperfect url parsing, since other miss ing a preload
7 // will typically result in a test that fails only occasionally). 7 // will typically result in a test that fails only occasionally).
8 // If failPattern is specified, then any url that matches the regex 8 // If failPattern is specified, then any url that matches the regex
9 // will be expected to fail to load. 9 // will be expected to fail to load.
10 function preloadImagesFromStyle(rootNode, imageCount, onComplete, failPattern) { 10 function preloadImagesFromStyle(rootNode, imageCount, onComplete, failPattern) {
11 var basePath = location.href.substring(0, location.href.lastIndexOf('/') + 1 ); 11 var basePath = location.href.substring(0, location.href.lastIndexOf('/') + 1 );
12 var nodes = rootNode.querySelectorAll('[style]'); 12 var nodes = rootNode.querySelectorAll('[style]');
13 var imagesToLoad = []; 13 var imagesToLoad = [];
14 var seenUrls = {}; 14 var seenUrls = {};
15 for (var i = 0; i < nodes.length; i++) { 15 for (var i = 0; i < nodes.length; i++) {
16 var urls = nodes[i].style.cssText.split(/url\w*\(([^)]*)\)/); 16 var urls = nodes[i].style.cssText.split(/url\w*\("([^)]*)"\)/);
17 for (var j = 1; j < urls.length; j += 2) { 17 for (var j = 1; j < urls.length; j += 2) {
18 // Attempt to convert URL to a relative path in order to have determ inistic error messages. 18 // Attempt to convert URL to a relative path in order to have determ inistic error messages.
19 var url = urls[j]; 19 var url = urls[j];
20 if (url.indexOf(basePath) == 0) 20 if (url.indexOf(basePath) == 0)
21 url = url.substring(basePath.length); 21 url = url.substring(basePath.length);
22 22
23 var error = false; 23 var error = false;
24 if (failPattern && failPattern.test(url)) 24 if (failPattern && failPattern.test(url))
25 error = true; 25 error = true;
26 if (url in seenUrls) 26 if (url in seenUrls)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 65 }
66 66
67 for (var i = 0; i < imagesToLoad.length; i++) { 67 for (var i = 0; i < imagesToLoad.length; i++) {
68 var img = new Image(); 68 var img = new Image();
69 var expectError = imagesToLoad[i].error; 69 var expectError = imagesToLoad[i].error;
70 img.addEventListener('load', onImageLoad.bind(undefined, imagesToLoad[i] .url, !expectError)); 70 img.addEventListener('load', onImageLoad.bind(undefined, imagesToLoad[i] .url, !expectError));
71 img.addEventListener('error', onImageLoad.bind(undefined, imagesToLoad[i ].url, !!expectError)); 71 img.addEventListener('error', onImageLoad.bind(undefined, imagesToLoad[i ].url, !!expectError));
72 img.src = imagesToLoad[i].url; 72 img.src = imagesToLoad[i].url;
73 } 73 }
74 } 74 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698