screens.context.js 4.53 KB
/*
 * ADOBE CONFIDENTIAL
 *
 * Copyright 2015 Adobe Systems Incorporated
 * All Rights Reserved.
 *
 * NOTICE:  All information contained herein is, and remains
 * the property of Adobe Systems Incorporated and its suppliers,
 * if any.  The intellectual and technical concepts contained
 * herein are proprietary to Adobe Systems Incorporated and its
 * suppliers and may be covered by U.S. and Foreign Patents,
 * patents in process, and are protected by trade secret or copyright law.
 * Dissemination of screens information or reproduction of screens material
 * is strictly forbidden unless prior written permission is obtained
 * from Adobe Systems Incorporated.
 */

(function(hobs, $) {
    'use strict';

    var screens = hobs.actions.screens;

    var _resetContext = function() {
        if (!screens._initialContext) {
            screens._initialContext = hobs.context().loadEl;
        }
        hobs.setContext(screens._initialContext);
    };

    /**
     * Restore the Hobbes context to its initial value
     * @param {Object} options Stand Step options
     */
    screens.resetContext = function(options) {
        var step = new hobs.actions.core.execFct(_resetContext, options); // eslint-disable-line new-cap
        hobs.TestStep.call(this, null, null, step, options);
    };

    screens.resetContext.prototype = new hobs.TestStep();

    screens.resetContext.prototype.constructor = screens.resetContext;
    screens.resetContext.prototype.type = 'hobs.actions.screens.resetContext';

    // Overwrite result messages
    screens.resetContext.prototype['res-msg-passed'] = 'Successfully restored context';
    screens.resetContext.prototype['res-msg-failed'] = 'Failed to restore context';

    /**
     * Set Hobbes context to the firmware frame
     * @param {Object} options Stand Step options
     */
    screens.setFirmwareContext = function(options) {
        var fct = function() {
            // firwmare is first frame, aka default context
            _resetContext();
        };
        var step = new hobs.actions.core.execFct(fct, options); // eslint-disable-line new-cap
        hobs.TestStep.call(this, null, null, step, options);
    };

    screens.setFirmwareContext.prototype = new hobs.TestStep();

    screens.resetContext.prototype.constructor = screens.setFirmwareContext;
    screens.resetContext.prototype.type = 'hobs.actions.screens.setFirmwareContext';

    // Overwrite result messages
    screens.setFirmwareContext.prototype['res-msg-passed'] = 'Successfully set Firmware context';
    screens.setFirmwareContext.prototype['res-msg-failed'] = 'Failed to set Firmware context';

    /**
     * Set Hobbes context to the display frame
     * @param {Object} options Stand Step options
     */
    screens.setDisplayContext = function(options) {
        var fct = function() {
            _resetContext();
            hobs.setContext(hobs.context().window.frames[0]);
        };

        var step = new hobs.actions.core.execFct(fct, options); // eslint-disable-line new-cap
        hobs.TestStep.call(this, null, null, step, options);
    };

    screens.setDisplayContext.prototype = new hobs.TestStep();

    screens.resetContext.prototype.constructor = screens.setDisplayContext;
    screens.resetContext.prototype.type = 'hobs.actions.screens.setDisplayContext';

    // Overwrite result messages
    screens.setDisplayContext.prototype['res-msg-passed'] = 'Successfully set Display context';
    screens.setDisplayContext.prototype['res-msg-failed'] = 'Failed to set Display context';

    /**
     * Set Hobbes context to the channel frame
     * @param {Number} index   Index of the channel, in case of multiple (defaults to 0)
     * @param {Object}  options Stand Step options
     */
    screens.setChannelContext = function(index, options) {
        var fct = function() {
            _resetContext();
            index = index || 0;
            hobs.setContext(hobs.context().window.frames[0].window.frames[index]);
        };

        var step = new hobs.actions.core.execFct(fct, options); // eslint-disable-line new-cap
        hobs.TestStep.call(this, null, null, step, options);
    };

    screens.setChannelContext.prototype = new hobs.TestStep();

    screens.resetContext.prototype.constructor = screens.setChannelContext;
    screens.resetContext.prototype.type = 'hobs.actions.screens.setChannelContext';

    // Overwrite result messages
    screens.setChannelContext.prototype['res-msg-passed'] = 'Successfully set Channel context';
    screens.setChannelContext.prototype['res-msg-failed'] = 'Failed to set Channel context';

}(window.hobs, window.jQuery));