Bug 1310079 - Implement the min and max attribute for <input type=datetime-local>. r=smaug
authorJessica Jong <jjong@mozilla.com>
Sun, 15 Jan 2017 22:10:00 -0500
changeset 329631 1e4e9cc1920c6c41c2ae878603fe94ed4460d8a3
parent 329630 d50140818c65c5f9cb9b4ce8678816eaaaa7e7d2
child 329632 7feb3cffb4a2a413f19176e09ecb98b3ffe57667
push id31218
push userphilringnalda@gmail.com
push dateTue, 17 Jan 2017 05:43:13 +0000
treeherdermozilla-central@3e275d37a062 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1310079
milestone53.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 1310079 - Implement the min and max attribute for <input type=datetime-local>. r=smaug
dom/html/HTMLInputElement.cpp
dom/html/test/forms/test_max_attribute.html
dom/html/test/forms/test_min_attribute.html
testing/web-platform/meta/html/semantics/forms/constraints/form-validation-checkValidity.html.ini
testing/web-platform/meta/html/semantics/forms/constraints/form-validation-reportValidity.html.ini
testing/web-platform/meta/html/semantics/forms/constraints/form-validation-validity-rangeOverflow.html.ini
testing/web-platform/meta/html/semantics/forms/constraints/form-validation-validity-rangeUnderflow.html.ini
testing/web-platform/meta/html/semantics/forms/constraints/form-validation-validity-valid.html.ini
testing/web-platform/meta/html/semantics/selectors/pseudo-classes/inrange-outofrange.html.ini
--- a/dom/html/HTMLInputElement.cpp
+++ b/dom/html/HTMLInputElement.cpp
@@ -7692,18 +7692,17 @@ HTMLInputElement::HasPatternMismatch() c
   nsIDocument* doc = OwnerDoc();
 
   return !nsContentUtils::IsPatternMatching(value, pattern, doc);
 }
 
 bool
 HTMLInputElement::IsRangeOverflow() const
 {
-  // TODO: this is temporary until bug 888331 is fixed.
-  if (!DoesMinMaxApply() || mType == NS_FORM_INPUT_DATETIME_LOCAL) {
+  if (!DoesMinMaxApply()) {
     return false;
   }
 
   Decimal maximum = GetMaximum();
   if (maximum.isNaN()) {
     return false;
   }
 
@@ -7713,18 +7712,17 @@ HTMLInputElement::IsRangeOverflow() cons
   }
 
   return value > maximum;
 }
 
 bool
 HTMLInputElement::IsRangeUnderflow() const
 {
-  // TODO: this is temporary until bug 888331 is fixed.
-  if (!DoesMinMaxApply() || mType == NS_FORM_INPUT_DATETIME_LOCAL) {
+  if (!DoesMinMaxApply()) {
     return false;
   }
 
   Decimal minimum = GetMinimum();
   if (minimum.isNaN()) {
     return false;
   }
 
@@ -8718,18 +8716,17 @@ HTMLInputElement::UpdateHasRange()
 {
   /*
    * There is a range if min/max applies for the type and if the element
    * currently have a valid min or max.
    */
 
   mHasRange = false;
 
-  // TODO: this is temporary until bug 888331 is fixed.
-  if (!DoesMinMaxApply() || mType == NS_FORM_INPUT_DATETIME_LOCAL) {
+  if (!DoesMinMaxApply()) {
     return;
   }
 
   Decimal minimum = GetMinimum();
   if (!minimum.isNaN()) {
     mHasRange = true;
     return;
   }
--- a/dom/html/test/forms/test_max_attribute.html
+++ b/dom/html/test/forms/test_max_attribute.html
@@ -26,18 +26,17 @@ var data = [
   { type: 'tel', apply: false },
   { type: 'url', apply: false },
   { type: 'email', apply: false },
   { type: 'password', apply: false },
   { type: 'date', apply: true },
   { type: 'month', apply: true },
   { type: 'week', apply: true },
   { type: 'time', apply: true },
-  // TODO: temporary set to false until bug 888331 is fixed.
-  { type: 'datetime-local', apply: false },
+  { type: 'datetime-local', apply: true },
   { type: 'number', apply: true },
   { type: 'range', apply: true },
   { type: 'color', apply: false },
   { type: 'checkbox', apply: false },
   { type: 'radio', apply: false },
   { type: 'file', apply: false },
   { type: 'submit', apply: false },
   { type: 'image', apply: false },
@@ -66,17 +65,18 @@ function checkValidity(aElement, aValidi
   aValidity = aApply ? aValidity : true;
 
   is(aElement.validity.valid, aValidity,
      "element validity should be " + aValidity);
   is(aElement.validity.rangeOverflow, !aValidity,
      "element overflow status should be " + !aValidity);
   var overflowMsg =
         (aElement.type == "date" || aElement.type == "time" ||
-         aElement.type == "month" || aElement.type == "week") ?
+         aElement.type == "month" || aElement.type == "week" ||
+         aElement.type == "datetime-local") ?
         ("Please select a value that is no later than " + aElement.max + ".") :
         ("Please select a value that is no more than " + aElement.max + ".");
   is(aElement.validationMessage,
      aValidity ? "" : overflowMsg, "Checking range overflow validation message");
 
   is(aElement.matches(":valid"), aElement.willValidate && aValidity,
      (aElement.willValidate && aValidity) ? ":valid should apply" : "valid shouldn't apply");
   is(aElement.matches(":invalid"), aElement.willValidate && !aValidity,
@@ -143,17 +143,17 @@ for (var test of data) {
       break;
     case 'month':
       input.max = '2016-12';
       break;
     case 'week':
       input.max = '2016-W39';
       break;
     case 'datetime-local':
-      // TODO: this is temporary until bug 888331 is fixed.
+      input.max = '2016-12-31T23:59:59';
       break;
     default:
       ok(false, 'please, add a case for this new type (' + input.type + ')');
   }
 
   checkValidity(input, true, apply, apply);
 
   switch (input.type) {
@@ -416,17 +416,54 @@ for (var test of data) {
       input.max = '';
       checkValidity(input, true, apply, false);
 
       input.max = 'foo';
       checkValidity(input, true, apply, false);
 
       break;
     case 'datetime-local':
-      // TODO: this is temporary until bug 888331 is fixed.
+      input.value = '2016-01-01T12:00';
+      checkValidity(input, true, apply, apply);
+
+      input.value = '2016-12-31T23:59:59';
+      checkValidity(input, true, apply, apply);
+
+      input.value = 'foo';
+      checkValidity(input, true, apply, apply);
+
+      input.value = '2016-12-31T23:59:59.123';
+      checkValidity(input, false, apply, apply);
+
+      input.value = '2017-01-01T10:00';
+      checkValidity(input, false, apply, apply);
+
+      input.max = '2017-01-01T10:00';
+      checkValidity(input, true, apply, apply);
+
+      input.value = '2017-01-01T10:00:30';
+      checkValidity(input, false, apply, apply);
+
+      input.value = '1000-01-01T12:00';
+      checkValidity(input, true, apply, apply);
+
+      input.value = '2100-01-01T12:00';
+      checkValidity(input, false, apply, apply);
+
+      input.max = '0050-12-31T23:59:59.999';
+      checkValidity(input, false, apply, apply);
+
+      input.value = '0050-12-31T23:59:59';
+      checkValidity(input, true, apply, apply);
+
+      input.max = '';
+      checkValidity(input, true, apply, false);
+
+      input.max = 'foo';
+      checkValidity(input, true, apply, false);
 
       break;
   }
 
   // Cleaning up,
   input.removeAttribute('max');
   input.value = '';
 }
--- a/dom/html/test/forms/test_min_attribute.html
+++ b/dom/html/test/forms/test_min_attribute.html
@@ -26,18 +26,17 @@ var data = [
   { type: 'tel', apply: false },
   { type: 'url', apply: false },
   { type: 'email', apply: false },
   { type: 'password', apply: false },
   { type: 'date', apply: true },
   { type: 'month', apply: true },
   { type: 'week', apply: true },
   { type: 'time', apply: true },
-  // TODO: temporary set to false until bug 888331 is fixed.
-  { type: 'datetime-local', apply: false },
+  { type: 'datetime-local', apply: true },
   { type: 'number', apply: true },
   { type: 'range', apply: true },
   { type: 'color', apply: false },
   { type: 'checkbox', apply: false },
   { type: 'radio', apply: false },
   { type: 'file', apply: false },
   { type: 'submit', apply: false },
   { type: 'image', apply: false },
@@ -66,17 +65,18 @@ function checkValidity(aElement, aValidi
   aValidity = aApply ? aValidity : true;
 
   is(aElement.validity.valid, aValidity,
      "element validity should be " + aValidity);
   is(aElement.validity.rangeUnderflow, !aValidity,
      "element underflow status should be " + !aValidity);
   var underflowMsg =
         (aElement.type == "date" || aElement.type == "time" ||
-         aElement.type == "month" || aElement.type == "week") ?
+         aElement.type == "month" || aElement.type == "week" ||
+         aElement.type == "datetime-local") ?
         ("Please select a value that is no earlier than " + aElement.min + ".") :
         ("Please select a value that is no less than " + aElement.min + ".");
   is(aElement.validationMessage,
      aValidity ? "" : underflowMsg, "Checking range underflow validation message");
 
   is(aElement.matches(":valid"), aElement.willValidate && aValidity,
      (aElement.willValidate && aValidity) ? ":valid should apply" : "valid shouldn't apply");
   is(aElement.matches(":invalid"), aElement.willValidate && !aValidity,
@@ -141,20 +141,20 @@ for (var test of data) {
       // range is special, since setting min to 999 will make it invalid since
       // it's default maximum is 100, its value would be 999, and it would
       // suffer from overflow.
       break;
     case 'month':
       input.min = '2016-06';
       break;
     case 'week':
-      input.min = "2016-W39";
+      input.min = '2016-W39';
       break;
     case 'datetime-local':
-      // TODO: this is temporary until bug 888331 is fixed.
+      input.min = '2017-01-01T00:00';
       break;
     default:
       ok(false, 'please, add a case for this new type (' + input.type + ')');
   }
 
   // The element should still be valid and range should apply if it can.
   checkValidity(input, true, apply, apply);
 
@@ -415,17 +415,54 @@ for (var test of data) {
 
       input.min = '';
       checkValidity(input, true, apply, false);
 
       input.min = 'foo';
       checkValidity(input, true, apply, false);
       break;
     case 'datetime-local':
-      // TODO: this is temporary until bug 888331 is fixed.
+      input.value = '2017-12-31T23:59';
+      checkValidity(input, true, apply, apply);
+
+      input.value = '2017-01-01T00:00';
+      checkValidity(input, true, apply, apply);
+
+      input.value = '2017-01-01T00:00:00.123';
+      checkValidity(input, true, apply, apply);
+
+      input.value = 'foo';
+      checkValidity(input, true, apply, apply);
+
+      input.value = '2016-12-31T23:59';
+      checkValidity(input, false, apply, apply);
+
+      input.min = '2016-01-01T00:00';
+      checkValidity(input, true, apply, apply);
+
+      input.value = '2015-12-31T23:59';
+      checkValidity(input, false, apply, apply);
+
+      input.value = '1000-01-01T00:00';
+      checkValidity(input, false, apply, apply);
+
+      input.value = '10000-01-01T00:00';
+      checkValidity(input, true, apply, apply);
+
+      input.min = '0010-01-01T12:00';
+      checkValidity(input, true, apply, apply);
+
+      input.value = '0010-01-01T10:00';
+      checkValidity(input, false, apply, apply);
+
+      input.min = '';
+      checkValidity(input, true, apply, false);
+
+      input.min = 'foo';
+      checkValidity(input, true, apply, false);
       break;
     default:
       ok(false, 'write tests for ' + input.type);
   }
 
   // Cleaning up,
   input.removeAttribute('min');
   input.value = '';
--- a/testing/web-platform/meta/html/semantics/forms/constraints/form-validation-checkValidity.html.ini
+++ b/testing/web-platform/meta/html/semantics/forms/constraints/form-validation-checkValidity.html.ini
@@ -28,29 +28,14 @@
     expected: FAIL
 
   [[INPUT in EMAIL status\] suffering from being too long (in a form)]
     expected: FAIL
 
   [[INPUT in DATETIME status\] The datetime type must be supported.]
     expected: FAIL
 
-  [[INPUT in DATETIME-LOCAL status\] The datetime-local type must be supported.]
-    expected: FAIL
-
-  [[INPUT in DATETIME-LOCAL status\] suffering from an overflow]
-    expected: FAIL
-
-  [[INPUT in DATETIME-LOCAL status\] suffering from an overflow (in a form)]
-    expected: FAIL
-
-  [[INPUT in DATETIME-LOCAL status\] suffering from an underflow]
-    expected: FAIL
-
-  [[INPUT in DATETIME-LOCAL status\] suffering from an underflow (in a form)]
-    expected: FAIL
-
   [[INPUT in DATETIME-LOCAL status\] suffering from a step mismatch]
     expected: FAIL
 
   [[INPUT in DATETIME-LOCAL status\] suffering from a step mismatch (in a form)]
     expected: FAIL
 
--- a/testing/web-platform/meta/html/semantics/forms/constraints/form-validation-reportValidity.html.ini
+++ b/testing/web-platform/meta/html/semantics/forms/constraints/form-validation-reportValidity.html.ini
@@ -34,29 +34,14 @@
     expected: FAIL
 
   [[INPUT in EMAIL status\] suffering from being too long (in a form)]
     expected: FAIL
 
   [[INPUT in DATETIME status\] The datetime type must be supported.]
     expected: FAIL
 
-  [[INPUT in DATETIME-LOCAL status\] The datetime-local type must be supported.]
-    expected: FAIL
-
-  [[INPUT in DATETIME-LOCAL status\] suffering from an overflow]
-    expected: FAIL
-
-  [[INPUT in DATETIME-LOCAL status\] suffering from an overflow (in a form)]
-    expected: FAIL
-
-  [[INPUT in DATETIME-LOCAL status\] suffering from an underflow]
-    expected: FAIL
-
-  [[INPUT in DATETIME-LOCAL status\] suffering from an underflow (in a form)]
-    expected: FAIL
-
   [[INPUT in DATETIME-LOCAL status\] suffering from a step mismatch]
     expected: FAIL
 
   [[INPUT in DATETIME-LOCAL status\] suffering from a step mismatch (in a form)]
     expected: FAIL
 
--- a/testing/web-platform/meta/html/semantics/forms/constraints/form-validation-validity-rangeOverflow.html.ini
+++ b/testing/web-platform/meta/html/semantics/forms/constraints/form-validation-validity-rangeOverflow.html.ini
@@ -1,23 +1,4 @@
 [form-validation-validity-rangeOverflow.html]
   type: testharness
   [[INPUT in DATETIME status\] The datetime type must be supported.]
     expected: FAIL
-
-  [[INPUT in DATETIME-LOCAL status\] The datetime-local type must be supported.]
-    expected: FAIL
-
-  [[INPUT in DATETIME-LOCAL status\] The value is greater than max]
-    expected: FAIL
-
-  [[INPUT in DATETIME-LOCAL status\] The value is greater than max(with millisecond in 1 digit)]
-    expected: FAIL
-
-  [[INPUT in DATETIME-LOCAL status\] The value is greater than max(with millisecond in 2 digits)]
-    expected: FAIL
-
-  [[INPUT in DATETIME-LOCAL status\] The value is greater than max(with millisecond in 3 digits)]
-    expected: FAIL
-
-  [[INPUT in DATETIME-LOCAL status\] The value is greater than max(Year is 10000 should be valid)]
-    expected: FAIL
-
--- a/testing/web-platform/meta/html/semantics/forms/constraints/form-validation-validity-rangeUnderflow.html.ini
+++ b/testing/web-platform/meta/html/semantics/forms/constraints/form-validation-validity-rangeUnderflow.html.ini
@@ -1,23 +1,5 @@
 [form-validation-validity-rangeUnderflow.html]
   type: testharness
   [[INPUT in DATETIME status\] The datetime type must be supported.]
     expected: FAIL
 
-  [[INPUT in DATETIME-LOCAL status\] The datetime-local type must be supported.]
-    expected: FAIL
-
-  [[INPUT in DATETIME-LOCAL status\] The value is less than min]
-    expected: FAIL
-
-  [[INPUT in DATETIME-LOCAL status\] The value is less than min(with millisecond in 1 digit)]
-    expected: FAIL
-
-  [[INPUT in DATETIME-LOCAL status\] The value is less than min(with millisecond in 2 digits)]
-    expected: FAIL
-
-  [[INPUT in DATETIME-LOCAL status\] The value is less than min(with millisecond in 3 digits)]
-    expected: FAIL
-
-  [[INPUT in DATETIME-LOCAL status\] The value is less than min(Year is 10000 should be valid)]
-    expected: FAIL
-
--- a/testing/web-platform/meta/html/semantics/forms/constraints/form-validation-validity-valid.html.ini
+++ b/testing/web-platform/meta/html/semantics/forms/constraints/form-validation-validity-valid.html.ini
@@ -19,20 +19,11 @@
     expected: FAIL
 
   [[INPUT in DATETIME status\] The datetime type must be supported.]
     expected: FAIL
 
   [[INPUT in MONTH status\] validity.valid must be false if validity.stepMismatch is true]
     expected: FAIL
 
-  [[INPUT in DATETIME-LOCAL status\] The datetime-local type must be supported.]
-    expected: FAIL
-
-  [[INPUT in DATETIME-LOCAL status\] validity.valid must be false if validity.rangeOverflow is true]
-    expected: FAIL
-
-  [[INPUT in DATETIME-LOCAL status\] validity.valid must be false if validity.rangeUnderflow is true]
-    expected: FAIL
-
   [[INPUT in DATETIME-LOCAL status\] validity.valid must be false if validity.stepMismatch is true]
     expected: FAIL
 
deleted file mode 100644
--- a/testing/web-platform/meta/html/semantics/selectors/pseudo-classes/inrange-outofrange.html.ini
+++ /dev/null
@@ -1,20 +0,0 @@
-[inrange-outofrange.html]
-  type: testharness
-  [':in-range' matches all elements that are candidates for constraint validation, have range limitations, and that are neither suffering from an underflow nor suffering from an overflow]
-    expected: FAIL
-
-  [':in-range' update number1's value < min]
-    expected: FAIL
-
-  [':in-range' update number3's min < value]
-    expected: FAIL
-
-  [':out-of-range' matches all elements that are candidates for constraint validation, have range limitations, and that are either suffering from an underflow or suffering from an overflow]
-    expected: FAIL
-
-  [':out-of-range' update number1's value < min]
-    expected: FAIL
-
-  [':out-of-range' update number3's min < value]
-    expected: FAIL
-