mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 677122 - Update start/end times of mediafragment URL on hashchanges. r=bz
This commit is contained in:
parent
4d7499d6b0
commit
f955145443
@ -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))
|
||||
|
85
content/html/document/test/test_bug677122.html
Normal file
85
content/html/document/test/test_bug677122.html
Normal 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>
|
||||
<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>
|
Loading…
Reference in New Issue
Block a user