license import { isNode , zoneSymbol } from '../lib/common/utils' ; export { zoneSymbol } ; declare const global ; export function ifEnvSupports ( test , block ) { return _ifEnvSupports ( test , block ) ; } export function ifEnvSupportsWithDone ( test , block ) { return _ifEnvSupports ( test , block , true ) ; } function _ifEnvSupports ( test , block , withDone = false ) { if ( withDone ) { return function ( done ? ) { _runTest ( test , block , done ) ; } ; } else { return function ( ) { _runTest ( test , block , undefined ) ; } ; } } function _runTest ( test , block , done ? ) { const message = ( test . message || test . name || test ) ; if ( typeof test === 'string' ? ! ! global [ test ] : test ( ) ) { if ( done ) { block ( done ) ; } else { block ( ) ; } } else { console . log ( 'WARNING: skipping ' + message + ' tests (missing this API)' ) ; done && done ( ) ; } } export function supportPatchXHROnProperty ( ) { let desc = Object . getOwnPropertyDescriptor ( XMLHttpRequest . prototype , 'onload' ) ; if ( ! desc && ( window as any ) [ 'XMLHttpRequestEventTarget' ] ) { desc = Object . getOwnPropertyDescriptor ( global [ 'XMLHttpRequestEventTarget' ] . prototype , 'onload' ) ; } if ( ! desc || ! desc . configurable ) { return false ; } return true ; } let supportSetErrorStack = true ; export function isSupportSetErrorStack ( ) { try { throw new Error ( 'test' ) ; } catch ( err ) { try { err . stack = 'new stack' ; supportSetErrorStack = err . stack === 'new stack' ; } catch ( error ) { supportSetErrorStack = false ; } } return supportSetErrorStack ; } ( isSupportSetErrorStack as any ) . message = 'supportSetErrorStack' ; export function asyncTest ( testFn , zone = Zone . current ) { const AsyncTestZoneSpec = ( Zone as any ) [ 'AsyncTestZoneSpec' ] ; return ( done ) => { let asyncTestZone = zone . fork ( new AsyncTestZoneSpec ( ( ) => { } , ( error ) => { fail ( error ) ; } , 'asyncTest' ) ) ; asyncTestZone . run ( testFn , this , [ done ] ) ; } ; } export function getIEVersion ( ) { const userAgent = navigator . userAgent . toLowerCase ( ) ; if ( userAgent . indexOf ( 'msie' ) != - 1 ) { return parseInt ( userAgent . split ( 'msie' ) [ 1 ] ) ; } return null ; } export function isFirefox ( ) { const userAgent = navigator . userAgent . toLowerCase ( ) ; if ( userAgent . indexOf ( 'firefox' ) != - 1 ) { return true ; } return false ; } export function isSafari ( ) { const userAgent = navigator . userAgent . toLowerCase ( ) ; if ( userAgent . indexOf ( 'safari' ) != - 1 ) { return true ; } return false ; } export function isEdge ( ) { const userAgent = navigator . userAgent . toLowerCase ( ) ; return userAgent . indexOf ( 'edge' ) !== - 1 ; } export function getEdgeVersion ( ) { const ua = navigator . userAgent . toLowerCase ( ) ; const edge = ua . indexOf ( 'edge/' ) ; if ( edge === - 1 ) { return - 1 ; } return parseInt ( ua . substring ( edge + 5 , ua . indexOf ( '.' , edge ) ) , 10 ) ; } export function isPhantomJS ( ) { if ( isNode ) { return false ; } const ua = navigator . userAgent . toLowerCase ( ) ; return ua . indexOf ( 'phantomjs' ) !== - 1 ; }