diff --git a/modules/@angular/compiler-cli/src/codegen.ts b/modules/@angular/compiler-cli/src/codegen.ts index 47667b0162..b439fed53a 100644 --- a/modules/@angular/compiler-cli/src/codegen.ts +++ b/modules/@angular/compiler-cli/src/codegen.ts @@ -123,8 +123,8 @@ export class CodeGenerator { static create( options: AngularCompilerOptions, cliOptions: NgcCliOptions, program: ts.Program, compilerHost: ts.CompilerHost, reflectorHostContext?: ReflectorHostContext, - xhr?: compiler.XHR): CodeGenerator { - xhr = xhr || { + resourceLoader?: compiler.ResourceLoader): CodeGenerator { + resourceLoader = resourceLoader || { get: (s: string) => { if (!compilerHost.fileExists(s)) { // TODO: We should really have a test for error cases like this! @@ -152,7 +152,7 @@ export class CodeGenerator { logBindingUpdate: false, useJit: false }); - const normalizer = new DirectiveNormalizer(xhr, urlResolver, htmlParser, config); + const normalizer = new DirectiveNormalizer(resourceLoader, urlResolver, htmlParser, config); const expressionParser = new Parser(new Lexer()); const elementSchemaRegistry = new DomElementSchemaRegistry(); const console = new Console(); diff --git a/modules/@angular/compiler-cli/src/extract_i18n.ts b/modules/@angular/compiler-cli/src/extract_i18n.ts index a67f555f9d..d966cb33ad 100644 --- a/modules/@angular/compiler-cli/src/extract_i18n.ts +++ b/modules/@angular/compiler-cli/src/extract_i18n.ts @@ -147,7 +147,7 @@ export class Extractor { options: tsc.AngularCompilerOptions, translationsFormat: string, program: ts.Program, compilerHost: ts.CompilerHost, htmlParser: compiler.i18n.HtmlParser, reflectorHostContext?: ReflectorHostContext): Extractor { - const xhr: compiler.XHR = { + const resourceLoader: compiler.ResourceLoader = { get: (s: string) => { if (!compilerHost.fileExists(s)) { // TODO: We should really have a test for error cases like this! @@ -169,7 +169,7 @@ export class Extractor { useJit: false }); - const normalizer = new DirectiveNormalizer(xhr, urlResolver, htmlParser, config); + const normalizer = new DirectiveNormalizer(resourceLoader, urlResolver, htmlParser, config); const expressionParser = new Parser(new Lexer()); const elementSchemaRegistry = new DomElementSchemaRegistry(); const console = new Console(); diff --git a/modules/@angular/compiler/index.ts b/modules/@angular/compiler/index.ts index 1b7ba3a397..8c703f3170 100644 --- a/modules/@angular/compiler/index.ts +++ b/modules/@angular/compiler/index.ts @@ -13,7 +13,7 @@ */ import * as i18n from './src/i18n/index'; -export {COMPILER_PROVIDERS, CompileDiDependencyMetadata, CompileDirectiveMetadata, CompileFactoryMetadata, CompileIdentifierMetadata, CompileMetadataWithIdentifier, CompilePipeMetadata, CompileProviderMetadata, CompileQueryMetadata, CompileTemplateMetadata, CompileTokenMetadata, CompileTypeMetadata, CompilerConfig, DEFAULT_PACKAGE_URL_PROVIDER, DirectiveResolver, NgModuleResolver, OfflineCompiler, PipeResolver, RenderTypes, RuntimeCompiler, SourceModule, TEMPLATE_TRANSFORMS, UrlResolver, XHR, analyzeAppProvidersForDeprecatedConfiguration, createOfflineCompileUrlResolver, platformCoreDynamic} from './src/compiler'; +export {COMPILER_PROVIDERS, CompileDiDependencyMetadata, CompileDirectiveMetadata, CompileFactoryMetadata, CompileIdentifierMetadata, CompileMetadataWithIdentifier, CompilePipeMetadata, CompileProviderMetadata, CompileQueryMetadata, CompileTemplateMetadata, CompileTokenMetadata, CompileTypeMetadata, CompilerConfig, DEFAULT_PACKAGE_URL_PROVIDER, DirectiveResolver, NgModuleResolver, OfflineCompiler, PipeResolver, RenderTypes, ResourceLoader, RuntimeCompiler, SourceModule, TEMPLATE_TRANSFORMS, UrlResolver, analyzeAppProvidersForDeprecatedConfiguration, createOfflineCompileUrlResolver, platformCoreDynamic} from './src/compiler'; export {DEFAULT_INTERPOLATION_CONFIG, InterpolationConfig} from './src/ml_parser/interpolation_config'; export {ElementSchemaRegistry} from './src/schema/element_schema_registry'; export {i18n}; diff --git a/modules/@angular/compiler/src/compiler.ts b/modules/@angular/compiler/src/compiler.ts index 1f70eac70f..b2d842670a 100644 --- a/modules/@angular/compiler/src/compiler.ts +++ b/modules/@angular/compiler/src/compiler.ts @@ -15,7 +15,7 @@ export * from './compile_metadata'; export * from './offline_compiler'; export {RuntimeCompiler} from './runtime_compiler'; export * from './url_resolver'; -export * from './xhr'; +export * from './resource_loader'; export {DirectiveResolver} from './directive_resolver'; export {PipeResolver} from './pipe_resolver'; @@ -41,12 +41,13 @@ import {DirectiveResolver} from './directive_resolver'; import {PipeResolver} from './pipe_resolver'; import {NgModuleResolver} from './ng_module_resolver'; import {Console, Reflector, reflector, ReflectorReader, ReflectionCapabilities} from '../core_private'; -import {XHR} from './xhr'; +import {ResourceLoader} from './resource_loader'; import * as i18n from './i18n/index'; -const _NO_XHR: XHR = { +const _NO_RESOURCE_LOADER: ResourceLoader = { get(url: string): Promise{ - throw new Error(`No XHR implementation has been provided. Can't read the url "${url}"`);} + throw new Error( + `No ResourceLoader implementation has been provided. Can't read the url "${url}"`);} }; /** @@ -56,7 +57,7 @@ const _NO_XHR: XHR = { export const COMPILER_PROVIDERS: Array|{[k: string]: any}|any[]> = [ {provide: Reflector, useValue: reflector}, {provide: ReflectorReader, useExisting: Reflector}, - {provide: XHR, useValue: _NO_XHR}, + {provide: ResourceLoader, useValue: _NO_RESOURCE_LOADER}, Console, Lexer, Parser, @@ -101,7 +102,7 @@ export function analyzeAppProvidersForDeprecatedConfiguration(appProviders: any[ const deprecationMessages: string[] = []; // Note: This is a hack to still support the old way - // of configuring platform directives / pipes and the compiler xhr. + // of configuring platform directives / pipes and the compiler resource loader. // This will soon be deprecated! const tempInj = ReflectiveInjector.resolveAndCreate(appProviders); const compilerConfig: CompilerConfig = tempInj.get(CompilerConfig, null); @@ -112,11 +113,11 @@ export function analyzeAppProvidersForDeprecatedConfiguration(appProviders: any[ deprecationMessages.push( `Passing CompilerConfig as a regular provider is deprecated. Use "compilerOptions" use a custom "CompilerFactory" platform provider instead.`); } - const xhr = tempInj.get(XHR, null); - if (xhr) { - compilerProviders.push([{provide: XHR, useValue: xhr}]); + const resourceLoader = tempInj.get(ResourceLoader, null); + if (resourceLoader) { + compilerProviders.push([{provide: ResourceLoader, useValue: resourceLoader}]); deprecationMessages.push( - `Passing XHR as regular provider is deprecated. Pass the provider via "compilerOptions" instead.`); + `Passing ResourceLoader as regular provider is deprecated. Pass the provider via "compilerOptions" instead.`); } const compilerOptions: CompilerOptions = { useJit: useJit, diff --git a/modules/@angular/compiler/src/directive_normalizer.ts b/modules/@angular/compiler/src/directive_normalizer.ts index 2488cccd9d..2a71a21282 100644 --- a/modules/@angular/compiler/src/directive_normalizer.ts +++ b/modules/@angular/compiler/src/directive_normalizer.ts @@ -15,36 +15,36 @@ import {isBlank, isPresent} from './facade/lang'; import * as html from './ml_parser/ast'; import {HtmlParser} from './ml_parser/html_parser'; import {InterpolationConfig} from './ml_parser/interpolation_config'; +import {ResourceLoader} from './resource_loader'; import {extractStyleUrls, isStyleUrlResolvable} from './style_url_resolver'; import {PreparsedElementType, preparseElement} from './template_parser/template_preparser'; import {UrlResolver} from './url_resolver'; import {SyncAsyncResult} from './util'; -import {XHR} from './xhr'; @Injectable() export class DirectiveNormalizer { - private _xhrCache = new Map>(); + private _resourceLoaderCache = new Map>(); constructor( - private _xhr: XHR, private _urlResolver: UrlResolver, private _htmlParser: HtmlParser, - private _config: CompilerConfig) {} + private _resourceLoader: ResourceLoader, private _urlResolver: UrlResolver, + private _htmlParser: HtmlParser, private _config: CompilerConfig) {} - clearCache() { this._xhrCache.clear(); } + clearCache() { this._resourceLoaderCache.clear(); } clearCacheFor(normalizedDirective: CompileDirectiveMetadata) { if (!normalizedDirective.isComponent) { return; } - this._xhrCache.delete(normalizedDirective.template.templateUrl); + this._resourceLoaderCache.delete(normalizedDirective.template.templateUrl); normalizedDirective.template.externalStylesheets.forEach( - (stylesheet) => { this._xhrCache.delete(stylesheet.moduleUrl); }); + (stylesheet) => { this._resourceLoaderCache.delete(stylesheet.moduleUrl); }); } private _fetch(url: string): Promise { - var result = this._xhrCache.get(url); + var result = this._resourceLoaderCache.get(url); if (!result) { - result = this._xhr.get(url); - this._xhrCache.set(url, result); + result = this._resourceLoader.get(url); + this._resourceLoaderCache.set(url, result); } return result; } diff --git a/modules/@angular/compiler/src/xhr.ts b/modules/@angular/compiler/src/resource_loader.ts similarity index 84% rename from modules/@angular/compiler/src/xhr.ts rename to modules/@angular/compiler/src/resource_loader.ts index c3847a3257..70f73e2964 100644 --- a/modules/@angular/compiler/src/xhr.ts +++ b/modules/@angular/compiler/src/resource_loader.ts @@ -6,11 +6,10 @@ * found in the LICENSE file at https://angular.io/license */ -// TODO: vsavkin rename it into TemplateLoader /** * An interface for retrieving documents by URL that the compiler uses * to load templates. */ -export class XHR { +export class ResourceLoader { get(url: string): Promise { return null; } } diff --git a/modules/@angular/compiler/test/directive_normalizer_spec.ts b/modules/@angular/compiler/test/directive_normalizer_spec.ts index 980e1974b0..cfff378f82 100644 --- a/modules/@angular/compiler/test/directive_normalizer_spec.ts +++ b/modules/@angular/compiler/test/directive_normalizer_spec.ts @@ -9,13 +9,13 @@ import {CompileDirectiveMetadata, CompileStylesheetMetadata, CompileTemplateMetadata, CompileTypeMetadata} from '@angular/compiler/src/compile_metadata'; import {CompilerConfig} from '@angular/compiler/src/config'; import {DirectiveNormalizer} from '@angular/compiler/src/directive_normalizer'; -import {XHR} from '@angular/compiler/src/xhr'; -import {MockXHR} from '@angular/compiler/testing/xhr_mock'; +import {ResourceLoader} from '@angular/compiler/src/resource_loader'; +import {MockResourceLoader} from '@angular/compiler/testing/resource_loader_mock'; import {ViewEncapsulation} from '@angular/core/src/metadata/view'; import {TestBed} from '@angular/core/testing'; import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; -import {SpyXHR} from './spies'; +import {SpyResourceLoader} from './spies'; import {TEST_COMPILER_PROVIDERS} from './test_bindings'; export function main() { @@ -115,9 +115,10 @@ export function main() { it('should load a template from a url that is resolved against moduleUrl', inject( - [AsyncTestCompleter, DirectiveNormalizer, XHR], - (async: AsyncTestCompleter, normalizer: DirectiveNormalizer, xhr: MockXHR) => { - xhr.expect('package:some/module/sometplurl.html', 'a'); + [AsyncTestCompleter, DirectiveNormalizer, ResourceLoader], + (async: AsyncTestCompleter, normalizer: DirectiveNormalizer, + resourceLoader: MockResourceLoader) => { + resourceLoader.expect('package:some/module/sometplurl.html', 'a'); normalizer .normalizeTemplateAsync(dirType, new CompileTemplateMetadata({ encapsulation: null, @@ -131,14 +132,15 @@ export function main() { expect(template.templateUrl).toEqual('package:some/module/sometplurl.html'); async.done(); }); - xhr.flush(); + resourceLoader.flush(); })); it('should resolve styles on the annotation against the moduleUrl', inject( - [AsyncTestCompleter, DirectiveNormalizer, XHR], - (async: AsyncTestCompleter, normalizer: DirectiveNormalizer, xhr: MockXHR) => { - xhr.expect('package:some/module/tpl/sometplurl.html', ''); + [AsyncTestCompleter, DirectiveNormalizer, ResourceLoader], + (async: AsyncTestCompleter, normalizer: DirectiveNormalizer, + resourceLoader: MockResourceLoader) => { + resourceLoader.expect('package:some/module/tpl/sometplurl.html', ''); normalizer .normalizeTemplateAsync(dirType, new CompileTemplateMetadata({ encapsulation: null, @@ -151,14 +153,15 @@ export function main() { expect(template.styleUrls).toEqual(['package:some/module/test.css']); async.done(); }); - xhr.flush(); + resourceLoader.flush(); })); it('should resolve styles in the template against the templateUrl', inject( - [AsyncTestCompleter, DirectiveNormalizer, XHR], - (async: AsyncTestCompleter, normalizer: DirectiveNormalizer, xhr: MockXHR) => { - xhr.expect( + [AsyncTestCompleter, DirectiveNormalizer, ResourceLoader], + (async: AsyncTestCompleter, normalizer: DirectiveNormalizer, + resourceLoader: MockResourceLoader) => { + resourceLoader.expect( 'package:some/module/tpl/sometplurl.html', ''); normalizer .normalizeTemplateAsync(dirType, new CompileTemplateMetadata({ @@ -172,21 +175,24 @@ export function main() { expect(template.styleUrls).toEqual(['package:some/module/tpl/test.css']); async.done(); }); - xhr.flush(); + resourceLoader.flush(); })); }); describe('normalizeExternalStylesheets', () => { - beforeEach( - () => { TestBed.configureCompiler({providers: [{provide: XHR, useClass: SpyXHR}]}); }); + beforeEach(() => { + TestBed.configureCompiler( + {providers: [{provide: ResourceLoader, useClass: SpyResourceLoader}]}); + }); it('should load an external stylesheet', inject( - [AsyncTestCompleter, DirectiveNormalizer, XHR], - (async: AsyncTestCompleter, normalizer: DirectiveNormalizer, xhr: SpyXHR) => { - programXhrSpy(xhr, {'package:some/module/test.css': 'a'}); + [AsyncTestCompleter, DirectiveNormalizer, ResourceLoader], + (async: AsyncTestCompleter, normalizer: DirectiveNormalizer, + resourceLoader: SpyResourceLoader) => { + programResourceLoaderSpy(resourceLoader, {'package:some/module/test.css': 'a'}); normalizer .normalizeExternalStylesheets(new CompileTemplateMetadata({ template: '', @@ -206,9 +212,10 @@ export function main() { it('should load stylesheets referenced by external stylesheets', inject( - [AsyncTestCompleter, DirectiveNormalizer, XHR], - (async: AsyncTestCompleter, normalizer: DirectiveNormalizer, xhr: SpyXHR) => { - programXhrSpy(xhr, { + [AsyncTestCompleter, DirectiveNormalizer, ResourceLoader], + (async: AsyncTestCompleter, normalizer: DirectiveNormalizer, + resourceLoader: SpyResourceLoader) => { + programResourceLoaderSpy(resourceLoader, { 'package:some/module/test.css': 'a@import "test2.css"', 'package:some/module/test2.css': 'b' }); @@ -238,9 +245,10 @@ export function main() { describe('caching', () => { it('should work for templateUrl', inject( - [AsyncTestCompleter, DirectiveNormalizer, XHR], - (async: AsyncTestCompleter, normalizer: DirectiveNormalizer, xhr: MockXHR) => { - xhr.expect('package:some/module/cmp.html', 'a'); + [AsyncTestCompleter, DirectiveNormalizer, ResourceLoader], + (async: AsyncTestCompleter, normalizer: DirectiveNormalizer, + resourceLoader: MockResourceLoader) => { + resourceLoader.expect('package:some/module/cmp.html', 'a'); var templateMeta = new CompileTemplateMetadata({ templateUrl: 'cmp.html', }); @@ -254,7 +262,7 @@ export function main() { expect(templates[1].template).toEqual('a'); async.done(); }); - xhr.flush(); + resourceLoader.flush(); })); }); @@ -426,7 +434,7 @@ export function main() { }); } -function programXhrSpy(spy: SpyXHR, results: {[key: string]: string}) { +function programResourceLoaderSpy(spy: SpyResourceLoader, results: {[key: string]: string}) { spy.spy('get').andCallFake((url: string): Promise => { var result = results[url]; if (result) { diff --git a/modules/@angular/compiler/test/i18n/integration_spec.ts b/modules/@angular/compiler/test/i18n/integration_spec.ts index b81f47a27e..425bd91ee0 100644 --- a/modules/@angular/compiler/test/i18n/integration_spec.ts +++ b/modules/@angular/compiler/test/i18n/integration_spec.ts @@ -6,21 +6,21 @@ * found in the LICENSE file at https://angular.io/license */ -import {DirectiveResolver, XHR, i18n} from '@angular/compiler'; +import {DirectiveResolver, ResourceLoader, i18n} from '@angular/compiler'; import {MockDirectiveResolver} from '@angular/compiler/testing'; import {Compiler, Component, DebugElement, Injector, TRANSLATIONS, TRANSLATIONS_FORMAT} from '@angular/core'; import {TestBed, fakeAsync} from '@angular/core/testing'; import {beforeEach, TestComponentBuilder, ddescribe, describe, iit, inject, it, xdescribe, xit,} from '@angular/core/testing/testing_internal'; import {expect} from '@angular/platform-browser/testing/matchers'; import {By} from '@angular/platform-browser/src/dom/debug/by'; -import {SpyXHR} from '../spies'; +import {SpyResourceLoader} from '../spies'; import {NgLocalization} from '@angular/common'; import {stringifyElement} from '@angular/platform-browser/testing/browser_util'; export function main() { describe('i18n integration spec', () => { let compiler: Compiler; - let xhr: SpyXHR; + let xhr: SpyResourceLoader; let tcb: TestComponentBuilder; let dirResolver: MockDirectiveResolver; let injector: Injector; @@ -28,7 +28,7 @@ export function main() { beforeEach(() => { TestBed.configureCompiler({ providers: [ - {provide: XHR, useClass: SpyXHR}, + {provide: ResourceLoader, useClass: SpyResourceLoader}, {provide: NgLocalization, useClass: FrLocalization}, {provide: TRANSLATIONS, useValue: XTB}, {provide: TRANSLATIONS_FORMAT, useValue: 'xtb'}, @@ -37,8 +37,8 @@ export function main() { }); beforeEach(fakeAsync(inject( - [Compiler, TestComponentBuilder, XHR, DirectiveResolver, Injector], - (_compiler: Compiler, _tcb: TestComponentBuilder, _xhr: SpyXHR, + [Compiler, TestComponentBuilder, ResourceLoader, DirectiveResolver, Injector], + (_compiler: Compiler, _tcb: TestComponentBuilder, _xhr: SpyResourceLoader, _dirResolver: MockDirectiveResolver, _injector: Injector) => { compiler = _compiler; tcb = _tcb; diff --git a/modules/@angular/compiler/test/xhr_mock_spec.ts b/modules/@angular/compiler/test/resource_loader_mock_spec.ts similarity index 57% rename from modules/@angular/compiler/test/xhr_mock_spec.ts rename to modules/@angular/compiler/test/resource_loader_mock_spec.ts index b7257c1d1e..9c22276e07 100644 --- a/modules/@angular/compiler/test/xhr_mock_spec.ts +++ b/modules/@angular/compiler/test/resource_loader_mock_spec.ts @@ -6,15 +6,15 @@ * found in the LICENSE file at https://angular.io/license */ -import {MockXHR} from '@angular/compiler/testing/xhr_mock'; +import {MockResourceLoader} from '@angular/compiler/testing/resource_loader_mock'; import {AsyncTestCompleter, beforeEach, ddescribe, describe, expect, iit, inject, it} from '@angular/core/testing/testing_internal'; import {isPresent} from '../src/facade/lang'; export function main() { - describe('MockXHR', () => { - var xhr: MockXHR; + describe('MockResourceLoader', () => { + var resourceLoader: MockResourceLoader; - beforeEach(() => { xhr = new MockXHR(); }); + beforeEach(() => { resourceLoader = new MockResourceLoader(); }); function expectResponse( request: Promise, url: string, response: string, done: () => void = null) { @@ -45,70 +45,71 @@ export function main() { inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { var url = '/foo'; var response = 'bar'; - xhr.when(url, response); - expectResponse(xhr.get(url), url, response, () => async.done()); - xhr.flush(); + resourceLoader.when(url, response); + expectResponse(resourceLoader.get(url), url, response, () => async.done()); + resourceLoader.flush(); })); it('should return an error from the definitions', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { var url = '/foo'; var response: any /** TODO #9100 */ = null; - xhr.when(url, response); - expectResponse(xhr.get(url), url, response, () => async.done()); - xhr.flush(); + resourceLoader.when(url, response); + expectResponse(resourceLoader.get(url), url, response, () => async.done()); + resourceLoader.flush(); })); it('should return a response from the expectations', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { var url = '/foo'; var response = 'bar'; - xhr.expect(url, response); - expectResponse(xhr.get(url), url, response, () => async.done()); - xhr.flush(); + resourceLoader.expect(url, response); + expectResponse(resourceLoader.get(url), url, response, () => async.done()); + resourceLoader.flush(); })); it('should return an error from the expectations', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { var url = '/foo'; var response: any /** TODO #9100 */ = null; - xhr.expect(url, response); - expectResponse(xhr.get(url), url, response, () => async.done()); - xhr.flush(); + resourceLoader.expect(url, response); + expectResponse(resourceLoader.get(url), url, response, () => async.done()); + resourceLoader.flush(); })); it('should not reuse expectations', () => { var url = '/foo'; var response = 'bar'; - xhr.expect(url, response); - xhr.get(url); - xhr.get(url); - expect(() => { xhr.flush(); }).toThrowError('Unexpected request /foo'); + resourceLoader.expect(url, response); + resourceLoader.get(url); + resourceLoader.get(url); + expect(() => { resourceLoader.flush(); }).toThrowError('Unexpected request /foo'); }); it('should return expectations before definitions', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { var url = '/foo'; - xhr.when(url, 'when'); - xhr.expect(url, 'expect'); - expectResponse(xhr.get(url), url, 'expect'); - expectResponse(xhr.get(url), url, 'when', () => async.done()); - xhr.flush(); + resourceLoader.when(url, 'when'); + resourceLoader.expect(url, 'expect'); + expectResponse(resourceLoader.get(url), url, 'expect'); + expectResponse(resourceLoader.get(url), url, 'when', () => async.done()); + resourceLoader.flush(); })); it('should throw when there is no definitions or expectations', () => { - xhr.get('/foo'); - expect(() => { xhr.flush(); }).toThrowError('Unexpected request /foo'); + resourceLoader.get('/foo'); + expect(() => { resourceLoader.flush(); }).toThrowError('Unexpected request /foo'); }); - it('should throw when flush is called without any pending requests', - () => { expect(() => { xhr.flush(); }).toThrowError('No pending requests to flush'); }); + it('should throw when flush is called without any pending requests', () => { + expect(() => { resourceLoader.flush(); }).toThrowError('No pending requests to flush'); + }); it('should throw on unsatisfied expectations', () => { - xhr.expect('/foo', 'bar'); - xhr.when('/bar', 'foo'); - xhr.get('/bar'); - expect(() => { xhr.flush(); }).toThrowError('Unsatisfied requests: /foo'); + resourceLoader.expect('/foo', 'bar'); + resourceLoader.when('/bar', 'foo'); + resourceLoader.get('/bar'); + expect(() => { resourceLoader.flush(); }).toThrowError('Unsatisfied requests: /foo'); }); }); } diff --git a/modules/@angular/compiler/test/runtime_compiler_spec.ts b/modules/@angular/compiler/test/runtime_compiler_spec.ts index be5f2617cc..abcba7567a 100644 --- a/modules/@angular/compiler/test/runtime_compiler_spec.ts +++ b/modules/@angular/compiler/test/runtime_compiler_spec.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {DirectiveResolver, XHR} from '@angular/compiler'; +import {DirectiveResolver, ResourceLoader} from '@angular/compiler'; import {MockDirectiveResolver} from '@angular/compiler/testing'; import {Compiler, Component, ComponentFactory, Injectable, Injector, Input, NgModule, NgModuleFactory, Type} from '@angular/core'; import {ComponentFixture, TestBed, fakeAsync, tick} from '@angular/core/testing'; @@ -16,7 +16,7 @@ import {expect} from '@angular/platform-browser/testing/matchers'; import {ViewMetadata} from '../core_private'; import {stringify} from '../src/facade/lang'; -import {SpyXHR} from './spies'; +import {SpyResourceLoader} from './spies'; @Component({selector: 'child-cmp', template: 'childComp'}) class ChildComp { @@ -33,21 +33,23 @@ class SomeCompWithUrlTemplate { export function main() { describe('RuntimeCompiler', () => { let compiler: Compiler; - let xhr: SpyXHR; + let resourceLoader: SpyResourceLoader; let tcb: TestComponentBuilder; let dirResolver: MockDirectiveResolver; let injector: Injector; - beforeEach( - () => { TestBed.configureCompiler({providers: [{provide: XHR, useClass: SpyXHR}]}); }); + beforeEach(() => { + TestBed.configureCompiler( + {providers: [{provide: ResourceLoader, useClass: SpyResourceLoader}]}); + }); beforeEach(fakeAsync(inject( - [Compiler, TestComponentBuilder, XHR, DirectiveResolver, Injector], - (_compiler: Compiler, _tcb: TestComponentBuilder, _xhr: SpyXHR, + [Compiler, TestComponentBuilder, ResourceLoader, DirectiveResolver, Injector], + (_compiler: Compiler, _tcb: TestComponentBuilder, _resourceLoader: SpyResourceLoader, _dirResolver: MockDirectiveResolver, _injector: Injector) => { compiler = _compiler; tcb = _tcb; - xhr = _xhr; + resourceLoader = _resourceLoader; dirResolver = _dirResolver; injector = _injector; }))); @@ -55,13 +57,13 @@ export function main() { describe('clearCacheFor', () => { it('should support changing the content of a template referenced via templateUrl', fakeAsync(() => { - xhr.spy('get').andCallFake(() => Promise.resolve('init')); + resourceLoader.spy('get').andCallFake(() => Promise.resolve('init')); let compFixture = tcb.overrideView(SomeComp, new ViewMetadata({templateUrl: '/myComp.html'})) .createFakeAsync(SomeComp); expect(compFixture.nativeElement).toHaveText('init'); - xhr.spy('get').andCallFake(() => Promise.resolve('new content')); + resourceLoader.spy('get').andCallFake(() => Promise.resolve('new content')); // Note: overrideView is calling .clearCacheFor... compFixture = tcb.overrideView(SomeComp, new ViewMetadata({templateUrl: '/myComp.html'})) .createFakeAsync(SomeComp); @@ -91,7 +93,7 @@ export function main() { describe('compileComponentSync', () => { it('should throw when using a templateUrl that has not been compiled before', () => { - xhr.spy('get').andCallFake(() => Promise.resolve('')); + resourceLoader.spy('get').andCallFake(() => Promise.resolve('')); expect(() => tcb.createSync(SomeCompWithUrlTemplate)) .toThrowError( `Can't compile synchronously as ${stringify(SomeCompWithUrlTemplate)} is still being loaded!`); @@ -99,7 +101,7 @@ export function main() { it('should throw when using a templateUrl in a nested component that has not been compiled before', () => { - xhr.spy('get').andCallFake(() => Promise.resolve('')); + resourceLoader.spy('get').andCallFake(() => Promise.resolve('')); let localTcb = tcb.overrideView(SomeComp, new ViewMetadata({template: '', directives: [ChildComp]})) .overrideView(ChildComp, new ViewMetadata({templateUrl: '/someTpl.html'})); @@ -110,7 +112,7 @@ export function main() { it('should allow to use templateUrl components that have been loaded before', fakeAsync(() => { - xhr.spy('get').andCallFake(() => Promise.resolve('hello')); + resourceLoader.spy('get').andCallFake(() => Promise.resolve('hello')); tcb.createFakeAsync(SomeCompWithUrlTemplate); let compFixture = tcb.createSync(SomeCompWithUrlTemplate); expect(compFixture.nativeElement).toHaveText('hello'); @@ -126,7 +128,7 @@ export function main() { class SomeModule { } - xhr.spy('get').andCallFake(() => Promise.resolve('hello')); + resourceLoader.spy('get').andCallFake(() => Promise.resolve('hello')); let ngModuleFactory: NgModuleFactory; compiler.compileModuleAsync(SomeModule).then((f) => ngModuleFactory = f); tick(); @@ -141,7 +143,7 @@ export function main() { class SomeModule { } - xhr.spy('get').andCallFake(() => Promise.resolve('')); + resourceLoader.spy('get').andCallFake(() => Promise.resolve('')); expect(() => compiler.compileModuleSync(SomeModule)) .toThrowError( `Can't compile synchronously as ${stringify(SomeCompWithUrlTemplate)} is still being loaded!`); @@ -153,7 +155,7 @@ export function main() { class SomeModule { } - xhr.spy('get').andCallFake(() => Promise.resolve('')); + resourceLoader.spy('get').andCallFake(() => Promise.resolve('')); dirResolver.setView(SomeComp, new ViewMetadata({template: '', directives: [ChildComp]})); dirResolver.setView(ChildComp, new ViewMetadata({templateUrl: '/someTpl.html'})); expect(() => compiler.compileModuleSync(SomeModule)) @@ -170,7 +172,7 @@ export function main() { class SomeModule { } - xhr.spy('get').andCallFake(() => Promise.resolve('hello')); + resourceLoader.spy('get').andCallFake(() => Promise.resolve('hello')); compiler.compileModuleAsync(SomeModule); tick(); diff --git a/modules/@angular/compiler/test/spies.ts b/modules/@angular/compiler/test/spies.ts index dcf54225fc..88d92fb263 100644 --- a/modules/@angular/compiler/test/spies.ts +++ b/modules/@angular/compiler/test/spies.ts @@ -6,10 +6,10 @@ * found in the LICENSE file at https://angular.io/license */ -import {XHR} from '@angular/compiler/src/xhr'; +import {ResourceLoader} from '@angular/compiler/src/resource_loader'; import {SpyObject, proxy} from '@angular/core/testing/testing_internal'; -export class SpyXHR extends SpyObject { - constructor() { super(XHR); } +export class SpyResourceLoader extends SpyObject { + constructor() { super(ResourceLoader); } } diff --git a/modules/@angular/compiler/test/test_bindings.ts b/modules/@angular/compiler/test/test_bindings.ts index 28b03ddd5a..16b691fb0e 100644 --- a/modules/@angular/compiler/test/test_bindings.ts +++ b/modules/@angular/compiler/test/test_bindings.ts @@ -6,13 +6,13 @@ * found in the LICENSE file at https://angular.io/license */ -import {ElementSchemaRegistry, UrlResolver, XHR} from '@angular/compiler'; +import {ElementSchemaRegistry, ResourceLoader, UrlResolver} from '@angular/compiler'; import {createUrlResolverWithoutPackagePrefix} from '@angular/compiler/src/url_resolver'; import {MockSchemaRegistry} from '@angular/compiler/testing'; -import {MockXHR} from '@angular/compiler/testing/xhr_mock'; +import {MockResourceLoader} from '@angular/compiler/testing/resource_loader_mock'; export var TEST_COMPILER_PROVIDERS: any[] = [ {provide: ElementSchemaRegistry, useValue: new MockSchemaRegistry({}, {})}, - {provide: XHR, useClass: MockXHR}, + {provide: ResourceLoader, useClass: MockResourceLoader}, {provide: UrlResolver, useFactory: createUrlResolverWithoutPackagePrefix} ]; diff --git a/modules/@angular/compiler/testing/xhr_mock.ts b/modules/@angular/compiler/testing/resource_loader_mock.ts similarity index 95% rename from modules/@angular/compiler/testing/xhr_mock.ts rename to modules/@angular/compiler/testing/resource_loader_mock.ts index 80b7463923..0fa2009861 100644 --- a/modules/@angular/compiler/testing/xhr_mock.ts +++ b/modules/@angular/compiler/testing/resource_loader_mock.ts @@ -8,16 +8,16 @@ import {BaseException} from '@angular/core'; -import {XHR} from '../index'; +import {ResourceLoader} from '../index'; import {ListWrapper, Map} from '../src/facade/collection'; import {isBlank, normalizeBlank} from '../src/facade/lang'; /** - * A mock implementation of {@link XHR} that allows outgoing requests to be mocked + * A mock implementation of {@link ResourceLoader} that allows outgoing requests to be mocked * and responded to within a single test, without going to the network. */ -export class MockXHR extends XHR { +export class MockResourceLoader extends ResourceLoader { private _expectations: _Expectation[] = []; private _definitions = new Map(); private _requests: _PendingRequest[] = []; diff --git a/modules/@angular/http/src/backends/xhr_backend.ts b/modules/@angular/http/src/backends/xhr_backend.ts index 0fde263c85..416cf552b3 100644 --- a/modules/@angular/http/src/backends/xhr_backend.ts +++ b/modules/@angular/http/src/backends/xhr_backend.ts @@ -53,7 +53,8 @@ export class XHRConnection implements Connection { // load event handler let onLoad = () => { // responseText is the old-school way of retrieving response (supported by IE8 & 9) - // response/responseType properties were introduced in XHR Level2 spec (supported by + // response/responseType properties were introduced in ResourceLoader Level2 spec (supported + // by // IE10) let body = isPresent(_xhr.response) ? _xhr.response : _xhr.responseText; // Implicitly strip a potential XSSI prefix. diff --git a/modules/@angular/http/testing/mock_backend.ts b/modules/@angular/http/testing/mock_backend.ts index 15b0e16912..22bc90a562 100644 --- a/modules/@angular/http/testing/mock_backend.ts +++ b/modules/@angular/http/testing/mock_backend.ts @@ -27,7 +27,7 @@ import {Response} from '../src/static_response'; */ export class MockConnection implements Connection { // TODO Name `readyState` should change to be more generic, and states could be made to be more - // descriptive than XHR states. + // descriptive than ResourceLoader states. /** * Describes the state of the connection, based on `XMLHttpRequest.readyState`, but with * additional states. For example, state 5 indicates an aborted connection. @@ -105,7 +105,7 @@ export class MockConnection implements Connection { * */ mockError(err?: Error) { - // Matches XHR semantics + // Matches ResourceLoader semantics this.readyState = ReadyState.Done; this.response.error(err); } diff --git a/modules/@angular/platform-browser-dynamic/index.ts b/modules/@angular/platform-browser-dynamic/index.ts index d33f00d0bc..3501416a77 100644 --- a/modules/@angular/platform-browser-dynamic/index.ts +++ b/modules/@angular/platform-browser-dynamic/index.ts @@ -6,21 +6,22 @@ * found in the LICENSE file at https://angular.io/license */ -import {XHR, analyzeAppProvidersForDeprecatedConfiguration, platformCoreDynamic} from '@angular/compiler'; +import {ResourceLoader, analyzeAppProvidersForDeprecatedConfiguration, platformCoreDynamic} from '@angular/compiler'; import {ApplicationRef, COMPILER_OPTIONS, CUSTOM_ELEMENTS_SCHEMA, CompilerFactory, CompilerOptions, ComponentRef, NgModule, PlatformRef, Provider, Type, createPlatformFactory} from '@angular/core'; import {BrowserModule, WORKER_SCRIPT, WorkerAppModule, platformWorkerUi} from '@angular/platform-browser'; import {Console} from './core_private'; import {INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS} from './src/platform_providers'; -import {CachedXHR} from './src/xhr/xhr_cache'; -import {XHRImpl} from './src/xhr/xhr_impl'; +import {CachedResourceLoader} from './src/resource_loader/resource_loader_cache'; +import {ResourceLoaderImpl} from './src/resource_loader/resource_loader_impl'; /** * @experimental */ -export const CACHED_TEMPLATE_PROVIDER: Provider[] = [{provide: XHR, useClass: CachedXHR}]; +export const RESOURCE_CACHE_PROVIDER: Provider[] = + [{provide: ResourceLoader, useClass: CachedResourceLoader}]; /** * @experimental API related to bootstrapping are still under review. @@ -46,12 +47,12 @@ export function bootstrapWorkerUi( /** * @experimental API related to bootstrapping are still under review. */ -export const platformWorkerAppDynamic = - createPlatformFactory(platformCoreDynamic, 'workerAppDynamic', [{ - provide: COMPILER_OPTIONS, - useValue: {providers: [{provide: XHR, useClass: XHRImpl}]}, - multi: true - }]); +export const platformWorkerAppDynamic = createPlatformFactory( + platformCoreDynamic, 'workerAppDynamic', [{ + provide: COMPILER_OPTIONS, + useValue: {providers: [{provide: ResourceLoader, useClass: ResourceLoaderImpl}]}, + multi: true + }]); function normalizeArray(arr: any[]): any[] { return arr ? arr : []; diff --git a/modules/@angular/platform-browser-dynamic/src/platform_providers.ts b/modules/@angular/platform-browser-dynamic/src/platform_providers.ts index 4930e7eb21..b4a73e6122 100644 --- a/modules/@angular/platform-browser-dynamic/src/platform_providers.ts +++ b/modules/@angular/platform-browser-dynamic/src/platform_providers.ts @@ -6,18 +6,18 @@ * found in the LICENSE file at https://angular.io/license */ -import {XHR} from '@angular/compiler'; +import {ResourceLoader} from '@angular/compiler'; import {COMPILER_OPTIONS} from '@angular/core'; import {INTERNAL_BROWSER_PLATFORM_PROVIDERS} from '../platform_browser_private'; -import {XHRImpl} from './xhr/xhr_impl'; +import {ResourceLoaderImpl} from './resource_loader/resource_loader_impl'; export const INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS: any[] = [ INTERNAL_BROWSER_PLATFORM_PROVIDERS, { provide: COMPILER_OPTIONS, - useValue: {providers: [{provide: XHR, useClass: XHRImpl}]}, + useValue: {providers: [{provide: ResourceLoader, useClass: ResourceLoaderImpl}]}, multi: true }, ]; diff --git a/modules/@angular/platform-browser-dynamic/src/xhr/xhr_cache.ts b/modules/@angular/platform-browser-dynamic/src/resource_loader/resource_loader_cache.ts similarity index 61% rename from modules/@angular/platform-browser-dynamic/src/xhr/xhr_cache.ts rename to modules/@angular/platform-browser-dynamic/src/resource_loader/resource_loader_cache.ts index 6296783606..2c49321f52 100644 --- a/modules/@angular/platform-browser-dynamic/src/xhr/xhr_cache.ts +++ b/modules/@angular/platform-browser-dynamic/src/resource_loader/resource_loader_cache.ts @@ -6,25 +6,26 @@ * found in the LICENSE file at https://angular.io/license */ -import {XHR} from '@angular/compiler'; +import {ResourceLoader} from '@angular/compiler'; import {BaseException} from '@angular/core'; import {global} from '../facade/lang'; /** - * An implementation of XHR that uses a template cache to avoid doing an actual - * XHR. + * An implementation of ResourceLoader that uses a template cache to avoid doing an actual + * ResourceLoader. * * The template cache needs to be built and loaded into window.$templateCache * via a separate mechanism. */ -export class CachedXHR extends XHR { +export class CachedResourceLoader extends ResourceLoader { private _cache: {[url: string]: string}; constructor() { super(); this._cache = (global).$templateCache; if (this._cache == null) { - throw new BaseException('CachedXHR: Template cache was not found in $templateCache.'); + throw new BaseException( + 'CachedResourceLoader: Template cache was not found in $templateCache.'); } } @@ -32,7 +33,8 @@ export class CachedXHR extends XHR { if (this._cache.hasOwnProperty(url)) { return Promise.resolve(this._cache[url]); } else { - return >Promise.reject('CachedXHR: Did not find cached template for ' + url); + return >Promise.reject( + 'CachedResourceLoader: Did not find cached template for ' + url); } } } diff --git a/modules/@angular/platform-browser-dynamic/src/xhr/xhr_impl.ts b/modules/@angular/platform-browser-dynamic/src/resource_loader/resource_loader_impl.ts similarity index 86% rename from modules/@angular/platform-browser-dynamic/src/xhr/xhr_impl.ts rename to modules/@angular/platform-browser-dynamic/src/resource_loader/resource_loader_impl.ts index cd7f38c738..2676ffdb42 100644 --- a/modules/@angular/platform-browser-dynamic/src/xhr/xhr_impl.ts +++ b/modules/@angular/platform-browser-dynamic/src/resource_loader/resource_loader_impl.ts @@ -5,13 +5,13 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {XHR} from '@angular/compiler'; +import {ResourceLoader} from '@angular/compiler'; import {Injectable} from '@angular/core'; import {isPresent} from '../facade/lang'; @Injectable() -export class XHRImpl extends XHR { +export class ResourceLoaderImpl extends ResourceLoader { get(url: string): Promise { var resolve: (result: any) => void; var reject: (error: any) => void; @@ -25,7 +25,8 @@ export class XHRImpl extends XHR { xhr.onload = function() { // responseText is the old-school way of retrieving response (supported by IE8 & 9) - // response/responseType properties were introduced in XHR Level2 spec (supported by IE10) + // response/responseType properties were introduced in ResourceLoader Level2 spec (supported + // by IE10) var response = isPresent(xhr.response) ? xhr.response : xhr.responseText; // normalize IE9 bug (http://bugs.jquery.com/ticket/1450) diff --git a/modules/@angular/platform-browser-dynamic/test/xhr/xhr_cache_setter.ts b/modules/@angular/platform-browser-dynamic/test/resource_loader/resource_loader_cache_setter.ts similarity index 100% rename from modules/@angular/platform-browser-dynamic/test/xhr/xhr_cache_setter.ts rename to modules/@angular/platform-browser-dynamic/test/resource_loader/resource_loader_cache_setter.ts diff --git a/modules/@angular/platform-browser-dynamic/test/xhr/xhr_cache_spec.ts b/modules/@angular/platform-browser-dynamic/test/resource_loader/resource_loader_cache_spec.ts similarity index 77% rename from modules/@angular/platform-browser-dynamic/test/xhr/xhr_cache_spec.ts rename to modules/@angular/platform-browser-dynamic/test/resource_loader/resource_loader_cache_spec.ts index 9d0539f153..1f195c6ef4 100644 --- a/modules/@angular/platform-browser-dynamic/test/xhr/xhr_cache_spec.ts +++ b/modules/@angular/platform-browser-dynamic/test/resource_loader/resource_loader_cache_spec.ts @@ -6,29 +6,29 @@ * found in the LICENSE file at https://angular.io/license */ -import {UrlResolver, XHR} from '@angular/compiler'; +import {ResourceLoader, UrlResolver} from '@angular/compiler'; import {BaseException, Component} from '@angular/core'; import {TestBed, fakeAsync, flushMicrotasks, tick} from '@angular/core/testing'; import {AsyncTestCompleter, TestComponentBuilder, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; import {expect} from '@angular/platform-browser/testing/matchers'; -import {CachedXHR} from '../../src/xhr/xhr_cache'; +import {CachedResourceLoader} from '../../src/resource_loader/resource_loader_cache'; -import {setTemplateCache} from './xhr_cache_setter'; +import {setTemplateCache} from './resource_loader_cache_setter'; export function main() { - describe('CachedXHR', () => { - var xhr: CachedXHR; + describe('CachedResourceLoader', () => { + var xhr: CachedResourceLoader; - function createCachedXHR(): CachedXHR { + function createCachedResourceLoader(): CachedResourceLoader { setTemplateCache({'test.html': '
Hello
'}); - return new CachedXHR(); + return new CachedResourceLoader(); } beforeEach(() => { TestBed.configureCompiler({ providers: [ {provide: UrlResolver, useClass: TestUrlResolver}, - {provide: XHR, useFactory: createCachedXHR} + {provide: ResourceLoader, useFactory: createCachedResourceLoader} ] }); }); @@ -36,14 +36,14 @@ export function main() { it('should throw exception if $templateCache is not found', () => { setTemplateCache(null); expect(() => { - xhr = new CachedXHR(); - }).toThrowError('CachedXHR: Template cache was not found in $templateCache.'); + xhr = new CachedResourceLoader(); + }).toThrowError('CachedResourceLoader: Template cache was not found in $templateCache.'); }); it('should resolve the Promise with the cached file content on success', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { setTemplateCache({'test.html': '
Hello
'}); - xhr = new CachedXHR(); + xhr = new CachedResourceLoader(); xhr.get('test.html').then((text) => { expect(text).toEqual('
Hello
'); async.done(); @@ -52,7 +52,7 @@ export function main() { it('should reject the Promise on failure', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - xhr = new CachedXHR(); + xhr = new CachedResourceLoader(); xhr.get('unknown.html') .then((text) => { throw new BaseException('Not expected to succeed.'); }) .catch((error) => { async.done(); }); diff --git a/modules/@angular/platform-browser-dynamic/test/xhr/xhr_impl_spec.ts b/modules/@angular/platform-browser-dynamic/test/resource_loader/resource_loader_impl_spec.ts similarity index 80% rename from modules/@angular/platform-browser-dynamic/test/xhr/xhr_impl_spec.ts rename to modules/@angular/platform-browser-dynamic/test/resource_loader/resource_loader_impl_spec.ts index 995beb9bab..47d83f967c 100644 --- a/modules/@angular/platform-browser-dynamic/test/xhr/xhr_impl_spec.ts +++ b/modules/@angular/platform-browser-dynamic/test/resource_loader/resource_loader_impl_spec.ts @@ -7,11 +7,11 @@ */ import {AsyncTestCompleter, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; -import {XHRImpl} from '../../src/xhr/xhr_impl'; +import {ResourceLoaderImpl} from '../../src/resource_loader/resource_loader_impl'; export function main() { - describe('XHRImpl', () => { - var xhr: XHRImpl; + describe('ResourceLoaderImpl', () => { + var resourceLoader: ResourceLoaderImpl; // TODO(juliemr): This file currently won't work with dart unit tests run using // exclusive it or describe (iit or ddescribe). This is because when @@ -22,11 +22,11 @@ export function main() { var url200 = '/base/modules/@angular/platform-browser/test/browser/static_assets/200.html'; var url404 = '/bad/path/404.html'; - beforeEach(() => { xhr = new XHRImpl(); }); + beforeEach(() => { resourceLoader = new ResourceLoaderImpl(); }); it('should resolve the Promise with the file content on success', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - xhr.get(url200).then((text) => { + resourceLoader.get(url200).then((text) => { expect(text.trim()).toEqual('

hey

'); async.done(); }); @@ -34,7 +34,7 @@ export function main() { it('should reject the Promise on failure', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - xhr.get(url404).catch((e) => { + resourceLoader.get(url404).catch((e) => { expect(e).toEqual(`Failed to load ${url404}`); async.done(); return null; diff --git a/modules/@angular/platform-browser-dynamic/test/testing_public_browser_spec.ts b/modules/@angular/platform-browser-dynamic/test/testing_public_browser_spec.ts index 573dca0abf..dac79a62dd 100644 --- a/modules/@angular/platform-browser-dynamic/test/testing_public_browser_spec.ts +++ b/modules/@angular/platform-browser-dynamic/test/testing_public_browser_spec.ts @@ -6,11 +6,11 @@ * found in the LICENSE file at https://angular.io/license */ -import {XHR} from '@angular/compiler'; +import {ResourceLoader} from '@angular/compiler'; import {Component} from '@angular/core'; import {TestBed, async, fakeAsync, inject, tick} from '@angular/core/testing'; -import {XHRImpl} from '../src/xhr/xhr_impl'; +import {ResourceLoaderImpl} from '../src/resource_loader/resource_loader_impl'; @@ -46,12 +46,13 @@ export function main() { afterEach(() => { expect(actuallyDone).toEqual(true); }); - it('should run async tests with XHRs', async(() => { - var xhr = new XHRImpl(); - xhr.get('/base/modules/@angular/platform-browser/test/static_assets/test.html') + it('should run async tests with ResourceLoaders', async(() => { + var resourceLoader = new ResourceLoaderImpl(); + resourceLoader + .get('/base/modules/@angular/platform-browser/test/static_assets/test.html') .then(() => { actuallyDone = true; }); }), - 10000); // Long timeout here because this test makes an actual XHR. + 10000); // Long timeout here because this test makes an actual ResourceLoader. }); describe('using the test injector with the inject helper', () => { @@ -61,8 +62,10 @@ export function main() { {providers: [{provide: FancyService, useValue: new FancyService()}]}); }); - it('provides a real XHR instance', - inject([XHR], (xhr: XHR) => { expect(xhr instanceof XHRImpl).toBeTruthy(); })); + it('provides a real ResourceLoader instance', + inject([ResourceLoader], (resourceLoader: ResourceLoader) => { + expect(resourceLoader instanceof ResourceLoaderImpl).toBeTruthy(); + })); it('should allow the use of fakeAsync', fakeAsync(inject([FancyService], (service: any /** TODO #9100 */) => { @@ -96,7 +99,7 @@ export function main() { var restoreJasmineIt = () => { jasmine.getEnv().it = originalJasmineIt; }; - it('should fail when an XHR fails', (done: any /** TODO #9100 */) => { + it('should fail when an ResourceLoader fails', (done: any /** TODO #9100 */) => { var itPromise = patchJasmineIt(); it('should fail with an error from a promise', async(() => { @@ -125,7 +128,8 @@ export function main() { .toEqual('from external template\n'); }); }), - 10000); // Long timeout here because this test makes an actual XHR, and is slow on Edge. + 10000); // Long timeout here because this test makes an actual ResourceLoader, and is slow + // on Edge. }); }); } diff --git a/modules/@angular/platform-browser/src/dom/dom_adapter.ts b/modules/@angular/platform-browser/src/dom/dom_adapter.ts index fa8e8e0d9d..226bd92159 100644 --- a/modules/@angular/platform-browser/src/dom/dom_adapter.ts +++ b/modules/@angular/platform-browser/src/dom/dom_adapter.ts @@ -31,7 +31,7 @@ export function setRootDomAdapter(adapter: DomAdapter) { * Provides DOM operations in an environment-agnostic way. */ export abstract class DomAdapter { - public xhrType: Type = null; + public resourceLoaderType: Type = null; abstract hasProperty(element: any /** TODO #9100 */, name: string): boolean; abstract setProperty(el: Element, name: string, value: any): any /** TODO #9100 */; abstract getProperty(el: Element, name: string): any; @@ -43,7 +43,7 @@ export abstract class DomAdapter { abstract logGroupEnd(): any /** TODO #9100 */; /** @deprecated */ - getXHR(): Type { return this.xhrType; } + getResourceLoader(): Type { return this.resourceLoaderType; } /** * Maps attribute names to their corresponding property names for cases diff --git a/modules/@angular/platform-browser/src/web_workers/worker/worker_adapter.ts b/modules/@angular/platform-browser/src/web_workers/worker/worker_adapter.ts index 1824fdfb7c..fc4fca07e5 100644 --- a/modules/@angular/platform-browser/src/web_workers/worker/worker_adapter.ts +++ b/modules/@angular/platform-browser/src/web_workers/worker/worker_adapter.ts @@ -50,7 +50,7 @@ export class WorkerDomAdapter extends DomAdapter { getProperty(el: Element, name: string): any { throw 'not implemented'; } invoke(el: Element, methodName: string, args: any[]): any { throw 'not implemented'; } - getXHR(): Type { throw 'not implemented'; } + getResourceLoader(): Type { throw 'not implemented'; } get attrToPropMap(): {[key: string]: string} { throw 'not implemented'; } set attrToPropMap(value: {[key: string]: string}) { throw 'not implemented'; } diff --git a/modules/@angular/platform-browser/test/browser/bootstrap_spec.ts b/modules/@angular/platform-browser/test/browser/bootstrap_spec.ts index 02b786c9d3..e7e9a81b66 100644 --- a/modules/@angular/platform-browser/test/browser/bootstrap_spec.ts +++ b/modules/@angular/platform-browser/test/browser/bootstrap_spec.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {XHR} from '@angular/compiler'; +import {ResourceLoader} from '@angular/compiler'; import {APP_INITIALIZER, CUSTOM_ELEMENTS_SCHEMA, Component, Directive, ExceptionHandler, Inject, Input, NgModule, OnDestroy, PLATFORM_INITIALIZER, Pipe, createPlatformFactory} from '@angular/core'; import {ApplicationRef, destroyPlatform} from '@angular/core/src/application_ref'; import {Console} from '@angular/core/src/console'; diff --git a/modules/@angular/platform-browser/test/testing_public_spec.ts b/modules/@angular/platform-browser/test/testing_public_spec.ts index 9a3d3ad07a..8fcf07d07d 100644 --- a/modules/@angular/platform-browser/test/testing_public_spec.ts +++ b/modules/@angular/platform-browser/test/testing_public_spec.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {CompilerConfig, XHR} from '@angular/compiler'; +import {CompilerConfig, ResourceLoader} from '@angular/compiler'; import {CUSTOM_ELEMENTS_SCHEMA, Component, Directive, Injectable, Input, NgModule, Pipe} from '@angular/core'; import {TestBed, async, fakeAsync, inject, tick, withModule} from '@angular/core/testing'; import {expect} from '@angular/platform-browser/testing/matchers'; @@ -368,10 +368,11 @@ export function main() { describe('providers', () => { beforeEach(() => { - let xhrGet = - jasmine.createSpy('xhrGet').and.returnValue(Promise.resolve('Hello world!')); + let resourceLoaderGet = jasmine.createSpy('resourceLoaderGet') + .and.returnValue(Promise.resolve('Hello world!')); TestBed.configureTestingModule({declarations: [CompWithUrlTemplate]}); - TestBed.configureCompiler({providers: [{provide: XHR, useValue: {get: xhrGet}}]}); + TestBed.configureCompiler( + {providers: [{provide: ResourceLoader, useValue: {get: resourceLoaderGet}}]}); }); it('should use set up providers', fakeAsync(() => { @@ -480,10 +481,12 @@ export function main() { }); describe('components', () => { - let xhrGet: jasmine.Spy; + let resourceLoaderGet: jasmine.Spy; beforeEach(() => { - xhrGet = jasmine.createSpy('xhrGet').and.returnValue(Promise.resolve('Hello world!')); - TestBed.configureCompiler({providers: [{provide: XHR, useValue: {get: xhrGet}}]}); + resourceLoaderGet = jasmine.createSpy('resourceLoaderGet') + .and.returnValue(Promise.resolve('Hello world!')); + TestBed.configureCompiler( + {providers: [{provide: ResourceLoader, useValue: {get: resourceLoaderGet}}]}); }); it('should report an error for declared components with templateUrl which never call TestBed.compileComponents', diff --git a/modules/@angular/platform-server/src/parse5_adapter.ts b/modules/@angular/platform-server/src/parse5_adapter.ts index 028565a3c6..24f29c366d 100644 --- a/modules/@angular/platform-server/src/parse5_adapter.ts +++ b/modules/@angular/platform-server/src/parse5_adapter.ts @@ -14,7 +14,7 @@ import {isPresent, isBlank, global, setValueOnPath, DateWrapper} from '../src/fa import {BaseException} from '../src/facade/exceptions'; import {SelectorMatcher, CssSelector} from '../compiler_private'; import {Type} from '@angular/core'; -import {XHR} from '@angular/compiler'; +import {ResourceLoader} from '@angular/compiler'; var parser: any /** TODO #9100 */ = null; var serializer: any /** TODO #9100 */ = null; @@ -69,7 +69,7 @@ export class Parse5DomAdapter extends DomAdapter { logGroupEnd() {} - getXHR(): Type { return XHR; } + getResourceLoader(): Type { return ResourceLoader; } get attrToPropMap() { return _attrToPropMap; } diff --git a/tools/public_api_guard/platform-browser-dynamic/index.d.ts b/tools/public_api_guard/platform-browser-dynamic/index.d.ts index 6ebf2b0fc0..2f91702846 100644 --- a/tools/public_api_guard/platform-browser-dynamic/index.d.ts +++ b/tools/public_api_guard/platform-browser-dynamic/index.d.ts @@ -1,11 +1,11 @@ /** @experimental */ export declare function bootstrapWorkerUi(workerScriptUri: string, customProviders?: Provider[]): Promise; -/** @experimental */ -export declare const CACHED_TEMPLATE_PROVIDER: Provider[]; - /** @experimental */ export declare const platformBrowserDynamic: (extraProviders?: any[]) => PlatformRef; /** @experimental */ export declare const platformWorkerAppDynamic: (extraProviders?: any[]) => PlatformRef; + +/** @experimental */ +export declare const RESOURCE_CACHE_PROVIDER: Provider[];