Hey Joe, Wondering why make this into a jasmine test? Does it make the results more easily captured? Other thing I'm wondering is if this should use some JS reflection to detect the available bridge modes since they are different on iOS and non-existant on others (mobile-spec tests are supposed to work on all platforms correct?) On Mon, Sep 10, 2012 at 5:18 PM, wrote: > Adding different bridge benchmarking to the Automated Mobile Spec Tests > > > Project: > http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/repo > Commit: > http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/commit/019c43ef > Tree: > http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/tree/019c43ef > Diff: > http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/diff/019c43ef > > Branch: refs/heads/master > Commit: 019c43ef8fe940289145c557bd669df60eb3b759 > Parents: 8cb36ea > Author: Joe Bowser > Authored: Mon Sep 10 14:17:31 2012 -0700 > Committer: Joe Bowser > Committed: Mon Sep 10 14:17:31 2012 -0700 > > ---------------------------------------------------------------------- > autotest/index.html | 1 + > autotest/pages/bridge.html | 49 ++++++++++ > autotest/tests/bridge.tests.js | 176 +++++++++++++++++++++++++++++++++++ > 3 files changed, 226 insertions(+), 0 deletions(-) > ---------------------------------------------------------------------- > > > > http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/blob/019c43ef/autotest/index.html > ---------------------------------------------------------------------- > diff --git a/autotest/index.html b/autotest/index.html > index 70a1eeb..48fe722 100755 > --- a/autotest/index.html > +++ b/autotest/index.html > @@ -28,6 +28,7 @@ > style="width:100%;">Run Notification Tests > style="width:100%;">Run Platform Tests > style="width:100%;">Run Storage Tests > + Run > Bridge Tests > >

