refactor(core): move Meta methods that only have one version from DomAdapter (#32408)

PR Close #32408
This commit is contained in:
Kara Erickson 2019-08-30 12:52:48 -07:00 committed by Miško Hevery
parent 1a7c79746d
commit 89434e09c2
28 changed files with 88 additions and 111 deletions

View File

@ -16,8 +16,8 @@
"uncompressed": {
"runtime-es5": 3042,
"runtime-es2015": 3048,
"main-es5": 499085,
"main-es2015": 438296,
"main-es5": 493330,
"main-es2015": 435296,
"polyfills-es5": 131024,
"polyfills-es2015": 52433
}
@ -28,7 +28,7 @@
"uncompressed": {
"runtime-es5": 2932,
"runtime-es2015": 2938,
"main-es5": 552068,
"main-es5": 550854,
"main-es2015": 493320,
"polyfills-es5": 131024,
"polyfills-es2015": 52433

View File

@ -3,7 +3,7 @@
"master": {
"uncompressed": {
"runtime": 1497,
"main": 158490,
"main": 157490,
"polyfills": 45399
}
}
@ -21,7 +21,7 @@
"master": {
"uncompressed": {
"runtime": 1440,
"main": 125882,
"main": 123904,
"polyfills": 45340
}
}

View File

@ -40,13 +40,8 @@ export abstract class DomAdapter {
abstract logGroupEnd(): any;
// Used by Meta
abstract querySelectorAll(el: any, selector: string): any[];
abstract remove(el: any): Node;
abstract getAttribute(element: any, attribute: string): string|null;
abstract appendChild(el: any, node: any): any;
abstract createElement(tagName: any, doc?: any): HTMLElement;
abstract setAttribute(element: any, name: string, value: string): any;
abstract getElementsByTagName(element: any, name: string): HTMLElement[];
abstract createHtmlDocument(): HTMLDocument;
abstract getDefaultDocument(): Document;

View File

@ -128,7 +128,7 @@ import {el} from '@angular/platform-browser/testing/src/browser_util';
const elementSelector = new CssSelector();
const element = el('<div attr></div>');
const empty = getDOM().getAttribute(element, 'attr') !;
const empty = element.getAttribute('attr') !;
elementSelector.addAttribute('some-decor', empty);
matcher.match(elementSelector, selectableCollector);
expect(matched).toEqual([s1[0], 1]);

View File

@ -35,11 +35,11 @@ class SomeComponent {
const doc = TestBed.get(DOCUMENT);
const rootEl =
<HTMLElement>getContent(createTemplate(`<${selector}></${selector}>`)).firstChild;
const oldRoots = getDOM().querySelectorAll(doc, selector);
const oldRoots = doc.querySelectorAll(selector);
for (let i = 0; i < oldRoots.length; i++) {
getDOM().remove(oldRoots[i]);
}
getDOM().appendChild(doc.body, rootEl);
doc.body.appendChild(rootEl);
}
type CreateModuleOptions =

View File

@ -883,7 +883,7 @@ class TestCmptWithPropBindings {
// Move the content element outside the component
// so that it can't be reached via querySelector.
getDOM().appendChild(parent, content);
parent.appendChild(content);
expect(fixture.debugElement.query(By.css('.content'))).toBeTruthy();

View File

@ -21,13 +21,13 @@ import {isTextNode} from '@angular/platform-browser/testing/src/browser_util';
const t = getDOM().getDefaultDocument().createTextNode('hello');
expect(isTextNode(t)).toBe(true);
const d = getDOM().createElement('div');
getDOM().appendChild(d, t);
d.appendChild(t);
expect(d.innerHTML).toEqual('hello');
});
it('should set className via the class attribute', () => {
const d = getDOM().createElement('div');
getDOM().setAttribute(d, 'class', 'class1');
d.setAttribute('class', 'class1');
expect(d.className).toEqual('class1');
});
@ -45,9 +45,9 @@ import {isTextNode} from '@angular/platform-browser/testing/src/browser_util';
it('should return the value of the base element', () => {
const baseEl = getDOM().createElement('base');
getDOM().setAttribute(baseEl, 'href', '/drop/bass/connon/');
baseEl.setAttribute('href', '/drop/bass/connon/');
const headEl = defaultDoc.head;
getDOM().appendChild(headEl, baseEl);
headEl.appendChild(baseEl);
const baseHref = getDOM().getBaseHref(defaultDoc);
headEl.removeChild(baseEl);
@ -58,9 +58,9 @@ import {isTextNode} from '@angular/platform-browser/testing/src/browser_util';
it('should return a relative url', () => {
const baseEl = getDOM().createElement('base');
getDOM().setAttribute(baseEl, 'href', 'base');
baseEl.setAttribute('href', 'base');
const headEl = defaultDoc.head;
getDOM().appendChild(headEl, baseEl);
headEl.appendChild(baseEl);
const baseHref = getDOM().getBaseHref(defaultDoc) !;
headEl.removeChild(baseEl);

View File

@ -114,12 +114,12 @@ function declareTests(config?: {useJit: boolean}) {
fixture.componentInstance.ctxProp = 'Initial aria label';
fixture.detectChanges();
expect(getDOM().getAttribute(fixture.debugElement.children[0].nativeElement, 'aria-label'))
expect(fixture.debugElement.children[0].nativeElement.getAttribute('aria-label'))
.toEqual('Initial aria label');
fixture.componentInstance.ctxProp = 'Changed aria label';
fixture.detectChanges();
expect(getDOM().getAttribute(fixture.debugElement.children[0].nativeElement, 'aria-label'))
expect(fixture.debugElement.children[0].nativeElement.getAttribute('aria-label'))
.toEqual('Changed aria label');
});
@ -131,8 +131,7 @@ function declareTests(config?: {useJit: boolean}) {
fixture.componentInstance.ctxProp = 'bar';
fixture.detectChanges();
expect(getDOM().getAttribute(fixture.debugElement.children[0].nativeElement, 'foo'))
.toEqual('bar');
expect(fixture.debugElement.children[0].nativeElement.getAttribute('foo')).toEqual('bar');
fixture.componentInstance.ctxProp = null !;
fixture.detectChanges();
@ -887,7 +886,7 @@ function declareTests(config?: {useJit: boolean}) {
fixture.detectChanges();
expect(getDOM().getAttribute(fixture.debugElement.nativeElement, 'role')).toEqual('button');
expect(fixture.debugElement.nativeElement.getAttribute('role')).toEqual('button');
});
it('should support updating host element via hostAttributes on host elements', () => {
@ -898,7 +897,7 @@ function declareTests(config?: {useJit: boolean}) {
fixture.detectChanges();
expect(getDOM().getAttribute(fixture.debugElement.children[0].nativeElement, 'role'))
expect(fixture.debugElement.children[0].nativeElement.getAttribute('role'))
.toEqual('button');
});
@ -1404,7 +1403,7 @@ function declareTests(config?: {useJit: boolean}) {
TestBed.overrideComponent(MyComp, {set: {template}});
const fixture = TestBed.createComponent(MyComp);
expect(getDOM().querySelectorAll(fixture.nativeElement, 'script').length).toEqual(0);
expect(fixture.nativeElement.querySelectorAll('script').length).toEqual(0);
});
it('should throw when using directives without selector in NgModule declarations', () => {
@ -2139,7 +2138,7 @@ class SimpleImperativeViewComponent {
constructor(self: ElementRef) {
const hostElement = self.nativeElement;
getDOM().appendChild(hostElement, el('hello imp view'));
hostElement.appendChild(el('hello imp view'));
}
}
@ -2663,7 +2662,7 @@ class SomeImperativeViewport {
this.view = this.vc.createEmbeddedView(this.templateRef);
const nodes = this.view.rootNodes;
for (let i = 0; i < nodes.length; i++) {
getDOM().appendChild(this.anchor, nodes[i]);
this.anchor.appendChild(nodes[i]);
}
}
}

View File

@ -524,8 +524,8 @@ describe('projection', () => {
const mainEl = main.nativeElement;
const div1 = mainEl.firstChild;
const div2 = getDOM().createElement('div');
getDOM().setAttribute(div2, 'class', 'redStyle');
getDOM().appendChild(mainEl, div2);
div2.setAttribute('class', 'redStyle');
mainEl.appendChild(div2);
expect(getComputedStyle(div1).color).toEqual('rgb(255, 0, 0)');
expect(getComputedStyle(div2).color).toEqual('rgb(255, 0, 0)');
});
@ -544,7 +544,7 @@ describe('projection', () => {
const mainEl = main.nativeElement;
const div1 = mainEl.firstChild;
const div2 = getDOM().createElement('div');
getDOM().appendChild(mainEl, div2);
mainEl.appendChild(div2);
expect(getComputedStyle(div1).color).toEqual('rgb(255, 0, 0)');
expect(getComputedStyle(div2).color).toEqual('rgb(0, 0, 0)');
});

View File

@ -438,7 +438,7 @@ function declareTestsUsingBootstrap() {
beforeEach(inject([DOCUMENT], (doc: any) => {
destroyPlatform();
const el = getDOM().createElement(COMP_SELECTOR, doc);
getDOM().appendChild(doc.body, el);
doc.body.appendChild(el);
logger = new MockConsole();
errorHandler = new ErrorHandler();

View File

@ -177,13 +177,12 @@ function declareTests(config?: {useJit: boolean}) {
fixture.detectChanges();
// In the browser, reading href returns an absolute URL. On the server side,
// it just echoes back the property.
let value =
isAttribute ? getDOM().getAttribute(e, 'href') : getDOM().getProperty(e, 'href');
let value = isAttribute ? e.getAttribute('href') : getDOM().getProperty(e, 'href');
expect(value).toMatch(/.*\/?hello$/);
ci.ctxProp = 'javascript:alert(1)';
fixture.detectChanges();
value = isAttribute ? getDOM().getAttribute(e, 'href') : getDOM().getProperty(e, 'href');
value = isAttribute ? e.getAttribute('href') : getDOM().getProperty(e, 'href');
expect(value).toEqual('unsafe:javascript:alert(1)');
}

View File

@ -58,7 +58,7 @@ const removeEventListener = '__zone_symbol__removeEventListener' as 'removeEvent
elementDef(0, NodeFlags.None, null, null, 0, 'div', [['title', 'a']]),
])).rootNodes;
expect(rootNodes.length).toBe(1);
expect(getDOM().getAttribute(rootNodes[0], 'title')).toBe('a');
expect(rootNodes[0].getAttribute('title')).toBe('a');
});
it('should add debug information to the renderer', () => {
@ -114,8 +114,8 @@ const removeEventListener = '__zone_symbol__removeEventListener' as 'removeEvent
Services.checkAndUpdateView(view);
const el = rootNodes[0];
expect(getDOM().getAttribute(el, 'a1')).toBe('v1');
expect(getDOM().getAttribute(el, 'a2')).toBe('v2');
expect(el.getAttribute('a1')).toBe('v1');
expect(el.getAttribute('a2')).toBe('v2');
});
});
});

View File

@ -55,8 +55,8 @@ import {compViewDef, compViewDefFactory, createAndGetRootNodes, createEmbeddedVi
// 2 anchors + 2 elements
const rootChildren = rootNodes[0].childNodes;
expect(rootChildren.length).toBe(4);
expect(getDOM().getAttribute(rootChildren[1], 'name')).toBe('child0');
expect(getDOM().getAttribute(rootChildren[2], 'name')).toBe('child1');
expect(rootChildren[1].getAttribute('name')).toBe('child0');
expect(rootChildren[2].getAttribute('name')).toBe('child1');
rf.begin !();
detachEmbeddedView(viewContainerData, 1);
@ -90,8 +90,8 @@ import {compViewDef, compViewDefFactory, createAndGetRootNodes, createEmbeddedVi
// 2 anchors + 2 elements
const rootChildren = rootNodes[0].childNodes;
expect(rootChildren.length).toBe(4);
expect(getDOM().getAttribute(rootChildren[1], 'name')).toBe('child1');
expect(getDOM().getAttribute(rootChildren[2], 'name')).toBe('child0');
expect(rootChildren[1].getAttribute('name')).toBe('child1');
expect(rootChildren[2].getAttribute('name')).toBe('child0');
});
it('should include embedded views in root nodes', () => {
@ -107,8 +107,8 @@ import {compViewDef, compViewDefFactory, createAndGetRootNodes, createEmbeddedVi
const rootNodes = rootRenderNodes(parentView);
expect(rootNodes.length).toBe(3);
expect(getDOM().getAttribute(rootNodes[1], 'name')).toBe('child0');
expect(getDOM().getAttribute(rootNodes[2], 'name')).toBe('after');
expect(rootNodes[1].getAttribute('name')).toBe('child0');
expect(rootNodes[2].getAttribute('name')).toBe('after');
});
it('should dirty check embedded views', () => {

View File

@ -340,7 +340,7 @@ import {ARG_TYPE_VALUES, checkNodeInlineOrDynamic, createRootView, createAndGetR
expect(instance.b).toBe('v2');
const el = rootNodes[0];
expect(getDOM().getAttribute(el, 'ng-reflect-a')).toBe('v1');
expect(el.getAttribute('ng-reflect-a')).toBe('v1');
});
});

View File

@ -23,11 +23,11 @@ export class DOMTestComponentRenderer extends TestComponentRenderer {
const rootEl = <HTMLElement>getContent(template).firstChild;
// TODO(juliemr): can/should this be optional?
const oldRoots = getDOM().querySelectorAll(this._doc, '[id^=root]');
const oldRoots = this._doc.querySelectorAll('[id^=root]');
for (let i = 0; i < oldRoots.length; i++) {
getDOM().remove(oldRoots[i]);
}
getDOM().appendChild(this._doc.body, rootEl);
this._doc.body.appendChild(rootEl);
}
}

