1
var suite = new Y.Test.Suite("event-resize"),
2
win = Y.one( Y.config.win ),
3
eventKey = 'event:' + Y.stamp(Y.config.win) + 'resizenative',
4
isOldGecko = (Y.UA.gecko && Y.UA.gecko < 1.91);
6
function simulateResize() {
7
// IE doesn't allow simulation of window.onresize, so I can't use
8
//Y.Event.simulate(Y.config.win, 'resize');
9
setTimeout(function () {
10
Y.Env.evt.dom_wrappers[eventKey].fire({
12
srcElement: Y.config.win,
18
suite.add(new Y.Test.Case({
23
// I can't get this damn test to pass in CI. It's likely a bad
24
// test, but I'm having a hell of a time divising a good one.
25
"test resize event throttling": true
29
"test Y.on('windowresize', fn)": function () {
35
argCount = arguments.length;
39
test.resume(function () {
40
Y.Assert.areSame('windowresize', e.type);
41
Y.Assert.areSame(1, argCount);
42
Y.Assert.areSame(win, thisObj, "this should be window");
43
Y.Assert.areSame(win, e.target, "e.target should be window");
47
handle = Y.on('windowresize', handler);
54
"test node.on('windowresize', fn)": function () {
56
refNode = Y.Node.create('<div />').appendTo(Y.one('body')),
61
argCount = arguments.length;
65
test.resume(function () {
66
// TODO: is this a bug?
67
Y.Assert.areSame(win, thisObj, "this should be window");
68
Y.Assert.areSame(win, e.target, "e.target should be window");
69
Y.Assert.areSame(1, argCount);
70
Y.Assert.areSame('windowresize', e.type);
74
handle = refNode.on('windowresize', handler);
81
"test resize event throttling": function () {
83
testThresholds = [40, 100, 300],
84
// This prevents the test from timing out if the browser is
86
keepAlive = Y.on('resize', function () {
87
test.resume(function () {
91
// Allow for 10ms of leeway from the threshold. FF is firing a few
92
// milliseconds before the threshold, and I think that's close
96
function runTest(threshold) {
100
Y.config.windowResizeDelay = threshold;
102
handle = Y.on('windowresize', function (e) {
103
var end = new Date();
108
test.resume(function () {
109
Y.assert(isOldGecko || (end - start + fudge >= threshold),
110
"Fired before threshold (" + threshold + ") - delta: " +
113
if (testThresholds.length) {
114
runTest(testThresholds.shift());
121
// recursive async function that fires resize on an incrementing
122
// delay, starting at 10ms, then 20ms, 30ms, and so on.
123
function scheduleResize() {
126
timer = Y.later(delay, Y, function () {
139
runTest(testThresholds.shift());
143
Y.Test.Runner.add(suite);