Bug 764481 - Add a pref to enable/disable experimental form features. r=mounir

--HG--
extra : rebase_source : 43b03c409b9cc52a991ca753c1848d453afbbb33
This commit is contained in:
Raphael Catolino 2012-06-23 14:32:54 +02:00
parent c0c5b1a1f3
commit 0081a6c0a7
14 changed files with 103 additions and 0 deletions

View File

@ -87,6 +87,7 @@
#include "mozilla/LookAndFeel.h"
#include "mozilla/Util.h" // DebugOnly
#include "mozilla/Preferences.h"
#include "nsIIDNService.h"
@ -2661,6 +2662,11 @@ nsHTMLInputElement::ParseAttribute(PRInt32 aNamespaceID,
bool success = aResult.ParseEnumValue(aValue, kInputTypeTable, false);
if (success) {
newType = aResult.GetEnumValue();
if (newType == NS_FORM_INPUT_NUMBER &&
!Preferences::GetBool("dom.experimental_forms", false)) {
newType = kInputDefaultType->value;
aResult.SetTo(newType, &aValue);
}
} else {
newType = kInputDefaultType->value;
}

View File

@ -47,6 +47,7 @@ _TEST_FILES = \
test_step_attribute.html \
test_stepup_stepdown.html \
test_valueasnumber_attribute.html \
test_experimental_forms_pref.html \
$(NULL)
libs:: $(_TEST_FILES)

View File

@ -0,0 +1,43 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=764481
-->
<head>
<title>Test for Bug 764481</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<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=764481">Mozilla Bug 764481</a>
<p id="display"></p>
<div id="content" style="display: none" >
</div>
<pre id="test">
<script type="application/javascript">
var input = document.createElement("input");
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({'set': [["dom.experimental_forms", false]]}, function() {
input.type = "number";
is(input.type, "text", "input type shouldn't be number when the experimental forms are disabled");
is(input.getAttribute('type'), "number", "input 'type' attribute should not change");
SpecialPowers.pushPrefEnv({'set': [["dom.experimental_forms",true]]}, function() {
// Change the type of input to text and then back to number,
// so that nsHTMLInputElement::ParseAttribute gets called with the pref enabled.
input.type = "text";
input.type = "number";
is(input.type, "number", "input type should be number when the experimental forms are enabled");
is(input.getAttribute('type'), "number", "input 'type' attribute should not change");
SimpleTest.finish();
});
});
</script>
</pre>
</body>
</html>

View File

@ -17,6 +17,8 @@
// TODO: maybe make those reflections be tested against all input types.
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({'set': [["dom.experimental_forms", true]]}, function() {
// .accept
reflectString({
element: document.createElement("input"),
@ -230,6 +232,9 @@ reflectUnsignedInt({
// .validationMessage doesn't reflect a content attribute.
// .labels doesn't reflect a content attribute.
SimpleTest.finish();
});
</script>
</pre>
</body>

View File

@ -77,6 +77,8 @@ function checkValidity(aElement, aValidity, aApply, aRangeApply)
}
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({'set': [["dom.experimental_forms", true]]}, function() {
for each (var data in types) {
input.type = data[0];
var apply = data[1];
@ -157,6 +159,9 @@ for each (var data in types) {
input.value = '';
}
SimpleTest.finish();
});
</script>
</pre>
</body>

View File

@ -77,6 +77,8 @@ function checkValidity(aElement, aValidity, aApply, aRangeApply)
}
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({'set': [["dom.experimental_forms", true]]}, function() {
for each (var data in types) {
input.type = data[0];
var apply = data[1];
@ -157,6 +159,9 @@ for each (var data in types) {
input.value = '';
}
SimpleTest.finish();
});
</script>
</pre>
</body>

View File

@ -102,6 +102,8 @@ function checkMozIsTextFieldValueTodo(aInput, aResult)
"mozIsTextField(true) should return " + aResult);
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({'set': [["dom.experimental_forms", true]]}, function() {
// Check if the method is defined for the correct elements.
for each (data in gElementTestData) {
checkMozIsTextFieldDefined(data[0], data[1]);
@ -120,6 +122,9 @@ for each (data in gInputTodoData) {
checkMozIsTextFieldValueTodo(input, data[1]);
}
SimpleTest.finish();
});
</script>
</pre>
</body>

View File

@ -266,6 +266,8 @@ var invalidTypes = Array('checkbox', 'radio', 'file', 'number');
// 'range', and 'color' do not accept the @pattern too but are not
// implemented yet.
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({'set': [["dom.experimental_forms", true]]}, function() {
for each (type in validTypes) {
input.type = type;
completeValidityCheck(input, false);
@ -282,6 +284,9 @@ for each (type in invalidTypes) {
completeValidityCheck(input, true);
}
SimpleTest.finish();
});
</script>
</pre>
</body>

View File

@ -78,6 +78,8 @@ function checkValidity(aElement, aValidity, aApply)
(aElement.wil && aValidity) ? ":invalid shouldn't apply" : "valid should apply");
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({'set': [["dom.experimental_forms", true]]}, function() {
for each (var data in types) {
input.type = data[0];
var apply = data[1];
@ -248,6 +250,9 @@ for each (var data in types) {
input.value = '';
}
SimpleTest.finish();
});
</script>
</pre>
</body>

View File

@ -336,11 +336,17 @@ function checkStepUpForNumber()
}
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({'set': [["dom.experimental_forms", true]]}, function() {
checkPresence();
checkAvailability();
checkStepDownForNumber();
checkStepUpForNumber();
SimpleTest.finish();
});
</script>
</pre>
</body>

View File

@ -285,6 +285,8 @@ function checkValidityStateObjectAliveWithoutElement(element)
ok(v.valid, "When the element is not alive, it should be valid");
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({'set': [["dom.experimental_forms", true]]}, function() {
checkConstraintValidationAPIExist(document.getElementById('f'));
checkConstraintValidationAPIExist(document.getElementById('i'));
checkConstraintValidationAPIExist(document.getElementById('b'));
@ -339,6 +341,9 @@ checkValidityStateObjectAliveWithoutElement("textarea");
checkValidityStateObjectAliveWithoutElement("output");
checkValidityStateObjectAliveWithoutElement("object");
SimpleTest.finish();
});
</script>
</pre>
</body>

View File

@ -166,10 +166,15 @@ function checkSet()
}
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({'set': [["dom.experimental_forms", true]]}, function() {
checkAvailability();
checkGet();
checkSet();
SimpleTest.finish();
});
</script>
</pre>
</body>

View File

@ -131,6 +131,8 @@ function checkSanitizing(element)
}
}
var pref = SpecialPowers.getBoolPref("dom.experimental_forms");
SpecialPowers.setBoolPref("dom.experimental_forms", true);
for each (type in inputTypes) {
var form = document.forms[0];
var element = document.createElement("input");
@ -166,6 +168,8 @@ for each (type in todoTypes) {
form.removeChild(element);
}
SpecialPowers.setBoolPref("dom.experimental_forms", pref);
</script>
</pre>
</body>

View File

@ -647,6 +647,9 @@ pref("dom.min_background_timeout_value", 1000);
pref("dom.new_bindings", true);
pref("dom.experimental_bindings", true);
// Don't use new input types
pref("dom.experimental_forms", false);
// Parsing perf prefs. For now just mimic what the old code did.
#ifndef XP_WIN
pref("content.sink.pending_event_mode", 0);