diff options
Diffstat (limited to 'test/scenario/ApplicationSpec.js')
| -rw-r--r-- | test/scenario/ApplicationSpec.js | 82 | 
1 files changed, 61 insertions, 21 deletions
| diff --git a/test/scenario/ApplicationSpec.js b/test/scenario/ApplicationSpec.js index 883701ba..122292c6 100644 --- a/test/scenario/ApplicationSpec.js +++ b/test/scenario/ApplicationSpec.js @@ -7,9 +7,10 @@ describe('angular.scenario.Application', function() {    });    it('should return new $window and $document after navigate', function() { +    var called;      var testWindow, testDocument, counter = 0;      app.navigateTo = noop; -    app.getWindow = function() { +    app.getWindow_ = function() {        return {x:counter++, document:{x:counter++}};      };      app.navigateTo('http://www.google.com/'); @@ -21,30 +22,45 @@ describe('angular.scenario.Application', function() {      app.executeAction(function($window, $document) {        expect($window).not.toEqual(testWindow);        expect($document).not.toEqual(testDocument); +      called = true;      }); +    expect(called).toBeTruthy();    });    it('should execute callback with correct arguments', function() { +    var called;      var testWindow = {document: {}}; -    app.getWindow = function() { +    app.getWindow_ = function() {        return testWindow;      };      app.executeAction(function($window, $document) {        expect(this).toEqual(app);        expect($document).toEqual(_jQuery($window.document));        expect($window).toEqual(testWindow); +      called = true;      }); +    expect(called).toBeTruthy();    }); -  it('should create a new iframe each time', function() { +  it('should use a new iframe each time', function() {      app.navigateTo('about:blank'); -    var frame = app.getFrame(); +    var frame = app.getFrame_();      frame.attr('test', true);      app.navigateTo('about:blank'); -    expect(app.getFrame().attr('test')).toBeFalsy(); +    expect(app.getFrame_().attr('test')).toBeFalsy();    }); -  it('should URL description bar', function() { +  it('should hide old iframes and navigate to about:blank', function() { +    app.navigateTo('about:blank#foo'); +    app.navigateTo('about:blank#bar'); +    var iframes = frames.find('iframe'); +    expect(iframes.length).toEqual(2); +    expect(iframes[0].src).toEqual('about:blank'); +    expect(iframes[1].src).toEqual('about:blank#bar'); +    expect(_jQuery(iframes[0]).css('display')).toEqual('none'); +  }); + +  it('should URL update description bar', function() {      app.navigateTo('about:blank');      var anchor = frames.find('> h2 a');      expect(anchor.attr('href')).toEqual('about:blank'); @@ -53,24 +69,48 @@ describe('angular.scenario.Application', function() {    it('should call onload handler when frame loads', function() {      var called; -    app.getFrame = function() { -      // Mock a little jQuery -      var result = { -        remove: function() { -          return result; -        }, -        attr: function(key, value) { -          return (!value) ? 'attribute value' : result; -        }, -        load: function() { -          called = true; -        } -      }; -      return result; +    app.getWindow_ = function() { +      return {};      }; -    app.navigateTo('about:blank', function() { +    app.navigateTo('about:blank', function($window, $document) {        called = true;      }); +    var handlers = app.getFrame_().data('events').load; +    expect(handlers).toBeDefined(); +    expect(handlers.length).toEqual(1); +    handlers[0].handler();      expect(called).toBeTruthy();    }); + +  it('should wait for pending requests in executeAction', function() { +    var called, polled; +    var handlers = []; +    var testWindow = { +      document: _jQuery('<div class="test-foo"></div>'), +      angular: { +        service: {}, +      } +    }; +    testWindow.angular.service.$browser = function() { +      return { +        poll: function() { +          polled = true; +        }, +        notifyWhenNoOutstandingRequests: function(fn) { +          handlers.push(fn); +        } +      } +    }; +    app.getWindow_ = function() { +      return testWindow; +    }; +    app.executeAction(function($window, $document) { +      expect($window).toEqual(testWindow); +      expect($document).toBeDefined(); +      expect($document[0].className).toEqual('test-foo'); +    }); +    expect(polled).toBeTruthy(); +    expect(handlers.length).toEqual(1); +    handlers[0](); +  });  }); | 
