Bug 1009935 - Tests - Implement the @autocomplete attribute for values other than off/on. r=smaug
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Fri, 06 Jun 2014 00:25:08 -0700
changeset 206269 da60b8bc18a32ca050ab8543c222a4443c34f768
parent 206268 21cf9d1e6f485da8dfceb8b3b3f4c4e5e95a2965
child 206270 e28e73446d88c5d9bd56465916a26eab0a0e43ac
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1009935
milestone32.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1009935 - Tests - Implement the @autocomplete attribute for values other than off/on. r=smaug
content/html/content/test/forms/mochitest.ini
content/html/content/test/forms/test_input_autocomplete.html
--- a/content/html/content/test/forms/mochitest.ini
+++ b/content/html/content/test/forms/mochitest.ini
@@ -13,16 +13,17 @@ skip-if = (buildapp == 'b2g' && toolkit 
 [test_form_attribute-1.html]
 [test_form_attribute-2.html]
 [test_form_attribute-3.html]
 [test_form_attribute-4.html]
 [test_form_attributes_reflection.html]
 [test_formaction_attribute.html]
 [test_formnovalidate_attribute.html]
 [test_input_attributes_reflection.html]
+[test_input_autocomplete.html]
 [test_input_color_input_change_events.html]
 [test_input_color_picker_initial.html]
 [test_input_color_picker_popup.html]
 [test_input_color_picker_update.html]
 [test_input_defaultValue.html]
 [test_input_email.html]
 [test_input_event.html]
 skip-if = (buildapp == 'b2g' && toolkit != 'gonk') #Bug 931116, b2g desktop specific, initial triage
new file mode 100644
--- /dev/null
+++ b/content/html/content/test/forms/test_input_autocomplete.html
@@ -0,0 +1,103 @@
+<!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"/>
+</head>
+
+<body>
+<p id="display"></p>
+<div id="content" style="display: none">
+  <form>
+    <input id="field" />
+  </form>
+</div>
+<pre id="test">
+<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.
+var field = document.getElementById("field");
+
+function checkAutocompleteValues(type) {
+  for (var test of values) {
+    if (typeof(test[0]) === "undefined")
+      field.removeAttribute("autocomplete");
+    else
+      field.setAttribute("autocomplete", test[0]);
+    ise(field.autocomplete, test[1], "Checking @autocomplete for @type=" + type + " of: " + test[0]);
+    ise(field.autocomplete, test[1], "Checking cached @autocomplete for @type=" + type + " of: " + test[0]);
+  }
+}
+
+function start() {
+  for (var type of types) {
+    // Switch the input type
+    if (typeof(type) === "undefined")
+      field.removeAttribute("type");
+    else
+      field.type = type;
+    checkAutocompleteValues(type || "");
+  }
+  SimpleTest.finish();
+}
+
+SimpleTest.waitForExplicitFinish();
+SpecialPowers.pushPrefEnv({"set": [["dom.forms.autocomplete.experimental", true]]}, start);
+
+</script>
+</pre>
+</body>
+</html>