245 lines
8.5 KiB
JavaScript
245 lines
8.5 KiB
JavaScript
|
|
/**
|
||
|
|
* @license Angular v15.2.10
|
||
|
|
* (c) 2010-2022 Google LLC. https://angular.io/
|
||
|
|
* License: MIT
|
||
|
|
*/
|
||
|
|
|
||
|
|
import { ɵgetDOM, PlatformLocation } from '@angular/common';
|
||
|
|
import { MockPlatformLocation } from '@angular/common/testing';
|
||
|
|
import * as i0 from '@angular/core';
|
||
|
|
import { NgZone, PLATFORM_INITIALIZER, createPlatformFactory, platformCore, APP_ID, NgModule } from '@angular/core';
|
||
|
|
import { ɵBrowserDomAdapter, BrowserModule } from '@angular/platform-browser';
|
||
|
|
|
||
|
|
class BrowserDetection {
|
||
|
|
get _ua() {
|
||
|
|
if (typeof this._overrideUa === 'string') {
|
||
|
|
return this._overrideUa;
|
||
|
|
}
|
||
|
|
return ɵgetDOM() ? ɵgetDOM().getUserAgent() : '';
|
||
|
|
}
|
||
|
|
static setup() {
|
||
|
|
return new BrowserDetection(null);
|
||
|
|
}
|
||
|
|
constructor(ua) {
|
||
|
|
this._overrideUa = ua;
|
||
|
|
}
|
||
|
|
get isFirefox() {
|
||
|
|
return this._ua.indexOf('Firefox') > -1;
|
||
|
|
}
|
||
|
|
get isAndroid() {
|
||
|
|
return this._ua.indexOf('Mozilla/5.0') > -1 && this._ua.indexOf('Android') > -1 &&
|
||
|
|
this._ua.indexOf('AppleWebKit') > -1 && this._ua.indexOf('Chrome') == -1 &&
|
||
|
|
this._ua.indexOf('IEMobile') == -1;
|
||
|
|
}
|
||
|
|
get isEdge() {
|
||
|
|
return this._ua.indexOf('Edge') > -1;
|
||
|
|
}
|
||
|
|
get isWebkit() {
|
||
|
|
return this._ua.indexOf('AppleWebKit') > -1 && this._ua.indexOf('Edge') == -1 &&
|
||
|
|
this._ua.indexOf('IEMobile') == -1;
|
||
|
|
}
|
||
|
|
get isIOS7() {
|
||
|
|
return (this._ua.indexOf('iPhone OS 7') > -1 || this._ua.indexOf('iPad OS 7') > -1) &&
|
||
|
|
this._ua.indexOf('IEMobile') == -1;
|
||
|
|
}
|
||
|
|
get isSlow() {
|
||
|
|
return this.isAndroid || this.isIOS7;
|
||
|
|
}
|
||
|
|
get isChromeDesktop() {
|
||
|
|
return this._ua.indexOf('Chrome') > -1 && this._ua.indexOf('Mobile Safari') == -1 &&
|
||
|
|
this._ua.indexOf('Edge') == -1;
|
||
|
|
}
|
||
|
|
// "Old Chrome" means Chrome 3X, where there are some discrepancies in the Intl API.
|
||
|
|
// Android 4.4 and 5.X have such browsers by default (respectively 30 and 39).
|
||
|
|
get isOldChrome() {
|
||
|
|
return this._ua.indexOf('Chrome') > -1 && this._ua.indexOf('Chrome/3') > -1 &&
|
||
|
|
this._ua.indexOf('Edge') == -1;
|
||
|
|
}
|
||
|
|
get supportsShadowDom() {
|
||
|
|
const testEl = document.createElement('div');
|
||
|
|
return (typeof testEl.attachShadow !== 'undefined');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
const browserDetection = BrowserDetection.setup();
|
||
|
|
function dispatchEvent(element, eventType) {
|
||
|
|
const evt = ɵgetDOM().getDefaultDocument().createEvent('Event');
|
||
|
|
evt.initEvent(eventType, true, true);
|
||
|
|
ɵgetDOM().dispatchEvent(element, evt);
|
||
|
|
return evt;
|
||
|
|
}
|
||
|
|
function createMouseEvent(eventType) {
|
||
|
|
const evt = ɵgetDOM().getDefaultDocument().createEvent('MouseEvent');
|
||
|
|
evt.initEvent(eventType, true, true);
|
||
|
|
return evt;
|
||
|
|
}
|
||
|
|
function el(html) {
|
||
|
|
return getContent(createTemplate(html)).firstChild;
|
||
|
|
}
|
||
|
|
function getAttributeMap(element) {
|
||
|
|
const res = new Map();
|
||
|
|
const elAttrs = element.attributes;
|
||
|
|
for (let i = 0; i < elAttrs.length; i++) {
|
||
|
|
const attrib = elAttrs.item(i);
|
||
|
|
res.set(attrib.name, attrib.value);
|
||
|
|
}
|
||
|
|
return res;
|
||
|
|
}
|
||
|
|
const _selfClosingTags = ['br', 'hr', 'input'];
|
||
|
|
function stringifyElement(el /** TODO #9100 */) {
|
||
|
|
let result = '';
|
||
|
|
if (ɵgetDOM().isElementNode(el)) {
|
||
|
|
const tagName = el.tagName.toLowerCase();
|
||
|
|
// Opening tag
|
||
|
|
result += `<${tagName}`;
|
||
|
|
// Attributes in an ordered way
|
||
|
|
const attributeMap = getAttributeMap(el);
|
||
|
|
const sortedKeys = Array.from(attributeMap.keys()).sort();
|
||
|
|
for (const key of sortedKeys) {
|
||
|
|
const lowerCaseKey = key.toLowerCase();
|
||
|
|
let attValue = attributeMap.get(key);
|
||
|
|
if (typeof attValue !== 'string') {
|
||
|
|
result += ` ${lowerCaseKey}`;
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
// Browsers order style rules differently. Order them alphabetically for consistency.
|
||
|
|
if (lowerCaseKey === 'style') {
|
||
|
|
attValue = attValue.split(/; ?/).filter(s => !!s).sort().map(s => `${s};`).join(' ');
|
||
|
|
}
|
||
|
|
result += ` ${lowerCaseKey}="${attValue}"`;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
result += '>';
|
||
|
|
// Children
|
||
|
|
const childrenRoot = templateAwareRoot(el);
|
||
|
|
const children = childrenRoot ? childrenRoot.childNodes : [];
|
||
|
|
for (let j = 0; j < children.length; j++) {
|
||
|
|
result += stringifyElement(children[j]);
|
||
|
|
}
|
||
|
|
// Closing tag
|
||
|
|
if (_selfClosingTags.indexOf(tagName) == -1) {
|
||
|
|
result += `</${tagName}>`;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else if (isCommentNode(el)) {
|
||
|
|
result += `<!--${el.nodeValue}-->`;
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
result += el.textContent;
|
||
|
|
}
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
function createNgZone() {
|
||
|
|
return new NgZone({ enableLongStackTrace: true, shouldCoalesceEventChangeDetection: false });
|
||
|
|
}
|
||
|
|
function isCommentNode(node) {
|
||
|
|
return node.nodeType === Node.COMMENT_NODE;
|
||
|
|
}
|
||
|
|
function isTextNode(node) {
|
||
|
|
return node.nodeType === Node.TEXT_NODE;
|
||
|
|
}
|
||
|
|
function getContent(node) {
|
||
|
|
if ('content' in node) {
|
||
|
|
return node.content;
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
return node;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
function templateAwareRoot(el) {
|
||
|
|
return ɵgetDOM().isElementNode(el) && el.nodeName === 'TEMPLATE' ? getContent(el) : el;
|
||
|
|
}
|
||
|
|
function setCookie(name, value) {
|
||
|
|
// document.cookie is magical, assigning into it assigns/overrides one cookie value, but does
|
||
|
|
// not clear other cookies.
|
||
|
|
document.cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value);
|
||
|
|
}
|
||
|
|
function hasStyle(element, styleName, styleValue) {
|
||
|
|
const value = element.style[styleName] || '';
|
||
|
|
return styleValue ? value == styleValue : value.length > 0;
|
||
|
|
}
|
||
|
|
function hasClass(element, className) {
|
||
|
|
return element.classList.contains(className);
|
||
|
|
}
|
||
|
|
function sortedClassList(element) {
|
||
|
|
return Array.prototype.slice.call(element.classList, 0).sort();
|
||
|
|
}
|
||
|
|
function createTemplate(html) {
|
||
|
|
const t = ɵgetDOM().getDefaultDocument().createElement('template');
|
||
|
|
t.innerHTML = html;
|
||
|
|
return t;
|
||
|
|
}
|
||
|
|
function childNodesAsList(el) {
|
||
|
|
const childNodes = el.childNodes;
|
||
|
|
const res = [];
|
||
|
|
for (let i = 0; i < childNodes.length; i++) {
|
||
|
|
res[i] = childNodes[i];
|
||
|
|
}
|
||
|
|
return res;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Controls whether the `MockPlatformLocation` class should be used
|
||
|
|
* as the `PlatformLocation` implementation when the `BrowserTestingModule`
|
||
|
|
* is imported.
|
||
|
|
*
|
||
|
|
* In v16, the value of this flag will be switched to `true` to enable
|
||
|
|
* the `MockPlatformLocation` by default.
|
||
|
|
*/
|
||
|
|
const ENABLE_MOCK_PLATFORM_LOCATION = false;
|
||
|
|
|
||
|
|
function initBrowserTests() {
|
||
|
|
ɵBrowserDomAdapter.makeCurrent();
|
||
|
|
BrowserDetection.setup();
|
||
|
|
}
|
||
|
|
const _TEST_BROWSER_PLATFORM_PROVIDERS = [{ provide: PLATFORM_INITIALIZER, useValue: initBrowserTests, multi: true }];
|
||
|
|
/**
|
||
|
|
* Platform for testing
|
||
|
|
*
|
||
|
|
* @publicApi
|
||
|
|
*/
|
||
|
|
const platformBrowserTesting = createPlatformFactory(platformCore, 'browserTesting', _TEST_BROWSER_PLATFORM_PROVIDERS);
|
||
|
|
/**
|
||
|
|
* NgModule for testing.
|
||
|
|
*
|
||
|
|
* @publicApi
|
||
|
|
*/
|
||
|
|
class BrowserTestingModule {
|
||
|
|
}
|
||
|
|
BrowserTestingModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: BrowserTestingModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
||
|
|
BrowserTestingModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.10", ngImport: i0, type: BrowserTestingModule, exports: [BrowserModule] });
|
||
|
|
BrowserTestingModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: BrowserTestingModule, providers: [
|
||
|
|
{ provide: APP_ID, useValue: 'a' },
|
||
|
|
{ provide: NgZone, useFactory: createNgZone },
|
||
|
|
(ENABLE_MOCK_PLATFORM_LOCATION ? [{ provide: PlatformLocation, useClass: MockPlatformLocation }] :
|
||
|
|
[]),
|
||
|
|
], imports: [BrowserModule] });
|
||
|
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: BrowserTestingModule, decorators: [{
|
||
|
|
type: NgModule,
|
||
|
|
args: [{
|
||
|
|
exports: [BrowserModule],
|
||
|
|
providers: [
|
||
|
|
{ provide: APP_ID, useValue: 'a' },
|
||
|
|
{ provide: NgZone, useFactory: createNgZone },
|
||
|
|
(ENABLE_MOCK_PLATFORM_LOCATION ? [{ provide: PlatformLocation, useClass: MockPlatformLocation }] :
|
||
|
|
[]),
|
||
|
|
]
|
||
|
|
}]
|
||
|
|
}] });
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @module
|
||
|
|
* @description
|
||
|
|
* Entry point for all public APIs of the platform-browser/testing package.
|
||
|
|
*/
|
||
|
|
|
||
|
|
/// <reference types="jasmine" />
|
||
|
|
|
||
|
|
// This file is not used to build this module. It is only used during editing
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Generated bundle index. Do not edit.
|
||
|
|
*/
|
||
|
|
|
||
|
|
export { BrowserTestingModule, platformBrowserTesting };
|
||
|
|
//# sourceMappingURL=testing.mjs.map
|