<commit_before>require File.join(File.dirname(__FILE__), "test_helper")

class GmailTest < Test::Unit::TestCase
  include StartAndStopRevisorServer

  def setup
    create_client
    @first_session = @client.start_session(:tester1)
    @first_tab = @first_session.create_tab(:tester1)

    @second_session = @client.start_session(:tester2)
    @second_tab = @second_session.create_tab(:tester2)

    @jquery_injection_js = <<-EOJS
    var jquery_loaded = false;

    (function () {
      var head = document.getElementsByTagName('head')[0];
      var script = document.createElement('script');
      script.type = 'text/javascript';

      script.onload = function () {
        jquery_loaded = true;
        jQuery.noConflict();
      };

      script.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js';
      head.appendChild(script);
    }());

    EOJS
  end

  def teardown
    @first_session.stop
    @second_session.stop
  end

  def login(tab, login, password)
    tab.visit("http://gmail.com/")
    tab.wait_for_load

    tab.e(@jquery_injection_js)
    tab.wait_for_true_evaluation("jquery_loaded == true", 500, 4)

    tab.e <<-EOE
    jQuery('#Passwd').val('#{password}');
    jQuery('#Email').val('#{login}');
    jQuery('#signIn').click();
    EOE

    assert tab.wait_for_true_evaluation("window.location.hash == '#inbox'", 1000, 4)

    tab.e(@jquery_injection_js)
    tab.wait_for_true_evaluation("jquery_loaded == true", 500, 4)
  end

  def test_mail_delivery
    login(@first_tab, '<EMAIL>', 'revirevi')
    login(@second_tab, '<EMAIL>', 'revirevi')

    x = @first_tab.e("jQuery('#canvas_frame').contents().find('span[id=:rc]').offset().left")
    y = @first_tab.e("jQuery('#canvas_frame').contents().find('span[id=:rc]').offset().top")
    @first_tab.send_mouse_event("click", x + 10, y + 10, :button => "left", :type => "click")

    sleep(1)
    assert @first_tab.wait_for_true_evaluation("jQuery('#canvas_frame').contents().find('.CoUvaf b:contains(\\'Send\\')').length == 1", 1000, 4)

    subject = "Hello from Revisor #{rand(20000)}"
    @first_tab.e <<-EOE
    jQuery('#canvas_frame').contents().find("textarea[name=to]").val("<EMAIL>");
    jQuery('#canvas_frame').contents().find("input[name=subject]").val("#{subject}");
    jQuery('#canvas_frame').contents().find("iframe.editable").contents().find("body").html("Hello from Revisor");
    document.getElementById("canvas_frame").contentWindow.scroll(0, 100);
    EOE

    x = @first_tab.e("jQuery('#canvas_frame').contents().find('.CoUvaf b:contains(\\'Send\\')').offset().left")
    y = @first_tab.e("jQuery('#canvas_frame').contents().find('.CoUvaf b:contains(\\'Send\\')').offset().top")
    @first_tab.send_mouse_event("click", x + 10, y + 10 - 100, :button => "left", :type => "click")

    assert @second_tab.wait_for_true_evaluation("jQuery('#canvas_frame').contents().find('*:contains(\\'#{subject}\\')').length > 0", 5000, 10)
  end
end<commit_msg>small gmail test fix for low resolution<commit_after>require File.join(File.dirname(__FILE__), "test_helper")

class GmailTest < Test::Unit::TestCase
  include StartAndStopRevisorServer

  def setup
    create_client
    @first_session = @client.start_session(:tester1)
    @first_tab = @first_session.create_tab(:tester1)

    @second_session = @client.start_session(:tester2)
    @second_tab = @second_session.create_tab(:tester2)

    @jquery_injection_js = <<-EOJS
    var jquery_loaded = false;

    (function () {
      var head = document.getElementsByTagName('head')[0];
      var script = document.createElement('script');
      script.type = 'text/javascript';

      script.onload = function () {
        jquery_loaded = true;
        jQuery.noConflict();
      };

      script.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js';
      head.appendChild(script);
    }());

    EOJS
  end

  def teardown
    @first_session.stop
    @second_session.stop
  end

  def login(tab, login, password)
    tab.visit("http://gmail.com/")
    tab.wait_for_load

    tab.e(@jquery_injection_js)
    tab.wait_for_true_evaluation("jquery_loaded == true", 500, 4)

    tab.e <<-EOE
    jQuery('#Passwd').val('<PASSWORD>}');
    jQuery('#Email').val('#{login}');
    jQuery('#signIn').click();
    EOE

    assert tab.wait_for_true_evaluation("console.log(window.location); window.location.hash == '#inbox'", 6000, 10)

    tab.e(@jquery_injection_js)
    tab.wait_for_true_evaluation("jquery_loaded == true", 500, 4)
  end

  def test_mail_delivery
    login(@first_tab, '<EMAIL>', 'revirevi')
    login(@second_tab, '<EMAIL>', 'revirevi')

    x = @first_tab.e("jQuery('#canvas_frame').contents().find('span[id=:rc]').offset().left")
    y = @first_tab.e("jQuery('#canvas_frame').contents().find('span[id=:rc]').offset().top")
    @first_tab.send_mouse_event("click", x + 10, y + 10, :button => "left", :type => "click")

    sleep(1)
    assert @first_tab.wait_for_true_evaluation("jQuery('#canvas_frame').contents().find('.CoUvaf b:contains(\\'Send\\')').length == 1", 1000, 4)

    subject = "Hello from Revisor #{rand(20000)}"
    @first_tab.e <<-EOE
    jQuery('#canvas_frame').contents().find("textarea[name=to]").val("<EMAIL>");
    jQuery('#canvas_frame').contents().find("input[name=subject]").val("#{subject}");
    jQuery('#canvas_frame').contents().find("iframe.editable").contents().find("body").html("Hello from Revisor");
    document.getElementById("canvas_frame").contentWindow.scroll(0, 300);
    EOE

    x = @first_tab.e("jQuery('#canvas_frame').contents().find('.CoUvaf b:contains(\\'Send\\')').offset().left")
    y = @first_tab.e("jQuery('#canvas_frame').contents().find('.CoUvaf b:contains(\\'Send\\')').offset().top")
    @first_tab.send_mouse_event("click", x + 10, y + 10 - 300, :button => "left", :type => "click")

    assert @second_tab.wait_for_true_evaluation("jQuery('#canvas_frame').contents().find('*:contains(\\'#{subject}\\')').length > 0", 5000, 10)
  end
end
{'fraction_non_alphanumeric': 0.1959176844570855, 'fraction_numerical': 0.018571189559979922, 'mean_word_length': 4.309058614564831, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 20, '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': '2926913', 'n_tokens_mistral': 2126, 'n_tokens_neox': 1981, 'n_words': 290}