<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.
*/

windmill.controller.asserts.assertRegistry = {
  'assertTrue': {
    expr: function (a) {
      if (typeof a != 'boolean') {
        throw('Bad argument to assertTrue.');
      }
      return a === true;
    },
    errMsg: 'expected true but was false.'
  },

  'assertFalse': {
    expr: function (a) {
      if (typeof a != 'boolean') {
        throw('Bad argument to assertFalse.');
      }
      return a === false;
    },
    errMsg: 'expected false but was true.'
  },

  'assertEquals': {
    expr: function (a, b) { return a === b; },
    errMsg: 'expected $1 but was $2.'
  },

  'assertNotEquals': {
    expr: function (a, b) { return a !== b; },
    errMsg: 'expected one of the two values not to be $1.'
  },

  'assertNull': {
    expr: function (a) { return a === null; },
    errMsg: 'expected to be null but was $1.'
  },

  'assertNotNull': {
    expr: function (a) { return a !== null; },
    errMsg: 'expected not to be null but was null.'
  },

  'assertUndefined': {
    expr: function (a) { return typeof a == 'undefined'; },
    errMsg: 'expected to be undefined but was $1.'
  },

  'assertNotUndefined': {
    expr: function (a) { return typeof a != 'undefined'; },
    errMsg: 'expected not to be undefined but was undefined.'
  },

  'assertNaN': {
    expr: function (a) { return typeof a == 'undefined'; },
    errMsg: 'expected to be undefined but was $1.'
  },

  'assertNotNaN': {
    expr: function (a) { return typeof a != 'undefined'; },
    errMsg: 'expected not to be undefined but was undefined.'
  },

  'assertEvaluatesToTrue': {
    expr: function (a) { return !!a; },
    errMsg: 'value of $1 does not evaluate to true.'
  },

  'assertEvaluatesToFalse': {
    expr: function (a) { return !a; },
    errMsg: 'value of $1 does not evaluate to false.'
  },

  'assertContains': {
    expr: function (a, b) {
      if (typeof a != 'string' || typeof b != 'string') {
        throw('Bad argument to assertContains.');
      }
      return (a.indexOf(b) > -1);
    },
    errMsg: 'value of $1 does not contain $2.'
  }
};

//Currently only does one level below the provided div
//To make it more thorough it needs recursion to be implemented later
windmill.controller.asserts.assertText = function (param_object) { 
    
    var n = windmill.controller._lookupDispatch(param_object);
    var validator = param_object.validator;
  try{
   if (n.innerHTML.indexOf(validator) != -1){
     return true;
   }
   if (n.hasChildNodes()){
      for(var m = n.firstChild; m != null; m = m.nextSibling) {       
       if (m.innerHTML.indexOf(validator) != -1){
        return true;
       }
       if (m.value.indexOf(validator) != -1){
         return true;  
       }
      }
    }
  }
  catch(error){
   return false;
  } 
   return false;
}; 
 
   //Assert that a specified node exists
windmill.controller.asserts.assertNode = function (param_object) { 

   var element = windmill.controller._lookupDispatch(param_object);
   if (!element){
    return false;
   }
    return true;
 };   

//Assert that a form element contains the expected value
windmill.controller.asserts.assertValue = function (param_object) { 
   var n = windmill.controller._lookupDispatch(param_object);
   var validator = param_object.validator;
 
   if (n.value.indexOf(validator) != -1){
    return true;
   }
   return false;
 };

//Assert that a provided value is selected in a select element
windmill.controller.asserts.assertSelected = function (param_object) { 
   var n = windmill.controller._lookupDispatch(param_object);
   var validator = param_object.validator;
 
   if (n.options[n.selectedIndex].value == validator){
    return true;
   }
   return false;
 };
 
//Assert that a provided value is selected in a select element
windmill.controller.asserts.assertChecked = function (param_object) { 
   var n = windmill.controller._lookupDispatch(param_object);
   var validator = param_object.validator;
 
   if (n.checked == true){
    return true;
   }
   return false;
 };

// Assert that a an element's property is a particular
// value
windmill.controller.asserts.assertProperty = function (param_object) { 
   var element = windmill.controller._lookupDispatch(param_object);
   if (!element){
    return false;
   }
   var vArray = param_object.validator.split('|');
   var value = eval ('element.' + vArray[0]+';');
   if (value.indexOf(vArray[1]) != -1){
     return true;
   }
   return false;
 };   

