From 2430f52bb97fa9d682e5f028c977c5bf94c5ec38 Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Fri, 23 Mar 2012 14:03:24 -0700
Subject: chore(module): move files around in preparation for more modules
---
src/ngScenario/Application.js | 102 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 102 insertions(+)
create mode 100644 src/ngScenario/Application.js
(limited to 'src/ngScenario/Application.js')
diff --git a/src/ngScenario/Application.js b/src/ngScenario/Application.js
new file mode 100644
index 00000000..d3a70569
--- /dev/null
+++ b/src/ngScenario/Application.js
@@ -0,0 +1,102 @@
+'use strict';
+
+/**
+ * Represents the application currently being tested and abstracts usage
+ * of iframes or separate windows.
+ *
+ * @param {Object} context jQuery wrapper around HTML context.
+ */
+angular.scenario.Application = function(context) {
+ this.context = context;
+ context.append(
+ '
Current URL: None
' +
+ ''
+ );
+};
+
+/**
+ * Gets the jQuery collection of frames. Don't use this directly because
+ * frames may go stale.
+ *
+ * @private
+ * @return {Object} jQuery collection
+ */
+angular.scenario.Application.prototype.getFrame_ = function() {
+ return this.context.find('#test-frames iframe:last');
+};
+
+/**
+ * Gets the window of the test runner frame. Always favor executeAction()
+ * instead of this method since it prevents you from getting a stale window.
+ *
+ * @private
+ * @return {Object} the window of the frame
+ */
+angular.scenario.Application.prototype.getWindow_ = function() {
+ var contentWindow = this.getFrame_().prop('contentWindow');
+ if (!contentWindow)
+ throw 'Frame window is not accessible.';
+ return contentWindow;
+};
+
+/**
+ * Changes the location of the frame.
+ *
+ * @param {string} url The URL. If it begins with a # then only the
+ * hash of the page is changed.
+ * @param {function()} loadFn function($window, $document) Called when frame loads.
+ * @param {function()} errorFn function(error) Called if any error when loading.
+ */
+angular.scenario.Application.prototype.navigateTo = function(url, loadFn, errorFn) {
+ var self = this;
+ var frame = this.getFrame_();
+ //TODO(esprehn): Refactor to use rethrow()
+ errorFn = errorFn || function(e) { throw e; };
+ if (url === 'about:blank') {
+ errorFn('Sandbox Error: Navigating to about:blank is not allowed.');
+ } else if (url.charAt(0) === '#') {
+ url = frame.attr('src').split('#')[0] + url;
+ frame.attr('src', url);
+ this.executeAction(loadFn);
+ } else {
+ frame.remove();
+ this.context.find('#test-frames').append('