blob: 1f1d2f6637cd8250e69fc68685213427d9ee3d17 [file] [log] [blame]
{"version":3,"file":"testing.js","sources":["../testing/src/browser_util.ts","../testing/src/browser.ts","../testing/testing.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google Inc. All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {NgZone, ɵglobal as global} from '@angular/core';\nimport {ɵgetDOM as getDOM} from '@angular/platform-browser';\n\nexport let browserDetection: BrowserDetection;\n\nexport class BrowserDetection {\n private _overrideUa: string|null;\n private get _ua(): string {\n if (typeof this._overrideUa === 'string') {\n return this._overrideUa;\n }\n\n return getDOM() ? getDOM().getUserAgent() : '';\n }\n\n static setup() { browserDetection = new BrowserDetection(null); }\n\n constructor(ua: string|null) { this._overrideUa = ua; }\n\n get isFirefox(): boolean { return this._ua.indexOf('Firefox') > -1; }\n\n get isAndroid(): boolean {\n return this._ua.indexOf('Mozilla/5.0') > -1 && this._ua.indexOf('Android') > -1 &&\n this._ua.indexOf('AppleWebKit') > -1 && this._ua.indexOf('Chrome') == -1 &&\n this._ua.indexOf('IEMobile') == -1;\n }\n\n get isEdge(): boolean { return this._ua.indexOf('Edge') > -1; }\n\n get isIE(): boolean { return this._ua.indexOf('Trident') > -1; }\n\n get isWebkit(): boolean {\n return this._ua.indexOf('AppleWebKit') > -1 && this._ua.indexOf('Edge') == -1 &&\n this._ua.indexOf('IEMobile') == -1;\n }\n\n get isIOS7(): boolean {\n return (this._ua.indexOf('iPhone OS 7') > -1 || this._ua.indexOf('iPad OS 7') > -1) &&\n this._ua.indexOf('IEMobile') == -1;\n }\n\n get isSlow(): boolean { return this.isAndroid || this.isIE || this.isIOS7; }\n\n // The Intl API is only natively supported in Chrome, Firefox, IE11 and Edge.\n // This detector is needed in tests to make the difference between:\n // 1) IE11/Edge: they have a native Intl API, but with some discrepancies\n // 2) IE9/IE10: they use the polyfill, and so no discrepancies\n get supportsNativeIntlApi(): boolean {\n return !!(<any>global).Intl && (<any>global).Intl !== (<any>global).IntlPolyfill;\n }\n\n get isChromeDesktop(): boolean {\n return this._ua.indexOf('Chrome') > -1 && this._ua.indexOf('Mobile Safari') == -1 &&\n this._ua.indexOf('Edge') == -1;\n }\n\n // \"Old Chrome\" means Chrome 3X, where there are some discrepancies in the Intl API.\n // Android 4.4 and 5.X have such browsers by default (respectively 30 and 39).\n get isOldChrome(): boolean {\n return this._ua.indexOf('Chrome') > -1 && this._ua.indexOf('Chrome/3') > -1 &&\n this._ua.indexOf('Edge') == -1;\n }\n\n get supportsCustomElements() { return (typeof(<any>global).customElements !== 'undefined'); }\n\n get supportsDeprecatedCustomCustomElementsV0() {\n return (typeof(document as any).registerElement !== 'undefined');\n }\n\n get supportsRegExUnicodeFlag(): boolean { return RegExp.prototype.hasOwnProperty('unicode'); }\n\n get supportsShadowDom() {\n const testEl = document.createElement('div');\n return (typeof testEl.attachShadow !== 'undefined');\n }\n\n get supportsDeprecatedShadowDomV0() {\n const testEl = document.createElement('div') as any;\n return (typeof testEl.createShadowRoot !== 'undefined');\n }\n}\n\nBrowserDetection.setup();\n\nexport function dispatchEvent(element: any, eventType: any): void {\n getDOM().dispatchEvent(element, getDOM().createEvent(eventType));\n}\n\nexport function el(html: string): HTMLElement {\n return <HTMLElement>getDOM().firstChild(getDOM().content(getDOM().createTemplate(html)));\n}\n\nexport function normalizeCSS(css: string): string {\n return css.replace(/\\s+/g, ' ')\n .replace(/:\\s/g, ':')\n .replace(/'/g, '\"')\n .replace(/ }/g, '}')\n .replace(/url\\((\\\"|\\s)(.+)(\\\"|\\s)\\)(\\s*)/g, (...match: string[]) => `url(\"${match[2]}\")`)\n .replace(/\\[(.+)=([^\"\\]]+)\\]/g, (...match: string[]) => `[${match[1]}=\"${match[2]}\"]`);\n}\n\nconst _selfClosingTags = ['br', 'hr', 'input'];\nexport function stringifyElement(el: any /** TODO #9100 */): string {\n let result = '';\n if (getDOM().isElementNode(el)) {\n const tagName = getDOM().tagName(el).toLowerCase();\n\n // Opening tag\n result += `<${tagName}`;\n\n // Attributes in an ordered way\n const attributeMap = getDOM().attributeMap(el);\n const sortedKeys = Array.from(attributeMap.keys()).sort();\n for (const key of sortedKeys) {\n const lowerCaseKey = key.toLowerCase();\n let attValue = attributeMap.get(key);\n\n if (typeof attValue !== 'string') {\n result += ` ${lowerCaseKey}`;\n } else {\n // Browsers order style rules differently. Order them alphabetically for consistency.\n if (lowerCaseKey === 'style') {\n attValue = attValue.split(/; ?/).filter(s => !!s).sort().map(s => `${s};`).join(' ');\n }\n\n result += ` ${lowerCaseKey}=\"${attValue}\"`;\n }\n }\n result += '>';\n\n // Children\n const childrenRoot = getDOM().templateAwareRoot(el);\n const children = childrenRoot ? getDOM().childNodes(childrenRoot) : [];\n for (let j = 0; j < children.length; j++) {\n result += stringifyElement(children[j]);\n }\n\n // Closing tag\n if (_selfClosingTags.indexOf(tagName) == -1) {\n result += `</${tagName}>`;\n }\n } else if (getDOM().isCommentNode(el)) {\n result += `<!--${getDOM().nodeValue(el)}-->`;\n } else {\n result += getDOM().getText(el);\n }\n\n return result;\n}\n\nexport function createNgZone(): NgZone {\n return new NgZone({enableLongStackTrace: true});\n}\n","/**\n * @license\n * Copyright Google Inc. All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\nimport {APP_ID, NgModule, NgZone, PLATFORM_INITIALIZER, PlatformRef, StaticProvider, createPlatformFactory, platformCore} from '@angular/core';\nimport {BrowserModule, ɵBrowserDomAdapter as BrowserDomAdapter, ɵELEMENT_PROBE_PROVIDERS as ELEMENT_PROBE_PROVIDERS} from '@angular/platform-browser';\nimport {BrowserDetection, createNgZone} from './browser_util';\n\nfunction initBrowserTests() {\n BrowserDomAdapter.makeCurrent();\n BrowserDetection.setup();\n}\n\nconst _TEST_BROWSER_PLATFORM_PROVIDERS: StaticProvider[] =\n [{provide: PLATFORM_INITIALIZER, useValue: initBrowserTests, multi: true}];\n\n/**\n * Platform for testing\n *\n * @publicApi\n */\nexport const platformBrowserTesting =\n createPlatformFactory(platformCore, 'browserTesting', _TEST_BROWSER_PLATFORM_PROVIDERS);\n\n/**\n * NgModule for testing.\n *\n * @publicApi\n */\n@NgModule({\n exports: [BrowserModule],\n providers: [\n {provide: APP_ID, useValue: 'a'},\n ELEMENT_PROBE_PROVIDERS,\n {provide: NgZone, useFactory: createNgZone},\n ]\n})\nexport class BrowserTestingModule {\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n\nexport {createNgZone as ɵangular_packages_platform_browser_testing_testing_a} from './src/browser_util';"],"names":["getDOM","global","BrowserDomAdapter","ELEMENT_PROBE_PROVIDERS"],"mappings":";;;;;;;;;;;;;MAaa,gBAAgB;;;;;IAE3B,IAAY,GAAG;QACb,IAAI,OAAO,IAAI,CAAC,WAAW,KAAK,QAAQ,EAAE;YACxC,OAAO,IAAI,CAAC,WAAW,CAAC;SACzB;QAED,OAAOA,OAAM,EAAE,GAAGA,OAAM,EAAE,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC;KAChD;;;;IAED,OAAO,KAAK,IAAmD,EAAE;;;;IAEjE,YAAY,EAAe,IAAI,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC,EAAE;;;;IAEvD,IAAI,SAAS,KAAc,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;;;;IAErE,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YAC3E,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACxE,IAAI,CAAC,GA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