From 3909e6d89e01e4cd8777377c63037896bb95aa2f Mon Sep 17 00:00:00 2001
From: Leif Johansson <leifj@sunet.se>
Date: Fri, 25 Nov 2011 21:18:19 +0100
Subject: new jq layout

---
 .../jquery-ui-1.9pre/tests/unit/draggable/all.html |  30 +
 .../tests/unit/draggable/draggable.html            |  60 ++
 .../tests/unit/draggable/draggable_core.js         |  67 ++
 .../tests/unit/draggable/draggable_defaults.js     |  36 +
 .../tests/unit/draggable/draggable_events.js       |  81 +++
 .../tests/unit/draggable/draggable_methods.js      |  99 +++
 .../tests/unit/draggable/draggable_options.js      | 753 +++++++++++++++++++++
 7 files changed, 1126 insertions(+)
 create mode 100644 src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/all.html
 create mode 100644 src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable.html
 create mode 100644 src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_core.js
 create mode 100644 src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_defaults.js
 create mode 100644 src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_events.js
 create mode 100644 src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_methods.js
 create mode 100644 src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_options.js

(limited to 'src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable')

diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/all.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/all.html
new file mode 100644
index 0000000..3796d3f
--- /dev/null
+++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/all.html
@@ -0,0 +1,30 @@
+<!doctype html>
+<html lang="en">
+<head>
+	<meta charset="utf-8">
+	<title>jQuery UI Draggable Test Suite</title>
+
+	<script src="../../../jquery-1.7.1.js"></script>
+
+	<link rel="stylesheet" href="../../../external/qunit.css">
+	<link rel="stylesheet" href="../subsuiteRunner.css">
+	<script src="../../../external/qunit.js"></script>
+	<script src="../subsuiteRunner.js"></script>
+	<script src="../subsuite.js"></script>
+
+	<script>
+	testAllVersions( "draggable" );
+	</script>
+</head>
+<body>
+
+<h1 id="qunit-header">jQuery UI Draggable Test Suite</h1>
+<h2 id="qunit-banner"></h2>
+<div id="qunit-testrunner-toolbar"></div>
+<h2 id="qunit-userAgent"></h2>
+<ol id="qunit-tests"></ol>
+<div id="qunit-fixture">
+
+</div>
+</body>
+</html>
diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable.html
new file mode 100644
index 0000000..5be71f4
--- /dev/null
+++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable.html
@@ -0,0 +1,60 @@
+<!doctype html>
+<html lang="en">
+<head>
+	<meta charset="utf-8">
+	<title>jQuery UI Draggable Test Suite</title>
+
+	<script src="../../jquery.js"></script>
+	<script src="../../resource_loader.js"></script>
+	<script>
+	loadResources({
+		css: [ "ui.core" ],
+		js: [
+			"ui/jquery.ui.core.js",
+			"ui/jquery.ui.widget.js",
+			"ui/jquery.ui.mouse.js",
+			"ui/jquery.ui.draggable.js"
+		]
+	});
+	</script>
+
+	<link rel="stylesheet" href="../../../external/qunit.css">
+	<script src="../../../external/qunit.js"></script>
+	<script src="../../jquery.simulate.js"></script>
+	<script src="../testsuite.js"></script>
+
+	<script src="draggable_core.js"></script>
+	<script src="draggable_defaults.js"></script>
+	<script src="draggable_events.js"></script>
+	<script src="draggable_methods.js"></script>
+	<script src="draggable_options.js"></script>
+
+	<script>
+	// disable this stale testsuite for testswarm only
+	var url = window.location.search;
+	url = decodeURIComponent( url.slice( url.indexOf("swarmURL=") + 9 ) );
+	if ( url && url.indexOf("http") == 0 ) {
+		// reset config to kill previous tests; make sure testsuite.js is loaded afterwards to init the testswarm script
+		QUnit.init();
+		test("draggable", function() { ok(true, "disabled draggable testsuite"); });
+	}
+	</script>
+	<script src="../swarminject.js"></script>
+</head>
+<body>
+
+<h1 id="qunit-header">jQuery UI Draggable Test Suite</h1>
+<h2 id="qunit-banner"></h2>
+<div id="qunit-testrunner-toolbar"></div>
+<h2 id="qunit-userAgent"></h2>
+<ol id="qunit-tests"></ol>
+<div id="qunit-fixture">
+
+<div id="draggable1" style="background: green; width: 200px; height: 100px;">Relative</div>
+<div id="draggable2" style="background: green; width: 200px; height: 100px; position: absolute; top: 10px; left: 10px;"><span>Absolute</span></div>
+<div style='width: 1px; height: 1000px;'></div>
+<div style="position: absolute; width: 1px; height: 2000px;"></div>
+
+</div>
+</body>
+</html>
diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_core.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_core.js
new file mode 100644
index 0000000..a01de40
--- /dev/null
+++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_core.js
@@ -0,0 +1,67 @@
+/*
+ * draggable_core.js
+ */
+
+var el, offsetBefore, offsetAfter, dragged;
+
+var drag = function(handle, dx, dy) {
+	var element = el.data("draggable").element;
+	offsetBefore = el.offset();
+	$(handle).simulate("drag", {
+		dx: dx || 0,
+		dy: dy || 0
+	});
+	dragged = { dx: dx, dy: dy };
+	offsetAfter = el.offset();
+}
+
+var moved = function (dx, dy, msg) {
+	msg = msg ? msg + "." : "";
+	var actual = { left: offsetAfter.left, top: offsetAfter.top };
+	var expected = { left: offsetBefore.left + dx, top: offsetBefore.top + dy };
+	same(actual, expected, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ' + msg);
+}
+
+function restoreScroll(what) {
+	if(what) {
+		$(document).scrollTop(0); $(document).scrollLeft(0);
+	} else {
+		$("#main")[0].scrollTop = 0; $("#main")[0].scrollLeft = 0;
+	}
+}
+
+(function($) {
+
+module("draggable");
+
+test("element types", function() {
+	var typeNames = ('p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form'
+		+ ',table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr'
+		+ ',acronym,code,samp,kbd,var,img,object,hr'
+		+ ',input,button,label,select,iframe').split(',');
+
+	$.each(typeNames, function(i) {
+		var typeName = typeNames[i];
+		el = $(document.createElement(typeName)).appendTo('body');
+		(typeName == 'table' && el.append("<tr><td>content</td></tr>"));
+		el.draggable({ cancel: '' });
+		drag(el, 50, 50);
+		moved(50, 50, "&lt;" + typeName + "&gt;");
+		el.draggable("destroy");
+		el.remove();
+	});
+});
+
+test("No options, relative", function() {
+	el = $("#draggable1").draggable();
+	drag(el, 50, 50);
+	moved(50, 50);
+});
+
+test("No options, absolute", function() {
+	el = $("#draggable2").draggable();
+	drag(el, 50, 50);
+	moved(50, 50);
+});
+
+})(jQuery);
diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_defaults.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_defaults.js
new file mode 100644
index 0000000..4b0aaca
--- /dev/null
+++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_defaults.js
@@ -0,0 +1,36 @@
+/*
+ * draggable_defaults.js
+ */
+
+var draggable_defaults = {
+	addClasses: true,
+	appendTo: "parent",
+	axis: false,
+	cancel: ":input,option",
+	connectToSortable: false,
+	containment: false,
+	cursor: "auto",
+	cursorAt: false,
+	delay: 0,
+	disabled: false,
+	distance: 1,
+	grid: false,
+	handle: false,
+	helper: "original",
+	iframeFix: false,
+	opacity: false,
+	refreshPositions: false,
+	revert: false,
+	revertDuration: 500,
+	scroll: true,
+	scrollSensitivity: 20,
+	scrollSpeed: 20,
+	scope: "default",
+	snap: false,
+	snapMode: "both",
+	snapTolerance: 20,
+	stack: false,
+	zIndex: false
+};
+
+commonWidgetTests('draggable', { defaults: draggable_defaults });
diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_events.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_events.js
new file mode 100644
index 0000000..d92d8ee
--- /dev/null
+++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_events.js
@@ -0,0 +1,81 @@
+/*
+ * draggable_events.js
+ */
+(function($) {
+
+module("draggable: events");
+
+test("callbacks occurance count", function() {
+
+	expect(3);
+
+	var start = 0, stop = 0, dragc = 0;
+	el = $("#draggable2").draggable({
+		start: function() { start++; },
+		drag: function() { dragc++; },
+		stop: function() { stop++; }
+	});
+
+	drag(el, 10, 10);
+
+	equals(start, 1, "start callback should happen exactly once");
+	equals(dragc, 3, "drag callback should happen exactly once per mousemove");
+	equals(stop, 1, "stop callback should happen exactly once");
+
+});
+
+test("stopping the start callback", function() {
+
+	expect(3);
+
+	var start = 0, stop = 0, dragc = 0;
+	el = $("#draggable2").draggable({
+		start: function() { start++; return false; },
+		drag: function() { dragc++; },
+		stop: function() { stop++; }
+	});
+
+	drag(el, 10, 10);
+
+	equals(start, 1, "start callback should happen exactly once");
+	equals(dragc, 0, "drag callback should not happen at all");
+	equals(stop, 0, "stop callback should not happen if there wasnt even a start");
+
+});
+
+test("stopping the drag callback", function() {
+
+	expect(3);
+
+	var start = 0, stop = 0, dragc = 0;
+	el = $("#draggable2").draggable({
+		start: function() { start++;},
+		drag: function() { dragc++; return false;  },
+		stop: function() { stop++; }
+	});
+
+	drag(el, 10, 10);
+
+	equals(start, 1, "start callback should happen exactly once");
+	equals(dragc, 1, "drag callback should happen exactly once");
+	equals(stop, 1, "stop callback should happen, as we need to actively stop the drag");
+
+});
+
+test("stopping the stop callback", function() {
+
+	expect(1);
+
+	el = $("#draggable2").draggable({
+		helper: 'clone',
+		stop: function() { return false; }
+	});
+
+	drag(el, 10, 10);
+
+	ok($("#draggable2").data('draggable').helper, "the clone should not be deleted if the stop callback is stopped");
+
+
+});
+
+})(jQuery);
diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_methods.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_methods.js
new file mode 100644
index 0000000..4ffadf0
--- /dev/null
+++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_methods.js
@@ -0,0 +1,99 @@
+/*
+ * draggable_methods.js
+ */
+(function($) {
+
+function shouldmove(why) {
+	drag(el, 50, 50);
+	moved(50, 50, why);
+}
+
+function shouldnotmove(why) {
+	drag(el, 50, 50);
+	moved(0, 0, why);
+}
+
+module("draggable: methods");
+
+test("init", function() {
+	expect(6);
+
+	$("<div></div>").appendTo('body').draggable().remove();
+	ok(true, '.draggable() called on element');
+
+	$([]).draggable();
+	ok(true, '.draggable() called on empty collection');
+
+	$("<div></div>").draggable();
+	ok(true, '.draggable() called on disconnected DOMElement');
+
+	$("<div></div>").draggable().draggable("foo");
+	ok(true, 'arbitrary method called after init');
+
+	$("<div></div>").draggable().draggable("option", "foo");
+	ok(true, 'arbitrary option getter after init');
+
+	$("<div></div>").draggable().draggable("option", "foo", "bar");
+	ok(true, 'arbitrary option setter after init');
+});
+
+test("destroy", function() {
+	$("<div></div>").appendTo('body').draggable().draggable("destroy").remove();
+	ok(true, '.draggable("destroy") called on element');
+
+	$([]).draggable().draggable("destroy");
+	ok(true, '.draggable("destroy") called on empty collection');
+
+	$("<div></div>").draggable().draggable("destroy");
+	ok(true, '.draggable("destroy") called on disconnected DOMElement');
+
+	$("<div></div>").draggable().draggable("destroy").draggable("foo");
+	ok(true, 'arbitrary method called after destroy');
+
+	var expected = $('<div></div>').draggable(),
+		actual = expected.draggable('destroy');
+	equals(actual, expected, 'destroy is chainable');
+});
+
+test("enable", function() {
+	expect(7);
+	el = $("#draggable2").draggable({ disabled: true });
+	shouldnotmove('.draggable({ disabled: true })');
+	el.draggable("enable");
+	shouldmove('.draggable("enable")');
+	equals(el.draggable("option", "disabled"), false, "disabled option getter");
+
+	el.draggable("destroy");
+	el.draggable({ disabled: true });
+	shouldnotmove('.draggable({ disabled: true })');
+	el.draggable("option", "disabled", false);
+	equals(el.draggable("option", "disabled"), false, "disabled option setter");
+	shouldmove('.draggable("option", "disabled", false)');
+	
+	var expected = $('<div></div>').draggable(),
+		actual = expected.draggable('enable');
+	equals(actual, expected, 'enable is chainable');
+});
+
+test("disable", function() {
+	expect(7);
+	el = $("#draggable2").draggable({ disabled: false });
+	shouldmove('.draggable({ disabled: false })');
+	el.draggable("disable");
+	shouldnotmove('.draggable("disable")');
+	equals(el.draggable("option", "disabled"), true, "disabled option getter");
+
+	el.draggable("destroy");
+
+	el.draggable({ disabled: false });
+	shouldmove('.draggable({ disabled: false })');
+	el.draggable("option", "disabled", true);
+	equals(el.draggable("option", "disabled"), true, "disabled option setter");
+	shouldnotmove('.draggable("option", "disabled", true)');
+	
+	var expected = $('<div></div>').draggable(),
+		actual = expected.draggable('disable');
+	equals(actual, expected, 'disable is chainable');
+});
+
+})(jQuery);
diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_options.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_options.js
new file mode 100644
index 0000000..8ba77fb
--- /dev/null
+++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_options.js
@@ -0,0 +1,753 @@
+/*
+ * draggable_options.js
+ */
+(function($) {
+
+function testScroll(position) {
+	$("#main").css('position', position);
+	drag(el, 50, 50);
+	moved(50, 50, position+' parent');
+}
+
+function setScroll(what) {
+	if(what) {
+		$(document).scrollTop(100); $(document).scrollLeft(100);
+	} else {
+		$("#main")[0].scrollTop = 100; $("#main")[0].scrollLeft = 100;
+	}
+}
+
+var border = function(el, side) { return parseInt(el.css('border-' + side + '-width')); }
+
+var margin = function(el, side) { return parseInt(el.css('margin-' + side)); }
+
+module("draggable: options");
+
+test("{ addClasses: true }, default", function() {
+	equals(draggable_defaults.addClasses, true);
+
+	el = $("<div></div>").draggable({ addClasses: true });
+	ok(el.is(".ui-draggable"), "'ui-draggable' class added");
+
+	el.draggable("destroy");
+});
+
+test("{ addClasses: false }", function() {
+	el = $("<div></div>").draggable({ addClasses: false });
+	ok(!el.is(".ui-draggable"), "'ui-draggable' class not added");
+
+	el.draggable("destroy");
+});
+
+test("{ appendTo: 'parent' }, default", function() {
+	equals(draggable_defaults.appendTo, "parent");
+
+	el = $("#draggable2").draggable({ appendTo: 'parent' });
+	drag(el, 50, 50);
+	moved(50, 50);
+	
+	el = $("#draggable1").draggable({ appendTo: 'parent' });
+	drag(el, 50, 50);
+	moved(50, 50);
+
+});
+
+test("{ appendTo: Element }", function() {
+	el = $("#draggable2").draggable({ appendTo: $("#draggable2").parent()[0] });
+	drag(el, 50, 50);
+	moved(50, 50);
+	
+	el = $("#draggable1").draggable({ appendTo: $("#draggable2").parent()[0] });
+	drag(el, 50, 50);
+	moved(50, 50);
+});
+
+test("{ appendTo: Selector }", function() {
+	el = $("#draggable2").draggable({ appendTo: "#main" });
+	drag(el, 50, 50);
+	moved(50, 50);
+	
+	el = $("#draggable1").draggable({ appendTo: "#main" });
+	drag(el, 50, 50);
+	moved(50, 50);
+});
+
+test("{ axis: false }, default", function() {
+	equals(draggable_defaults.axis, false);
+
+	el = $("#draggable2").draggable({ axis: false });
+	drag(el, 50, 50);
+	moved(50, 50);
+});
+
+test("{ axis: 'x' }", function() {
+	el = $("#draggable2").draggable({ axis: "x" });
+	drag(el, 50, 50);
+	moved(50, 0);
+});
+
+test("{ axis: 'y' }", function() {
+	el = $("#draggable2").draggable({ axis: "y" });
+	drag(el, 50, 50);
+	moved(0, 50);
+});
+
+test("{ axis: ? }, unexpected", function() {
+	var unexpected = {
+		"true": true,
+		"{}": {},
+		"[]": [],
+		"null": null,
+		"undefined": undefined,
+		"function() {}": function() {}
+	};
+	$.each(unexpected, function(key, val) {
+		el = $("#draggable2").draggable({ axis: val });
+		drag(el, 50, 50);
+		moved(50, 50, "axis: " + key);
+		el.draggable("destroy");
+	})
+});
+
+test("{ cancel: ':input,option' }, default", function() {
+	equals(draggable_defaults.cancel, ":input,option");
+
+	$('<div id="draggable-option-cancel-default"><input type="text"></div>').appendTo('#main');
+
+	el = $("#draggable-option-cancel-default").draggable({ cancel: ":input,option" });
+	drag("#draggable-option-cancel-default", 50, 50);
+	moved(50, 50);
+
+	el = $("#draggable-option-cancel-default").draggable({ cancel: ":input,option" });
+	drag("#draggable-option-cancel-default :input", 50, 50);
+	moved(0, 0);
+
+	el.draggable("destroy");
+});
+
+test("{ cancel: 'span' }", function() {
+	el = $("#draggable2").draggable();
+	drag("#draggable2 span", 50, 50);
+	moved(50, 50);
+
+	el.draggable("destroy");
+
+	el = $("#draggable2").draggable({ cancel: 'span' });
+	drag("#draggable2 span", 50, 50);
+	moved(0, 0);
+});
+
+test("{ cancel: ? }, unexpected", function() {
+	var unexpected = {
+		"true": true,
+		"false": false,
+		"{}": {},
+		"[]": [],
+		"null": null,
+		"undefined": undefined,
+		"function() {return '';}": function() {return '';},
+		"function() {return true;}": function() {return true;},
+		"function() {return false;}": function() {return false;}
+	};
+	$.each(unexpected, function(key, val) {
+		el = $("#draggable2").draggable({ cancel: val });
+		drag(el, 50, 50);
+		var expected = [50, 50];
+		moved(expected[0], expected[1], "cancel: " + key);
+		el.draggable("destroy");
+	})
+});
+
+test("{ containment: false }, default", function() {
+	equals(draggable_defaults.containment, false);
+
+	ok(false, 'missing test - untested code is broken code');
+});
+
+test("{ containment: Element }", function() {
+	ok(false, 'missing test - untested code is broken code');
+});
+
+test("{ containment: 'parent' }, relative", function() {
+	el = $("#draggable1").draggable({ containment: 'parent' });
+	var p = el.parent(), po = p.offset();
+	drag(el, -100, -100);
+	var expected = {
+		left: po.left + border(p, 'left') + margin(el, 'left'),
+		top: po.top + border(p, 'top') + margin(el, 'top')
+	}
+	same(offsetAfter, expected, 'compare offset to parent');
+});
+
+test("{ containment: 'parent' }, absolute", function() {
+	el = $("#draggable2").draggable({ containment: 'parent' });
+	var p = el.parent(), po = p.offset();
+	drag(el, -100, -100);
+	var expected = {
+		left: po.left + border(p, 'left') + margin(el, 'left'),
+		top: po.top + border(p, 'top') + margin(el, 'top')
+	}
+	same(offsetAfter, expected, 'compare offset to parent');
+});
+
+test("{ containment: 'document' }", function() {
+	ok(false, 'missing test - untested code is broken code');
+});
+
+test("{ containment: 'window' }", function() {
+	ok(false, 'missing test - untested code is broken code');
+});
+
+test("{ containment: Selector }", function() {
+	ok(false, 'missing test - untested code is broken code');
+});
+
+test("{ containment: [x1, y1, x2, y2] }", function() {
+	ok(false, 'missing test - untested code is broken code');
+});
+
+test("{ cursor: 'auto' }, default", function() {
+	equals(draggable_defaults.cursor, 'auto');
+
+	function getCursor() { return $("#draggable2").css("cursor"); }
+
+	expect(3);
+
+	var expected = "auto", actual, before, after;
+
+	el = $("#draggable2").draggable({
+		cursor: expected,
+		start: function(event, ui) {
+			actual = getCursor();
+		}
+	});
+
+	before = getCursor();
+	drag("#draggable2", -1, -1);
+	after = getCursor();
+
+	equals(actual, expected, "start callback: cursor '" + expected + "'");
+	equals(after, before, "after drag: cursor restored");
+
+});
+
+test("{ cursor: 'move' }", function() {
+
+	function getCursor() { return $("body").css("cursor"); }
+
+	expect(2);
+
+	var expected = "move", actual, before, after;
+
+	el = $("#draggable2").draggable({
+		cursor: expected,
+		start: function(event, ui) {
+			actual = getCursor();
+		}
+	});
+
+	before = getCursor();
+	drag("#draggable2", -1, -1);
+	after = getCursor();
+
+	equals(actual, expected, "start callback: cursor '" + expected + "'");
+	equals(after, before, "after drag: cursor restored");
+
+});
+
+test("{ cursorAt: false}, default", function() {
+	equals(draggable_defaults.cursorAt, false);
+
+	ok(false, 'missing test - untested code is broken code');
+});
+
+test("{ cursorAt: { left: -5, top: -5 } }", function() {
+	expect(4);
+
+	var deltaX = -3, deltaY = -3,
+		offsetX = 5, offsetY = 5,
+		cursorAtX = -5, cursorAtY = -5;
+
+	$.each(['relative', 'absolute'], function(i, position) {
+		var el = $('#draggable' + (i + 1)).draggable({
+				cursorAt: { left: cursorAtX, top: cursorAtY },
+				drag: function(event, ui) {
+					equals(ui.offset.left, expected.left, position + ' left');
+					equals(ui.offset.top, expected.top, position + ' top');
+				}
+			}),
+			before = el.offset(),
+			pos = {
+				clientX: before.left + offsetX,
+				clientY: before.top + offsetY
+			},
+			expected = {
+				left: before.left + offsetX - cursorAtX + deltaX,
+				top: before.top + offsetY - cursorAtY + deltaY
+			};
+
+		el.simulate("mousedown", pos);
+		pos.clientX += deltaX;
+		pos.clientY += deltaY;
+		$(document).simulate("mousemove", pos);
+		el.simulate("mouseup", pos);
+	});
+});
+
+test("{ cursorAt: { right: 10, bottom: 20 } }", function() {
+	expect(4);
+
+	var deltaX = -3, deltaY = -3,
+		offsetX = 5, offsetY = 5,
+		cursorAtX = 10, cursorAtY = 20;
+
+	$.each(['relative', 'absolute'], function(i, position) {
+		var el = $('#draggable' + (i + 1)).draggable({
+				cursorAt: { right: cursorAtX, bottom: cursorAtY },
+				drag: function(event, ui) {
+					equals(ui.offset.left, expected.left, position + ' left');
+					equals(ui.offset.top, expected.top, position + ' top');
+				}
+			}),
+			before = el.offset(),
+			pos = {
+				clientX: before.left + offsetX,
+				clientY: before.top + offsetY
+			},
+			expected = {
+				left: before.left + offsetX - el.width() + cursorAtX + deltaX,
+				top: before.top + offsetY - el.height() + cursorAtY + deltaY
+			};
+
+		el.simulate("mousedown", pos);
+		pos.clientX += deltaX;
+		pos.clientY += deltaY;
+		$(document).simulate("mousemove", pos);
+		el.simulate("mouseup", pos);
+	});
+});
+
+test("{ cursorAt: [10, 20] }", function() {
+	expect(4);
+
+	var deltaX = -3, deltaY = -3,
+		offsetX = 5, offsetY = 5,
+		cursorAtX = 10, cursorAtY = 20;
+
+	$.each(['relative', 'absolute'], function(i, position) {
+		var el = $('#draggable' + (i + 1)).draggable({
+				cursorAt: { left: cursorAtX, top: cursorAtY },
+				drag: function(event, ui) {
+					equals(ui.offset.left, expected.left, position + ' left');
+					equals(ui.offset.top, expected.top, position + ' top');
+				}
+			}),
+			before = el.offset(),
+			pos = {
+				clientX: before.left + offsetX,
+				clientY: before.top + offsetY
+			},
+			expected = {
+				left: before.left + offsetX - cursorAtX + deltaX,
+				top: before.top + offsetY - cursorAtY + deltaY
+			};
+
+		el.simulate("mousedown", pos);
+		pos.clientX += deltaX;
+		pos.clientY += deltaY;
+		$(document).simulate("mousemove", pos);
+		el.simulate("mouseup", pos);
+	});
+});
+
+test("{ cursorAt: '20, 40' }", function() {
+	expect(4);
+
+	var deltaX = -3, deltaY = -3,
+		offsetX = 5, offsetY = 5,
+		cursorAtX = 20, cursorAtY = 40;
+
+	$.each(['relative', 'absolute'], function(i, position) {
+		var el = $('#draggable' + (i + 1)).draggable({
+				cursorAt: { left: cursorAtX, top: cursorAtY },
+				drag: function(event, ui) {
+					equals(ui.offset.left, expected.left, position + ' left');
+					equals(ui.offset.top, expected.top, position + ' top');
+				}
+			}),
+			before = el.offset(),
+			pos = {
+				clientX: before.left + offsetX,
+				clientY: before.top + offsetY
+			},
+			expected = {
+				left: before.left + offsetX - cursorAtX + deltaX,
+				top: before.top + offsetY - cursorAtY + deltaY
+			};
+
+		el.simulate("mousedown", pos);
+		pos.clientX += deltaX;
+		pos.clientY += deltaY;
+		$(document).simulate("mousemove", pos);
+		el.simulate("mouseup", pos);
+	});
+});
+
+test("{ distance: 10 }", function() {
+
+	el = $("#draggable2").draggable({ distance: 10 });
+	drag(el, -9, -9);
+	moved(0, 0, 'distance not met');
+
+	drag(el, -10, -10);
+	moved(-10, -10, 'distance met');
+
+	drag(el, 9, 9);
+	moved(0, 0, 'distance not met');
+
+});
+
+test("{ grid: [50, 50] }, relative", function() {
+	el = $("#draggable1").draggable({ grid: [50, 50] });
+	drag(el, 24, 24);
+	moved(0, 0);
+	drag(el, 26, 25);
+	moved(50, 50);
+});
+
+test("{ grid: [50, 50] }, absolute", function() {
+	el = $("#draggable2").draggable({ grid: [50, 50] });
+	drag(el, 24, 24);
+	moved(0, 0);
+	drag(el, 26, 25);
+	moved(50, 50);
+});
+
+test("{ handle: 'span' }", function() {
+	el = $("#draggable2").draggable({ handle: 'span' });
+
+	drag("#draggable2 span", 50, 50);
+	moved(50, 50, "drag span");
+
+	drag("#draggable2", 50, 50);
+	moved(0, 0, "drag element");
+});
+
+test("{ helper: 'clone' }, relative", function() {
+	el = $("#draggable1").draggable({ helper: "clone" });
+	drag(el, 50, 50);
+	moved(0, 0);
+});
+
+test("{ helper: 'clone' }, absolute", function() {
+	el = $("#draggable2").draggable({ helper: "clone" });
+	drag(el, 50, 50);
+	moved(0, 0);
+});
+
+test("{ helper: 'original' }, relative, with scroll offset on parent", function() {
+	
+	el = $("#draggable1").draggable({ helper: "original" });
+
+	setScroll();
+	testScroll('relative');
+	
+	setScroll();
+	testScroll('static');
+	
+	setScroll();
+	testScroll('absolute');
+
+	restoreScroll();
+	
+});
+
+test("{ helper: 'original' }, relative, with scroll offset on root", function() {
+	
+	el = $("#draggable1").draggable({ helper: "original" });
+	
+	setScroll('root');
+	testScroll('relative');
+	
+	setScroll('root');
+	testScroll('static');
+	
+	setScroll('root');
+	testScroll('absolute');
+
+	restoreScroll('root');
+	
+});
+
+test("{ helper: 'original' }, relative, with scroll offset on root and parent", function() {
+	
+	el = $("#draggable1").draggable({ helper: "original" });
+	
+	setScroll();
+	setScroll('root');
+	testScroll('relative');
+	
+	setScroll();
+	setScroll('root');
+	testScroll('static');
+	
+	setScroll();
+	setScroll('root');
+	testScroll('absolute');
+
+	restoreScroll();
+	restoreScroll('root');
+	
+});
+
+test("{ helper: 'original' }, absolute, with scroll offset on parent", function() {
+
+	el = $("#draggable1").css({ position: 'absolute', top: 0, left: 0 }).draggable({ helper: "original" });
+
+	setScroll();
+	testScroll('relative');
+	
+	setScroll();
+	testScroll('static');
+	
+	setScroll();
+	testScroll('absolute');
+
+	restoreScroll();
+
+});
+
+test("{ helper: 'original' }, absolute, with scroll offset on root", function() {
+
+	el = $("#draggable1").css({ position: 'absolute', top: 0, left: 0 }).draggable({ helper: "original" });
+	
+	setScroll('root');
+	testScroll('relative');
+	
+	setScroll('root');
+	testScroll('static');
+	
+	setScroll('root');
+	testScroll('absolute');
+
+	restoreScroll('root');
+	
+});
+
+test("{ helper: 'original' }, absolute, with scroll offset on root and parent", function() {
+
+	el = $("#draggable1").css({ position: 'absolute', top: 0, left: 0 }).draggable({ helper: "original" });
+
+	setScroll();
+	setScroll('root');
+	testScroll('relative');
+	
+	setScroll();
+	setScroll('root');
+	testScroll('static');
+	
+	setScroll();
+	setScroll('root');
+	testScroll('absolute');
+
+	restoreScroll();
+	restoreScroll('root');
+	
+});
+
+test("{ helper: 'original' }, fixed, with scroll offset on parent", function() {
+
+	el = $("#draggable1").css({ position: 'fixed', top: 0, left: 0 }).draggable({ helper: "original" });
+
+	setScroll();
+	testScroll('relative');
+	
+	setScroll();
+	testScroll('static');
+	
+	setScroll();
+	testScroll('absolute');
+
+	restoreScroll();
+
+});
+
+test("{ helper: 'original' }, fixed, with scroll offset on root", function() {
+	
+	el = $("#draggable1").css({ position: 'fixed', top: 0, left: 0 }).draggable({ helper: "original" });
+
+	setScroll('root');
+	testScroll('relative');
+	
+	setScroll('root');
+	testScroll('static');
+	
+	setScroll('root');
+	testScroll('absolute');
+
+	restoreScroll('root');
+});
+
+test("{ helper: 'original' }, fixed, with scroll offset on root and parent", function() {
+
+	el = $("#draggable1").css({ position: 'fixed', top: 0, left: 0 }).draggable({ helper: "original" });
+
+	setScroll();
+	setScroll('root');
+	testScroll('relative');
+	
+	setScroll();
+	setScroll('root');
+	testScroll('static');
+	
+	setScroll();
+	setScroll('root');
+	testScroll('absolute');
+	
+	restoreScroll();
+	restoreScroll('root');
+
+});
+
+test("{ helper: 'clone' }, absolute", function() {
+
+	var helperOffset = null;
+	var origOffset = $("#draggable1").offset();
+
+	el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) {
+		helperOffset = ui.helper.offset();
+	} });
+
+	drag(el, 1, 1);
+	same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');
+
+});
+
+test("{ helper: 'clone' }, absolute with scroll offset on parent", function() {
+
+	setScroll();
+	var helperOffset = null;
+	var origOffset = null;
+
+	el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) {
+		helperOffset = ui.helper.offset();
+	} });
+
+	$("#main").css('position', 'relative');
+	origOffset = $("#draggable1").offset();
+	drag(el, 1, 1);
+	same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');
+
+	$("#main").css('position', 'static');
+	origOffset = $("#draggable1").offset();
+	drag(el, 1, 1);
+	same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');
+	
+	$("#main").css('position', 'absolute');
+	origOffset = $("#draggable1").offset();
+	drag(el, 1, 1);
+	same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');
+	
+	restoreScroll();
+
+});
+
+test("{ helper: 'clone' }, absolute with scroll offset on root", function() {
+
+	setScroll('root');
+	var helperOffset = null;
+	var origOffset = null;
+
+	el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) {
+		helperOffset = ui.helper.offset();
+	} });
+	
+	$("#main").css('position', 'relative');
+	origOffset = $("#draggable1").offset();
+	drag(el, 1, 1);
+	same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');
+
+	$("#main").css('position', 'static');
+	origOffset = $("#draggable1").offset();
+	drag(el, 1, 1);
+	same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');
+	
+	$("#main").css('position', 'absolute');
+	origOffset = $("#draggable1").offset();
+	drag(el, 1, 1);
+	same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');	
+	
+	restoreScroll('root');
+
+});
+
+test("{ helper: 'clone' }, absolute with scroll offset on root and parent", function() {
+
+	setScroll('root');
+	setScroll();
+	var helperOffset = null;
+	var origOffset = null;
+
+	el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) {
+		helperOffset = ui.helper.offset();
+	} });
+
+	$("#main").css('position', 'relative');
+	origOffset = $("#draggable1").offset()
+	drag(el, 1, 1);
+	same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');
+
+	$("#main").css('position', 'static');
+	origOffset = $("#draggable1").offset()
+	drag(el, 1, 1);
+	same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');
+	
+	$("#main").css('position', 'absolute');
+	origOffset = $("#draggable1").offset()
+	drag(el, 1, 1);
+	same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');
+	
+	restoreScroll('root');
+	restoreScroll();
+
+});
+
+test("{ opacity: 0.5 }", function() {
+
+	expect(1);
+
+	var opacity = null;
+	el = $("#draggable2").draggable({
+		opacity: 0.5,
+		start: function(event, ui) {
+			opacity = $(this).css("opacity");
+		}
+	});
+
+	drag("#draggable2", -1, -1);
+
+	equals(opacity, 0.5, "start callback: opacity is");
+
+});
+
+test("{ zIndex: 10 }", function() {
+
+	expect(1);
+
+	var expected = 10, actual;
+
+	var zIndex = null;
+	el = $("#draggable2").draggable({
+		zIndex: expected,
+		start: function(event, ui) {
+			actual = $(this).css("zIndex");
+		}
+	});
+
+	drag("#draggable2", -1, -1);
+
+	equals(actual, expected, "start callback: zIndex is");
+
+});
+
+})(jQuery);
-- 
cgit v1.1