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.

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

mercurial