diff --git a/b2g/components/test/mochitest/SandboxPromptTest.html b/b2g/components/test/mochitest/SandboxPromptTest.html new file mode 100644 index 000000000000..1fcaf09d822f --- /dev/null +++ b/b2g/components/test/mochitest/SandboxPromptTest.html @@ -0,0 +1,16 @@ + + + + + diff --git a/b2g/components/test/mochitest/mochitest.ini b/b2g/components/test/mochitest/mochitest.ini new file mode 100644 index 000000000000..9470fd792fae --- /dev/null +++ b/b2g/components/test/mochitest/mochitest.ini @@ -0,0 +1,7 @@ +[DEFAULT] +run-if = toolkit == "gonk" +support-files = + permission_handler_chrome.js + SandboxPromptTest.html + +[test_sandbox_permission.html] diff --git a/b2g/components/test/mochitest/permission_handler_chrome.js b/b2g/components/test/mochitest/permission_handler_chrome.js new file mode 100644 index 000000000000..1c8f4888fd3f --- /dev/null +++ b/b2g/components/test/mochitest/permission_handler_chrome.js @@ -0,0 +1,76 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +function debug(str) { + dump("CHROME PERMISSON HANDLER -- " + str + "\n"); +} + +const Cc = Components.classes; +const Ci = Components.interfaces; +const Cu = Components.utils; + +const { Services } = Cu.import("resource://gre/modules/Services.jsm"); + +let browser = Services.wm.getMostRecentWindow("navigator:browser"); +let shell; +let test_counts = 0; + +function loadShell() { + if (!browser) { + debug("no browser"); + return false; + } + shell = browser.shell; + return true; +} + +function getContentWindow() { + return shell.contentBrowser.contentWindow; +} + +function addChromeEventListener(type, listener) { + let content = getContentWindow(); + content.addEventListener("mozChromeEvent", function chromeListener(evt) { + if (!evt.detail || evt.detail.type !== type) { + return; + } + + let remove = listener(evt); + if (remove) { + content.removeEventListener("mozChromeEvent", chromeListener); + } + }); +} + +function checkPromptEvent(prompt_evt) { + let detail = prompt_evt.detail; + + if (detail.permission == "audio-capture") { + sendAsyncMessage("permission.granted", "audio-capture"); + test_counts--; + } else if (detail.permission == "desktop-notification") { + sendAsyncMessage("permission.granted", "desktop-notification"); + test_counts--; + } else if (detail.permission == "geolocation") { + sendAsyncMessage("permission.granted", "geolocation"); + test_counts--; + } + + if (!test_counts) { + debug("remove prompt event listener."); + return true; + } + + return false; +} + +if (loadShell()) { + addMessageListener("test.counts", function (counts) { + test_counts = counts; + }); + + addChromeEventListener("permission-prompt", checkPromptEvent); +} diff --git a/b2g/components/test/mochitest/test_sandbox_permission.html b/b2g/components/test/mochitest/test_sandbox_permission.html new file mode 100644 index 000000000000..360489e5ce98 --- /dev/null +++ b/b2g/components/test/mochitest/test_sandbox_permission.html @@ -0,0 +1,78 @@ + + + + + + Permission Prompt Test + + + + +Permission prompt web content test + + + + diff --git a/b2g/components/test/moz.build b/b2g/components/test/moz.build index 191c90f0b92d..b985130de0c3 100644 --- a/b2g/components/test/moz.build +++ b/b2g/components/test/moz.build @@ -5,3 +5,4 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini'] +MOCHITEST_MANIFESTS += ['mochitest/mochitest.ini'] diff --git a/testing/mochitest/b2g-debug.json b/testing/mochitest/b2g-debug.json index 3c9d71d5c417..653d34b2db53 100644 --- a/testing/mochitest/b2g-debug.json +++ b/testing/mochitest/b2g-debug.json @@ -1,5 +1,6 @@ { "runtests": { + "b2g": "", "caps": "", "content": "", "docshell": "", diff --git a/testing/mochitest/b2g-desktop.json b/testing/mochitest/b2g-desktop.json index f611c6216579..f3c9ca7111a3 100644 --- a/testing/mochitest/b2g-desktop.json +++ b/testing/mochitest/b2g-desktop.json @@ -1,5 +1,6 @@ { "runtests": { + "b2g": "", "caps": "", "content": "", "docshell": "", diff --git a/testing/mochitest/b2g.json b/testing/mochitest/b2g.json index 788ddc94c772..3ebd6a20bd48 100644 --- a/testing/mochitest/b2g.json +++ b/testing/mochitest/b2g.json @@ -1,5 +1,6 @@ { "runtests": { + "b2g": "", "caps": "", "content": "", "docshell": "",