View File

@ -50,7 +50,6 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
}
}
querySelectorAll(el: any, selector: string): any[] { return el.querySelectorAll(selector); }
onAndCancel(el: Node, evt: any, listener: any): Function {
el.addEventListener(evt, listener, false);
// Needed to follow Dart's subscription semantic, until fix of
@ -58,7 +57,6 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
return () => { el.removeEventListener(evt, listener, false); };
}
dispatchEvent(el: Node, evt: any) { el.dispatchEvent(evt); }
appendChild(el: Node, node: Node) { el.appendChild(node); }
remove(node: Node): Node {
if (node.parentNode) {
node.parentNode.removeChild(node);
@ -70,15 +68,6 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
doc = doc || this.getDefaultDocument();
return doc.createElement(tagName);
}
getElementsByTagName(element: any, name: string): HTMLElement[] {
return element.getElementsByTagName(name);
}
getAttribute(element: Element, attribute: string): string|null {
return element.getAttribute(attribute);
}
setAttribute(element: Element, name: string, value: string) { element.setAttribute(name, value); }
createHtmlDocument(): HTMLDocument {
return document.implementation.createHTMLDocument('fakeTitle');
}

View File

@ -65,7 +65,7 @@ export class Meta {
getTags(attrSelector: string): HTMLMetaElement[] {
if (!attrSelector) return [];
const list /*NodeList*/ = this._dom.querySelectorAll(this._doc, `meta[${attrSelector}]`);
const list /*NodeList*/ = this._doc.querySelectorAll(`meta[${attrSelector}]`);
return list ? [].slice.call(list) : [];
}
@ -99,13 +99,13 @@ export class Meta {
}
const element: HTMLMetaElement = this._dom.createElement('meta') as HTMLMetaElement;
this._setMetaElementAttributes(meta, element);
const head = this._dom.getElementsByTagName(this._doc, 'head')[0];
this._dom.appendChild(head, element);
const head = this._doc.getElementsByTagName('head')[0];
head.appendChild(element);
return element;
}
private _setMetaElementAttributes(tag: MetaDefinition, el: HTMLMetaElement): HTMLMetaElement {
Object.keys(tag).forEach((prop: string) => this._dom.setAttribute(el, prop, tag[prop]));
Object.keys(tag).forEach((prop: string) => el.setAttribute(prop, tag[prop]));
return el;
}
@ -115,6 +115,6 @@ export class Meta {
}
private _containsAttributes(tag: MetaDefinition, elem: HTMLMetaElement): boolean {
return Object.keys(tag).every((key: string) => this._dom.getAttribute(elem, key) === tag[key]);
return Object.keys(tag).every((key: string) => elem.getAttribute(key) === tag[key]);
}
}

