~zaspire/cordova-ubuntu-tests/disable-more-tests

« back to all changes in this revision

Viewing changes to www/cordova-plugin-whitelist/test/main.js

  • Committer: VĂ­ctor R. Ruiz
  • Date: 2013-07-25 13:09:34 UTC
  • Revision ID: victor.ruiz@canonical.com-20130725130934-d4q95mh8eehbv363
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 * Licensed to the Apache Software Foundation (ASF) under one
 
4
 * or more contributor license agreements.  See the NOTICE file
 
5
 * distributed with this work for additional information
 
6
 * regarding copyright ownership.  The ASF licenses this file
 
7
 * to you under the Apache License, Version 2.0 (the
 
8
 * "License"); you may not use this file except in compliance
 
9
 * with the License.  You may obtain a copy of the License at
 
10
 *
 
11
 *   http://www.apache.org/licenses/LICENSE-2.0
 
12
 *
 
13
 * Unless required by applicable law or agreed to in writing,
 
14
 * software distributed under the License is distributed on an
 
15
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 
16
 * KIND, either express or implied.  See the License for the
 
17
 * specific language governing permissions and limitations
 
18
 * under the License.
 
19
 *
 
20
*/
 
21
 
 
22
var deviceInfo = function() {
 
23
    document.getElementById("platform").innerHTML = device.platform;
 
24
    document.getElementById("version").innerHTML = device.version;
 
25
    document.getElementById("uuid").innerHTML = device.uuid;
 
26
    document.getElementById("model").innerHTML = device.model;
 
27
    document.getElementById("width").innerHTML = screen.width;
 
28
    document.getElementById("height").innerHTML = screen.height;
 
29
    document.getElementById("colorDepth").innerHTML = screen.colorDepth;
 
30
};
 
31
 
 
32
var getLocation = function() {
 
33
    var suc = function(p) {
 
34
        alert(p.coords.latitude + " " + p.coords.longitude);
 
35
    };
 
36
    var locFail = function() {
 
37
    };
 
38
    navigator.geolocation.getCurrentPosition(suc, locFail);
 
39
};
 
40
 
 
41
var beep = function() {
 
42
    navigator.notification.beep(2);
 
43
};
 
44
 
 
45
var vibrate = function() {
 
46
    navigator.notification.vibrate(0);
 
47
};
 
48
 
 
49
function roundNumber(num) {
 
50
    var dec = 3;
 
51
    var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
 
52
    return result;
 
53
}
 
54
 
 
55
var accelerationWatch = null;
 
56
 
 
57
function updateAcceleration(a) {
 
58
    document.getElementById('x').innerHTML = roundNumber(a.x);
 
59
    document.getElementById('y').innerHTML = roundNumber(a.y);
 
60
    document.getElementById('z').innerHTML = roundNumber(a.z);
 
61
}
 
62
 
 
63
var toggleAccel = function() {
 
64
    if (accelerationWatch !== null) {
 
65
        navigator.accelerometer.clearWatch(accelerationWatch);
 
66
        updateAcceleration({
 
67
            x : "",
 
68
            y : "",
 
69
            z : ""
 
70
        });
 
71
        accelerationWatch = null;
 
72
    } else {
 
73
        var options = {};
 
74
        options.frequency = 1000;
 
75
        accelerationWatch = navigator.accelerometer.watchAcceleration(
 
76
                updateAcceleration, function(ex) {
 
77
                    alert("accel fail (" + ex.name + ": " + ex.message + ")");
 
78
                }, options);
 
79
    }
 
80
};
 
81
 
 
82
var preventBehavior = function(e) {
 
83
    e.preventDefault();
 
84
};
 
85
 
 
86
function dump_pic(data) {
 
87
    var viewport = document.getElementById('viewport');
 
88
    console.log(data);
 
89
    viewport.style.display = "";
 
90
    viewport.style.position = "absolute";
 
91
    viewport.style.top = "10px";
 
92
    viewport.style.left = "10px";
 
93
    document.getElementById("test_img").src = "data:image/jpeg;base64," + data;
 
94
}
 
95
 
 
96
function fail(msg) {
 
97
    alert(msg);
 
98
}
 
99
 
 
100
function show_pic() {
 
101
    navigator.camera.getPicture(dump_pic, fail, {
 
102
        quality : 50
 
103
    });
 
104
}
 
105
 
 
106
function close() {
 
107
    var viewport = document.getElementById('viewport');
 
108
    viewport.style.position = "relative";
 
109
    viewport.style.display = "none";
 
110
}
 
111
 
 
112
// This is just to do this.
 
113
function readFile() {
 
114
    navigator.file.read('/sdcard/cordova.txt', fail, fail);
 
115
}
 
116
 
 
117
function writeFile() {
 
118
    navigator.file.write('foo.txt', "This is a test of writing to a file",
 
119
            fail, fail);
 
120
}
 
121
 
 
122
function contacts_success(contacts) {
 
123
    alert(contacts.length
 
124
            + ' contacts returned.'
 
125
            + (contacts[2] && contacts[2].name ? (' Third contact is ' + contacts[2].name.formatted)
 
126
                    : ''));
 
127
}
 
128
 
 
129
function get_contacts() {
 
130
    var obj = new ContactFindOptions();
 
131
    obj.filter = "";
 
132
    obj.multiple = true;
 
133
    obj.limit = 5;
 
134
    navigator.service.contacts.find(
 
135
            [ "displayName", "name" ], contacts_success,
 
136
            fail, obj);
 
137
}
 
138
 
 
139
var networkReachableCallback = function(reachability) {
 
140
    // There is no consistency on the format of reachability
 
141
    var networkState = reachability.code || reachability;
 
142
 
 
143
    var currentState = {};
 
144
    currentState[NetworkStatus.NOT_REACHABLE] = 'No network connection';
 
145
    currentState[NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK] = 'Carrier data connection';
 
146
    currentState[NetworkStatus.REACHABLE_VIA_WIFI_NETWORK] = 'WiFi connection';
 
147
 
 
148
    confirm("Connection type:\n" + currentState[networkState]);
 
149
};
 
150
 
 
151
function check_network() {
 
152
    navigator.network.isReachable("www.mobiledevelopersolutions.com",
 
153
            networkReachableCallback, {});
 
154
}
 
155
 
 
156
function init() {
 
157
    // the next line makes it impossible to see Contacts on the HTC Evo since it
 
158
    // doesn't have a scroll button
 
159
    // document.addEventListener("touchmove", preventBehavior, false);
 
160
    document.addEventListener("deviceready", deviceInfo, true);
 
161
    document.getElementById("user-agent").textContent = navigator.userAgent;
 
162
}