Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | "use strict"; |
michael@0 | 5 | |
michael@0 | 6 | const { Cu } = require('chrome'); |
michael@0 | 7 | const { PageMod } = require('sdk/page-mod'); |
michael@0 | 8 | const tabs = require('sdk/tabs'); |
michael@0 | 9 | const promise = require('sdk/core/promise') |
michael@0 | 10 | const { getMostRecentBrowserWindow } = require('sdk/window/utils'); |
michael@0 | 11 | const { data } = require('sdk/self'); |
michael@0 | 12 | const { set } = require('sdk/preferences/service'); |
michael@0 | 13 | |
michael@0 | 14 | const { DebuggerServer } = Cu.import('resource://gre/modules/devtools/dbg-server.jsm', {}); |
michael@0 | 15 | const { DebuggerClient } = Cu.import('resource://gre/modules/devtools/dbg-client.jsm', {}); |
michael@0 | 16 | |
michael@0 | 17 | let gClient; |
michael@0 | 18 | let ok; |
michael@0 | 19 | let testName = 'testDebugger'; |
michael@0 | 20 | let iframeURL = 'data:text/html;charset=utf-8,' + testName; |
michael@0 | 21 | let TAB_URL = 'data:text/html;charset=utf-8,' + encodeURIComponent('<iframe src="' + iframeURL + '" />'); |
michael@0 | 22 | TAB_URL = data.url('index.html'); |
michael@0 | 23 | let mod; |
michael@0 | 24 | |
michael@0 | 25 | exports.testDebugger = function(assert, done) { |
michael@0 | 26 | ok = assert.ok.bind(assert); |
michael@0 | 27 | assert.pass('starting test'); |
michael@0 | 28 | set('devtools.debugger.log', true); |
michael@0 | 29 | |
michael@0 | 30 | if (!DebuggerServer.initialized) { |
michael@0 | 31 | DebuggerServer.init(() => true); |
michael@0 | 32 | DebuggerServer.addBrowserActors(); |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | let transport = DebuggerServer.connectPipe(); |
michael@0 | 36 | gClient = new DebuggerClient(transport); |
michael@0 | 37 | gClient.connect((aType, aTraits) => { |
michael@0 | 38 | tabs.open({ |
michael@0 | 39 | url: TAB_URL, |
michael@0 | 40 | onLoad: function(tab) { |
michael@0 | 41 | assert.pass('tab loaded'); |
michael@0 | 42 | |
michael@0 | 43 | attachTabActorForUrl(gClient, TAB_URL). |
michael@0 | 44 | then(_ => { assert.pass('attachTabActorForUrl called'); return _; }). |
michael@0 | 45 | then(attachThread). |
michael@0 | 46 | then(testDebuggerStatement). |
michael@0 | 47 | then(_ => { assert.pass('testDebuggerStatement called') }). |
michael@0 | 48 | then(closeConnection). |
michael@0 | 49 | then(_ => { assert.pass('closeConnection called') }). |
michael@0 | 50 | then(done). |
michael@0 | 51 | then(null, aError => { |
michael@0 | 52 | ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
michael@0 | 53 | }); |
michael@0 | 54 | } |
michael@0 | 55 | }); |
michael@0 | 56 | }); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | function attachThread([aGrip, aResponse]) { |
michael@0 | 60 | let deferred = promise.defer(); |
michael@0 | 61 | |
michael@0 | 62 | // Now attach and resume... |
michael@0 | 63 | gClient.request({ to: aResponse.threadActor, type: "attach" }, () => { |
michael@0 | 64 | gClient.request({ to: aResponse.threadActor, type: "resume" }, () => { |
michael@0 | 65 | ok(true, "Pause wasn't called before we've attached."); |
michael@0 | 66 | deferred.resolve([aGrip, aResponse]); |
michael@0 | 67 | }); |
michael@0 | 68 | }); |
michael@0 | 69 | |
michael@0 | 70 | return deferred.promise; |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | function testDebuggerStatement([aGrip, aResponse]) { |
michael@0 | 74 | let deferred = promise.defer(); |
michael@0 | 75 | ok(aGrip, 'aGrip existss') |
michael@0 | 76 | |
michael@0 | 77 | gClient.addListener("paused", (aEvent, aPacket) => { |
michael@0 | 78 | ok(true, 'there was a pause event'); |
michael@0 | 79 | gClient.request({ to: aResponse.threadActor, type: "resume" }, () => { |
michael@0 | 80 | ok(true, "The pause handler was triggered on a debugger statement."); |
michael@0 | 81 | deferred.resolve(); |
michael@0 | 82 | }); |
michael@0 | 83 | }); |
michael@0 | 84 | |
michael@0 | 85 | mod = PageMod({ |
michael@0 | 86 | include: TAB_URL, |
michael@0 | 87 | attachTo: ['existing', 'top', 'frame'], |
michael@0 | 88 | contentScriptFile: data.url('script.js'), |
michael@0 | 89 | onAttach: function(mod) { |
michael@0 | 90 | ok(true, 'the page-mod was attached to ' + mod.tab.url); |
michael@0 | 91 | |
michael@0 | 92 | require('sdk/timers').setTimeout(function() { |
michael@0 | 93 | let debuggee = getMostRecentBrowserWindow().gBrowser.selectedTab.linkedBrowser.contentWindow.wrappedJSObject; |
michael@0 | 94 | debuggee.runDebuggerStatement(); |
michael@0 | 95 | ok(true, 'called runDebuggerStatement'); |
michael@0 | 96 | }, 500) |
michael@0 | 97 | } |
michael@0 | 98 | }); |
michael@0 | 99 | ok(true, 'PageMod was created'); |
michael@0 | 100 | |
michael@0 | 101 | return deferred.promise; |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | function getTabActorForUrl(aClient, aUrl) { |
michael@0 | 105 | let deferred = promise.defer(); |
michael@0 | 106 | |
michael@0 | 107 | aClient.listTabs(aResponse => { |
michael@0 | 108 | let tabActor = aResponse.tabs.filter(aGrip => aGrip.url == aUrl).pop(); |
michael@0 | 109 | deferred.resolve(tabActor); |
michael@0 | 110 | }); |
michael@0 | 111 | |
michael@0 | 112 | return deferred.promise; |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | function attachTabActorForUrl(aClient, aUrl) { |
michael@0 | 116 | let deferred = promise.defer(); |
michael@0 | 117 | |
michael@0 | 118 | getTabActorForUrl(aClient, aUrl).then(aGrip => { |
michael@0 | 119 | aClient.attachTab(aGrip.actor, aResponse => { |
michael@0 | 120 | deferred.resolve([aGrip, aResponse]); |
michael@0 | 121 | }); |
michael@0 | 122 | }); |
michael@0 | 123 | |
michael@0 | 124 | return deferred.promise; |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | function closeConnection() { |
michael@0 | 128 | let deferred = promise.defer(); |
michael@0 | 129 | gClient.close(deferred.resolve); |
michael@0 | 130 | return deferred.promise; |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | require('sdk/test/runner').runTestsFromModule(module); |