View File

@ -23,7 +23,7 @@ export function appInitializerFactory(transitionId: string, document: any, injec
const dom = getDOM();
const styles: any[] =
Array.prototype.slice.apply(document.querySelectorAll(`style[ng-transition]`));
styles.filter(el => dom.getAttribute(el, 'ng-transition') === transitionId)
styles.filter(el => el.getAttribute('ng-transition') === transitionId)
.forEach(el => dom.remove(el));
});
};

View File

@ -142,7 +142,7 @@ function bootstrap(
compilerConsole = new DummyConsole();
testProviders = [{provide: Console, useValue: compilerConsole}];
const oldRoots = getDOM().querySelectorAll(doc, 'hello-app,hello-app-2,light-dom-el');
const oldRoots = doc.querySelectorAll('hello-app,hello-app-2,light-dom-el');
for (let i = 0; i < oldRoots.length; i++) {
getDOM().remove(oldRoots[i]);
}
@ -150,9 +150,9 @@ function bootstrap(
el = getDOM().createElement('hello-app', doc);
el2 = getDOM().createElement('hello-app-2', doc);
lightDom = getDOM().createElement('light-dom-el', doc);
getDOM().appendChild(doc.body, el);
getDOM().appendChild(doc.body, el2);
getDOM().appendChild(el, lightDom);
doc.body.appendChild(el);
doc.body.appendChild(el2);
el.appendChild(lightDom);
lightDom.textContent = 'loading';
}));
@ -440,17 +440,17 @@ function bootstrap(
const platform = platformBrowserDynamic();
const document = platform.injector.get(DOCUMENT);
const style = dom.createElement('style', document);
dom.setAttribute(style, 'ng-transition', 'my-app');
dom.appendChild(document.head, style);
style.setAttribute('ng-transition', 'my-app');
document.head.appendChild(style);
const root = dom.createElement('root', document);
dom.appendChild(document.body, root);
document.body.appendChild(root);
platform.bootstrapModule(TestModule).then(() => {
const styles: HTMLElement[] =
Array.prototype.slice.apply(dom.getElementsByTagName(document, 'style') || []);
Array.prototype.slice.apply(document.getElementsByTagName('style') || []);
styles.forEach(
style => { expect(dom.getAttribute(style, 'ng-transition')).not.toBe('my-app'); });
style => { expect(style.getAttribute('ng-transition')).not.toBe('my-app'); });
async.done();
});
}));

