-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
11,721 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/*[email protected]#browser/actions*/ | ||
define(function (require, exports, module) { | ||
var $ = require('./jquery'); | ||
var FuncUnit = require('./core'); | ||
var syn = window.syn = require('syn'); | ||
var clicks = [ | ||
'click', | ||
'dblclick', | ||
'rightClick' | ||
], makeClick = function (name) { | ||
FuncUnit.prototype[name] = function (options, success) { | ||
this._addExists(); | ||
if (typeof options == 'function') { | ||
success = options; | ||
options = {}; | ||
} | ||
var selector = this.selector; | ||
FuncUnit.add({ | ||
method: function (success, error) { | ||
options = options || {}; | ||
syn('_' + name, this.bind[0], options, success); | ||
}, | ||
success: success, | ||
error: 'Could not ' + name + ' \'' + this.selector + '\'', | ||
bind: this, | ||
type: 'action' | ||
}); | ||
return this; | ||
}; | ||
}; | ||
for (var i = 0; i < clicks.length; i++) { | ||
makeClick(clicks[i]); | ||
} | ||
$.extend(FuncUnit.prototype, { | ||
_addExists: function () { | ||
this.exists(false); | ||
}, | ||
type: function (text, success) { | ||
this._addExists(); | ||
this.click(); | ||
var selector = this.selector; | ||
if (text === '') { | ||
text = '[ctrl]a[ctrl-up]\b'; | ||
} | ||
FuncUnit.add({ | ||
method: function (success, error) { | ||
syn('_type', this.bind[0], text, success); | ||
}, | ||
success: success, | ||
error: 'Could not type ' + text + ' into ' + this.selector, | ||
bind: this, | ||
type: 'action' | ||
}); | ||
return this; | ||
}, | ||
sendKeys: function (keys, success) { | ||
this._addExists(); | ||
var selector = this.selector; | ||
if (keys === '') { | ||
keys = '[ctrl]a[ctrl-up]\b'; | ||
} | ||
FuncUnit.add({ | ||
method: function (success, error) { | ||
syn('_type', this.bind[0], keys, success); | ||
}, | ||
success: success, | ||
error: 'Could not send the keys ' + keys + ' into ' + this.selector, | ||
bind: this, | ||
type: 'action' | ||
}); | ||
return this; | ||
}, | ||
trigger: function (evName, success) { | ||
this._addExists(); | ||
FuncUnit.add({ | ||
method: function (success, error) { | ||
if (!FuncUnit.win.jQuery) { | ||
throw 'Can not trigger custom event, no jQuery found on target page.'; | ||
} | ||
FuncUnit.win.jQuery(this.bind.selector).trigger(evName); | ||
success(); | ||
}, | ||
success: success, | ||
error: 'Could not trigger ' + evName, | ||
bind: this, | ||
type: 'action' | ||
}); | ||
return this; | ||
}, | ||
drag: function (options, success) { | ||
this._addExists(); | ||
if (typeof options == 'string') { | ||
options = { to: options }; | ||
} | ||
options.from = this.selector; | ||
var selector = this.selector; | ||
FuncUnit.add({ | ||
method: function (success, error) { | ||
syn('_drag', this.bind[0], options, success); | ||
}, | ||
success: success, | ||
error: 'Could not drag ' + this.selector, | ||
bind: this, | ||
type: 'action' | ||
}); | ||
return this; | ||
}, | ||
move: function (options, success) { | ||
this._addExists(); | ||
if (typeof options == 'string') { | ||
options = { to: options }; | ||
} | ||
options.from = this.selector; | ||
var selector = this.selector; | ||
FuncUnit.add({ | ||
method: function (success, error) { | ||
syn('_move', this.bind[0], options, success); | ||
}, | ||
success: success, | ||
error: 'Could not move ' + this.selector, | ||
bind: this, | ||
type: 'action' | ||
}); | ||
return this; | ||
}, | ||
scroll: function (direction, amount, success) { | ||
this._addExists(); | ||
var selector = this.selector, direction; | ||
if (direction == 'left' || direction == 'right') { | ||
direction = 'Left'; | ||
} else if (direction == 'top' || direction == 'bottom') { | ||
direction = 'Top'; | ||
} | ||
FuncUnit.add({ | ||
method: function (success, error) { | ||
this.bind.each(function (i, el) { | ||
this['scroll' + direction] = amount; | ||
}); | ||
success(); | ||
}, | ||
success: success, | ||
error: 'Could not scroll ' + this.selector, | ||
bind: this, | ||
type: 'action' | ||
}); | ||
return this; | ||
} | ||
}); | ||
module.exports = FuncUnit; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/*[email protected]#browser/adapters/adapters*/ | ||
define(function (require, exports, module) { | ||
(function (global) { | ||
var jasmineAdapter = require('./jasmine'); | ||
var jasmine2Adapter = require('./jasmine2'); | ||
var qunitAdapter = require('./qunit'); | ||
var mochaAdapter = require('./mocha'); | ||
var FuncUnit = require('../core'); | ||
var noop = function () { | ||
}; | ||
var defaultAdapter = { | ||
pauseTest: noop, | ||
resumeTest: noop, | ||
assertOK: noop, | ||
equiv: function (expected, actual) { | ||
return expected == actual; | ||
} | ||
}; | ||
FuncUnit.unit = defaultAdapter; | ||
FuncUnit.attach = function (runner) { | ||
var unit; | ||
if (isQUnit(runner)) { | ||
unit = qunitAdapter(runner); | ||
} else if (isMocha(runner)) { | ||
unit = mochaAdapter(runner); | ||
} else if (isJasmine(runner)) { | ||
unit = jasmineAdapter(runner); | ||
} else if (isJasmine2(runner)) { | ||
unit = jasmine2Adapter(runner); | ||
} else { | ||
unit = defaultAdapter; | ||
} | ||
FuncUnit.unit = unit; | ||
}; | ||
function isQUnit(runner) { | ||
return !!(runner.ok && runner.start && runner.stop); | ||
} | ||
function isMocha(runner) { | ||
return !!(runner.setup && runner.globals && runner.reporter); | ||
} | ||
function isJasmine(runner) { | ||
return !!(runner.getEnv && typeof window.waitsFor === 'function'); | ||
} | ||
function isJasmine2(runner) { | ||
return !!(runner.getEnv && typeof runner.clock === 'function' && !window.waitsFor); | ||
} | ||
FuncUnit.detach = function () { | ||
FuncUnit.unit = defaultAdapter; | ||
}; | ||
}(function () { | ||
return this; | ||
}())); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/*[email protected]#browser/adapters/jasmine*/ | ||
define(function (require, exports, module) { | ||
module.exports = function (jasmine) { | ||
var paused = false; | ||
return { | ||
pauseTest: function () { | ||
paused = true; | ||
waitsFor(function () { | ||
return paused === false; | ||
}, 60000); | ||
}, | ||
resumeTest: function () { | ||
paused = false; | ||
}, | ||
assertOK: function (assertion, message) { | ||
expect(assertion).toBeTruthy(); | ||
}, | ||
equiv: function (expected, actual) { | ||
return jasmine.getEnv().equals_(expected, actual); | ||
} | ||
}; | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/*[email protected]#browser/adapters/jasmine2*/ | ||
define(function (require, exports, module) { | ||
var FuncUnit = require('../core'); | ||
module.exports = function (jasmine) { | ||
FuncUnit.timeout = 4900; | ||
return { | ||
pauseTest: function () { | ||
}, | ||
resumeTest: function () { | ||
}, | ||
assertOK: function (assertion, message) { | ||
expect(assertion).toBeTruthy(); | ||
}, | ||
equiv: function (expected, actual) { | ||
return expected == actual; | ||
} | ||
}; | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/*[email protected]#browser/adapters/mocha*/ | ||
define(function (require, exports, module) { | ||
var FuncUnit = require('../core'); | ||
var ok = function (expr, msg) { | ||
if (!expr) | ||
throw new Error(msg); | ||
}; | ||
module.exports = function (mocha) { | ||
FuncUnit.timeout = 1900; | ||
return { | ||
pauseTest: function () { | ||
}, | ||
resumeTest: function () { | ||
}, | ||
assertOK: function (assertion, message) { | ||
ok(assertion, message); | ||
}, | ||
equiv: function (expected, actual) { | ||
return expected == actual; | ||
} | ||
}; | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/*[email protected]#browser/adapters/qunit*/ | ||
define(function (require, exports, module) { | ||
module.exports = function (QUnit) { | ||
return { | ||
pauseTest: function () { | ||
QUnit.stop(); | ||
}, | ||
resumeTest: function () { | ||
QUnit.start(); | ||
}, | ||
assertOK: function (assertion, message) { | ||
QUnit.ok(assertion, message); | ||
}, | ||
equiv: function (expected, actual) { | ||
return QUnit.equiv(expected, actual); | ||
} | ||
}; | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/*[email protected]#browser/core*/ | ||
define(function (require, exports, module) { | ||
var jQuery = require('./jquery'); | ||
var oldFuncUnit = require('./init'); | ||
var FuncUnit = oldFuncUnit.jQuery.sub(); | ||
var origFuncUnit = FuncUnit; | ||
FuncUnit = function (selector, frame) { | ||
var frame, forceSync, isSyncOnly = false; | ||
if (frame && frame.forceSync) { | ||
forceSync = frame.forceSync; | ||
} | ||
if (frame && typeof frame.frame !== 'undefined') { | ||
frame = frame.frame; | ||
} | ||
isSyncOnly = typeof forceSync === 'boolean' ? forceSync : isSyncOnly; | ||
if (typeof selector == 'function') { | ||
return FuncUnit.wait(0, selector); | ||
} | ||
this.selector = selector; | ||
if (isSyncOnly === true) { | ||
var collection = performSyncQuery(selector, frame); | ||
return collection; | ||
} else { | ||
performAsyncQuery(selector, frame, this); | ||
var collection = performSyncQuery(selector, frame); | ||
return collection; | ||
} | ||
}; | ||
var getContext = function (context) { | ||
if (typeof context === 'number' || typeof context === 'string') { | ||
var sel = typeof context === 'number' ? 'iframe:eq(' + context + ')' : 'iframe[name=\'' + context + '\']', frames = new origFuncUnit.fn.init(sel, FuncUnit.win.document.documentElement, true); | ||
var frame = (frames.length ? frames.get(0).contentWindow : FuncUnit.win).document.documentElement; | ||
} else { | ||
frame = FuncUnit.win.document.documentElement; | ||
} | ||
return frame; | ||
}, performAsyncQuery = function (selector, frame, self) { | ||
FuncUnit.add({ | ||
method: function (success, error) { | ||
this.frame = frame; | ||
if (FuncUnit.win) { | ||
frame = getContext(frame); | ||
} | ||
this.selector = selector; | ||
this.bind = new origFuncUnit.fn.init(selector, frame, true); | ||
success(); | ||
return this; | ||
}, | ||
error: 'selector failed: ' + selector, | ||
type: 'query' | ||
}); | ||
}, performSyncQuery = function (selector, frame) { | ||
var origFrame = frame; | ||
if (FuncUnit.win) { | ||
frame = getContext(frame); | ||
} | ||
var obj = new origFuncUnit.fn.init(selector, frame, true); | ||
obj.frame = origFrame; | ||
return obj; | ||
}; | ||
oldFuncUnit.jQuery.extend(FuncUnit, oldFuncUnit, origFuncUnit); | ||
FuncUnit.prototype = origFuncUnit.prototype; | ||
module.exports = FuncUnit; | ||
}); |
Oops, something went wrong.