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 +++++ src/ngScenario/Describe.js | 155 ++++++++ src/ngScenario/Future.js | 64 ++++ src/ngScenario/ObjectModel.js | 247 ++++++++++++ src/ngScenario/Runner.js | 227 +++++++++++ src/ngScenario/Scenario.js | 417 +++++++++++++++++++++ src/ngScenario/SpecRunner.js | 145 +++++++ src/ngScenario/angular-bootstrap.js | 60 +++ src/ngScenario/angular.prefix | 7 + src/ngScenario/angular.suffix | 22 ++ src/ngScenario/dsl.js | 405 ++++++++++++++++++++ src/ngScenario/jstd-scenario-adapter/Adapter.js | 177 +++++++++ .../jstd-scenario-adapter/angular.prefix | 6 + .../jstd-scenario-adapter/angular.suffix | 2 + src/ngScenario/matchers.js | 45 +++ src/ngScenario/output/Html.js | 171 +++++++++ src/ngScenario/output/Json.js | 10 + src/ngScenario/output/Object.js | 8 + src/ngScenario/output/Xml.js | 51 +++ 19 files changed, 2321 insertions(+) create mode 100644 src/ngScenario/Application.js create mode 100644 src/ngScenario/Describe.js create mode 100644 src/ngScenario/Future.js create mode 100644 src/ngScenario/ObjectModel.js create mode 100644 src/ngScenario/Runner.js create mode 100644 src/ngScenario/Scenario.js create mode 100644 src/ngScenario/SpecRunner.js create mode 100644 src/ngScenario/angular-bootstrap.js create mode 100644 src/ngScenario/angular.prefix create mode 100644 src/ngScenario/angular.suffix create mode 100644 src/ngScenario/dsl.js create mode 100644 src/ngScenario/jstd-scenario-adapter/Adapter.js create mode 100644 src/ngScenario/jstd-scenario-adapter/angular.prefix create mode 100644 src/ngScenario/jstd-scenario-adapter/angular.suffix create mode 100644 src/ngScenario/matchers.js create mode 100644 src/ngScenario/output/Html.js create mode 100644 src/ngScenario/output/Json.js create mode 100644 src/ngScenario/output/Object.js create mode 100644 src/ngScenario/output/Xml.js (limited to 'src/ngScenario') 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('