Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CF47F17A3D for ; Fri, 20 Mar 2015 14:37:35 +0000 (UTC) Received: (qmail 68507 invoked by uid 500); 20 Mar 2015 14:37:26 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 68481 invoked by uid 500); 20 Mar 2015 14:37:26 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 68468 invoked by uid 99); 20 Mar 2015 14:37:26 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Mar 2015 14:37:26 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 37999E10AC; Fri, 20 Mar 2015 14:37:26 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sgrebnov@apache.org To: commits@cordova.apache.org Message-Id: <85afe735502941f9be7b0533a2b73c53@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: cordova-plugin-geolocation git commit: CB-8681 Fixed occasional test failures Date: Fri, 20 Mar 2015 14:37:26 +0000 (UTC) Repository: cordova-plugin-geolocation Updated Branches: refs/heads/master 973014e43 -> 90aeac681 CB-8681 Fixed occasional test failures github close #41 Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation/commit/90aeac68 Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation/tree/90aeac68 Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation/diff/90aeac68 Branch: refs/heads/master Commit: 90aeac681c764a314b9b3f8f9de98b1a0f3c8b02 Parents: 973014e Author: alsorokin Authored: Fri Mar 20 17:31:00 2015 +0300 Committer: sgrebnov Committed: Fri Mar 20 17:37:04 2015 +0300 ---------------------------------------------------------------------- tests/tests.js | 81 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 57 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation/blob/90aeac68/tests/tests.js ---------------------------------------------------------------------- diff --git a/tests/tests.js b/tests/tests.js index 89fc957..0105196 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -19,18 +19,41 @@ * */ exports.defineAutoTests = function () { - var fail = function (done) { - expect(true).toBe(false); - done(); - }, - succeed = function (done) { - expect(true).toBe(true); - // callback could be called sync so we invoke done async to make sure we know watcher id to .clear in afterEach - setTimeout(function () { - done(); - }); - }; - var isWindowsStore = (cordova.platformId == "windows8") || (cordova.platformId == "windows" && !WinJS.Utilities.isPhone); + var fail = function (done, context, message) { + // prevents done() to be called several times + if (context) { + if (context.done) return; + context.done = true; + } + + if (message) { + expect(false).toBe(true, message); + } else { + expect(false).toBe(true); + } + + // watchPosition could call its callback sync (before returning the value) + // so we invoke done async to make sure we know watcher id to .clear in afterEach + setTimeout(function () { + done(); + }); + }, + succeed = function (done, context) { + // prevents done() to be called several times + if (context) { + if (context.done) return; + context.done = true; + } + + expect(true).toBe(true); + + // watchPosition could call its callback sync (before returning the value) + // so we invoke done async to make sure we know watcher id to .clear in afterEach + setTimeout(function () { + done(); + }); + }, + isWindowsStore = (cordova.platformId == "windows8") || (cordova.platformId == "windows" && !WinJS.Utilities.isPhone); describe('Geolocation (navigator.geolocation)', function () { @@ -65,6 +88,7 @@ exports.defineAutoTests = function () { if (isWindowsStore) { pending(); } + navigator.geolocation.getCurrentPosition( fail.bind(null, done), succeed.bind(null, done), @@ -84,6 +108,7 @@ exports.defineAutoTests = function () { if (isWindowsStore) { pending(); } + navigator.geolocation.getCurrentPosition(function (p) { expect(p.coords).toBeDefined(); expect(p.timestamp).toBeDefined(); @@ -91,16 +116,23 @@ exports.defineAutoTests = function () { }, fail.bind(null, done), { - maximumAge: 300000 // 5 minutes maximum age of cached position + maximumAge: (5 * 60 * 1000) // 5 minutes maximum age of cached position }); - }); - + }, 25000); // first geolocation call can take several seconds on some devices }); }); describe('watchPosition method', function () { + beforeEach(function(done) { + // This timeout is set to lessen the load on platform's geolocation services + // which were causing occasional test failures + setTimeout(function() { + done(); + }, 100); + }); + describe('error callback', function () { var errorWatch = null; @@ -114,9 +146,11 @@ exports.defineAutoTests = function () { if (isWindowsStore) { pending(); } + + var context = this; errorWatch = navigator.geolocation.watchPosition( - fail.bind(null, done), - succeed.bind(null, done), + fail.bind(null, done, context, 'Unexpected win'), + succeed.bind(null, done, context), { maximumAge: 0, timeout: 0 @@ -138,26 +172,25 @@ exports.defineAutoTests = function () { if (isWindowsStore) { pending(); } - var self = this; + + var context = this; successWatch = navigator.geolocation.watchPosition( function (p) { // prevents done() to be called several times - if (self.done) return; - self.done = true; + if (context.done) return; + context.done = true; expect(p.coords).toBeDefined(); expect(p.timestamp).toBeDefined(); // callback could be called sync so we invoke done async to make sure we know watcher id to .clear in afterEach setTimeout(function () { done(); - }) - + }); }, - fail.bind(null, done), + fail.bind(null, done, context, 'Unexpected fail callback'), { maximumAge: (5 * 60 * 1000) // 5 minutes maximum age of cached position }); - }); }); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org For additional commands, e-mail: commits-help@cordova.apache.org