1 // A framework for testing.
5 Framework.safeRun = function(callback, onSuccess, onException, breakOnUncaught)
10 Framework.safeRun(onSuccess, undefined, onException, breakOnUncaught);
13 Framework.safeRun(onException, undefined, breakOnUncaught ? Framework.breakInFramework : undefined);
14 else if (breakOnUncaught)
15 Framework.breakInFramework();
19 Framework.throwFrameworkException = function(msg)
21 throw Error("FrameworkException" + (msg ? ": " + msg : ""));
24 Framework.breakInFramework = function()
29 Framework.empty = function()
33 Framework.doSomeWork = function()
35 const numberOfSteps = 50;
36 for (var i = 0; i < numberOfSteps; ++i) {
37 if (window["dummy property should not exist!" + i]) // Prevent optimizations.
39 Framework.safeRun(Framework.empty, Framework.empty, Framework.empty, true);
43 Framework.schedule = function(callback, delay)
45 setTimeout(callback, delay || 0);
48 Framework.willSchedule = function(callback, delay)
50 return function Framework_willSchedule() {
51 return Framework.schedule(callback, delay);
55 Framework.doSomeAsyncChainCalls = function(callback)
57 var func1 = Framework.willSchedule(function Framework_inner1() {
61 var func2 = Framework.willSchedule(function Framework_inner2() {
62 if (window.callbackFromFramework)
63 window.callbackFromFramework(func1);
67 Framework.schedule(func2);
70 Framework.appendChild = function(parent, child)
72 parent.appendChild(child);
75 Framework.sendXHR = function(url)
77 var request = new XMLHttpRequest();
78 request.open("GET", url, true);
79 try { request.send(); } catch (e) {}
82 Framework.addEventListener = function(element, eventType, listener, capture)
84 function Framework_eventListener()
86 var result = listener ? listener() : void 0;
90 function Framework_remover()
92 element.removeEventListener(eventType, Framework_eventListener, capture);
95 element.addEventListener(eventType, Framework_eventListener, capture);
96 return Framework_remover;
99 Framework.bind = function(func, thisObject, var_args)
101 var args = Array.prototype.slice.call(arguments, 2);
103 function Framework_bound(var_args)
105 return func.apply(thisObject, args.concat(Array.prototype.slice.call(arguments)));
107 Framework_bound.toString = function()
109 return "Framework_bound: " + func;
111 return Framework_bound;
114 Framework.throwInNative = function()
116 var wrongJson = "})";
117 window["dummy"] = JSON.parse(wrongJson);
120 Framework.throwInNativeAndCatch = function()
123 Framework.throwInNative();
128 Framework.throwFrameworkExceptionAndCatch = function()
131 Framework.throwFrameworkException();
136 Framework.scheduleUntilDone = function(callback, delay)
138 Framework.schedule(Framework_scheduleUntilDone, delay);
140 function Framework_scheduleUntilDone()
142 if (callback && callback())
144 Framework.schedule(Framework_scheduleUntilDone, delay);
148 Framework.doSomeWorkDoNotChangeTopCallFrame = function()
150 const numberOfSteps = 5000;
151 for (var i = 0; i < numberOfSteps; ++i) {
152 if (window["dummy property should not exist!" + i]) // Prevent optimizations.
158 Framework.assert = function(var_args)
160 var args = Array.prototype.slice.call(arguments, 0);
161 return console.assert.apply(console, args);
164 Framework.createButtonWithEventListenersAndClick = function(eventListener)
166 var button = document.createElement("input");
167 button.type = "button";
168 Framework.addEventListener(button, "click", Framework.empty, true);
169 Framework.addEventListener(button, "click", Framework.bind(Framework.empty, null), false);
170 Framework.addEventListener(button, "click", Framework.bind(Framework.safeRun, null, Framework.empty, Framework.empty, Framework.empty), true);
172 Framework.addEventListener(button, "click", eventListener, true);