View File

@ -22,9 +22,9 @@ import {expect} from '@angular/platform-browser/testing/src/matchers';
doc = getDOM().createHtmlDocument();
metaService = new Meta(doc);
defaultMeta = getDOM().createElement('meta', doc) as HTMLMetaElement;
getDOM().setAttribute(defaultMeta, 'property', 'fb:app_id');
getDOM().setAttribute(defaultMeta, 'content', '123456789');
getDOM().appendChild(getDOM().getElementsByTagName(doc, 'head')[0], defaultMeta);
defaultMeta.setAttribute('property', 'fb:app_id');
defaultMeta.setAttribute('content', '123456789');
doc.getElementsByTagName('head')[0].appendChild(defaultMeta);
});
afterEach(() => getDOM().remove(defaultMeta));
@ -32,7 +32,7 @@ import {expect} from '@angular/platform-browser/testing/src/matchers';
it('should return meta tag matching selector', () => {
const actual: HTMLMetaElement = metaService.getTag('property="fb:app_id"') !;
expect(actual).not.toBeNull();
expect(getDOM().getAttribute(actual, 'content')).toEqual('123456789');
expect(actual.getAttribute('content')).toEqual('123456789');
});
it('should return all meta tags matching selector', () => {
@ -41,8 +41,8 @@ import {expect} from '@angular/platform-browser/testing/src/matchers';
const actual: HTMLMetaElement[] = metaService.getTags('name=author');
expect(actual.length).toEqual(2);
expect(getDOM().getAttribute(actual[0], 'content')).toEqual('page author');
expect(getDOM().getAttribute(actual[1], 'content')).toEqual('another page author');
expect(actual[0].getAttribute('content')).toEqual('page author');
expect(actual[1].getAttribute('content')).toEqual('another page author');
// clean up
metaService.removeTagElement(tag1);
@ -87,7 +87,7 @@ import {expect} from '@angular/platform-browser/testing/src/matchers';
const actual = metaService.getTag(selector);
expect(actual).not.toBeNull();
expect(getDOM().getAttribute(actual, 'content')).toEqual('4321');
expect(actual !.getAttribute('content')).toEqual('4321');
});
it('should extract selector from the tag definition', () => {
@ -96,7 +96,7 @@ import {expect} from '@angular/platform-browser/testing/src/matchers';
const actual = metaService.getTag(selector);
expect(actual).not.toBeNull();
expect(getDOM().getAttribute(actual, 'content')).toEqual('666');
expect(actual !.getAttribute('content')).toEqual('666');
});
it('should create meta tag if it does not exist', () => {
@ -106,7 +106,7 @@ import {expect} from '@angular/platform-browser/testing/src/matchers';
const actual = metaService.getTag(selector) !;
expect(actual).not.toBeNull();
expect(getDOM().getAttribute(actual, 'content')).toEqual('Content Title');
expect(actual.getAttribute('content')).toEqual('Content Title');
// clean up
metaService.removeTagElement(actual);
@ -120,7 +120,7 @@ import {expect} from '@angular/platform-browser/testing/src/matchers';
const actual = metaService.getTag(selector) !;
expect(actual).not.toBeNull();
expect(getDOM().getAttribute(actual, 'content')).toEqual('Content Title');
expect(actual.getAttribute('content')).toEqual('Content Title');
// clean up
metaService.removeTagElement(actual);

View File

@ -61,7 +61,7 @@ import {createMouseEvent, el} from '../../../testing/src/browser_util';
it('events are caught when fired from a child', () => {
const element = el('<div><div></div></div>');
// Workaround for https://bugs.webkit.org/show_bug.cgi?id=122755
getDOM().appendChild(doc.body, element);
doc.body.appendChild(element);
const child = element.firstChild as Element;
const dispatchedEvent = createMouseEvent('click');
@ -76,7 +76,7 @@ import {createMouseEvent, el} from '../../../testing/src/browser_util';
it('should add and remove global event listeners', () => {
const element = el('<div><div></div></div>');
getDOM().appendChild(doc.body, element);
doc.body.appendChild(element);
const dispatchedEvent = createMouseEvent('click');
let receivedEvent: any /** TODO #9100 */ = null;
const handler = (e: any /** TODO #9100 */) => { receivedEvent = e; };
@ -96,7 +96,7 @@ import {createMouseEvent, el} from '../../../testing/src/browser_util';
const Zone = (window as any)['Zone'];
const element = el('<div><div></div></div>');
getDOM().appendChild(doc.body, element);
doc.body.appendChild(element);
const dispatchedEvent = createMouseEvent('click');
let receivedEvent: any /** TODO #9100 */ = null;
let receivedZone: any = null;
@ -122,7 +122,7 @@ import {createMouseEvent, el} from '../../../testing/src/browser_util';
const Zone = (window as any)['Zone'];
const element = el('<div><div></div></div>');
getDOM().appendChild(doc.body, element);
doc.body.appendChild(element);
const dispatchedEvent = createMouseEvent('click');
let receivedEvents: any[] /** TODO #9100 */ = [];
let receivedZones: any[] = [];
@ -157,7 +157,7 @@ import {createMouseEvent, el} from '../../../testing/src/browser_util';
const Zone = (window as any)['Zone'];
const element = el('<div><div></div></div>');
getDOM().appendChild(doc.body, element);
doc.body.appendChild(element);
const dispatchedEvent = createMouseEvent('click');
let receivedEvents: any[] /** TODO #9100 */ = [];
let receivedZones: any[] = [];
@ -193,7 +193,7 @@ import {createMouseEvent, el} from '../../../testing/src/browser_util';
const Zone = (window as any)['Zone'];
const element = el('<div><div></div></div>');
getDOM().appendChild(doc.body, element);
doc.body.appendChild(element);
const dispatchedEvent = createMouseEvent('click');
let receivedEvents: any[] /** TODO #9100 */ = [];
let receivedZones: any[] = [];
@ -229,7 +229,7 @@ import {createMouseEvent, el} from '../../../testing/src/browser_util';
const Zone = (window as any)['Zone'];
const element = el('<div><div></div></div>');
getDOM().appendChild(doc.body, element);
doc.body.appendChild(element);
const dispatchedEvent = createMouseEvent('click');
let receivedEvents: any[] /** TODO #9100 */ = [];
let receivedZones: any[] = [];
@ -260,7 +260,7 @@ import {createMouseEvent, el} from '../../../testing/src/browser_util';
const Zone = (window as any)['Zone'];
const element = el('<div><div></div></div>');
getDOM().appendChild(doc.body, element);
doc.body.appendChild(element);
const dispatchedEvent = createMouseEvent('click');
let receivedEvents: any[] /** TODO #9100 */ = [];
let receivedZones: any[] = [];
@ -299,7 +299,7 @@ import {createMouseEvent, el} from '../../../testing/src/browser_util';
it('should run blockListedEvents handler outside of ngZone', () => {
const Zone = (window as any)['Zone'];
const element = el('<div><div></div></div>');
getDOM().appendChild(doc.body, element);
doc.body.appendChild(element);
const dispatchedEvent = createMouseEvent('scroll');
let receivedEvent: any /** TODO #9100 */ = null;
let receivedZone: any = null;

View File

@ -78,7 +78,7 @@ export class DominoAdapter extends BrowserDomAdapter {
if (name === 'href') {
// Domino tries to resolve href-s which we do not want. Just return the
// attribute value.
return this.getAttribute(el, 'href');
return el.getAttribute('href');
} else if (name === 'innerText') {
// Domino does not support innerText. Just map it to textContent.
return el.textContent;

View File

@ -88,7 +88,7 @@ class DefaultServerRenderer2 implements Renderer2 {
return doc.createTextNode(value);
}
appendChild(parent: any, newChild: any): void { getDOM().appendChild(parent, newChild); }
appendChild(parent: any, newChild: any): void { parent.appendChild(newChild); }
insertBefore(parent: any, newChild: any, refChild: any): void {
if (parent) {
@ -126,7 +126,7 @@ class DefaultServerRenderer2 implements Renderer2 {
if (namespace) {
el.setAttributeNS(NAMESPACE_URIS[namespace], namespace + ':' + name, value);
} else {
getDOM().setAttribute(el, name, value);
el.setAttribute(name, value);
}
}

View File

@ -18,7 +18,7 @@ export class ServerStylesHost extends SharedStylesHost {
@Inject(DOCUMENT) private doc: any,
@Optional() @Inject(ɵTRANSITION_ID) private transitionId: string) {
super();
this.head = getDOM().getElementsByTagName(doc, 'head')[0];
this.head = doc.getElementsByTagName('head')[0];
}
private _addStyle(style: string): void {
@ -26,9 +26,9 @@ export class ServerStylesHost extends SharedStylesHost {
const el = adapter.createElement('style');
el.textContent = style;
if (!!this.transitionId) {
adapter.setAttribute(el, 'ng-transition', this.transitionId);
el.setAttribute('ng-transition', this.transitionId);
}
adapter.appendChild(this.head, el);
this.head.appendChild(el);
}
onStylesAdded(additions: Set<string>) { additions.forEach(style => this._addStyle(style)); }

View File

@ -473,11 +473,11 @@ class HiddenModule {
}]);
platform.bootstrapModule(ExampleStylesModule).then(ref => {
const doc = ref.injector.get(DOCUMENT);
const head = getDOM().getElementsByTagName(doc, 'head')[0];
const head = doc.getElementsByTagName('head')[0];
const styles: any[] = head.children as any;
expect(styles.length).toBe(1);
expect(styles[0].textContent).toContain('color: red');
expect(getDOM().getAttribute(styles[0], 'ng-transition')).toBe('example-styles');
expect(styles[0].getAttribute('ng-transition')).toBe('example-styles');
});
}));
@ -487,7 +487,7 @@ class HiddenModule {
platform.bootstrapModule(ImageExampleModule).then(ref => {
const appRef: ApplicationRef = ref.injector.get(ApplicationRef);
const app = appRef.components[0].location.nativeElement;
const img = getDOM().getElementsByTagName(app, 'img')[0] as any;
const img = app.getElementsByTagName('img')[0] as any;
expect(img.attributes['src'].value).toEqual('link');
});
}));

View File

@ -44,15 +44,10 @@ export class WorkerDomAdapter extends DomAdapter {
getProperty(el: Element, name: string): any { throw 'not implemented'; }
querySelectorAll(el: any, selector: string): any[] { throw 'not implemented'; }
onAndCancel(el: any, evt: any, listener: any): Function { throw 'not implemented'; }
dispatchEvent(el: any, evt: any) { throw 'not implemented'; }
appendChild(el: any, node: any) { throw 'not implemented'; }
remove(el: any): Node { throw 'not implemented'; }
createElement(tagName: any, doc?: any): HTMLElement { throw 'not implemented'; }
getElementsByTagName(element: any, name: string): HTMLElement[] { throw 'not implemented'; }
getAttribute(element: any, attribute: string): string { throw 'not implemented'; }
setAttribute(element: any, name: string, value: string) { throw 'not implemented'; }
createHtmlDocument(): HTMLDocument { throw 'not implemented'; }
getDefaultDocument(): Document { throw 'not implemented'; }
isElementNode(node: any): boolean { throw 'not implemented'; }

View File

@ -121,7 +121,7 @@ let lastCreatedRenderer: Renderer2;
expect(el.style['width']).toEqual('');
lastCreatedRenderer.setAttribute(workerEl, 'someattr', 'someValue');
expect(getDOM().getAttribute(el, 'someattr')).toEqual('someValue');
expect(el.getAttribute('someattr')).toEqual('someValue');
};
// root element

View File

@ -42,15 +42,15 @@ describe('bootstrap', () => {
const el1 = getDOM().createElement('test-app', doc);
const el2 = getDOM().createElement('test-app2', doc);
getDOM().appendChild(doc.body, el1);
getDOM().appendChild(doc.body, el2);
doc.body.appendChild(el1);
doc.body.appendChild(el2);
log = [];
testProviders = [{provide: APP_BASE_HREF, useValue: ''}];
}));
afterEach(inject([DOCUMENT], (doc: any) => {
const oldRoots = getDOM().querySelectorAll(doc, 'test-app,test-app2');
const oldRoots = doc.querySelectorAll('test-app,test-app2');
for (let i = 0; i < oldRoots.length; i++) {
getDOM().remove(oldRoots[i]);
}