Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 | "use strict"; |
michael@0 | 5 | |
michael@0 | 6 | function test() { |
michael@0 | 7 | runTests(); |
michael@0 | 8 | } |
michael@0 | 9 | |
michael@0 | 10 | var EchoServer = { |
michael@0 | 11 | _deferred: null, |
michael@0 | 12 | _stopwatch: null, |
michael@0 | 13 | _browser: null, |
michael@0 | 14 | |
michael@0 | 15 | timeAsyncMessage: function timeAsyncMessage(aJson) { |
michael@0 | 16 | if (this._stopwatch == null) { |
michael@0 | 17 | this._stopwatch = new StopWatch(false); |
michael@0 | 18 | } |
michael@0 | 19 | this._deferred = Promise.defer(); |
michael@0 | 20 | messageManager.addMessageListener("Test:EchoResponse", this); |
michael@0 | 21 | this._stopwatch.start(); |
michael@0 | 22 | this._browser.messageManager.sendAsyncMessage("Test:EchoRequest", aJson); |
michael@0 | 23 | return this._deferred.promise; |
michael@0 | 24 | }, |
michael@0 | 25 | |
michael@0 | 26 | receiveMessage: function receiveMessage(aMessage) { |
michael@0 | 27 | let json = aMessage.json; |
michael@0 | 28 | switch (aMessage.name) { |
michael@0 | 29 | case "Test:EchoResponse": |
michael@0 | 30 | let msec = this._stopwatch.stop(); |
michael@0 | 31 | messageManager.removeMessageListener("Test:EchoResponse", this); |
michael@0 | 32 | this._deferred.resolve(msec); |
michael@0 | 33 | break; |
michael@0 | 34 | } |
michael@0 | 35 | }, |
michael@0 | 36 | }; |
michael@0 | 37 | |
michael@0 | 38 | |
michael@0 | 39 | gTests.push({ |
michael@0 | 40 | desc: "msg manager 1", |
michael@0 | 41 | run: function run() { |
michael@0 | 42 | yield addTab("about:blank"); |
michael@0 | 43 | yield hideContextUI(); |
michael@0 | 44 | |
michael@0 | 45 | let browser = Browser.selectedTab.browser; |
michael@0 | 46 | EchoServer._browser = browser; |
michael@0 | 47 | |
michael@0 | 48 | browser.messageManager.loadFrameScript(chromeRoot + "msgmanagerecho.js", true); |
michael@0 | 49 | |
michael@0 | 50 | yield waitForMs(1000); |
michael@0 | 51 | |
michael@0 | 52 | let openDataSet = new Array(); |
michael@0 | 53 | |
michael@0 | 54 | for (let idx = 0; idx < 100; idx++) { |
michael@0 | 55 | let msec = yield EchoServer.timeAsyncMessage({}); |
michael@0 | 56 | openDataSet.push(msec); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | PerfTest.declareTest("A4354ACB-34DE-4796-914F-FD01EF298B1D", |
michael@0 | 60 | "msg manager 01", "platform", "", |
michael@0 | 61 | "Measures the time it takes to send/recv 100 message manager messages with an empty payload. " + |
michael@0 | 62 | "Browser displays about:blank during the test."); |
michael@0 | 63 | let result = PerfTest.computeAverage(openDataSet, { stripOutliers: false }); |
michael@0 | 64 | PerfTest.declareNumericalResult(result, "msec"); |
michael@0 | 65 | } |
michael@0 | 66 | }); |
michael@0 | 67 | |
michael@0 | 68 | gTests.push({ |
michael@0 | 69 | desc: "msg manager 1", |
michael@0 | 70 | run: function run() { |
michael@0 | 71 | yield addTab("about:blank"); |
michael@0 | 72 | yield hideContextUI(); |
michael@0 | 73 | |
michael@0 | 74 | let browser = Browser.selectedTab.browser; |
michael@0 | 75 | EchoServer._browser = browser; |
michael@0 | 76 | |
michael@0 | 77 | browser.messageManager.loadFrameScript(chromeRoot + "msgmanagerecho.js", true); |
michael@0 | 78 | |
michael@0 | 79 | let ds = {}; |
michael@0 | 80 | |
michael@0 | 81 | for (let i = 0; i < 100; i++) { |
michael@0 | 82 | ds["i" + i] = { idx: i }; |
michael@0 | 83 | let table = ds["i" + i]; |
michael@0 | 84 | for (let j = 0; j < 100; j++) { |
michael@0 | 85 | table["j" + i] = { rnd: Math.random() }; |
michael@0 | 86 | } |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | yield waitForMs(1000); |
michael@0 | 90 | |
michael@0 | 91 | let openDataSet = new Array(); |
michael@0 | 92 | |
michael@0 | 93 | for (let idx = 0; idx < 100; idx++) { |
michael@0 | 94 | let msec = yield EchoServer.timeAsyncMessage(ds); |
michael@0 | 95 | openDataSet.push(msec); |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | PerfTest.declareTest("B4354ACB-34DE-4796-914F-FD01EF298B1D", |
michael@0 | 99 | "msg manager 02", "platform", "", |
michael@0 | 100 | "Measures the time it takes to send/recv 100 message manager messages with a heavy payload. " + |
michael@0 | 101 | "Browser displays about:blank during the test."); |
michael@0 | 102 | let result = PerfTest.computeAverage(openDataSet, { stripOutliers: false }); |
michael@0 | 103 | PerfTest.declareNumericalResult(result, "msec"); |
michael@0 | 104 | } |
michael@0 | 105 | }); |
michael@0 | 106 | |
michael@0 | 107 | gTests.push({ |
michael@0 | 108 | desc: "msg manager 3", |
michael@0 | 109 | run: function run() { |
michael@0 | 110 | yield addTab(chromeRoot + "res/ripples.html"); |
michael@0 | 111 | yield hideContextUI(); |
michael@0 | 112 | |
michael@0 | 113 | let browser = Browser.selectedTab.browser; |
michael@0 | 114 | EchoServer._browser = browser; |
michael@0 | 115 | |
michael@0 | 116 | browser.messageManager.loadFrameScript(chromeRoot + "msgmanagerecho.js", true); |
michael@0 | 117 | |
michael@0 | 118 | let ds = {}; |
michael@0 | 119 | |
michael@0 | 120 | for (let i = 0; i < 100; i++) { |
michael@0 | 121 | ds["i" + i] = { idx: i }; |
michael@0 | 122 | let table = ds["i" + i]; |
michael@0 | 123 | for (let j = 0; j < 100; j++) { |
michael@0 | 124 | table["j" + i] = { rnd: Math.random() }; |
michael@0 | 125 | } |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | yield waitForMs(1000); |
michael@0 | 129 | |
michael@0 | 130 | let openDataSet = new Array(); |
michael@0 | 131 | |
michael@0 | 132 | for (let idx = 0; idx < 100; idx++) { |
michael@0 | 133 | let msec = yield EchoServer.timeAsyncMessage(ds); |
michael@0 | 134 | openDataSet.push(msec); |
michael@0 | 135 | } |
michael@0 | 136 | |
michael@0 | 137 | PerfTest.declareTest("C4354ACB-34DE-4796-914F-FD01EF298B1D", |
michael@0 | 138 | "msg manager 03", "platform", "", |
michael@0 | 139 | "Measures the time it takes to send/recv 100 message manager messages with a heavy payload. " + |
michael@0 | 140 | "Browser displays ripples during the test."); |
michael@0 | 141 | let result = PerfTest.computeAverage(openDataSet, { stripOutliers: false }); |
michael@0 | 142 | PerfTest.declareNumericalResult(result, "msec"); |
michael@0 | 143 | } |
michael@0 | 144 | }); |