Skip to content

Commit

Permalink
rework test infra. Fixes #22. Ref #6.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastien Pereira committed Sep 2, 2014
1 parent cafb772 commit 6c6826c
Show file tree
Hide file tree
Showing 17 changed files with 428 additions and 161 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
16 changes: 13 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
language: node_js
node_js: "0.10"
install: "npm -g install jshint@2.4.x"
script: "jshint ."
node_js:
- '0.10'
install:
- npm install -g grunt-cli
- npm -g install bower
- npm install
- bower install
script:
- grunt jshint test:remote
env:
global:
- secure: eY1OxvXmDHrxYoO5hQwcWNptaJClL69aswUw5G+ZNppSEymNCTquYN/MS87iZm76G98o4A0aafM989d5UDhjU187NYdxf6K7jEPwtaxuHi6d48M0LRG/DoAWCNOUoNyNuhpRCVEB7XmwvZOG9nmoRcPvt+KjM5VkiOvp+CluCk0=
- secure: F0RyTrC3kdKomLNbKXJJA1Ju0ZCnB5E7oW7eYwkikLjlfn/4rBkuX4MYJqGBdCIwotpx0k30Wmql7cpYsk9pfM36NIqZoY3bOMITAY/FR8gxiE6zLjFEV/JBdY1hKIeDStsCEPJIRPd27oq4yK1j8dVFel9rI+aENWV1+CZ7o7o=
73 changes: 73 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* global module */
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),

jshint: {
src: [
"**/*.js", "!{node_modules,dev}/**"
],
options: {
jshintrc: ".jshintrc"
}
},

intern: {
// run tests on local desktop browser(s)
local: {
options: {
runType: "runner",
config: "tests/intern/local",
reporters: ["runner"]
}
},
// run tests on remote cloud service
remote: {
options: {
runType: "runner",
config: "tests/intern/saucelab",
reporters: ["runner"]
}
}
}
});

// Load plugins
grunt.loadNpmTasks("intern");
grunt.loadNpmTasks("grunt-contrib-jshint");

// Aliases
grunt.registerTask("default", ["jshint"]);

