Bug 677122 - Update start/end times of mediafragment URL on hashchanges. r=bz

This commit is contained in:
Scott Downe 2012-04-11 07:49:20 -04:00
parent 98d9a07062
commit 89f1c3ab13
3 changed files with 111 additions and 1 deletions

View File

@ -63,6 +63,7 @@ protected:
// Sets document <title> to reflect the file name and description.
void UpdateTitle(nsIChannel* aChannel);
void InsertMediaFragmentScript();
nsresult CreateSyntheticVideoDocument(nsIChannel* aChannel,
nsIStreamListener** aListener);
@ -106,6 +107,29 @@ VideoDocument::SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject)
LinkStylesheet(NS_LITERAL_STRING("resource://gre/res/TopLevelVideoDocument.css"));
LinkStylesheet(NS_LITERAL_STRING("chrome://global/skin/TopLevelVideoDocument.css"));
}
if (aScriptGlobalObject) {
InsertMediaFragmentScript();
}
}
void
VideoDocument::InsertMediaFragmentScript()
{
nsCOMPtr<nsINodeInfo> nodeInfo;
nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::script, nsnull,
kNameSpaceID_XHTML,
nsIDOMNode::ELEMENT_NODE);
if (!nodeInfo)
{
return;
}
nsRefPtr<nsGenericHTMLElement> script = NS_NewHTMLScriptElement(nodeInfo.forget());
script->SetTextContent(NS_LITERAL_STRING("window.addEventListener('hashchange',function(e){document.querySelector('audio,video').src=e.newURL;},false);"));
Element* head = GetHeadElement();
head->AppendChildTo(script, false);
}
nsresult

View File

@ -104,10 +104,11 @@ _TEST_FILES = test_bug1682.html \
bug499092.html \
test_bug512367.html \
test_bug571981.html \
test_bug677122.html \
test_bug677495.html \
test_bug677495-1.html \
test_bug742261.html \
test_bug741266.html \
test_bug742261.html \
$(NULL)
ifneq (mobile,$(MOZ_BUILD_APP))

View File

@ -0,0 +1,85 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Media test: MediaDocument hashchange mediafragment.</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
var iframe = document.createElement("iframe");
document.body.appendChild(iframe);
var url = "../../../media/test/seek.ogv";
var expects = 5;
var count = 0;
var test;
var tests = [
{ start: 1, end: 2 },
{ start: 3, end: 4 }
];
var next = function () {
test = tests.shift();
if (test) {
iframe.src = url + "#t=" + test.start + "," + test.end;
} else {
ok(expects === ++count, "Expected number of tests run. Expected: " + expects + " Actual: " + count);
SimpleTest.finish();
}
};
iframe.addEventListener("load", function (e) {
var media = iframe.contentWindow.document.querySelector("audio,video");
media.addEventListener("seeked", function () {
var currentTime = Math.round(media.currentTime);
count++;
ok(currentTime === test.start, "Hashchange mediafragment start. Expected: " + test.start + " Actual: " + currentTime);
}, false);
media.addEventListener("pause", function () {
var currentTime = Math.round(media.currentTime);
if (count === 1) {
count++;
ok(currentTime === test.end, "Hashchange mediafragment end. Expected: " + test.end + " Actual: " + currentTime);
}
next();
}, false);
// having an ended event ensures we're more likely to fail, instead of timing out.
media.addEventListener("ended", function () {
var currentTime = Math.round(media.currentTime);
if (count === 3) {
count++;
ok(currentTime === test.end, "Hashchange mediafragment end. Expected: " + test.end + " Actual: " + currentTime);
}
next();
}, false);
next();
}, false);
iframe.src = url;
</script>
</pre>
</body>
</html>