зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1346872 - part3 : add and modify test. r=Ehsan
Add new tests and move some share codes to head.js. MozReview-Commit-ID: GcCio6JupZu --HG-- extra : rebase_source : a9324aaebd89412d77bed19b0554e6cf2959b6e2
This commit is contained in:
Родитель
611c9842fe
Коммит
dd5be9dee0
|
@ -3,6 +3,7 @@
|
|||
<head>
|
||||
<title>Mute window before the plugin starts playing</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="application/javascript" src="plugin.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
|
@ -12,39 +13,6 @@
|
|||
|
||||
<script type="application/javascript">
|
||||
|
||||
// Copied from /dom/plugins/test/mochitest/utils.js
|
||||
function getTestPlugin(pluginName) {
|
||||
var ph = SpecialPowers.Cc["@mozilla.org/plugin/host;1"]
|
||||
.getService(SpecialPowers.Ci.nsIPluginHost);
|
||||
var tags = ph.getPluginTags();
|
||||
var name = pluginName || "Test Plug-in";
|
||||
for (var tag of tags) {
|
||||
if (tag.name == name) {
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
|
||||
ok(false, "Could not find plugin tag with plugin name '" + name + "'");
|
||||
return null;
|
||||
}
|
||||
// Copied from /dom/plugins/test/mochitest/utils.js
|
||||
function setTestPluginEnabledState(newEnabledState, pluginName) {
|
||||
var oldEnabledState = SpecialPowers.setTestPluginEnabledState(newEnabledState, pluginName);
|
||||
if (!oldEnabledState) {
|
||||
return;
|
||||
}
|
||||
var plugin = getTestPlugin(pluginName);
|
||||
while (plugin.enabledState != newEnabledState) {
|
||||
// Run a nested event loop to wait for the preference change to
|
||||
// propagate to the child. Yuck!
|
||||
SpecialPowers.Services.tm.currentThread.processNextEvent(true);
|
||||
}
|
||||
SimpleTest.registerCleanupFunction(function() {
|
||||
SpecialPowers.setTestPluginEnabledState(oldEnabledState, pluginName);
|
||||
});
|
||||
}
|
||||
setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
function runTest() {
|
||||
|
@ -59,6 +27,9 @@ function runTest() {
|
|||
ok(iframe.contentWindow.pluginMuted(), "Plugin should still be muted after playing");
|
||||
|
||||
iframe.contentWindow.stopAudio();
|
||||
|
||||
// Reset the window's mute state, avoid to interrupt other tests.
|
||||
iframe.contentWindow.toggleMuteState(false);
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
|
|
|
@ -73,6 +73,10 @@ tags = audiochannel
|
|||
tags = audiochannel
|
||||
[browser_mute2.js]
|
||||
tags = audiochannel
|
||||
[browser_mute_plugIn.js]
|
||||
tags = audiochannel
|
||||
[browser_mute_webAudio.js]
|
||||
tags = audiochannel
|
||||
[browser_quickfind_editable.js]
|
||||
[browser_save_resend_postdata.js]
|
||||
support-files =
|
||||
|
|
|
@ -7,32 +7,6 @@ var SuspendedType = {
|
|||
SUSPENDED_PAUSE_DISPOSABLE: 3
|
||||
};
|
||||
|
||||
function disable_non_test_mouse(disable) {
|
||||
let utils = window.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIDOMWindowUtils);
|
||||
utils.disableNonTestMouseEvents(disable);
|
||||
}
|
||||
|
||||
function* hover_icon(icon, tooltip) {
|
||||
disable_non_test_mouse(true);
|
||||
|
||||
let popupShownPromise = BrowserTestUtils.waitForEvent(tooltip, "popupshown");
|
||||
EventUtils.synthesizeMouse(icon, 1, 1, {type: "mouseover"});
|
||||
EventUtils.synthesizeMouse(icon, 2, 2, {type: "mousemove"});
|
||||
EventUtils.synthesizeMouse(icon, 3, 3, {type: "mousemove"});
|
||||
EventUtils.synthesizeMouse(icon, 4, 4, {type: "mousemove"});
|
||||
return popupShownPromise;
|
||||
}
|
||||
|
||||
function leave_icon(icon) {
|
||||
EventUtils.synthesizeMouse(icon, 0, 0, {type: "mouseout"});
|
||||
EventUtils.synthesizeMouseAtCenter(document.documentElement, {type: "mousemove"});
|
||||
EventUtils.synthesizeMouseAtCenter(document.documentElement, {type: "mousemove"});
|
||||
EventUtils.synthesizeMouseAtCenter(document.documentElement, {type: "mousemove"});
|
||||
|
||||
disable_non_test_mouse(false);
|
||||
}
|
||||
|
||||
function* click_unblock_icon(tab) {
|
||||
let icon = document.getAnonymousElementByAttribute(tab, "anonid", "soundplaying-icon");
|
||||
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
const PAGE = "https://example.com/browser/toolkit/content/tests/browser/file_plugIn.html";
|
||||
|
||||
function* click_icon(tab) {
|
||||
let icon = document.getAnonymousElementByAttribute(tab, "anonid", "soundplaying-icon");
|
||||
|
||||
yield hover_icon(icon, document.getElementById("tabbrowser-tab-tooltip"));
|
||||
EventUtils.synthesizeMouseAtCenter(icon, {button: 0});
|
||||
leave_icon(icon);
|
||||
}
|
||||
|
||||
function start_plugin(suspendedType) {
|
||||
var startButton = content.document.getElementById("start");
|
||||
if (!startButton) {
|
||||
ok(false, "Can't get the start button!");
|
||||
}
|
||||
|
||||
startButton.click();
|
||||
}
|
||||
|
||||
function stop_plugin(suspendedType) {
|
||||
var stopButton = content.document.getElementById("stop");
|
||||
if (!stopButton) {
|
||||
ok(false, "Can't get the stop button!");
|
||||
}
|
||||
|
||||
stopButton.click();
|
||||
}
|
||||
|
||||
add_task(function* setup_test_preference() {
|
||||
setTestPluginEnabledState(Ci.nsIPluginTag.STATE_ENABLED, "Test Plug-in");
|
||||
yield SpecialPowers.pushPrefEnv({"set": [
|
||||
["media.useAudioChannelService.testing", true],
|
||||
["media.block-autoplay-until-in-foreground", true]
|
||||
]});
|
||||
});
|
||||
|
||||
add_task(function* block_plug_in() {
|
||||
info("- open new tab -");
|
||||
let tab = yield BrowserTestUtils.openNewForegroundTab(window.gBrowser,
|
||||
"about:blank");
|
||||
tab.linkedBrowser.loadURI(PAGE);
|
||||
yield BrowserTestUtils.browserLoaded(tab.linkedBrowser);
|
||||
|
||||
info("- tab should be audible -");
|
||||
yield waitForTabPlayingEvent(tab, true);
|
||||
|
||||
info("- mute browser -");
|
||||
ok(!tab.linkedBrowser.audioMuted, "Audio should not be muted by default");
|
||||
yield click_icon(tab);
|
||||
ok(tab.linkedBrowser.audioMuted, "Audio should be muted now");
|
||||
|
||||
info("- stop plugin -");
|
||||
yield ContentTask.spawn(tab.linkedBrowser, null, stop_plugin);
|
||||
|
||||
info("- start plugin -");
|
||||
yield ContentTask.spawn(tab.linkedBrowser, null, start_plugin);
|
||||
|
||||
info("- unmute browser -");
|
||||
ok(tab.linkedBrowser.audioMuted, "Audio should be muted now");
|
||||
yield click_icon(tab);
|
||||
ok(!tab.linkedBrowser.audioMuted, "Audio should be unmuted now");
|
||||
|
||||
info("- tab should be audible -");
|
||||
yield waitForTabPlayingEvent(tab, true);
|
||||
|
||||
info("- remove tab -");
|
||||
yield BrowserTestUtils.removeTab(tab);
|
||||
});
|
|
@ -0,0 +1,68 @@
|
|||
const PAGE = "https://example.com/browser/toolkit/content/tests/browser/file_webAudio.html";
|
||||
|
||||
function* click_icon(tab) {
|
||||
let icon = document.getAnonymousElementByAttribute(tab, "anonid", "soundplaying-icon");
|
||||
|
||||
yield hover_icon(icon, document.getElementById("tabbrowser-tab-tooltip"));
|
||||
EventUtils.synthesizeMouseAtCenter(icon, {button: 0});
|
||||
leave_icon(icon);
|
||||
}
|
||||
|
||||
function start_webAudio() {
|
||||
var startButton = content.document.getElementById("start");
|
||||
if (!startButton) {
|
||||
ok(false, "Can't get the start button!");
|
||||
}
|
||||
|
||||
startButton.click();
|
||||
}
|
||||
|
||||
function stop_webAudio() {
|
||||
var stopButton = content.document.getElementById("stop");
|
||||
if (!stopButton) {
|
||||
ok(false, "Can't get the stop button!");
|
||||
}
|
||||
|
||||
stopButton.click();
|
||||
}
|
||||
|
||||
add_task(function* setup_test_preference() {
|
||||
setTestPluginEnabledState(Ci.nsIPluginTag.STATE_ENABLED, "Test Plug-in");
|
||||
yield SpecialPowers.pushPrefEnv({"set": [
|
||||
["media.useAudioChannelService.testing", true],
|
||||
["media.block-autoplay-until-in-foreground", true]
|
||||
]});
|
||||
});
|
||||
|
||||
add_task(function* mute_web_audio() {
|
||||
info("- open new tab -");
|
||||
let tab = yield BrowserTestUtils.openNewForegroundTab(window.gBrowser,
|
||||
"about:blank");
|
||||
tab.linkedBrowser.loadURI(PAGE);
|
||||
yield BrowserTestUtils.browserLoaded(tab.linkedBrowser);
|
||||
|
||||
info("- tab should be audible -");
|
||||
yield waitForTabPlayingEvent(tab, true);
|
||||
|
||||
info("- mute browser -");
|
||||
ok(!tab.linkedBrowser.audioMuted, "Audio should not be muted by default");
|
||||
yield click_icon(tab);
|
||||
ok(tab.linkedBrowser.audioMuted, "Audio should be muted now");
|
||||
|
||||
info("- stop web audip -");
|
||||
yield ContentTask.spawn(tab.linkedBrowser, null, stop_webAudio);
|
||||
|
||||
info("- start web audio -");
|
||||
yield ContentTask.spawn(tab.linkedBrowser, null, start_webAudio);
|
||||
|
||||
info("- unmute browser -");
|
||||
ok(tab.linkedBrowser.audioMuted, "Audio should be muted now");
|
||||
yield click_icon(tab);
|
||||
ok(!tab.linkedBrowser.audioMuted, "Audio should be unmuted now");
|
||||
|
||||
info("- tab should be audible -");
|
||||
yield waitForTabPlayingEvent(tab, true);
|
||||
|
||||
info("- remove tab -");
|
||||
yield BrowserTestUtils.removeTab(tab);
|
||||
});
|
|
@ -5,4 +5,15 @@ var plugin = document.querySelector("embed");
|
|||
onload = function() {
|
||||
plugin.startAudioPlayback();
|
||||
};
|
||||
</script>
|
||||
|
||||
function start_plugin() {
|
||||
plugin.startAudioPlayback();
|
||||
}
|
||||
|
||||
function stop_plugin() {
|
||||
plugin.stopAudioPlayback();
|
||||
}
|
||||
|
||||
</script>
|
||||
<button id="start" onclick="start_plugin()">Start</button>
|
||||
<button id="stop" onclick="stop_plugin()">Stop</button>
|
||||
|
|
|
@ -9,6 +9,16 @@
|
|||
var osc = ac.createOscillator();
|
||||
osc.connect(dest);
|
||||
osc.start();
|
||||
|
||||
function start_webaudio() {
|
||||
ac.resume();
|
||||
}
|
||||
|
||||
function stop_webaudio() {
|
||||
ac.suspend();
|
||||
}
|
||||
</script>
|
||||
<body>
|
||||
<button id="start" onclick="start_webaudio()">Start</button>
|
||||
<button id="stop" onclick="stop_webaudio()">Stop</button>
|
||||
</body>
|
|
@ -98,3 +98,29 @@ function setTestPluginEnabledState(newEnabledState, pluginName) {
|
|||
SpecialPowers.setTestPluginEnabledState(oldEnabledState, pluginName);
|
||||
});
|
||||
}
|
||||
|
||||
function disable_non_test_mouse(disable) {
|
||||
let utils = window.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIDOMWindowUtils);
|
||||
utils.disableNonTestMouseEvents(disable);
|
||||
}
|
||||
|
||||
function* hover_icon(icon, tooltip) {
|
||||
disable_non_test_mouse(true);
|
||||
|
||||
let popupShownPromise = BrowserTestUtils.waitForEvent(tooltip, "popupshown");
|
||||
EventUtils.synthesizeMouse(icon, 1, 1, {type: "mouseover"});
|
||||
EventUtils.synthesizeMouse(icon, 2, 2, {type: "mousemove"});
|
||||
EventUtils.synthesizeMouse(icon, 3, 3, {type: "mousemove"});
|
||||
EventUtils.synthesizeMouse(icon, 4, 4, {type: "mousemove"});
|
||||
return popupShownPromise;
|
||||
}
|
||||
|
||||
function leave_icon(icon) {
|
||||
EventUtils.synthesizeMouse(icon, 0, 0, {type: "mouseout"});
|
||||
EventUtils.synthesizeMouseAtCenter(document.documentElement, {type: "mousemove"});
|
||||
EventUtils.synthesizeMouseAtCenter(document.documentElement, {type: "mousemove"});
|
||||
EventUtils.synthesizeMouseAtCenter(document.documentElement, {type: "mousemove"});
|
||||
|
||||
disable_non_test_mouse(false);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче