1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | import { ɵglobal, NgZone, PLATFORM_INITIALIZER, createPlatformFactory, platformCore, NgModule, APP_ID } from '@angular/core';
|
8 | import { ɵgetDOM, ɵBrowserDomAdapter, BrowserModule, ɵELEMENT_PROBE_PROVIDERS } from '@angular/platform-browser';
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | let browserDetection;
|
16 | class BrowserDetection {
|
17 | |
18 |
|
19 |
|
20 |
|
21 | get _ua() {
|
22 | if (typeof this._overrideUa === 'string') {
|
23 | return this._overrideUa;
|
24 | }
|
25 | return ɵgetDOM() ? ɵgetDOM().getUserAgent() : '';
|
26 | }
|
27 | |
28 |
|
29 |
|
30 | static setup() { browserDetection = new BrowserDetection(null); }
|
31 | |
32 |
|
33 |
|
34 | constructor(ua) { this._overrideUa = ua; }
|
35 | |
36 |
|
37 |
|
38 | get isFirefox() { return this._ua.indexOf('Firefox') > -1; }
|
39 | |
40 |
|
41 |
|
42 | get isAndroid() {
|
43 | return this._ua.indexOf('Mozilla/5.0') > -1 && this._ua.indexOf('Android') > -1 &&
|
44 | this._ua.indexOf('AppleWebKit') > -1 && this._ua.indexOf('Chrome') == -1 &&
|
45 | this._ua.indexOf('IEMobile') == -1;
|
46 | }
|
47 | |
48 |
|
49 |
|
50 | get isEdge() { return this._ua.indexOf('Edge') > -1; }
|
51 | |
52 |
|
53 |
|
54 | get isIE() { return this._ua.indexOf('Trident') > -1; }
|
55 | |
56 |
|
57 |
|
58 | get isWebkit() {
|
59 | return this._ua.indexOf('AppleWebKit') > -1 && this._ua.indexOf('Edge') == -1 &&
|
60 | this._ua.indexOf('IEMobile') == -1;
|
61 | }
|
62 | |
63 |
|
64 |
|
65 | get isIOS7() {
|
66 | return (this._ua.indexOf('iPhone OS 7') > -1 || this._ua.indexOf('iPad OS 7') > -1) &&
|
67 | this._ua.indexOf('IEMobile') == -1;
|
68 | }
|
69 | |
70 |
|
71 |
|
72 | get isSlow() { return this.isAndroid || this.isIE || this.isIOS7; }
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | |
78 |
|
79 |
|
80 | get supportsNativeIntlApi() {
|
81 | return !!(( (ɵglobal))).Intl && (( (ɵglobal))).Intl !== (( (ɵglobal))).IntlPolyfill;
|
82 | }
|
83 | |
84 |
|
85 |
|
86 | get isChromeDesktop() {
|
87 | return this._ua.indexOf('Chrome') > -1 && this._ua.indexOf('Mobile Safari') == -1 &&
|
88 | this._ua.indexOf('Edge') == -1;
|
89 | }
|
90 |
|
91 |
|
92 | |
93 |
|
94 |
|
95 | get isOldChrome() {
|
96 | return this._ua.indexOf('Chrome') > -1 && this._ua.indexOf('Chrome/3') > -1 &&
|
97 | this._ua.indexOf('Edge') == -1;
|
98 | }
|
99 | |
100 |
|
101 |
|
102 | get supportsCustomElements() { return (typeof (( (ɵglobal))).customElements !== 'undefined'); }
|
103 | |
104 |
|
105 |
|
106 | get supportsDeprecatedCustomCustomElementsV0() {
|
107 | return (typeof (( (document))).registerElement !== 'undefined');
|
108 | }
|
109 | |
110 |
|
111 |
|
112 | get supportsRegExUnicodeFlag() { return RegExp.prototype.hasOwnProperty('unicode'); }
|
113 | |
114 |
|
115 |
|
116 | get supportsShadowDom() {
|
117 |
|
118 | const testEl = document.createElement('div');
|
119 | return (typeof testEl.attachShadow !== 'undefined');
|
120 | }
|
121 | |
122 |
|
123 |
|
124 | get supportsDeprecatedShadowDomV0() {
|
125 |
|
126 | const testEl = ( (document.createElement('div')));
|
127 | return (typeof testEl.createShadowRoot !== 'undefined');
|
128 | }
|
129 | }
|
130 | if (false) {
|
131 | |
132 |
|
133 |
|
134 |
|
135 | BrowserDetection.prototype._overrideUa;
|
136 | }
|
137 | BrowserDetection.setup();
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 | function dispatchEvent(element, eventType) {
|
144 | ɵgetDOM().dispatchEvent(element, ɵgetDOM().createEvent(eventType));
|
145 | }
|
146 |
|
147 |
|
148 |
|
149 |
|
150 | function el(html) {
|
151 | return ( (ɵgetDOM().firstChild(ɵgetDOM().content(ɵgetDOM().createTemplate(html)))));
|
152 | }
|
153 |
|
154 |
|
155 |
|
156 |
|
157 | function normalizeCSS(css) {
|
158 | return css.replace(/\s+/g, ' ')
|
159 | .replace(/:\s/g, ':')
|
160 | .replace(/'/g, '"')
|
161 | .replace(/ }/g, '}')
|
162 | .replace(/url\((\"|\s)(.+)(\"|\s)\)(\s*)/g, ( |
163 |
|
164 |
|
165 |
|
166 | (...match) => `url("${match[2]}")`))
|
167 | .replace(/\[(.+)=([^"\]]+)\]/g, ( |
168 |
|
169 |
|
170 |
|
171 | (...match) => `[${match[1]}="${match[2]}"]`));
|
172 | }
|
173 |
|
174 | const _selfClosingTags = ['br', 'hr', 'input'];
|
175 |
|
176 |
|
177 |
|
178 |
|
179 | function stringifyElement(el /** TODO #9100 */) {
|
180 |
|
181 | let result = '';
|
182 | if (ɵgetDOM().isElementNode(el)) {
|
183 |
|
184 | const tagName = ɵgetDOM().tagName(el).toLowerCase();
|
185 |
|
186 | result += `<${tagName}`;
|
187 |
|
188 |
|
189 | const attributeMap = ɵgetDOM().attributeMap(el);
|
190 |
|
191 | const sortedKeys = Array.from(attributeMap.keys()).sort();
|
192 | for (const key of sortedKeys) {
|
193 |
|
194 | const lowerCaseKey = key.toLowerCase();
|
195 |
|
196 | let attValue = attributeMap.get(key);
|
197 | if (typeof attValue !== 'string') {
|
198 | result += ` ${lowerCaseKey}`;
|
199 | }
|
200 | else {
|
201 |
|
202 | if (lowerCaseKey === 'style') {
|
203 | attValue = attValue.split(/; ?/).filter(( |
204 |
|
205 |
|
206 |
|
207 | s => !!s)).sort().map(( |
208 |
|
209 |
|
210 |
|
211 | s => `${s};`)).join(' ');
|
212 | }
|
213 | result += ` ${lowerCaseKey}="${attValue}"`;
|
214 | }
|
215 | }
|
216 | result += '>';
|
217 |
|
218 |
|
219 | const childrenRoot = ɵgetDOM().templateAwareRoot(el);
|
220 |
|
221 | const children = childrenRoot ? ɵgetDOM().childNodes(childrenRoot) : [];
|
222 | for (let j = 0; j < children.length; j++) {
|
223 | result += stringifyElement(children[j]);
|
224 | }
|
225 |
|
226 | if (_selfClosingTags.indexOf(tagName) == -1) {
|
227 | result += `</${tagName}>`;
|
228 | }
|
229 | }
|
230 | else if (ɵgetDOM().isCommentNode(el)) {
|
231 | result += `<!--${ɵgetDOM().nodeValue(el)}-->`;
|
232 | }
|
233 | else {
|
234 | result += ɵgetDOM().getText(el);
|
235 | }
|
236 | return result;
|
237 | }
|
238 |
|
239 |
|
240 |
|
241 | function createNgZone() {
|
242 | return new NgZone({ enableLongStackTrace: true });
|
243 | }
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 | function initBrowserTests() {
|
253 | ɵBrowserDomAdapter.makeCurrent();
|
254 | BrowserDetection.setup();
|
255 | }
|
256 |
|
257 | const _TEST_BROWSER_PLATFORM_PROVIDERS = [{ provide: PLATFORM_INITIALIZER, useValue: initBrowserTests, multi: true }];
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 | const platformBrowserTesting = createPlatformFactory(platformCore, 'browserTesting', _TEST_BROWSER_PLATFORM_PROVIDERS);
|
265 | const ɵ0 = createNgZone;
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 | class BrowserTestingModule {
|
272 | }
|
273 | BrowserTestingModule.decorators = [
|
274 | { type: NgModule, args: [{
|
275 | exports: [BrowserModule],
|
276 | providers: [
|
277 | { provide: APP_ID, useValue: 'a' },
|
278 | ɵELEMENT_PROBE_PROVIDERS,
|
279 | { provide: NgZone, useFactory: ɵ0 },
|
280 | ]
|
281 | },] }
|
282 | ];
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 | export { createNgZone as ɵangular_packages_platform_browser_testing_testing_a, platformBrowserTesting, BrowserTestingModule };
|
304 |
|