tor-browser

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

test_form_validator.js (2159B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 const { FormValidator } = ChromeUtils.importESModule(
      5  "resource://services-sync/engines/forms.sys.mjs"
      6 );
      7 
      8 function getDummyServerAndClient() {
      9  return {
     10    server: [
     11      {
     12        id: "11111",
     13        guid: "11111",
     14        name: "foo",
     15        fieldname: "foo",
     16        value: "bar",
     17      },
     18      {
     19        id: "22222",
     20        guid: "22222",
     21        name: "foo2",
     22        fieldname: "foo2",
     23        value: "bar2",
     24      },
     25      {
     26        id: "33333",
     27        guid: "33333",
     28        name: "foo3",
     29        fieldname: "foo3",
     30        value: "bar3",
     31      },
     32    ],
     33    client: [
     34      {
     35        id: "11111",
     36        guid: "11111",
     37        name: "foo",
     38        fieldname: "foo",
     39        value: "bar",
     40      },
     41      {
     42        id: "22222",
     43        guid: "22222",
     44        name: "foo2",
     45        fieldname: "foo2",
     46        value: "bar2",
     47      },
     48      {
     49        id: "33333",
     50        guid: "33333",
     51        name: "foo3",
     52        fieldname: "foo3",
     53        value: "bar3",
     54      },
     55    ],
     56  };
     57 }
     58 
     59 add_task(async function test_valid() {
     60  let { server, client } = getDummyServerAndClient();
     61  let validator = new FormValidator();
     62  let { problemData, clientRecords, records, deletedRecords } =
     63    await validator.compareClientWithServer(client, server);
     64  equal(clientRecords.length, 3);
     65  equal(records.length, 3);
     66  equal(deletedRecords.length, 0);
     67  deepEqual(problemData, validator.emptyProblemData());
     68 });
     69 
     70 add_task(async function test_formValidatorIgnoresMissingClients() {
     71  // Since history form records are not deleted from the server, the
     72  // |FormValidator| shouldn't set the |missingClient| flag in |problemData|.
     73  let { server, client } = getDummyServerAndClient();
     74  client.pop();
     75 
     76  let validator = new FormValidator();
     77  let { problemData, clientRecords, records, deletedRecords } =
     78    await validator.compareClientWithServer(client, server);
     79 
     80  equal(clientRecords.length, 2);
     81  equal(records.length, 3);
     82  equal(deletedRecords.length, 0);
     83 
     84  let expected = validator.emptyProblemData();
     85  deepEqual(problemData, expected);
     86 });