<commit_before>/*
 Copyright 2007-2009 WebDriver committers
 Copyright 2007-2009 Google Inc.
 Portions copyright 2011 Software Freedom Conservatory

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


function FirefoxDriver(server, enableNativeEvents, win) {
  this.server = server;
  this.enableNativeEvents = enableNativeEvents;
  this.window = win;

  // Default to a two second timeout.
  this.alertTimeout = 2000;

  this.currentX = 0;
  this.currentY = 0;

  // We do this here to work around an issue in the import function:
  // https://groups.google.com/group/mozilla.dev.apps.firefox/browse_thread/thread/e178d41afa2ccc87?hl=en&pli=1#
  var atoms = {};
  Components.utils.import('resource://fxdriver/modules/atoms.js', atoms);
  
  // This really shouldn't be here, but the firefoxdriver isn't compiled with closure, so the atoms
  // aren't exported into global scope
  FirefoxDriver.prototype.dismissAlert.preconditions =
      [ function() { atoms.fxdriver.preconditions.alertPresent(this) } ];
  FirefoxDriver.prototype.acceptAlert.preconditions =
      [ function() { atoms.fxdriver.preconditions.alertPresent(this) } ];
  FirefoxDriver.prototype.getAlertText.preconditions =
      [ function() { atoms.fxdriver.preconditions.alertPresent(this) } ];
  FirefoxDriver.prototype.setAlertValue.preconditions =
      [ function() { atoms.fxdriver.preconditions.alertPresent(this) } ];


  var utils = {};
  Components.utils.import('resource://fxdriver/modules/utils.js', utils);

  goog.userAgent.GECKO = true;

  FirefoxDriver.listenerScript = Utils.loadUrl("resource://fxdriver/evaluate.js");

  this.jsTimer = new fxdriver.Timer();
  this.mouse = Utils.newInstance("@googlecode.com/webdriver/syntheticmouse;1", "wdIMouse");
  // Current state of modifier keys (for synthenized events).
  this.modifierKeysState = undefined;
}


FirefoxDriver.prototype.__defineGetter__("id", function() {
  if (!this.id_) {
    this.id_ = this.server.getNextId();
  }

  return this.id_;
});


FirefoxDriver.prototype.getCurrentWindowHandle = function(respond) {
  respond.value = this.id;
  respond.send();
};


FirefoxDriver.prototype.get = function(respond, parameters) {
  var url = parameters.url;
  // Check to see if the given url is the same as the current one, but
  // with a different anchor tag.
  var current = respond.session.getWindow().location;
  var ioService =
      fxdriver.moz.getService("@mozilla.org/network/io-service;1", "nsIIOService");
  var currentUri = ioService.newURI(current, "", null);
  var futureUri = ioService.newURI(url, "", currentUri);

  var loadEventExpected = true;

  if (currentUri && futureUri &&
      currentUri.prePath == futureUri.prePath &&
      currentUri.filePath == futureUri.filePath) {
    // Looks like we're at the same url with a ref
    // Being clever and checking the ref was causing me headaches.
    // Brute force for now
    loadEventExpected = futureUri.path.indexOf("#") == -1;
  }

  if (loadEventExpected) {
    new WebLoadingListener(respond.session.getBrowser(), function() {
      var responseText = "";
      // Focus on the top window.
      respond.session.setWindow(respond.session.getBrowser().contentWindow);
      respond.value = responseText;
      respond.send();
    });
  }

  respond.session.getBrowser().loadURI(url);

  if (!loadEventExpected) {
    fxdriver.Logger.dumpn("No load event expected");
    respond.send();
  }
};


FirefoxDriver.prototype.close = function(respond) {
  // Grab all the references we'll need. Once we call close all this might go away<commit_msg>SimonStewart: Passing the current window through to the webloadinglistener on a get<commit_after>/*
 Copyright 2007-2009 WebDriver committers
 Copyright 2007-2009 Google Inc.
 Portions copyright 2011 Software Freedom Conservatory

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


function FirefoxDriver(server, enableNativeEvents, win) {
  this.server = server;
  this.enableNativeEvents = enableNativeEvents;
  this.window = win;

  // Default to a two second timeout.
  this.alertTimeout = 2000;

  this.currentX = 0;
  this.currentY = 0;

  // We do this here to work around an issue in the import function:
  // https://groups.google.com/group/mozilla.dev.apps.firefox/browse_thread/thread/e178d41afa2ccc87?hl=en&pli=1#
  var atoms = {};
  Components.utils.import('resource://fxdriver/modules/atoms.js', atoms);
  
  // This really shouldn't be here, but the firefoxdriver isn't compiled with closure, so the atoms
  // aren't exported into global scope
  FirefoxDriver.prototype.dismissAlert.preconditions =
      [ function() { atoms.fxdriver.preconditions.alertPresent(this) } ];
  FirefoxDriver.prototype.acceptAlert.preconditions =
      [ function() { atoms.fxdriver.preconditions.alertPresent(this) } ];
  FirefoxDriver.prototype.getAlertText.preconditions =
      [ function() { atoms.fxdriver.preconditions.alertPresent(this) } ];
  FirefoxDriver.prototype.setAlertValue.preconditions =
      [ function() { atoms.fxdriver.preconditions.alertPresent(this) } ];


  var utils = {};
  Components.utils.import('resource://fxdriver/modules/utils.js', utils);

  goog.userAgent.GECKO = true;

  FirefoxDriver.listenerScript = Utils.loadUrl("resource://fxdriver/evaluate.js");

  this.jsTimer = new fxdriver.Timer();
  this.mouse = Utils.newInstance("@googlecode.com/webdriver/syntheticmouse;1", "wdIMouse");
  // Current state of modifier keys (for synthenized events).
  this.modifierKeysState = undefined;
}


FirefoxDriver.prototype.__defineGetter__("id", function() {
  if (!this.id_) {
    this.id_ = this.server.getNextId();
  }

  return this.id_;
});


FirefoxDriver.prototype.getCurrentWindowHandle = function(respond) {
  respond.value = this.id;
  respond.send();
};


FirefoxDriver.prototype.get = function(respond, parameters) {
  var url = parameters.url;
  // Check to see if the given url is the same as the current one, but
  // with a different anchor tag.
  var current = respond.session.getWindow().location;
  var ioService =
      fxdriver.moz.getService("@mozilla.org/network/io-service;1", "nsIIOService");
  var currentUri = ioService.newURI(current, "", null);
  var futureUri = ioService.newURI(url, "", currentUri);

  var loadEventExpected = true;

  if (currentUri && futureUri &&
      currentUri.prePath == futureUri.prePath &&
      currentUri.filePath == futureUri.filePath) {
    // Looks like we're at the same url with a ref
    // Being clever and checking the ref was causing me headaches.
    // Brute force for now
    loadEventExpected = futureUri.path.indexOf("#") == -1;
  }

  if (loadEventExpected) {
    new WebLoadingListener(respond.session.getBrowser(), function() {
      var responseText = "";
      // Focus on the top window.
      respond.session.setWindow(respond.session.getBrowser().contentWindow);
      respond.value = responseText;
      respond.send();
    }, respond.session.getWindow());
  }

  respond.session.getBrowser().loadURI(url);

  if (!loadEventExpected) {
    fxdriver.Logger.dumpn("No load event expected");
    respond.send();
  }
};


FirefoxDriver.prototype.close = function(respond) {
  // Grab all the references we'll need. Once we call close all this might go away
{'fraction_non_alphanumeric': 0.11242820481486007, 'fraction_numerical': 0.010265183917878529, 'mean_word_length': 3.9153153153153153, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '1563821', 'n_tokens_mistral': 2442, 'n_tokens_neox': 2322, 'n_words': 653}