fixed up tests to now check WebIDL double conversion being done properly
authorMarcos Caceres <w3c@marcosc.com>
Mon, 16 Jul 2012 12:08:11 +0100
changeset 157 2f67049e0a21
parent 156 1e5571daf449
child 158 95fb886b157d
fixed up tests to now check WebIDL double conversion being done properly
light/tests/submissions/marcosc/DeviceLight_tests.js
--- a/light/tests/submissions/marcosc/DeviceLight_tests.js	Fri Jul 13 20:47:01 2012 +0100
+++ b/light/tests/submissions/marcosc/DeviceLight_tests.js	Mon Jul 16 12:08:11 2012 +0100
@@ -1,325 +1,334 @@
 /**
-* W3C 3-clause BSD License
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are
-* met:
-* o Redistributions of works must retain the original copyright notice,
-*     this list of conditions and the following disclaimer.
-*
-* o Redistributions in binary form must reproduce the original copyright
-*     notice, this list of conditions and the following disclaimer in the
-*     documentation and/or other materials provided with the distribution.
-*
-* o Neither the name of the W3C nor the names of its contributors may be
-*     used to endorse or promote products derived from this work without
-*     specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
-* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-* POSSIBILITY OF SUCH DAMAGE.
-**/
-(function() {
-    //inheritance tests
-    test(function() {
-        var event = new DeviceLightEvent('');
-        assert_true(event instanceof window.DeviceLightEvent);
-    }, 'the event is an instance of DeviceLightEvent');
-
-    test(function() {
-        var event = new DeviceLightEvent('');
-        assert_true(event instanceof window.Event);
-    }, 'the event inherits from Event');
-
-    //Type attribute tests
-    test(function() {
-        assert_throws(TypeError(), function() {
-            new DeviceLightEvent();
-        }, 'First argument is required, so was expecting a TypeError.');
-    }, 'Missing type argument');
-
-    test(function() {
-        var event = new DeviceLightEvent(undefined);
-        assert_equals(event.type, 'undefined');
-    }, 'Event type set to undefined');
-
-    test(function() {
-        var event = new DeviceLightEvent(null);
-        assert_equals(event.type, 'null');
-    }, 'type argument is null');
-
-    test(function() {
-        var event = new DeviceLightEvent(123);
-        assert_equals(event.type, '123');
-    }, 'type argument is number');
-
-    test(function() {
-        var event = new DeviceLightEvent(new Number(123));
-        assert_equals(event.type, '123');
-    }, 'type argument is Number');
-
-    test(function() {
-        var event = new DeviceLightEvent([]);
-        assert_equals(event.type, '');
-    }, 'type argument is array');
-
-    test(function() {
-        var event = new DeviceLightEvent(new Array());
-        assert_equals(event.type, '');
-    }, 'type argument is instance of Array');
-
-    test(function() {
-        var event = new DeviceLightEvent(['t', ['e', ['s', ['t']]]]);
-        assert_equals(event.type, 't,e,s,t');
-    }, 'type argument is nested array');
-
-    test(function() {
-        var event = new DeviceLightEvent(Math);
-        assert_equals(event.type, '[object Math]');
-    }, 'type argument is host object');
-
-    test(function() {
-        var event = new DeviceLightEvent(true);
-        assert_equals(event.type, 'true');
-    }, 'type argument is boolean (true)');
-
-    test(function() {
-        var event = new DeviceLightEvent(new Boolean(true));
-        assert_equals(event.type, 'true');
-    }, 'type argument is instance of boolean');
-
-    test(function() {
-        var event = new DeviceLightEvent(false);
-        assert_equals(event.type, 'false');
-    }, 'type argument is boolean (false)');
-
-    test(function() {
-        var event = new DeviceLightEvent(new Boolean(false));
-        assert_equals(event.type, 'false');
-    }, '');
-
-    test(function() {
-        var event = new DeviceLightEvent('test');
-        assert_equals(event.type, 'test');
-    }, 'type argument is instance of boolean (false)');
-
-    test(function() {
-        var event = new DeviceLightEvent(new String('test'));
-        assert_equals(event.type, 'test');
-    }, 'type argument is string');
-
-    test(function() {
-        var event = new DeviceLightEvent(function test() {});
-        assert_equals(event.type, 'function test() {}');
-    }, 'type argument is function');
-
-    test(function() {
-        var event = new DeviceLightEvent({
-            toString: function() {
-                return '123';
-            }
-        });
-        assert_equals(event.type, '123');
-    }, 'type argument is complext object, with toString method');
-
-    test(function() {
-        assert_throws(TypeError(), function() {
-            new DeviceLightEvent({
-                toString: function() {
-                    return function() {}
-                }
-            });
-        });
-    }, 'toString is of type function');
-
-    //test readonly attribute boolean value;
-    test(function() {
-        var event = new DeviceLightEvent('test');
-        assert_readonly(event, 'value', 'readonly attribute value');
-    }, 'value is readonly');
-
-    test(function() {
-        var event = new DeviceLightEvent('test', {
-            value: false
-        });
-        assert_equals(event.value, false, 'value set to false');
-    }, 'value set to false');
-
-    test(function() {
-        var event = new DeviceLightEvent('test', {
-            value: true
-        });
-        assert_equals(event.value, true, 'value set to true');
-    }, 'value set to true');
+ * W3C 3-clause BSD License
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * o Redistributions of works must retain the original copyright notice,
+ *     this list of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the original copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * o Neither the name of the W3C nor the names of its contributors may be
+ *     used to endorse or promote products derived from this work without
+ *     specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ **/ 
 
-    test(function() {
-        var event = new DeviceLightEvent('test', {
-            value: undefined
-        });
-        assert_equals(event.value, false, 'argument is truthy');
-    }, 'value set to a falsy object');
-
-    test(function() {
-        var event = new DeviceLightEvent('test', {
-            value: null
-        });
-        assert_equals(event.value, false, 'argument is flasy');
-    }, 'value set to a falsy object');
-
-    test(function() {
-        var event = new DeviceLightEvent('test', {
-            value: 0
-        });
-        assert_equals(event.value, false, 'argument is flasy');
-    }, 'value set to a falsy object');
-
-    test(function() {
-        var event = new DeviceLightEvent('test', {
-            value: ''
-        });
-        assert_equals(event.value, false, 'argument is flasy');
-    }, 'value set to a falsy object');
-
-    test(function() {
-        var event = new DeviceLightEvent('test', {
-            value: '\u0020'
-        });
-        assert_equals(event.value, true, 'argument is truthy');
-    }, 'value set to a truthy object');
-
-    test(function() {
-        var event = new DeviceLightEvent('test', {
-            value: 1
-        });
-        assert_equals(event.value, true, 'argument is truthy');
-    }, 'value set to a truthy object');
-
-    test(function() {
-        var event = new DeviceLightEvent('test', {
-            value: []
-        });
-        assert_equals(event.value, true, 'argument is truthy');
-    }, 'value set to a truthy object');
-
-    test(function() {
-        var event = new DeviceLightEvent('test', {
-            value: {}
-        });
-        assert_equals(event.value, true, 'argument is truthy');
-    }, 'value set to a truthy object');
-
-    test(function() {
-        var dict = {
-            get test() {
-                return false;
-            }
-        };
-        var event = new DeviceLightEvent('test', {
-            value: dict.test
-        });
-        assert_equals(event.value, false, 'explict false');
-    }, 'value set to object that resolves to false');
-
-    test(function() {
-        var desc = 'Expected to find ondevicelight attribute on window object';
-        assert_own_property(window, 'ondevicelight', desc);
-    }, 'ondevicelight exists');
-
-    test(function() {
-        var desc = 'window.ondevicelight must be null';
-        assert_equals(window.ondevicelight, null, desc);
-    }, 'ondevicelight is null');
+ (function() {
+  //inheritance tests
+  test(function() {
+    var event = new DeviceLightEvent('');
+    assert_true(event instanceof window.DeviceLightEvent);
+  }, 'the event is an instance of DeviceLightEvent');
 
-    test(function() {
-        var desc = 'window.ondevicelight did not accept callable object',
-            func = function() {}
-        window.ondevicelight = func;
-        assert_equals(window.ondevicelight, func, desc);
-    }, 'ondevicelight is set to function');
-
-    test(function() {
-        var desc = 'window.ondevicelight did not treat noncallable as null';
-        window.ondevicelight = function() {};
-        window.ondevicelight = {};
-        assert_equals(window.ondevicelight, null, desc);
-    }, 'treat object as null');
-
-    test(function() {
-        var desc = 'window.ondevicelight did not treat noncallable as null';
-        window.ondevicelight = function() {};
-        window.ondevicelight = {
-            call: 'test'
-        };
-        assert_equals(window.ondevicelight, null, desc);
-    }, 'treat object with non-callable call property as null');
-
-    test(function() {
-        var desc = 'window.ondevicelight did not treat noncallable as null',
-            test = function() {};
-        test.call = 'test';
-        window.ondevicelight = function() {};
-        window.ondevicelight = test;
-        assert_equals(window.ondevicelight, null, desc);
-    }, 'treat object with non-callable call property as null');
-
-    test(function() {
-        var desc = 'window.ondevicelight did not treat noncallable (string) as null';
-        window.ondevicelight = function() {};
-        window.ondevicelight = 'string';
-        assert_equals(window.ondevicelight, null, desc);
-    }, 'treat string as null');
+  test(function() {
+    var event = new DeviceLightEvent('');
+    assert_true(event instanceof window.Event);
+  }, 'the event inherits from Event');
 
-    test(function() {
-        var desc = 'window.ondevicelight did not treat noncallable (number) as null';
-        window.ondevicelight = function() {};
-        window.ondevicelight = 123;
-        assert_equals(window.ondevicelight, null, desc);
-    }, 'treat number as null');
-
-    test(function() {
-        var desc = 'window.ondevicelight did not treat noncallable (undefined) as null';
-        window.ondevicelight = function() {};
-        window.ondevicelight = undefined;
-        assert_equals(window.ondevicelight, null, desc);
-    }, 'treat undefined as null');
-
-    test(function() {
-        var desc = 'window.ondevicelight did not treat noncallable (array) as null';
-        window.ondevicelight = function() {};
-        window.ondevicelight = [];
-        assert_equals(window.ondevicelight, null, desc);
-    }, 'treat array as null');
+  //Type attribute tests
+  test(function() {
+    assert_throws(TypeError(), function() {
+      new DeviceLightEvent();
+    }, 'First argument is required, so was expecting a TypeError.');
+  }, 'Missing type argument');
 
-    test(function() {
-        var desc = 'window.ondevicelight did not treat noncallable host object as null';
-        window.ondevicelight = function() {};
-        window.ondevicelight = Node;
-        assert_equals(window.ondevicelight, null, desc);
-    }, 'treat non-callable host object as null');
+  test(function() {
+    var event = new DeviceLightEvent(undefined);
+    assert_equals(event.type, 'undefined');
+  }, 'Event type set to undefined');
 
-    //Async tests
-    var t = async_test('test if user proximity event recieved');
-    window.addEventListener('userproximity', function(e) {
-        t.step(function() {
-            var msg = 'expected instance of DeviceLightEvent: ';
-            assert_true(e instanceof window.DeviceLightEvent, msg);
-        });
-        t.done();
+  test(function() {
+    var event = new DeviceLightEvent(null);
+    assert_equals(event.type, 'null');
+  }, 'type argument is null');
+
+  test(function() {
+    var event = new DeviceLightEvent(123);
+    assert_equals(event.type, '123');
+  }, 'type argument is number');
+
+  test(function() {
+    var event = new DeviceLightEvent(new Number(123));
+    assert_equals(event.type, '123');
+  }, 'type argument is Number');
+
+  test(function() {
+    var event = new DeviceLightEvent([]);
+    assert_equals(event.type, '');
+  }, 'type argument is array');
+
+  test(function() {
+    var event = new DeviceLightEvent(new Array());
+    assert_equals(event.type, '');
+  }, 'type argument is instance of Array');
+
+  test(function() {
+    var event = new DeviceLightEvent(['t', ['e', ['s', ['t']]]]);
+    assert_equals(event.type, 't,e,s,t');
+  }, 'type argument is nested array');
+
+  test(function() {
+    var event = new DeviceLightEvent(Math);
+    assert_equals(event.type, '[object Math]');
+  }, 'type argument is host object');
+
+  test(function() {
+    var event = new DeviceLightEvent(true);
+    assert_equals(event.type, 'true');
+  }, 'type argument is boolean (true)');
+
+  test(function() {
+    var event = new DeviceLightEvent(new Boolean(true));
+    assert_equals(event.type, 'true');
+  }, 'type argument is instance of boolean');
+
+  test(function() {
+    var event = new DeviceLightEvent(false);
+    assert_equals(event.type, 'false');
+  }, 'type argument is boolean (false)');
+
+  test(function() {
+    var event = new DeviceLightEvent(new Boolean(false));
+    assert_equals(event.type, 'false');
+  }, '');
+
+  test(function() {
+    var event = new DeviceLightEvent('test');
+    assert_equals(event.type, 'test');
+  }, 'type argument is instance of boolean (false)');
+
+  test(function() {
+    var event = new DeviceLightEvent(new String('test'));
+    assert_equals(event.type, 'test');
+  }, 'type argument is string');
+
+  test(function() {
+    var event = new DeviceLightEvent(function test() {});
+    assert_equals(event.type, 'function test() {}');
+  }, 'type argument is function');
+
+  test(function() {
+    var event = new DeviceLightEvent({
+      toString: function() {
+        return '123';
+      }
     });
+    assert_equals(event.type, '123');
+  }, 'type argument is complext object, with toString method');
 
-    var t2 = async_test('test if user proximity event recieved');
-    window.ondevicelight = function(e) {
-        t2.step(function() {
-            var msg = 'expected instance of DeviceLightEvent: ';
-            assert_true(e instanceof window.DeviceLightEvent, msg);
-        });
-        t2.done();
+  test(function() {
+    assert_throws(TypeError(), function() {
+      new DeviceLightEvent({
+        toString: function() {
+          return function() {}
+        }
+      });
+    });
+  }, 'toString is of type function');
+
+  //test readonly attribute double value;
+  test(function() {
+    var event = new DeviceLightEvent('test');
+    assert_readonly(event, 'value', 'readonly attribute value');
+  }, 'value is readonly');
+
+  test(function() {
+    var event = new DeviceLightEvent('test', {
+      value: false
+    });
+    assert_equals(event.value, 0, 'value set to false');
+  }, 'value set to false');
+
+  test(function() {
+    var event = new DeviceLightEvent('test', {
+      value: true
+    });
+    assert_equals(event.value, 1, 'value set to true');
+  }, 'value set to true');
+
+
+  test(function() {
+    var prop = {
+      value: undefined
     };
+    assert_throws(TypeError(), function() {
+      new DeviceLightEvent('test', prop);
+    }, 'value resolves to NaN');
+  }, 'value resolves to NaN, expected type error');
+
+  test(function() {
+    var event = new DeviceLightEvent('test', {
+      value: null
+    });
+    assert_equals(event.value, 0, 'value resolves to 0');
+  }, 'value resolves to 0');
+
+
+  test(function() {
+    var event = new DeviceLightEvent('test', {
+      value: ''
+    });
+    assert_equals(event.value, false, 'value must resolve to 0');
+  }, 'value must resolve to 0');
+
+  test(function() {
+    var event = new DeviceLightEvent('test', {
+      value: '\u0020'
+    });
+    assert_equals(event.value, true, 'value must resolve to 0');
+  }, 'value must resolve to 0');
+
+  test(function() {
+    var event = new DeviceLightEvent('test', {
+      value: '\u0020\u0020\u0020\u0020\u0020\u0020'
+    });
+    assert_equals(event.value, true, 'value must resolve to 0');
+  }, 'value must resolve to 0');
+
+  test(function() {
+    var event = new DeviceLightEvent('test', {
+      value: '\u0020\u0020\u00201234\u0020\u0020\u0020'
+    });
+    assert_equals(event.value, 1234, 'converts to 1234');
+  }, 'converts to 1234');
+
+  test(function() {
+    var event = new DeviceLightEvent('test', {
+      value: []
+    });
+    assert_equals(event.value, 0, 'converts to 0');
+  }, 'converts to 0');
+
+
+  test(function() {
+    var prop = {
+      value: {}
+    };
+    assert_throws(TypeError(), function() {
+      new DeviceLightEvent('test', prop);
+    }, 'value of {} resolves to NaN');
+  }, 'value resolves to NaN, expected type error');
+
+  test(function() {
+    var prop = {
+      get value() {
+        return 123;
+      }
+    };
+    assert_throws(TypeError(), function() {
+      new DeviceLightEvent('test', prop);
+    }, 'value of {} resolves to NaN');
+  }, 'value resolves to NaN, expected type error');
+
+
+  test(function() {
+    var desc = 'Expected to find ondevicelight attribute on window object';
+    assert_own_property(window, 'ondevicelight', desc);
+  }, 'ondevicelight exists');
+
+  test(function() {
+    var desc = 'window.ondevicelight must be null';
+    assert_equals(window.ondevicelight, null, desc);
+  }, 'ondevicelight is null');
+
+  test(function() {
+    var desc = 'window.ondevicelight did not accept callable object',
+      func = function() {};
+    window.ondevicelight = func;
+    assert_equals(window.ondevicelight, func, desc);
+  }, 'ondevicelight is set to function');
+
+  test(function() {
+    var desc = 'window.ondevicelight did not treat noncallable as null';
+    window.ondevicelight = function() {};
+    window.ondevicelight = {};
+    assert_equals(window.ondevicelight, null, desc);
+  }, 'treat object as null');
+
+  test(function() {
+    var desc = 'window.ondevicelight did not treat noncallable as null';
+    window.ondevicelight = function() {};
+    window.ondevicelight = {
+      call: 'test'
+    };
+    assert_equals(window.ondevicelight, null, desc);
+  }, 'treat object with non-callable call property as null');
+
+  test(function() {
+    var desc = 'window.ondevicelight did not treat noncallable as null',
+      test = function() {};
+    test.call = 'test';
+    window.ondevicelight = function() {};
+    window.ondevicelight = test;
+    assert_equals(window.ondevicelight, null, desc);
+  }, 'treat object with non-callable call property as null');
+
+  test(function() {
+    var desc = 'window.ondevicelight did not treat noncallable (string) as null';
+    window.ondevicelight = function() {};
+    window.ondevicelight = 'string';
+    assert_equals(window.ondevicelight, null, desc);
+  }, 'treat string as null');
+
+  test(function() {
+    var desc = 'window.ondevicelight did not treat noncallable (number) as null';
+    window.ondevicelight = function() {};
+    window.ondevicelight = 123;
+    assert_equals(window.ondevicelight, null, desc);
+  }, 'treat number as null');
+
+  test(function() {
+    var desc = 'window.ondevicelight did not treat noncallable (undefined) as null';
+    window.ondevicelight = function() {};
+    window.ondevicelight = undefined;
+    assert_equals(window.ondevicelight, null, desc);
+  }, 'treat undefined as null');
+
+  test(function() {
+    var desc = 'window.ondevicelight did not treat noncallable (array) as null';
+    window.ondevicelight = function() {};
+    window.ondevicelight = [];
+    assert_equals(window.ondevicelight, null, desc);
+  }, 'treat array as null');
+
+  test(function() {
+    var desc = 'window.ondevicelight did not treat noncallable host object as null';
+    window.ondevicelight = function() {};
+    window.ondevicelight = window.Node;
+    assert_equals(window.ondevicelight, null, desc);
+  }, 'treat non-callable host object as null');
+
+  //Async tests
+  var t = async_test('test if DeviceLightEvent recieved');
+  window.addEventListener('devicelight', function(e) {
+    t.step(function() {
+      var msg = 'expected instance of DeviceLightEvent: ';
+      assert_true(e instanceof window.DeviceLightEvent, msg);
+    });
+    t.done();
+  });
+
+  var t2 = async_test('test if DeviceLightEvent recieved');
+  window.ondevicelight = function(e) {
+    t2.step(function() {
+      var msg = 'expected instance of DeviceLightEvent: ';
+      assert_true(e instanceof window.DeviceLightEvent, msg);
+    });
+    t2.done();
+  };
+
 })();