Bug 887703 - navigator.doNotTrack returns { "0", "1", "unspecified" }. r=jlebar

--HG--
rename : dom/tests/mochitest/general/test_bug629535.html => dom/tests/mochitest/general/test_donottrack.html
This commit is contained in:
Mounir Lamouri 2014-05-26 22:10:39 +01:00
Родитель 017a4114a2
Коммит d219051569
4 изменённых файлов: 113 добавлений и 48 удалений

Просмотреть файл

@ -107,6 +107,7 @@ namespace mozilla {
namespace dom {
static bool sDoNotTrackEnabled = false;
static uint32_t sDoNotTrackValue = 1;
static bool sVibratorEnabled = false;
static uint32_t sMaxVibrateMS = 0;
static uint32_t sMaxVibrateListLen = 0;
@ -118,6 +119,9 @@ Navigator::Init()
Preferences::AddBoolVarCache(&sDoNotTrackEnabled,
"privacy.donottrackheader.enabled",
false);
Preferences::AddUintVarCache(&sDoNotTrackValue,
"privacy.donottrackheader.value",
1);
Preferences::AddBoolVarCache(&sVibratorEnabled,
"dom.vibrator.enabled", true);
Preferences::AddUintVarCache(&sMaxVibrateMS,
@ -621,7 +625,11 @@ NS_IMETHODIMP
Navigator::GetDoNotTrack(nsAString &aResult)
{
if (sDoNotTrackEnabled) {
aResult.AssignLiteral("yes");
if (sDoNotTrackValue == 0) {
aResult.AssignLiteral("0");
} else {
aResult.AssignLiteral("1");
}
} else {
aResult.AssignLiteral("unspecified");
}

Просмотреть файл

@ -21,7 +21,6 @@ skip-if = (buildapp == 'b2g' && toolkit != 'gonk') || toolkit == 'android' #Bug
[test_bug628069_1.html]
skip-if = (buildapp == 'b2g' && toolkit != 'gonk') #Bug 931116, b2g desktop specific, initial triage
[test_bug628069_2.html]
[test_bug629535.html]
[test_bug631440.html]
skip-if = (buildapp == 'b2g' && toolkit != 'gonk') #Bug 931116, b2g desktop specific, initial triage
[test_bug653364.html]
@ -33,6 +32,7 @@ skip-if = buildapp == 'b2g' # b2g(clipboard undefined) b2g-debug(clipboard undef
[test_domWindowUtils.html]
[test_domWindowUtils_scrollXY.html]
[test_domWindowUtils_scrollbarSize.html]
[test_donottrack.html]
[test_focus_legend_noparent.html]
[test_focusrings.xul]
skip-if = buildapp == 'b2g' || toolkit == 'android' #TIMED_OUT

Просмотреть файл

@ -1,46 +0,0 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=629535
-->
<head>
<title>Test for Bug 629535</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=629535">Mozilla Bug 629535</a>
<script type="application/javascript">
const dntPref = 'privacy.donottrackheader.enabled';
SimpleTest.waitForExplicitFinish();
is(SpecialPowers.getBoolPref(dntPref), false,
'DNT should be disabled by default');
is(navigator.doNotTrack, 'unspecified',
'navigator.doNotTrack should initially be "unspecified".');
SpecialPowers.pushPrefEnv({"clear": [[dntPref]]}, test1);
function test1() {
is(navigator.doNotTrack, "unspecified", 'after clearing pref');
SpecialPowers.pushPrefEnv({"set": [[dntPref, true]]}, test2);
}
function test2() {
is(navigator.doNotTrack, "yes", 'after setting pref to true');
SpecialPowers.pushPrefEnv({"set": [[dntPref, false]]}, test3);
}
function test3() {
is(navigator.doNotTrack, "unspecified", 'after setting pref to false');
SimpleTest.finish();
}
</script>
</body>
</html>

Просмотреть файл

@ -0,0 +1,103 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=629535
-->
<head>
<title>Test for Bug 629535</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=629535">Mozilla Bug 629535</a>
<script type="application/javascript">
const dntPref = 'privacy.donottrackheader.enabled';
const dntValuePref = 'privacy.donottrackheader.value';
SimpleTest.waitForExplicitFinish();
var currentTestIdx = -1;
var tests = [];
function nextTest() {
currentTestIdx++;
if (currentTestIdx >= tests.length) {
SimpleTest.finish();
return;
}
tests[currentTestIdx]();
}
tests.push(function testDefaultValues() {
// The default pref values depend on the OS it seems.
var isAndroid = !!navigator.userAgent.contains("Android");
var isB2G = !isAndroid && /Mobile|Tablet/.test(navigator.userAgent);
is(SpecialPowers.getBoolPref(dntPref), false,
'DNT should be disabled by default');
is(navigator.doNotTrack, 'unspecified',
'navigator.doNotTrack should initially be "unspecified".');
is(SpecialPowers.getIntPref(dntValuePref), isB2G ? -1 : 1,
'DNT value should be "1" by default');
nextTest();
});
tests.push(function clearedEnabled() {
SpecialPowers.pushPrefEnv({"clear": [[dntPref]]}, function() {
is(navigator.doNotTrack, "unspecified", 'after clearing pref');
nextTest();
});
});
tests.push(function setEnabled() {
SpecialPowers.pushPrefEnv({"set": [[dntPref, true]]}, function() {
is(navigator.doNotTrack, "1", 'after setting pref to true');
nextTest();
});
});
tests.push(function clearedValue() {
SpecialPowers.pushPrefEnv({"clear": [[dntValuePref]]}, function() {
is(navigator.doNotTrack, "1", 'after clearing value pref');
nextTest();
});
});
tests.push(function setValue0() {
SpecialPowers.pushPrefEnv({"set": [[dntValuePref, 0]]}, function() {
is(navigator.doNotTrack, "0", 'after setting value pref');
nextTest();
});
});
tests.push(function setValue42() {
SpecialPowers.pushPrefEnv({"set": [[dntValuePref, 42]]}, function() {
is(navigator.doNotTrack, "1", 'after setting value pref');
nextTest();
});
});
tests.push(function clearValueAgain() {
SpecialPowers.pushPrefEnv({"clear": [[dntValuePref]]}, function() {
is(navigator.doNotTrack, "1", 'after clearing value pref');
nextTest();
});
});
tests.push(function setDisabled() {
SpecialPowers.pushPrefEnv({"set": [[dntPref, false]]}, function() {
is(navigator.doNotTrack, "unspecified", 'after setting pref to false');
nextTest();
});
});
nextTest();
</script>
</body>
</html>