// Testing.
// always specify the target e.g. grunt test:remote, grunt test:remote
// then add on any other flags afterwards e.g. console, lcovhtml
var testTaskDescription = "Run this task instead of the intern task directly! \n" +
"Always specify the test target e.g. \n" +
"grunt test:local\n" +
"grunt test:local.android\n" +
"grunt test:local.ios\n" +
"grunt test:remote\n\n" +
"Add any optional reporters via a flag e.g. \n" +
"grunt test:local:console\n" +
"grunt test:local:lcovhtml\n" +
"grunt test:local:console:lcovhtml";
grunt.registerTask("test", testTaskDescription, function (target) {
function addReporter(reporter) {
var property = "intern." + target + ".options.reporters",
value = grunt.config.get(property);
if (value.indexOf(reporter) !== -1) {
return;
}
value.push(reporter);
grunt.config.set(property, value);
}
if (this.flags.lcovhtml) {
addReporter("lcovhtml");
}
if (this.flags.console) {
addReporter("console");
}
grunt.task.run("intern:" + target);
});
};
8 changes: 5 additions & 3 deletions handlers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ define([

// Check if MouseEvent constructor is supported.
try {
new MouseEvent("mousedown", {}); // jshint ignore:line
//jshint nonew: false
new MouseEvent("mousedown", {});
//jshint nonew: true
utils.SUPPORT_MOUSE_EVENT_CONSTRUCTOR = true;
} catch (e) {
}
Expand Down Expand Up @@ -253,6 +255,7 @@ define([
* @param props event properties
* @returns MouseEvent
*/
/*jshint maxcomplexity: 15*/
function createMouseEvent(pointerType, props) {
// Mouse Event spec
// http://www.w3.org/TR/2001/WD-DOM-Level-3-Events-20010823/events.html#Events-eventgroupings-mouseevents
Expand All @@ -261,7 +264,7 @@ define([
return new MouseEvent(pointerType, props);
}
var e = document.createEvent("MouseEvents");
/* jshint ignore:start */

e.initMouseEvent(
pointerType,
(props.bubbles),
Expand All @@ -279,7 +282,6 @@ define([
(props.button) || 0,
(props.relatedTarget) ||
null);
/* jshint ignore:end */
return e;
}

Expand Down
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "dpointer",
"version": "0.1.1-dev",
"dependencies": {
},
"devDependencies": {
"intern": "1.6.x",
"grunt": "~0.4.2",
"grunt-contrib-jshint": "~0.6.3"
},
"licenses": [
{
"type": "BSD",
"url": "https://github.com/ibm-js/dpointer/blob/master/LICENSE"
}
],
"bugs": "https://github.com/ibm-js/dpointer/issues"
}
40 changes: 22 additions & 18 deletions tests/capture/capture1.html → samples/capture.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<meta name="viewport"
content="width=device-width, initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<title>Pointer Events: capture > capture1</title>

<style>
Expand All @@ -23,24 +24,15 @@
}

#container {
height: 200px;
width: 200px;
height: auto;
width: auto;
background-color: #AAAAAA;
margin: 0;
padding: 10px;
top: 0;
left: 0;
position: absolute;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}

.btn {
top: 30px;
left: 5px;
width: 150px;
height: 35px;
color: #000000;
Expand All @@ -53,6 +45,11 @@
border-color: #000000;
border-radius: 10%;
cursor: pointer;
-webkit-touch-callout: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}

.btn:active {
Expand All @@ -62,11 +59,9 @@
}

#msgArea {
color: white;
background-color: orange;
position: relative;
margin: 0;
top: 200px;
left: 0;
padding: 0;
color: #000000;
Expand All @@ -75,12 +70,12 @@
}
</style>

<script>var require = {baseUrl: "../../.."}</script>
<script type="text/javascript" src="../../../requirejs/require.js"></script>
<script>var require = {baseUrl: "../.."}</script>
<script type="text/javascript" src="../../requirejs/require.js"></script>
<script type="text/javascript">
requirejs([
"dpointer/events",
"domReady/domReady!"
"requirejs-domready/domReady!"
], function(pointer){
var msgArea = document.getElementById("msgArea");

Expand All @@ -107,6 +102,15 @@
logit(event.target.id + ":pointermove (" + event.clientX + "/" + event.clientY + ")");
});

// disable text selection
msgArea.addEventListener("selectstart", function (e) {
e.preventDefault();
}, false);

// clear log on double click
msgArea.addEventListener("dblclick", function(event){
msgArea.innerHTML = "";
});

function logit(msg){
msgArea.innerHTML = msg + "</br>" + msgArea.innerHTML;
Expand All @@ -121,6 +125,6 @@
&#160;
<div id="capturedBtn" class="btn">CAPTURE</div>
</div>
<div id="msgArea">== LOG ==</div>
<div id="msgArea" touch-action="pan-x pan-y">== LOG ==</div>
</body>
</html>
23 changes: 11 additions & 12 deletions tests/paint/paint2.html → samples/paint-with-capture.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<!DOCTYPE html>
<!--
. This sample relies on
pointer capture rather than pointermove and event.button value.
Simple paint application to demonstrate multi touch handling with Pointer Events, using dpointer API.
This sample relies on pointer capture rather than pointermove and event.button value.
Sample paint application to demonstrate multi touch handling. This sample illustrate a possible usage of
pointer capture. IE9 doesn't reflect pressed button state on mousemove events. Pointer capture allow to get over
this limitation.
This sample illustrate a possible usage of pointer capture. IE9 doesn't reflect pressed button state on
mousemove events. Pointer capture allow to get over this limitation.
Simply change the device orientation to reset the canvas.
Number of active touch point depends on hardware capabilities and system option.
The number of active touch point depends on hardware capabilities and system option.
To use more than 3 touch points on iOS, disable Mutitasking Gestures in Settings > General.
Double Tab/click to clear the canvas.
Tested on:
- Android 4.1.1: stockbrowser + Chrome
Expand Down Expand Up @@ -49,12 +48,12 @@
}
</style>

<script>var require = {baseUrl: "../../.."}</script>
<script type="text/javascript" src="../../../requirejs/require.js"></script>
<script>var require = {baseUrl: "../.."}</script>
<script type="text/javascript" src="../../requirejs/require.js"></script>
<script type="text/javascript">
requirejs([
"dpointer/events",
"domReady/domReady!"
"requirejs-domready/domReady!"
], function(pointer){
var canvas = document.getElementById("drawingArea");
var context = canvas.getContext("2d");
Expand Down Expand Up @@ -88,8 +87,8 @@
context.fillRect(event.clientX, event.clientY, 5, 5);
}
});
// reset canvas on orientation change
window.addEventListener("resize", function(){
// reset canvas on double tap/click
canvas.addEventListener("dblclick", function(){
canvas.height = window.innerHeight;
canvas.width = window.innerWidth;
});
Expand Down
16 changes: 8 additions & 8 deletions tests/paint/paint1.html → samples/paint.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!DOCTYPE html>
<!--
Sample paint application to demonstrate multi touch handling with pointer events.
Simply change the device orientation to reset the canvas.
Number of active touch point depends on hardware capabilities and system option.
Simple paint application to demonstrate multi touch handling with Pointer Events, using dpointer API.
The number of active touch point depends on hardware capabilities and system option.
To use more than 3 touch points on iOS, disable Mutitasking Gestures in Settings > General.
Double Tab/click to clear the canvas.
Tested on:
- Android 4.1.1: stockbrowser + Chrome
Expand Down Expand Up @@ -43,12 +43,12 @@
}
</style>

<script>var require = {baseUrl: "../../.."}</script>
<script type="text/javascript" src="../../../requirejs/require.js"></script>
<script>var require = {baseUrl: "../.."}</script>
<script type="text/javascript" src="../../requirejs/require.js"></script>
<script type="text/javascript">
requirejs([
"dpointer/events",
"domReady/domReady!"
"requirejs-domready/domReady!"
], function(pointer){
try {
var canvas = document.getElementById("drawingArea");
Expand All @@ -64,8 +64,8 @@
}
});

// reset canvas on orientation change
window.addEventListener("resize", function(){
// reset canvas on double tap/click
canvas.addEventListener("dblclick", function(){
canvas.height = window.innerHeight;
canvas.width = window.innerWidth;
});
Expand Down
15 changes: 15 additions & 0 deletions tests/intern/TestUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Utilities for unit tests
*/
define([], function () {
// avoid failure on IE9: console is not be defined when dev tools is not opened
if (!window.console) {
window.console = {};
}
if (!window.console.log) {
window.console.log = function () {
};
}
return this;
}
);
Loading

0 comments on commit 6c6826c

Please sign in to comment.