incubator-callback-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Grieve <agri...@chromium.org>
Subject Re: [2/2] spec commit: Adding different bridge benchmarking to the Automated Mobile Spec Tests
Date Tue, 11 Sep 2012 02:44:03 GMT
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, <bowserj@apache.org> 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 <bowserj@apache.org>
> Authored: Mon Sep 10 14:17:31 2012 -0700
> Committer: Joe Bowser <bowserj@apache.org>
> 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 @@
>      <a href="pages/notification.html" class="btn large"
> style="width:100%;">Run Notification Tests</a>
>      <a href="pages/platform.html" class="btn large"
> style="width:100%;">Run Platform Tests</a>
>      <a href="pages/storage.html" class="btn large"
> style="width:100%;">Run Storage Tests</a>
> +    <a href="pages/bridge.html" class="btn large" style="width:100%;">Run
> Bridge Tests</a>
>
>      <h2> </h2><div class="backBtn" onclick="backHome();">Back</div>
>    </body>
>
>
> 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 @@
> +<!DOCTYPE html>
> +<html>
> +
> +<head>
> +  <title>Cordova: Device API Specs</title>
> +
> +  <meta name="viewport" content="width=device-width,
> height=device-height, user-scalable=yes, initial-scale=1.0;" />
> +  <!-- Load jasmine -->
> +  <link href="../jasmine.css" rel="stylesheet"/>
> +  <script type="text/javascript" src="../jasmine.js"></script>
> +  <script type="text/javascript"
> src="../html/HtmlReporterHelpers.js"></script>
> +  <script type="text/javascript" src="../html/HtmlReporter.js"></script>
> +  <script type="text/javascript" src="../html/ReporterView.js"></script>
> +  <script type="text/javascript" src="../html/SpecView.js"></script>
> +  <script type="text/javascript" src="../html/SuiteView.js"></script>
> +  <script type="text/javascript"
> src="../html/TrivialReporter.js"></script>
> +
> +  <!-- Source -->
> +  <script type="text/javascript" src="../../cordova.js"></script>
> +
> +  <!-- Load Test Runner -->
> +  <script type="text/javascript" src="../test-runner.js"></script>
> +
> +  <!-- Tests -->
> +  <script type="text/javascript" src="../tests/bridge.tests.js"></script>
> +
> +  <script type="text/javascript">
> +    document.addEventListener('deviceready', function () {
> +      var jasmineEnv = jasmine.getEnv();
> +      jasmineEnv.updateInterval = 1000;
> +
> +      var htmlReporter = new jasmine.HtmlReporter();
> +
> +      jasmineEnv.addReporter(htmlReporter);
> +
> +      jasmineEnv.specFilter = function(spec) {
> +        return htmlReporter.specFilter(spec);
> +      };
> +
> +      jasmineEnv.execute();
> +    }, false);
> +  </script>
> +</head>
> +
> +<body>
> +  <a href="javascript:" class="backBtn" onclick="backHome();">Back</a>
> +</body>
> +</html>
> +
>
>
> 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);
> +        });
> +    });
> +});
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message