<commit_before>/*
Copyright 2006, Open Source Applications Foundation

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
*/

/*
 * Copyright 2004 ThoughtWorks, Inc
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */

/*
 Functionality that works for every browser
 Mozilla specific functionality abstracted to mozcontroller.js
 Safari specific functionality abstracted to safcontroller.js
 IE specific functionality abstracted to iecontroller.js

 The reason for this is that the start page only includes the one corresponding
 to the current browser, this means that the functionality in the controller
 object is only for the current browser, and there is only one copy of the code being
 loaded into the browser for performance.
 */
 
windmill.controller = new function () {
    
    this.extensions           = {};
    this.commands             = {};
    this.asserts              = {};
    this.waits                = {};
    
    this.optionLocatorFactory = new OptionLocatorFactory();

    
    /*******************************
    /* Helper functions, non user facing
    /* Note: the getControllerMethods command above returns a list of all the user facing functions to the user
    /* And the ones that start with an underscore are ignored in that list
    /* So if you are adding functionality for internal use and doesnt map from json please start with _
    /*******************************/
    this._getDocument = function () { return windmill.testingApp.document; }
    this._getCurrentWindow = function() { return parent; }
    this._getTitle = function() {
        var t = this._getDocument().title;
        if (typeof(t) == "string") {
            t = t.trim();
        }
        return t;
    }

    //Translates from the way we are passing objects to functions to the lookups
    this._lookupDispatch = function (param_object){

        var element = null;
        //If a link was passed, lookup as link
        if(typeof param_object.link != "undefined") {
            element = this.findElement("link=" + param_object.link)
        }
    
        //if xpath was passed, lookup as xpath
        if(typeof param_object.xpath != "undefined") {                
            element = this.findElement("xpath=" + param_object.xpath);
        }
    
        //if id was passed, do as such
        if(typeof param_object.id != "undefined") {
            element = this.findElement("id=" + param_object.id)
        }
    
        //if jsid was passed
        if(typeof param_object.jsid != "undefined") {
            var jsid;
            eval ("jsid=" + param_object.jsid + ";");
            element = this.findElement("id=" + jsid);
        }
    
        //if name was passed
        if(typeof param_object.name != "undefined") {
            element = this.findElement("name=" + param_object.name)
        }        
        

        return element;
    };

    //Function to handle the random keyword scenario
    this._handleVariable = function (actualValue){
         var variables = actualValue.match(/{\$[^}]*}/g);
                                
         for (var i = 0; i < variables.length; i++){
            var variable = variables[i];
            
            if (windmill.varRegistry.hasKey(variable)){
               actualValue = actualValue.replace(variable, windmill.varRegistry.getByKey(variable));
            }
            //if it doesn't exist and contains the string random we create it (username or pass etc)
            else if (variable.indexOf('random') != -1){
             actualValue = actualValue.replace(variable, windmill.varRegistry.addItemCreateValue(variable));
            }
          }
    
      return actualValue;
     }

  /************************************
  /* User facing windmill functionality
  /************************************/
  this.defer = function (){
      //We may want to somehow display that the loop is being deferred but right now it was too messy in output.
      //windmill.ui.results.writeResult('Deferring..')
      //If we are getting defers, no tests are running.. and the playback button should be available
      //windmill.remote.$('playback').src = 'ide/img/playback.png';
      //console.log(windmill.remote.$('playback'));
  };

  //After a page is done loading, continue the loop
  this.continueLoop = function (){
    cont = function(){
      windmill.xhr.loopState = 1;
      windmill.xhr.startJsonLoop();
    }
    //Just making sure the page is fully loaded
    setTimeout("cont()", 1000);
  };

  //open an url in the webapp iframe
  this.open = function (param_object) {
      //We need to tell the service where we are before we
      //head to a new page
      windmill.service.setTestURL();
    
      //Turn the loop off until the page loads
      windmill.xhr.loopState = 0;
      webappframe = document.getElementById('webapp');        
      webappframe.src = param_object.url;
    
      //Turn off loop until the onload for the iframe restarts it
      //windmill.xhr.togglePauseJsonLoop();
      done = function(){
        return true;
      }
      setTimeout('done()', 5000);
  };


  //Type Function
  this.type = function (param_object){

  var element = this._lookupDispatch(param_object);
  if (!element){
     return false;
  }
       //Get the focus on to the item to be typed in, or selected
       windmill.events.triggerEvent(element, 'focus', false);
       windmill.events.triggerEvent(element, 'select', true);
     
       //Make sure text fits in the textbox
       var maxLengthAttr = element.getAttribute("maxLength");
       var actualValue = param_object.text;
       var stringValue = param_object.text;
     
       if (maxLengthAttr != null) {
           var maxLength = parseInt(maxLengthAttr);
           if (stringValue.length > maxLength) {
               //truncate it to fit
               actualValue = stringValue.substr(0, maxLength);
           }
       }
     
       //actualValue = this._handleRandom(actualValue);<commit_msg>Tweaking open<commit_after>/*
Copyright 2006, Open Source Applications Foundation

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
*/

/*
 * Copyright 2004 ThoughtWorks, Inc
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */

/*
 Functionality that works for every browser
 Mozilla specific functionality abstracted to mozcontroller.js
 Safari specific functionality abstracted to safcontroller.js
 IE specific functionality abstracted to iecontroller.js

 The reason for this is that the start page only includes the one corresponding
 to the current browser, this means that the functionality in the controller
 object is only for the current browser, and there is only one copy of the code being
 loaded into the browser for performance.
 */
 
windmill.controller = new function () {
    
    this.extensions           = {};
    this.commands             = {};
    this.asserts              = {};
    this.waits                = {};
    
    this.optionLocatorFactory = new OptionLocatorFactory();

    
    /*******************************
    /* Helper functions, non user facing
    /* Note: the getControllerMethods command above returns a list of all the user facing functions to the user
    /* And the ones that start with an underscore are ignored in that list
    /* So if you are adding functionality for internal use and doesnt map from json please start with _
    /*******************************/
    this._getDocument = function () { return windmill.testingApp.document; }
    this._getCurrentWindow = function() { return parent; }
    this._getTitle = function() {
        var t = this._getDocument().title;
        if (typeof(t) == "string") {
            t = t.trim();
        }
        return t;
    }

    //Translates from the way we are passing objects to functions to the lookups
    this._lookupDispatch = function (param_object){

        var element = null;
        //If a link was passed, lookup as link
        if(typeof param_object.link != "undefined") {
            element = this.findElement("link=" + param_object.link)
        }
    
        //if xpath was passed, lookup as xpath
        if(typeof param_object.xpath != "undefined") {                
            element = this.findElement("xpath=" + param_object.xpath);
        }
    
        //if id was passed, do as such
        if(typeof param_object.id != "undefined") {
            element = this.findElement("id=" + param_object.id)
        }
    
        //if jsid was passed
        if(typeof param_object.jsid != "undefined") {
            var jsid;
            eval ("jsid=" + param_object.jsid + ";");
            element = this.findElement("id=" + jsid);
        }
    
        //if name was passed
        if(typeof param_object.name != "undefined") {
            element = this.findElement("name=" + param_object.name)
        }        
        

        return element;
    };

    //Function to handle the random keyword scenario
    this._handleVariable = function (actualValue){
         var variables = actualValue.match(/{\$[^}]*}/g);
                                
         for (var i = 0; i < variables.length; i++){
            var variable = variables[i];
            
            if (windmill.varRegistry.hasKey(variable)){
               actualValue = actualValue.replace(variable, windmill.varRegistry.getByKey(variable));
            }
            //if it doesn't exist and contains the string random we create it (username or pass etc)
            else if (variable.indexOf('random') != -1){
             actualValue = actualValue.replace(variable, windmill.varRegistry.addItemCreateValue(variable));
            }
          }
    
      return actualValue;
     }

  /************************************
  /* User facing windmill functionality
  /************************************/
  this.defer = function (){
      //We may want to somehow display that the loop is being deferred but right now it was too messy in output.
      //windmill.ui.results.writeResult('Deferring..')
      //If we are getting defers, no tests are running.. and the playback button should be available
      //windmill.remote.$('playback').src = 'ide/img/playback.png';
      //console.log(windmill.remote.$('playback'));
  };

  //After a page is done loading, continue the loop
  this.continueLoop = function (){
    cont = function(){
      windmill.xhr.loopState = 1;
      windmill.xhr.startJsonLoop();
    }
    //Just making sure the page is fully loaded
    setTimeout("cont()", 1000);
  };

  //open an url in the webapp iframe
  this.open = function (param_object) {
      //We need to tell the service where we are before we
      //head to a new page
      windmill.service.setTestURL();
    
      //Turn the loop off until the page loads
      windmill.xhr.loopState = 0;
      webappframe = document.getElementById('webapp');        
      webappframe.src = param_object.url;
    
      //Turn off loop until the onload for the iframe restarts it
      //windmill.xhr.togglePauseJsonLoop();
      done = function(){
        return true;
      }
      setTimeout('done()', 5000);
      return true;
  };


  //Type Function
  this.type = function (param_object){

  var element = this._lookupDispatch(param_object);
  if (!element){
     return false;
  }
       //Get the focus on to the item to be typed in, or selected
       windmill.events.triggerEvent(element, 'focus', false);
       windmill.events.triggerEvent(element, 'select', true);
     
       //Make sure text fits in the textbox
       var maxLengthAttr = element.getAttribute("maxLength");
       var actualValue = param_object.text;
       var stringValue = param_object.text;
     
       if (maxLengthAttr != null) {
           var maxLength = parseInt(maxLengthAttr);
           if (stringValue.length > maxLength) {
               //truncate it to fit
               actualValue = stringValue.substr(0, maxLength);
           }
       }
     
       //actualValue = this._handleRandom(actualValue);
{'fraction_non_alphanumeric': 0.10855098389982111, 'fraction_numerical': 0.004150268336314848, 'mean_word_length': 2.4137762579384465, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6871371', 'n_tokens_mistral': 3621, 'n_tokens_neox': 3528, 'n_words': 1318}