test_browserGlue_migration_formautofill.js (4434B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const TOPIC_BROWSERGLUE_TEST = "browser-glue-test"; 7 const TOPICDATA_BROWSERGLUE_TEST = "force-ui-migration"; 8 9 const gBrowserGlue = Cc["@mozilla.org/browser/browserglue;1"].getService( 10 Ci.nsIObserver 11 ); 12 const UI_VERSION = 124; 13 14 function ensureOldPrefsAreCleared() { 15 Assert.ok( 16 !Services.prefs.prefHasUserValue("extensions.formautofill.available"), 17 "main module available pref should have been cleared" 18 ); 19 Assert.ok( 20 !Services.prefs.prefHasUserValue( 21 "extensions.formautofill.creditCards.available" 22 ), 23 "old credit card available pref should have been cleared" 24 ); 25 } 26 27 add_task(async function setup() { 28 registerCleanupFunction(() => { 29 Services.prefs.clearUserPref("browser.migration.version"); 30 Services.prefs.clearUserPref("extensions.formautofill.available"); 31 Services.prefs.clearUserPref( 32 "extensions.formautofill.creditCards.available" 33 ); 34 Services.prefs.clearUserPref( 35 "extensions.formautofill.creditCards.supported" 36 ); 37 }); 38 }); 39 40 add_task(async function test_check_form_autofill_module_detect() { 41 Services.prefs.setIntPref("browser.migration.version", UI_VERSION - 1); 42 Services.prefs.setCharPref("extensions.formautofill.available", "detect"); 43 // Simulate a migration. 44 gBrowserGlue.observe( 45 null, 46 TOPIC_BROWSERGLUE_TEST, 47 TOPICDATA_BROWSERGLUE_TEST 48 ); 49 // old credit card available should migrate to "detect" due to 50 // "extensions.formautofill.available" being "on". 51 Assert.equal( 52 Services.prefs.getCharPref("extensions.formautofill.creditCards.supported"), 53 "on" 54 ); 55 // old address available pref follows the main module pref 56 Assert.equal( 57 Services.prefs.getCharPref("extensions.formautofill.addresses.supported"), 58 "detect" 59 ); 60 ensureOldPrefsAreCleared(); 61 }); 62 63 add_task(async function test_check_old_form_autofill_module_off() { 64 Services.prefs.setIntPref("browser.migration.version", UI_VERSION - 1); 65 Services.prefs.setCharPref("extensions.formautofill.available", "off"); 66 67 // Simulate a migration. 68 gBrowserGlue.observe( 69 null, 70 TOPIC_BROWSERGLUE_TEST, 71 TOPICDATA_BROWSERGLUE_TEST 72 ); 73 74 // old credit card available should migrate to off due to 75 // "extensions.formautofill.available" being off. 76 Assert.equal( 77 Services.prefs.getCharPref("extensions.formautofill.creditCards.supported"), 78 "off" 79 ); 80 // old address available pref follows the main module pref 81 Assert.equal( 82 Services.prefs.getCharPref("extensions.formautofill.addresses.supported"), 83 "off" 84 ); 85 ensureOldPrefsAreCleared(); 86 }); 87 88 add_task(async function test_check_old_form_autofill_module_on_cc_on() { 89 Services.prefs.setIntPref("browser.migration.version", UI_VERSION - 1); 90 Services.prefs.setCharPref("extensions.formautofill.available", "on"); 91 Services.prefs.setBoolPref( 92 "extensions.formautofill.creditCards.available", 93 true 94 ); 95 96 // Simulate a migration. 97 gBrowserGlue.observe( 98 null, 99 TOPIC_BROWSERGLUE_TEST, 100 TOPICDATA_BROWSERGLUE_TEST 101 ); 102 103 // old credit card available should migrate to "on" due to 104 // "extensions.formautofill.available" being on and 105 // "extensions.formautofill.creditCards.available" having a default value of true. 106 Assert.equal( 107 Services.prefs.getCharPref("extensions.formautofill.creditCards.supported"), 108 "on" 109 ); 110 // old address available pref follows the main module pref 111 Assert.equal( 112 Services.prefs.getCharPref("extensions.formautofill.addresses.supported"), 113 "on" 114 ); 115 ensureOldPrefsAreCleared(); 116 }); 117 118 add_task(async function test_check_old_form_autofill_module_on_cc_off() { 119 Services.prefs.setIntPref("browser.migration.version", UI_VERSION - 1); 120 Services.prefs.setCharPref("extensions.formautofill.available", "on"); 121 Services.prefs.setBoolPref( 122 "extensions.formautofill.creditCards.available", 123 false 124 ); 125 126 // Simulate a migration. 127 gBrowserGlue.observe( 128 null, 129 TOPIC_BROWSERGLUE_TEST, 130 TOPICDATA_BROWSERGLUE_TEST 131 ); 132 133 // old credit card available should migrate to "off" due to 134 // "extensions.formautofill.available" being on and 135 // "extensions.formautofill.creditCards.available" having a user set value of false. 136 Assert.equal( 137 Services.prefs.getCharPref("extensions.formautofill.creditCards.supported"), 138 "off" 139 ); 140 141 ensureOldPrefsAreCleared(); 142 });