Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
// Check that CA is active if and only if:
// 1. browser.contentanalysis.enabled is true and
// 2. Either browser.contentanalysis.enabled was set by an enteprise
// policy or the "-allow-content-analysis" command line arg was present
// We can't really test command line arguments so we instead use a test-only
// method to set the value the command-line is supposed to update.
"use strict";
const { EnterprisePolicyTesting, PoliciesPrefTracker } =
ChromeUtils.importESModule(
);
const kEnabledPref = "enabled";
const kPipeNamePref = "pipe_path_name";
const kTimeoutPref = "agent_timeout";
const kAllowUrlPref = "allow_url_regex_list";
const kDenyUrlPref = "deny_url_regex_list";
const kAgentNamePref = "agent_name";
const kClientSignaturePref = "client_signature";
const kPerUserPref = "is_per_user";
const kShowBlockedPref = "show_blocked_result";
const kDefaultResultPref = "default_result";
const kBypassForSameTabOperationsPref = "bypass_for_same_tab_operations";
const kInterceptionPoints = [
"clipboard",
"drag_and_drop",
"file_upload",
"print",
];
const ca = Cc["@mozilla.org/contentanalysis;1"].getService(
Ci.nsIContentAnalysis
);
add_task(async function test_ca_active() {
PoliciesPrefTracker.start();
ok(!ca.isActive, "CA is inactive when pref and cmd line arg are missing");
// Set the pref without enterprise policy. CA should not be active.
Services.prefs.setBoolPref("browser.contentanalysis." + kEnabledPref, true);
ok(
!ca.isActive,
"CA is inactive when pref is set but cmd line arg is missing"
);
// Set the pref without enterprise policy but also set command line arg
// property. CA should be active.
ca.testOnlySetCACmdLineArg(true);
ok(ca.isActive, "CA is active when pref is set and cmd line arg is present");
// Undo test-only value before later tests.
ca.testOnlySetCACmdLineArg(false);
ok(!ca.isActive, "properly unset cmd line arg value");
// Disabled the pref with enterprise policy. CA should not be active.
await EnterprisePolicyTesting.setupPolicyEngineWithJson({
policies: {
ContentAnalysis: { Enabled: false },
},
});
ok(!ca.isActive, "CA is inactive when disabled by enterprise policy pref");
// Enabled the pref with enterprise policy. CA should be active.
await EnterprisePolicyTesting.setupPolicyEngineWithJson({
policies: {
ContentAnalysis: { Enabled: true },
},
});
ok(ca.isActive, "CA is active when enabled by enterprise policy pref");
for (let interceptionPoint of kInterceptionPoints) {
is(
Services.prefs.getBoolPref(
`browser.contentanalysis.interception_point.${interceptionPoint}.enabled`
),
true,
`${interceptionPoint} enabled by default`
);
}
Services.prefs.setBoolPref("browser.contentanalysis." + kEnabledPref, false);
PoliciesPrefTracker.stop();
});
add_task(async function test_ca_enterprise_config() {
PoliciesPrefTracker.start();
const string1 = "this is a string";
const string2 = "this is another string";
const string3 = "an agent name";
const string4 = "a client signature";
await EnterprisePolicyTesting.setupPolicyEngineWithJson({
policies: {
ContentAnalysis: {
PipePathName: "abc",
AgentTimeout: 99,
AllowUrlRegexList: string1,
DenyUrlRegexList: string2,
AgentName: string3,
ClientSignature: string4,
IsPerUser: true,
ShowBlockedResult: false,
DefaultResult: 1,
BypassForSameTabOperations: true,
InterceptionPoints: {
Clipboard: {
Enabled: false,
},
DragAndDrop: {
Enabled: false,
},
FileUpload: {
Enabled: false,
},
Print: {
Enabled: false,
},
},
},
},
});
is(
Services.prefs.getStringPref("browser.contentanalysis." + kPipeNamePref),
"abc",
"pipe name match"
);
is(
Services.prefs.getIntPref("browser.contentanalysis." + kTimeoutPref),
99,
"timeout match"
);
is(
Services.prefs.getStringPref("browser.contentanalysis." + kAllowUrlPref),
string1,
"allow urls match"
);
is(
Services.prefs.getStringPref("browser.contentanalysis." + kDenyUrlPref),
string2,
"deny urls match"
);
is(
Services.prefs.getStringPref("browser.contentanalysis." + kAgentNamePref),
string3,
"agent names match"
);
is(
Services.prefs.getStringPref(
"browser.contentanalysis." + kClientSignaturePref
),
string4,
"client signatures match"
);
is(
Services.prefs.getBoolPref("browser.contentanalysis." + kPerUserPref),
true,
"per user match"
);
is(
Services.prefs.getBoolPref("browser.contentanalysis." + kShowBlockedPref),
false,
"show blocked match"
);
is(
Services.prefs.getIntPref("browser.contentanalysis." + kDefaultResultPref),
1,
"default result match"
);
is(
Services.prefs.getBoolPref(
"browser.contentanalysis." + kBypassForSameTabOperationsPref
),
true,
"bypass for same tab operations match"
);
for (let interceptionPoint of kInterceptionPoints) {
is(
Services.prefs.getBoolPref(
`browser.contentanalysis.interception_point.${interceptionPoint}.enabled`
),
false,
`${interceptionPoint} interception point match`
);
}
PoliciesPrefTracker.stop();
});
add_task(async function test_cleanup() {
ca.testOnlySetCACmdLineArg(false);
await EnterprisePolicyTesting.setupPolicyEngineWithJson({
policies: {},
});
// These may have gotten set when ContentAnalysis was enabled through
// the policy and do not get cleared if there is no ContentAnalysis
// element - reset them manually here.
ca.isSetByEnterprisePolicy = false;
Services.prefs.setBoolPref("browser.contentanalysis." + kEnabledPref, false);
for (let interceptionPoint of kInterceptionPoints) {
Services.prefs.setBoolPref(
`browser.contentanalysis.interception_point.${interceptionPoint}.enabled`,
true
);
}
});