Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | // Tests that the pref commands work |
michael@0 | 5 | |
michael@0 | 6 | let prefBranch = Cc["@mozilla.org/preferences-service;1"] |
michael@0 | 7 | .getService(Ci.nsIPrefService).getBranch(null) |
michael@0 | 8 | .QueryInterface(Ci.nsIPrefBranch2); |
michael@0 | 9 | |
michael@0 | 10 | let supportsString = Cc["@mozilla.org/supports-string;1"] |
michael@0 | 11 | .createInstance(Ci.nsISupportsString); |
michael@0 | 12 | |
michael@0 | 13 | let settings = require("gcli/settings"); |
michael@0 | 14 | |
michael@0 | 15 | const TEST_URI = "data:text/html;charset=utf-8,gcli-settings"; |
michael@0 | 16 | |
michael@0 | 17 | function test() { |
michael@0 | 18 | return Task.spawn(spawnTest).then(finish, helpers.handleError); |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | function spawnTest() { |
michael@0 | 22 | // Setup |
michael@0 | 23 | let options = yield helpers.openTab(TEST_URI); |
michael@0 | 24 | |
michael@0 | 25 | let tiltEnabled = settings.getSetting("devtools.tilt.enabled"); |
michael@0 | 26 | let tabSize = settings.getSetting("devtools.editor.tabsize"); |
michael@0 | 27 | let remoteHost = settings.getSetting("devtools.debugger.remote-host"); |
michael@0 | 28 | |
michael@0 | 29 | let tiltEnabledOrig = prefBranch.getBoolPref("devtools.tilt.enabled"); |
michael@0 | 30 | let tabSizeOrig = prefBranch.getIntPref("devtools.editor.tabsize"); |
michael@0 | 31 | let remoteHostOrig = prefBranch.getComplexValue( |
michael@0 | 32 | "devtools.debugger.remote-host", |
michael@0 | 33 | Components.interfaces.nsISupportsString).data; |
michael@0 | 34 | |
michael@0 | 35 | info("originally: devtools.tilt.enabled = " + tiltEnabledOrig); |
michael@0 | 36 | info("originally: devtools.editor.tabsize = " + tabSizeOrig); |
michael@0 | 37 | info("originally: devtools.debugger.remote-host = " + remoteHostOrig); |
michael@0 | 38 | |
michael@0 | 39 | // Actual tests |
michael@0 | 40 | is(tiltEnabled.value, tiltEnabledOrig, "tiltEnabled default"); |
michael@0 | 41 | is(tabSize.value, tabSizeOrig, "tabSize default"); |
michael@0 | 42 | is(remoteHost.value, remoteHostOrig, "remoteHost default"); |
michael@0 | 43 | |
michael@0 | 44 | tiltEnabled.setDefault(); |
michael@0 | 45 | tabSize.setDefault(); |
michael@0 | 46 | remoteHost.setDefault(); |
michael@0 | 47 | |
michael@0 | 48 | let tiltEnabledDefault = tiltEnabled.value; |
michael@0 | 49 | let tabSizeDefault = tabSize.value; |
michael@0 | 50 | let remoteHostDefault = remoteHost.value; |
michael@0 | 51 | |
michael@0 | 52 | tiltEnabled.value = false; |
michael@0 | 53 | tabSize.value = 42; |
michael@0 | 54 | remoteHost.value = "example.com" |
michael@0 | 55 | |
michael@0 | 56 | is(tiltEnabled.value, false, "tiltEnabled basic"); |
michael@0 | 57 | is(tabSize.value, 42, "tabSize basic"); |
michael@0 | 58 | is(remoteHost.value, "example.com", "remoteHost basic"); |
michael@0 | 59 | |
michael@0 | 60 | function tiltEnabledCheck(ev) { |
michael@0 | 61 | is(ev.setting, tiltEnabled, "tiltEnabled event setting"); |
michael@0 | 62 | is(ev.value, true, "tiltEnabled event value"); |
michael@0 | 63 | is(ev.setting.value, true, "tiltEnabled event setting value"); |
michael@0 | 64 | } |
michael@0 | 65 | tiltEnabled.onChange.add(tiltEnabledCheck); |
michael@0 | 66 | tiltEnabled.value = true; |
michael@0 | 67 | is(tiltEnabled.value, true, "tiltEnabled change"); |
michael@0 | 68 | |
michael@0 | 69 | function tabSizeCheck(ev) { |
michael@0 | 70 | is(ev.setting, tabSize, "tabSize event setting"); |
michael@0 | 71 | is(ev.value, 1, "tabSize event value"); |
michael@0 | 72 | is(ev.setting.value, 1, "tabSize event setting value"); |
michael@0 | 73 | } |
michael@0 | 74 | tabSize.onChange.add(tabSizeCheck); |
michael@0 | 75 | tabSize.value = 1; |
michael@0 | 76 | is(tabSize.value, 1, "tabSize change"); |
michael@0 | 77 | |
michael@0 | 78 | function remoteHostCheck(ev) { |
michael@0 | 79 | is(ev.setting, remoteHost, "remoteHost event setting"); |
michael@0 | 80 | is(ev.value, "y.com", "remoteHost event value"); |
michael@0 | 81 | is(ev.setting.value, "y.com", "remoteHost event setting value"); |
michael@0 | 82 | } |
michael@0 | 83 | remoteHost.onChange.add(remoteHostCheck); |
michael@0 | 84 | remoteHost.value = "y.com"; |
michael@0 | 85 | is(remoteHost.value, "y.com", "remoteHost change"); |
michael@0 | 86 | |
michael@0 | 87 | tiltEnabled.onChange.remove(tiltEnabledCheck); |
michael@0 | 88 | tabSize.onChange.remove(tabSizeCheck); |
michael@0 | 89 | remoteHost.onChange.remove(remoteHostCheck); |
michael@0 | 90 | |
michael@0 | 91 | function remoteHostReCheck(ev) { |
michael@0 | 92 | is(ev.setting, remoteHost, "remoteHost event reset"); |
michael@0 | 93 | is(ev.value, null, "remoteHost event revalue"); |
michael@0 | 94 | is(ev.setting.value, null, "remoteHost event setting revalue"); |
michael@0 | 95 | } |
michael@0 | 96 | remoteHost.onChange.add(remoteHostReCheck); |
michael@0 | 97 | |
michael@0 | 98 | tiltEnabled.setDefault(); |
michael@0 | 99 | tabSize.setDefault(); |
michael@0 | 100 | remoteHost.setDefault(); |
michael@0 | 101 | |
michael@0 | 102 | remoteHost.onChange.remove(remoteHostReCheck); |
michael@0 | 103 | |
michael@0 | 104 | is(tiltEnabled.value, tiltEnabledDefault, "tiltEnabled reset"); |
michael@0 | 105 | is(tabSize.value, tabSizeDefault, "tabSize reset"); |
michael@0 | 106 | is(remoteHost.value, remoteHostDefault, "remoteHost reset"); |
michael@0 | 107 | |
michael@0 | 108 | // Cleanup |
michael@0 | 109 | prefBranch.setBoolPref("devtools.tilt.enabled", tiltEnabledOrig); |
michael@0 | 110 | prefBranch.setIntPref("devtools.editor.tabsize", tabSizeOrig); |
michael@0 | 111 | supportsString.data = remoteHostOrig; |
michael@0 | 112 | prefBranch.setComplexValue("devtools.debugger.remote-host", |
michael@0 | 113 | Components.interfaces.nsISupportsString, |
michael@0 | 114 | supportsString); |
michael@0 | 115 | |
michael@0 | 116 | yield helpers.closeTab(options); |
michael@0 | 117 | } |