|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 function test() { |
|
5 waitForExplicitFinish(); |
|
6 |
|
7 gBrowser.selectedTab = gBrowser.addTab("http://example.org/browser/browser/base/content/test/general/dummy_page.html"); |
|
8 |
|
9 gBrowser.selectedBrowser.addEventListener("load", function runTests() { |
|
10 gBrowser.selectedBrowser.removeEventListener("load", runTests, true); |
|
11 |
|
12 let doc = gBrowser.contentDocument; |
|
13 let base = doc.createElement("base"); |
|
14 doc.head.appendChild(base); |
|
15 |
|
16 let check = function (baseURI, fieldName, expected) { |
|
17 base.href = baseURI; |
|
18 |
|
19 let form = doc.createElement("form"); |
|
20 let element = doc.createElement("input"); |
|
21 element.setAttribute("type", "text"); |
|
22 element.setAttribute("name", fieldName); |
|
23 form.appendChild(element); |
|
24 doc.body.appendChild(form); |
|
25 |
|
26 let data = GetSearchFieldBookmarkData(element); |
|
27 is(data.spec, expected, "Bookmark spec for search field named " + fieldName + " and baseURI " + baseURI + " incorrect"); |
|
28 |
|
29 doc.body.removeChild(form); |
|
30 } |
|
31 |
|
32 let testData = [ |
|
33 /* baseURI, field name, expected */ |
|
34 [ 'http://example.com/', 'q', 'http://example.com/?q=%s' ], |
|
35 [ 'http://example.com/new-path-here/', 'q', 'http://example.com/new-path-here/?q=%s' ], |
|
36 [ '', 'q', 'http://example.org/browser/browser/base/content/test/general/dummy_page.html?q=%s' ], |
|
37 ] |
|
38 |
|
39 for (let data of testData) { |
|
40 check(data[0], data[1], data[2]); |
|
41 } |
|
42 |
|
43 // cleanup |
|
44 gBrowser.removeCurrentTab(); |
|
45 finish(); |
|
46 }, true); |
|
47 } |