main.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. "use strict";
  5. const { data } = require("sdk/self");
  6. const { Symbiont } = require("sdk/deprecated/symbiont");
  7. exports["test:direct communication with trusted document"] = function(assert, done) {
  8. let worker = Symbiont({
  9. contentURL: data.url("test-trusted-document.html")
  10. });
  11. worker.port.on('document-to-addon', function (arg) {
  12. assert.equal(arg, "ok", "Received an event from the document");
  13. worker.destroy();
  14. done();
  15. });
  16. worker.port.emit('addon-to-document', 'ok');
  17. };
  18. exports["test:`addon` is not available when a content script is set"] = function(assert, done) {
  19. let worker = Symbiont({
  20. contentURL: data.url("test-trusted-document.html"),
  21. contentScript: "new " + function ContentScriptScope() {
  22. self.port.emit("cs-to-addon", "addon" in unsafeWindow);
  23. }
  24. });
  25. worker.port.on('cs-to-addon', function (hasAddon) {
  26. assert.equal(hasAddon, false,
  27. "`addon` is not available");
  28. worker.destroy();
  29. done();
  30. });
  31. };
  32. require("sdk/test/runner").runTestsFromModule(module);