test_autoconfig_nonascii.js (3035B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 /* eslint no-unsafe-finally: "off"*/ 5 /* Turning off this rule to allow control flow operations in finally block 6 * http://eslint.org/docs/rules/no-unsafe-finally */ 7 8 function run_test() { 9 let greD = Services.dirsvc.get("GreD", Ci.nsIFile); 10 let defaultPrefD = Services.dirsvc.get("PrfDef", Ci.nsIFile); 11 let testDir = do_get_cwd(); 12 13 try { 14 let autoConfigJS = testDir.clone(); 15 autoConfigJS.append("autoconfig.js"); 16 autoConfigJS.copyTo(defaultPrefD, "autoconfig.js"); 17 18 // Make sure nsReadConfig is initialized. 19 Cc["@mozilla.org/readconfig;1"].getService(Ci.nsISupports); 20 Services.prefs.resetPrefs(); 21 22 var tests = [ 23 { 24 filename: "autoconfig-utf8.cfg", 25 prefs: { 26 "_test.string.ASCII": "UTF-8", 27 "_test.string.non-ASCII": "日本語", 28 "_test.string.getPref": "日本語", 29 "_test.string.gIsUTF8": "true", 30 }, 31 }, 32 { 33 filename: "autoconfig-latin1.cfg", 34 prefs: { 35 "_test.string.ASCII": "ASCII", 36 "_test.string.non-ASCII": "日本語", 37 "_test.string.getPref": "日本語", 38 "_test.string.gIsUTF8": "false", 39 }, 40 }, 41 { 42 filename: "autoconfig-chromecheck.cfg", 43 prefs: { 44 "_test.string.typeofComponents": "undefined", 45 "_test.string.typeofChromeUtils": "undefined", 46 "_test.string.typeofServices": "undefined", 47 }, 48 }, 49 ]; 50 51 function testAutoConfig(test) { 52 // Make sure pref values are unset. 53 for (let prefName in test.prefs) { 54 Assert.equal( 55 Ci.nsIPrefBranch.PREF_INVALID, 56 Services.prefs.getPrefType(prefName) 57 ); 58 } 59 60 let autoConfigCfg = testDir.clone(); 61 autoConfigCfg.append(test.filename); 62 autoConfigCfg.copyTo(greD, "autoconfig.cfg"); 63 64 Services.obs.notifyObservers( 65 Services.prefs, 66 "prefservice:before-read-userprefs" 67 ); 68 69 for (let prefName in test.prefs) { 70 Assert.equal( 71 test.prefs[prefName], 72 Services.prefs.getStringPref(prefName) 73 ); 74 } 75 76 Services.prefs.resetPrefs(); 77 // Make sure pref values are reset. 78 for (let prefName in test.prefs) { 79 Assert.equal( 80 Ci.nsIPrefBranch.PREF_INVALID, 81 Services.prefs.getPrefType(prefName) 82 ); 83 } 84 } 85 86 tests.forEach(testAutoConfig); 87 } finally { 88 try { 89 let autoConfigJS = defaultPrefD.clone(); 90 autoConfigJS.append("autoconfig.js"); 91 autoConfigJS.remove(false); 92 } catch (e) { 93 if (e.result != Cr.NS_ERROR_FILE_NOT_FOUND) { 94 throw e; 95 } 96 } 97 98 try { 99 let autoConfigCfg = greD.clone(); 100 autoConfigCfg.append("autoconfig.cfg"); 101 autoConfigCfg.remove(false); 102 } catch (e) { 103 if (e.result != Cr.NS_ERROR_FILE_NOT_FOUND) { 104 throw e; 105 } 106 } 107 108 Services.prefs.resetPrefs(); 109 } 110 }