tor-browser

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

browser_456342.js (2581B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 addCoopTask(
      7  "browser_456342_sample.xhtml",
      8  test_restore_nonstandard_input_values,
      9  HTTPSROOT
     10 );
     11 addNonCoopTask(
     12  "browser_456342_sample.xhtml",
     13  test_restore_nonstandard_input_values,
     14  ROOT
     15 );
     16 addNonCoopTask(
     17  "browser_456342_sample.xhtml",
     18  test_restore_nonstandard_input_values,
     19  HTTPROOT
     20 );
     21 addNonCoopTask(
     22  "browser_456342_sample.xhtml",
     23  test_restore_nonstandard_input_values,
     24  HTTPSROOT
     25 );
     26 
     27 const EXPECTED_IDS = new Set(["searchTerm"]);
     28 
     29 const EXPECTED_XPATHS = new Set([
     30  "/xhtml:html/xhtml:body/xhtml:form/xhtml:p[2]/xhtml:input",
     31  "/xhtml:html/xhtml:body/xhtml:form/xhtml:p[3]/xhtml:input[@name='fill-in']",
     32  "/xhtml:html/xhtml:body/xhtml:form/xhtml:p[4]/xhtml:input[@name='mistyped']",
     33  "/xhtml:html/xhtml:body/xhtml:form/xhtml:p[5]/xhtml:textarea[@name='textarea_pass']",
     34 ]);
     35 
     36 /**
     37 * Bug 456342 - Restore values from non-standard input field types.
     38 */
     39 async function test_restore_nonstandard_input_values(aURL) {
     40  // Add tab with various non-standard input field types.
     41  let tab = BrowserTestUtils.addTab(gBrowser, aURL);
     42  let browser = tab.linkedBrowser;
     43  await promiseBrowserLoaded(browser);
     44 
     45  // Fill in form values.
     46  let expectedValue = Math.random();
     47 
     48  await SpecialPowers.spawn(browser, [expectedValue], valueChild => {
     49    for (let elem of content.document.forms[0].elements) {
     50      elem.value = valueChild;
     51      let event = elem.ownerDocument.createEvent("UIEvents");
     52      event.initUIEvent("input", true, true, elem.ownerGlobal, 0);
     53      elem.dispatchEvent(event);
     54    }
     55  });
     56 
     57  // Remove tab and check collected form data.
     58  await promiseRemoveTabAndSessionState(tab);
     59  let undoItems = ss.getClosedTabDataForWindow(window);
     60  let savedFormData = undoItems[0].state.formdata;
     61 
     62  let foundIds = 0;
     63  for (let id of Object.keys(savedFormData.id)) {
     64    ok(EXPECTED_IDS.has(id), `Check saved ID "${id}" was expected`);
     65    is(
     66      savedFormData.id[id],
     67      "" + expectedValue,
     68      `Check saved value for #${id}`
     69    );
     70    foundIds++;
     71  }
     72 
     73  let foundXpaths = 0;
     74  for (let exp of Object.keys(savedFormData.xpath)) {
     75    ok(EXPECTED_XPATHS.has(exp), `Check saved xpath "${exp}" was expected`);
     76    is(
     77      savedFormData.xpath[exp],
     78      "" + expectedValue,
     79      `Check saved value for ${exp}`
     80    );
     81    foundXpaths++;
     82  }
     83 
     84  is(foundIds, EXPECTED_IDS.size, "Check number of fields saved by ID");
     85  is(
     86    foundXpaths,
     87    EXPECTED_XPATHS.size,
     88    "Check number of fields saved by xpath"
     89  );
     90 }