Wed, 31 Dec 2014 07:16:47 +0100
Revert simplistic fix pending revisit of Mozilla integration attempt.
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 | "use strict"; |
michael@0 | 5 | |
michael@0 | 6 | function runPaneTest(fn) { |
michael@0 | 7 | function observer(win, topic, data) { |
michael@0 | 8 | Services.obs.removeObserver(observer, "advanced-pane-loaded"); |
michael@0 | 9 | |
michael@0 | 10 | let policy = Components.classes["@mozilla.org/datareporting/service;1"] |
michael@0 | 11 | .getService(Components.interfaces.nsISupports) |
michael@0 | 12 | .wrappedJSObject |
michael@0 | 13 | .policy; |
michael@0 | 14 | ok(policy, "Policy object defined"); |
michael@0 | 15 | |
michael@0 | 16 | fn(win, policy); |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | Services.obs.addObserver(observer, "advanced-pane-loaded", false); |
michael@0 | 20 | openDialog("chrome://browser/content/preferences/preferences.xul", "Preferences", |
michael@0 | 21 | "chrome,titlebar,toolbar,centerscreen,dialog=no", "paneAdvanced"); |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | function test() { |
michael@0 | 25 | waitForExplicitFinish(); |
michael@0 | 26 | resetPreferences(); |
michael@0 | 27 | registerCleanupFunction(resetPreferences); |
michael@0 | 28 | |
michael@0 | 29 | Services.prefs.lockPref("datareporting.healthreport.uploadEnabled"); |
michael@0 | 30 | runPaneTest(testUploadDisabled); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | function testUploadDisabled(win, policy) { |
michael@0 | 34 | ok(policy.healthReportUploadLocked, "Upload enabled flag is locked."); |
michael@0 | 35 | let checkbox = win.document.getElementById("submitHealthReportBox"); |
michael@0 | 36 | is(checkbox.getAttribute("disabled"), "true", "Checkbox is disabled if upload setting is locked."); |
michael@0 | 37 | policy._healthReportPrefs.unlock("uploadEnabled"); |
michael@0 | 38 | |
michael@0 | 39 | win.close(); |
michael@0 | 40 | runPaneTest(testBasic); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | function testBasic(win, policy) { |
michael@0 | 44 | let doc = win.document; |
michael@0 | 45 | |
michael@0 | 46 | is(policy.dataSubmissionPolicyAccepted, false, "Data submission policy not accepted."); |
michael@0 | 47 | is(policy.healthReportUploadEnabled, true, "Health Report upload enabled on app first run."); |
michael@0 | 48 | |
michael@0 | 49 | let checkbox = doc.getElementById("submitHealthReportBox"); |
michael@0 | 50 | ok(checkbox); |
michael@0 | 51 | is(checkbox.checked, true, "Health Report checkbox is checked on app first run."); |
michael@0 | 52 | |
michael@0 | 53 | checkbox.checked = false; |
michael@0 | 54 | checkbox.doCommand(); |
michael@0 | 55 | is(policy.healthReportUploadEnabled, false, "Unchecking checkbox opts out of FHR upload."); |
michael@0 | 56 | |
michael@0 | 57 | checkbox.checked = true; |
michael@0 | 58 | checkbox.doCommand(); |
michael@0 | 59 | is(policy.healthReportUploadEnabled, true, "Checking checkbox allows FHR upload."); |
michael@0 | 60 | |
michael@0 | 61 | win.close(); |
michael@0 | 62 | finish(); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | function resetPreferences() { |
michael@0 | 66 | Services.prefs.clearUserPref("datareporting.healthreport.uploadEnabled"); |
michael@0 | 67 | } |
michael@0 | 68 |