summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/dom/icon-url-list.html
blob: 2e95d7b6127c4c825548087382e4ad2f4c19c149 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<html>
<head>
<title>Original Title</title>
<link rel="shortcut icon" type="image/x-icon" href="http://test.com/oldfavicon.ico"/>
<link rel="shortcut icon" type="image/x-icon" href="http://test.com/foofavicon.ico"/>
<link rel="shortcut icon" type="image/x-icon" href="http://test.com/barfavicon.ico"/>
<script src="../../resources/js-test.js"></script>
<script>

function setFavIcon(iconURL) {
    var docHead = document.getElementsByTagName("head")[0];

    // set up a new node for the new iconURL
    var newLink = document.createElement("link");
    newLink.type = "image/x-icon";
    newLink.rel = "shortcut icon";
    newLink.href = iconURL;

    var links = docHead.getElementsByTagName("link");
    for (var i = 0; i < links.length; ++i) {
        var oldLink = links[i];
        if (oldLink.type=="image/x-icon" && oldLink.rel=="shortcut icon") {
          // if we find the child, replace it with the new node.
          docHead.replaceChild(newLink, oldLink);
          return; // Assuming only one match at most.
        }
    }

    // if we didn't find the icon URL link, add it now.
    docHead.appendChild(newLink);
}

function runTests() {
    if (window.testRunner)
        testRunner.dumpAsText();

    iconURL = document.getElementsByTagName("link")[0].href;
    debug('Original iconURL is: ' + iconURL);

    // change icon to new icon
    newURL = 'http://test.com/newfavicon.ico';
    debug('Setting new icon URL to: ' + newURL);
    setFavIcon(newURL);
    iconURL = document.getElementsByTagName("link")[0].href
    debug('New iconURL is: ' + iconURL);

    // check that the URL list in the document is as we expect
    var expectedURL0 = "http://test.com/barfavicon.ico";
    var expectedURL1 = "http://test.com/foofavicon.ico";
    var expectedURL2 = "http://test.com/newfavicon.ico";
    var iconURLs = window.internals.shortcutIconURLs(document);
    if (expectedURL0 == iconURLs[0] && expectedURL1 == iconURLs[1] && expectedURL2 == iconURLs[2]) 
        testPassed('URL list matches expected');
    else
        testFailed('URL list does not match expected');
}

</script>
</head>
<body onload='runTests();'>
</div>
</body>
</html>