~ps-jenkins/cordova-ubuntu-tests/latestsnapshot-2.11+14.04.20131106-0ubuntu1

« back to all changes in this revision

Viewing changes to www/cordova-plugin-whitelist/test/autotest/test-runner.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
if (window.sessionStorage != null) {
 
23
    window.sessionStorage.clear();
 
24
}
 
25
 
 
26
// Timeout is 2 seconds to allow physical devices enough
 
27
// time to query the response. This is important for some
 
28
// Android devices.
 
29
var Tests = function() {};
 
30
Tests.TEST_TIMEOUT = 7500;
 
31
 
 
32
// Creates a spy that will fail if called.
 
33
function createDoNotCallSpy(name, opt_extraMessage) {
 
34
    return jasmine.createSpy().andCallFake(function() {
 
35
        var errorMessage = name + ' should not have been called.';
 
36
        if (arguments.length) {
 
37
            errorMessage += ' Got args: ' + JSON.stringify(arguments);
 
38
        }
 
39
        if (opt_extraMessage) {
 
40
            errorMessage += '\n' + opt_extraMessage;
 
41
        }
 
42
        expect(false).toBe(true, errorMessage);
 
43
    });
 
44
}
 
45
 
 
46
// Waits for any of the given spys to be called.
 
47
// Last param may be a custom timeout duration.
 
48
function waitsForAny() {
 
49
    var spys = [].slice.call(arguments);
 
50
    var timeout = Tests.TEST_TIMEOUT;
 
51
    if (typeof spys[spys.length - 1] == 'number') {
 
52
        timeout = spys.pop();
 
53
    }
 
54
    waitsFor(function() {
 
55
        for (var i = 0; i < spys.length; ++i) {
 
56
            if (spys[i].wasCalled) {
 
57
                return true;
 
58
            }
 
59
        }
 
60
        return false;
 
61
    }, "Expecting callbacks to be called.", timeout);
 
62
}