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 URL = "data:text/html;charset=utf8,<p>JavaScript Profiler test</p>"; |
michael@0 | 5 | |
michael@0 | 6 | let gTab1, gPanel1; |
michael@0 | 7 | let gTab2, gPanel2; |
michael@0 | 8 | |
michael@0 | 9 | // Tests that you can run the profiler in multiple tabs at the same |
michael@0 | 10 | // time and that closing the debugger panel in one tab doesn't lock |
michael@0 | 11 | // profilers in other tabs. |
michael@0 | 12 | |
michael@0 | 13 | registerCleanupFunction(function () { |
michael@0 | 14 | gTab1 = gTab2 = gPanel1 = gPanel2 = null; |
michael@0 | 15 | }); |
michael@0 | 16 | |
michael@0 | 17 | function test() { |
michael@0 | 18 | waitForExplicitFinish(); |
michael@0 | 19 | |
michael@0 | 20 | openTwoTabs() |
michael@0 | 21 | .then(startTwoProfiles) |
michael@0 | 22 | .then(stopFirstProfile) |
michael@0 | 23 | .then(stopSecondProfile) |
michael@0 | 24 | .then(closeTabs) |
michael@0 | 25 | .then(openTwoTabs) |
michael@0 | 26 | .then(startTwoProfiles) |
michael@0 | 27 | .then(closeFirstPanel) |
michael@0 | 28 | .then(stopSecondProfile) |
michael@0 | 29 | .then(closeTabs) |
michael@0 | 30 | .then(finish); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | function openTwoTabs() { |
michael@0 | 34 | let deferred = promise.defer(); |
michael@0 | 35 | |
michael@0 | 36 | setUp(URL, (tab, browser, panel) => { |
michael@0 | 37 | gTab1 = tab; |
michael@0 | 38 | gPanel1 = panel; |
michael@0 | 39 | |
michael@0 | 40 | loadTab(URL, (tab, browser) => { |
michael@0 | 41 | gTab2 = tab; |
michael@0 | 42 | openProfiler(tab, () => { |
michael@0 | 43 | let target = TargetFactory.forTab(tab); |
michael@0 | 44 | gPanel2 = gDevTools.getToolbox(target).getPanel("jsprofiler"); |
michael@0 | 45 | deferred.resolve(); |
michael@0 | 46 | }); |
michael@0 | 47 | }); |
michael@0 | 48 | }); |
michael@0 | 49 | |
michael@0 | 50 | return deferred.promise; |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | function startTwoProfiles() { |
michael@0 | 54 | let deferred = promise.defer(); |
michael@0 | 55 | gPanel1.controller.start("Profile 1", (err) => { |
michael@0 | 56 | ok(!err, "Profile in tab 1 started without errors"); |
michael@0 | 57 | gPanel2.controller.start("Profile 1", (err) => { |
michael@0 | 58 | ok(!err, "Profile in tab 2 started without errors"); |
michael@0 | 59 | gPanel1.controller.isActive((err, isActive) => { |
michael@0 | 60 | ok(isActive, "Profiler is active"); |
michael@0 | 61 | deferred.resolve(); |
michael@0 | 62 | }); |
michael@0 | 63 | }); |
michael@0 | 64 | }); |
michael@0 | 65 | |
michael@0 | 66 | return deferred.promise; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | function stopFirstProfile() { |
michael@0 | 70 | let deferred = promise.defer(); |
michael@0 | 71 | |
michael@0 | 72 | gPanel1.controller.stop("Profile 1", (err, data) => { |
michael@0 | 73 | ok(!err, "Profile in tab 1 stopped without errors"); |
michael@0 | 74 | ok(data, "Profile in tab 1 returned some data"); |
michael@0 | 75 | deferred.resolve(); |
michael@0 | 76 | }); |
michael@0 | 77 | |
michael@0 | 78 | return deferred.promise; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | function stopSecondProfile() { |
michael@0 | 82 | let deferred = promise.defer(); |
michael@0 | 83 | |
michael@0 | 84 | gPanel2.controller.stop("Profile 1", (err, data) => { |
michael@0 | 85 | ok(!err, "Profile in tab 2 stopped without errors"); |
michael@0 | 86 | ok(data, "Profile in tab 2 returned some data"); |
michael@0 | 87 | deferred.resolve(); |
michael@0 | 88 | }); |
michael@0 | 89 | |
michael@0 | 90 | return deferred.promise; |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | function closeTabs() { |
michael@0 | 94 | while (gBrowser.tabs.length > 1) { |
michael@0 | 95 | gBrowser.removeCurrentTab(); |
michael@0 | 96 | } |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | function closeFirstPanel() { |
michael@0 | 100 | let target = TargetFactory.forTab(gTab1); |
michael@0 | 101 | let toolbox = gDevTools.getToolbox(target); |
michael@0 | 102 | return toolbox.destroy; |
michael@0 | 103 | } |