summaryrefslogtreecommitdiffstats
path: root/toolkit/components/satchel/test/test_capture_limit.html
blob: 859154401624318c8e89e18486a906712f1ff8c7 (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
<!DOCTYPE HTML>
<html>
<head>
  <title>Form History capture no more than 100 changes</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="satchel_common.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
  <form id="form1">
    <button type="submit">Submit</button>
  </form>
</div>
<script>

add_setup(async () => {
  const count = await countEntries(null, null);
  ok(!count, "initial storage is empty");
});

add_task(async function captureLimit() {
  // Capture no more than 100 fields per submit. See FormHistoryChild.jsm.
  const inputsCount = 100 + 2;
  const form = document.getElementById("form1");
  for (let i = 1; i <= inputsCount; i++) {
    const newField = document.createElement("input");
    newField.setAttribute("type", "text");
    newField.setAttribute("name", "test" + i);
    form.appendChild(newField);
    if( i != 50) {
      SpecialPowers.wrap(newField).setUserInput(i);
    }
  }

  form.addEventListener("submit", e => e.preventDefault(), { once: true });
  const storageUpdated = promiseNextStorageEvent();
  getFormSubmitButton(1).click();
  await storageUpdated;

  for (let i = 1; i <= inputsCount; i++) { // check all but last
    const historyEntries = await countEntries("test" + i, i);

    switch(i) {
      case 50:
        is(historyEntries, 0, `no history saved for input ${i} because user didn't modify it`);
        break;
      case 102:
        is(historyEntries, 0, `no history saved for input ${i} because form already captured 100 fields`);
        break;
      default:
        is(historyEntries, 1, `history saved for input ${i}`);
        break;
    }
  }
});

</script>
</body>
</html>