toolkit/components/extensions/test/mochitest/test_ext_background_api_injection.html
author Kris Maglione <maglione.k@gmail.com>
Tue, 22 Dec 2015 23:43:23 -0500
changeset 317182 a357c7e76527ac42fc450826d37f57c3c99ad97f
parent 310805 f127897cdf0193ac09fa96f6f5bec5d2ae2d2331
child 324716 b76ab3324cd20c8743af4d6695977c67e99ed3fa
permissions -rw-r--r--
Bug 1234755: [webext] Make JS in HTML files pass ESLint. r?billm This also changes the `type` attribute in our script tags to text/javascript, since that's currently all the eslint-html plugin supports.

<!DOCTYPE HTML>
<html>
<head>
  <title>Test for privilege escalation into content pages</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
  <script type="text/javascript" src="head.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>

<script type="text/javascript">
"use strict";

add_task(function* testBackgroundWindow() {
  let extension = ExtensionTestUtils.loadExtension({
    background: "new " + function() {
      const BASE = "http://mochi.test:8888/tests/toolkit/components/extensions/test/mochitest";

      browser.test.log("background script executed");
      window.location = `${BASE}/file_privilege_escalation.html`;
    },
  });

  let awaitConsole = new Promise(resolve => {
    let chromeScript = SpecialPowers.loadChromeScript(
      SimpleTest.getTestFileURL("file_ext_background_api_injection.js"));

    chromeScript.addMessageListener("console-message", resolve);
  });

  yield extension.startup();

  let message = yield awaitConsole;

  ok(message.message.includes("WebExt Privilege Escalation: typeof(browser) = undefined"),
     "Document does not have `browser` APIs.");

  yield extension.unload();
});

</script>

</body>
</html>