Back
> > > > http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/blob/019c43ef/autotest/pages/bridge.html > ---------------------------------------------------------------------- > diff --git a/autotest/pages/bridge.html b/autotest/pages/bridge.html > new file mode 100644 > index 0000000..56d2d59 > --- /dev/null > +++ b/autotest/pages/bridge.html > @@ -0,0 +1,49 @@ > + > + > + > + > + Cordova: Device API Specs > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + Back > + > + > + > > > http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/blob/019c43ef/autotest/tests/bridge.tests.js > ---------------------------------------------------------------------- > diff --git a/autotest/tests/bridge.tests.js > b/autotest/tests/bridge.tests.js > new file mode 100644 > index 0000000..5a700e0 > --- /dev/null > +++ b/autotest/tests/bridge.tests.js > @@ -0,0 +1,176 @@ > +/* This test requires some extra code to run, because we want benchmark > results */ > + > +/* > + It's never going to be OVER 9000 > + http://youtu.be/SiMHTK15Pik > +*/ > +var FENCEPOST = 9000; > + > +var exec = cordova.require('cordova/exec'); > + > +var echo = cordova.require('cordova/plugin/echo'), > + startTime = +new Date, > + callCount = 0, > + durationMs = 1000, > + asyncEcho = true, > + useSetTimeout = true, > + payloadSize = 5, > + callsPerSecond = 0, > + completeSpy = null, > + payload = new Array(payloadSize * 10 + 1).join('012\n\n > 6789'); > + > +var vanillaWin = function(result) { > + callCount++; > + if (result != payload) { > + console.log('Wrong echo data!'); > + } > + var elapsedMs = new Date - startTime; > + if (elapsedMs < durationMs) { > + if (useSetTimeout) { > + setTimeout(echoMessage, 0); > + } else { > + echoMessage(); > + } > + } else { > + callsPerSecond = callCount * 1000 / elapsedMs; > + console.log('Calls per second: ' + callsPerSecond); > + if(completeSpy != null) > + completeSpy(); > + } > + } > + > +var reset = function() > +{ > + startTime = +new Date, > + callCount = 0, > + durationMs = 1000, > + asyncEcho = true, > + useSetTimeout = true, > + payloadSize = 5, > + callsPerSecond = 0, > + completeSpy = null, > + payload = new Array(payloadSize * 10 + 1).join('012\n\n > 6789'); > +} > + > +var echoMessage = function() > +{ > + echo(vanillaWin, fail, payload, asyncEcho); > +} > + > +var fail = jasmine.createSpy(); > + > +describe('The JS to Native Bridge', function() { > + > + //Run the reset > + beforeEach(function() { > + reset(); > + }); > + > + it('should work with prompt', function() { > + exec.setJsToNativeBridgeMode(0); > + var win = jasmine.createSpy().andCallFake(function(r) { > + vanillaWin(r); > + }); > + completeSpy = jasmine.createSpy(); > + runs(function() { > + echo(win, fail, payload, asyncEcho); > + }); > + waitsFor(function() { return completeSpy.wasCalled; }, "never > completed", durationMs * 2); > + runs(function() { > + expect(callsPerSecond).toBeGreaterThan(FENCEPOST); > + }); > + }); > + it("should work with jsObject", function() { > + exec.setJsToNativeBridgeMode(1); > + var win = jasmine.createSpy().andCallFake(function(r) { > + vanillaWin(r); > + }); > + completeSpy = jasmine.createSpy(); > + runs(function() { > + echo(win, fail, payload, asyncEcho); > + }); > + waitsFor(function() { return completeSpy.wasCalled; }, "never > completed", durationMs * 2); > + runs(function() { > + expect(callsPerSecond).toBeGreaterThan(FENCEPOST); > + }); > + }); > +}); > + > +describe("The Native to JS Bridge", function() { > + > + //Run the reset > + beforeEach(function() { > + reset(); > + }); > + > + it("should work with polling", function() { > + exec.setNativeToJsBridgeMode(0); > + var win = jasmine.createSpy().andCallFake(function(r) { > + vanillaWin(r); > + }); > + completeSpy = jasmine.createSpy(); > + runs(function() { > + echo(win, fail, payload, asyncEcho); > + }); > + waitsFor(function() { return completeSpy.wasCalled; }, "never > completed", durationMs * 2); > + runs(function() { > + expect(callsPerSecond).toBeGreaterThan(FENCEPOST); > + }); > + }); > + it("should work with hanging get", function() { > + exec.setNativeToJsBridgeMode(1); > + var win = jasmine.createSpy().andCallFake(function(r) { > + vanillaWin(r); > + }); > + completeSpy = jasmine.createSpy(); > + runs(function() { > + echo(win, fail, payload, asyncEcho); > + }); > + waitsFor(function() { return completeSpy.wasCalled; }, "never > completed", durationMs * 2); > + runs(function() { > + expect(callsPerSecond).toBeGreaterThan(FENCEPOST); > + }); > + }); > + it("should work with load_url (not on emulator)", function() { > + exec.setNativeToJsBridgeMode(2); > + var win = jasmine.createSpy().andCallFake(function(r) { > + vanillaWin(r); > + }); > + completeSpy = jasmine.createSpy(); > + runs(function() { > + echo(win, fail, payload, asyncEcho); > + }); > + waitsFor(function() { return completeSpy.wasCalled; }, "never > completed", durationMs * 2); > + runs(function() { > + expect(callsPerSecond).toBeGreaterThan(FENCEPOST); > + }); > + }); > + it("should work with online event", function() { > + exec.setNativeToJsBridgeMode(3); > + var win = jasmine.createSpy().andCallFake(function(r) { > + vanillaWin(r); > + }); > + completeSpy = jasmine.createSpy(); > + runs(function() { > + echo(win, fail, payload, asyncEcho); > + }); > + waitsFor(function() { return completeSpy.wasCalled; }, "never > completed", durationMs * 2); > + runs(function() { > + expect(callsPerSecond).toBeGreaterThan(FENCEPOST); > + }); > + }); > + it("should work with the private api", function() { > + exec.setNativeToJsBridgeMode(4); > + var win = jasmine.createSpy().andCallFake(function(r) { > + vanillaWin(r); > + }); > + completeSpy = jasmine.createSpy(); > + runs(function() { > + echo(win, fail, payload, asyncEcho); > + }); > + waitsFor(function() { return completeSpy.wasCalled; }, "never > completed", durationMs * 2); > + runs(function() { > + expect(callsPerSecond).toBeGreaterThan(FENCEPOST); > + }); > + }); > +}); > >