Skip to content

Commit

Permalink
Added initial UserProximityEvent tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoscaceres-remote committed May 21, 2012
1 parent 70e29e0 commit 289ce24
Show file tree
Hide file tree
Showing 3 changed files with 248 additions and 38 deletions.
96 changes: 60 additions & 36 deletions DeviceProximityEvent_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
* To the extent possible under law, Marcos Caceres has waived all copyright and
* related or neighboring rights to DeviceProximityEvent Implementation.
**/
test(function() {
assert_throws(TypeError(), function() {
new DeviceProximityEvent();
}, 'First argument is required, so was expecting a TypeError.');
}, 'Missing type argument');

//inheritance tests
test(function() {
var event = new DeviceProximityEvent('');
assert_true(event instanceof window.DeviceProximityEvent);
Expand All @@ -21,96 +17,124 @@ test(function() {
}, 'the event inherits from Event');

//Type attribute tests
test(function() {
assert_throws(TypeError(), function() {
new DeviceProximityEvent();
}, 'First argument is required, so was expecting a TypeError.');
}, 'Missing type argument');

test(function() {
var event = new DeviceProximityEvent(undefined);
assert_equals(event.type, 'undefined');
}, 'Event type set to undefined');

test(function() {
event = new DeviceProximityEvent(null);
var event = new DeviceProximityEvent(null);
assert_equals(event.type, 'null');
}, '');
}, 'type argument is null');

test(function() {
event = new DeviceProximityEvent(123);
var event = new DeviceProximityEvent(123);
assert_equals(event.type, '123');
}, '');
}, 'type argument is number');

test(function() {
event = new DeviceProximityEvent(new Number(123));
var event = new DeviceProximityEvent(new Number(123));
assert_equals(event.type, '123');
}, '');
}, 'type argument is Number');

test(function() {
event = new DeviceProximityEvent([]);
var event = new DeviceProximityEvent([]);
assert_equals(event.type, '');
}, '');
}, 'type argument is array');

test(function() {
event = new DeviceProximityEvent(new Array());
var event = new DeviceProximityEvent(new Array());
assert_equals(event.type, '');
}, '');
}, 'type argument is instance of Array');

test(function() {
event = new DeviceProximityEvent(['t', ['e', ['s', ['t']]]]);
var event = new DeviceProximityEvent(['t', ['e', ['s', ['t']]]]);
assert_equals(event.type, 't,e,s,t');
}, '');
}, 'type argument is nested array');

test(function() {
event = new DeviceProximityEvent(Math);
var event = new DeviceProximityEvent(Math);
assert_equals(event.type, '[object Math]');
}, '');
}, 'type argument is host object');

test(function() {
event = new DeviceProximityEvent(true);
var event = new DeviceProximityEvent(true);
assert_equals(event.type, 'true');
}, '');
}, 'type argument is boolean (true)');

test(function() {
event = new DeviceProximityEvent(new Boolean(true));
var event = new DeviceProximityEvent(new Boolean(true));
assert_equals(event.type, 'true');
}, '');
}, 'type argument is instance of boolean');

test(function() {
event = new DeviceProximityEvent(false);
var event = new DeviceProximityEvent(false);
assert_equals(event.type, 'false');
}, '');
}, 'type argument is boolean (false)');

test(function() {
event = new DeviceProximityEvent(new Boolean(false));
var event = new DeviceProximityEvent(new Boolean(false));
assert_equals(event.type, 'false');
}, '');

test(function() {
event = new DeviceProximityEvent('test');
var event = new DeviceProximityEvent('test');
assert_equals(event.type, 'test');
}, '');
}, 'type argument is instance of boolean (false)');

test(function() {
event = new DeviceProximityEvent(new String('test'));
var event = new DeviceProximityEvent(new String('test'));
assert_equals(event.type, 'test');
}, '');
}, 'type argument is string');

test(function() {
event = new DeviceProximityEvent(function test() {});
var event = new DeviceProximityEvent(function test() {});
assert_equals(event.type, 'function test() {}');
}, '');
}, 'type argument is function');

test(function() {
event = new DeviceProximityEvent({
var event = new DeviceProximityEvent({
toString: function() {
return '123';
}
});
assert_equals(event.type, '123');
}, '');
}, 'type argument is complext object, with toString method');

test(function() {
assert_throws(TypeError(), function() {
new new DeviceProximityEvent({
new DeviceProximityEvent({
toString: function() {
return function() {}
}
});
});
}, '');
}, 'toString is of type function');

//test readonly attribute double value;
test(function() {
var event = new DeviceProximityEvent('test');
assert_readonly(event, 'value', 'readonly attribute value');
}
, 'value attribute is readonly');

//test readonly attribute double min
test(function() {
var event = new DeviceProximityEvent('test');
assert_readonly(event, 'min', 'readonly attribute min');
}
, 'min attribute is readonly');

//readonly attribute double max;
test(function() {
var event = new DeviceProximityEvent('test');
assert_readonly(event, 'max', 'readonly attribute max');
}
, 'max attribute is readonly');

185 changes: 185 additions & 0 deletions UserProximityEvent_tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
/**
* UserProximityEvent_tests.js
* Public Domain Software
* To the extent possible under law, Marcos Caceres has waived all copyright and
* related or neighboring rights to UserProximityEvent Implementation.
**/

//inheritance tests
test(function() {
var event = new UserProximityEvent('');
assert_true(event instanceof window.UserProximityEvent);
}, 'the event is an instance of UserProximityEvent');

