Bug 1364505 - Write tests for plugin favor-fallback mode. r=qDot
authorFelipe Gomes <felipc@gmail.com>
Tue, 16 May 2017 22:56:22 -0300
changeset 579415 e30e7ee30b7c7672ae4bf6265e63db5ae8829d53
parent 579414 f35b966ff0247b8adccde22222aee3814ad38919
child 579416 ddc27dd93ec08c707dbfb924d7b51a23861c96b7
push id59244
push usergsquelart@mozilla.com
push dateWed, 17 May 2017 09:45:34 +0000
reviewersqDot
bugs1364505
milestone55.0a1
Bug 1364505 - Write tests for plugin favor-fallback mode. r=qDot MozReview-Commit-ID: AefeRMb9t9q
browser/base/content/test/plugins/browser.ini
browser/base/content/test/plugins/browser_CTP_favorfallback.js
browser/base/content/test/plugins/plugin_favorfallback.html
browser/base/content/test/plugins/plugin_simple_blank.swf
--- a/browser/base/content/test/plugins/browser.ini
+++ b/browser/base/content/test/plugins/browser.ini
@@ -17,21 +17,23 @@ support-files =
   plugin_bug744745.html
   plugin_bug749455.html
   plugin_bug787619.html
   plugin_bug797677.html
   plugin_bug820497.html
   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
   plugin_test.html
   plugin_test2.html
   plugin_test3.html
   plugin_two_types.html
   plugin_unknown.html
@@ -54,16 +56,17 @@ skip-if = toolkit == "gtk2" || toolkit =
 tags = blocklist
 [browser_CTP_crashreporting.js]
 skip-if = !crashreporter
 tags = blocklist
 [browser_CTP_data_urls.js]
 tags = blocklist
 [browser_CTP_drag_drop.js]
 tags = blocklist
+[browser_CTP_favorfallback.js]
 [browser_CTP_hide_overlay.js]
 tags = blocklist
 [browser_CTP_iframe.js]
 tags = blocklist
 [browser_CTP_multi_allow.js]
 tags = blocklist
 [browser_CTP_nonplugins.js]
 tags = blocklist
new file mode 100644
--- /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);
+  }
+})
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/plugins/plugin_favorfallback.html
@@ -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>
copy from layout/generic/crashtests/simple_blank.swf
copy to browser/base/content/test/plugins/plugin_simple_blank.swf