Touchgui/plugins/org.apache.cordova.device/tests/tests.js

changeset 0
e8ccd40d0ef6
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Touchgui/plugins/org.apache.cordova.device/tests/tests.js	Thu Jun 04 14:50:33 2015 +0200
     1.3 @@ -0,0 +1,94 @@
     1.4 +/*
     1.5 + *
     1.6 + * Licensed to the Apache Software Foundation (ASF) under one
     1.7 + * or more contributor license agreements.  See the NOTICE file
     1.8 + * distributed with this work for additional information
     1.9 + * regarding copyright ownership.  The ASF licenses this file
    1.10 + * to you under the Apache License, Version 2.0 (the
    1.11 + * "License"); you may not use this file except in compliance
    1.12 + * with the License.  You may obtain a copy of the License at
    1.13 + *
    1.14 + *   http://www.apache.org/licenses/LICENSE-2.0
    1.15 + *
    1.16 + * Unless required by applicable law or agreed to in writing,
    1.17 + * software distributed under the License is distributed on an
    1.18 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    1.19 + * KIND, either express or implied.  See the License for the
    1.20 + * specific language governing permissions and limitations
    1.21 + * under the License.
    1.22 + *
    1.23 +*/
    1.24 +
    1.25 +exports.defineAutoTests = function() {
    1.26 +  describe('Device Information (window.device)', function () {
    1.27 +    it("should exist", function() {
    1.28 +      expect(window.device).toBeDefined();
    1.29 +    });
    1.30 +
    1.31 +    it("should contain a platform specification that is a string", function() {
    1.32 +      expect(window.device.platform).toBeDefined();
    1.33 +      expect((new String(window.device.platform)).length > 0).toBe(true);
    1.34 +    });
    1.35 +
    1.36 +    it("should contain a version specification that is a string", function() {
    1.37 +      expect(window.device.version).toBeDefined();
    1.38 +      expect((new String(window.device.version)).length > 0).toBe(true);
    1.39 +    });
    1.40 +
    1.41 +    it("should contain a UUID specification that is a string or a number", function() {
    1.42 +      expect(window.device.uuid).toBeDefined();
    1.43 +      if (typeof window.device.uuid == 'string' || typeof window.device.uuid == 'object') {
    1.44 +        expect((new String(window.device.uuid)).length > 0).toBe(true);
    1.45 +      } else {
    1.46 +        expect(window.device.uuid > 0).toBe(true);
    1.47 +      }
    1.48 +    });
    1.49 +
    1.50 +    it("should contain a cordova specification that is a string", function() {
    1.51 +      expect(window.device.cordova).toBeDefined();
    1.52 +      expect((new String(window.device.cordova)).length > 0).toBe(true);
    1.53 +    });
    1.54 +
    1.55 +    it("should depend on the precense of cordova.version string", function() {
    1.56 +      expect(window.cordova.version).toBeDefined();
    1.57 +      expect((new String(window.cordova.version)).length > 0).toBe(true);
    1.58 +    });
    1.59 +
    1.60 +    it("should contain device.cordova equal to cordova.version", function() {
    1.61 +      expect(window.device.cordova).toBe(window.cordova.version);
    1.62 +    });
    1.63 +
    1.64 +    it("should contain a model specification that is a string", function() {
    1.65 +      expect(window.device.model).toBeDefined();
    1.66 +      expect((new String(window.device.model)).length > 0).toBe(true);
    1.67 +    });
    1.68 +  });
    1.69 +};
    1.70 +
    1.71 +exports.defineManualTests = function(contentEl, createActionButton) {
    1.72 +  var logMessage = function (message, color) {
    1.73 +        var log = document.getElementById('info');
    1.74 +        var logLine = document.createElement('div');
    1.75 +        if (color) {
    1.76 +            logLine.style.color = color;
    1.77 +        }
    1.78 +        logLine.innerHTML = message;
    1.79 +        log.appendChild(logLine);
    1.80 +    }
    1.81 +
    1.82 +    var clearLog = function () {
    1.83 +        var log = document.getElementById('info');
    1.84 +        log.innerHTML = '';
    1.85 +    }
    1.86 +
    1.87 +    var device_tests = '<h3>Press Dump Device button to get device information</h3>' +
    1.88 +        '<div id="dump_device"></div>' +
    1.89 +        'Expected result: Status box will get updated with device info. (i.e. platform, version, uuid, model, etc)';
    1.90 +
    1.91 +    contentEl.innerHTML = '<div id="info"></div>' + device_tests;
    1.92 +
    1.93 +    createActionButton('Dump device', function() {
    1.94 +      clearLog();
    1.95 +      logMessage(JSON.stringify(window.device, null, '\t'));
    1.96 +    }, "dump_device");
    1.97 +};

mercurial