test(function() {
var event = new UserProximityEvent('');
assert_true(event instanceof window.Event);
}, 'the event inherits from Event');

//Type attribute tests
test(function() {
assert_throws(TypeError(), function() {
new UserProximityEvent();
}, 'First argument is required, so was expecting a TypeError.');
}, 'Missing type argument');

test(function() {
var event = new UserProximityEvent(undefined);
assert_equals(event.type, 'undefined');
}, 'Event type set to undefined');

test(function() {
var event = new UserProximityEvent(null);
assert_equals(event.type, 'null');
}, 'type argument is null');

test(function() {
var event = new UserProximityEvent(123);
assert_equals(event.type, '123');
}, 'type argument is number');

test(function() {
var event = new UserProximityEvent(new Number(123));
assert_equals(event.type, '123');
}, 'type argument is Number');

test(function() {
var event = new UserProximityEvent([]);
assert_equals(event.type, '');
}, 'type argument is array');

test(function() {
var event = new UserProximityEvent(new Array());
assert_equals(event.type, '');
}, 'type argument is instance of Array');

test(function() {
var event = new UserProximityEvent(['t', ['e', ['s', ['t']]]]);
assert_equals(event.type, 't,e,s,t');
}, 'type argument is nested array');

test(function() {
var event = new UserProximityEvent(Math);
assert_equals(event.type, '[object Math]');
}, 'type argument is host object');

test(function() {
var event = new UserProximityEvent(true);
assert_equals(event.type, 'true');
}, 'type argument is boolean (true)');

test(function() {
var event = new UserProximityEvent(new Boolean(true));
assert_equals(event.type, 'true');
}, 'type argument is instance of boolean');

test(function() {
var event = new UserProximityEvent(false);
assert_equals(event.type, 'false');
}, 'type argument is boolean (false)');

test(function() {
var event = new UserProximityEvent(new Boolean(false));
assert_equals(event.type, 'false');
}, '');

test(function() {
var event = new UserProximityEvent('test');
assert_equals(event.type, 'test');
}, 'type argument is instance of boolean (false)');

test(function() {
var event = new UserProximityEvent(new String('test'));
assert_equals(event.type, 'test');
}, 'type argument is string');

test(function() {
var event = new UserProximityEvent(function test() {});
assert_equals(event.type, 'function test() {}');
}, 'type argument is function');

test(function() {
var event = new UserProximityEvent({
toString: function() {
return '123';
}
});
assert_equals(event.type, '123');
}, 'type argument is complext object, with toString method');

test(function() {
assert_throws(TypeError(), function() {
new UserProximityEvent({
toString: function() {
return function() {}
}
});
});
}, 'toString is of type function');

//test readonly attribute boolean near;
test(function() {
var event = new UserProximityEvent('test');
assert_readonly(event, 'near', 'readonly attribute near');
}, 'near is readonly');

//test attribute boolean near;
test(function() {
var event = new UserProximityEvent('test', {near: false});
assert_equals(event.near, false, 'near set to false');
}, 'near set to false');

//test attribute boolean near;
test(function() {
var event = new UserProximityEvent('test', {near: true});
assert_equals(event.near, true, 'near set to true');
}, 'near set to true');

//test attribute boolean near;
test(function() {
var event = new UserProximityEvent('test', {near: undefined});
assert_equals(event.near, false, 'argument is truthy');
}, 'near set to a falsy object');


test(function() {
var event = new UserProximityEvent('test', {near: null});
assert_equals(event.near, false, 'argument is flasy');
}, 'near set to a falsy object');

test(function() {
var event = new UserProximityEvent('test', {near: 0});
assert_equals(event.near, false, 'argument is flasy');
}, 'near set to a falsy object');

test(function() {
var event = new UserProximityEvent('test', {near: ''});
assert_equals(event.near, false, 'argument is flasy');
}, 'near set to a falsy object');

test(function() {
var event = new UserProximityEvent('test', {near: '\u0020'});
assert_equals(event.near, true, 'argument is truthy');
}, 'near set to a truthy object');

test(function() {
var event = new UserProximityEvent('test', {near: 1});
assert_equals(event.near, true, 'argument is truthy');
}, 'near set to a truthy object');

test(function() {
var event = new UserProximityEvent('test', {near: []});
assert_equals(event.near, true, 'argument is truthy');
}, 'near set to a truthy object');

test(function() {
var event = new UserProximityEvent('test', {near: {}});
assert_equals(event.near, true, 'argument is truthy');
}, 'near set to a truthy object');

test(function() {
var dict = {get test() {return false}};
var event = new UserProximityEvent('test', {near: dict.test});
assert_equals(event.near, false, 'explict false');
}, 'near set to object that resolves to false');

5 changes: 3 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<!doctype html>
<title>DeviceProximityEvent and UserProximity</title>
<script src="http://www.w3c-test.org/resources/testharness.js"></script>
<script src="//www.w3c-test.org/resources/testharness.js"></script>
<script src="DeviceProximityEvent.js"></script>
<script src="UserProximityEvent.js"></script>
<script src="DeviceProximityEvent_tests.js"></script>
<h1>Reference implementation of DeviceProximityEvent</h1>
<script src="UserProximityEvent_tests.js"></script>
<h1>Reference implementation of Device/UserProximityEvent</h1>
<div id="log"></div>

0 comments on commit 289ce24

Please sign in to comment.