UNPKG

12.5 kBJavaScriptView Raw
1/**
2 * @license Angular v9.1.3
3 * (c) 2010-2020 Google LLC. https://angular.io/
4 * License: MIT
5 */
6
7import { ɵglobal, NgZone, PLATFORM_INITIALIZER, createPlatformFactory, platformCore, NgModule, APP_ID } from '@angular/core';
8import { ɵBrowserDomAdapter, BrowserModule, ɵELEMENT_PROBE_PROVIDERS } from '@angular/platform-browser';
9import { ɵgetDOM } from '@angular/common';
10
11/**
12 * @fileoverview added by tsickle
13 * Generated from: packages/platform-browser/testing/src/browser_util.ts
14 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
15 */
16class BrowserDetection {
17 /**
18 * @param {?} ua
19 */
20 constructor(ua) {
21 this._overrideUa = ua;
22 }
23 /**
24 * @private
25 * @return {?}
26 */
27 get _ua() {
28 if (typeof this._overrideUa === 'string') {
29 return this._overrideUa;
30 }
31 return ɵgetDOM() ? ɵgetDOM().getUserAgent() : '';
32 }
33 /**
34 * @return {?}
35 */
36 static setup() {
37 return new BrowserDetection(null);
38 }
39 /**
40 * @return {?}
41 */
42 get isFirefox() {
43 return this._ua.indexOf('Firefox') > -1;
44 }
45 /**
46 * @return {?}
47 */
48 get isAndroid() {
49 return this._ua.indexOf('Mozilla/5.0') > -1 && this._ua.indexOf('Android') > -1 &&
50 this._ua.indexOf('AppleWebKit') > -1 && this._ua.indexOf('Chrome') == -1 &&
51 this._ua.indexOf('IEMobile') == -1;
52 }
53 /**
54 * @return {?}
55 */
56 get isEdge() {
57 return this._ua.indexOf('Edge') > -1;
58 }
59 /**
60 * @return {?}
61 */
62 get isIE() {
63 return this._ua.indexOf('Trident') > -1;
64 }
65 /**
66 * @return {?}
67 */
68 get isWebkit() {
69 return this._ua.indexOf('AppleWebKit') > -1 && this._ua.indexOf('Edge') == -1 &&
70 this._ua.indexOf('IEMobile') == -1;
71 }
72 /**
73 * @return {?}
74 */
75 get isIOS7() {
76 return (this._ua.indexOf('iPhone OS 7') > -1 || this._ua.indexOf('iPad OS 7') > -1) &&
77 this._ua.indexOf('IEMobile') == -1;
78 }
79 /**
80 * @return {?}
81 */
82 get isSlow() {
83 return this.isAndroid || this.isIE || this.isIOS7;
84 }
85 // The Intl API is only natively supported in Chrome, Firefox, IE11 and Edge.
86 // This detector is needed in tests to make the difference between:
87 // 1) IE11/Edge: they have a native Intl API, but with some discrepancies
88 // 2) IE9/IE10: they use the polyfill, and so no discrepancies
89 /**
90 * @return {?}
91 */
92 get supportsNativeIntlApi() {
93 return !!((/** @type {?} */ (ɵglobal))).Intl && ((/** @type {?} */ (ɵglobal))).Intl !== ((/** @type {?} */ (ɵglobal))).IntlPolyfill;
94 }
95 /**
96 * @return {?}
97 */
98 get isChromeDesktop() {
99 return this._ua.indexOf('Chrome') > -1 && this._ua.indexOf('Mobile Safari') == -1 &&
100 this._ua.indexOf('Edge') == -1;
101 }
102 // "Old Chrome" means Chrome 3X, where there are some discrepancies in the Intl API.
103 // Android 4.4 and 5.X have such browsers by default (respectively 30 and 39).
104 /**
105 * @return {?}
106 */
107 get isOldChrome() {
108 return this._ua.indexOf('Chrome') > -1 && this._ua.indexOf('Chrome/3') > -1 &&
109 this._ua.indexOf('Edge') == -1;
110 }
111 /**
112 * @return {?}
113 */
114 get supportsCustomElements() {
115 return (typeof ((/** @type {?} */ (ɵglobal))).customElements !== 'undefined');
116 }
117 /**
118 * @return {?}
119 */
120 get supportsDeprecatedCustomCustomElementsV0() {
121 return (typeof ((/** @type {?} */ (document))).registerElement !== 'undefined');
122 }
123 /**
124 * @return {?}
125 */
126 get supportsRegExUnicodeFlag() {
127 return RegExp.prototype.hasOwnProperty('unicode');
128 }
129 /**
130 * @return {?}
131 */
132 get supportsShadowDom() {
133 /** @type {?} */
134 const testEl = document.createElement('div');
135 return (typeof testEl.attachShadow !== 'undefined');
136 }
137 /**
138 * @return {?}
139 */
140 get supportsDeprecatedShadowDomV0() {
141 /** @type {?} */
142 const testEl = (/** @type {?} */ (document.createElement('div')));
143 return (typeof testEl.createShadowRoot !== 'undefined');
144 }
145}
146if (false) {
147 /**
148 * @type {?}
149 * @private
150 */
151 BrowserDetection.prototype._overrideUa;
152}
153/** @type {?} */
154const browserDetection = BrowserDetection.setup();
155/**
156 * @param {?} element
157 * @param {?} eventType
158 * @return {?}
159 */
160function dispatchEvent(element, eventType) {
161 /** @type {?} */
162 const evt = ɵgetDOM().getDefaultDocument().createEvent('Event');
163 evt.initEvent(eventType, true, true);
164 ɵgetDOM().dispatchEvent(element, evt);
165}
166/**
167 * @param {?} eventType
168 * @return {?}
169 */
170function createMouseEvent(eventType) {
171 /** @type {?} */
172 const evt = ɵgetDOM().getDefaultDocument().createEvent('MouseEvent');
173 evt.initEvent(eventType, true, true);
174 return evt;
175}
176/**
177 * @param {?} html
178 * @return {?}
179 */
180function el(html) {
181 return (/** @type {?} */ (getContent(createTemplate(html)).firstChild));
182}
183/**
184 * @param {?} css
185 * @return {?}
186 */
187function normalizeCSS(css) {
188 return css.replace(/\s+/g, ' ')
189 .replace(/:\s/g, ':')
190 .replace(/'/g, '"')
191 .replace(/ }/g, '}')
192 .replace(/url\((\"|\s)(.+)(\"|\s)\)(\s*)/g, (/**
193 * @param {...?} match
194 * @return {?}
195 */
196 (...match) => `url("${match[2]}")`))
197 .replace(/\[(.+)=([^"\]]+)\]/g, (/**
198 * @param {...?} match
199 * @return {?}
200 */
201 (...match) => `[${match[1]}="${match[2]}"]`));
202}
203/**
204 * @param {?} element
205 * @return {?}
206 */
207function getAttributeMap(element) {
208 /** @type {?} */
209 const res = new Map();
210 /** @type {?} */
211 const elAttrs = element.attributes;
212 for (let i = 0; i < elAttrs.length; i++) {
213 /** @type {?} */
214 const attrib = elAttrs.item(i);
215 res.set(attrib.name, attrib.value);
216 }
217 return res;
218}
219/** @type {?} */
220const _selfClosingTags = ['br', 'hr', 'input'];
221/**
222 * @param {?} el
223 * @return {?}
224 */
225function stringifyElement(el /** TODO #9100 */) {
226 /** @type {?} */
227 let result = '';
228 if (ɵgetDOM().isElementNode(el)) {
229 /** @type {?} */
230 const tagName = el.tagName.toLowerCase();
231 // Opening tag
232 result += `<${tagName}`;
233 // Attributes in an ordered way
234 /** @type {?} */
235 const attributeMap = getAttributeMap(el);
236 /** @type {?} */
237 const sortedKeys = Array.from(attributeMap.keys()).sort();
238 for (const key of sortedKeys) {
239 /** @type {?} */
240 const lowerCaseKey = key.toLowerCase();
241 /** @type {?} */
242 let attValue = attributeMap.get(key);
243 if (typeof attValue !== 'string') {
244 result += ` ${lowerCaseKey}`;
245 }
246 else {
247 // Browsers order style rules differently. Order them alphabetically for consistency.
248 if (lowerCaseKey === 'style') {
249 attValue = attValue.split(/; ?/).filter((/**
250 * @param {?} s
251 * @return {?}
252 */
253 s => !!s)).sort().map((/**
254 * @param {?} s
255 * @return {?}
256 */
257 s => `${s};`)).join(' ');
258 }
259 result += ` ${lowerCaseKey}="${attValue}"`;
260 }
261 }
262 result += '>';
263 // Children
264 /** @type {?} */
265 const childrenRoot = templateAwareRoot(el);
266 /** @type {?} */
267 const children = childrenRoot ? childrenRoot.childNodes : [];
268 for (let j = 0; j < children.length; j++) {
269 result += stringifyElement(children[j]);
270 }
271 // Closing tag
272 if (_selfClosingTags.indexOf(tagName) == -1) {
273 result += `</${tagName}>`;
274 }
275 }
276 else if (isCommentNode(el)) {
277 result += `<!--${el.nodeValue}-->`;
278 }
279 else {
280 result += el.textContent;
281 }
282 return result;
283}
284/**
285 * @return {?}
286 */
287function createNgZone() {
288 return new NgZone({ enableLongStackTrace: true, shouldCoalesceEventChangeDetection: false });
289}
290/**
291 * @param {?} node
292 * @return {?}
293 */
294function isCommentNode(node) {
295 return node.nodeType === Node.COMMENT_NODE;
296}
297/**
298 * @param {?} node
299 * @return {?}
300 */
301function isTextNode(node) {
302 return node.nodeType === Node.TEXT_NODE;
303}
304/**
305 * @param {?} node
306 * @return {?}
307 */
308function getContent(node) {
309 if ('content' in node) {
310 return ((/** @type {?} */ (node))).content;
311 }
312 else {
313 return node;
314 }
315}
316/**
317 * @param {?} el
318 * @return {?}
319 */
320function templateAwareRoot(el) {
321 return ɵgetDOM().isElementNode(el) && el.nodeName === 'TEMPLATE' ? getContent(el) : el;
322}
323/**
324 * @param {?} name
325 * @param {?} value
326 * @return {?}
327 */
328function setCookie(name, value) {
329 // document.cookie is magical, assigning into it assigns/overrides one cookie value, but does
330 // not clear other cookies.
331 document.cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value);
332}
333/**
334 * @return {?}
335 */
336function supportsWebAnimation() {
337 return typeof ((/** @type {?} */ (Element))).prototype['animate'] === 'function';
338}
339/**
340 * @param {?} element
341 * @param {?} styleName
342 * @param {?=} styleValue
343 * @return {?}
344 */
345function hasStyle(element, styleName, styleValue) {
346 /** @type {?} */
347 const value = element.style[styleName] || '';
348 return styleValue ? value == styleValue : value.length > 0;
349}
350/**
351 * @param {?} element
352 * @param {?} className
353 * @return {?}
354 */
355function hasClass(element, className) {
356 return element.classList.contains(className);
357}
358/**
359 * @param {?} element
360 * @return {?}
361 */
362function sortedClassList(element) {
363 return Array.prototype.slice.call(element.classList, 0).sort();
364}
365/**
366 * @param {?} html
367 * @return {?}
368 */
369function createTemplate(html) {
370 /** @type {?} */
371 const t = ɵgetDOM().getDefaultDocument().createElement('template');
372 t.innerHTML = html;
373 return t;
374}
375/**
376 * @param {?} el
377 * @return {?}
378 */
379function childNodesAsList(el) {
380 /** @type {?} */
381 const childNodes = el.childNodes;
382 /** @type {?} */
383 const res = [];
384 for (let i = 0; i < childNodes.length; i++) {
385 res[i] = childNodes[i];
386 }
387 return res;
388}
389
390/**
391 * @fileoverview added by tsickle
392 * Generated from: packages/platform-browser/testing/src/browser.ts
393 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
394 */
395/**
396 * @return {?}
397 */
398function initBrowserTests() {
399 ɵBrowserDomAdapter.makeCurrent();
400 BrowserDetection.setup();
401}
402/** @type {?} */
403const _TEST_BROWSER_PLATFORM_PROVIDERS = [{ provide: PLATFORM_INITIALIZER, useValue: initBrowserTests, multi: true }];
404/**
405 * Platform for testing
406 *
407 * \@publicApi
408 * @type {?}
409 */
410const platformBrowserTesting = createPlatformFactory(platformCore, 'browserTesting', _TEST_BROWSER_PLATFORM_PROVIDERS);
411const ɵ0 = createNgZone;
412/**
413 * NgModule for testing.
414 *
415 * \@publicApi
416 */
417class BrowserTestingModule {
418}
419BrowserTestingModule.decorators = [
420 { type: NgModule, args: [{
421 exports: [BrowserModule],
422 providers: [
423 { provide: APP_ID, useValue: 'a' },
424 ɵELEMENT_PROBE_PROVIDERS,
425 { provide: NgZone, useFactory: ɵ0 },
426 ]
427 },] }
428];
429
430/**
431 * @fileoverview added by tsickle
432 * Generated from: packages/platform-browser/testing/src/testing.ts
433 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
434 */
435
436/**
437 * @fileoverview added by tsickle
438 * Generated from: packages/platform-browser/testing/public_api.ts
439 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
440 */
441
442/**
443 * @fileoverview added by tsickle
444 * Generated from: packages/platform-browser/testing/index.ts
445 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
446 */
447
448/**
449 * Generated bundle index. Do not edit.
450 */
451
452export { BrowserTestingModule, platformBrowserTesting, createNgZone as ɵangular_packages_platform_browser_testing_testing_a };
453//# sourceMappingURL=testing.js.map