1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | import { ɵgetDOM, PlatformLocation } from '@angular/common';
|
8 | import { MockPlatformLocation } from '@angular/common/testing';
|
9 | import * as i0 from '@angular/core';
|
10 | import { NgZone, PLATFORM_INITIALIZER, createPlatformFactory, platformCore, APP_ID, NgModule } from '@angular/core';
|
11 | import { ɵBrowserDomAdapter, BrowserModule } from '@angular/platform-browser';
|
12 |
|
13 | class 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 |
|
53 |
|
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 | }
|
63 | const browserDetection = BrowserDetection.setup();
|
64 | function 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 | }
|
70 | function createMouseEvent(eventType) {
|
71 | const evt = ɵgetDOM().getDefaultDocument().createEvent('MouseEvent');
|
72 | evt.initEvent(eventType, true, true);
|
73 | return evt;
|
74 | }
|
75 | function el(html) {
|
76 | return getContent(createTemplate(html)).firstChild;
|
77 | }
|
78 | function 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 | }
|
87 | const _selfClosingTags = ['br', 'hr', 'input'];
|
88 | function stringifyElement(el /** TODO #9100 */) {
|
89 | let result = '';
|
90 | if (ɵgetDOM().isElementNode(el)) {
|
91 | const tagName = el.tagName.toLowerCase();
|
92 |
|
93 | result += `<${tagName}`;
|
94 |
|
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 |
|
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 |
|
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 |
|
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 | }
|
131 | function createNgZone() {
|
132 | return new NgZone({ enableLongStackTrace: true, shouldCoalesceEventChangeDetection: false });
|
133 | }
|
134 | function isCommentNode(node) {
|
135 | return node.nodeType === Node.COMMENT_NODE;
|
136 | }
|
137 | function isTextNode(node) {
|
138 | return node.nodeType === Node.TEXT_NODE;
|
139 | }
|
140 | function getContent(node) {
|
141 | if ('content' in node) {
|
142 | return node.content;
|
143 | }
|
144 | else {
|
145 | return node;
|
146 | }
|
147 | }
|
148 | function templateAwareRoot(el) {
|
149 | return ɵgetDOM().isElementNode(el) && el.nodeName === 'TEMPLATE' ? getContent(el) : el;
|
150 | }
|
151 | function setCookie(name, value) {
|
152 |
|
153 |
|
154 | document.cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value);
|
155 | }
|
156 | function hasStyle(element, styleName, styleValue) {
|
157 | const value = element.style[styleName] || '';
|
158 | return styleValue ? value == styleValue : value.length > 0;
|
159 | }
|
160 | function hasClass(element, className) {
|
161 | return element.classList.contains(className);
|
162 | }
|
163 | function sortedClassList(element) {
|
164 | return Array.prototype.slice.call(element.classList, 0).sort();
|
165 | }
|
166 | function createTemplate(html) {
|
167 | const t = ɵgetDOM().getDefaultDocument().createElement('template');
|
168 | t.innerHTML = html;
|
169 | return t;
|
170 | }
|
171 | function 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 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 | const ENABLE_MOCK_PLATFORM_LOCATION = false;
|
189 |
|
190 | function initBrowserTests() {
|
191 | ɵBrowserDomAdapter.makeCurrent();
|
192 | BrowserDetection.setup();
|
193 | }
|
194 | const _TEST_BROWSER_PLATFORM_PROVIDERS = [{ provide: PLATFORM_INITIALIZER, useValue: initBrowserTests, multi: true }];
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 | const platformBrowserTesting = createPlatformFactory(platformCore, 'browserTesting', _TEST_BROWSER_PLATFORM_PROVIDERS);
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 | class BrowserTestingModule {
|
207 | }
|
208 | BrowserTestingModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.2", ngImport: i0, type: BrowserTestingModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
209 | BrowserTestingModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.2", ngImport: i0, type: BrowserTestingModule, exports: [BrowserModule] });
|
210 | BrowserTestingModule.ɵ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] });
|
216 | i0.ɵɵ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 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 | export { BrowserTestingModule, platformBrowserTesting };
|
244 |
|