1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/b2g/components/test/mochitest/permission_handler_chrome.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,36 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +"use strict"; 1.9 + 1.10 +function debug(str) { 1.11 + dump("CHROME PERMISSON HANDLER -- " + str + "\n"); 1.12 +} 1.13 + 1.14 +const Cc = Components.classes; 1.15 +const Ci = Components.interfaces; 1.16 +const Cu = Components.utils; 1.17 + 1.18 +const { Services } = Cu.import("resource://gre/modules/Services.jsm"); 1.19 +const { SystemAppProxy } = Cu.import("resource://gre/modules/SystemAppProxy.jsm"); 1.20 + 1.21 +let eventHandler = function(evt) { 1.22 + if (!evt.detail || evt.detail.type !== "permission-prompt") { 1.23 + return; 1.24 + } 1.25 + 1.26 + sendAsyncMessage("permission-request", evt.detail); 1.27 +}; 1.28 + 1.29 +SystemAppProxy.addEventListener("mozChromeEvent", eventHandler); 1.30 + 1.31 +// need to remove ChromeEvent listener after test finished. 1.32 +addMessageListener("teardown", function() { 1.33 + SystemAppProxy.removeEventListener("mozChromeEvent", eventHandler); 1.34 +}); 1.35 + 1.36 +addMessageListener("permission-response", function(detail) { 1.37 + SystemAppProxy._sendCustomEvent('mozContentEvent', detail); 1.38 +}); 1.39 +