diff --git a/browser/base/content/test/plugins/browser.ini b/browser/base/content/test/plugins/browser.ini index 181c1dad6195..03abd87fa96a 100644 --- a/browser/base/content/test/plugins/browser.ini +++ b/browser/base/content/test/plugins/browser.ini @@ -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] diff --git a/browser/base/content/test/plugins/browser_CTP_favorfallback.js b/browser/base/content/test/plugins/browser_CTP_favorfallback.js new file mode 100644 index 000000000000..7ed6fed49df5 --- /dev/null +++ b/browser/base/content/test/plugins/browser_CTP_favorfallback.js @@ -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); + } +}) diff --git a/browser/base/content/test/plugins/plugin_favorfallback.html b/browser/base/content/test/plugins/plugin_favorfallback.html new file mode 100644 index 000000000000..6eaf15499446 --- /dev/null +++ b/browser/base/content/test/plugins/plugin_favorfallback.html @@ -0,0 +1,96 @@ + + + + + + + +
+ + Unexpected fallback + + + + Expected fallback + +
+ + +
+ + + Unexpected fallback + + + Expected fallback + +
+ + +
+ + + Unexpected fallback + + + Expected fallback + +
+ + + + + +
+ + Install -- Unexpected fallback + + + Flash -- Unexpected fallback + + + Download -- Unexpected fallback + + + + Expected Fallback + + + Expected fallback + +
+ + + + diff --git a/browser/base/content/test/plugins/plugin_simple_blank.swf b/browser/base/content/test/plugins/plugin_simple_blank.swf new file mode 100644 index 000000000000..b846387eb8b8 Binary files /dev/null and b/browser/base/content/test/plugins/plugin_simple_blank.swf differ