tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_UrlbarQueryContext.js (2170B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 add_task(function test_constructor() {
      7  Assert.throws(
      8    () => new UrlbarQueryContext({}),
      9    /Missing or empty allowAutofill provided to UrlbarQueryContext/,
     10    "Should throw with no arguments"
     11  );
     12 
     13  Assert.throws(
     14    () =>
     15      new UrlbarQueryContext({
     16        allowAutofill: true,
     17        isPrivate: false,
     18        searchString: "foo",
     19      }),
     20    /Missing or empty maxResults provided to UrlbarQueryContext/,
     21    "Should throw with a missing maxResults parameter"
     22  );
     23 
     24  Assert.throws(
     25    () =>
     26      new UrlbarQueryContext({
     27        allowAutofill: true,
     28        maxResults: 1,
     29        searchString: "foo",
     30      }),
     31    /Missing or empty isPrivate provided to UrlbarQueryContext/,
     32    "Should throw with a missing isPrivate parameter"
     33  );
     34 
     35  Assert.throws(
     36    () =>
     37      new UrlbarQueryContext({
     38        isPrivate: false,
     39        maxResults: 1,
     40        searchString: "foo",
     41      }),
     42    /Missing or empty allowAutofill provided to UrlbarQueryContext/,
     43    "Should throw with a missing allowAutofill parameter"
     44  );
     45 
     46  Assert.throws(
     47    () =>
     48      new UrlbarQueryContext({
     49        allowAutofill: true,
     50        isPrivate: false,
     51        maxResults: 1,
     52        searchString: "foo",
     53      }),
     54    /Missing or empty sapName provided to UrlbarQueryContext/,
     55    "Should throw with a missing sapName parameter"
     56  );
     57 
     58  let qc = new UrlbarQueryContext({
     59    allowAutofill: false,
     60    isPrivate: true,
     61    maxResults: 1,
     62    sapName: "foo",
     63    searchString: "bar",
     64  });
     65 
     66  Assert.strictEqual(
     67    qc.allowAutofill,
     68    false,
     69    "Should have saved the correct value for allowAutofill"
     70  );
     71  Assert.strictEqual(
     72    qc.isPrivate,
     73    true,
     74    "Should have saved the correct value for isPrivate"
     75  );
     76  Assert.equal(
     77    qc.maxResults,
     78    1,
     79    "Should have saved the correct value for maxResults"
     80  );
     81  Assert.equal(
     82    qc.sapName,
     83    "foo",
     84    "Should have saved the correct value for searchString"
     85  );
     86  Assert.equal(
     87    qc.searchString,
     88    "bar",
     89    "Should have saved the correct value for searchString"
     90  );
     91 });