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

This commit is contained in:
Scott Downe 2012-03-27 19:17:35 -04:00
Родитель 8d0603d771
Коммит acee3ce72b
4 изменённых файлов: 110 добавлений и 0 удалений

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

@ -363,6 +363,25 @@ MediaDocument::LinkStylesheet(const nsAString& aStylesheet)
return head->AppendChildTo(link, false);
}
void
MediaDocument::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);
}
void
MediaDocument::UpdateTitleAndCharset(const nsACString& aTypeStr,
const char* const* aFormatNames,
@ -439,6 +458,10 @@ MediaDocument::SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject)
nsContentUtils::AddScriptRunner(
new nsDocElementCreatedNotificationRunner(this));
}
if (aGlobalObject) {
InsertMediaFragmentScript();
}
}
} // namespace dom

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

@ -75,6 +75,7 @@ protected:
void GetFileName(nsAString& aResult);
nsresult LinkStylesheet(const nsAString& aStylesheet);
void InsertMediaFragmentScript();
// |aFormatNames[]| needs to have four elements in the following order:
// a format name with neither dimension nor file, a format name with

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

@ -106,6 +106,7 @@ _TEST_FILES = test_bug1682.html \
test_bug571981.html \
test_bug677495.html \
test_bug677495-1.html \
test_bug677122.html \
$(NULL)
ifneq (mobile,$(MOZ_BUILD_APP))

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

@ -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>
<iframe id = "iframe">
</iframe>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
var url = "../../../media/test/seek.ogv";
var iframe = document.getElementById("iframe");
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>