browser/base/content/test/general/browser_addKeywordSearch.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/base/content/test/general/browser_addKeywordSearch.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,47 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +function test() {
     1.8 +  waitForExplicitFinish();
     1.9 +
    1.10 +  gBrowser.selectedTab = gBrowser.addTab("http://example.org/browser/browser/base/content/test/general/dummy_page.html");
    1.11 +
    1.12 +  gBrowser.selectedBrowser.addEventListener("load", function runTests() {
    1.13 +    gBrowser.selectedBrowser.removeEventListener("load", runTests, true);
    1.14 +
    1.15 +    let doc = gBrowser.contentDocument;
    1.16 +    let base = doc.createElement("base");
    1.17 +    doc.head.appendChild(base);
    1.18 +
    1.19 +    let check = function (baseURI, fieldName, expected) {
    1.20 +      base.href = baseURI;
    1.21 +
    1.22 +      let form = doc.createElement("form");
    1.23 +      let element = doc.createElement("input");
    1.24 +      element.setAttribute("type", "text");
    1.25 +      element.setAttribute("name", fieldName);
    1.26 +      form.appendChild(element);
    1.27 +      doc.body.appendChild(form);
    1.28 +
    1.29 +      let data = GetSearchFieldBookmarkData(element);
    1.30 +      is(data.spec, expected, "Bookmark spec for search field named " + fieldName + " and baseURI " + baseURI + " incorrect");
    1.31 +
    1.32 +      doc.body.removeChild(form);
    1.33 +    }
    1.34 +
    1.35 +    let testData = [
    1.36 +    /* baseURI, field name, expected */
    1.37 +      [ 'http://example.com/', 'q', 'http://example.com/?q=%s' ],
    1.38 +      [ 'http://example.com/new-path-here/', 'q', 'http://example.com/new-path-here/?q=%s' ],
    1.39 +      [ '', 'q', 'http://example.org/browser/browser/base/content/test/general/dummy_page.html?q=%s' ],
    1.40 +    ]
    1.41 +
    1.42 +    for (let data of testData) {
    1.43 +      check(data[0], data[1], data[2]);
    1.44 +    }
    1.45 +
    1.46 +    // cleanup
    1.47 +    gBrowser.removeCurrentTab();
    1.48 +    finish();
    1.49 +  }, true);
    1.50 +}

mercurial