Bug 1364505 - Write tests for plugin favor-fallback mode. r=qDot

MozReview-Commit-ID: AefeRMb9t9q

--HG--
rename : layout/generic/crashtests/simple_blank.swf => browser/base/content/test/plugins/plugin_simple_blank.swf
This commit is contained in:
Felipe Gomes 2017-05-16 22:56:22 -03:00
parent c18d8c931c
commit b5204da9bc
4 changed files with 183 additions and 0 deletions

View File

@ -22,11 +22,13 @@ support-files =
plugin_clickToPlayAllow.html
plugin_clickToPlayDeny.html
plugin_data_url.html
plugin_favorfallback.html
plugin_hidden_to_visible.html
plugin_iframe.html
plugin_outsideScrollArea.html
plugin_overlayed.html
plugin_positioned.html
plugin_simple_blank.swf
plugin_small.html
plugin_small_2.html
plugin_syncRemoved.html
@ -59,6 +61,7 @@ tags = blocklist
tags = blocklist
[browser_CTP_drag_drop.js]
tags = blocklist
[browser_CTP_favorfallback.js]
[browser_CTP_hide_overlay.js]
tags = blocklist
[browser_CTP_iframe.js]

View File

@ -0,0 +1,84 @@
var rootDir = getRootDirectory(gTestPath);
const gTestRoot = rootDir.replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");
var gPluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost);
add_task(async function() {
registerCleanupFunction(function() {
clearAllPluginPermissions();
setTestPluginEnabledState(Ci.nsIPluginTag.STATE_ENABLED, "Shockwave Flash");
Services.prefs.clearUserPref("plugins.favorfallback.mode");
Services.prefs.clearUserPref("plugins.favorfallback.rules");
});
});
add_task(async function() {
Services.prefs.setCharPref("plugins.favorfallback.mode", "follow-ctp");
setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY, "Shockwave Flash");
});
/* The expected behavior of each testcase is documented with its markup
* in plugin_favorfallback.html.
*
* - "name" is the name of the testcase in the test file.
* - "rule" is how the plugins.favorfallback.rules must be configured
* for this testcase.
*/
const testcases = [
{
name: "video",
rule: "video",
},
{
name: "nosrc",
rule: "nosrc",
},
{
name: "embed",
rule: "embed,true",
},
{
name: "adobelink",
rule: "adobelink,true",
},
{
name: "installinstructions",
rule: "installinstructions,true",
},
];
add_task(async function() {
for (let testcase of Object.values(testcases)) {
info(`Running testcase ${testcase.name}`);
Services.prefs.setCharPref("plugins.favorfallback.rules", testcase.rule);
let tab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
`${gTestRoot}plugin_favorfallback.html?testcase=${testcase.name}`
);
await ContentTask.spawn(tab.linkedBrowser, testcase.name, async function testPlugins(name) {
let testcaseDiv = content.document.getElementById(`testcase_${name}`);
let ctpPlugins = testcaseDiv.querySelectorAll(".expected_ctp");
for (let ctpPlugin of ctpPlugins) {
ok(ctpPlugin instanceof Ci.nsIObjectLoadingContent, "This is a plugin object");
is(ctpPlugin.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, "Plugin is CTP");
}
let fallbackPlugins = testcaseDiv.querySelectorAll(".expected_fallback");
for (let fallbackPlugin of fallbackPlugins) {
ok(fallbackPlugin instanceof Ci.nsIObjectLoadingContent, "This is a plugin object");
is(fallbackPlugin.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_ALTERNATE, "Plugin fallback content was used");
}
});
await BrowserTestUtils.removeTab(tab);
}
})

View File

@ -0,0 +1,96 @@
<!DOCTYPE html>
<html>
<head><meta charset="utf-8"/></head>
<body>
<style>
.testcase {
display: none;
}
object {
width: 200px;
height: 200px;
}
</style>
<!-- Tests that a <video> tag in the fallback content favors the fallback content -->
<div id="testcase_video" class="testcase">
<object class="expected_ctp" type="application/x-shockwave-flash-test">
Unexpected fallback
</object>
<object class="expected_fallback" type="application/x-shockwave-flash-test">
<video></video>
Expected fallback
</object>
</div>
<!-- Tests that an object with no src specified (no data="") favors the fallback content -->
<div id="testcase_nosrc" class="testcase">
<!-- We must use an existing and valid file here because otherwise the failed load
triggers the plugin's alternate content, indepedent of the favor-fallback code path -->
<object class="expected_ctp" type="application/x-shockwave-flash-test" data="plugin_simple_blank.swf">
Unexpected fallback
</object>
<object class="expected_fallback" type="application/x-shockwave-flash-test">
Expected fallback
</object>
</div>
<!-- Tests that an <embed> tag in the fallback content forces the plugin content,
when fallback is defaulting to true -->
<div id="testcase_embed" class="testcase">
<object class="expected_ctp" type="application/x-shockwave-flash-test">
<embed></embed>
Unexpected fallback
</object>
<object class="expected_fallback" type="application/x-shockwave-flash-test">
Expected fallback
</object>
</div>
<!-- Tests that links to adobe.com inside the fallback content forces the plugin content,
when fallback is defaulting to true -->
<div id="testcase_adobelink" class="testcase">
<object class="expected_ctp" type="application/x-shockwave-flash-test">
<a href="https://www.adobe.com">Go to adobe.com</a>
Unexpected fallback
</object>
<object class="expected_ctp" type="application/x-shockwave-flash-test">
<a href="https://adobe.com">Go to adobe.com</a>
Unexpected fallback
</object>
<object class="expected_fallback" type="application/x-shockwave-flash-test">
Expected fallback
</object>
</div>
<!-- Tests that instructions to download or install flash inside the fallback content
forces the plugin content, when fallback is defaulting to true -->
<div id="testcase_installinstructions" class="testcase">
<object class="expected_ctp" type="application/x-shockwave-flash-test">
Install -- Unexpected fallback
</object>
<object class="expected_ctp" type="application/x-shockwave-flash-test">
Flash -- Unexpected fallback
</object>
<object class="expected_ctp" type="application/x-shockwave-flash-test">
Download -- Unexpected fallback
</object>
<object class="expected_fallback" type="application/x-shockwave-flash-test">
<!-- Tests that the words Install, Flash or Download do not trigger
this behavior if it's just inside a comment, and not part of
the text content -->
Expected Fallback
</object>
<object class="expected_fallback" type="application/x-shockwave-flash-test">
Expected fallback
</object>
</div>
<script>
let queryString = location.search;
let match = /^\?testcase=([a-z]+)$/.exec(queryString);
let testcase = match[1];
document.getElementById(`testcase_${testcase}`).style.display = "block";
</script>
</body>
</html>