toolkit/devtools/tests/mochitest/test_devtools_extensions.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/devtools/tests/mochitest/test_devtools_extensions.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,117 @@
     1.4 +<!DOCTYPE html>
     1.5 +<!--
     1.6 +  Any copyright is dedicated to the Public Domain.
     1.7 +  http://creativecommons.org/publicdomain/zero/1.0/
     1.8 +-->
     1.9 +
    1.10 +<html>
    1.11 +
    1.12 +  <head>
    1.13 +    <meta charset="utf8">
    1.14 +    <title></title>
    1.15 +
    1.16 +    <script type="application/javascript"
    1.17 +            src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    1.18 +    <link rel="stylesheet" type="text/css"
    1.19 +          href="chrome://mochikit/content/tests/SimpleTest/test.css">
    1.20 +
    1.21 +    <script type="application/javascript;version=1.8">
    1.22 +      const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
    1.23 +      const { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
    1.24 +      const { gDevToolsExtensions } = Cu.import("resource://gre/modules/devtools/DevToolsExtensions.jsm", {});
    1.25 +      Cu.import("resource://gre/modules/devtools/Loader.jsm");
    1.26 +      const { require } = devtools;
    1.27 +      const tabs = require('sdk/tabs');
    1.28 +      const { getMostRecentBrowserWindow, getInnerId } = require('sdk/window/utils');
    1.29 +      const { PageMod } = require('sdk/page-mod');
    1.30 +
    1.31 +      var _tests = [];
    1.32 +      function addTest(test) {
    1.33 +        _tests.push(test);
    1.34 +      }
    1.35 +
    1.36 +      function runNextTest() {
    1.37 +        if (_tests.length == 0) {
    1.38 +          SimpleTest.finish()
    1.39 +          return;
    1.40 +        }
    1.41 +        _tests.shift()();
    1.42 +      }
    1.43 +
    1.44 +      window.onload = function() {
    1.45 +        SimpleTest.waitForExplicitFinish();
    1.46 +        runNextTest();
    1.47 +      }
    1.48 +
    1.49 +      addTest(function () {
    1.50 +        let TEST_URL = 'data:text/html;charset=utf-8,test';
    1.51 +
    1.52 +        let mod = PageMod({
    1.53 +          include: TEST_URL,
    1.54 +          contentScriptWhen: 'ready',
    1.55 +          contentScript: 'null;'
    1.56 +        });
    1.57 +
    1.58 +        tabs.open({
    1.59 +          url: TEST_URL,
    1.60 +          onLoad: function(tab) {
    1.61 +            let id = getInnerId(getMostRecentBrowserWindow().gBrowser.selectedTab.linkedBrowser.contentWindow);
    1.62 +
    1.63 +            // getting
    1.64 +            is(gDevToolsExtensions.getContentGlobals({
    1.65 +              'inner-window-id': id
    1.66 +            }).length, 1, 'found a global for inner-id = ' + id);
    1.67 +
    1.68 +            Services.obs.addObserver(function observer(subject, topic, data) {
    1.69 +              if (id == subject.QueryInterface(Components.interfaces.nsISupportsPRUint64).data) {
    1.70 +                Services.obs.removeObserver(observer, 'inner-window-destroyed');
    1.71 +                setTimeout(function() {
    1.72 +                  // closing the tab window should have removed the global
    1.73 +                  is(gDevToolsExtensions.getContentGlobals({
    1.74 +                    'inner-window-id': id
    1.75 +                  }).length, 0, 'did not find a global for inner-id = ' + id);
    1.76 +
    1.77 +                  mod.destroy();
    1.78 +                  runNextTest();
    1.79 +                })
    1.80 +              }
    1.81 +            }, 'inner-window-destroyed', false);
    1.82 +
    1.83 +            tab.close();
    1.84 +          }
    1.85 +        });
    1.86 +      })
    1.87 +
    1.88 +      addTest(function testAddRemoveGlobal() {
    1.89 +        let global = {};
    1.90 +        let globalDetails = {
    1.91 +          global: global,
    1.92 +          'inner-window-id': 5
    1.93 +        };
    1.94 +
    1.95 +        // adding
    1.96 +        gDevToolsExtensions.addContentGlobal(globalDetails);
    1.97 +
    1.98 +        // getting
    1.99 +        is(gDevToolsExtensions.getContentGlobals({
   1.100 +          'inner-window-id': 5
   1.101 +        }).length, 1, 'found a global for inner-id = 5');
   1.102 +        is(gDevToolsExtensions.getContentGlobals({
   1.103 +          'inner-window-id': 4
   1.104 +        }).length, 0, 'did not find a global for inner-id = 4');
   1.105 +
   1.106 +        // remove
   1.107 +        gDevToolsExtensions.removeContentGlobal(globalDetails);
   1.108 +
   1.109 +        // getting again
   1.110 +        is(gDevToolsExtensions.getContentGlobals({
   1.111 +          'inner-window-id': 5
   1.112 +        }).length, 0, 'did not find a global for inner-id = 5');
   1.113 +
   1.114 +        runNextTest();
   1.115 +      });
   1.116 +
   1.117 +    </script>
   1.118 +  </head>
   1.119 +  <body></body>
   1.120 +</html>

mercurial