Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(466)

Unified Diff: third_party/pkg/angular/test/core/templateurl_spec.dart

Issue 124053002: Adding Angular and dependent packages for testing (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/pkg/angular/test/core/templateurl_spec.dart
diff --git a/third_party/pkg/angular/test/core/templateurl_spec.dart b/third_party/pkg/angular/test/core/templateurl_spec.dart
new file mode 100644
index 0000000000000000000000000000000000000000..4a71f6b8f633ded9b0b34112b7821ac9e7d384bb
--- /dev/null
+++ b/third_party/pkg/angular/test/core/templateurl_spec.dart
@@ -0,0 +1,209 @@
+library templateurl_spec;
+
+import '../_specs.dart';
+
+@NgComponent(
+ selector: 'simple-url',
+ templateUrl: 'simple.html')
+class SimpleUrlComponent {
+}
+
+@NgComponent(
+ selector: 'html-and-css',
+ templateUrl: 'simple.html',
+ cssUrl: 'simple.css')
+class HtmlAndCssComponent {
+}
+
+@NgComponent(
+ selector: 'html-and-css',
+ templateUrl: 'simple.html',
+ cssUrls: const ['simple.css', 'another.css'])
+class HtmlAndMultipleCssComponent {
+}
+
+@NgComponent(
+ selector: 'inline-with-css',
+ template: '<div>inline!</div>',
+ cssUrl: 'simple.css')
+class InlineWithCssComponent {
+}
+
+@NgComponent(
+ selector: 'only-css',
+ cssUrl: 'simple.css')
+class OnlyCssComponent {
+}
+
+class PrefixedUrlRewriter extends UrlRewriter {
+ call(url) => "PREFIX:$url";
+}
+
+main() => describe('template url', () {
+ afterEach(inject((MockHttpBackend backend) {
+ backend.verifyNoOutstandingRequest();
+ }));
+
+ describe('loading with http rewriting', () {
+ beforeEach(module((Module module) {
+ module
+ ..type(HtmlAndCssComponent)
+ ..type(UrlRewriter, implementedBy: PrefixedUrlRewriter);
+ }));
+
+ it('should use the UrlRewriter for both HTML and CSS URLs', async(inject((Http $http,
+ Compiler $compile, Scope $rootScope, Logger log, Injector injector, NgZone zone,
+ MockHttpBackend backend) {
+
+ backend.whenGET('PREFIX:simple.html').respond('<div log="SIMPLE">Simple!</div>');
+ backend.whenGET('PREFIX:simple.css').respond('.hello{}');
+
+ var element = $('<div><html-and-css log>ignore</html-and-css><div>');
+ zone.run(() {
+ $compile(element)(injector, element);
+ });
+
+ backend.flush();
+ microLeap();
+
+ expect(renderedText(element)).toEqual('.hello{}Simple!');
+ expect(element[0].nodes[0].shadowRoot.innerHtml).toEqual(
+ '<style>.hello{}</style><div log="SIMPLE">Simple!</div>'
+ );
+ })));
+ });
+
+
+ describe('async template loading', () {
+ beforeEach(module((Module module) {
+ module.type(LogAttrDirective);
+ module.type(SimpleUrlComponent);
+ module.type(HtmlAndCssComponent);
+ module.type(OnlyCssComponent);
+ module.type(InlineWithCssComponent);
+ }));
+
+ it('should replace element with template from url', async(inject((Http $http,
+ Compiler $compile, Scope $rootScope, Logger log, Injector injector,
+ MockHttpBackend backend) {
+ backend.expectGET('simple.html').respond('<div log="SIMPLE">Simple!</div>');
+
+ var element = $('<div><simple-url log>ignore</simple-url><div>');
+ $compile(element)(injector, element);
+
+ backend.flush();
+ microLeap();
+
+ expect(renderedText(element)).toEqual('Simple!');
+ $rootScope.$digest();
+ // Note: There is no ordering. It is who ever comes off the wire first!
+ expect(log.result()).toEqual('LOG; SIMPLE');
+ })));
+
+ it('should load template from URL once', async(inject((Http $http,
+ Compiler $compile, Scope $rootScope, Logger log, Injector injector,
+ MockHttpBackend backend) {
+ backend.whenGET('simple.html').respond('<div log="SIMPLE">Simple!</div>');
+
+ var element = $(
+ '<div>' +
+ '<simple-url log>ignore</simple-url>' +
+ '<simple-url log>ignore</simple-url>' +
+ '<div>');
+ $compile(element)(injector, element);
+
+ backend.flush();
+ microLeap();
+
+ expect(renderedText(element)).toEqual('Simple!Simple!');
+ $rootScope.$digest();
+ // Note: There is no ordering. It is who ever comes off the wire first!
+ expect(log.result()).toEqual('LOG; LOG; SIMPLE; SIMPLE');
+ })));
+
+ it('should load a CSS file into a style', async(inject((Http $http,
+ Compiler $compile, Scope $rootScope, Logger log, Injector injector,
+ MockHttpBackend backend) {
+ backend.expectGET('simple.css').respond('.hello{}');
+ backend.expectGET('simple.html').respond('<div log="SIMPLE">Simple!</div>');
+
+ var element = $('<div><html-and-css log>ignore</html-and-css><div>');
+ $compile(element)(injector, element);
+
+ backend.flush();
+ microLeap();
+
+ expect(renderedText(element)).toEqual('.hello{}Simple!');
+ expect(element[0].nodes[0].shadowRoot.innerHtml).toEqual(
+ '<style>.hello{}</style><div log="SIMPLE">Simple!</div>'
+ );
+ $rootScope.$digest();
+ // Note: There is no ordering. It is who ever comes off the wire first!
+ expect(log.result()).toEqual('LOG; SIMPLE');
+ })));
+
+ it('should load a CSS file with a \$template', async(inject((Http $http,
+ Compiler $compile, Scope $rootScope, Injector injector, MockHttpBackend backend) {
+ var element = $('<div><inline-with-css log>ignore</inline-with-css><div>');
+ backend.expectGET('simple.css').respond('.hello{}');
+ $compile(element)(injector, element);
+
+ backend.flush();
+ microLeap();
+ expect(renderedText(element)).toEqual('.hello{}inline!');
+ })));
+
+ it('should load a CSS with no template', async(inject((Http $http,
+ Compiler $compile, Scope $rootScope, Injector injector, MockHttpBackend backend) {
+ var element = $('<div><only-css log>ignore</only-css><div>');
+ backend.expectGET('simple.css').respond('.hello{}');
+ $compile(element)(injector, element);
+
+ backend.flush();
+ microLeap();
+ expect(renderedText(element)).toEqual('.hello{}');
+ })));
+
+ it('should load the CSS before the template is loaded', async(inject((Http $http,
+ Compiler $compile, Scope $rootScope, Injector injector, MockHttpBackend backend) {
+ backend.expectGET('simple.css').respond('.hello{}');
+ backend.expectGET('simple.html').respond('<div>Simple!</div>');
+
+ var element = $('<html-and-css>ignore</html-and-css>');
+ $compile(element)(injector, element);
+
+ backend.flush();
+ microLeap();
+ expect(renderedText(element)).toEqual('.hello{}Simple!');
+ })));
+ });
+
+ describe('multiple css loading', () {
+ beforeEach(module((Module module) {
+ module.type(LogAttrDirective);
+ module.type(HtmlAndMultipleCssComponent);
+ }));
+
+ it('should load multiple CSS files into a style', async(inject((Http $http,
+ Compiler $compile, Scope $rootScope, Logger log, Injector injector,
+ MockHttpBackend backend) {
+ backend.expectGET('simple.css').respond('.hello{}');
+ backend.expectGET('another.css').respond('.world{}');
+ backend.expectGET('simple.html').respond('<div log="SIMPLE">Simple!</div>');
+
+ var element = $('<div><html-and-css log>ignore</html-and-css><div>');
+ $compile(element)(injector, element);
+
+ backend.flush();
+ microLeap();
+
+ expect(renderedText(element)).toEqual('.hello{}.world{}Simple!');
+ expect(element[0].nodes[0].shadowRoot.innerHtml).toEqual(
+ '<style>.hello{}.world{}</style><div log="SIMPLE">Simple!</div>'
+ );
+ $rootScope.$digest();
+ // Note: There is no ordering. It is who ever comes off the wire first!
+ expect(log.result()).toEqual('LOG; SIMPLE');
+ })));
+ });
+});

Powered by Google App Engine
This is Rietveld 408576698