2019-05-31 11:56:07 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
(function(_global) {
|
2020-04-13 19:40:21 -04:00
|
|
|
var testRunner = _global['__zone_symbol__testRunner'];
|
|
|
|
var mark = _global['__zone_symbol__mark'];
|
|
|
|
var measure = _global['__zone_symbol__measure'];
|
|
|
|
var zone = _global['__zone_symbol__callbackZone'];
|
|
|
|
var button;
|
|
|
|
var testTarget = {
|
|
|
|
title: 'addEventListener',
|
|
|
|
times: 10,
|
|
|
|
before: function() {
|
|
|
|
button = document.createElement('button');
|
|
|
|
document.body.appendChild(button);
|
|
|
|
_global['__zone_symbol__callbackContext'].measureName = 'addEventListener_callback';
|
|
|
|
_global['__zone_symbol__callbackContext'].type = 'eventTask';
|
|
|
|
_global['__zone_symbol__callbackContext'].source = 'addEventListener';
|
|
|
|
},
|
|
|
|
after: function() {
|
|
|
|
document.body.removeChild(button);
|
|
|
|
button = null;
|
|
|
|
},
|
|
|
|
apis: [
|
|
|
|
{
|
|
|
|
supportClear: true,
|
|
|
|
method: 'addEventListener',
|
|
|
|
nativeMethod: '__zone_symbol__addEventListener',
|
|
|
|
clearMethod: 'removeEventListener',
|
|
|
|
nativeClearMethod: '__zone_symbol__removeEventListener',
|
|
|
|
run: function() {
|
|
|
|
var listener = function() {};
|
|
|
|
button.addEventListener('click', listener);
|
|
|
|
return listener;
|
|
|
|
},
|
|
|
|
runClear: function(timerId) {
|
|
|
|
return button.removeEventListener('click', timerId);
|
|
|
|
},
|
|
|
|
nativeRun: function() {
|
|
|
|
var listener = function() {};
|
|
|
|
button['__zone_symbol__addEventListener']('click', listener);
|
|
|
|
return listener;
|
|
|
|
},
|
|
|
|
nativeRunClear: function(timerId) {
|
|
|
|
return button['__zone_symbol__removeEventListener']('click', timerId);
|
|
|
|
}
|
2019-05-31 11:56:07 -04:00
|
|
|
},
|
2020-04-13 19:40:21 -04:00
|
|
|
{
|
|
|
|
isCallback: true,
|
|
|
|
supportClear: false,
|
|
|
|
method: 'addEventListener_callback',
|
|
|
|
nativeMethod: 'native_addEventListener_callback',
|
|
|
|
run: function() {
|
|
|
|
var listener = function() {};
|
|
|
|
zone.run(function() {
|
2019-05-31 11:56:07 -04:00
|
|
|
button.addEventListener('click', listener);
|
2020-04-13 19:40:21 -04:00
|
|
|
});
|
|
|
|
var event = document.createEvent('Event');
|
|
|
|
event.initEvent('click', true, true);
|
|
|
|
button.dispatchEvent(event);
|
|
|
|
button.removeEventListener('click', listener);
|
2019-05-31 11:56:07 -04:00
|
|
|
},
|
2020-04-13 19:40:21 -04:00
|
|
|
nativeRun: function() {
|
|
|
|
var func = function() {};
|
|
|
|
var listener = function() {
|
|
|
|
mark('native_addEventListener_callback');
|
|
|
|
func.apply(this, arguments);
|
|
|
|
measure('native_addEventListener_callback', 'native_addEventListener_callback');
|
|
|
|
};
|
|
|
|
button['__zone_symbol__addEventListener']('click', listener);
|
|
|
|
var event = document.createEvent('Event');
|
|
|
|
event.initEvent('click', true, true);
|
|
|
|
button.dispatchEvent(event);
|
|
|
|
button['__zone_symbol__removeEventListener']('click', listener);
|
2019-05-31 11:56:07 -04:00
|
|
|
}
|
2020-04-13 19:40:21 -04:00
|
|
|
}
|
|
|
|
],
|
|
|
|
};
|
|
|
|
return testRunner(testTarget);
|
2019-05-31 11:56:07 -04:00
|
|
|
}(typeof window === 'undefined' ? global : window));
|