summaryrefslogtreecommitdiffstats
path: root/dom/html/test/forms/test_input_types_pref.html
blob: 1222e88a866b072abae38ca62137a46b60e598c1 (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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=764481
-->
<head>
  <title>Test for Bug 764481</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=764481">Mozilla Bug 764481</a>
<p id="display"></p>
<div id="content" style="display: none" >
</div>
<pre id="test">
<script type="application/javascript">

  var input = document.createElement("input");

  var testData = [
    {
      prefs: [["dom.forms.datetime.others", false]],
      inputType: "month",
      expectedType: "text"
    }, {
      prefs: [["dom.forms.datetime.others", false]],
      inputType: "month",
      expectedType: "text"
    }, {
      prefs: [["dom.forms.datetime.others", true]],
      inputType: "month",
      expectedType: "month"
    }, {
      prefs: [["dom.forms.datetime.others", false]],
      inputType: "week",
      expectedType: "text"
    }, {
      prefs: [["dom.forms.datetime.others", false]],
      inputType: "week",
      expectedType: "text"
    }, {
      prefs: [["dom.forms.datetime.others", true]],
      inputType: "week",
      expectedType: "week"
    }
  ];

  function testInputTypePreference(aData) {
    return SpecialPowers.pushPrefEnv({'set': aData.prefs})
      .then(() => {
        // Change the type of input to text and then back to the tested input type,
        // so that HTMLInputElement::ParseAttribute gets called with the pref enabled.
        input.type = "text";
        input.type = aData.inputType;
        is(input.type, aData.expectedType, "input type should be '" +
           aData.expectedType + "'' when pref " + aData.prefs + " is set");
        is(input.getAttribute('type'), aData.inputType,
           "input 'type' attribute should not change");
      });
  }

  SimpleTest.waitForExplicitFinish();

  let promise = Promise.resolve();
  for (let i = 0; i < testData.length; i++) {
    let data = testData[i];
    promise = promise.then(() => testInputTypePreference(data));
  }

  promise.catch(error => ok(false, "Promise reject: " + error))
    .then(() => SimpleTest.finish());

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