summaryrefslogtreecommitdiffstats
path: root/browser/components/urlbar/tests/browser/browser_keywordSearch_postData.js
blob: d2b3aa253a7f2ca44bda3a21400e7c98fa6d7445 (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
64
65
66
67
68
69
70
71
72
73
74
/**
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

var gTests = [
  {
    name: "single word search (search service)",
    text: "pizza",
    expectText: "pizza",
  },
  {
    name: "multi word search (search service)",
    text: "test search",
    expectText: "test+search",
  },
  {
    name: "?-prefixed search (search service)",
    text: "?   foo  ",
    expectText: "foo",
  },
];

add_setup(async function () {
  await SearchTestUtils.promiseNewSearchEngine({
    url: getRootDirectory(gTestPath) + "POSTSearchEngine.xml",
    setAsDefault: true,
  });
});

add_task(async function () {
  // Test both directly setting a value and pressing enter, or setting the
  // value through input events, like the user would do.
  const setValueFns = [
    value => {
      gURLBar.value = value;
    },
    value => {
      return UrlbarTestUtils.promiseAutocompleteResultPopup({
        window,
        value,
      });
    },
  ];

  for (let test of gTests) {
    info("Testing: " + test.name);
    await BrowserTestUtils.withNewTab({ gBrowser }, async browser => {
      for (let setValueFn of setValueFns) {
        gURLBar.select();
        await setValueFn(test.text);
        EventUtils.synthesizeKey("KEY_Enter");

        await BrowserTestUtils.browserLoaded(
          browser,
          false,
          "http://mochi.test:8888/browser/browser/components/urlbar/tests/browser/print_postdata.sjs"
        );

        let textContent = await SpecialPowers.spawn(browser, [], async () => {
          return content.document.body.textContent;
        });

        Assert.ok(textContent, "search page loaded");
        let needle = "searchterms=" + test.expectText;
        Assert.equal(
          textContent,
          needle,
          "The query POST data should be returned in the response"
        );
      }
    });
  }
});