Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | var browser; |
michael@0 | 2 | |
michael@0 | 3 | function doc() browser.contentDocument; |
michael@0 | 4 | |
michael@0 | 5 | function setHandlerFunc(aResultFunc) { |
michael@0 | 6 | gBrowser.addEventListener("DOMLinkAdded", function (event) { |
michael@0 | 7 | gBrowser.removeEventListener("DOMLinkAdded", arguments.callee, false); |
michael@0 | 8 | executeSoon(aResultFunc); |
michael@0 | 9 | }, false); |
michael@0 | 10 | } |
michael@0 | 11 | |
michael@0 | 12 | function test() { |
michael@0 | 13 | waitForExplicitFinish(); |
michael@0 | 14 | |
michael@0 | 15 | gBrowser.selectedTab = gBrowser.addTab(); |
michael@0 | 16 | browser = gBrowser.selectedBrowser; |
michael@0 | 17 | browser.addEventListener("load", function (event) { |
michael@0 | 18 | event.currentTarget.removeEventListener("load", arguments.callee, true); |
michael@0 | 19 | iconDiscovery(); |
michael@0 | 20 | }, true); |
michael@0 | 21 | var rootDir = getRootDirectory(gTestPath); |
michael@0 | 22 | content.location = rootDir + "discovery.html"; |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | var iconDiscoveryTests = [ |
michael@0 | 26 | { text: "rel icon discovered" }, |
michael@0 | 27 | { rel: "abcdefg icon qwerty", text: "rel may contain additional rels separated by spaces" }, |
michael@0 | 28 | { rel: "ICON", text: "rel is case insensitive" }, |
michael@0 | 29 | { rel: "shortcut-icon", pass: false, text: "rel shortcut-icon not discovered" }, |
michael@0 | 30 | { href: "moz.png", text: "relative href works" }, |
michael@0 | 31 | { href: "notthere.png", text: "404'd icon is removed properly" }, |
michael@0 | 32 | { href: "data:image/x-icon,%00", type: "image/x-icon", text: "data: URIs work" }, |
michael@0 | 33 | { type: "image/png; charset=utf-8", text: "type may have optional parameters (RFC2046)" } |
michael@0 | 34 | ]; |
michael@0 | 35 | |
michael@0 | 36 | function runIconDiscoveryTest() { |
michael@0 | 37 | var test = iconDiscoveryTests[0]; |
michael@0 | 38 | var head = doc().getElementById("linkparent"); |
michael@0 | 39 | var hasSrc = gBrowser.getIcon() != null; |
michael@0 | 40 | if (test.pass) |
michael@0 | 41 | ok(hasSrc, test.text); |
michael@0 | 42 | else |
michael@0 | 43 | ok(!hasSrc, test.text); |
michael@0 | 44 | |
michael@0 | 45 | head.removeChild(head.getElementsByTagName('link')[0]); |
michael@0 | 46 | iconDiscoveryTests.shift(); |
michael@0 | 47 | iconDiscovery(); // Run the next test. |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | function iconDiscovery() { |
michael@0 | 51 | if (iconDiscoveryTests.length) { |
michael@0 | 52 | setHandlerFunc(runIconDiscoveryTest); |
michael@0 | 53 | gBrowser.setIcon(gBrowser.selectedTab, null); |
michael@0 | 54 | |
michael@0 | 55 | var test = iconDiscoveryTests[0]; |
michael@0 | 56 | var head = doc().getElementById("linkparent"); |
michael@0 | 57 | var link = doc().createElement("link"); |
michael@0 | 58 | |
michael@0 | 59 | var rootDir = getRootDirectory(gTestPath); |
michael@0 | 60 | var rel = test.rel || "icon"; |
michael@0 | 61 | var href = test.href || rootDir + "moz.png"; |
michael@0 | 62 | var type = test.type || "image/png"; |
michael@0 | 63 | if (test.pass == undefined) |
michael@0 | 64 | test.pass = true; |
michael@0 | 65 | |
michael@0 | 66 | link.rel = rel; |
michael@0 | 67 | link.href = href; |
michael@0 | 68 | link.type = type; |
michael@0 | 69 | head.appendChild(link); |
michael@0 | 70 | } else { |
michael@0 | 71 | searchDiscovery(); |
michael@0 | 72 | } |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | var searchDiscoveryTests = [ |
michael@0 | 76 | { text: "rel search discovered" }, |
michael@0 | 77 | { rel: "SEARCH", text: "rel is case insensitive" }, |
michael@0 | 78 | { rel: "-search-", pass: false, text: "rel -search- not discovered" }, |
michael@0 | 79 | { rel: "foo bar baz search quux", text: "rel may contain additional rels separated by spaces" }, |
michael@0 | 80 | { href: "https://not.mozilla.com", text: "HTTPS ok" }, |
michael@0 | 81 | { href: "ftp://not.mozilla.com", text: "FTP ok" }, |
michael@0 | 82 | { href: "data:text/foo,foo", pass: false, text: "data URI not permitted" }, |
michael@0 | 83 | { href: "javascript:alert(0)", pass: false, text: "JS URI not permitted" }, |
michael@0 | 84 | { type: "APPLICATION/OPENSEARCHDESCRIPTION+XML", text: "type is case insensitve" }, |
michael@0 | 85 | { type: " application/opensearchdescription+xml ", text: "type may contain extra whitespace" }, |
michael@0 | 86 | { type: "application/opensearchdescription+xml; charset=utf-8", text: "type may have optional parameters (RFC2046)" }, |
michael@0 | 87 | { type: "aapplication/opensearchdescription+xml", pass: false, text: "type should not be loosely matched" }, |
michael@0 | 88 | { rel: "search search search", count: 1, text: "only one engine should be added" } |
michael@0 | 89 | ]; |
michael@0 | 90 | |
michael@0 | 91 | function runSearchDiscoveryTest() { |
michael@0 | 92 | var test = searchDiscoveryTests[0]; |
michael@0 | 93 | var title = test.title || searchDiscoveryTests.length; |
michael@0 | 94 | if (browser.engines) { |
michael@0 | 95 | var hasEngine = (test.count) ? (browser.engines[0].title == title && |
michael@0 | 96 | browser.engines.length == test.count) : |
michael@0 | 97 | (browser.engines[0].title == title); |
michael@0 | 98 | ok(hasEngine, test.text); |
michael@0 | 99 | browser.engines = null; |
michael@0 | 100 | } |
michael@0 | 101 | else |
michael@0 | 102 | ok(!test.pass, test.text); |
michael@0 | 103 | |
michael@0 | 104 | searchDiscoveryTests.shift(); |
michael@0 | 105 | searchDiscovery(); // Run the next test. |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | // This handler is called twice, once for each added link element. |
michael@0 | 109 | // Only want to check once the second link element has been added. |
michael@0 | 110 | var ranOnce = false; |
michael@0 | 111 | function runMultipleEnginesTestAndFinalize() { |
michael@0 | 112 | if (!ranOnce) { |
michael@0 | 113 | ranOnce = true; |
michael@0 | 114 | return; |
michael@0 | 115 | } |
michael@0 | 116 | ok(browser.engines, "has engines"); |
michael@0 | 117 | is(browser.engines.length, 1, "only one engine"); |
michael@0 | 118 | is(browser.engines[0].uri, "http://first.mozilla.com/search.xml", "first engine wins"); |
michael@0 | 119 | |
michael@0 | 120 | gBrowser.removeCurrentTab(); |
michael@0 | 121 | finish(); |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | function searchDiscovery() { |
michael@0 | 125 | var head = doc().getElementById("linkparent"); |
michael@0 | 126 | |
michael@0 | 127 | if (searchDiscoveryTests.length) { |
michael@0 | 128 | setHandlerFunc(runSearchDiscoveryTest); |
michael@0 | 129 | var test = searchDiscoveryTests[0]; |
michael@0 | 130 | var link = doc().createElement("link"); |
michael@0 | 131 | |
michael@0 | 132 | var rel = test.rel || "search"; |
michael@0 | 133 | var href = test.href || "http://so.not.here.mozilla.com/search.xml"; |
michael@0 | 134 | var type = test.type || "application/opensearchdescription+xml"; |
michael@0 | 135 | var title = test.title || searchDiscoveryTests.length; |
michael@0 | 136 | if (test.pass == undefined) |
michael@0 | 137 | test.pass = true; |
michael@0 | 138 | |
michael@0 | 139 | link.rel = rel; |
michael@0 | 140 | link.href = href; |
michael@0 | 141 | link.type = type; |
michael@0 | 142 | link.title = title; |
michael@0 | 143 | head.appendChild(link); |
michael@0 | 144 | } else { |
michael@0 | 145 | setHandlerFunc(runMultipleEnginesTestAndFinalize); |
michael@0 | 146 | setHandlerFunc(runMultipleEnginesTestAndFinalize); |
michael@0 | 147 | // Test multiple engines with the same title |
michael@0 | 148 | var link = doc().createElement("link"); |
michael@0 | 149 | link.rel = "search"; |
michael@0 | 150 | link.href = "http://first.mozilla.com/search.xml"; |
michael@0 | 151 | link.type = "application/opensearchdescription+xml"; |
michael@0 | 152 | link.title = "Test Engine"; |
michael@0 | 153 | var link2 = link.cloneNode(false); |
michael@0 | 154 | link2.href = "http://second.mozilla.com/search.xml"; |
michael@0 | 155 | |
michael@0 | 156 | head.appendChild(link); |
michael@0 | 157 | head.appendChild(link2); |
michael@0 | 158 | } |
michael@0 | 159 | } |