Bug 601881 - video and audio should never play automatically in editor; r=bzbarsky,cpearce a=bsmedberg

--HG--
rename : content/media/test/test_play_events.html => content/media/test/test_autoplay_contentEditable.html
This commit is contained in:
Ehsan Akhgari 2010-10-14 20:13:29 -04:00
parent 3d5ca7986b
commit e7bc30c680
6 changed files with 73 additions and 75 deletions

View File

@ -647,9 +647,6 @@ protected:
// readyState change to HAVE_CURRENT_DATA.
PRPackedBool mWaitingFired;
// PR_TRUE if we're in BindToTree().
PRPackedBool mIsBindingToTree;
// PR_TRUE if we're running the "load()" method.
PRPackedBool mIsRunningLoadMethod;

View File

@ -389,8 +389,7 @@ NS_IMPL_STRING_ATTR(nsHTMLMediaElement, Preload, preload)
/* readonly attribute nsIDOMHTMLMediaElement mozAutoplayEnabled; */
NS_IMETHODIMP nsHTMLMediaElement::GetMozAutoplayEnabled(PRBool *aAutoplayEnabled)
{
// Do not allow autoplay on editable nodes
*aAutoplayEnabled = !IsEditable() && mAutoplayEnabled;
*aAutoplayEnabled = mAutoplayEnabled;
return NS_OK;
}
@ -1287,7 +1286,6 @@ nsHTMLMediaElement::nsHTMLMediaElement(already_AddRefed<nsINodeInfo> aNodeInfo,
mPlayingBeforeSeek(PR_FALSE),
mPausedForInactiveDocument(PR_FALSE),
mWaitingFired(PR_FALSE),
mIsBindingToTree(PR_FALSE),
mIsRunningLoadMethod(PR_FALSE),
mIsLoadingFromSourceChildren(PR_FALSE),
mDelayingLoadEvent(PR_FALSE),
@ -1496,19 +1494,18 @@ nsresult nsHTMLMediaElement::BindToTree(nsIDocument* aDocument, nsIContent* aPar
nsIContent* aBindingParent,
PRBool aCompileEventHandlers)
{
if (aDocument) {
mIsBindingToTree = PR_TRUE;
mAutoplayEnabled =
IsAutoplayEnabled() && (!aDocument || !aDocument->IsStaticDocument());
// The preload action depends on the value of the autoplay attribute.
// It's value may have changed, so update it.
UpdatePreloadAction();
}
nsresult rv = nsGenericHTMLElement::BindToTree(aDocument,
aParent,
aBindingParent,
aCompileEventHandlers);
mIsBindingToTree = PR_FALSE;
if (aDocument) {
mAutoplayEnabled =
IsAutoplayEnabled() && (!aDocument || !aDocument->IsStaticDocument()) &&
!IsEditable();
// The preload action depends on the value of the autoplay attribute.
// It's value may have changed, so update it.
UpdatePreloadAction();
}
return rv;
}
@ -2180,7 +2177,8 @@ PRBool nsHTMLMediaElement::CanActivateAutoplay()
return mAutoplaying &&
mPaused &&
HasAttr(kNameSpaceID_None, nsGkAtoms::autoplay) &&
mAutoplayEnabled;
mAutoplayEnabled &&
!IsEditable();
}
void nsHTMLMediaElement::NotifyAutoplayDataReady()

View File

@ -93,6 +93,7 @@ _TEST_FILES = \
test_audio1.html \
test_audio2.html \
test_autoplay.html \
test_autoplay_contentEditable.html \
test_buffered.html \
test_bug448534.html \
test_bug463162.xhtml \

View File

@ -0,0 +1,61 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Media test: play() method</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script type="text/javascript" src="manifest.js"></script>
</head>
<body contenteditable="true">
<pre id="test">
<script>
var manager = new MediaTestManager;
var tokens = {
0: ["canplay"],
"canplay": ["canplaythrough"],
"canplaythrough": ["canplay", "canplaythrough"]
};
function gotPlayEvent(event) {
var v = event.target;
ok(tokens[v._state].indexOf(event.type) >= 0,
"Check expected event got " + event.type + " at " + v._state + " for " + v.src +
" uneval(event.type)=" + uneval(event.type) + " typeof(event.type)=" + typeof(event.type) +
" uneval(v._state)=" + uneval(v._state) + " typeof(v._state)=" + typeof(v._state) +
" tokens["+v._state+"]=" + tokens[v._state] +
" tokens["+v._state+"].indexOf(event.type)=" + tokens[v._state].indexOf(event.type));
v._state = event.type;
}
function goToNext(v) {
v.parentNode.removeChild(v);
manager.finished(v.token);
}
function initTest(test, token) {
var v = document.createElement('video');
v.token = token;
manager.started(token);
v._state = 0;
["play", "canplay", "playing", "canplaythrough", "ended"].forEach(function (e) {
v.addEventListener(e, gotPlayEvent, false);
});
setTimeout(function() goToNext(v), 500);
v.src = test.name;
v.autoplay = true;
document.body.appendChild(v); // Causes load.
}
manager.runTests(gSmallTests, initTest);
</script>
</pre>
</body>
</html>

View File

@ -66,7 +66,6 @@ _TEST_FILES = \
test_bug592592.html \
test_bug597784.html \
test_bug599322.html \
test_bug601881.html \
test_bug607584.html \
test_CF_HTML_clipboard.html \
test_contenteditable_focus.html \

View File

@ -1,58 +0,0 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=601881
-->
<head>
<title>Test for Bug 601881</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.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=601881">Mozilla Bug 601881</a>
<p id="display"></p>
<div id="content">
<video id="v"></video>
<audio id="a"></audio>
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 601881 **/
var v = document.getElementById("v");
var a = document.getElementById("a");
var content = document.getElementById("content");
function runPass(makeEditable, makeUneditable, callback) {
is(v.mozAutoplayEnabled, true, "Video should be autoplay-able when not made editable yet");
is(a.mozAutoplayEnabled, true, "Audio should be autoplay-able when not made editable yet");
makeEditable();
is(v.mozAutoplayEnabled, false, "Video should not be autoplay-able when made editable");
is(a.mozAutoplayEnabled, false, "Audio should not be autoplay-able ehen made editable");
makeUneditable();
is(v.mozAutoplayEnabled, true, "Video should be autoplay-able after being made uneditable");
is(a.mozAutoplayEnabled, true, "Audio should be autoplay-able after being made uneditable");
callback();
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
runPass(function () document.designMode = 'on',
function () document.designMode = 'off',
function () {
runPass(function() content.setAttribute("contenteditable", "true"),
function() content.removeAttribute("contenteditable"),
function() SimpleTest.finish()
)
}
);
});
</script>
</pre>
</body>
</html>