blob: 4ee0dd03bde51ca180416b2ee1ee58b73dd629d9 (
plain)
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
|
/**
* Represents the application currently being tested and abstracts usage
* of iframes or separate windows.
*/
angular.scenario.Application = function(context) {
this.context = context;
context.append('<h2>Current URL: <a href="about:blank">None</a></h2>');
};
/**
* Gets the jQuery collection of frames. Don't use this directly because
* frames may go stale.
*
* @return {Object} jQuery collection
*/
angular.scenario.Application.prototype.getFrame = function() {
return this.context.find('> iframe');
};
/**
* Gets the window of the test runner frame. Always favor executeAction()
* instead of this method since it prevents you from getting a stale window.
*
* @return {Object} the window of the frame
*/
angular.scenario.Application.prototype.getWindow = function() {
var contentWindow = this.getFrame().attr('contentWindow');
if (!contentWindow)
throw 'No window available because frame not loaded.';
return contentWindow;
};
/**
* Changes the location of the frame.
*/
angular.scenario.Application.prototype.navigateTo = function(url, onloadFn) {
this.getFrame().remove();
this.context.append('<iframe src=""></iframe>');
this.context.find('> h2 a').attr('href', url).text(url);
this.getFrame().attr('src', url).load(onloadFn);
};
/**
* Executes a function in the context of the tested application.
*
* @param {Function} The callback to execute. function($window, $document)
*/
angular.scenario.Application.prototype.executeAction = function(action) {
var $window = this.getWindow();
return action.call(this, $window, _jQuery($window.document));
};
|