// Assert that a specified image has actually loaded
// The Safari workaround results in additional requests
// for broken images (in Safari only) but works reliably
windmill.controller.asserts.assertImageLoaded = function (param_object) {
  var img = windmill.controller._lookupDispatch(param_object);
  if (!img || img.tagName != 'IMG') {
    return false;
  }
  var comp = img.complete;
  var ret = null; // Return value

  // Workaround for Safari -- it only supports the
  // complete attrib on script-created images
  if (typeof comp == 'undefined') {
    test = new Image();
    // If the original image was successfully loaded,
    // src for new one should be pulled from cache
    test.src = img.src;
    comp = test.complete;
  }

  // Check the complete attrib. Note the strict
  // equality check -- we don't want undefined, null, etc.<commit_msg>Fixing a bug so that you can test a form element if its disabled<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.
*/

windmill.controller.asserts.assertRegistry = {
  'assertTrue': {
    expr: function (a) {
      if (typeof a != 'boolean') {
        throw('Bad argument to assertTrue.');
      }
      return a === true;
    },
    errMsg: 'expected true but was false.'
  },

  'assertFalse': {
    expr: function (a) {
      if (typeof a != 'boolean') {
        throw('Bad argument to assertFalse.');
      }
      return a === false;
    },
    errMsg: 'expected false but was true.'
  },

  'assertEquals': {
    expr: function (a, b) { return a === b; },
    errMsg: 'expected $1 but was $2.'
  },

  'assertNotEquals': {
    expr: function (a, b) { return a !== b; },
    errMsg: 'expected one of the two values not to be $1.'
  },

  'assertNull': {
    expr: function (a) { return a === null; },
    errMsg: 'expected to be null but was $1.'
  },

  'assertNotNull': {
    expr: function (a) { return a !== null; },
    errMsg: 'expected not to be null but was null.'
  },

  'assertUndefined': {
    expr: function (a) { return typeof a == 'undefined'; },
    errMsg: 'expected to be undefined but was $1.'
  },

  'assertNotUndefined': {
    expr: function (a) { return typeof a != 'undefined'; },
    errMsg: 'expected not to be undefined but was undefined.'
  },

  'assertNaN': {
    expr: function (a) { return typeof a == 'undefined'; },
    errMsg: 'expected to be undefined but was $1.'
  },

  'assertNotNaN': {
    expr: function (a) { return typeof a != 'undefined'; },
    errMsg: 'expected not to be undefined but was undefined.'
  },

  'assertEvaluatesToTrue': {
    expr: function (a) { return !!a; },
    errMsg: 'value of $1 does not evaluate to true.'
  },

  'assertEvaluatesToFalse': {
    expr: function (a) { return !a; },
    errMsg: 'value of $1 does not evaluate to false.'
  },

  'assertContains': {
    expr: function (a, b) {
      if (typeof a != 'string' || typeof b != 'string') {
        throw('Bad argument to assertContains.');
      }
      return (a.indexOf(b) > -1);
    },
    errMsg: 'value of $1 does not contain $2.'
  }
};

//Currently only does one level below the provided div
//To make it more thorough it needs recursion to be implemented later
windmill.controller.asserts.assertText = function (param_object) { 
    
    var n = windmill.controller._lookupDispatch(param_object);
    var validator = param_object.validator;
  try{
   if (n.innerHTML.indexOf(validator) != -1){
     return true;
   }
   if (n.hasChildNodes()){
      for(var m = n.firstChild; m != null; m = m.nextSibling) {       
       if (m.innerHTML.indexOf(validator) != -1){
        return true;
       }
       if (m.value.indexOf(validator) != -1){
         return true;  
       }
      }
    }
  }
  catch(error){
   return false;
  } 
   return false;
}; 
 
   //Assert that a specified node exists
windmill.controller.asserts.assertNode = function (param_object) { 

   var element = windmill.controller._lookupDispatch(param_object);
   if (!element){
    return false;
   }
    return true;
 };   

//Assert that a form element contains the expected value
windmill.controller.asserts.assertValue = function (param_object) { 
   var n = windmill.controller._lookupDispatch(param_object);
   var validator = param_object.validator;
 
   if (n.value.indexOf(validator) != -1){
    return true;
   }
   return false;
 };

//Assert that a provided value is selected in a select element
windmill.controller.asserts.assertSelected = function (param_object) { 
   var n = windmill.controller._lookupDispatch(param_object);
   var validator = param_object.validator;
 
   if (n.options[n.selectedIndex].value == validator){
    return true;
   }
   return false;
 };
 
//Assert that a provided value is selected in a select element
windmill.controller.asserts.assertChecked = function (param_object) { 
   var n = windmill.controller._lookupDispatch(param_object);
   var validator = param_object.validator;
 
   if (n.checked == true){
    return true;
   }
   return false;
 };

// Assert that a an element's property is a particular
// value
windmill.controller.asserts.assertProperty = function (param_object) { 
   var element = windmill.controller._lookupDispatch(param_object);
   if (!element){
    return false;
   }
   var vArray = param_object.validator.split('|');
   var value = eval ('element.' + vArray[0]+';');
   var res = false;
   try {
     if (value.indexOf(vArray[1]) != -1){
       res = true;
     }
    }
    catch(err){  
    }
    if (String(value) == String(vArray[1])) {
     res = true;
    }
   return res;
 };   

// Assert that a specified image has actually loaded
// The Safari workaround results in additional requests
// for broken images (in Safari only) but works reliably
windmill.controller.asserts.assertImageLoaded = function (param_object) {
  var img = windmill.controller._lookupDispatch(param_object);
  if (!img || img.tagName != 'IMG') {
    return false;
  }
  var comp = img.complete;
  var ret = null; // Return value

  // Workaround for Safari -- it only supports the
  // complete attrib on script-created images
  if (typeof comp == 'undefined') {
    test = new Image();
    // If the original image was successfully loaded,
    // src for new one should be pulled from cache
    test.src = img.src;
    comp = test.complete;
  }

  // Check the complete attrib. Note the strict
  // equality check -- we don't want undefined, null, etc.
{'fraction_non_alphanumeric': 0.12117922164690162, 'fraction_numerical': 0.004426256889928178, 'mean_word_length': 2.921087098886706, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5266453', 'n_tokens_mistral': 3581, 'n_tokens_neox': 3508, 'n_words': 1232}