toolkit/devtools/tests/mochitest/test_devtools_extensions.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <!DOCTYPE html>
     2 <!--
     3   Any copyright is dedicated to the Public Domain.
     4   http://creativecommons.org/publicdomain/zero/1.0/
     5 -->
     7 <html>
     9   <head>
    10     <meta charset="utf8">
    11     <title></title>
    13     <script type="application/javascript"
    14             src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    15     <link rel="stylesheet" type="text/css"
    16           href="chrome://mochikit/content/tests/SimpleTest/test.css">
    18     <script type="application/javascript;version=1.8">
    19       const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
    20       const { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
    21       const { gDevToolsExtensions } = Cu.import("resource://gre/modules/devtools/DevToolsExtensions.jsm", {});
    22       Cu.import("resource://gre/modules/devtools/Loader.jsm");
    23       const { require } = devtools;
    24       const tabs = require('sdk/tabs');
    25       const { getMostRecentBrowserWindow, getInnerId } = require('sdk/window/utils');
    26       const { PageMod } = require('sdk/page-mod');
    28       var _tests = [];
    29       function addTest(test) {
    30         _tests.push(test);
    31       }
    33       function runNextTest() {
    34         if (_tests.length == 0) {
    35           SimpleTest.finish()
    36           return;
    37         }
    38         _tests.shift()();
    39       }
    41       window.onload = function() {
    42         SimpleTest.waitForExplicitFinish();
    43         runNextTest();
    44       }
    46       addTest(function () {
    47         let TEST_URL = 'data:text/html;charset=utf-8,test';
    49         let mod = PageMod({
    50           include: TEST_URL,
    51           contentScriptWhen: 'ready',
    52           contentScript: 'null;'
    53         });
    55         tabs.open({
    56           url: TEST_URL,
    57           onLoad: function(tab) {
    58             let id = getInnerId(getMostRecentBrowserWindow().gBrowser.selectedTab.linkedBrowser.contentWindow);
    60             // getting
    61             is(gDevToolsExtensions.getContentGlobals({
    62               'inner-window-id': id
    63             }).length, 1, 'found a global for inner-id = ' + id);
    65             Services.obs.addObserver(function observer(subject, topic, data) {
    66               if (id == subject.QueryInterface(Components.interfaces.nsISupportsPRUint64).data) {
    67                 Services.obs.removeObserver(observer, 'inner-window-destroyed');
    68                 setTimeout(function() {
    69                   // closing the tab window should have removed the global
    70                   is(gDevToolsExtensions.getContentGlobals({
    71                     'inner-window-id': id
    72                   }).length, 0, 'did not find a global for inner-id = ' + id);
    74                   mod.destroy();
    75                   runNextTest();
    76                 })
    77               }
    78             }, 'inner-window-destroyed', false);
    80             tab.close();
    81           }
    82         });
    83       })
    85       addTest(function testAddRemoveGlobal() {
    86         let global = {};
    87         let globalDetails = {
    88           global: global,
    89           'inner-window-id': 5
    90         };
    92         // adding
    93         gDevToolsExtensions.addContentGlobal(globalDetails);
    95         // getting
    96         is(gDevToolsExtensions.getContentGlobals({
    97           'inner-window-id': 5
    98         }).length, 1, 'found a global for inner-id = 5');
    99         is(gDevToolsExtensions.getContentGlobals({
   100           'inner-window-id': 4
   101         }).length, 0, 'did not find a global for inner-id = 4');
   103         // remove
   104         gDevToolsExtensions.removeContentGlobal(globalDetails);
   106         // getting again
   107         is(gDevToolsExtensions.getContentGlobals({
   108           'inner-window-id': 5
   109         }).length, 0, 'did not find a global for inner-id = 5');
   111         runNextTest();
   112       });
   114     </script>
   115   </head>
   116   <body></body>
   117 </html>

mercurial