Reviewers: felix8a,

Description:
* Whitelist input type={search,tel,url,email,datetime,date,month,week,
  time,datetime-local,number,range,color}.
* Add properties/methods for numeric field types: stepUp, stepDown,
  step, min, max, valueAsNumber.
* Export assertNaN to guest tests.

Does not work in ES5/3 mode because the cajoler is not allowing the new
types despite the schema change, but we can debug that later.

Fixes <https://code.google.com/p/google-caja/issues/detail?id=1609>.

Please review this at https://codereview.appspot.com/9023047/

Affected files:
  M     src/com/google/caja/lang/html/html4-attributes-defs.json
  M     src/com/google/caja/plugin/domado.js
  M     tests/com/google/caja/plugin/browser-test-case.js
  M     tests/com/google/caja/plugin/es53-test-domado-forms-guest.html


Index: tests/com/google/caja/plugin/browser-test-case.js
===================================================================
--- tests/com/google/caja/plugin/browser-test-case.js   (revision 5387)
+++ tests/com/google/caja/plugin/browser-test-case.js   (working copy)
@@ -638,7 +638,7 @@
   var jsunitFns = [
       'assert', 'assertContains', 'assertEquals', 'assertEvaluatesToFalse',
       'assertEvaluatesToTrue', 'assertFalse', 'assertHTMLEquals',
-      'assertHashEquals', 'assertNotEquals', 'assertNotNull',
+      'assertHashEquals', 'assertNaN', 'assertNotEquals', 'assertNotNull',
       'assertNotUndefined', 'assertNull', 'assertRoughlyEquals',
       'assertThrows', 'assertTrue', 'assertObjectEquals', 'assertUndefined',
       'assertThrowsMsg', 'error', 'fail', 'setUp', 'tearDown'];
Index: tests/com/google/caja/plugin/es53-test-domado-forms-guest.html
===================================================================
--- tests/com/google/caja/plugin/es53-test-domado-forms-guest.html (revision 5387) +++ tests/com/google/caja/plugin/es53-test-domado-forms-guest.html (working copy)
@@ -220,3 +220,33 @@
     pass('testDynamicForm');
   });
 </script>
+
+<form class="testcontainer" id="testFancyInputs">testFancyInputs
+  <!-- HTML5 input types and related interface -->
+  <input type="text" id="testFancyInputs-plain" value="7">
+  <input type="number" id="testFancyInputs-num" value="7">
+</form>
+<script type="text/javascript">
+  // TODO(kpreid): Marked ES5 only because the cajoler is not allowing
+ // type=number through despite it being in the schema; I don't know why yet. + jsunitRegisterIf(inES5Mode, 'testFancyInputs', function testFancyInputs() {
+    // TODO(kpreid): test other HTML5 input types.
+
+    // basics/comparison
+    assertEquals('text', $('testFancyInputs-plain').type);
+    assertNaN($('testFancyInputs-plain').valueAsNumber);
+
+    assertEquals('number', $('testFancyInputs-num').getAttribute('type'));
+    if ($('testFancyInputs-num').type === 'number') {  // browser support
+      assertEquals('number', $('testFancyInputs-num').type);
+      assertEquals(7, $('testFancyInputs-num').valueAsNumber);
+
+      $('testFancyInputs-num').stepDown();
+      assertEquals(6, $('testFancyInputs-num').valueAsNumber);
+      $('testFancyInputs-num').stepUp();
+      assertEquals(7, $('testFancyInputs-num').valueAsNumber);
+    }
+
+    pass('testFancyInputs');
+  });
+</script>
Index: src/com/google/caja/lang/html/html4-attributes-defs.json
===================================================================
--- src/com/google/caja/lang/html/html4-attributes-defs.json    (revision 5387)
+++ src/com/google/caja/lang/html/html4-attributes-defs.json    (working copy)
@@ -598,8 +598,9 @@
         "optional": false, "default": "text/javascript" },
{ "key": "STYLE::TYPE", "description": "content type of style language",
         "optional": false, "default": "text/css" },
- { "key": "INPUT::TYPE", "description": "what kind of widget is needed",
-        "values": 
"text,password,checkbox,radio,submit,reset,file,hidden,image,button",
+      { "key": "INPUT::TYPE", "description": "Type of form control",
+        "values": 
"hidden,text,search,tel,url,email,password,datetime,date,month,week,time,datetime-local,number,range,color,checkbox,radio,file,submit,image,reset,button",
+        "comment": "Values include HTML5 features",
         "default": "TEXT", "optional": true },
       { "key": "LI::TYPE", "description": "list item style",
         "optional": true },
Index: src/com/google/caja/plugin/domado.js
===================================================================
--- src/com/google/caja/plugin/domado.js        (revision 5387)
+++ src/com/google/caja/plugin/domado.js        (working copy)
@@ -5326,15 +5326,25 @@
           defaultValue: NP.filter(
             false, function (x) { return x == null ? null : String(x); },
             false, function (x) { return x == null ? '' : '' + x; }),
+          min: NP.rw,
+          max: NP.rw,
           readOnly: NP.rw,
           selectedIndex: NP.filterProp(identity, toInt),
           size: NP.rw,
-          type: NP.rw
+          step: NP.rw,
+          type: NP.rw,
+          valueAsNumber: NP.rw
         }
       });
       TameInputElement.prototype.select = nodeAmp(function(privates) {
         privates.feral.select();
       });
+      TameInputElement.prototype.stepDown = nodeAmp(function(privates) {
+        privates.feral.stepDown();
+      });
+      TameInputElement.prototype.stepUp = nodeAmp(function(privates) {
+        privates.feral.stepUp();
+      });

       defineElement({
         superclass: TameFormField,


--

--- You received this message because you are subscribed to the Google Groups "Google Caja Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to