From 0a18092e350e05529c011d1cab7c5b0856d53ff1 Mon Sep 17 00:00:00 2001 From: Jim Mathies Date: Mon, 19 Oct 2015 10:38:42 -0500 Subject: [PATCH] Bug 1214878 - add tests. r=roc --- dom/plugins/test/mochitest/browser.ini | 2 + .../test/mochitest/browser_pluginscroll.js | 139 +++++++++++++++++- .../test/mochitest/plugin_no_scroll_div.html | 10 ++ .../test/mochitest/plugin_subframe_test.html | 10 ++ 4 files changed, 156 insertions(+), 5 deletions(-) create mode 100644 dom/plugins/test/mochitest/plugin_no_scroll_div.html create mode 100644 dom/plugins/test/mochitest/plugin_subframe_test.html diff --git a/dom/plugins/test/mochitest/browser.ini b/dom/plugins/test/mochitest/browser.ini index b169c46f279f..ea83e3395551 100644 --- a/dom/plugins/test/mochitest/browser.ini +++ b/dom/plugins/test/mochitest/browser.ini @@ -2,6 +2,8 @@ support-files = head.js plugin_test.html + plugin_subframe_test.html + plugin_no_scroll_div.html [browser_bug1163570.js] skip-if = (!e10s || os != "win") diff --git a/dom/plugins/test/mochitest/browser_pluginscroll.js b/dom/plugins/test/mochitest/browser_pluginscroll.js index 1cb9f99c8c1c..7314b84103fc 100644 --- a/dom/plugins/test/mochitest/browser_pluginscroll.js +++ b/dom/plugins/test/mochitest/browser_pluginscroll.js @@ -40,7 +40,7 @@ add_task(function*() { }); /* - * test plugin visibility when scrolling with scroll wheel and apz. + * test plugin visibility when scrolling with scroll wheel and apz in a top level document. */ add_task(function* () { @@ -105,10 +105,74 @@ add_task(function* () { }); /* - * test visibility when scrolling with keyboard shortcuts. This circumvents apz - * and relies on dom scroll, which is what we want to target for this test. Note - * this test should only run with e10s since we do not hide plugin windows when - * scrolling in single process mode. + * test plugin visibility when scrolling with scroll wheel and apz in a sub document. + */ + +add_task(function* () { + let result; + + if (!apzEnabled) { + ok(true, "nothing to test, need apz"); + return; + } + + if (!pluginHideEnabled) { + ok(true, "nothing to test, need gfx.e10s.hide-plugins-for-scroll"); + return; + } + + setTestPluginEnabledState(Ci.nsIPluginTag.STATE_ENABLED, "Test Plug-in"); + + let testTab = gBrowser.selectedTab; + let pluginTab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, gTestRoot + "plugin_subframe_test.html"); + + result = yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() { + let doc = content.document.getElementById("subframe").contentDocument; + let plugin = doc.getElementById("testplugin"); + return !!plugin; + }); + is(result, true, "plugin is loaded"); + + result = yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() { + let doc = content.document.getElementById("subframe").contentDocument; + let plugin = doc.getElementById("testplugin"); + return XPCNativeWrapper.unwrap(plugin).nativeWidgetIsVisible(); + }); + is(result, true, "plugin is visible"); + + let nativeId = nativeVerticalWheelEventMsg(); + let utils = SpecialPowers.getDOMWindowUtils(window); + let screenCoords = coordinatesRelativeToWindow(10, 10, + gBrowser.selectedBrowser); + utils.sendNativeMouseScrollEvent(screenCoords.x, screenCoords.y, + nativeId, 0, -50, 0, 0, 0, + gBrowser.selectedBrowser); + + yield waitScrollStart(gBrowser.selectedBrowser); + + result = yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() { + let doc = content.document.getElementById("subframe").contentDocument; + let plugin = doc.getElementById("testplugin"); + return XPCNativeWrapper.unwrap(plugin).nativeWidgetIsVisible(); + }); + is(result, false, "plugin is hidden"); + + yield waitScrollFinish(gBrowser.selectedBrowser); + + result = yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() { + let doc = content.document.getElementById("subframe").contentDocument; + let plugin = doc.getElementById("testplugin"); + return XPCNativeWrapper.unwrap(plugin).nativeWidgetIsVisible(); + }); + is(result, true, "plugin is visible"); + + gBrowser.removeTab(pluginTab); +}); + +/* + * test visibility when scrolling with keyboard shortcuts for a top level document. + * This circumvents apz and relies on dom scroll, which is what we want to target + * for this test. */ add_task(function* () { @@ -171,3 +235,68 @@ add_task(function* () { gBrowser.removeTab(pluginTab); }); + +/* + * test visibility when scrolling with keyboard shortcuts for a sub document. + */ + +add_task(function* () { + let result; + + if (!pluginHideEnabled) { + ok(true, "nothing to test, need gfx.e10s.hide-plugins-for-scroll"); + return; + } + + setTestPluginEnabledState(Ci.nsIPluginTag.STATE_ENABLED, "Test Plug-in"); + + let testTab = gBrowser.selectedTab; + let pluginTab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, gTestRoot + "plugin_subframe_test.html"); + + result = yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() { + let doc = content.document.getElementById("subframe").contentDocument; + let plugin = doc.getElementById("testplugin"); + return !!plugin; + }); + is(result, true, "plugin is loaded"); + + result = yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() { + let doc = content.document.getElementById("subframe").contentDocument; + let plugin = doc.getElementById("testplugin"); + return XPCNativeWrapper.unwrap(plugin).nativeWidgetIsVisible(); + }); + is(result, true, "plugin is visible"); + + EventUtils.synthesizeKey("VK_END", {}); + + yield waitScrollStart(gBrowser.selectedBrowser); + + result = yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() { + let doc = content.document.getElementById("subframe").contentDocument; + let plugin = doc.getElementById("testplugin"); + return XPCNativeWrapper.unwrap(plugin).nativeWidgetIsVisible(); + }); + is(result, false, "plugin is hidden"); + + yield waitScrollFinish(gBrowser.selectedBrowser); + + result = yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() { + let doc = content.document.getElementById("subframe").contentDocument; + let plugin = doc.getElementById("testplugin"); + return XPCNativeWrapper.unwrap(plugin).nativeWidgetIsVisible(); + }); + is(result, false, "plugin is hidden"); + + EventUtils.synthesizeKey("VK_HOME", {}); + + yield waitScrollFinish(gBrowser.selectedBrowser); + + result = yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() { + let doc = content.document.getElementById("subframe").contentDocument; + let plugin = doc.getElementById("testplugin"); + return XPCNativeWrapper.unwrap(plugin).nativeWidgetIsVisible(); + }); + is(result, true, "plugin is visible"); + + gBrowser.removeTab(pluginTab); +}); diff --git a/dom/plugins/test/mochitest/plugin_no_scroll_div.html b/dom/plugins/test/mochitest/plugin_no_scroll_div.html new file mode 100644 index 000000000000..15ec2918bf26 --- /dev/null +++ b/dom/plugins/test/mochitest/plugin_no_scroll_div.html @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/dom/plugins/test/mochitest/plugin_subframe_test.html b/dom/plugins/test/mochitest/plugin_subframe_test.html new file mode 100644 index 000000000000..8f20c1dc856f --- /dev/null +++ b/dom/plugins/test/mochitest/plugin_subframe_test.html @@ -0,0 +1,10 @@ + + + + + + + +
+ +