summaryrefslogtreecommitdiffstats
path: root/dom/html/test/forms/test_input_autocomplete.html
blob: 2aaeac0202ecb1d01cccba94564e70f912ba699a (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!DOCTYPE html>
<html>
<!--
Test @autocomplete on <input>
-->
<head>
  <title>Test for &lt;input autocomplete='…'&gt;</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
<script>
"use strict";

var values = [
  // @autocomplete content attribute, expected IDL attribute value

  // Missing or empty attribute
  [undefined, ""],
  ["", ""],

  // One token
  ["on", "on"],
  ["On", "on"],
  ["off", "off"],
  ["OFF", "off"],
  ["username", "username"],
  [" username ", "username"],
  ["foobar", ""],

  // Two tokens
  ["on off", ""],
  ["off on", ""],
  ["username tel", ""],
  ["tel username ", ""],
  [" username tel ", ""],
  ["tel mobile", ""],
  ["tel shipping", ""],
  ["shipping tel", "shipping tel"],
  ["shipPING tel", "shipping tel"],
  ["mobile tel", "mobile tel"],
  ["  MoBiLe  TeL  ", "mobile tel"],
  ["XXX tel", ""],
  ["XXX username", ""],

  // Three tokens
  ["billing invalid tel", ""],
  ["___ mobile tel", ""],
  ["mobile foo tel", ""],
  ["mobile tel foo", ""],
  ["tel mobile billing", ""],
  ["billing mobile tel", "billing mobile tel"],
  ["  BILLing   MoBiLE   tEl  ", "billing mobile tel"],
  ["billing home tel", "billing home tel"],

  // Four tokens (invalid)
  ["billing billing mobile tel", ""],

  // Five tokens (invalid)
  ["billing billing billing mobile tel", ""],
];

var types = [undefined, "hidden", "text", "search"]; // Valid types for all non-multiline hints.

function checkAutocompleteValues(field, type) {
  for (var test of values) {
    if (typeof(test[0]) === "undefined")
      field.removeAttribute("autocomplete");
    else
      field.setAttribute("autocomplete", test[0]);
    is(field.autocomplete, test[1], "Checking @autocomplete for @type=" + type + " of: " + test[0]);
    is(field.autocomplete, test[1], "Checking cached @autocomplete for @type=" + type + " of: " + test[0]);
  }
}

function start() {
  var inputField = document.getElementById("input-field");
  for (var type of types) {
    // Switch the input type
    if (typeof(type) === "undefined")
      inputField.removeAttribute("type");
    else
      inputField.type = type;
    checkAutocompleteValues(inputField, type || "");
  }

  var selectField = document.getElementById("select-field");
  checkAutocompleteValues(selectField, "select");
  SimpleTest.finish();
}

SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["dom.forms.autocomplete.experimental", true]]}, start);
</script>
</head>

<body>
<p id="display"></p>
<div id="content" style="display: none">
  <form>
    <input id="input-field" />
    <select id="select-field" />
  </form>
</div>
<pre id="test">
</pre>
</body>
</html>