tests.js 5.32 KB
Newer Older
李晓兵's avatar
李晓兵 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
*/

/* jshint jasmine: true */
/* global StatusBar */

exports.defineAutoTests = function () {
    describe("StatusBar", function () {
        it("statusbar.spec.1 should exist", function() {
            expect(window.StatusBar).toBeDefined();
        });

        it("statusbar.spec.2 should have show|hide methods", function() {
            expect(window.StatusBar.show).toBeDefined();
            expect(typeof window.StatusBar.show).toBe("function");

            expect(window.StatusBar.hide).toBeDefined();
            expect(typeof window.StatusBar.hide).toBe("function");
        });

        it("statusbar.spec.3 should have set backgroundColor methods", function() {
            expect(window.StatusBar.backgroundColorByName).toBeDefined();
            expect(typeof window.StatusBar.backgroundColorByName).toBe("function");

            expect(window.StatusBar.backgroundColorByHexString).toBeDefined();
            expect(typeof window.StatusBar.backgroundColorByHexString).toBe("function");
        });

        it("statusbar.spec.4 should have set style methods", function() {
            expect(window.StatusBar.styleBlackTranslucent).toBeDefined();
            expect(typeof window.StatusBar.styleBlackTranslucent).toBe("function");

            expect(window.StatusBar.styleDefault).toBeDefined();
            expect(typeof window.StatusBar.styleDefault).toBe("function");

            expect(window.StatusBar.styleLightContent).toBeDefined();
            expect(typeof window.StatusBar.styleLightContent).toBe("function");

            expect(window.StatusBar.styleBlackOpaque).toBeDefined();
            expect(typeof window.StatusBar.styleBlackOpaque).toBe("function");

            expect(window.StatusBar.overlaysWebView).toBeDefined();
            expect(typeof window.StatusBar.overlaysWebView).toBe("function");
        });
    });
};

exports.defineManualTests = function (contentEl, createActionButton) {
    function log(msg) {
        var el = document.getElementById("info");
        var logLine = document.createElement('div');
        logLine.innerHTML = msg;
        el.appendChild(logLine);
    }

    function doShow() {
        StatusBar.show();
        log('StatusBar.isVisible=' + StatusBar.isVisible);
    }

    function doHide() {
        StatusBar.hide();
        log('StatusBar.isVisible=' + StatusBar.isVisible);
    }

    function doColor1() {
        log('set color=red');
        StatusBar.backgroundColorByName('red');
    }

    function doColor2() {
        log('set style=translucent black');
        StatusBar.styleBlackTranslucent();
    }

    function doColor3() {
        log('set style=default');
        StatusBar.styleDefault();
    }

    var showOverlay = true;
    function doOverlay() {
        showOverlay = !showOverlay;
        StatusBar.overlaysWebView(showOverlay);
        log('Set overlay=' + showOverlay);
    }

    /******************************************************************************/

    contentEl.innerHTML = '<div id="info"></div>' +
        'Also: tapping bar on iOS should emit a log.' +
        '<div id="action-show"></div>' +
        'Expected result: Status bar will be visible' +
        '</p> <div id="action-hide"></div>' +
        'Expected result: Status bar will be hidden' +
        '</p> <div id="action-color2"></div>' +
        'Expected result: Status bar text will be a light (white) color' +
        '</p> <div id="action-color3"></div>' +
        'Expected result: Status bar text will be a dark (black) color' +
        '</p> <div id="action-overlays"></div>' +
        'Expected result:<br>Overlay true = status bar will lay on top of web view content<br>Overlay false = status bar will be separate from web view and will not cover content' +
        '</p> <div id="action-color1"></div>' +
        'Expected result: If overlay false, background color for status bar will be red';

    log('StatusBar.isVisible=' + StatusBar.isVisible);
    window.addEventListener('statusTap', function () {
        log('tap!');
    }, false);

    createActionButton("Show", function () {
        doShow();
    }, 'action-show');

    createActionButton("Hide", function () {
        doHide();
    }, 'action-hide');

    createActionButton("Style=red (background)", function () {
        doColor1();
    }, 'action-color1');

    createActionButton("Style=translucent black", function () {
        doColor2();
    }, 'action-color2');

    createActionButton("Style=default", function () {
        doColor3();
    }, 'action-color3');

    createActionButton("Toggle Overlays", function () {
        doOverlay();
    }, 'action-overlays');
};