diff --git a/modules/angular2/src/dom/browser_adapter.dart b/modules/angular2/src/dom/browser_adapter.dart index 7e91cebb2c..8084d9b98c 100644 --- a/modules/angular2/src/dom/browser_adapter.dart +++ b/modules/angular2/src/dom/browser_adapter.dart @@ -326,4 +326,7 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter { var baseUri = Uri.parse(uri); return baseUri.path; } + String getUserAgent() { + return window.navigator.userAgent; + } } diff --git a/modules/angular2/src/dom/browser_adapter.ts b/modules/angular2/src/dom/browser_adapter.ts index 08d1944f2b..095a8efe1a 100644 --- a/modules/angular2/src/dom/browser_adapter.ts +++ b/modules/angular2/src/dom/browser_adapter.ts @@ -372,6 +372,9 @@ getLocation() { getBaseHref() { return relativePath(document.baseURI); } +getUserAgent(): string { + return window.navigator.userAgent; +} } // based on urlUtils.js in AngularJS 1 diff --git a/modules/angular2/src/dom/dom_adapter.ts b/modules/angular2/src/dom/dom_adapter.ts index 1acc45ee6a..3ecf47ea5d 100644 --- a/modules/angular2/src/dom/dom_adapter.ts +++ b/modules/angular2/src/dom/dom_adapter.ts @@ -114,4 +114,5 @@ export class DomAdapter { getHistory() { throw _abstract(); } getLocation() { throw _abstract(); } getBaseHref() { throw _abstract(); } + getUserAgent() { throw _abstract(); } } diff --git a/modules/angular2/src/dom/html_adapter.dart b/modules/angular2/src/dom/html_adapter.dart index c7b31e727b..4ff959868c 100644 --- a/modules/angular2/src/dom/html_adapter.dart +++ b/modules/angular2/src/dom/html_adapter.dart @@ -303,4 +303,7 @@ class Html5LibDomAdapter implements DomAdapter { getBaseHref() { throw 'not implemented'; } + String getUserAgent() { + throw 'not implemented'; + } } diff --git a/modules/angular2/src/dom/parse5_adapter.cjs b/modules/angular2/src/dom/parse5_adapter.cjs index cd22d98787..252202329c 100644 --- a/modules/angular2/src/dom/parse5_adapter.cjs +++ b/modules/angular2/src/dom/parse5_adapter.cjs @@ -540,6 +540,9 @@ export class Parse5DomAdapter extends DomAdapter { getLocation() { throw 'not implemented'; } + getUserAgent() { + return "Fake user agent"; + } } //TODO: build a proper list, this one is all the keys of a HTMLInputElement diff --git a/modules/angular2/test/change_detection/pipes/promise_pipe_spec.js b/modules/angular2/test/change_detection/pipes/promise_pipe_spec.js index 9099b0fea4..36cb6d9a36 100644 --- a/modules/angular2/test/change_detection/pipes/promise_pipe_spec.js +++ b/modules/angular2/test/change_detection/pipes/promise_pipe_spec.js @@ -5,6 +5,7 @@ import {PromisePipe} from 'angular2/src/change_detection/pipes/promise_pipe'; import {WrappedValue} from 'angular2/src/change_detection/pipes/pipe'; import {ChangeDetectorRef} from 'angular2/src/change_detection/change_detector_ref'; import {PromiseWrapper, TimerWrapper} from 'angular2/src/facade/async'; +import {DOM} from 'angular2/src/dom/dom_adapter'; export function main() { describe("PromisePipe", () => { @@ -12,6 +13,8 @@ export function main() { var pipe; var completer; var ref; + //adds longer timers for passing tests in IE + var timer = (DOM.getUserAgent().indexOf("Trident") > -1) ? 50 : 0; beforeEach(() => { completer = PromiseWrapper.completer(); @@ -43,7 +46,7 @@ export function main() { TimerWrapper.setTimeout(() => { expect(pipe.transform(completer.promise)).toEqual(new WrappedValue(message)); async.done(); - }, 0) + }, timer) })); it("should return unwrapped value when nothing has changed since the last call", @@ -55,7 +58,7 @@ export function main() { pipe.transform(completer.promise); expect(pipe.transform(completer.promise)).toBe(message); async.done(); - }, 0) + }, timer) })); it("should dispose of the existing subscription when subscribing to a new promise", @@ -71,7 +74,7 @@ export function main() { TimerWrapper.setTimeout(() => { expect(pipe.transform(newCompleter.promise)).toBe(null); async.done(); - }, 0) + }, timer) })); it("should request a change detection check upon receiving a new value", @@ -82,7 +85,7 @@ export function main() { TimerWrapper.setTimeout(() => { expect(ref.spy('requestCheck')).toHaveBeenCalled(); async.done(); - }, 0) + }, timer) })); describe("onDestroy", () => { @@ -101,7 +104,7 @@ export function main() { pipe.onDestroy(); expect(pipe.transform(completer.promise)).toBe(null); async.done(); - }, 0); + }, timer); })); }); }); diff --git a/modules/angular2/test/core/zone/ng_zone_spec.js b/modules/angular2/test/core/zone/ng_zone_spec.js index c49a3e4398..a78249e0c1 100644 --- a/modules/angular2/test/core/zone/ng_zone_spec.js +++ b/modules/angular2/test/core/zone/ng_zone_spec.js @@ -16,12 +16,15 @@ import { import {PromiseWrapper, TimerWrapper} from 'angular2/src/facade/async'; import {ListWrapper} from 'angular2/src/facade/collection'; import {BaseException} from 'angular2/src/facade/lang'; +import {DOM} from 'angular2/src/dom/dom_adapter'; import {NgZone} from 'angular2/src/core/zone/ng_zone'; +var isIE = DOM.getUserAgent().indexOf("Trident") > -1; // Schedules a macrotask (using a timer) -function macroTask(fn: Function): void { - _zone.runOutsideAngular(() => TimerWrapper.setTimeout(fn, 1)); +function macroTask(fn: Function, timer = 1): void { + //adds longer timers for passing tests in IE + _zone.runOutsideAngular(() => TimerWrapper.setTimeout(fn, isIE ? timer : 1)); } // Schedules a microtasks (using a resolved promise .then()) @@ -192,7 +195,7 @@ function commonTests() { // The microtask (async) is executed after the macrotask (run) expect(_log.result()).toEqual('onTurnStart; run start; run end; async; onTurnDone'); async.done(); - }); + }, 50); })); it('should not run onTurnStart and onTurnDone for nested Zone.run', @@ -211,7 +214,7 @@ function commonTests() { macroTask(() => { expect(_log.result()).toEqual('onTurnStart; start run; nested run; end run; nested run microtask; onTurnDone'); async.done(); - }); + }, 50); })); it('should call onTurnStart and onTurnDone before and after each top-level run', @@ -256,7 +259,7 @@ function commonTests() { macroTask(() => { expect(_log.result()).toEqual('onTurnStart; run start; onTurnDone; onTurnStart; a then; b then; onTurnDone'); async.done(); - }); + }, 50); })); it('should run a function outside of the angular zone', inject([AsyncTestCompleter], (async) => { @@ -303,7 +306,7 @@ function commonTests() { 'onTurnStart; executedMicrotask; onTurnDone' ); async.done(); - }); + }, 50); })); it('should call onTurnStart before executing a microtask scheduled in onTurnDone as well as ' + @@ -334,7 +337,7 @@ function commonTests() { 'onTurnStart; executedMicrotask; onTurnDone(begin); onTurnDone(end)' ); async.done(); - }); + }, 50); })); it('should call onTurnStart and onTurnDone for a scheduleMicrotask in onTurnDone triggered by ' + @@ -369,8 +372,7 @@ function commonTests() { 'onTurnStart; onTurnDone(executeMicrotask); onTurnDone(begin); onTurnDone(end)' ); async.done(); - - }); + }, 50); })); it('should execute promises scheduled in onTurnStart before promises scheduled in run', @@ -426,7 +428,7 @@ function commonTests() { 'onTurnStart(begin); onTurnStart(end); onTurnDone(executePromise); onTurnDone(begin); onTurnDone(end)' ); async.done(); - }); + }, 50); })); it('should call onTurnStart and onTurnDone before and after each turn, respectively', @@ -447,14 +449,14 @@ function commonTests() { _zone.run(() => { completerA.resolve(null); }); - }); + }, 10); macroTask(() => { _zone.run(() => { completerB.resolve(null); }); - }); + }, 30); macroTask(() => { expect(_log.result()).toEqual( @@ -465,7 +467,7 @@ function commonTests() { // Third VM turn 'onTurnStart; b then; onTurnDone'); async.done(); - }); + }, 60); })); it('should call onTurnStart and onTurnDone before and after (respectively) all turns in a chain', @@ -484,7 +486,7 @@ function commonTests() { macroTask(() => { expect(_log.result()).toEqual('onTurnStart; run start; run end; async1; async2; onTurnDone'); async.done(); - }); + }, 50); })); it('should call onTurnStart and onTurnDone for promises created outside of run body', @@ -505,7 +507,7 @@ function commonTests() { macroTask(() => { expect(_log.result()).toEqual('onTurnStart; zone run; onTurnDone; onTurnStart; promise then; onTurnDone'); async.done(); - }); + }, 50); })); }); @@ -541,7 +543,7 @@ function commonTests() { expect(_errors.length).toBe(1); expect(_errors[0]).toEqual(exception); async.done(); - }); + }, 50); })); it('should call onError when onTurnDone throws and the zone is sync', @@ -561,7 +563,7 @@ function commonTests() { expect(_errors.length).toBe(1); expect(_errors[0]).toEqual(exception); async.done(); - }); + }, 50); })); it('should call onError when onTurnDone throws and the zone is async', @@ -587,7 +589,7 @@ function commonTests() { expect(_errors.length).toBe(1); expect(_errors[0]).toEqual(exception); async.done(); - }); + }, 50); })); }); }