PageRenderTime 210ms CodeModel.GetById 37ms RepoModel.GetById 2ms app.codeStats 0ms

/toolkit/components/passwordmgr/test/browser/browser_capture_doorhanger.js

https://bitbucket.org/vionika/spin.android
JavaScript | 782 lines | 646 code | 121 blank | 15 comment | 0 complexity | 005091c4588b4593a4c447b7350088c0 MD5 | raw file
Possible License(s): JSON, 0BSD, AGPL-1.0, BSD-2-Clause, GPL-3.0, LGPL-2.1, LGPL-3.0, CC0-1.0, AGPL-3.0, MPL-2.0, Apache-2.0, MIT, BSD-3-Clause, MPL-2.0-no-copyleft-exception, GPL-2.0, Unlicense
  1. /*
  2. * Test capture popup notifications
  3. */
  4. const BRAND_BUNDLE = Services.strings.createBundle(
  5. "chrome://branding/locale/brand.properties"
  6. );
  7. const BRAND_SHORT_NAME = BRAND_BUNDLE.GetStringFromName("brandShortName");
  8. let nsLoginInfo = new Components.Constructor(
  9. "@mozilla.org/login-manager/loginInfo;1",
  10. Ci.nsILoginInfo,
  11. "init"
  12. );
  13. let login1 = new nsLoginInfo(
  14. "http://example.com",
  15. "http://example.com",
  16. null,
  17. "notifyu1",
  18. "notifyp1",
  19. "user",
  20. "pass"
  21. );
  22. let login2 = new nsLoginInfo(
  23. "http://example.com",
  24. "http://example.com",
  25. null,
  26. "",
  27. "notifyp1",
  28. "",
  29. "pass"
  30. );
  31. let login1B = new nsLoginInfo(
  32. "http://example.com",
  33. "http://example.com",
  34. null,
  35. "notifyu1B",
  36. "notifyp1B",
  37. "user",
  38. "pass"
  39. );
  40. let login2B = new nsLoginInfo(
  41. "http://example.com",
  42. "http://example.com",
  43. null,
  44. "",
  45. "notifyp1B",
  46. "",
  47. "pass"
  48. );
  49. requestLongerTimeout(2);
  50. add_task(async function setup() {
  51. // Load recipes for this test.
  52. let recipeParent = await LoginManagerParent.recipeParentPromise;
  53. await recipeParent.load({
  54. siteRecipes: [
  55. {
  56. hosts: ["example.org"],
  57. usernameSelector: "#user",
  58. passwordSelector: "#pass",
  59. },
  60. ],
  61. });
  62. });
  63. add_task(async function test_remember_opens() {
  64. await testSubmittingLoginForm("subtst_notifications_1.html", function(
  65. fieldValues
  66. ) {
  67. is(fieldValues.username, "notifyu1", "Checking submitted username");
  68. is(fieldValues.password, "notifyp1", "Checking submitted password");
  69. let notif = getCaptureDoorhanger("password-save");
  70. ok(notif, "got notification popup");
  71. notif.remove();
  72. });
  73. });
  74. add_task(async function test_clickNever() {
  75. await testSubmittingLoginForm("subtst_notifications_1.html", async function(
  76. fieldValues
  77. ) {
  78. is(fieldValues.username, "notifyu1", "Checking submitted username");
  79. is(fieldValues.password, "notifyp1", "Checking submitted password");
  80. let notif = getCaptureDoorhanger("password-save");
  81. ok(notif, "got notification popup");
  82. is(
  83. true,
  84. Services.logins.getLoginSavingEnabled("http://example.com"),
  85. "Checking for login saving enabled"
  86. );
  87. await checkDoorhangerUsernamePassword("notifyu1", "notifyp1");
  88. clickDoorhangerButton(notif, NEVER_MENUITEM);
  89. });
  90. is(
  91. Services.logins.getAllLogins().length,
  92. 0,
  93. "Should not have any logins yet"
  94. );
  95. info("Make sure Never took effect");
  96. await testSubmittingLoginForm("subtst_notifications_1.html", function(
  97. fieldValues
  98. ) {
  99. is(fieldValues.username, "notifyu1", "Checking submitted username");
  100. is(fieldValues.password, "notifyp1", "Checking submitted password");
  101. let notif = getCaptureDoorhanger("password-save");
  102. ok(!notif, "checking for no notification popup");
  103. is(
  104. false,
  105. Services.logins.getLoginSavingEnabled("http://example.com"),
  106. "Checking for login saving disabled"
  107. );
  108. Services.logins.setLoginSavingEnabled("http://example.com", true);
  109. });
  110. is(
  111. Services.logins.getAllLogins().length,
  112. 0,
  113. "Should not have any logins yet"
  114. );
  115. });
  116. add_task(async function test_clickRemember() {
  117. await testSubmittingLoginForm("subtst_notifications_1.html", async function(
  118. fieldValues
  119. ) {
  120. is(fieldValues.username, "notifyu1", "Checking submitted username");
  121. is(fieldValues.password, "notifyp1", "Checking submitted password");
  122. let notif = getCaptureDoorhanger("password-save");
  123. ok(notif, "got notification popup");
  124. is(
  125. Services.logins.getAllLogins().length,
  126. 0,
  127. "Should not have any logins yet"
  128. );
  129. await checkDoorhangerUsernamePassword("notifyu1", "notifyp1");
  130. clickDoorhangerButton(notif, REMEMBER_BUTTON);
  131. });
  132. let logins = Services.logins.getAllLogins();
  133. is(logins.length, 1, "Should only have 1 login");
  134. let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  135. is(login.username, "notifyu1", "Check the username used on the new entry");
  136. is(login.password, "notifyp1", "Check the password used on the new entry");
  137. is(login.timesUsed, 1, "Check times used on new entry");
  138. info(
  139. "Make sure Remember took effect and we don't prompt for an existing login"
  140. );
  141. await testSubmittingLoginForm("subtst_notifications_1.html", function(
  142. fieldValues
  143. ) {
  144. is(fieldValues.username, "notifyu1", "Checking submitted username");
  145. is(fieldValues.password, "notifyp1", "Checking submitted password");
  146. let notif = getCaptureDoorhanger("password-save");
  147. ok(!notif, "checking for no notification popup");
  148. });
  149. logins = Services.logins.getAllLogins();
  150. is(logins.length, 1, "Should only have 1 login");
  151. login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  152. is(login.username, "notifyu1", "Check the username used");
  153. is(login.password, "notifyp1", "Check the password used");
  154. is(login.timesUsed, 2, "Check times used incremented");
  155. checkOnlyLoginWasUsedTwice({ justChanged: false });
  156. // remove that login
  157. Services.logins.removeLogin(login1);
  158. });
  159. /* signons.rememberSignons pref tests... */
  160. add_task(async function test_rememberSignonsFalse() {
  161. info("Make sure we don't prompt with rememberSignons=false");
  162. Services.prefs.setBoolPref("signon.rememberSignons", false);
  163. await testSubmittingLoginForm("subtst_notifications_1.html", function(
  164. fieldValues
  165. ) {
  166. is(fieldValues.username, "notifyu1", "Checking submitted username");
  167. is(fieldValues.password, "notifyp1", "Checking submitted password");
  168. let notif = getCaptureDoorhanger("password-save");
  169. ok(!notif, "checking for no notification popup");
  170. });
  171. is(
  172. Services.logins.getAllLogins().length,
  173. 0,
  174. "Should not have any logins yet"
  175. );
  176. });
  177. add_task(async function test_rememberSignonsTrue() {
  178. info("Make sure we prompt with rememberSignons=true");
  179. Services.prefs.setBoolPref("signon.rememberSignons", true);
  180. await testSubmittingLoginForm("subtst_notifications_1.html", function(
  181. fieldValues
  182. ) {
  183. is(fieldValues.username, "notifyu1", "Checking submitted username");
  184. is(fieldValues.password, "notifyp1", "Checking submitted password");
  185. let notif = getCaptureDoorhanger("password-save");
  186. ok(notif, "got notification popup");
  187. notif.remove();
  188. });
  189. is(
  190. Services.logins.getAllLogins().length,
  191. 0,
  192. "Should not have any logins yet"
  193. );
  194. });
  195. /* autocomplete=off tests... */
  196. add_task(async function test_autocompleteOffUsername() {
  197. info(
  198. "Check for notification popup when autocomplete=off present on username"
  199. );
  200. await testSubmittingLoginForm("subtst_notifications_2.html", function(
  201. fieldValues
  202. ) {
  203. is(fieldValues.username, "notifyu1", "Checking submitted username");
  204. is(fieldValues.password, "notifyp1", "Checking submitted password");
  205. let notif = getCaptureDoorhanger("password-save");
  206. ok(notif, "checking for notification popup");
  207. notif.remove();
  208. });
  209. is(
  210. Services.logins.getAllLogins().length,
  211. 0,
  212. "Should not have any logins yet"
  213. );
  214. });
  215. add_task(async function test_autocompleteOffPassword() {
  216. info(
  217. "Check for notification popup when autocomplete=off present on password"
  218. );
  219. await testSubmittingLoginForm("subtst_notifications_3.html", function(
  220. fieldValues
  221. ) {
  222. is(fieldValues.username, "notifyu1", "Checking submitted username");
  223. is(fieldValues.password, "notifyp1", "Checking submitted password");
  224. let notif = getCaptureDoorhanger("password-save");
  225. ok(notif, "checking for notification popup");
  226. notif.remove();
  227. });
  228. is(
  229. Services.logins.getAllLogins().length,
  230. 0,
  231. "Should not have any logins yet"
  232. );
  233. });
  234. add_task(async function test_autocompleteOffForm() {
  235. info("Check for notification popup when autocomplete=off present on form");
  236. await testSubmittingLoginForm("subtst_notifications_4.html", function(
  237. fieldValues
  238. ) {
  239. is(fieldValues.username, "notifyu1", "Checking submitted username");
  240. is(fieldValues.password, "notifyp1", "Checking submitted password");
  241. let notif = getCaptureDoorhanger("password-save");
  242. ok(notif, "checking for notification popup");
  243. notif.remove();
  244. });
  245. is(
  246. Services.logins.getAllLogins().length,
  247. 0,
  248. "Should not have any logins yet"
  249. );
  250. });
  251. add_task(async function test_noPasswordField() {
  252. info("Check for no notification popup when no password field present");
  253. await testSubmittingLoginForm("subtst_notifications_5.html", function(
  254. fieldValues
  255. ) {
  256. is(fieldValues.username, "notifyu1", "Checking submitted username");
  257. is(fieldValues.password, "null", "Checking submitted password");
  258. let notif = getCaptureDoorhanger("password-save");
  259. ok(!notif, "checking for no notification popup");
  260. });
  261. is(
  262. Services.logins.getAllLogins().length,
  263. 0,
  264. "Should not have any logins yet"
  265. );
  266. });
  267. add_task(async function test_pwOnlyLoginMatchesForm() {
  268. info("Check for update popup when existing pw-only login matches form.");
  269. Services.logins.addLogin(login2);
  270. await testSubmittingLoginForm("subtst_notifications_1.html", function(
  271. fieldValues
  272. ) {
  273. is(fieldValues.username, "notifyu1", "Checking submitted username");
  274. is(fieldValues.password, "notifyp1", "Checking submitted password");
  275. let notif = getCaptureDoorhanger("password-change");
  276. ok(notif, "checking for notification popup");
  277. notif.remove();
  278. });
  279. let logins = Services.logins.getAllLogins();
  280. is(logins.length, 1, "Should only have 1 login");
  281. let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  282. is(login.username, "", "Check the username");
  283. is(login.password, "notifyp1", "Check the password");
  284. is(login.timesUsed, 1, "Check times used");
  285. Services.logins.removeLogin(login2);
  286. });
  287. add_task(async function test_pwOnlyFormMatchesLogin() {
  288. info(
  289. "Check for no notification popup when pw-only form matches existing login."
  290. );
  291. Services.logins.addLogin(login1);
  292. await testSubmittingLoginForm("subtst_notifications_6.html", function(
  293. fieldValues
  294. ) {
  295. is(fieldValues.username, "null", "Checking submitted username");
  296. is(fieldValues.password, "notifyp1", "Checking submitted password");
  297. let notif = getCaptureDoorhanger("password-save");
  298. ok(!notif, "checking for no notification popup");
  299. });
  300. let logins = Services.logins.getAllLogins();
  301. is(logins.length, 1, "Should only have 1 login");
  302. let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  303. is(login.username, "notifyu1", "Check the username");
  304. is(login.password, "notifyp1", "Check the password");
  305. is(login.timesUsed, 2, "Check times used");
  306. Services.logins.removeLogin(login1);
  307. });
  308. add_task(async function test_pwOnlyFormDoesntMatchExisting() {
  309. info(
  310. "Check for notification popup when pw-only form doesn't match existing login."
  311. );
  312. Services.logins.addLogin(login1B);
  313. await testSubmittingLoginForm("subtst_notifications_6.html", function(
  314. fieldValues
  315. ) {
  316. is(fieldValues.username, "null", "Checking submitted username");
  317. is(fieldValues.password, "notifyp1", "Checking submitted password");
  318. let notif = getCaptureDoorhanger("password-save");
  319. ok(notif, "got notification popup");
  320. notif.remove();
  321. });
  322. let logins = Services.logins.getAllLogins();
  323. is(logins.length, 1, "Should only have 1 login");
  324. let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  325. is(login.username, "notifyu1B", "Check the username unchanged");
  326. is(login.password, "notifyp1B", "Check the password unchanged");
  327. is(login.timesUsed, 1, "Check times used");
  328. Services.logins.removeLogin(login1B);
  329. });
  330. add_task(async function test_changeUPLoginOnUPForm_dont() {
  331. info("Check for change-password popup, u+p login on u+p form. (not changed)");
  332. Services.logins.addLogin(login1);
  333. await testSubmittingLoginForm("subtst_notifications_8.html", async function(
  334. fieldValues
  335. ) {
  336. is(fieldValues.username, "notifyu1", "Checking submitted username");
  337. is(fieldValues.password, "pass2", "Checking submitted password");
  338. let notif = getCaptureDoorhanger("password-change");
  339. ok(notif, "got notification popup");
  340. await checkDoorhangerUsernamePassword("notifyu1", "pass2");
  341. clickDoorhangerButton(notif, DONT_CHANGE_BUTTON);
  342. });
  343. let logins = Services.logins.getAllLogins();
  344. is(logins.length, 1, "Should only have 1 login");
  345. let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  346. is(login.username, "notifyu1", "Check the username unchanged");
  347. is(login.password, "notifyp1", "Check the password unchanged");
  348. is(login.timesUsed, 1, "Check times used");
  349. Services.logins.removeLogin(login1);
  350. });
  351. add_task(async function test_changeUPLoginOnUPForm_change() {
  352. info("Check for change-password popup, u+p login on u+p form.");
  353. Services.logins.addLogin(login1);
  354. await testSubmittingLoginForm("subtst_notifications_8.html", async function(
  355. fieldValues
  356. ) {
  357. is(fieldValues.username, "notifyu1", "Checking submitted username");
  358. is(fieldValues.password, "pass2", "Checking submitted password");
  359. let notif = getCaptureDoorhanger("password-change");
  360. ok(notif, "got notification popup");
  361. await checkDoorhangerUsernamePassword("notifyu1", "pass2");
  362. clickDoorhangerButton(notif, CHANGE_BUTTON);
  363. ok(!getCaptureDoorhanger("password-change"), "popup should be gone");
  364. });
  365. let logins = Services.logins.getAllLogins();
  366. is(logins.length, 1, "Should only have 1 login");
  367. let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  368. is(login.username, "notifyu1", "Check the username unchanged");
  369. is(login.password, "pass2", "Check the password changed");
  370. is(login.timesUsed, 2, "Check times used");
  371. checkOnlyLoginWasUsedTwice({ justChanged: true });
  372. // cleanup
  373. login1.password = "pass2";
  374. Services.logins.removeLogin(login1);
  375. login1.password = "notifyp1";
  376. });
  377. add_task(async function test_changePLoginOnUPForm() {
  378. info("Check for change-password popup, p-only login on u+p form.");
  379. Services.logins.addLogin(login2);
  380. await testSubmittingLoginForm("subtst_notifications_9.html", async function(
  381. fieldValues
  382. ) {
  383. is(fieldValues.username, "", "Checking submitted username");
  384. is(fieldValues.password, "pass2", "Checking submitted password");
  385. let notif = getCaptureDoorhanger("password-change");
  386. ok(notif, "got notification popup");
  387. await checkDoorhangerUsernamePassword("", "pass2");
  388. clickDoorhangerButton(notif, CHANGE_BUTTON);
  389. ok(!getCaptureDoorhanger("password-change"), "popup should be gone");
  390. });
  391. let logins = Services.logins.getAllLogins();
  392. is(logins.length, 1, "Should only have 1 login");
  393. let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  394. is(login.username, "", "Check the username unchanged");
  395. is(login.password, "pass2", "Check the password changed");
  396. is(login.timesUsed, 2, "Check times used");
  397. // no cleanup -- saved password to be used in the next test.
  398. });
  399. add_task(async function test_changePLoginOnPForm() {
  400. info("Check for change-password popup, p-only login on p-only form.");
  401. await testSubmittingLoginForm("subtst_notifications_10.html", async function(
  402. fieldValues
  403. ) {
  404. is(fieldValues.username, "null", "Checking submitted username");
  405. is(fieldValues.password, "notifyp1", "Checking submitted password");
  406. let notif = getCaptureDoorhanger("password-change");
  407. ok(notif, "got notification popup");
  408. await checkDoorhangerUsernamePassword("", "notifyp1");
  409. clickDoorhangerButton(notif, CHANGE_BUTTON);
  410. ok(!getCaptureDoorhanger("password-change"), "popup should be gone");
  411. });
  412. let logins = Services.logins.getAllLogins();
  413. is(logins.length, 1, "Should only have 1 login");
  414. let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  415. is(login.username, "", "Check the username unchanged");
  416. is(login.password, "notifyp1", "Check the password changed");
  417. is(login.timesUsed, 3, "Check times used");
  418. Services.logins.removeLogin(login2);
  419. });
  420. add_task(async function test_checkUPSaveText() {
  421. info("Check text on a user+pass notification popup");
  422. await testSubmittingLoginForm("subtst_notifications_1.html", function(
  423. fieldValues
  424. ) {
  425. is(fieldValues.username, "notifyu1", "Checking submitted username");
  426. is(fieldValues.password, "notifyp1", "Checking submitted password");
  427. let notif = getCaptureDoorhanger("password-save");
  428. ok(notif, "got notification popup");
  429. // Check the text, which comes from the localized saveLoginMsg string.
  430. let notificationText = notif.message;
  431. let expectedText =
  432. "Would you like " +
  433. BRAND_SHORT_NAME +
  434. " to save this login for example.com?";
  435. is(expectedText, notificationText, "Checking text: " + notificationText);
  436. notif.remove();
  437. });
  438. is(
  439. Services.logins.getAllLogins().length,
  440. 0,
  441. "Should not have any logins yet"
  442. );
  443. });
  444. add_task(async function test_checkPSaveText() {
  445. info("Check text on a pass-only notification popup");
  446. await testSubmittingLoginForm("subtst_notifications_6.html", function(
  447. fieldValues
  448. ) {
  449. is(fieldValues.username, "null", "Checking submitted username");
  450. is(fieldValues.password, "notifyp1", "Checking submitted password");
  451. let notif = getCaptureDoorhanger("password-save");
  452. ok(notif, "got notification popup");
  453. // Check the text, which comes from the localized saveLoginMsgNoUser string.
  454. let notificationText = notif.message;
  455. let expectedText =
  456. "Would you like " +
  457. BRAND_SHORT_NAME +
  458. " to save this password for example.com?";
  459. is(expectedText, notificationText, "Checking text: " + notificationText);
  460. notif.remove();
  461. });
  462. is(
  463. Services.logins.getAllLogins().length,
  464. 0,
  465. "Should not have any logins yet"
  466. );
  467. });
  468. add_task(async function test_capture2pw0un() {
  469. info(
  470. "Check for notification popup when a form with 2 password fields (no username) " +
  471. "is submitted and there are no saved logins."
  472. );
  473. await testSubmittingLoginForm("subtst_notifications_2pw_0un.html", function(
  474. fieldValues
  475. ) {
  476. is(fieldValues.username, "null", "Checking submitted username");
  477. is(fieldValues.password, "notifyp1", "Checking submitted password");
  478. let notif = getCaptureDoorhanger("password-save");
  479. ok(notif, "got notification popup");
  480. notif.remove();
  481. });
  482. is(
  483. Services.logins.getAllLogins().length,
  484. 0,
  485. "Should not have any logins yet"
  486. );
  487. });
  488. add_task(async function test_change2pw0unExistingDifferentUP() {
  489. info(
  490. "Check for notification popup when a form with 2 password fields (no username) " +
  491. "is submitted and there is a saved login with a username and different password."
  492. );
  493. Services.logins.addLogin(login1B);
  494. await testSubmittingLoginForm("subtst_notifications_2pw_0un.html", function(
  495. fieldValues
  496. ) {
  497. is(fieldValues.username, "null", "Checking submitted username");
  498. is(fieldValues.password, "notifyp1", "Checking submitted password");
  499. let notif = getCaptureDoorhanger("password-change");
  500. ok(notif, "got notification popup");
  501. notif.remove();
  502. });
  503. let logins = Services.logins.getAllLogins();
  504. is(logins.length, 1, "Should only have 1 login");
  505. let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  506. is(login.username, "notifyu1B", "Check the username unchanged");
  507. is(login.password, "notifyp1B", "Check the password unchanged");
  508. is(login.timesUsed, 1, "Check times used");
  509. Services.logins.removeLogin(login1B);
  510. });
  511. add_task(async function test_change2pw0unExistingDifferentP() {
  512. info(
  513. "Check for notification popup when a form with 2 password fields (no username) " +
  514. "is submitted and there is a saved login with no username and different password."
  515. );
  516. Services.logins.addLogin(login2B);
  517. await testSubmittingLoginForm("subtst_notifications_2pw_0un.html", function(
  518. fieldValues
  519. ) {
  520. is(fieldValues.username, "null", "Checking submitted username");
  521. is(fieldValues.password, "notifyp1", "Checking submitted password");
  522. let notif = getCaptureDoorhanger("password-change");
  523. ok(notif, "got notification popup");
  524. notif.remove();
  525. });
  526. let logins = Services.logins.getAllLogins();
  527. is(logins.length, 1, "Should only have 1 login");
  528. let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  529. is(login.username, "", "Check the username unchanged");
  530. is(login.password, "notifyp1B", "Check the password unchanged");
  531. is(login.timesUsed, 1, "Check times used");
  532. Services.logins.removeLogin(login2B);
  533. });
  534. add_task(async function test_change2pw0unExistingWithSameP() {
  535. info(
  536. "Check for no notification popup when a form with 2 password fields (no username) " +
  537. "is submitted and there is a saved login with a username and the same password."
  538. );
  539. Services.logins.addLogin(login2);
  540. await testSubmittingLoginForm("subtst_notifications_2pw_0un.html", function(
  541. fieldValues
  542. ) {
  543. is(fieldValues.username, "null", "Checking submitted username");
  544. is(fieldValues.password, "notifyp1", "Checking submitted password");
  545. let notif = getCaptureDoorhanger("password-change");
  546. ok(!notif, "checking for no notification popup");
  547. });
  548. let logins = Services.logins.getAllLogins();
  549. is(logins.length, 1, "Should only have 1 login");
  550. let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  551. is(login.username, "", "Check the username unchanged");
  552. is(login.password, "notifyp1", "Check the password unchanged");
  553. is(login.timesUsed, 2, "Check times used incremented");
  554. checkOnlyLoginWasUsedTwice({ justChanged: false });
  555. Services.logins.removeLogin(login2);
  556. });
  557. add_task(async function test_changeUPLoginOnPUpdateForm() {
  558. info("Check for change-password popup, u+p login on password update form.");
  559. Services.logins.addLogin(login1);
  560. await testSubmittingLoginForm(
  561. "subtst_notifications_change_p.html",
  562. async function(fieldValues) {
  563. is(fieldValues.username, "null", "Checking submitted username");
  564. is(fieldValues.password, "pass2", "Checking submitted password");
  565. let notif = getCaptureDoorhanger("password-change");
  566. ok(notif, "got notification popup");
  567. await checkDoorhangerUsernamePassword("notifyu1", "pass2");
  568. clickDoorhangerButton(notif, CHANGE_BUTTON);
  569. ok(!getCaptureDoorhanger("password-change"), "popup should be gone");
  570. }
  571. );
  572. let logins = Services.logins.getAllLogins();
  573. is(logins.length, 1, "Should only have 1 login");
  574. let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  575. is(login.username, "notifyu1", "Check the username unchanged");
  576. is(login.password, "pass2", "Check the password changed");
  577. is(login.timesUsed, 2, "Check times used");
  578. checkOnlyLoginWasUsedTwice({ justChanged: true });
  579. // cleanup
  580. login1.password = "pass2";
  581. Services.logins.removeLogin(login1);
  582. login1.password = "notifyp1";
  583. });
  584. add_task(async function test_recipeCaptureFields_NewLogin() {
  585. info(
  586. "Check that we capture the proper fields when a field recipe is in use."
  587. );
  588. await testSubmittingLoginForm(
  589. "subtst_notifications_2pw_1un_1text.html",
  590. async function(fieldValues) {
  591. is(fieldValues.username, "notifyu1", "Checking submitted username");
  592. is(fieldValues.password, "notifyp1", "Checking submitted password");
  593. let notif = getCaptureDoorhanger("password-save");
  594. ok(notif, "got notification popup");
  595. // Sanity check, no logins should exist yet.
  596. let logins = Services.logins.getAllLogins();
  597. is(logins.length, 0, "Should not have any logins yet");
  598. await checkDoorhangerUsernamePassword("notifyu1", "notifyp1");
  599. clickDoorhangerButton(notif, REMEMBER_BUTTON);
  600. },
  601. "http://example.org"
  602. ); // The recipe is for example.org
  603. let logins = Services.logins.getAllLogins();
  604. is(logins.length, 1, "Should only have 1 login");
  605. let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  606. is(login.username, "notifyu1", "Check the username unchanged");
  607. is(login.password, "notifyp1", "Check the password unchanged");
  608. is(login.timesUsed, 1, "Check times used");
  609. });
  610. add_task(async function test_recipeCaptureFields_ExistingLogin() {
  611. info(
  612. "Check that we capture the proper fields when a field recipe is in use " +
  613. "and there is a matching login"
  614. );
  615. await testSubmittingLoginForm(
  616. "subtst_notifications_2pw_1un_1text.html",
  617. function(fieldValues) {
  618. is(fieldValues.username, "notifyu1", "Checking submitted username");
  619. is(fieldValues.password, "notifyp1", "Checking submitted password");
  620. let notif = getCaptureDoorhanger("password-save");
  621. ok(!notif, "checking for no notification popup");
  622. },
  623. "http://example.org"
  624. );
  625. checkOnlyLoginWasUsedTwice({ justChanged: false });
  626. let logins = Services.logins.getAllLogins();
  627. is(logins.length, 1, "Should only have 1 login");
  628. let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  629. is(login.username, "notifyu1", "Check the username unchanged");
  630. is(login.password, "notifyp1", "Check the password unchanged");
  631. is(login.timesUsed, 2, "Check times used incremented");
  632. Services.logins.removeAllLogins();
  633. });
  634. add_task(async function test_noShowPasswordOnDismissal() {
  635. info("Check for no Show Password field when the doorhanger is dismissed");
  636. await testSubmittingLoginForm("subtst_notifications_1.html", async function(
  637. fieldValues
  638. ) {
  639. info("Opening popup");
  640. let notif = getCaptureDoorhanger("password-save");
  641. let { panel } = PopupNotifications;
  642. info("Hiding popup.");
  643. let promiseHidden = BrowserTestUtils.waitForEvent(panel, "popuphidden");
  644. panel.hidePopup();
  645. await promiseHidden;
  646. info("Clicking on anchor to reshow popup.");
  647. let promiseShown = BrowserTestUtils.waitForEvent(panel, "popupshown");
  648. notif.anchorElement.click();
  649. await promiseShown;
  650. let passwordVisiblityToggle = panel.querySelector(
  651. "#password-notification-visibilityToggle"
  652. );
  653. is(
  654. passwordVisiblityToggle.hidden,
  655. true,
  656. "Check that the Show Password field is Hidden"
  657. );
  658. });
  659. });
  660. // TODO:
  661. // * existing login test, form has different password --> change password, no save prompt