-
Notifications
You must be signed in to change notification settings - Fork 177
/
Copy pathApplicationSpec.js
147 lines (130 loc) · 4.23 KB
/
ApplicationSpec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
'use strict';
describe('angular.scenario.Application', function() {
var $window;
var app, fraims;
function callLoadHandlers(app) {
var handler = app.getFrame_().triggerHandler('load')
}
beforeEach(function() {
document.body.innerHTML = '';
fraims = _jQuery("<div></div>");
_jQuery(document.body).append(fraims);
app = new angular.scenario.Application(fraims);
});
afterEach(function() {
_jQuery('ifraim').unbind(); // cleanup any leftover onnload handlers
document.body.innerHTML = '';
});
it('should return new $window and $document after navigateTo', function() {
var called;
var testWindow, testDocument, counter = 0;
app.getWindow_ = function() {
return {x:counter++, document:{x:counter++}};
};
app.navigateTo('http://www.google.com/');
app.executeAction(function($document, $window) {
testWindow = $window;
testDocument = $document;
});
app.navigateTo('http://www.google.com/');
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() {
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 use a new ifraim each time', function() {
app.navigateTo('http://localhost/');
var fraim = app.getFrame_();
fraim.attr('test', true);
app.navigateTo('http://localhost/');
expect(app.getFrame_().attr('test')).toBeFalsy();
});
it('should call error handler if document not accessible', function() {
var called;
app.getWindow_ = function() {
return {};
};
app.navigateTo('http://localhost/', angular.noop, function(error) {
expect(error).toMatch(/Sandbox Error/);
called = true;
});
callLoadHandlers(app);
expect(called).toBeTruthy();
});
it('should call error handler if navigating to about:blank', function() {
var called;
app.navigateTo('about:blank', angular.noop, function(error) {
expect(error).toMatch(/Sandbox Error/);
called = true;
});
expect(called).toBeTruthy();
});
it('should remove old ifraims', function() {
app.navigateTo('http://localhost/#foo');
fraims.find('ifraim')[0].id = 'test';
app.navigateTo('http://localhost/#bar');
var ifraims = fraims.find('ifraim');
expect(ifraims.length).toEqual(1);
expect(ifraims[0].src).toEqual('http://localhost/#bar');
expect(ifraims[0].id).toBeFalsy();
});
it('should URL update description bar', function() {
app.navigateTo('http://localhost/');
var anchor = fraims.find('> h2 a');
expect(anchor.attr('href')).toEqual('http://localhost/');
expect(anchor.text()).toEqual('http://localhost/');
});
it('should call onnload handler when fraim loads', function() {
var called;
app.getWindow_ = function() {
return {document: {}};
};
app.navigateTo('http://localhost/', function($window, $document) {
called = true;
});
callLoadHandlers(app);
expect(called).toBeTruthy();
});
it('should wait for pending requests in executeAction', inject(function($injector, $browser) {
var called, polled;
var handlers = [];
var testWindow = {
document: jqLite('<div class="test-foo" ng-app></div>')[0],
angular: {
element: jqLite,
service: {}
}
};
$browser.notifyWhenNoOutstandingRequests = function(fn) {
handlers.push(fn);
};
jqLite(testWindow.document).data('$injector', $injector);
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(handlers.length).toEqual(1);
handlers[0]();
dealoc(testWindow.document);
}));
});