<commit_before><!DOCTYPE html>
<title>inject_test.html</title>
<script src="../../webdriver-bootstrap.js"></script>
<script>
  goog.require('bot.inject');
  goog.require('bot.userAgent');
  goog.require('core.inject');
  goog.require('goog.array');
  goog.require('goog.dom');
  goog.require('goog.json');
  goog.require('goog.testing.jsunit');
  goog.require('goog.testing.ExpectedFailures');
</script>
<body>
<script>
  goog.global.MY_GLOBAL_CONSTANT = 123;

  var expectedFailures;

  function setUp() {
    expectedFailures = new goog.testing.ExpectedFailures();
  }

  function tearDown() {
    expectedFailures.handleTearDown();

    // Force the cache to be recreated on the next access. We cannot
    // "delete" it here because IE complains about it being an unsupported
    // operation.
    document[bot.inject.cache.CACHE_KEY_] = null;

    // Delete our test frame, if it was created.
    var testFrame = goog.dom.$('test-frame');
    if (testFrame) {
      goog.dom.removeNode(testFrame);
    }
  }

  function createTestFrame() {
    var testFrame = goog.dom.createElement('iframe');
    testFrame.id = 'test-frame';
    testFrame.src = 'javascript:void(0);';
    document.body.appendChild(testFrame);
    return testFrame;
  }

  function executeScript(script, opt_window, var_args) {
    var result = core.inject.executeScript({
      'script': script,
      'args': goog.array.slice(arguments, 2)
    }, opt_window);

    var parsedResult = goog.json.parse(result);
    assertEquals('Script failed: ' + result,
        bot.ErrorCode.SUCCESS, parsedResult['status']);
    return parsedResult['value'];
  }

  function testExecutesScriptInThisWindowByDefault() {
    assertEquals('Returned the wrong value', goog.global.MY_GLOBAL_CONSTANT,
        executeScript('return MY_GLOBAL_CONSTANT'));
  }

  function testCanExecuteScriptsInTheContextOfAnotherWindow() {
    var testFrame = createTestFrame();
    var testFrameWin = goog.dom.getFrameContentWindow(testFrame);
    expectedFailures.expectFailureFor(goog.userAgent.IE && !bot.userAction.isVersion(9),
        'Fails in IE before 9 - issue 3723');
    expectedFailures.run(function() {
      assertEquals('undefined',
          executeScript('return typeof MY_GLOBAL_CONSTANT', testFrameWin));
    });
  }

  function testUpdatesElementReferencesToBeSeleneseLocators() {
    var el = executeScript('return document.body');
    assertNotNull(el);
    assertEquals('object', goog.typeOf(el));<commit_msg>DanielWagnerHall: Someone can't type.  That someone may be me.<commit_after><!DOCTYPE html>
<title>inject_test.html</title>
<script src="../../webdriver-bootstrap.js"></script>
<script>
  goog.require('bot.inject');
  goog.require('bot.userAgent');
  goog.require('core.inject');
  goog.require('goog.array');
  goog.require('goog.dom');
  goog.require('goog.json');
  goog.require('goog.testing.jsunit');
  goog.require('goog.testing.ExpectedFailures');
</script>
<body>
<script>
  goog.global.MY_GLOBAL_CONSTANT = 123;

  var expectedFailures;

  function setUp() {
    expectedFailures = new goog.testing.ExpectedFailures();
  }

  function tearDown() {
    expectedFailures.handleTearDown();

    // Force the cache to be recreated on the next access. We cannot
    // "delete" it here because IE complains about it being an unsupported
    // operation.
    document[bot.inject.cache.CACHE_KEY_] = null;

    // Delete our test frame, if it was created.
    var testFrame = goog.dom.$('test-frame');
    if (testFrame) {
      goog.dom.removeNode(testFrame);
    }
  }

  function createTestFrame() {
    var testFrame = goog.dom.createElement('iframe');
    testFrame.id = 'test-frame';
    testFrame.src = 'javascript:void(0);';
    document.body.appendChild(testFrame);
    return testFrame;
  }

  function executeScript(script, opt_window, var_args) {
    var result = core.inject.executeScript({
      'script': script,
      'args': goog.array.slice(arguments, 2)
    }, opt_window);

    var parsedResult = goog.json.parse(result);
    assertEquals('Script failed: ' + result,
        bot.ErrorCode.SUCCESS, parsedResult['status']);
    return parsedResult['value'];
  }

  function testExecutesScriptInThisWindowByDefault() {
    assertEquals('Returned the wrong value', goog.global.MY_GLOBAL_CONSTANT,
        executeScript('return MY_GLOBAL_CONSTANT'));
  }

  function testCanExecuteScriptsInTheContextOfAnotherWindow() {
    var testFrame = createTestFrame();
    var testFrameWin = goog.dom.getFrameContentWindow(testFrame);
    expectedFailures.expectFailureFor(goog.userAgent.IE && !bot.userAgent.isVersion(9),
        'Fails in IE before 9 - issue 3723');
    expectedFailures.run(function() {
      assertEquals('undefined',
          executeScript('return typeof MY_GLOBAL_CONSTANT', testFrameWin));
    });
  }

  function testUpdatesElementReferencesToBeSeleneseLocators() {
    var el = executeScript('return document.body');
    assertNotNull(el);
    assertEquals('object', goog.typeOf(el));
{'fraction_non_alphanumeric': 0.13421474358974358, 'fraction_numerical': 0.004407051282051282, 'mean_word_length': 3.9830339321357284, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6712058', 'n_tokens_mistral': 1527, 'n_tokens_neox': 1469, 'n_words': 299}