Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
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 | open_preferences((win) => { |
michael@0 | 8 | let doc = win.document; |
michael@0 | 9 | win.gotoPref("paneAdvanced"); |
michael@0 | 10 | let advancedPrefs = doc.getElementById("advancedPrefs"); |
michael@0 | 11 | let tab = doc.getElementById("dataChoicesTab"); |
michael@0 | 12 | advancedPrefs.selectedTab = tab; |
michael@0 | 13 | |
michael@0 | 14 | let policy = Components.classes["@mozilla.org/datareporting/service;1"] |
michael@0 | 15 | .getService(Components.interfaces.nsISupports) |
michael@0 | 16 | .wrappedJSObject |
michael@0 | 17 | .policy; |
michael@0 | 18 | |
michael@0 | 19 | ok(policy, "Policy object is defined."); |
michael@0 | 20 | fn(win, doc, policy); |
michael@0 | 21 | }); |
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 | runPaneTest(testBasic); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | function testBasic(win, doc, policy) { |
michael@0 | 32 | is(policy.dataSubmissionPolicyAccepted, false, "Data submission policy not accepted."); |
michael@0 | 33 | is(policy.healthReportUploadEnabled, true, "Health Report upload enabled on app first run."); |
michael@0 | 34 | |
michael@0 | 35 | let checkbox = doc.getElementById("submitHealthReportBox"); |
michael@0 | 36 | ok(checkbox); |
michael@0 | 37 | is(checkbox.checked, true, "Health Report checkbox is checked on app first run."); |
michael@0 | 38 | |
michael@0 | 39 | checkbox.checked = false; |
michael@0 | 40 | checkbox.doCommand(); |
michael@0 | 41 | is(policy.healthReportUploadEnabled, false, "Unchecking checkbox opts out of FHR upload."); |
michael@0 | 42 | |
michael@0 | 43 | checkbox.checked = true; |
michael@0 | 44 | checkbox.doCommand(); |
michael@0 | 45 | is(policy.healthReportUploadEnabled, true, "Checking checkbox allows FHR upload."); |
michael@0 | 46 | |
michael@0 | 47 | win.close(); |
michael@0 | 48 | Services.prefs.lockPref("datareporting.healthreport.uploadEnabled"); |
michael@0 | 49 | runPaneTest(testUploadDisabled); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | function testUploadDisabled(win, doc, policy) { |
michael@0 | 53 | ok(policy.healthReportUploadLocked, "Upload enabled flag is locked."); |
michael@0 | 54 | let checkbox = doc.getElementById("submitHealthReportBox"); |
michael@0 | 55 | is(checkbox.getAttribute("disabled"), "true", "Checkbox is disabled if upload flag is locked."); |
michael@0 | 56 | policy._healthReportPrefs.unlock("uploadEnabled"); |
michael@0 | 57 | |
michael@0 | 58 | win.close(); |
michael@0 | 59 | finish(); |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | function resetPreferences() { |
michael@0 | 63 | Services.prefs.clearUserPref("datareporting.healthreport.uploadEnabled"); |
michael@0 | 64 | } |
michael@0 | 65 |