Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | const TEST_BASE = "chrome://mochitests/content/browser/browser/devtools/styleeditor/test/"; |
michael@0 | 5 | const TEST_BASE_HTTP = "http://example.com/browser/browser/devtools/styleeditor/test/"; |
michael@0 | 6 | const TEST_BASE_HTTPS = "https://example.com/browser/browser/devtools/styleeditor/test/"; |
michael@0 | 7 | const TEST_HOST = 'mochi.test:8888'; |
michael@0 | 8 | |
michael@0 | 9 | let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}); |
michael@0 | 10 | let TargetFactory = devtools.TargetFactory; |
michael@0 | 11 | let {LoadContextInfo} = Cu.import("resource://gre/modules/LoadContextInfo.jsm", {}); |
michael@0 | 12 | let {console} = Cu.import("resource://gre/modules/devtools/Console.jsm", {}); |
michael@0 | 13 | let {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {}); |
michael@0 | 14 | |
michael@0 | 15 | let gPanelWindow; |
michael@0 | 16 | let cache = Cc["@mozilla.org/netwerk/cache-storage-service;1"] |
michael@0 | 17 | .getService(Ci.nsICacheStorageService); |
michael@0 | 18 | |
michael@0 | 19 | |
michael@0 | 20 | // Import the GCLI test helper |
michael@0 | 21 | let testDir = gTestPath.substr(0, gTestPath.lastIndexOf("/")); |
michael@0 | 22 | Services.scriptloader.loadSubScript(testDir + "../../../commandline/test/helpers.js", this); |
michael@0 | 23 | |
michael@0 | 24 | gDevTools.testing = true; |
michael@0 | 25 | SimpleTest.registerCleanupFunction(() => { |
michael@0 | 26 | gDevTools.testing = false; |
michael@0 | 27 | }); |
michael@0 | 28 | |
michael@0 | 29 | /** |
michael@0 | 30 | * Define an async test based on a generator function |
michael@0 | 31 | */ |
michael@0 | 32 | function asyncTest(generator) { |
michael@0 | 33 | return () => Task.spawn(generator).then(null, ok.bind(null, false)).then(finish); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | function* cleanup() |
michael@0 | 37 | { |
michael@0 | 38 | gPanelWindow = null; |
michael@0 | 39 | while (gBrowser.tabs.length > 1) { |
michael@0 | 40 | let target = TargetFactory.forTab(gBrowser.selectedTab); |
michael@0 | 41 | yield gDevTools.closeToolbox(target); |
michael@0 | 42 | |
michael@0 | 43 | gBrowser.removeCurrentTab(); |
michael@0 | 44 | } |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | function addTabAndOpenStyleEditors(count, callback, uri) { |
michael@0 | 48 | let deferred = promise.defer(); |
michael@0 | 49 | let currentCount = 0; |
michael@0 | 50 | let panel; |
michael@0 | 51 | addTabAndCheckOnStyleEditorAdded(p => panel = p, function () { |
michael@0 | 52 | currentCount++; |
michael@0 | 53 | info(currentCount + " of " + count + " editors opened"); |
michael@0 | 54 | if (currentCount == count) { |
michael@0 | 55 | if (callback) { |
michael@0 | 56 | callback(panel); |
michael@0 | 57 | } |
michael@0 | 58 | deferred.resolve(panel); |
michael@0 | 59 | } |
michael@0 | 60 | }); |
michael@0 | 61 | |
michael@0 | 62 | if (uri) { |
michael@0 | 63 | content.location = uri; |
michael@0 | 64 | } |
michael@0 | 65 | return deferred.promise; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | function addTabAndCheckOnStyleEditorAdded(callbackOnce, callbackOnAdded) { |
michael@0 | 69 | gBrowser.selectedTab = gBrowser.addTab(); |
michael@0 | 70 | gBrowser.selectedBrowser.addEventListener("load", function onLoad() { |
michael@0 | 71 | gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); |
michael@0 | 72 | openStyleEditorInWindow(window, function (panel) { |
michael@0 | 73 | // Execute the individual callback with the panel argument. |
michael@0 | 74 | callbackOnce(panel); |
michael@0 | 75 | // Report editors that already opened while loading. |
michael@0 | 76 | for (let editor of panel.UI.editors) { |
michael@0 | 77 | callbackOnAdded(editor); |
michael@0 | 78 | } |
michael@0 | 79 | // Report new editors added afterwards. |
michael@0 | 80 | panel.UI.on("editor-added", (event, editor) => callbackOnAdded(editor)); |
michael@0 | 81 | }); |
michael@0 | 82 | }, true); |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | function openStyleEditorInWindow(win, callback) { |
michael@0 | 86 | let target = TargetFactory.forTab(win.gBrowser.selectedTab); |
michael@0 | 87 | win.gDevTools.showToolbox(target, "styleeditor").then(function(toolbox) { |
michael@0 | 88 | let panel = toolbox.getCurrentPanel(); |
michael@0 | 89 | gPanelWindow = panel._panelWin; |
michael@0 | 90 | |
michael@0 | 91 | panel.UI._alwaysDisableAnimations = true; |
michael@0 | 92 | callback(panel); |
michael@0 | 93 | }); |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | function checkDiskCacheFor(host, done) |
michael@0 | 97 | { |
michael@0 | 98 | let foundPrivateData = false; |
michael@0 | 99 | |
michael@0 | 100 | Visitor.prototype = { |
michael@0 | 101 | onCacheStorageInfo: function(num, consumption) |
michael@0 | 102 | { |
michael@0 | 103 | info("disk storage contains " + num + " entries"); |
michael@0 | 104 | }, |
michael@0 | 105 | onCacheEntryInfo: function(entry) |
michael@0 | 106 | { |
michael@0 | 107 | info(entry.key); |
michael@0 | 108 | foundPrivateData |= entry.key.contains(host); |
michael@0 | 109 | }, |
michael@0 | 110 | onCacheEntryVisitCompleted: function() |
michael@0 | 111 | { |
michael@0 | 112 | is(foundPrivateData, false, "web content present in disk cache"); |
michael@0 | 113 | done(); |
michael@0 | 114 | } |
michael@0 | 115 | }; |
michael@0 | 116 | function Visitor() {} |
michael@0 | 117 | |
michael@0 | 118 | var storage = cache.diskCacheStorage(LoadContextInfo.default, false); |
michael@0 | 119 | storage.asyncVisitStorage(new Visitor(), true /* Do walk entries */); |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | registerCleanupFunction(cleanup); |