Bug 1347186 - (Part 2) Add mochitest-browser-chrome test for Form Autofill edit profile dialog. r?lchang draft
authorScott Wu <scottcwwu@gmail.com>
Fri, 17 Mar 2017 10:32:10 +0800
changeset 567616 01ec728bf79977438e228f62e1bcceac74e0c211
parent 567615 4c13d919317be55f824e009767c42c3f7ad1ea68
child 625712 9f440df719cfb94f43d3c4ba68fe57442ff5b409
push id55639
push userbmo:scwwu@mozilla.com
push dateTue, 25 Apr 2017 09:35:00 +0000
reviewerslchang
bugs1347186
milestone55.0a1
Bug 1347186 - (Part 2) Add mochitest-browser-chrome test for Form Autofill edit profile dialog. r?lchang MozReview-Commit-ID: 8HfdkfOkxcQ
browser/extensions/formautofill/test/browser/browser.ini
browser/extensions/formautofill/test/browser/browser_editProfileDialog.js
--- a/browser/extensions/formautofill/test/browser/browser.ini
+++ b/browser/extensions/formautofill/test/browser/browser.ini
@@ -1,6 +1,7 @@
 [DEFAULT]
 head = head.js
 
 [browser_check_installed.js]
+[browser_editProfileDialog.js]
 [browser_privacyPreferences.js]
 [browser_manageProfilesDialog.js]
new file mode 100644
--- /dev/null
+++ b/browser/extensions/formautofill/test/browser/browser_editProfileDialog.js
@@ -0,0 +1,87 @@
+"use strict";
+
+registerCleanupFunction(function* () {
+  let profiles = yield getProfiles();
+  if (profiles.length) {
+    yield removeProfiles(profiles.map(profile => profile.guid));
+  }
+});
+
+add_task(function* test_cancelEditProfileDialog() {
+  yield new Promise(resolve => {
+    let win = window.openDialog(EDIT_PROFILE_DIALOG_URL, null, null, null);
+    win.addEventListener("load", () => {
+      win.addEventListener("unload", () => {
+        ok(true, "Edit profile dialog is closed");
+        resolve();
+      }, {once: true});
+      win.document.querySelector("#cancel").click();
+    }, {once: true});
+  });
+});
+
+add_task(function* test_saveProfile() {
+  yield new Promise(resolve => {
+    let win = window.openDialog(EDIT_PROFILE_DIALOG_URL, null, null, null);
+    win.addEventListener("load", () => {
+      win.addEventListener("unload", () => {
+        ok(true, "Edit profile dialog is closed");
+        resolve();
+      }, {once: true});
+      EventUtils.synthesizeKey("VK_TAB", {}, win);
+      EventUtils.synthesizeKey(TEST_PROFILE_1.organization, {}, win);
+      EventUtils.synthesizeKey("VK_TAB", {}, win);
+      EventUtils.synthesizeKey(TEST_PROFILE_1["street-address"], {}, win);
+      EventUtils.synthesizeKey("VK_TAB", {}, win);
+      EventUtils.synthesizeKey(TEST_PROFILE_1["address-level2"], {}, win);
+      EventUtils.synthesizeKey("VK_TAB", {}, win);
+      EventUtils.synthesizeKey(TEST_PROFILE_1["address-level1"], {}, win);
+      EventUtils.synthesizeKey("VK_TAB", {}, win);
+      EventUtils.synthesizeKey(TEST_PROFILE_1["postal-code"], {}, win);
+      EventUtils.synthesizeKey("VK_TAB", {}, win);
+      EventUtils.synthesizeKey(TEST_PROFILE_1.country, {}, win);
+      EventUtils.synthesizeKey("VK_TAB", {}, win);
+      EventUtils.synthesizeKey(TEST_PROFILE_1.email, {}, win);
+      EventUtils.synthesizeKey("VK_TAB", {}, win);
+      EventUtils.synthesizeKey(TEST_PROFILE_1.tel, {}, win);
+      EventUtils.synthesizeKey("VK_TAB", {}, win);
+      EventUtils.synthesizeKey("VK_TAB", {}, win);
+      EventUtils.synthesizeKey("VK_RETURN", {}, win);
+    }, {once: true});
+  });
+  let profiles = yield getProfiles();
+
+  is(profiles.length, 1, "only one profile is in storage");
+  is(profiles[0].organization, TEST_PROFILE_1.organization, "match organization");
+  is(profiles[0]["street-address"], TEST_PROFILE_1["street-address"], "match street-address");
+  is(profiles[0]["address-level2"], TEST_PROFILE_1["address-level2"], "match address-level2");
+  is(profiles[0]["address-level1"], TEST_PROFILE_1["address-level1"], "match address-level1");
+  is(profiles[0]["postal-code"], TEST_PROFILE_1["postal-code"], "match postal-code");
+  is(profiles[0].country, TEST_PROFILE_1.country, "match country");
+  is(profiles[0].email, TEST_PROFILE_1.email, "match email");
+  is(profiles[0].tel, TEST_PROFILE_1.tel, "match tel");
+});
+
+add_task(function* test_editProfile() {
+  let profiles = yield getProfiles();
+  yield new Promise(resolve => {
+    let win = window.openDialog(EDIT_PROFILE_DIALOG_URL, null, null, profiles[0]);
+    win.addEventListener("load", () => {
+      win.addEventListener("unload", () => {
+        ok(true, "Edit profile dialog is closed");
+        resolve();
+      }, {once: true});
+      EventUtils.synthesizeKey("VK_TAB", {}, win);
+      EventUtils.synthesizeKey("test", {}, win);
+      win.document.querySelector("#save").click();
+    }, {once: true});
+  });
+  profiles = yield getProfiles();
+
+  is(profiles.length, 1, "only one profile is in storage");
+  is(profiles[0].organization, TEST_PROFILE_1.organization + "test", "organization changed");
+  yield removeProfiles([profiles[0].guid]);
+
+  profiles = yield getProfiles();
+  is(profiles.length, 0, "Profile storage is empty");
+});