Bug 1014609 - Part 2: Remove jquery methods in mozmill test. r=mkmelin
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Sat, 06 Dec 2014 15:40:00 +0100
changeset 22544 90852d005f772fdb21ba4090a9fd0f8df453efaf
parent 22543 6e421c79d586fb1aef003c91c67fe2b9de38a76f
child 22545 abbb61a1b23f6f67c9d2bd206393819751e87639
push id1420
push usermbanner@mozilla.com
push dateMon, 29 Jun 2015 20:47:24 +0000
treeherdercomm-beta@b3db00bb24e8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs1014609
Bug 1014609 - Part 2: Remove jquery methods in mozmill test. r=mkmelin
mail/test/mozmill/newmailaccount/test-newmailaccount.js
--- a/mail/test/mozmill/newmailaccount/test-newmailaccount.js
+++ b/mail/test/mozmill/newmailaccount/test-newmailaccount.js
@@ -171,50 +171,48 @@ function subtest_get_an_account(w) {
   // Make sure we don't have bar as the default engine yet.
   let engine = Services.search.getEngineByName("bar");
   assert_not_equals(engine, Services.search.currentEngine);
 
   wait_for_provider_list_loaded(w);
   wait_for_search_ready(w);
 
   // Fill in some data
-  let $ = w.window.$;
   type_in_search_name(w, "Green Llama");
 
-  $("#searchSubmit").click();
+  w.click(w.eid("searchSubmit"));
   wait_for_search_results(w);
 
   // Click on the first address. This reveals the button with the price.
-  $(".address:first").click();
-  mc.waitFor(function () $("button.create:visible").length > 0);
+  let address = w.window.document.querySelector(".address:first-child");
+  w.click(new elib.Elem(address));
+  w.waitFor(function () w.window.document.querySelectorAll("button.create:not([hidden=true])").length > 0);
 
   // Pick the email address green@example.com
   plan_for_content_tab_load();
 
   // Clicking this button should close the modal dialog.
-  $('button.create[address="green@example.com"]').click();
+  let button = w.window.document.querySelector('button.create[address="green@example.com"]');
+  w.click(new elib.Elem(button));
 }
 
 /**
  * This is a subtest for test_get_an_account, and runs the second time the
  * account provisioner window is opened.
  */
 function subtest_get_an_account_part_2(w) {
-  // Re-get the new window
-  let $ = w.window.$;
-
   // An account should have been added.
   assert_equals(nAccounts(), gNumAccounts + 1);
 
   // We want this provider to be our default search engine.
   wait_for_element_invisible(w, "window");
   wait_for_element_visible(w, "successful_account");
 
   // Make sure the search engine is checked
-  assert_true($("#search_engine_check").is(":checked"));
+  assert_true(w.e("search_engine_check").checked);
 
   // Then click "Finish"
   mc.click(w.eid("closeWindow"));
 }
 
 /**
  * Runs test_get_an_account again, but this time, closes and restores the
  * order form tab before submitting it.
@@ -296,18 +294,20 @@ function test_can_display_providers_in_o
  * simply clicks on the div for displaying account providers in other
  * languages, and ensures that those other providers become visible.
  */
 function subtest_can_display_providers_in_other_languages(w) {
   wait_for_provider_list_loaded(w);
 
   // Check that the "Other languages" div is hidden
   wait_for_element_visible(w, "otherLangDesc");
-  let otherLanguages = w.window.$(".otherLanguage");
-  assert_false(otherLanguages.is(":visible"));
+  let otherLanguages = w.window.document.querySelectorAll(".otherLanguage");
+  for (let element of otherLanguages) {
+    assert_element_visible(new elib.Elem(element));
+  }
   // Click on the "Other languages" div
   mc.click(w.eid("otherLangDesc"));
 
   wait_for_element_invisible(w, "otherLangDesc");
 }
 
 /**
  * Spawn the provisioner window by clicking on the menuitem,
@@ -387,39 +387,38 @@ function test_persist_name_in_search_fie
 /**
  * Subtest used by test_persist_name_in_search_field.  This function simply
  * puts a name into the search field, starts a search, and then dismisses
  * the window.
  */
 function subtest_persist_name_in_search_field(w) {
   wait_for_provider_list_loaded(w);
   wait_for_search_ready(w);
-  let $ = w.window.$;
 
   // Type a name into the search field
   type_in_search_name(w, NAME);
 
   // Do a search
-  $("#searchSubmit").click();
+  w.click(w.eid("searchSubmit"));
   wait_for_search_results(w);
 
   plan_for_window_close(w);
   // Click on the "I think I'll configure my account later" button.
   mc.click(new elib.Elem(w.window.document.querySelector(".close")));
   wait_for_window_close();
 }
 
 /**
  * Subtest used by test_persist_name_in_search_field, the second time that
  * the account provisioner window is opened.  This function simply checks to
  * ensure that the name inserted in subtest_persist_name_in_search_field has
  * indeed persisted.
  */
 function subtest_persist_name_in_search_field_part_2(w) {
-  mc.waitFor(function () w.window.$("#name").val() == NAME);
+  mc.waitFor(function () w.e("name").value == NAME);
 }
 
 /**
  * Test that names with HTML characters are escaped properly when displayed
  * back to the user.
  */
 function test_html_characters_and_ampersands() {
   plan_for_modal_dialog("AccountCreation",
@@ -431,29 +430,28 @@ function test_html_characters_and_ampers
 /**
  * Subtest used by test_html_characters_and_ampersands.  This function puts
  * a name with HTML tags into the search input, does a search, and ensures
  * that the rendered name has escaped the HTML tags properly.
  */
 function subtest_html_characters_and_ampersands(w) {
   wait_for_provider_list_loaded(w);
   wait_for_search_ready(w);
-  let $ = w.window.$;
 
   // Type a name with some HTML tags and an ampersand in there
   // to see if we can trip up account provisioner.
   const CLEVER_STRING = "<i>Hey, I'm ''clever &\"\" smart!<!-- Ain't I a stinkah? --></i>";
   type_in_search_name(w, CLEVER_STRING);
 
   // Do the search.
-  $("#searchSubmit").click();
+  w.click(w.eid("searchSubmit"));
 
   wait_for_search_results(w);
 
-  let displayedName = $("#FirstAndLastName").html();
+  let displayedName = w.e("FirstAndLastName").innerHTML;
 
   assert_not_equals(CLEVER_STRING, displayedName);
   // & should have been replaced with &amp;, and the
   // greater than / less than characters with &gt; and
   // &lt; respectively.
   assert_true(displayedName.contains("&amp;"),
               "Should have eliminated ampersands");
   assert_true(displayedName.contains("&gt;"),
@@ -475,58 +473,60 @@ function test_show_tos_privacy_links_for
 
 /**
  * Subtest used by test_show_tos_privacy_links_for_selected_providers.  This
  * function selects and deselects a series of providers, and ensures that the
  * appropriate terms of service and privacy links are shown.
  */
 function subtest_show_tos_privacy_links_for_selected_providers(w) {
   wait_for_provider_list_loaded(w);
-  let $ = w.window.$;
 
   // We should be showing the TOS and Privacy links for the selected
   // providers immediately after the providers have been loaded.
   // Those providers should be "foo" and "bar".
   assert_links_shown(w, ['http://www.example.com/foo-tos',
                          'http://www.example.com/foo-privacy',
                          'http://www.example.com/bar-tos',
                          'http://www.example.com/bar-privacy',]);
 
   assert_links_not_shown(w, ['http://www.example.com/French-tos',
                              'http://www.example.com/French-privacy']);
 
   // Now click off one of those providers - we shouldn't be displaying
   // and links for that one now.
-  w.click(new elib.Elem($('input[type="checkbox"][value="foo"]')[0]));
+  let input = w.window.document.querySelector('input[type="checkbox"][value="foo"]');
+  w.click(new elib.Elem(input));
 
   assert_links_not_shown(w, ['http://www.example.com/foo-tos',
                              'http://www.example.com/foo-privacy',]);
 
   // Ensure that the "Other languages" div is visible
   wait_for_element_visible(w, "otherLangDesc");
   // Now show the providers from different locales...
   w.click(w.eid("otherLangDesc"));
   wait_for_element_invisible(w, "otherLangDesc");
 
   // And click on one of those providers...
-  w.click(new elib.Elem($('input[type="checkbox"][value="French"]')[0]));
+  input = w.window.document.querySelector('input[type="checkbox"][value="French"]');
+  w.click(new elib.Elem(input));
   // We should be showing the French TOS / Privacy links, along
   // with those from the bar provider.
   assert_links_shown(w, ['http://www.example.com/French-tos',
                          'http://www.example.com/French-privacy',
                          'http://www.example.com/bar-tos',
                          'http://www.example.com/bar-privacy']);
 
   // The foo provider should still have it's links hidden.
   assert_links_not_shown(w, ['http://www.example.com/foo-tos',
                              'http://www.example.com/foo-privacy',]);
 
   // Click on the German provider.  It's links should now be
   // shown, along with the French and bar providers.
-  w.click(new elib.Elem($('input[type="checkbox"][value="German"]')[0]));
+  input = w.window.document.querySelector('input[type="checkbox"][value="German"]');
+  w.click(new elib.Elem(input));
   assert_links_shown(w, ['http://www.example.com/French-tos',
                          'http://www.example.com/French-privacy',
                          'http://www.example.com/bar-tos',
                          'http://www.example.com/bar-privacy',
                          'http://www.example.com/German-tos',
                          'http://www.example.com/German-privacy']);
 
   // And the foo links should still be hidden.
@@ -552,24 +552,23 @@ function test_shows_error_on_bad_suggest
 /**
  * Subtest for test_shows_error_on_bad_suggest_from_name.  This function does
  * a search, and then ensures that an error is displayed, since we got back
  * garbage from the server.
  */
 function subtest_shows_error_on_bad_suggest_from_name(w) {
   wait_for_provider_list_loaded(w);
   wait_for_search_ready(w);
-  let $ = w.window.$;
 
   type_in_search_name(w, "Boston Low");
 
   // Do the search.
-  $("#searchSubmit").click();
+  w.click(w.eid("searchSubmit"));
 
-  mc.waitFor(function () $("#notifications .error").is(":visible"));
+  mc.waitFor(function () !w.window.document.querySelector("#notifications > .error").hidden);
 }
 
 /**
  * Test that if we get an empty result from the server after a search, that
  * we show an error message.
  */
 function test_shows_error_on_empty_suggest_from_name() {
   let original = Services.prefs.getCharPref(kSuggestFromNamePref);
@@ -584,24 +583,23 @@ function test_shows_error_on_empty_sugge
 /**
  * Subtest for test_shows_error_on_empty_suggest_from_name. This function does
  * a search, and then ensures that an error is displayed, since we got back
  * an empty result from the server.
  */
 function subtest_shows_error_on_empty_suggest_from_name(w) {
   wait_for_provider_list_loaded(w);
   wait_for_search_ready(w);
-  let $ = w.window.$;
 
   type_in_search_name(w, "Maggie Robbins");
 
   // Do the search.
-  $("#searchSubmit").click();
+  w.click(w.eid("searchSubmit"));
 
-  mc.waitFor(function () $("#notifications .error").is(":visible"));
+  mc.waitFor(function () !w.window.document.querySelector("#notifications > .error").hidden);
 }
 
 /**
  * Tests that if a provider returns broken or erroneous XML back
  * to the user after account registration, that we log the error
  * in the error console.
  */
 function test_throws_console_error_on_corrupt_XML() {
@@ -671,22 +669,23 @@ function test_incomplete_provider_not_di
  * Subtest for test_incomplete_provider_not_displayed. This function just
  * ensures that the provider that didn't include all of the required fields
  * is not displayed.
  */
 function subtest_incomplete_provider_not_displayed(w) {
   wait_for_provider_list_loaded(w);
   // Make sure that the provider that didn't include the required fields
   // is not displayed.
-  let $ = w.window.$;
-  assert_equals(0, $('input[type="checkbox"][value="corrupt"]').length,
+  let input = w.window.document.querySelectorAll('input[type="checkbox"][value="corrupt"]');
+  assert_equals(0, input.length,
                 "The Corrupt provider should not have been displayed");
 
   // And check to ensure that at least one other provider is displayed
-  assert_equals(1, $('input[type="checkbox"][value="foo"]').length,
+  input = w.window.document.querySelectorAll('input[type="checkbox"][value="foo"]');
+  assert_equals(1, input.length,
                 "The foo provider should have been displayed");
 }
 
 /**
  * Test that if the search text input is empty, or if no providers are selected,
  * that the search submit button is disabled.
  */
 function test_search_button_disabled_cases() {
@@ -700,62 +699,68 @@ function test_search_button_disabled_cas
  * Subtest for test_search_button_disabled_cases.  This function ensures that
  * if the search input is empty, or if no providers are selected, then the
  * search submit button is disabled.  If, on the other hand some providers
  * are selected AND some text is in the search input, then the search submit
  * button should be enabled.
  */
 function subtest_search_button_disabled_cases(w) {
   wait_for_provider_list_loaded(w);
-  let $ = w.window.$;
-  let searchInput = new elib.Elem($("#name")[0]);
+  let searchInput = w.eid("name");
   // Case 1:  Search input empty, some providers selected.
 
   // Empty any strings in the search input.  Select all of the input with
   // Ctrl-A, and then hit backspace.
   searchInput.getNode().focus();
   w.keypress(null, 'a', {accelKey: true});
   w.keypress(null, 'VK_BACK_SPACE', {});
 
   // Make sure at least one provider is checked
-  $('input[type="checkbox"]:checked').click();
-  $('input[type="checkbox"][value="foo"]').click();
+  let input = w.window.document.querySelector('input[type="checkbox"]:checked');
+  w.click(new elib.Elem(input));
+  input = w.window.document.querySelector('input[type="checkbox"][value="foo"]');
+  w.click(new elib.Elem(input));
 
   // The search submit button should become disabled
   wait_for_element_enabled(w, w.e("searchSubmit"), false);
 
   // Case 2:  Search input has text, some providers selected
 
   // Put something into the search input
   type_in_search_name(w, "Dexter Morgan");
 
   // We already have at least one provider checked from the last case, so
   // the search submit button should become enabled
   wait_for_element_enabled(w, w.e("searchSubmit"), true);
 
   // Case 3:  Search input has text, no providers selected
   // Make sure no provider checkboxes are checked.
-  $('input[type="checkbox"]:checked').click();
+  inputs = w.window.document.querySelectorAll('input[type="checkbox"]:checked');
+  for (input of inputs) {
+    mc.click(new elib.Elem(input));
+  }
 
   // The search submit button should now be disabled
   wait_for_element_enabled(w, w.e("searchSubmit"), false);
 
   // We'll turn on a single provider now to enable the search button,
   // so we can ensure that it actually *becomes* disabled for the next
   // case.
-  $('input[type="checkbox"][value="foo"]').click();
+  input = w.window.document.querySelector('input[type="checkbox"][value="foo"]');
+  w.click(new elib.Elem(input));
   wait_for_element_enabled(w, w.e("searchSubmit"), true);
 
   // Case 4:  Search input has no text, and no providers are
   // selected.
 
   // Clear out the search input
   w.keypress(null, 'a', {accelKey: true});
   w.keypress(null, 'VK_BACK_SPACE', {});
-  $('input[type="checkbox"]:checked').click();
+  input = w.window.document.querySelector('input[type="checkbox"]:checked');
+  w.click(new elib.Elem(input));
 
   wait_for_element_enabled(w, w.e("searchSubmit"), false);
 }
 
 /**
  * Tests that when we pref off the Account Provisioner, the menuitem for it
  * becomes hidden, and the button to switch to it from the Existing Account
  * wizard also becomes hidden.  Note that this doesn't test explicitly
@@ -889,31 +894,33 @@ function get_to_order_form(aAddress) {
 /**
  * Fills in the Account Provisioner dialog to get us to the order form.
  */
 function sub_get_to_order_form(aController, aAddress) {
   wait_for_provider_list_loaded(aController);
   wait_for_search_ready(aController);
 
   // Fill in some data
-  let $ = aController.window.$;
   type_in_search_name(aController, "Joe Nobody");
 
-  $("#searchSubmit").click();
+  aController.click(aController.eid("searchSubmit"));
   wait_for_search_results(aController);
 
   // Click on the first address. This reveals the button with the price.
-  $(".address:first").click();
-  mc.waitFor(function () $("button.create:visible").length > 0);
+  let address = aController.window.document.querySelector(".address:first-child");
+  aController.click(new elib.Elem(address));
+  aController.waitFor(function () aController.window.document.querySelectorAll("button.create:not([hidden=true])").length > 0);
 
   // Pick the email address green@example.com
   plan_for_content_tab_load();
 
   // Clicking this button should close the modal dialog.
-  $('button.create[address="' + aAddress + '"]').click();
+  let button = aController.window.document.querySelector('button.create[address="' + aAddress + '"]');
+  // mc.click() causes a failure here so click() is used for now.
+  button.click();
 }
 
 /**
  * Helper function to be passed to plan_for_modal_dialog that closes the
  * Account Provisioner dialog immediately.
  */
 function close_dialog_immediately(aController) {
   plan_for_window_close(aController);
@@ -1267,33 +1274,49 @@ function test_per_address_prices() {
 /**
  * Subtest used by test_html_characters_and_ampersands.  This function puts
  * a name with HTML tags into the search input, does a search, and ensures
  * that the rendered name has escaped the HTML tags properly.
  */
 function subtest_per_address_prices(w) {
   wait_for_provider_list_loaded(w);
   wait_for_search_ready(w);
-  let $ = w.window.$;
 
   // Type a name with some HTML tags and an ampersand in there
   // to see if we can trip up account provisioner.
   type_in_search_name(w, "Joanna Finkelstein");
 
   // Do the search.
-  $("#searchSubmit").click();
+  mc.click(w.eid("searchSubmit"));
 
   wait_for_search_results(w);
 
   let prices = ["$20-$0 a year", "Free", "$20.00 a year"];
 
   // Check that the multi-provider has the default price.
-  assert_true($(".provider:contains('multi') ~ .price").text(), prices[0].slice(0, 6));
+  let providers = w.window.document.querySelectorAll('.provider');
+  let price;
+  let multi;
+  for (let provider of providers) {
+    if (provider.innerHTML == "multi") {
+      multi = provider;
+      price = provider.parentNode.querySelector('.price');
+      break;
+    }
+  }
+  assert_equals(price.innerHTML, prices[0].slice(0, 6));
 
   // Click on the multi provider. This reveals the buttons with the prices.
-  $(".provider:contains('multi')").click();
-  mc.waitFor(function () $("button.create:visible").length > 0);
+  mc.click(new elib.Elem(multi));
+  mc.waitFor(function () w.window.document.querySelectorAll("button.create:not([hidden=true])").length > 0);
 
   // For each button, make sure it has the correct price.
-  $("button.create:visible").text(function(index, text){
-    assert_equals(text, prices[index]);
-  });
+  let buttons = w.window.document.querySelectorAll("button.create:not([hidden=true])");
+  let index = 0;
+  for (let button of buttons) {
+    // Emulate jquery's :visible selector
+    if (button.offsetWidth == 0 && button.offsetHeight == 0) {
+      continue;
+    }
+    assert_equals(button.innerHTML, prices[index]);
+    index++;
+  }
 }