UNPKG

8.7 kBJavaScriptView Raw
1/**
2 * @license Angular v15.1.2
3 * (c) 2010-2022 Google LLC. https://angular.io/
4 * License: MIT
5 */
6
7import { ɵgetDOM, PlatformLocation } from '@angular/common';
8import { MockPlatformLocation } from '@angular/common/testing';
9import * as i0 from '@angular/core';
10import { NgZone, PLATFORM_INITIALIZER, createPlatformFactory, platformCore, APP_ID, NgModule } from '@angular/core';
11import { ɵBrowserDomAdapter, BrowserModule } from '@angular/platform-browser';
12
13class BrowserDetection {
14 get _ua() {
15 if (typeof this._overrideUa === 'string') {
16 return this._overrideUa;
17 }
18 return ɵgetDOM() ? ɵgetDOM().getUserAgent() : '';
19 }
20 static setup() {
21 return new BrowserDetection(null);
22 }
23 constructor(ua) {
24 this._overrideUa = ua;
25 }
26 get isFirefox() {
27 return this._ua.indexOf('Firefox') > -1;
28 }
29 get isAndroid() {
30 return this._ua.indexOf('Mozilla/5.0') > -1 && this._ua.indexOf('Android') > -1 &&
31 this._ua.indexOf('AppleWebKit') > -1 && this._ua.indexOf('Chrome') == -1 &&
32 this._ua.indexOf('IEMobile') == -1;
33 }
34 get isEdge() {
35 return this._ua.indexOf('Edge') > -1;
36 }
37 get isWebkit() {
38 return this._ua.indexOf('AppleWebKit') > -1 && this._ua.indexOf('Edge') == -1 &&
39 this._ua.indexOf('IEMobile') == -1;
40 }
41 get isIOS7() {
42 return (this._ua.indexOf('iPhone OS 7') > -1 || this._ua.indexOf('iPad OS 7') > -1) &&
43 this._ua.indexOf('IEMobile') == -1;
44 }
45 get isSlow() {
46 return this.isAndroid || this.isIOS7;
47 }
48 get isChromeDesktop() {
49 return this._ua.indexOf('Chrome') > -1 && this._ua.indexOf('Mobile Safari') == -1 &&
50 this._ua.indexOf('Edge') == -1;
51 }
52 // "Old Chrome" means Chrome 3X, where there are some discrepancies in the Intl API.
53 // Android 4.4 and 5.X have such browsers by default (respectively 30 and 39).
54 get isOldChrome() {
55 return this._ua.indexOf('Chrome') > -1 && this._ua.indexOf('Chrome/3') > -1 &&
56 this._ua.indexOf('Edge') == -1;
57 }
58 get supportsShadowDom() {
59 const testEl = document.createElement('div');
60 return (typeof testEl.attachShadow !== 'undefined');
61 }
62}
63const browserDetection = BrowserDetection.setup();
64function dispatchEvent(element, eventType) {
65 const evt = ɵgetDOM().getDefaultDocument().createEvent('Event');
66 evt.initEvent(eventType, true, true);
67 ɵgetDOM().dispatchEvent(element, evt);
68 return evt;
69}
70function createMouseEvent(eventType) {
71 const evt = ɵgetDOM().getDefaultDocument().createEvent('MouseEvent');
72 evt.initEvent(eventType, true, true);
73 return evt;
74}
75function el(html) {
76 return getContent(createTemplate(html)).firstChild;
77}
78function getAttributeMap(element) {
79 const res = new Map();
80 const elAttrs = element.attributes;
81 for (let i = 0; i < elAttrs.length; i++) {
82 const attrib = elAttrs.item(i);
83 res.set(attrib.name, attrib.value);
84 }
85 return res;
86}
87const _selfClosingTags = ['br', 'hr', 'input'];
88function stringifyElement(el /** TODO #9100 */) {
89 let result = '';
90 if (ɵgetDOM().isElementNode(el)) {
91 const tagName = el.tagName.toLowerCase();
92 // Opening tag
93 result += `<${tagName}`;
94 // Attributes in an ordered way
95 const attributeMap = getAttributeMap(el);
96 const sortedKeys = Array.from(attributeMap.keys()).sort();
97 for (const key of sortedKeys) {
98 const lowerCaseKey = key.toLowerCase();
99 let attValue = attributeMap.get(key);
100 if (typeof attValue !== 'string') {
101 result += ` ${lowerCaseKey}`;
102 }
103 else {
104 // Browsers order style rules differently. Order them alphabetically for consistency.
105 if (lowerCaseKey === 'style') {
106 attValue = attValue.split(/; ?/).filter(s => !!s).sort().map(s => `${s};`).join(' ');
107 }
108 result += ` ${lowerCaseKey}="${attValue}"`;
109 }
110 }
111 result += '>';
112 // Children
113 const childrenRoot = templateAwareRoot(el);
114 const children = childrenRoot ? childrenRoot.childNodes : [];
115 for (let j = 0; j < children.length; j++) {
116 result += stringifyElement(children[j]);
117 }
118 // Closing tag
119 if (_selfClosingTags.indexOf(tagName) == -1) {
120 result += `</${tagName}>`;
121 }
122 }
123 else if (isCommentNode(el)) {
124 result += `<!--${el.nodeValue}-->`;
125 }
126 else {
127 result += el.textContent;
128 }
129 return result;
130}
131function createNgZone() {
132 return new NgZone({ enableLongStackTrace: true, shouldCoalesceEventChangeDetection: false });
133}
134function isCommentNode(node) {
135 return node.nodeType === Node.COMMENT_NODE;
136}
137function isTextNode(node) {
138 return node.nodeType === Node.TEXT_NODE;
139}
140function getContent(node) {
141 if ('content' in node) {
142 return node.content;
143 }
144 else {
145 return node;
146 }
147}
148function templateAwareRoot(el) {
149 return ɵgetDOM().isElementNode(el) && el.nodeName === 'TEMPLATE' ? getContent(el) : el;
150}
151function setCookie(name, value) {
152 // document.cookie is magical, assigning into it assigns/overrides one cookie value, but does
153 // not clear other cookies.
154 document.cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value);
155}
156function hasStyle(element, styleName, styleValue) {
157 const value = element.style[styleName] || '';
158 return styleValue ? value == styleValue : value.length > 0;
159}
160function hasClass(element, className) {
161 return element.classList.contains(className);
162}
163function sortedClassList(element) {
164 return Array.prototype.slice.call(element.classList, 0).sort();
165}
166function createTemplate(html) {
167 const t = ɵgetDOM().getDefaultDocument().createElement('template');
168 t.innerHTML = html;
169 return t;
170}
171function childNodesAsList(el) {
172 const childNodes = el.childNodes;
173 const res = [];
174 for (let i = 0; i < childNodes.length; i++) {
175 res[i] = childNodes[i];
176 }
177 return res;
178}
179
180/**
181 * Controls whether the `MockPlatformLocation` class should be used
182 * as the `PlatformLocation` implementation when the `BrowserTestingModule`
183 * is imported.
184 *
185 * In v16, the value of this flag will be switched to `true` to enable
186 * the `MockPlatformLocation` by default.
187 */
188const ENABLE_MOCK_PLATFORM_LOCATION = false;
189
190function initBrowserTests() {
191 ɵBrowserDomAdapter.makeCurrent();
192 BrowserDetection.setup();
193}
194const _TEST_BROWSER_PLATFORM_PROVIDERS = [{ provide: PLATFORM_INITIALIZER, useValue: initBrowserTests, multi: true }];
195/**
196 * Platform for testing
197 *
198 * @publicApi
199 */
200const platformBrowserTesting = createPlatformFactory(platformCore, 'browserTesting', _TEST_BROWSER_PLATFORM_PROVIDERS);
201/**
202 * NgModule for testing.
203 *
204 * @publicApi
205 */
206class BrowserTestingModule {
207}
208BrowserTestingModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.2", ngImport: i0, type: BrowserTestingModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
209BrowserTestingModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.2", ngImport: i0, type: BrowserTestingModule, exports: [BrowserModule] });
210BrowserTestingModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.2", ngImport: i0, type: BrowserTestingModule, providers: [
211 { provide: APP_ID, useValue: 'a' },
212 { provide: NgZone, useFactory: createNgZone },
213 (ENABLE_MOCK_PLATFORM_LOCATION ? [{ provide: PlatformLocation, useClass: MockPlatformLocation }] :
214 []),
215 ], imports: [BrowserModule] });
216i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.2", ngImport: i0, type: BrowserTestingModule, decorators: [{
217 type: NgModule,
218 args: [{
219 exports: [BrowserModule],
220 providers: [
221 { provide: APP_ID, useValue: 'a' },
222 { provide: NgZone, useFactory: createNgZone },
223 (ENABLE_MOCK_PLATFORM_LOCATION ? [{ provide: PlatformLocation, useClass: MockPlatformLocation }] :
224 []),
225 ]
226 }]
227 }] });
228
229/**
230 * @module
231 * @description
232 * Entry point for all public APIs of the platform-browser/testing package.
233 */
234
235/// <reference types="jasmine" />
236
237// This file is not used to build this module. It is only used during editing
238
239/**
240 * Generated bundle index. Do not edit.
241 */
242
243export { BrowserTestingModule, platformBrowserTesting };
244//# sourceMappingURL=testing.mjs.map