diff --git a/LICENSE b/LICENSE index 7a4a3ea2..6092a574 100644 --- a/LICENSE +++ b/LICENSE @@ -199,4 +199,228 @@ 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. \ No newline at end of file + limitations under the License. + + SUBCOMPONENTS + + Apache Callback includes software components under different license terms. + Your use of these subcomponents is subject to the terms and conditions of + the following licenses. + + For the framework/libs/junit-4.10.jar component: + + Common Public License - v 1.0 + + THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS COMMON PUBLIC + LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM + CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. + + 1. DEFINITIONS + + "Contribution" means: + + a) in the case of the initial Contributor, the initial code and + documentation distributed under this Agreement, and + b) in the case of each subsequent Contributor: + + i) changes to the Program, and + + ii) additions to the Program; + + where such changes and/or additions to the Program originate from and are +distributed by that particular Contributor. A Contribution 'originates' from a +Contributor if it was added to the Program by such Contributor itself or anyone +acting on such Contributor's behalf. Contributions do not include additions to +the Program which: (i) are separate modules of software distributed in +conjunction with the Program under their own license agreement, and (ii) are +not derivative works of the Program. + +"Contributor" means any person or entity that distributes the Program. + +"Licensed Patents " mean patent claims licensable by a Contributor which are +necessarily infringed by the use or sale of its Contribution alone or when +combined with the Program. + +"Program" means the Contributions distributed in accordance with this Agreement. + +"Recipient" means anyone who receives the Program under this Agreement, +including all Contributors. + + 2. GRANT OF RIGHTS + + a) Subject to the terms of this Agreement, each Contributor hereby grants +Recipient a non-exclusive, worldwide, royalty-free copyright license to +reproduce, prepare derivative works of, publicly display, publicly perform, +distribute and sublicense the Contribution of such Contributor, if any, and +such derivative works, in source code and object code form. + + b) Subject to the terms of this Agreement, each Contributor hereby grants +Recipient a non-exclusive, worldwide, royalty-free patent license under +Licensed Patents to make, use, sell, offer to sell, import and otherwise +transfer the Contribution of such Contributor, if any, in source code and +object code form. This patent license shall apply to the combination of the +Contribution and the Program if, at the time the Contribution is added by the +Contributor, such addition of the Contribution causes such combination to be +covered by the Licensed Patents. The patent license shall not apply to any +other combinations which include the Contribution. No hardware per se is +licensed hereunder. + + c) Recipient understands that although each Contributor grants the +licenses to its Contributions set forth herein, no assurances are provided by +any Contributor that the Program does not infringe the patent or other +intellectual property rights of any other entity. Each Contributor disclaims +any liability to Recipient for claims brought by any other entity based on +infringement of intellectual property rights or otherwise. As a condition to +exercising the rights and licenses granted hereunder, each Recipient hereby +assumes sole responsibility to secure any other intellectual property rights +needed, if any. For example, if a third party patent license is required to +allow Recipient to distribute the Program, it is Recipient's responsibility to +acquire that license before distributing the Program. + + d) Each Contributor represents that to its knowledge it has sufficient +copyright rights in its Contribution, if any, to grant the copyright license +set forth in this Agreement. + + 3. REQUIREMENTS + +A Contributor may choose to distribute the Program in object code form under +its own license agreement, provided that: + + a) it complies with the terms and conditions of this Agreement; and + + b) its license agreement: + + i) effectively disclaims on behalf of all Contributors all warranties and +conditions, express and implied, including warranties or conditions of title +and non-infringement, and implied warranties or conditions of merchantability +and fitness for a particular purpose; + + ii) effectively excludes on behalf of all Contributors all liability for +damages, including direct, indirect, special, incidental and consequential +damages, such as lost profits; + + iii) states that any provisions which differ from this Agreement are +offered by that Contributor alone and not by any other party; and + + iv) states that source code for the Program is available from such +Contributor, and informs licensees how to obtain it in a reasonable manner on +or through a medium customarily used for software exchange. + +When the Program is made available in source code form: + + a) it must be made available under this Agreement; and + + b) a copy of this Agreement must be included with each copy of the +Program. + +Contributors may not remove or alter any copyright notices contained within the +Program. + +Each Contributor must identify itself as the originator of its Contribution, if +any, in a manner that reasonably allows subsequent Recipients to identify the +originator of the Contribution. + +4. COMMERCIAL DISTRIBUTION + +Commercial distributors of software may accept certain responsibilities with +respect to end users, business partners and the like. While this license is +intended to facilitate the commercial use of the Program, the Contributor who +includes the Program in a commercial product offering should do so in a manner +which does not create potential liability for other Contributors. Therefore, if +a Contributor includes the Program in a commercial product offering, such +Contributor ("Commercial Contributor") hereby agrees to defend and indemnify +every other Contributor ("Indemnified Contributor") against any losses, damages +and costs (collectively "Losses") arising from claims, lawsuits and other legal +actions brought by a third party against the Indemnified Contributor to the +extent caused by the acts or omissions of such Commercial Contributor in +connection with its distribution of the Program in a commercial product +offering. The obligations in this section do not apply to any claims or Losses +relating to any actual or alleged intellectual property infringement. In order +to qualify, an Indemnified Contributor must: a) promptly notify the Commercial +Contributor in writing of such claim, and b) allow the Commercial Contributor +to control, and cooperate with the Commercial Contributor in, the defense and +any related settlement negotiations. The Indemnified Contributor may +participate in any such claim at its own expense. + +For example, a Contributor might include the Program in a commercial product +offering, Product X. That Contributor is then a Commercial Contributor. If that +Commercial Contributor then makes performance claims, or offers warranties +related to Product X, those performance claims and warranties are such +Commercial Contributor's responsibility alone. Under this section, the +Commercial Contributor would have to defend claims against the other +Contributors related to those performance claims and warranties, and if a court +requires any other Contributor to pay any damages as a result, the Commercial +Contributor must pay those damages. + +5. NO WARRANTY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR +IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, +NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each +Recipient is solely responsible for determining the appropriateness of using +and distributing the Program and assumes all risks associated with its exercise +of rights under this Agreement, including but not limited to the risks and +costs of program errors, compliance with applicable laws, damage to or loss of +data, programs or equipment, and unavailability or interruption of operations. + +6. DISCLAIMER OF LIABILITY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY +CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST +), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY +WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS +GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +7. GENERAL + +If any provision of this Agreement is invalid or unenforceable under applicable +law, it shall not affect the validity or enforceability of the remainder of the +terms of this Agreement, and without further action by the parties hereto, such +provision shall be reformed to the minimum extent necessary to make such +provision valid and enforceable. + +If Recipient institutes patent litigation against a Contributor with respect to +a patent applicable to software (including a cross-claim or counterclaim in a +lawsuit), then any patent licenses granted by that Contributor to such +Recipient under this Agreement shall terminate as of the date such litigation +is filed. In addition, if Recipient institutes patent litigation against any +entity (including a cross-claim or counterclaim in a lawsuit) alleging that the +Program itself (excluding combinations of the Program with other software or +hardware) infringes such Recipient's patent(s), then such Recipient's rights +granted under Section 2(b) shall terminate as of the date such litigation is +filed. + +All Recipient's rights under this Agreement shall terminate if it fails to +comply with any of the material terms or conditions of this Agreement and does +not cure such failure in a reasonable period of time after becoming aware of +such noncompliance. If all Recipient's rights under this Agreement terminate, +Recipient agrees to cease use and distribution of the Program as soon as +reasonably practicable. However, Recipient's obligations under this Agreement +and any licenses granted by Recipient relating to the Program shall continue +and survive. + +Everyone is permitted to copy and distribute copies of this Agreement, but in +order to avoid inconsistency the Agreement is copyrighted and may only be +modified in the following manner. The Agreement Steward reserves the right to +publish new versions (including revisions) of this Agreement from time to time. +No one other than the Agreement Steward has the right to modify this Agreement. +IBM is the initial Agreement Steward. IBM may assign the responsibility to +serve as the Agreement Steward to a suitable separate entity. Each new version +of the Agreement will be given a distinguishing version number. The Program +(including Contributions) may always be distributed subject to the version of +the Agreement under which it was received. In addition, after a new version of +the Agreement is published, Contributor may elect to distribute the Program +(including its Contributions) under the new version. Except as expressly stated +in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to +the intellectual property of any Contributor under this Agreement, whether +expressly, by implication, estoppel or otherwise. All rights in the Program not +expressly granted under this Agreement are reserved. + +This Agreement is governed by the laws of the State of New York and the +intellectual property laws of the United States of America. No party to this +Agreement will bring a legal action under this Agreement more than one year +after the cause of action arose. Each party waives its rights to a jury trial +in any resulting litigation. diff --git a/VERSION b/VERSION index 9c6d6293..d88d8e71 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.6.1 +1.7.0rc1 diff --git a/changelog b/changelog index 0eafa220..68f6e488 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,16 @@ ChangeLog ios -Shazron Abdullah (12): +Ben Birch (2): + ios camera targetWidth/Height don't match the documentation Fixes CB-183 and CB-54 + iOS camera targetWidth/Height don't match the documentation - changes per shazron + +Fil Maj (1): + [CB-511] Changed deviceproperties version to "cordova" property + +Shazron Abdullah (29): + Updated js for iOS only parameter cropToTargetSize (Camera.getPicture) + Fixed CB-483 - FileTransfer - unknown property attribute 'atomic' when building from source (Xcode 3 only) + Updated to cordova-js 1.6.1 Fixed CB-496 - Camera.getPicture - will always return FILE_URI even though DATA_URL specified Fixed CB-497 - online and offline events are not being fired in 1.6.0 Fixed CB-501 - orientationchange event is not being fired in 1.6.0 @@ -13,37 +23,64 @@ Shazron Abdullah (12): Added 1.6.1 availability constants Fixed pause and resume event firing to use cordova channels onPause and onResume Re-fix CB-347 - don't apply .plist fix if the key does not exist + Implemented CB-536 - Add new selector to CDVViewController to create a new CDVCordovaView, so subclasses can override it + Removed cropToSize option, defaults to NO always (like the other platforms) re: CB-54, CB-183 + Removing verbose logging that is confusing devs. + Workaround for CB-509 - geolocation.clearWatch doesn't shut the GPS down under iOS + Fixed CB-537 - media.seekTo fails with NSRangeException + Fixed CB-544 - iOS Geolocation fails if Cordova.plist EnableLocation = YES + Fixed CB-543 - FileTransfer.upload WebKit discarded an uncaught exception + Fixed CB-391 - camera.getPicture crash + Update to CB-391 - remove 10 sec purge check, leaving it up to the iOS watchdog to re-send memory warning again + Fixed CB-535 - Add a way to log JavaScript exceptions, parse errors, and get JS stack frame events (with line numbers, etc) + Added doc for CB-535 - JavaScript Exception Logging + Fixed CB-494 - Move Cordova.plist section from "How to use Cordova as a Component Guide" to its own doc + Added cordova-js 1.7.0rc1 + Updated VERSION to 1.7.0rc1, updated Makefile to include new guides. blackberry Fil Maj (1): - version 1.6.1 + bumping version to 1.7.0rc1 android -Joe Bowser (4): - Copying new XML into the templates for 1.6.1. Turns out tags are broken - Getting setup to tag 1.6.1 - CB-489 - Adding .js to the example, thought it was removed for a reason - Adding fix for CB-482 +Fil Maj (3): + [CB-164] Changed network plugin to sync from async and removed setKeepCallback(true) on plugin result in there. Fixes location.reload() not firing deviceready due to network plugin being unresponsive + Proper fix for CB-164. Online/offline events now propagated to webview properly + [CB-473] run ant clean before ant debug install + +Joe Bowser (5): + CB-480 work, back button and history issues are preventing this from being tested properly + Fixed back button behaviour. WIN + Reverting the back button change that I made, for some reason certain methods aren't inherited when you extend DroidGap + Fix for CB-549 + Incrementing project to 1.7.0rc1 macdonst (2): - Remove duplicate files from repository - Automatically update index.html in templates directory on version change + CB-539: FileTransfer.download fails when target starts with 'file://' + Removing un-needed logs windows -Jesse MacFadyen (3): - cleanup console logging, toLower on OverrideBackButton - updated for 1.6.1 - updated template, permissions, and js +Jesse MacFadyen (11): + added hint to debug output when device ready cannot fire because the dev did not include the tag in their page. + release was private, and therefore uncallable from js + changed test project to use updated tests + jasmine + remove method added, dispatches not supported error + debug output for exception in ProcessCommand + remove unused + added mouse support + fancy animation on load, ala metro style + splash image is animated away on load + update JS from cordova-js, update version file + rebuild of lib + template gen + +Takashi Okamoto (1): + Fixed filetransfer boundary without parameter. webos hermwong (1): - update to 1.6.1 + update version to 1.7.0 bada -Anis Kadri (5): - updating bada project parameters - adding artwork and removing old phonegap references - CB-4 adding Apache Source Headers - fixing network problem - updating version to 1.6.1 +Anis Kadri (1): + updating version to 1.7.0rc1 diff --git a/doc/_index.html b/doc/_index.html index 529e058a..dc74057f 100644 --- a/doc/_index.html +++ b/doc/_index.html @@ -15,7 +15,8 @@

Cordova Documentation

- + + diff --git a/doc/cordova_camera_camera.md.html b/doc/cordova_camera_camera.md.html index 1773c827..9aba3494 100644 --- a/doc/cordova_camera_camera.md.html +++ b/doc/cordova_camera_camera.md.html @@ -15,7 +15,8 @@

Cordova Documentation

- + + diff --git a/doc/cordova_connection_connection.md.html b/doc/cordova_connection_connection.md.html index e4f04bca..5c261fbe 100644 --- a/doc/cordova_connection_connection.md.html +++ b/doc/cordova_connection_connection.md.html @@ -15,7 +15,8 @@

Cordova Documentation

- + + diff --git a/doc/cordova_device_device.md.html b/doc/cordova_device_device.md.html index b71d5535..82f3061c 100644 --- a/doc/cordova_device_device.md.html +++ b/doc/cordova_device_device.md.html @@ -15,7 +15,8 @@

Cordova Documentation

- + + diff --git a/doc/cordova_file_file.md.html b/doc/cordova_file_file.md.html index 83bc5bee..21599ed1 100644 --- a/doc/cordova_file_file.md.html +++ b/doc/cordova_file_file.md.html @@ -15,7 +15,8 @@

Cordova Documentation

- + + diff --git a/doc/cordova_media_capture_capture.md.html b/doc/cordova_media_capture_capture.md.html index 0e46d7aa..b476cdb0 100644 --- a/doc/cordova_media_capture_capture.md.html +++ b/doc/cordova_media_capture_capture.md.html @@ -15,7 +15,8 @@

Cordova Documentation

- + + diff --git a/doc/cordova_notification_notification.md.html b/doc/cordova_notification_notification.md.html index c333bb9d..2589e3aa 100644 --- a/doc/cordova_notification_notification.md.html +++ b/doc/cordova_notification_notification.md.html @@ -15,7 +15,8 @@

Cordova Documentation

- + + diff --git a/doc/guide_getting-started_android_index.md.html b/doc/guide_getting-started_android_index.md.html index ec918352..eaa31ba3 100644 --- a/doc/guide_getting-started_android_index.md.html +++ b/doc/guide_getting-started_android_index.md.html @@ -15,7 +15,8 @@

Cordova Documentation

- + + diff --git a/doc/guide_getting-started_index.md.html b/doc/guide_getting-started_index.md.html index 8b464c53..e4fccf39 100644 --- a/doc/guide_getting-started_index.md.html +++ b/doc/guide_getting-started_index.md.html @@ -15,7 +15,8 @@

Cordova Documentation

- + + diff --git a/doc/guide_getting-started_symbian_index.md.html b/doc/guide_getting-started_symbian_index.md.html index 610845ab..5021a5ad 100644 --- a/doc/guide_getting-started_symbian_index.md.html +++ b/doc/guide_getting-started_symbian_index.md.html @@ -15,7 +15,8 @@

Cordova Documentation

- + + diff --git a/doc/guide_getting-started_windows-phone_index.md.html b/doc/guide_getting-started_windows-phone_index.md.html index 5d9a04cf..092cb115 100644 --- a/doc/guide_getting-started_windows-phone_index.md.html +++ b/doc/guide_getting-started_windows-phone_index.md.html @@ -15,7 +15,8 @@

Cordova Documentation

- + + diff --git a/lib/android/VERSION b/lib/android/VERSION index 9c6d6293..d88d8e71 100644 --- a/lib/android/VERSION +++ b/lib/android/VERSION @@ -1 +1 @@ -1.6.1 +1.7.0rc1 diff --git a/lib/android/cordova-1.6.1.jar b/lib/android/cordova-1.7.0rc1.jar similarity index 74% rename from lib/android/cordova-1.6.1.jar rename to lib/android/cordova-1.7.0rc1.jar index 75b7e058..bfa27ab8 100644 Binary files a/lib/android/cordova-1.6.1.jar and b/lib/android/cordova-1.7.0rc1.jar differ diff --git a/lib/android/example/assets/www/cordova-1.6.1.js b/lib/android/cordova-1.7.0rc1.js similarity index 95% rename from lib/android/example/assets/www/cordova-1.6.1.js rename to lib/android/cordova-1.7.0rc1.js index 1b879160..cf56912e 100644 --- a/lib/android/example/assets/www/cordova-1.6.1.js +++ b/lib/android/cordova-1.7.0rc1.js @@ -1,6 +1,6 @@ -// commit b2de4baa76a94ecb916619a536339ffee9ef6843 +// commit 017a948047e355ae0c2cdc8c4188ae57b115528a -// File generated at :: Tue Apr 17 2012 12:19:35 GMT-0700 (PDT) +// File generated at :: Mon Apr 23 2012 11:36:23 GMT-0700 (PDT) /* Licensed to the Apache Software Foundation (ASF) under one @@ -67,10 +67,20 @@ if (typeof module === "object" && typeof require === "function") { module.exports.require = require; module.exports.define = define; } - // file: lib/cordova.js define("cordova", function(require, exports, module) { var channel = require('cordova/channel'); + +/** + * Listen for DOMContentLoaded and notify our channel subscribers. + */ +document.addEventListener('DOMContentLoaded', function() { + channel.onDOMContentLoaded.fire(); +}, false); +if (document.readyState == 'complete') { + channel.onDOMContentLoaded.fire(); +} + /** * Intercept calls to addEventListener + removeEventListener and handle deviceready, * resume, and pause events. @@ -115,13 +125,18 @@ window.addEventListener = function(evt, handler, capture) { }; document.removeEventListener = function(evt, handler, capture) { - var e = evt.toLowerCase(); - // If unsubcribing from an event that is handled by a plugin - if (typeof documentEventHandlers[e] != "undefined") { - documentEventHandlers[e].unsubscribe(handler); - } else { - m_document_removeEventListener.call(document, evt, handler, capture); - } + var e = evt.toLowerCase(); + // Check for pause/resume events first. + if (e == 'resume') { + channel.onResume.unsubscribe(handler); + } else if (e == 'pause') { + channel.onPause.unsubscribe(handler); + // If unsubcribing from an event that is handled by a plugin + } else if (typeof documentEventHandlers[e] != "undefined") { + documentEventHandlers[e].unsubscribe(handler); + } else { + m_document_removeEventListener.call(document, evt, handler, capture); + } }; window.removeEventListener = function(evt, handler, capture) { @@ -149,9 +164,9 @@ function createEvent(type, data) { if(typeof window.console === "undefined") { - window.console = { - log:function(){} - }; + window.console = { + log:function(){} + }; } var cordova = { @@ -292,7 +307,7 @@ var cordova = { console.log("Error: Plugin "+name+" already exists."); } }, - + addConstructor: function(func) { channel.onCordovaReady.subscribeOnce(function() { try { @@ -304,7 +319,7 @@ var cordova = { } }; -/** +/** * Legacy variable for plugin support * TODO: remove in 2.0. */ @@ -326,6 +341,8 @@ module.exports = cordova; // file: lib/common/builder.js define("cordova/builder", function(require, exports, module) { +var utils = require('cordova/utils'); + function each(objects, func, context) { for (var prop in objects) { if (objects.hasOwnProperty(prop)) { @@ -502,10 +519,10 @@ var Channel = function(type, opts) { /** * cordova Channels that must fire before "deviceready" is fired. - */ + */ deviceReadyChannelsArray: [], deviceReadyChannelsMap: {}, - + /** * Indicate that a feature needs to be initialized before it is ready to be used. * This holds up Cordova's "deviceready" event until the feature has been initialized @@ -542,7 +559,7 @@ var Channel = function(type, opts) { utils = require('cordova/utils'); /** - * Subscribes the given function to the channel. Any time that + * Subscribes the given function to the channel. Any time that * Channel.fire is called so too will the function. * Optionally specify an execution context for the function * and a guid that can be used to stop subscribing to the channel. @@ -587,7 +604,7 @@ Channel.prototype.subscribeOnce = function(f, c) { return g; }; -/** +/** * Unsubscribes the function with the given guid from the channel. */ Channel.prototype.unsubscribe = function(g) { @@ -601,7 +618,7 @@ Channel.prototype.unsubscribe = function(g) { if (this.events.onUnsubscribe) this.events.onUnsubscribe.call(this); }; -/** +/** * Calls all functions subscribed to this channel. */ Channel.prototype.fire = function(e) { @@ -656,7 +673,6 @@ channel.waitForInitialization('onCordovaInfoReady'); channel.waitForInitialization('onCordovaConnectionReady'); module.exports = channel; - }); // file: lib/common/common.js @@ -841,7 +857,6 @@ module.exports = { } } }; - }); // file: lib/android/exec.js @@ -873,7 +888,8 @@ module.exports = function(success, fail, service, action, args) { // If a result was returned if (r.length > 0) { - eval("var v="+r+";"); + var v; + eval("v="+r+";"); // If status is OK, then return value back to caller if (v.status === cordova.callbackStatus.OK) { @@ -1003,7 +1019,7 @@ module.exports = { var db = null; try { db = originalOpenDatabase(name, version, desc, size); - } + } catch (ex) { if (ex.code === 18) { db = null; @@ -1018,7 +1034,7 @@ module.exports = { else { return db; } - + }; } @@ -1077,7 +1093,6 @@ module.exports = { } } }; - }); // file: lib/common/plugin/Acceleration.js @@ -1090,7 +1105,6 @@ var Acceleration = function(x, y, z, timestamp) { }; module.exports = Acceleration; - }); // file: lib/common/plugin/Camera.js @@ -1172,35 +1186,34 @@ cameraExport.getPicture = function(successCallback, errorCallback, options) { if (typeof options.encodingType == "number") { encodingType = options.encodingType; } - + var mediaType = Camera.MediaType.PICTURE; if (typeof options.mediaType == "number") { mediaType = options.mediaType; } var allowEdit = false; if (typeof options.allowEdit == "boolean") { - allowEdit = options.allowEdit; + allowEdit = options.allowEdit; } else if (typeof options.allowEdit == "number") { - allowEdit = options.allowEdit <= 0 ? false : true; + allowEdit = options.allowEdit <= 0 ? false : true; } var correctOrientation = false; if (typeof options.correctOrientation == "boolean") { - correctOrientation = options.correctOrientation; + correctOrientation = options.correctOrientation; } else if (typeof options.correctOrientation == "number") { - correctOrientation = options.correctOrientation <=0 ? false : true; + correctOrientation = options.correctOrientation <=0 ? false : true; } var saveToPhotoAlbum = false; - if (typeof options.saveToPhotoAlbum == "boolean") { - saveToPhotoAlbum = options.saveToPhotoAlbum; + if (typeof options.saveToPhotoAlbum == "boolean") { + saveToPhotoAlbum = options.saveToPhotoAlbum; } else if (typeof options.saveToPhotoAlbum == "number") { - saveToPhotoAlbum = options.saveToPhotoAlbum <=0 ? false : true; + saveToPhotoAlbum = options.saveToPhotoAlbum <=0 ? false : true; } exec(successCallback, errorCallback, "Camera", "takePicture", [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType, mediaType, allowEdit, correctOrientation, saveToPhotoAlbum]); -} +}; module.exports = cameraExport; - }); // file: lib/common/plugin/CameraConstants.js @@ -1225,7 +1238,6 @@ module.exports = { SAVEDPHOTOALBUM : 2 // Choose image from picture library (same as PHOTOLIBRARY for Android) } }; - }); // file: lib/common/plugin/CaptureAudioOptions.js @@ -1234,16 +1246,15 @@ define("cordova/plugin/CaptureAudioOptions", function(require, exports, module) * Encapsulates all audio capture operation configuration options. */ var CaptureAudioOptions = function(){ - // Upper limit of sound clips user can record. Value must be equal or greater than 1. - this.limit = 1; - // Maximum duration of a single sound clip in seconds. - this.duration = 0; - // The selected audio mode. Must match with one of the elements in supportedAudioModes array. - this.mode = null; + // Upper limit of sound clips user can record. Value must be equal or greater than 1. + this.limit = 1; + // Maximum duration of a single sound clip in seconds. + this.duration = 0; + // The selected audio mode. Must match with one of the elements in supportedAudioModes array. + this.mode = null; }; module.exports = CaptureAudioOptions; - }); // file: lib/common/plugin/CaptureError.js @@ -1255,7 +1266,7 @@ var CaptureError = function(c) { this.code = c || null; }; -// Camera or microphone failed to capture image or sound. +// Camera or microphone failed to capture image or sound. CaptureError.CAPTURE_INTERNAL_ERR = 0; // Camera application or audio capture application is currently serving other capture request. CaptureError.CAPTURE_APPLICATION_BUSY = 1; @@ -1267,7 +1278,6 @@ CaptureError.CAPTURE_NO_MEDIA_FILES = 3; CaptureError.CAPTURE_NOT_SUPPORTED = 20; module.exports = CaptureError; - }); // file: lib/common/plugin/CaptureImageOptions.js @@ -1276,14 +1286,13 @@ define("cordova/plugin/CaptureImageOptions", function(require, exports, module) * Encapsulates all image capture operation configuration options. */ var CaptureImageOptions = function(){ - // Upper limit of images user can take. Value must be equal or greater than 1. - this.limit = 1; - // The selected image mode. Must match with one of the elements in supportedImageModes array. - this.mode = null; + // Upper limit of images user can take. Value must be equal or greater than 1. + this.limit = 1; + // The selected image mode. Must match with one of the elements in supportedImageModes array. + this.mode = null; }; module.exports = CaptureImageOptions; - }); // file: lib/common/plugin/CaptureVideoOptions.js @@ -1292,16 +1301,15 @@ define("cordova/plugin/CaptureVideoOptions", function(require, exports, module) * Encapsulates all video capture operation configuration options. */ var CaptureVideoOptions = function(){ - // Upper limit of videos user can record. Value must be equal or greater than 1. - this.limit = 1; - // Maximum duration of a single video clip in seconds. - this.duration = 0; - // The selected video mode. Must match with one of the elements in supportedVideoModes array. - this.mode = null; + // Upper limit of videos user can record. Value must be equal or greater than 1. + this.limit = 1; + // Maximum duration of a single video clip in seconds. + this.duration = 0; + // The selected video mode. Must match with one of the elements in supportedVideoModes array. + this.mode = null; }; module.exports = CaptureVideoOptions; - }); // file: lib/common/plugin/CompassError.js @@ -1319,7 +1327,6 @@ CompassError.COMPASS_INTERNAL_ERR = 0; CompassError.COMPASS_NOT_SUPPORTED = 20; module.exports = CompassError; - }); // file: lib/common/plugin/CompassHeading.js @@ -1332,7 +1339,6 @@ var CompassHeading = function(magneticHeading, trueHeading, headingAccuracy, tim }; module.exports = CompassHeading; - }); // file: lib/common/plugin/ConfigurationData.js @@ -1341,18 +1347,17 @@ define("cordova/plugin/ConfigurationData", function(require, exports, module) { * Encapsulates a set of parameters that the capture device supports. */ function ConfigurationData() { - // The ASCII-encoded string in lower case representing the media type. - this.type = null; - // The height attribute represents height of the image or video in pixels. - // In the case of a sound clip this attribute has value 0. + // The ASCII-encoded string in lower case representing the media type. + this.type = null; + // The height attribute represents height of the image or video in pixels. + // In the case of a sound clip this attribute has value 0. this.height = 0; - // The width attribute represents width of the image or video in pixels. + // The width attribute represents width of the image or video in pixels. // In the case of a sound clip this attribute has value 0 this.width = 0; } module.exports = ConfigurationData; - }); // file: lib/common/plugin/Connection.js @@ -1361,15 +1366,14 @@ define("cordova/plugin/Connection", function(require, exports, module) { * Network status */ module.exports = { - UNKNOWN: "unknown", - ETHERNET: "ethernet", - WIFI: "wifi", - CELL_2G: "2g", - CELL_3G: "3g", - CELL_4G: "4g", - NONE: "none" + UNKNOWN: "unknown", + ETHERNET: "ethernet", + WIFI: "wifi", + CELL_2G: "2g", + CELL_3G: "3g", + CELL_4G: "4g", + NONE: "none" }; - }); // file: lib/common/plugin/Contact.js @@ -1390,7 +1394,7 @@ function convertIn(contact) { console.log("Cordova Contact convertIn error: exception creating date."); } return contact; -}; +} /** * Converts Complex objects into primitives @@ -1399,7 +1403,7 @@ function convertIn(contact) { function convertOut(contact) { var value = contact.birthday; - if (value != null) { + if (value !== null) { // try to make it a Date object if it is not already if (!value instanceof Date){ try { @@ -1414,7 +1418,7 @@ function convertOut(contact) { contact.birthday = value; } return contact; -}; +} /** * Contains information about a single contact. @@ -1533,7 +1537,7 @@ Contact.prototype.save = function(successCB, errorCB) { var fail = function(code) { errorCB(new ContactError(code)); }; - var success = function(result) { + var success = function(result) { if (result) { if (typeof successCB === 'function') { var fullContact = require('cordova/plugin/contacts').create(result); @@ -1545,13 +1549,12 @@ Contact.prototype.save = function(successCB, errorCB) { fail(ContactError.UNKNOWN_ERROR); } }; - var dupContact = convertOut(utils.clone(this)); - exec(success, fail, "Contacts", "save", [dupContact]); + var dupContact = convertOut(utils.clone(this)); + exec(success, fail, "Contacts", "save", [dupContact]); }; module.exports = Contact; - }); // file: lib/common/plugin/ContactAddress.js @@ -1581,7 +1584,6 @@ var ContactAddress = function(pref, type, formatted, streetAddress, locality, re }; module.exports = ContactAddress; - }); // file: lib/common/plugin/ContactError.js @@ -1607,7 +1609,6 @@ ContactError.NOT_SUPPORTED_ERROR = 5; ContactError.PERMISSION_DENIED_ERROR = 20; module.exports = ContactError; - }); // file: lib/common/plugin/ContactField.js @@ -1628,7 +1629,6 @@ var ContactField = function(type, value, pref) { }; module.exports = ContactField; - }); // file: lib/common/plugin/ContactFindOptions.js @@ -1646,7 +1646,6 @@ var ContactFindOptions = function(filter, multiple) { }; module.exports = ContactFindOptions; - }); // file: lib/common/plugin/ContactName.js @@ -1671,7 +1670,6 @@ var ContactName = function(formatted, familyName, givenName, middle, prefix, suf }; module.exports = ContactName; - }); // file: lib/common/plugin/ContactOrganization.js @@ -1699,7 +1697,6 @@ var ContactOrganization = function(pref, type, name, dept, title) { }; module.exports = ContactOrganization; - }); // file: lib/common/plugin/Coordinates.js @@ -1747,7 +1744,6 @@ var Coordinates = function(lat, lng, alt, acc, head, vel, altacc) { }; module.exports = Coordinates; - }); // file: lib/common/plugin/DirectoryEntry.js @@ -1755,6 +1751,7 @@ define("cordova/plugin/DirectoryEntry", function(require, exports, module) { var utils = require('cordova/utils'), exec = require('cordova/exec'), Entry = require('cordova/plugin/Entry'), + FileError = require('cordova/plugin/FileError'), DirectoryReader = require('cordova/plugin/DirectoryReader'); /** @@ -1837,7 +1834,8 @@ module.exports = DirectoryEntry; // file: lib/common/plugin/DirectoryReader.js define("cordova/plugin/DirectoryReader", function(require, exports, module) { -var exec = require('cordova/exec'); +var exec = require('cordova/exec'), + FileError = require('cordova/plugin/FileError') ; /** * An interface that lists the files and directories in a directory. @@ -1858,10 +1856,10 @@ DirectoryReader.prototype.readEntries = function(successCallback, errorCallback) for (var i=0; i 0) { - // is an iOS request for watch by filter, no timer needed - timers[id] = "iOS"; - compass.getCurrentHeading(successCallback, errorCallback, options); - } else { - // Start watch timer to get headings - timers[id] = window.setInterval(function() { - compass.getCurrentHeading(successCallback, errorCallback); - }, frequency); - } - + if (filter > 0) { + // is an iOS request for watch by filter, no timer needed + timers[id] = "iOS"; + compass.getCurrentHeading(successCallback, errorCallback, options); + } else { + // Start watch timer to get headings + timers[id] = window.setInterval(function() { + compass.getCurrentHeading(successCallback, errorCallback); + }, frequency); + } + return id; }, @@ -4410,19 +4383,18 @@ var exec = require('cordova/exec'), clearWatch:function(id) { // Stop javascript timer & remove from timer list if (id && timers[id]) { - if (timers[id] != "iOS") { - clearInterval(timers[id]); - } else { - // is iOS watch by filter so call into device to stop - exec(null, null, "Compass", "stopHeading", []); - } - delete timers[id]; + if (timers[id] != "iOS") { + clearInterval(timers[id]); + } else { + // is iOS watch by filter so call into device to stop + exec(null, null, "Compass", "stopHeading", []); + } + delete timers[id]; } } }; module.exports = compass; - }); // file: lib/common/plugin/contacts.js @@ -4484,7 +4456,6 @@ var contacts = { }; module.exports = contacts; - }); // file: lib/common/plugin/geolocation.js @@ -4548,7 +4519,7 @@ var geolocation = { errorCallback(new PositionError(e.code, e.message)); }; - exec(win, fail, "Geolocation", "getLocation", [options.enableHighAccuracy, options.timeout, options.maximumAge]); + exec(win, fail, "Geolocation", "getLocation", [options.enableHighAccuracy, options.timeout, options.maximumAge]); }, /** * Asynchronously watches the geolocation for changes to geolocation. When a change occurs, @@ -4583,7 +4554,6 @@ var geolocation = { }; module.exports = geolocation; - }); // file: lib/common/plugin/network.js @@ -4648,7 +4618,6 @@ NetworkConnection.prototype.getInfo = function (successCallback, errorCallback) }; module.exports = new NetworkConnection(); - }); // file: lib/common/plugin/notification.js @@ -4709,7 +4678,6 @@ module.exports = { exec(null, null, "Notification", "beep", [count]); } }; - }); // file: lib/common/plugin/requestFileSystem.js @@ -4754,13 +4722,13 @@ var requestFileSystem = function(type, size, successCallback, errorCallback) { }; module.exports = requestFileSystem; - }); // file: lib/common/plugin/resolveLocalFileSystemURI.js define("cordova/plugin/resolveLocalFileSystemURI", function(require, exports, module) { var DirectoryEntry = require('cordova/plugin/DirectoryEntry'), FileEntry = require('cordova/plugin/FileEntry'), + FileError = require('cordova/plugin/FileError'), exec = require('cordova/exec'); /** @@ -4822,12 +4790,12 @@ var _self = { * Does a deep clone of the object. */ clone: function(obj) { - if(!obj) { + if(!obj) { return obj; } - + var retVal, i; - + if(obj instanceof Array){ retVal = []; for(i = 0; i < obj.length; ++i){ @@ -4835,15 +4803,15 @@ var _self = { } return retVal; } - + if (obj instanceof Function) { return obj; } - + if(!(obj instanceof Object)){ return obj; } - + if(obj instanceof Date){ return obj; } @@ -4886,7 +4854,7 @@ var _self = { */ extend: (function() { // proxy used to establish prototype chain - var F = function() {}; + var F = function() {}; // extend Child from Parent return function(Child, Parent) { F.prototype = Parent.prototype; @@ -4909,7 +4877,6 @@ var _self = { }; module.exports = _self; - }); @@ -4920,20 +4887,6 @@ window.cordova = require('cordova'); var channel = require("cordova/channel"), _self = { boot: function () { - //--------------- - // Event handling - //--------------- - - /** - * Listen for DOMContentLoaded and notify our channel subscribers. - */ - document.addEventListener('DOMContentLoaded', function() { - channel.onDOMContentLoaded.fire(); - }, false); - if (document.readyState == 'complete') { - channel.onDOMContentLoaded.fire(); - } - /** * Create all cordova objects once page has fully loaded and native side is ready. */ @@ -4966,11 +4919,11 @@ window.cordova = require('cordova'); channel.join(function() { channel.onDeviceReady.fire(); }, channel.deviceReadyChannelsArray); - + }, [ channel.onDOMContentLoaded, channel.onNativeReady ]); } }; - + // boot up once native side is ready channel.onNativeReady.subscribeOnce(_self.boot); @@ -4983,5 +4936,4 @@ window.cordova = require('cordova'); }(window)); - })(); \ No newline at end of file diff --git a/lib/android/example/libs/cordova-1.6.1.jar b/lib/android/example/.cordova/android/cordova-1.7.0rc1.jar similarity index 74% rename from lib/android/example/libs/cordova-1.6.1.jar rename to lib/android/example/.cordova/android/cordova-1.7.0rc1.jar index 75b7e058..bfa27ab8 100644 Binary files a/lib/android/example/libs/cordova-1.6.1.jar and b/lib/android/example/.cordova/android/cordova-1.7.0rc1.jar differ diff --git a/lib/android/cordova-1.6.1.js b/lib/android/example/.cordova/android/cordova-1.7.0rc1.js similarity index 95% rename from lib/android/cordova-1.6.1.js rename to lib/android/example/.cordova/android/cordova-1.7.0rc1.js index 1b879160..cf56912e 100644 --- a/lib/android/cordova-1.6.1.js +++ b/lib/android/example/.cordova/android/cordova-1.7.0rc1.js @@ -1,6 +1,6 @@ -// commit b2de4baa76a94ecb916619a536339ffee9ef6843 +// commit 017a948047e355ae0c2cdc8c4188ae57b115528a -// File generated at :: Tue Apr 17 2012 12:19:35 GMT-0700 (PDT) +// File generated at :: Mon Apr 23 2012 11:36:23 GMT-0700 (PDT) /* Licensed to the Apache Software Foundation (ASF) under one @@ -67,10 +67,20 @@ if (typeof module === "object" && typeof require === "function") { module.exports.require = require; module.exports.define = define; } - // file: lib/cordova.js define("cordova", function(require, exports, module) { var channel = require('cordova/channel'); + +/** + * Listen for DOMContentLoaded and notify our channel subscribers. + */ +document.addEventListener('DOMContentLoaded', function() { + channel.onDOMContentLoaded.fire(); +}, false); +if (document.readyState == 'complete') { + channel.onDOMContentLoaded.fire(); +} + /** * Intercept calls to addEventListener + removeEventListener and handle deviceready, * resume, and pause events. @@ -115,13 +125,18 @@ window.addEventListener = function(evt, handler, capture) { }; document.removeEventListener = function(evt, handler, capture) { - var e = evt.toLowerCase(); - // If unsubcribing from an event that is handled by a plugin - if (typeof documentEventHandlers[e] != "undefined") { - documentEventHandlers[e].unsubscribe(handler); - } else { - m_document_removeEventListener.call(document, evt, handler, capture); - } + var e = evt.toLowerCase(); + // Check for pause/resume events first. + if (e == 'resume') { + channel.onResume.unsubscribe(handler); + } else if (e == 'pause') { + channel.onPause.unsubscribe(handler); + // If unsubcribing from an event that is handled by a plugin + } else if (typeof documentEventHandlers[e] != "undefined") { + documentEventHandlers[e].unsubscribe(handler); + } else { + m_document_removeEventListener.call(document, evt, handler, capture); + } }; window.removeEventListener = function(evt, handler, capture) { @@ -149,9 +164,9 @@ function createEvent(type, data) { if(typeof window.console === "undefined") { - window.console = { - log:function(){} - }; + window.console = { + log:function(){} + }; } var cordova = { @@ -292,7 +307,7 @@ var cordova = { console.log("Error: Plugin "+name+" already exists."); } }, - + addConstructor: function(func) { channel.onCordovaReady.subscribeOnce(function() { try { @@ -304,7 +319,7 @@ var cordova = { } }; -/** +/** * Legacy variable for plugin support * TODO: remove in 2.0. */ @@ -326,6 +341,8 @@ module.exports = cordova; // file: lib/common/builder.js define("cordova/builder", function(require, exports, module) { +var utils = require('cordova/utils'); + function each(objects, func, context) { for (var prop in objects) { if (objects.hasOwnProperty(prop)) { @@ -502,10 +519,10 @@ var Channel = function(type, opts) { /** * cordova Channels that must fire before "deviceready" is fired. - */ + */ deviceReadyChannelsArray: [], deviceReadyChannelsMap: {}, - + /** * Indicate that a feature needs to be initialized before it is ready to be used. * This holds up Cordova's "deviceready" event until the feature has been initialized @@ -542,7 +559,7 @@ var Channel = function(type, opts) { utils = require('cordova/utils'); /** - * Subscribes the given function to the channel. Any time that + * Subscribes the given function to the channel. Any time that * Channel.fire is called so too will the function. * Optionally specify an execution context for the function * and a guid that can be used to stop subscribing to the channel. @@ -587,7 +604,7 @@ Channel.prototype.subscribeOnce = function(f, c) { return g; }; -/** +/** * Unsubscribes the function with the given guid from the channel. */ Channel.prototype.unsubscribe = function(g) { @@ -601,7 +618,7 @@ Channel.prototype.unsubscribe = function(g) { if (this.events.onUnsubscribe) this.events.onUnsubscribe.call(this); }; -/** +/** * Calls all functions subscribed to this channel. */ Channel.prototype.fire = function(e) { @@ -656,7 +673,6 @@ channel.waitForInitialization('onCordovaInfoReady'); channel.waitForInitialization('onCordovaConnectionReady'); module.exports = channel; - }); // file: lib/common/common.js @@ -841,7 +857,6 @@ module.exports = { } } }; - }); // file: lib/android/exec.js @@ -873,7 +888,8 @@ module.exports = function(success, fail, service, action, args) { // If a result was returned if (r.length > 0) { - eval("var v="+r+";"); + var v; + eval("v="+r+";"); // If status is OK, then return value back to caller if (v.status === cordova.callbackStatus.OK) { @@ -1003,7 +1019,7 @@ module.exports = { var db = null; try { db = originalOpenDatabase(name, version, desc, size); - } + } catch (ex) { if (ex.code === 18) { db = null; @@ -1018,7 +1034,7 @@ module.exports = { else { return db; } - + }; } @@ -1077,7 +1093,6 @@ module.exports = { } } }; - }); // file: lib/common/plugin/Acceleration.js @@ -1090,7 +1105,6 @@ var Acceleration = function(x, y, z, timestamp) { }; module.exports = Acceleration; - }); // file: lib/common/plugin/Camera.js @@ -1172,35 +1186,34 @@ cameraExport.getPicture = function(successCallback, errorCallback, options) { if (typeof options.encodingType == "number") { encodingType = options.encodingType; } - + var mediaType = Camera.MediaType.PICTURE; if (typeof options.mediaType == "number") { mediaType = options.mediaType; } var allowEdit = false; if (typeof options.allowEdit == "boolean") { - allowEdit = options.allowEdit; + allowEdit = options.allowEdit; } else if (typeof options.allowEdit == "number") { - allowEdit = options.allowEdit <= 0 ? false : true; + allowEdit = options.allowEdit <= 0 ? false : true; } var correctOrientation = false; if (typeof options.correctOrientation == "boolean") { - correctOrientation = options.correctOrientation; + correctOrientation = options.correctOrientation; } else if (typeof options.correctOrientation == "number") { - correctOrientation = options.correctOrientation <=0 ? false : true; + correctOrientation = options.correctOrientation <=0 ? false : true; } var saveToPhotoAlbum = false; - if (typeof options.saveToPhotoAlbum == "boolean") { - saveToPhotoAlbum = options.saveToPhotoAlbum; + if (typeof options.saveToPhotoAlbum == "boolean") { + saveToPhotoAlbum = options.saveToPhotoAlbum; } else if (typeof options.saveToPhotoAlbum == "number") { - saveToPhotoAlbum = options.saveToPhotoAlbum <=0 ? false : true; + saveToPhotoAlbum = options.saveToPhotoAlbum <=0 ? false : true; } exec(successCallback, errorCallback, "Camera", "takePicture", [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType, mediaType, allowEdit, correctOrientation, saveToPhotoAlbum]); -} +}; module.exports = cameraExport; - }); // file: lib/common/plugin/CameraConstants.js @@ -1225,7 +1238,6 @@ module.exports = { SAVEDPHOTOALBUM : 2 // Choose image from picture library (same as PHOTOLIBRARY for Android) } }; - }); // file: lib/common/plugin/CaptureAudioOptions.js @@ -1234,16 +1246,15 @@ define("cordova/plugin/CaptureAudioOptions", function(require, exports, module) * Encapsulates all audio capture operation configuration options. */ var CaptureAudioOptions = function(){ - // Upper limit of sound clips user can record. Value must be equal or greater than 1. - this.limit = 1; - // Maximum duration of a single sound clip in seconds. - this.duration = 0; - // The selected audio mode. Must match with one of the elements in supportedAudioModes array. - this.mode = null; + // Upper limit of sound clips user can record. Value must be equal or greater than 1. + this.limit = 1; + // Maximum duration of a single sound clip in seconds. + this.duration = 0; + // The selected audio mode. Must match with one of the elements in supportedAudioModes array. + this.mode = null; }; module.exports = CaptureAudioOptions; - }); // file: lib/common/plugin/CaptureError.js @@ -1255,7 +1266,7 @@ var CaptureError = function(c) { this.code = c || null; }; -// Camera or microphone failed to capture image or sound. +// Camera or microphone failed to capture image or sound. CaptureError.CAPTURE_INTERNAL_ERR = 0; // Camera application or audio capture application is currently serving other capture request. CaptureError.CAPTURE_APPLICATION_BUSY = 1; @@ -1267,7 +1278,6 @@ CaptureError.CAPTURE_NO_MEDIA_FILES = 3; CaptureError.CAPTURE_NOT_SUPPORTED = 20; module.exports = CaptureError; - }); // file: lib/common/plugin/CaptureImageOptions.js @@ -1276,14 +1286,13 @@ define("cordova/plugin/CaptureImageOptions", function(require, exports, module) * Encapsulates all image capture operation configuration options. */ var CaptureImageOptions = function(){ - // Upper limit of images user can take. Value must be equal or greater than 1. - this.limit = 1; - // The selected image mode. Must match with one of the elements in supportedImageModes array. - this.mode = null; + // Upper limit of images user can take. Value must be equal or greater than 1. + this.limit = 1; + // The selected image mode. Must match with one of the elements in supportedImageModes array. + this.mode = null; }; module.exports = CaptureImageOptions; - }); // file: lib/common/plugin/CaptureVideoOptions.js @@ -1292,16 +1301,15 @@ define("cordova/plugin/CaptureVideoOptions", function(require, exports, module) * Encapsulates all video capture operation configuration options. */ var CaptureVideoOptions = function(){ - // Upper limit of videos user can record. Value must be equal or greater than 1. - this.limit = 1; - // Maximum duration of a single video clip in seconds. - this.duration = 0; - // The selected video mode. Must match with one of the elements in supportedVideoModes array. - this.mode = null; + // Upper limit of videos user can record. Value must be equal or greater than 1. + this.limit = 1; + // Maximum duration of a single video clip in seconds. + this.duration = 0; + // The selected video mode. Must match with one of the elements in supportedVideoModes array. + this.mode = null; }; module.exports = CaptureVideoOptions; - }); // file: lib/common/plugin/CompassError.js @@ -1319,7 +1327,6 @@ CompassError.COMPASS_INTERNAL_ERR = 0; CompassError.COMPASS_NOT_SUPPORTED = 20; module.exports = CompassError; - }); // file: lib/common/plugin/CompassHeading.js @@ -1332,7 +1339,6 @@ var CompassHeading = function(magneticHeading, trueHeading, headingAccuracy, tim }; module.exports = CompassHeading; - }); // file: lib/common/plugin/ConfigurationData.js @@ -1341,18 +1347,17 @@ define("cordova/plugin/ConfigurationData", function(require, exports, module) { * Encapsulates a set of parameters that the capture device supports. */ function ConfigurationData() { - // The ASCII-encoded string in lower case representing the media type. - this.type = null; - // The height attribute represents height of the image or video in pixels. - // In the case of a sound clip this attribute has value 0. + // The ASCII-encoded string in lower case representing the media type. + this.type = null; + // The height attribute represents height of the image or video in pixels. + // In the case of a sound clip this attribute has value 0. this.height = 0; - // The width attribute represents width of the image or video in pixels. + // The width attribute represents width of the image or video in pixels. // In the case of a sound clip this attribute has value 0 this.width = 0; } module.exports = ConfigurationData; - }); // file: lib/common/plugin/Connection.js @@ -1361,15 +1366,14 @@ define("cordova/plugin/Connection", function(require, exports, module) { * Network status */ module.exports = { - UNKNOWN: "unknown", - ETHERNET: "ethernet", - WIFI: "wifi", - CELL_2G: "2g", - CELL_3G: "3g", - CELL_4G: "4g", - NONE: "none" + UNKNOWN: "unknown", + ETHERNET: "ethernet", + WIFI: "wifi", + CELL_2G: "2g", + CELL_3G: "3g", + CELL_4G: "4g", + NONE: "none" }; - }); // file: lib/common/plugin/Contact.js @@ -1390,7 +1394,7 @@ function convertIn(contact) { console.log("Cordova Contact convertIn error: exception creating date."); } return contact; -}; +} /** * Converts Complex objects into primitives @@ -1399,7 +1403,7 @@ function convertIn(contact) { function convertOut(contact) { var value = contact.birthday; - if (value != null) { + if (value !== null) { // try to make it a Date object if it is not already if (!value instanceof Date){ try { @@ -1414,7 +1418,7 @@ function convertOut(contact) { contact.birthday = value; } return contact; -}; +} /** * Contains information about a single contact. @@ -1533,7 +1537,7 @@ Contact.prototype.save = function(successCB, errorCB) { var fail = function(code) { errorCB(new ContactError(code)); }; - var success = function(result) { + var success = function(result) { if (result) { if (typeof successCB === 'function') { var fullContact = require('cordova/plugin/contacts').create(result); @@ -1545,13 +1549,12 @@ Contact.prototype.save = function(successCB, errorCB) { fail(ContactError.UNKNOWN_ERROR); } }; - var dupContact = convertOut(utils.clone(this)); - exec(success, fail, "Contacts", "save", [dupContact]); + var dupContact = convertOut(utils.clone(this)); + exec(success, fail, "Contacts", "save", [dupContact]); }; module.exports = Contact; - }); // file: lib/common/plugin/ContactAddress.js @@ -1581,7 +1584,6 @@ var ContactAddress = function(pref, type, formatted, streetAddress, locality, re }; module.exports = ContactAddress; - }); // file: lib/common/plugin/ContactError.js @@ -1607,7 +1609,6 @@ ContactError.NOT_SUPPORTED_ERROR = 5; ContactError.PERMISSION_DENIED_ERROR = 20; module.exports = ContactError; - }); // file: lib/common/plugin/ContactField.js @@ -1628,7 +1629,6 @@ var ContactField = function(type, value, pref) { }; module.exports = ContactField; - }); // file: lib/common/plugin/ContactFindOptions.js @@ -1646,7 +1646,6 @@ var ContactFindOptions = function(filter, multiple) { }; module.exports = ContactFindOptions; - }); // file: lib/common/plugin/ContactName.js @@ -1671,7 +1670,6 @@ var ContactName = function(formatted, familyName, givenName, middle, prefix, suf }; module.exports = ContactName; - }); // file: lib/common/plugin/ContactOrganization.js @@ -1699,7 +1697,6 @@ var ContactOrganization = function(pref, type, name, dept, title) { }; module.exports = ContactOrganization; - }); // file: lib/common/plugin/Coordinates.js @@ -1747,7 +1744,6 @@ var Coordinates = function(lat, lng, alt, acc, head, vel, altacc) { }; module.exports = Coordinates; - }); // file: lib/common/plugin/DirectoryEntry.js @@ -1755,6 +1751,7 @@ define("cordova/plugin/DirectoryEntry", function(require, exports, module) { var utils = require('cordova/utils'), exec = require('cordova/exec'), Entry = require('cordova/plugin/Entry'), + FileError = require('cordova/plugin/FileError'), DirectoryReader = require('cordova/plugin/DirectoryReader'); /** @@ -1837,7 +1834,8 @@ module.exports = DirectoryEntry; // file: lib/common/plugin/DirectoryReader.js define("cordova/plugin/DirectoryReader", function(require, exports, module) { -var exec = require('cordova/exec'); +var exec = require('cordova/exec'), + FileError = require('cordova/plugin/FileError') ; /** * An interface that lists the files and directories in a directory. @@ -1858,10 +1856,10 @@ DirectoryReader.prototype.readEntries = function(successCallback, errorCallback) for (var i=0; i 0) { - // is an iOS request for watch by filter, no timer needed - timers[id] = "iOS"; - compass.getCurrentHeading(successCallback, errorCallback, options); - } else { - // Start watch timer to get headings - timers[id] = window.setInterval(function() { - compass.getCurrentHeading(successCallback, errorCallback); - }, frequency); - } - + if (filter > 0) { + // is an iOS request for watch by filter, no timer needed + timers[id] = "iOS"; + compass.getCurrentHeading(successCallback, errorCallback, options); + } else { + // Start watch timer to get headings + timers[id] = window.setInterval(function() { + compass.getCurrentHeading(successCallback, errorCallback); + }, frequency); + } + return id; }, @@ -4410,19 +4383,18 @@ var exec = require('cordova/exec'), clearWatch:function(id) { // Stop javascript timer & remove from timer list if (id && timers[id]) { - if (timers[id] != "iOS") { - clearInterval(timers[id]); - } else { - // is iOS watch by filter so call into device to stop - exec(null, null, "Compass", "stopHeading", []); - } - delete timers[id]; + if (timers[id] != "iOS") { + clearInterval(timers[id]); + } else { + // is iOS watch by filter so call into device to stop + exec(null, null, "Compass", "stopHeading", []); + } + delete timers[id]; } } }; module.exports = compass; - }); // file: lib/common/plugin/contacts.js @@ -4484,7 +4456,6 @@ var contacts = { }; module.exports = contacts; - }); // file: lib/common/plugin/geolocation.js @@ -4548,7 +4519,7 @@ var geolocation = { errorCallback(new PositionError(e.code, e.message)); }; - exec(win, fail, "Geolocation", "getLocation", [options.enableHighAccuracy, options.timeout, options.maximumAge]); + exec(win, fail, "Geolocation", "getLocation", [options.enableHighAccuracy, options.timeout, options.maximumAge]); }, /** * Asynchronously watches the geolocation for changes to geolocation. When a change occurs, @@ -4583,7 +4554,6 @@ var geolocation = { }; module.exports = geolocation; - }); // file: lib/common/plugin/network.js @@ -4648,7 +4618,6 @@ NetworkConnection.prototype.getInfo = function (successCallback, errorCallback) }; module.exports = new NetworkConnection(); - }); // file: lib/common/plugin/notification.js @@ -4709,7 +4678,6 @@ module.exports = { exec(null, null, "Notification", "beep", [count]); } }; - }); // file: lib/common/plugin/requestFileSystem.js @@ -4754,13 +4722,13 @@ var requestFileSystem = function(type, size, successCallback, errorCallback) { }; module.exports = requestFileSystem; - }); // file: lib/common/plugin/resolveLocalFileSystemURI.js define("cordova/plugin/resolveLocalFileSystemURI", function(require, exports, module) { var DirectoryEntry = require('cordova/plugin/DirectoryEntry'), FileEntry = require('cordova/plugin/FileEntry'), + FileError = require('cordova/plugin/FileError'), exec = require('cordova/exec'); /** @@ -4822,12 +4790,12 @@ var _self = { * Does a deep clone of the object. */ clone: function(obj) { - if(!obj) { + if(!obj) { return obj; } - + var retVal, i; - + if(obj instanceof Array){ retVal = []; for(i = 0; i < obj.length; ++i){ @@ -4835,15 +4803,15 @@ var _self = { } return retVal; } - + if (obj instanceof Function) { return obj; } - + if(!(obj instanceof Object)){ return obj; } - + if(obj instanceof Date){ return obj; } @@ -4886,7 +4854,7 @@ var _self = { */ extend: (function() { // proxy used to establish prototype chain - var F = function() {}; + var F = function() {}; // extend Child from Parent return function(Child, Parent) { F.prototype = Parent.prototype; @@ -4909,7 +4877,6 @@ var _self = { }; module.exports = _self; - }); @@ -4920,20 +4887,6 @@ window.cordova = require('cordova'); var channel = require("cordova/channel"), _self = { boot: function () { - //--------------- - // Event handling - //--------------- - - /** - * Listen for DOMContentLoaded and notify our channel subscribers. - */ - document.addEventListener('DOMContentLoaded', function() { - channel.onDOMContentLoaded.fire(); - }, false); - if (document.readyState == 'complete') { - channel.onDOMContentLoaded.fire(); - } - /** * Create all cordova objects once page has fully loaded and native side is ready. */ @@ -4966,11 +4919,11 @@ window.cordova = require('cordova'); channel.join(function() { channel.onDeviceReady.fire(); }, channel.deviceReadyChannelsArray); - + }, [ channel.onDOMContentLoaded, channel.onNativeReady ]); } }; - + // boot up once native side is ready channel.onNativeReady.subscribeOnce(_self.boot); @@ -4983,5 +4936,4 @@ window.cordova = require('cordova'); }(window)); - })(); \ No newline at end of file diff --git a/lib/android/example/.cordova/config b/lib/android/example/.cordova/config index 85ef6878..15f1f59c 100644 --- a/lib/android/example/.cordova/config +++ b/lib/android/example/.cordova/config @@ -1,4 +1,4 @@ -VERSION=1.6.1 +VERSION=1.7.0rc1 PROJECT_PATH=./example PACKAGE=org.apache.cordova.example ACTIVITY=cordovaExample diff --git a/lib/android/example/.cordova/android/cordova-1.6.1.js b/lib/android/example/assets/www/cordova-1.7.0rc1.js similarity index 95% rename from lib/android/example/.cordova/android/cordova-1.6.1.js rename to lib/android/example/assets/www/cordova-1.7.0rc1.js index 1b879160..cf56912e 100644 --- a/lib/android/example/.cordova/android/cordova-1.6.1.js +++ b/lib/android/example/assets/www/cordova-1.7.0rc1.js @@ -1,6 +1,6 @@ -// commit b2de4baa76a94ecb916619a536339ffee9ef6843 +// commit 017a948047e355ae0c2cdc8c4188ae57b115528a -// File generated at :: Tue Apr 17 2012 12:19:35 GMT-0700 (PDT) +// File generated at :: Mon Apr 23 2012 11:36:23 GMT-0700 (PDT) /* Licensed to the Apache Software Foundation (ASF) under one @@ -67,10 +67,20 @@ if (typeof module === "object" && typeof require === "function") { module.exports.require = require; module.exports.define = define; } - // file: lib/cordova.js define("cordova", function(require, exports, module) { var channel = require('cordova/channel'); + +/** + * Listen for DOMContentLoaded and notify our channel subscribers. + */ +document.addEventListener('DOMContentLoaded', function() { + channel.onDOMContentLoaded.fire(); +}, false); +if (document.readyState == 'complete') { + channel.onDOMContentLoaded.fire(); +} + /** * Intercept calls to addEventListener + removeEventListener and handle deviceready, * resume, and pause events. @@ -115,13 +125,18 @@ window.addEventListener = function(evt, handler, capture) { }; document.removeEventListener = function(evt, handler, capture) { - var e = evt.toLowerCase(); - // If unsubcribing from an event that is handled by a plugin - if (typeof documentEventHandlers[e] != "undefined") { - documentEventHandlers[e].unsubscribe(handler); - } else { - m_document_removeEventListener.call(document, evt, handler, capture); - } + var e = evt.toLowerCase(); + // Check for pause/resume events first. + if (e == 'resume') { + channel.onResume.unsubscribe(handler); + } else if (e == 'pause') { + channel.onPause.unsubscribe(handler); + // If unsubcribing from an event that is handled by a plugin + } else if (typeof documentEventHandlers[e] != "undefined") { + documentEventHandlers[e].unsubscribe(handler); + } else { + m_document_removeEventListener.call(document, evt, handler, capture); + } }; window.removeEventListener = function(evt, handler, capture) { @@ -149,9 +164,9 @@ function createEvent(type, data) { if(typeof window.console === "undefined") { - window.console = { - log:function(){} - }; + window.console = { + log:function(){} + }; } var cordova = { @@ -292,7 +307,7 @@ var cordova = { console.log("Error: Plugin "+name+" already exists."); } }, - + addConstructor: function(func) { channel.onCordovaReady.subscribeOnce(function() { try { @@ -304,7 +319,7 @@ var cordova = { } }; -/** +/** * Legacy variable for plugin support * TODO: remove in 2.0. */ @@ -326,6 +341,8 @@ module.exports = cordova; // file: lib/common/builder.js define("cordova/builder", function(require, exports, module) { +var utils = require('cordova/utils'); + function each(objects, func, context) { for (var prop in objects) { if (objects.hasOwnProperty(prop)) { @@ -502,10 +519,10 @@ var Channel = function(type, opts) { /** * cordova Channels that must fire before "deviceready" is fired. - */ + */ deviceReadyChannelsArray: [], deviceReadyChannelsMap: {}, - + /** * Indicate that a feature needs to be initialized before it is ready to be used. * This holds up Cordova's "deviceready" event until the feature has been initialized @@ -542,7 +559,7 @@ var Channel = function(type, opts) { utils = require('cordova/utils'); /** - * Subscribes the given function to the channel. Any time that + * Subscribes the given function to the channel. Any time that * Channel.fire is called so too will the function. * Optionally specify an execution context for the function * and a guid that can be used to stop subscribing to the channel. @@ -587,7 +604,7 @@ Channel.prototype.subscribeOnce = function(f, c) { return g; }; -/** +/** * Unsubscribes the function with the given guid from the channel. */ Channel.prototype.unsubscribe = function(g) { @@ -601,7 +618,7 @@ Channel.prototype.unsubscribe = function(g) { if (this.events.onUnsubscribe) this.events.onUnsubscribe.call(this); }; -/** +/** * Calls all functions subscribed to this channel. */ Channel.prototype.fire = function(e) { @@ -656,7 +673,6 @@ channel.waitForInitialization('onCordovaInfoReady'); channel.waitForInitialization('onCordovaConnectionReady'); module.exports = channel; - }); // file: lib/common/common.js @@ -841,7 +857,6 @@ module.exports = { } } }; - }); // file: lib/android/exec.js @@ -873,7 +888,8 @@ module.exports = function(success, fail, service, action, args) { // If a result was returned if (r.length > 0) { - eval("var v="+r+";"); + var v; + eval("v="+r+";"); // If status is OK, then return value back to caller if (v.status === cordova.callbackStatus.OK) { @@ -1003,7 +1019,7 @@ module.exports = { var db = null; try { db = originalOpenDatabase(name, version, desc, size); - } + } catch (ex) { if (ex.code === 18) { db = null; @@ -1018,7 +1034,7 @@ module.exports = { else { return db; } - + }; } @@ -1077,7 +1093,6 @@ module.exports = { } } }; - }); // file: lib/common/plugin/Acceleration.js @@ -1090,7 +1105,6 @@ var Acceleration = function(x, y, z, timestamp) { }; module.exports = Acceleration; - }); // file: lib/common/plugin/Camera.js @@ -1172,35 +1186,34 @@ cameraExport.getPicture = function(successCallback, errorCallback, options) { if (typeof options.encodingType == "number") { encodingType = options.encodingType; } - + var mediaType = Camera.MediaType.PICTURE; if (typeof options.mediaType == "number") { mediaType = options.mediaType; } var allowEdit = false; if (typeof options.allowEdit == "boolean") { - allowEdit = options.allowEdit; + allowEdit = options.allowEdit; } else if (typeof options.allowEdit == "number") { - allowEdit = options.allowEdit <= 0 ? false : true; + allowEdit = options.allowEdit <= 0 ? false : true; } var correctOrientation = false; if (typeof options.correctOrientation == "boolean") { - correctOrientation = options.correctOrientation; + correctOrientation = options.correctOrientation; } else if (typeof options.correctOrientation == "number") { - correctOrientation = options.correctOrientation <=0 ? false : true; + correctOrientation = options.correctOrientation <=0 ? false : true; } var saveToPhotoAlbum = false; - if (typeof options.saveToPhotoAlbum == "boolean") { - saveToPhotoAlbum = options.saveToPhotoAlbum; + if (typeof options.saveToPhotoAlbum == "boolean") { + saveToPhotoAlbum = options.saveToPhotoAlbum; } else if (typeof options.saveToPhotoAlbum == "number") { - saveToPhotoAlbum = options.saveToPhotoAlbum <=0 ? false : true; + saveToPhotoAlbum = options.saveToPhotoAlbum <=0 ? false : true; } exec(successCallback, errorCallback, "Camera", "takePicture", [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType, mediaType, allowEdit, correctOrientation, saveToPhotoAlbum]); -} +}; module.exports = cameraExport; - }); // file: lib/common/plugin/CameraConstants.js @@ -1225,7 +1238,6 @@ module.exports = { SAVEDPHOTOALBUM : 2 // Choose image from picture library (same as PHOTOLIBRARY for Android) } }; - }); // file: lib/common/plugin/CaptureAudioOptions.js @@ -1234,16 +1246,15 @@ define("cordova/plugin/CaptureAudioOptions", function(require, exports, module) * Encapsulates all audio capture operation configuration options. */ var CaptureAudioOptions = function(){ - // Upper limit of sound clips user can record. Value must be equal or greater than 1. - this.limit = 1; - // Maximum duration of a single sound clip in seconds. - this.duration = 0; - // The selected audio mode. Must match with one of the elements in supportedAudioModes array. - this.mode = null; + // Upper limit of sound clips user can record. Value must be equal or greater than 1. + this.limit = 1; + // Maximum duration of a single sound clip in seconds. + this.duration = 0; + // The selected audio mode. Must match with one of the elements in supportedAudioModes array. + this.mode = null; }; module.exports = CaptureAudioOptions; - }); // file: lib/common/plugin/CaptureError.js @@ -1255,7 +1266,7 @@ var CaptureError = function(c) { this.code = c || null; }; -// Camera or microphone failed to capture image or sound. +// Camera or microphone failed to capture image or sound. CaptureError.CAPTURE_INTERNAL_ERR = 0; // Camera application or audio capture application is currently serving other capture request. CaptureError.CAPTURE_APPLICATION_BUSY = 1; @@ -1267,7 +1278,6 @@ CaptureError.CAPTURE_NO_MEDIA_FILES = 3; CaptureError.CAPTURE_NOT_SUPPORTED = 20; module.exports = CaptureError; - }); // file: lib/common/plugin/CaptureImageOptions.js @@ -1276,14 +1286,13 @@ define("cordova/plugin/CaptureImageOptions", function(require, exports, module) * Encapsulates all image capture operation configuration options. */ var CaptureImageOptions = function(){ - // Upper limit of images user can take. Value must be equal or greater than 1. - this.limit = 1; - // The selected image mode. Must match with one of the elements in supportedImageModes array. - this.mode = null; + // Upper limit of images user can take. Value must be equal or greater than 1. + this.limit = 1; + // The selected image mode. Must match with one of the elements in supportedImageModes array. + this.mode = null; }; module.exports = CaptureImageOptions; - }); // file: lib/common/plugin/CaptureVideoOptions.js @@ -1292,16 +1301,15 @@ define("cordova/plugin/CaptureVideoOptions", function(require, exports, module) * Encapsulates all video capture operation configuration options. */ var CaptureVideoOptions = function(){ - // Upper limit of videos user can record. Value must be equal or greater than 1. - this.limit = 1; - // Maximum duration of a single video clip in seconds. - this.duration = 0; - // The selected video mode. Must match with one of the elements in supportedVideoModes array. - this.mode = null; + // Upper limit of videos user can record. Value must be equal or greater than 1. + this.limit = 1; + // Maximum duration of a single video clip in seconds. + this.duration = 0; + // The selected video mode. Must match with one of the elements in supportedVideoModes array. + this.mode = null; }; module.exports = CaptureVideoOptions; - }); // file: lib/common/plugin/CompassError.js @@ -1319,7 +1327,6 @@ CompassError.COMPASS_INTERNAL_ERR = 0; CompassError.COMPASS_NOT_SUPPORTED = 20; module.exports = CompassError; - }); // file: lib/common/plugin/CompassHeading.js @@ -1332,7 +1339,6 @@ var CompassHeading = function(magneticHeading, trueHeading, headingAccuracy, tim }; module.exports = CompassHeading; - }); // file: lib/common/plugin/ConfigurationData.js @@ -1341,18 +1347,17 @@ define("cordova/plugin/ConfigurationData", function(require, exports, module) { * Encapsulates a set of parameters that the capture device supports. */ function ConfigurationData() { - // The ASCII-encoded string in lower case representing the media type. - this.type = null; - // The height attribute represents height of the image or video in pixels. - // In the case of a sound clip this attribute has value 0. + // The ASCII-encoded string in lower case representing the media type. + this.type = null; + // The height attribute represents height of the image or video in pixels. + // In the case of a sound clip this attribute has value 0. this.height = 0; - // The width attribute represents width of the image or video in pixels. + // The width attribute represents width of the image or video in pixels. // In the case of a sound clip this attribute has value 0 this.width = 0; } module.exports = ConfigurationData; - }); // file: lib/common/plugin/Connection.js @@ -1361,15 +1366,14 @@ define("cordova/plugin/Connection", function(require, exports, module) { * Network status */ module.exports = { - UNKNOWN: "unknown", - ETHERNET: "ethernet", - WIFI: "wifi", - CELL_2G: "2g", - CELL_3G: "3g", - CELL_4G: "4g", - NONE: "none" + UNKNOWN: "unknown", + ETHERNET: "ethernet", + WIFI: "wifi", + CELL_2G: "2g", + CELL_3G: "3g", + CELL_4G: "4g", + NONE: "none" }; - }); // file: lib/common/plugin/Contact.js @@ -1390,7 +1394,7 @@ function convertIn(contact) { console.log("Cordova Contact convertIn error: exception creating date."); } return contact; -}; +} /** * Converts Complex objects into primitives @@ -1399,7 +1403,7 @@ function convertIn(contact) { function convertOut(contact) { var value = contact.birthday; - if (value != null) { + if (value !== null) { // try to make it a Date object if it is not already if (!value instanceof Date){ try { @@ -1414,7 +1418,7 @@ function convertOut(contact) { contact.birthday = value; } return contact; -}; +} /** * Contains information about a single contact. @@ -1533,7 +1537,7 @@ Contact.prototype.save = function(successCB, errorCB) { var fail = function(code) { errorCB(new ContactError(code)); }; - var success = function(result) { + var success = function(result) { if (result) { if (typeof successCB === 'function') { var fullContact = require('cordova/plugin/contacts').create(result); @@ -1545,13 +1549,12 @@ Contact.prototype.save = function(successCB, errorCB) { fail(ContactError.UNKNOWN_ERROR); } }; - var dupContact = convertOut(utils.clone(this)); - exec(success, fail, "Contacts", "save", [dupContact]); + var dupContact = convertOut(utils.clone(this)); + exec(success, fail, "Contacts", "save", [dupContact]); }; module.exports = Contact; - }); // file: lib/common/plugin/ContactAddress.js @@ -1581,7 +1584,6 @@ var ContactAddress = function(pref, type, formatted, streetAddress, locality, re }; module.exports = ContactAddress; - }); // file: lib/common/plugin/ContactError.js @@ -1607,7 +1609,6 @@ ContactError.NOT_SUPPORTED_ERROR = 5; ContactError.PERMISSION_DENIED_ERROR = 20; module.exports = ContactError; - }); // file: lib/common/plugin/ContactField.js @@ -1628,7 +1629,6 @@ var ContactField = function(type, value, pref) { }; module.exports = ContactField; - }); // file: lib/common/plugin/ContactFindOptions.js @@ -1646,7 +1646,6 @@ var ContactFindOptions = function(filter, multiple) { }; module.exports = ContactFindOptions; - }); // file: lib/common/plugin/ContactName.js @@ -1671,7 +1670,6 @@ var ContactName = function(formatted, familyName, givenName, middle, prefix, suf }; module.exports = ContactName; - }); // file: lib/common/plugin/ContactOrganization.js @@ -1699,7 +1697,6 @@ var ContactOrganization = function(pref, type, name, dept, title) { }; module.exports = ContactOrganization; - }); // file: lib/common/plugin/Coordinates.js @@ -1747,7 +1744,6 @@ var Coordinates = function(lat, lng, alt, acc, head, vel, altacc) { }; module.exports = Coordinates; - }); // file: lib/common/plugin/DirectoryEntry.js @@ -1755,6 +1751,7 @@ define("cordova/plugin/DirectoryEntry", function(require, exports, module) { var utils = require('cordova/utils'), exec = require('cordova/exec'), Entry = require('cordova/plugin/Entry'), + FileError = require('cordova/plugin/FileError'), DirectoryReader = require('cordova/plugin/DirectoryReader'); /** @@ -1837,7 +1834,8 @@ module.exports = DirectoryEntry; // file: lib/common/plugin/DirectoryReader.js define("cordova/plugin/DirectoryReader", function(require, exports, module) { -var exec = require('cordova/exec'); +var exec = require('cordova/exec'), + FileError = require('cordova/plugin/FileError') ; /** * An interface that lists the files and directories in a directory. @@ -1858,10 +1856,10 @@ DirectoryReader.prototype.readEntries = function(successCallback, errorCallback) for (var i=0; i 0) { - // is an iOS request for watch by filter, no timer needed - timers[id] = "iOS"; - compass.getCurrentHeading(successCallback, errorCallback, options); - } else { - // Start watch timer to get headings - timers[id] = window.setInterval(function() { - compass.getCurrentHeading(successCallback, errorCallback); - }, frequency); - } - + if (filter > 0) { + // is an iOS request for watch by filter, no timer needed + timers[id] = "iOS"; + compass.getCurrentHeading(successCallback, errorCallback, options); + } else { + // Start watch timer to get headings + timers[id] = window.setInterval(function() { + compass.getCurrentHeading(successCallback, errorCallback); + }, frequency); + } + return id; }, @@ -4410,19 +4383,18 @@ var exec = require('cordova/exec'), clearWatch:function(id) { // Stop javascript timer & remove from timer list if (id && timers[id]) { - if (timers[id] != "iOS") { - clearInterval(timers[id]); - } else { - // is iOS watch by filter so call into device to stop - exec(null, null, "Compass", "stopHeading", []); - } - delete timers[id]; + if (timers[id] != "iOS") { + clearInterval(timers[id]); + } else { + // is iOS watch by filter so call into device to stop + exec(null, null, "Compass", "stopHeading", []); + } + delete timers[id]; } } }; module.exports = compass; - }); // file: lib/common/plugin/contacts.js @@ -4484,7 +4456,6 @@ var contacts = { }; module.exports = contacts; - }); // file: lib/common/plugin/geolocation.js @@ -4548,7 +4519,7 @@ var geolocation = { errorCallback(new PositionError(e.code, e.message)); }; - exec(win, fail, "Geolocation", "getLocation", [options.enableHighAccuracy, options.timeout, options.maximumAge]); + exec(win, fail, "Geolocation", "getLocation", [options.enableHighAccuracy, options.timeout, options.maximumAge]); }, /** * Asynchronously watches the geolocation for changes to geolocation. When a change occurs, @@ -4583,7 +4554,6 @@ var geolocation = { }; module.exports = geolocation; - }); // file: lib/common/plugin/network.js @@ -4648,7 +4618,6 @@ NetworkConnection.prototype.getInfo = function (successCallback, errorCallback) }; module.exports = new NetworkConnection(); - }); // file: lib/common/plugin/notification.js @@ -4709,7 +4678,6 @@ module.exports = { exec(null, null, "Notification", "beep", [count]); } }; - }); // file: lib/common/plugin/requestFileSystem.js @@ -4754,13 +4722,13 @@ var requestFileSystem = function(type, size, successCallback, errorCallback) { }; module.exports = requestFileSystem; - }); // file: lib/common/plugin/resolveLocalFileSystemURI.js define("cordova/plugin/resolveLocalFileSystemURI", function(require, exports, module) { var DirectoryEntry = require('cordova/plugin/DirectoryEntry'), FileEntry = require('cordova/plugin/FileEntry'), + FileError = require('cordova/plugin/FileError'), exec = require('cordova/exec'); /** @@ -4822,12 +4790,12 @@ var _self = { * Does a deep clone of the object. */ clone: function(obj) { - if(!obj) { + if(!obj) { return obj; } - + var retVal, i; - + if(obj instanceof Array){ retVal = []; for(i = 0; i < obj.length; ++i){ @@ -4835,15 +4803,15 @@ var _self = { } return retVal; } - + if (obj instanceof Function) { return obj; } - + if(!(obj instanceof Object)){ return obj; } - + if(obj instanceof Date){ return obj; } @@ -4886,7 +4854,7 @@ var _self = { */ extend: (function() { // proxy used to establish prototype chain - var F = function() {}; + var F = function() {}; // extend Child from Parent return function(Child, Parent) { F.prototype = Parent.prototype; @@ -4909,7 +4877,6 @@ var _self = { }; module.exports = _self; - }); @@ -4920,20 +4887,6 @@ window.cordova = require('cordova'); var channel = require("cordova/channel"), _self = { boot: function () { - //--------------- - // Event handling - //--------------- - - /** - * Listen for DOMContentLoaded and notify our channel subscribers. - */ - document.addEventListener('DOMContentLoaded', function() { - channel.onDOMContentLoaded.fire(); - }, false); - if (document.readyState == 'complete') { - channel.onDOMContentLoaded.fire(); - } - /** * Create all cordova objects once page has fully loaded and native side is ready. */ @@ -4966,11 +4919,11 @@ window.cordova = require('cordova'); channel.join(function() { channel.onDeviceReady.fire(); }, channel.deviceReadyChannelsArray); - + }, [ channel.onDOMContentLoaded, channel.onNativeReady ]); } }; - + // boot up once native side is ready channel.onNativeReady.subscribeOnce(_self.boot); @@ -4983,5 +4936,4 @@ window.cordova = require('cordova'); }(window)); - })(); \ No newline at end of file diff --git a/lib/android/example/assets/www/index.html b/lib/android/example/assets/www/index.html index bf3e0859..88927d72 100644 --- a/lib/android/example/assets/www/index.html +++ b/lib/android/example/assets/www/index.html @@ -5,7 +5,7 @@ PhoneGap - + diff --git a/lib/android/example/cordova/debug b/lib/android/example/cordova/debug index 8dd31874..0bac2c79 100755 --- a/lib/android/example/cordova/debug +++ b/lib/android/example/cordova/debug @@ -4,6 +4,6 @@ # if there are no devices listed then emulate - +ant clean ant debug install adb shell am start -n $PACKAGE/$PACKAGE.$ACTIVITY diff --git a/lib/android/example/cordova/templates/project/assets/www/index.html b/lib/android/example/cordova/templates/project/assets/www/index.html index bf3e0859..88927d72 100644 --- a/lib/android/example/cordova/templates/project/assets/www/index.html +++ b/lib/android/example/cordova/templates/project/assets/www/index.html @@ -5,7 +5,7 @@ PhoneGap - + diff --git a/lib/android/example/.cordova/android/cordova-1.6.1.jar b/lib/android/example/libs/cordova-1.7.0rc1.jar similarity index 74% rename from lib/android/example/.cordova/android/cordova-1.6.1.jar rename to lib/android/example/libs/cordova-1.7.0rc1.jar index 75b7e058..bfa27ab8 100644 Binary files a/lib/android/example/.cordova/android/cordova-1.6.1.jar and b/lib/android/example/libs/cordova-1.7.0rc1.jar differ diff --git a/lib/bada/VERSION b/lib/bada/VERSION index 64a542d4..e07cf32a 100644 --- a/lib/bada/VERSION +++ b/lib/bada/VERSION @@ -1,2 +1,2 @@ -1.6.1 +1.7.0rc1 diff --git a/lib/bada/src/Device.cpp b/lib/bada/src/Device.cpp index 15246baf..a22eb541 100755 --- a/lib/bada/src/Device.cpp +++ b/lib/bada/src/Device.cpp @@ -69,7 +69,7 @@ Device::SetDeviceInfo() { if(r == E_SUCCESS) { String res; - res.Format(1024, L"window.device={platform:'bada',version:'%S',name:'n/a',cordova:'1.6.1',uuid:'%S'}", platformVersion.GetPointer(), imei.GetPointer()); + res.Format(1024, L"window.device={platform:'bada',version:'%S',name:'n/a',cordova:'1.7.0rc1',uuid:'%S'}", platformVersion.GetPointer(), imei.GetPointer()); //AppLogDebug("%S", res.GetPointer()); pWeb->EvaluateJavascriptN(res); } diff --git a/lib/blackberry/sample/lib/cordova.1.6.1/ext-air/Cordova_Network/library.xml b/lib/blackberry/sample/lib/cordova.1.7.0rc1/ext-air/Cordova_Network/library.xml similarity index 100% rename from lib/blackberry/sample/lib/cordova.1.6.1/ext-air/Cordova_Network/library.xml rename to lib/blackberry/sample/lib/cordova.1.7.0rc1/ext-air/Cordova_Network/library.xml diff --git a/lib/blackberry/sample/lib/cordova.1.6.1/ext-air/Cordova_Network/src/org/apache/cordova/network/Network.as b/lib/blackberry/sample/lib/cordova.1.7.0rc1/ext-air/Cordova_Network/src/org/apache/cordova/network/Network.as similarity index 100% rename from lib/blackberry/sample/lib/cordova.1.6.1/ext-air/Cordova_Network/src/org/apache/cordova/network/Network.as rename to lib/blackberry/sample/lib/cordova.1.7.0rc1/ext-air/Cordova_Network/src/org/apache/cordova/network/Network.as diff --git a/lib/blackberry/sample/www/ext/cordova.1.6.1.jar b/lib/blackberry/sample/lib/cordova.1.7.0rc1/ext/cordova.1.7.0rc1.jar similarity index 92% rename from lib/blackberry/sample/www/ext/cordova.1.6.1.jar rename to lib/blackberry/sample/lib/cordova.1.7.0rc1/ext/cordova.1.7.0rc1.jar index 42ecff8c..a7af983c 100644 Binary files a/lib/blackberry/sample/www/ext/cordova.1.6.1.jar and b/lib/blackberry/sample/lib/cordova.1.7.0rc1/ext/cordova.1.7.0rc1.jar differ diff --git a/lib/blackberry/sample/www/cordova-1.6.1.js b/lib/blackberry/sample/lib/cordova.1.7.0rc1/javascript/cordova-1.7.0rc1.js similarity index 95% rename from lib/blackberry/sample/www/cordova-1.6.1.js rename to lib/blackberry/sample/lib/cordova.1.7.0rc1/javascript/cordova-1.7.0rc1.js index 801b37f9..d4680da6 100644 --- a/lib/blackberry/sample/www/cordova-1.6.1.js +++ b/lib/blackberry/sample/lib/cordova.1.7.0rc1/javascript/cordova-1.7.0rc1.js @@ -1,4 +1,6 @@ -// File generated at :: Tue Apr 10 2012 15:32:24 GMT-0500 (CDT) +// commit a42f0ae6245e7609c9bad1eb582777a696201aad + +// File generated at :: Tue Apr 24 2012 15:08:45 GMT-0700 (PDT) /* Licensed to the Apache Software Foundation (ASF) under one @@ -65,10 +67,20 @@ if (typeof module === "object" && typeof require === "function") { module.exports.require = require; module.exports.define = define; } - // file: lib/cordova.js define("cordova", function(require, exports, module) { var channel = require('cordova/channel'); + +/** + * Listen for DOMContentLoaded and notify our channel subscribers. + */ +document.addEventListener('DOMContentLoaded', function() { + channel.onDOMContentLoaded.fire(); +}, false); +if (document.readyState == 'complete') { + channel.onDOMContentLoaded.fire(); +} + /** * Intercept calls to addEventListener + removeEventListener and handle deviceready, * resume, and pause events. @@ -113,13 +125,18 @@ window.addEventListener = function(evt, handler, capture) { }; document.removeEventListener = function(evt, handler, capture) { - var e = evt.toLowerCase(); - // If unsubcribing from an event that is handled by a plugin - if (typeof documentEventHandlers[e] != "undefined") { - documentEventHandlers[e].unsubscribe(handler); - } else { - m_document_removeEventListener.call(document, evt, handler, capture); - } + var e = evt.toLowerCase(); + // Check for pause/resume events first. + if (e == 'resume') { + channel.onResume.unsubscribe(handler); + } else if (e == 'pause') { + channel.onPause.unsubscribe(handler); + // If unsubcribing from an event that is handled by a plugin + } else if (typeof documentEventHandlers[e] != "undefined") { + documentEventHandlers[e].unsubscribe(handler); + } else { + m_document_removeEventListener.call(document, evt, handler, capture); + } }; window.removeEventListener = function(evt, handler, capture) { @@ -147,9 +164,9 @@ function createEvent(type, data) { if(typeof window.console === "undefined") { - window.console = { - log:function(){} - }; + window.console = { + log:function(){} + }; } var cordova = { @@ -290,7 +307,7 @@ var cordova = { console.log("Error: Plugin "+name+" already exists."); } }, - + addConstructor: function(func) { channel.onCordovaReady.subscribeOnce(function() { try { @@ -302,13 +319,16 @@ var cordova = { } }; -/** +/** * Legacy variable for plugin support * TODO: remove in 2.0. */ if (!window.PhoneGap) { window.PhoneGap = cordova; } +if (!window.Cordova) { + window.Cordova = cordova; +} /** * Plugins object @@ -324,6 +344,8 @@ module.exports = cordova; // file: lib/common/builder.js define("cordova/builder", function(require, exports, module) { +var utils = require('cordova/utils'); + function each(objects, func, context) { for (var prop in objects) { if (objects.hasOwnProperty(prop)) { @@ -500,10 +522,10 @@ var Channel = function(type, opts) { /** * cordova Channels that must fire before "deviceready" is fired. - */ + */ deviceReadyChannelsArray: [], deviceReadyChannelsMap: {}, - + /** * Indicate that a feature needs to be initialized before it is ready to be used. * This holds up Cordova's "deviceready" event until the feature has been initialized @@ -540,7 +562,7 @@ var Channel = function(type, opts) { utils = require('cordova/utils'); /** - * Subscribes the given function to the channel. Any time that + * Subscribes the given function to the channel. Any time that * Channel.fire is called so too will the function. * Optionally specify an execution context for the function * and a guid that can be used to stop subscribing to the channel. @@ -585,7 +607,7 @@ Channel.prototype.subscribeOnce = function(f, c) { return g; }; -/** +/** * Unsubscribes the function with the given guid from the channel. */ Channel.prototype.unsubscribe = function(g) { @@ -599,7 +621,7 @@ Channel.prototype.unsubscribe = function(g) { if (this.events.onUnsubscribe) this.events.onUnsubscribe.call(this); }; -/** +/** * Calls all functions subscribed to this channel. */ Channel.prototype.fire = function(e) { @@ -654,7 +676,6 @@ channel.waitForInitialization('onCordovaInfoReady'); channel.waitForInitialization('onCordovaConnectionReady'); module.exports = channel; - }); // file: lib/common/common.js @@ -839,7 +860,6 @@ module.exports = { } } }; - }); // file: lib/blackberry/exec.js @@ -901,7 +921,6 @@ module.exports = function(success, fail, service, action, args) { utils.alert("Error: "+e); } }; - }); // file: lib/blackberry/platform.js @@ -1085,7 +1104,6 @@ module.exports = { } } }; - }); // file: lib/common/plugin/Acceleration.js @@ -1098,7 +1116,6 @@ var Acceleration = function(x, y, z, timestamp) { }; module.exports = Acceleration; - }); // file: lib/common/plugin/Camera.js @@ -1180,35 +1197,34 @@ cameraExport.getPicture = function(successCallback, errorCallback, options) { if (typeof options.encodingType == "number") { encodingType = options.encodingType; } - + var mediaType = Camera.MediaType.PICTURE; if (typeof options.mediaType == "number") { mediaType = options.mediaType; } var allowEdit = false; if (typeof options.allowEdit == "boolean") { - allowEdit = options.allowEdit; + allowEdit = options.allowEdit; } else if (typeof options.allowEdit == "number") { - allowEdit = options.allowEdit <= 0 ? false : true; + allowEdit = options.allowEdit <= 0 ? false : true; } var correctOrientation = false; if (typeof options.correctOrientation == "boolean") { - correctOrientation = options.correctOrientation; + correctOrientation = options.correctOrientation; } else if (typeof options.correctOrientation == "number") { - correctOrientation = options.correctOrientation <=0 ? false : true; + correctOrientation = options.correctOrientation <=0 ? false : true; } var saveToPhotoAlbum = false; - if (typeof options.saveToPhotoAlbum == "boolean") { - saveToPhotoAlbum = options.saveToPhotoAlbum; + if (typeof options.saveToPhotoAlbum == "boolean") { + saveToPhotoAlbum = options.saveToPhotoAlbum; } else if (typeof options.saveToPhotoAlbum == "number") { - saveToPhotoAlbum = options.saveToPhotoAlbum <=0 ? false : true; + saveToPhotoAlbum = options.saveToPhotoAlbum <=0 ? false : true; } exec(successCallback, errorCallback, "Camera", "takePicture", [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType, mediaType, allowEdit, correctOrientation, saveToPhotoAlbum]); -} +}; module.exports = cameraExport; - }); // file: lib/common/plugin/CameraConstants.js @@ -1233,7 +1249,6 @@ module.exports = { SAVEDPHOTOALBUM : 2 // Choose image from picture library (same as PHOTOLIBRARY for Android) } }; - }); // file: lib/common/plugin/CaptureAudioOptions.js @@ -1242,16 +1257,15 @@ define("cordova/plugin/CaptureAudioOptions", function(require, exports, module) * Encapsulates all audio capture operation configuration options. */ var CaptureAudioOptions = function(){ - // Upper limit of sound clips user can record. Value must be equal or greater than 1. - this.limit = 1; - // Maximum duration of a single sound clip in seconds. - this.duration = 0; - // The selected audio mode. Must match with one of the elements in supportedAudioModes array. - this.mode = null; + // Upper limit of sound clips user can record. Value must be equal or greater than 1. + this.limit = 1; + // Maximum duration of a single sound clip in seconds. + this.duration = 0; + // The selected audio mode. Must match with one of the elements in supportedAudioModes array. + this.mode = null; }; module.exports = CaptureAudioOptions; - }); // file: lib/common/plugin/CaptureError.js @@ -1263,7 +1277,7 @@ var CaptureError = function(c) { this.code = c || null; }; -// Camera or microphone failed to capture image or sound. +// Camera or microphone failed to capture image or sound. CaptureError.CAPTURE_INTERNAL_ERR = 0; // Camera application or audio capture application is currently serving other capture request. CaptureError.CAPTURE_APPLICATION_BUSY = 1; @@ -1275,7 +1289,6 @@ CaptureError.CAPTURE_NO_MEDIA_FILES = 3; CaptureError.CAPTURE_NOT_SUPPORTED = 20; module.exports = CaptureError; - }); // file: lib/common/plugin/CaptureImageOptions.js @@ -1284,14 +1297,13 @@ define("cordova/plugin/CaptureImageOptions", function(require, exports, module) * Encapsulates all image capture operation configuration options. */ var CaptureImageOptions = function(){ - // Upper limit of images user can take. Value must be equal or greater than 1. - this.limit = 1; - // The selected image mode. Must match with one of the elements in supportedImageModes array. - this.mode = null; + // Upper limit of images user can take. Value must be equal or greater than 1. + this.limit = 1; + // The selected image mode. Must match with one of the elements in supportedImageModes array. + this.mode = null; }; module.exports = CaptureImageOptions; - }); // file: lib/common/plugin/CaptureVideoOptions.js @@ -1300,16 +1312,15 @@ define("cordova/plugin/CaptureVideoOptions", function(require, exports, module) * Encapsulates all video capture operation configuration options. */ var CaptureVideoOptions = function(){ - // Upper limit of videos user can record. Value must be equal or greater than 1. - this.limit = 1; - // Maximum duration of a single video clip in seconds. - this.duration = 0; - // The selected video mode. Must match with one of the elements in supportedVideoModes array. - this.mode = null; + // Upper limit of videos user can record. Value must be equal or greater than 1. + this.limit = 1; + // Maximum duration of a single video clip in seconds. + this.duration = 0; + // The selected video mode. Must match with one of the elements in supportedVideoModes array. + this.mode = null; }; module.exports = CaptureVideoOptions; - }); // file: lib/common/plugin/CompassError.js @@ -1327,7 +1338,6 @@ CompassError.COMPASS_INTERNAL_ERR = 0; CompassError.COMPASS_NOT_SUPPORTED = 20; module.exports = CompassError; - }); // file: lib/common/plugin/CompassHeading.js @@ -1340,7 +1350,6 @@ var CompassHeading = function(magneticHeading, trueHeading, headingAccuracy, tim }; module.exports = CompassHeading; - }); // file: lib/common/plugin/ConfigurationData.js @@ -1349,18 +1358,17 @@ define("cordova/plugin/ConfigurationData", function(require, exports, module) { * Encapsulates a set of parameters that the capture device supports. */ function ConfigurationData() { - // The ASCII-encoded string in lower case representing the media type. - this.type = null; - // The height attribute represents height of the image or video in pixels. - // In the case of a sound clip this attribute has value 0. + // The ASCII-encoded string in lower case representing the media type. + this.type = null; + // The height attribute represents height of the image or video in pixels. + // In the case of a sound clip this attribute has value 0. this.height = 0; - // The width attribute represents width of the image or video in pixels. + // The width attribute represents width of the image or video in pixels. // In the case of a sound clip this attribute has value 0 this.width = 0; } module.exports = ConfigurationData; - }); // file: lib/common/plugin/Connection.js @@ -1369,15 +1377,14 @@ define("cordova/plugin/Connection", function(require, exports, module) { * Network status */ module.exports = { - UNKNOWN: "unknown", - ETHERNET: "ethernet", - WIFI: "wifi", - CELL_2G: "2g", - CELL_3G: "3g", - CELL_4G: "4g", - NONE: "none" + UNKNOWN: "unknown", + ETHERNET: "ethernet", + WIFI: "wifi", + CELL_2G: "2g", + CELL_3G: "3g", + CELL_4G: "4g", + NONE: "none" }; - }); // file: lib/common/plugin/Contact.js @@ -1398,7 +1405,7 @@ function convertIn(contact) { console.log("Cordova Contact convertIn error: exception creating date."); } return contact; -}; +} /** * Converts Complex objects into primitives @@ -1407,7 +1414,7 @@ function convertIn(contact) { function convertOut(contact) { var value = contact.birthday; - if (value != null) { + if (value !== null) { // try to make it a Date object if it is not already if (!value instanceof Date){ try { @@ -1422,7 +1429,7 @@ function convertOut(contact) { contact.birthday = value; } return contact; -}; +} /** * Contains information about a single contact. @@ -1541,7 +1548,7 @@ Contact.prototype.save = function(successCB, errorCB) { var fail = function(code) { errorCB(new ContactError(code)); }; - var success = function(result) { + var success = function(result) { if (result) { if (typeof successCB === 'function') { var fullContact = require('cordova/plugin/contacts').create(result); @@ -1553,13 +1560,12 @@ Contact.prototype.save = function(successCB, errorCB) { fail(ContactError.UNKNOWN_ERROR); } }; - var dupContact = convertOut(utils.clone(this)); - exec(success, fail, "Contacts", "save", [dupContact]); + var dupContact = convertOut(utils.clone(this)); + exec(success, fail, "Contacts", "save", [dupContact]); }; module.exports = Contact; - }); // file: lib/common/plugin/ContactAddress.js @@ -1589,7 +1595,6 @@ var ContactAddress = function(pref, type, formatted, streetAddress, locality, re }; module.exports = ContactAddress; - }); // file: lib/common/plugin/ContactError.js @@ -1615,7 +1620,6 @@ ContactError.NOT_SUPPORTED_ERROR = 5; ContactError.PERMISSION_DENIED_ERROR = 20; module.exports = ContactError; - }); // file: lib/common/plugin/ContactField.js @@ -1636,7 +1640,6 @@ var ContactField = function(type, value, pref) { }; module.exports = ContactField; - }); // file: lib/common/plugin/ContactFindOptions.js @@ -1654,7 +1657,6 @@ var ContactFindOptions = function(filter, multiple) { }; module.exports = ContactFindOptions; - }); // file: lib/common/plugin/ContactName.js @@ -1679,7 +1681,6 @@ var ContactName = function(formatted, familyName, givenName, middle, prefix, suf }; module.exports = ContactName; - }); // file: lib/common/plugin/ContactOrganization.js @@ -1707,7 +1708,6 @@ var ContactOrganization = function(pref, type, name, dept, title) { }; module.exports = ContactOrganization; - }); // file: lib/common/plugin/Coordinates.js @@ -1755,7 +1755,6 @@ var Coordinates = function(lat, lng, alt, acc, head, vel, altacc) { }; module.exports = Coordinates; - }); // file: lib/common/plugin/DirectoryEntry.js @@ -1763,6 +1762,7 @@ define("cordova/plugin/DirectoryEntry", function(require, exports, module) { var utils = require('cordova/utils'), exec = require('cordova/exec'), Entry = require('cordova/plugin/Entry'), + FileError = require('cordova/plugin/FileError'), DirectoryReader = require('cordova/plugin/DirectoryReader'); /** @@ -1845,7 +1845,8 @@ module.exports = DirectoryEntry; // file: lib/common/plugin/DirectoryReader.js define("cordova/plugin/DirectoryReader", function(require, exports, module) { -var exec = require('cordova/exec'); +var exec = require('cordova/exec'), + FileError = require('cordova/plugin/FileError') ; /** * An interface that lists the files and directories in a directory. @@ -1866,10 +1867,10 @@ DirectoryReader.prototype.readEntries = function(successCallback, errorCallback) for (var i=0; i 0) { - // is an iOS request for watch by filter, no timer needed - timers[id] = "iOS"; - compass.getCurrentHeading(successCallback, errorCallback, options); - } else { - // Start watch timer to get headings - timers[id] = window.setInterval(function() { - compass.getCurrentHeading(successCallback, errorCallback); - }, frequency); - } - + if (filter > 0) { + // is an iOS request for watch by filter, no timer needed + timers[id] = "iOS"; + compass.getCurrentHeading(successCallback, errorCallback, options); + } else { + // Start watch timer to get headings + timers[id] = window.setInterval(function() { + compass.getCurrentHeading(successCallback, errorCallback); + }, frequency); + } + return id; }, @@ -5060,19 +5039,18 @@ var exec = require('cordova/exec'), clearWatch:function(id) { // Stop javascript timer & remove from timer list if (id && timers[id]) { - if (timers[id] != "iOS") { - clearInterval(timers[id]); - } else { - // is iOS watch by filter so call into device to stop - exec(null, null, "Compass", "stopHeading", []); - } - delete timers[id]; + if (timers[id] != "iOS") { + clearInterval(timers[id]); + } else { + // is iOS watch by filter so call into device to stop + exec(null, null, "Compass", "stopHeading", []); + } + delete timers[id]; } } }; module.exports = compass; - }); // file: lib/common/plugin/contacts.js @@ -5134,7 +5112,6 @@ var contacts = { }; module.exports = contacts; - }); // file: lib/common/plugin/geolocation.js @@ -5198,7 +5175,7 @@ var geolocation = { errorCallback(new PositionError(e.code, e.message)); }; - exec(win, fail, "Geolocation", "getLocation", [options.enableHighAccuracy, options.timeout, options.maximumAge]); + exec(win, fail, "Geolocation", "getLocation", [options.enableHighAccuracy, options.timeout, options.maximumAge]); }, /** * Asynchronously watches the geolocation for changes to geolocation. When a change occurs, @@ -5233,7 +5210,6 @@ var geolocation = { }; module.exports = geolocation; - }); // file: lib/common/plugin/network.js @@ -5298,7 +5274,6 @@ NetworkConnection.prototype.getInfo = function (successCallback, errorCallback) }; module.exports = new NetworkConnection(); - }); // file: lib/common/plugin/notification.js @@ -5359,7 +5334,6 @@ module.exports = { exec(null, null, "Notification", "beep", [count]); } }; - }); // file: lib/common/plugin/requestFileSystem.js @@ -5404,13 +5378,13 @@ var requestFileSystem = function(type, size, successCallback, errorCallback) { }; module.exports = requestFileSystem; - }); // file: lib/common/plugin/resolveLocalFileSystemURI.js define("cordova/plugin/resolveLocalFileSystemURI", function(require, exports, module) { var DirectoryEntry = require('cordova/plugin/DirectoryEntry'), FileEntry = require('cordova/plugin/FileEntry'), + FileError = require('cordova/plugin/FileError'), exec = require('cordova/exec'); /** @@ -5469,7 +5443,6 @@ module.exports = { return {"status" : cordova.callbackStatus.CLASS_NOT_FOUND_EXCEPTION, "message" : "Class " + clazz + " cannot be found"}; } }; - }); // file: lib/common/utils.js @@ -5491,12 +5464,12 @@ var _self = { * Does a deep clone of the object. */ clone: function(obj) { - if(!obj) { + if(!obj) { return obj; } - + var retVal, i; - + if(obj instanceof Array){ retVal = []; for(i = 0; i < obj.length; ++i){ @@ -5504,15 +5477,15 @@ var _self = { } return retVal; } - + if (obj instanceof Function) { return obj; } - + if(!(obj instanceof Object)){ return obj; } - + if(obj instanceof Date){ return obj; } @@ -5555,7 +5528,7 @@ var _self = { */ extend: (function() { // proxy used to establish prototype chain - var F = function() {}; + var F = function() {}; // extend Child from Parent return function(Child, Parent) { F.prototype = Parent.prototype; @@ -5578,7 +5551,6 @@ var _self = { }; module.exports = _self; - }); @@ -5589,20 +5561,6 @@ window.cordova = require('cordova'); var channel = require("cordova/channel"), _self = { boot: function () { - //--------------- - // Event handling - //--------------- - - /** - * Listen for DOMContentLoaded and notify our channel subscribers. - */ - document.addEventListener('DOMContentLoaded', function() { - channel.onDOMContentLoaded.fire(); - }, false); - if (document.readyState == 'complete') { - channel.onDOMContentLoaded.fire(); - } - /** * Create all cordova objects once page has fully loaded and native side is ready. */ @@ -5635,11 +5593,11 @@ window.cordova = require('cordova'); channel.join(function() { channel.onDeviceReady.fire(); }, channel.deviceReadyChannelsArray); - + }, [ channel.onDOMContentLoaded, channel.onNativeReady ]); } }; - + // boot up once native side is ready channel.onNativeReady.subscribeOnce(_self.boot); @@ -5652,5 +5610,4 @@ window.cordova = require('cordova'); }(window)); - })(); \ No newline at end of file diff --git a/lib/blackberry/sample/www/playbook/cordova-1.6.1.js b/lib/blackberry/sample/lib/cordova.1.7.0rc1/javascript/playbook/cordova-1.7.0rc1.js similarity index 95% rename from lib/blackberry/sample/www/playbook/cordova-1.6.1.js rename to lib/blackberry/sample/lib/cordova.1.7.0rc1/javascript/playbook/cordova-1.7.0rc1.js index 4e74c4fa..0a180bbb 100644 --- a/lib/blackberry/sample/www/playbook/cordova-1.6.1.js +++ b/lib/blackberry/sample/lib/cordova.1.7.0rc1/javascript/playbook/cordova-1.7.0rc1.js @@ -1,4 +1,6 @@ -// File generated at :: Tue Apr 10 2012 15:32:25 GMT-0500 (CDT) +// commit a42f0ae6245e7609c9bad1eb582777a696201aad + +// File generated at :: Tue Apr 24 2012 15:08:45 GMT-0700 (PDT) /* Licensed to the Apache Software Foundation (ASF) under one @@ -65,10 +67,20 @@ if (typeof module === "object" && typeof require === "function") { module.exports.require = require; module.exports.define = define; } - // file: lib/cordova.js define("cordova", function(require, exports, module) { var channel = require('cordova/channel'); + +/** + * Listen for DOMContentLoaded and notify our channel subscribers. + */ +document.addEventListener('DOMContentLoaded', function() { + channel.onDOMContentLoaded.fire(); +}, false); +if (document.readyState == 'complete') { + channel.onDOMContentLoaded.fire(); +} + /** * Intercept calls to addEventListener + removeEventListener and handle deviceready, * resume, and pause events. @@ -113,13 +125,18 @@ window.addEventListener = function(evt, handler, capture) { }; document.removeEventListener = function(evt, handler, capture) { - var e = evt.toLowerCase(); - // If unsubcribing from an event that is handled by a plugin - if (typeof documentEventHandlers[e] != "undefined") { - documentEventHandlers[e].unsubscribe(handler); - } else { - m_document_removeEventListener.call(document, evt, handler, capture); - } + var e = evt.toLowerCase(); + // Check for pause/resume events first. + if (e == 'resume') { + channel.onResume.unsubscribe(handler); + } else if (e == 'pause') { + channel.onPause.unsubscribe(handler); + // If unsubcribing from an event that is handled by a plugin + } else if (typeof documentEventHandlers[e] != "undefined") { + documentEventHandlers[e].unsubscribe(handler); + } else { + m_document_removeEventListener.call(document, evt, handler, capture); + } }; window.removeEventListener = function(evt, handler, capture) { @@ -147,9 +164,9 @@ function createEvent(type, data) { if(typeof window.console === "undefined") { - window.console = { - log:function(){} - }; + window.console = { + log:function(){} + }; } var cordova = { @@ -290,7 +307,7 @@ var cordova = { console.log("Error: Plugin "+name+" already exists."); } }, - + addConstructor: function(func) { channel.onCordovaReady.subscribeOnce(function() { try { @@ -302,13 +319,16 @@ var cordova = { } }; -/** +/** * Legacy variable for plugin support * TODO: remove in 2.0. */ if (!window.PhoneGap) { window.PhoneGap = cordova; } +if (!window.Cordova) { + window.Cordova = cordova; +} /** * Plugins object @@ -324,6 +344,8 @@ module.exports = cordova; // file: lib/common/builder.js define("cordova/builder", function(require, exports, module) { +var utils = require('cordova/utils'); + function each(objects, func, context) { for (var prop in objects) { if (objects.hasOwnProperty(prop)) { @@ -500,10 +522,10 @@ var Channel = function(type, opts) { /** * cordova Channels that must fire before "deviceready" is fired. - */ + */ deviceReadyChannelsArray: [], deviceReadyChannelsMap: {}, - + /** * Indicate that a feature needs to be initialized before it is ready to be used. * This holds up Cordova's "deviceready" event until the feature has been initialized @@ -540,7 +562,7 @@ var Channel = function(type, opts) { utils = require('cordova/utils'); /** - * Subscribes the given function to the channel. Any time that + * Subscribes the given function to the channel. Any time that * Channel.fire is called so too will the function. * Optionally specify an execution context for the function * and a guid that can be used to stop subscribing to the channel. @@ -585,7 +607,7 @@ Channel.prototype.subscribeOnce = function(f, c) { return g; }; -/** +/** * Unsubscribes the function with the given guid from the channel. */ Channel.prototype.unsubscribe = function(g) { @@ -599,7 +621,7 @@ Channel.prototype.unsubscribe = function(g) { if (this.events.onUnsubscribe) this.events.onUnsubscribe.call(this); }; -/** +/** * Calls all functions subscribed to this channel. */ Channel.prototype.fire = function(e) { @@ -654,7 +676,6 @@ channel.waitForInitialization('onCordovaInfoReady'); channel.waitForInitialization('onCordovaConnectionReady'); module.exports = channel; - }); // file: lib/common/common.js @@ -839,7 +860,6 @@ module.exports = { } } }; - }); // file: lib/playbook/exec.js @@ -902,7 +922,6 @@ module.exports = function(success, fail, service, action, args) { utils.alert("Error: "+e); } }; - }); // file: lib/playbook/platform.js @@ -925,7 +944,6 @@ module.exports = { } } }; - }); // file: lib/common/plugin/Acceleration.js @@ -938,7 +956,6 @@ var Acceleration = function(x, y, z, timestamp) { }; module.exports = Acceleration; - }); // file: lib/common/plugin/Camera.js @@ -1020,35 +1037,34 @@ cameraExport.getPicture = function(successCallback, errorCallback, options) { if (typeof options.encodingType == "number") { encodingType = options.encodingType; } - + var mediaType = Camera.MediaType.PICTURE; if (typeof options.mediaType == "number") { mediaType = options.mediaType; } var allowEdit = false; if (typeof options.allowEdit == "boolean") { - allowEdit = options.allowEdit; + allowEdit = options.allowEdit; } else if (typeof options.allowEdit == "number") { - allowEdit = options.allowEdit <= 0 ? false : true; + allowEdit = options.allowEdit <= 0 ? false : true; } var correctOrientation = false; if (typeof options.correctOrientation == "boolean") { - correctOrientation = options.correctOrientation; + correctOrientation = options.correctOrientation; } else if (typeof options.correctOrientation == "number") { - correctOrientation = options.correctOrientation <=0 ? false : true; + correctOrientation = options.correctOrientation <=0 ? false : true; } var saveToPhotoAlbum = false; - if (typeof options.saveToPhotoAlbum == "boolean") { - saveToPhotoAlbum = options.saveToPhotoAlbum; + if (typeof options.saveToPhotoAlbum == "boolean") { + saveToPhotoAlbum = options.saveToPhotoAlbum; } else if (typeof options.saveToPhotoAlbum == "number") { - saveToPhotoAlbum = options.saveToPhotoAlbum <=0 ? false : true; + saveToPhotoAlbum = options.saveToPhotoAlbum <=0 ? false : true; } exec(successCallback, errorCallback, "Camera", "takePicture", [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType, mediaType, allowEdit, correctOrientation, saveToPhotoAlbum]); -} +}; module.exports = cameraExport; - }); // file: lib/common/plugin/CameraConstants.js @@ -1073,7 +1089,6 @@ module.exports = { SAVEDPHOTOALBUM : 2 // Choose image from picture library (same as PHOTOLIBRARY for Android) } }; - }); // file: lib/common/plugin/CaptureAudioOptions.js @@ -1082,16 +1097,15 @@ define("cordova/plugin/CaptureAudioOptions", function(require, exports, module) * Encapsulates all audio capture operation configuration options. */ var CaptureAudioOptions = function(){ - // Upper limit of sound clips user can record. Value must be equal or greater than 1. - this.limit = 1; - // Maximum duration of a single sound clip in seconds. - this.duration = 0; - // The selected audio mode. Must match with one of the elements in supportedAudioModes array. - this.mode = null; + // Upper limit of sound clips user can record. Value must be equal or greater than 1. + this.limit = 1; + // Maximum duration of a single sound clip in seconds. + this.duration = 0; + // The selected audio mode. Must match with one of the elements in supportedAudioModes array. + this.mode = null; }; module.exports = CaptureAudioOptions; - }); // file: lib/common/plugin/CaptureError.js @@ -1103,7 +1117,7 @@ var CaptureError = function(c) { this.code = c || null; }; -// Camera or microphone failed to capture image or sound. +// Camera or microphone failed to capture image or sound. CaptureError.CAPTURE_INTERNAL_ERR = 0; // Camera application or audio capture application is currently serving other capture request. CaptureError.CAPTURE_APPLICATION_BUSY = 1; @@ -1115,7 +1129,6 @@ CaptureError.CAPTURE_NO_MEDIA_FILES = 3; CaptureError.CAPTURE_NOT_SUPPORTED = 20; module.exports = CaptureError; - }); // file: lib/common/plugin/CaptureImageOptions.js @@ -1124,14 +1137,13 @@ define("cordova/plugin/CaptureImageOptions", function(require, exports, module) * Encapsulates all image capture operation configuration options. */ var CaptureImageOptions = function(){ - // Upper limit of images user can take. Value must be equal or greater than 1. - this.limit = 1; - // The selected image mode. Must match with one of the elements in supportedImageModes array. - this.mode = null; + // Upper limit of images user can take. Value must be equal or greater than 1. + this.limit = 1; + // The selected image mode. Must match with one of the elements in supportedImageModes array. + this.mode = null; }; module.exports = CaptureImageOptions; - }); // file: lib/common/plugin/CaptureVideoOptions.js @@ -1140,16 +1152,15 @@ define("cordova/plugin/CaptureVideoOptions", function(require, exports, module) * Encapsulates all video capture operation configuration options. */ var CaptureVideoOptions = function(){ - // Upper limit of videos user can record. Value must be equal or greater than 1. - this.limit = 1; - // Maximum duration of a single video clip in seconds. - this.duration = 0; - // The selected video mode. Must match with one of the elements in supportedVideoModes array. - this.mode = null; + // Upper limit of videos user can record. Value must be equal or greater than 1. + this.limit = 1; + // Maximum duration of a single video clip in seconds. + this.duration = 0; + // The selected video mode. Must match with one of the elements in supportedVideoModes array. + this.mode = null; }; module.exports = CaptureVideoOptions; - }); // file: lib/common/plugin/CompassError.js @@ -1167,7 +1178,6 @@ CompassError.COMPASS_INTERNAL_ERR = 0; CompassError.COMPASS_NOT_SUPPORTED = 20; module.exports = CompassError; - }); // file: lib/common/plugin/CompassHeading.js @@ -1180,7 +1190,6 @@ var CompassHeading = function(magneticHeading, trueHeading, headingAccuracy, tim }; module.exports = CompassHeading; - }); // file: lib/common/plugin/ConfigurationData.js @@ -1189,18 +1198,17 @@ define("cordova/plugin/ConfigurationData", function(require, exports, module) { * Encapsulates a set of parameters that the capture device supports. */ function ConfigurationData() { - // The ASCII-encoded string in lower case representing the media type. - this.type = null; - // The height attribute represents height of the image or video in pixels. - // In the case of a sound clip this attribute has value 0. + // The ASCII-encoded string in lower case representing the media type. + this.type = null; + // The height attribute represents height of the image or video in pixels. + // In the case of a sound clip this attribute has value 0. this.height = 0; - // The width attribute represents width of the image or video in pixels. + // The width attribute represents width of the image or video in pixels. // In the case of a sound clip this attribute has value 0 this.width = 0; } module.exports = ConfigurationData; - }); // file: lib/common/plugin/Connection.js @@ -1209,15 +1217,14 @@ define("cordova/plugin/Connection", function(require, exports, module) { * Network status */ module.exports = { - UNKNOWN: "unknown", - ETHERNET: "ethernet", - WIFI: "wifi", - CELL_2G: "2g", - CELL_3G: "3g", - CELL_4G: "4g", - NONE: "none" + UNKNOWN: "unknown", + ETHERNET: "ethernet", + WIFI: "wifi", + CELL_2G: "2g", + CELL_3G: "3g", + CELL_4G: "4g", + NONE: "none" }; - }); // file: lib/common/plugin/Contact.js @@ -1238,7 +1245,7 @@ function convertIn(contact) { console.log("Cordova Contact convertIn error: exception creating date."); } return contact; -}; +} /** * Converts Complex objects into primitives @@ -1247,7 +1254,7 @@ function convertIn(contact) { function convertOut(contact) { var value = contact.birthday; - if (value != null) { + if (value !== null) { // try to make it a Date object if it is not already if (!value instanceof Date){ try { @@ -1262,7 +1269,7 @@ function convertOut(contact) { contact.birthday = value; } return contact; -}; +} /** * Contains information about a single contact. @@ -1381,7 +1388,7 @@ Contact.prototype.save = function(successCB, errorCB) { var fail = function(code) { errorCB(new ContactError(code)); }; - var success = function(result) { + var success = function(result) { if (result) { if (typeof successCB === 'function') { var fullContact = require('cordova/plugin/contacts').create(result); @@ -1393,13 +1400,12 @@ Contact.prototype.save = function(successCB, errorCB) { fail(ContactError.UNKNOWN_ERROR); } }; - var dupContact = convertOut(utils.clone(this)); - exec(success, fail, "Contacts", "save", [dupContact]); + var dupContact = convertOut(utils.clone(this)); + exec(success, fail, "Contacts", "save", [dupContact]); }; module.exports = Contact; - }); // file: lib/common/plugin/ContactAddress.js @@ -1429,7 +1435,6 @@ var ContactAddress = function(pref, type, formatted, streetAddress, locality, re }; module.exports = ContactAddress; - }); // file: lib/common/plugin/ContactError.js @@ -1455,7 +1460,6 @@ ContactError.NOT_SUPPORTED_ERROR = 5; ContactError.PERMISSION_DENIED_ERROR = 20; module.exports = ContactError; - }); // file: lib/common/plugin/ContactField.js @@ -1476,7 +1480,6 @@ var ContactField = function(type, value, pref) { }; module.exports = ContactField; - }); // file: lib/common/plugin/ContactFindOptions.js @@ -1494,7 +1497,6 @@ var ContactFindOptions = function(filter, multiple) { }; module.exports = ContactFindOptions; - }); // file: lib/common/plugin/ContactName.js @@ -1519,7 +1521,6 @@ var ContactName = function(formatted, familyName, givenName, middle, prefix, suf }; module.exports = ContactName; - }); // file: lib/common/plugin/ContactOrganization.js @@ -1547,7 +1548,6 @@ var ContactOrganization = function(pref, type, name, dept, title) { }; module.exports = ContactOrganization; - }); // file: lib/common/plugin/Coordinates.js @@ -1595,7 +1595,6 @@ var Coordinates = function(lat, lng, alt, acc, head, vel, altacc) { }; module.exports = Coordinates; - }); // file: lib/common/plugin/DirectoryEntry.js @@ -1603,6 +1602,7 @@ define("cordova/plugin/DirectoryEntry", function(require, exports, module) { var utils = require('cordova/utils'), exec = require('cordova/exec'), Entry = require('cordova/plugin/Entry'), + FileError = require('cordova/plugin/FileError'), DirectoryReader = require('cordova/plugin/DirectoryReader'); /** @@ -1685,7 +1685,8 @@ module.exports = DirectoryEntry; // file: lib/common/plugin/DirectoryReader.js define("cordova/plugin/DirectoryReader", function(require, exports, module) { -var exec = require('cordova/exec'); +var exec = require('cordova/exec'), + FileError = require('cordova/plugin/FileError') ; /** * An interface that lists the files and directories in a directory. @@ -1706,10 +1707,10 @@ DirectoryReader.prototype.readEntries = function(successCallback, errorCallback) for (var i=0; i 0) { - // is an iOS request for watch by filter, no timer needed - timers[id] = "iOS"; - compass.getCurrentHeading(successCallback, errorCallback, options); - } else { - // Start watch timer to get headings - timers[id] = window.setInterval(function() { - compass.getCurrentHeading(successCallback, errorCallback); - }, frequency); - } - + if (filter > 0) { + // is an iOS request for watch by filter, no timer needed + timers[id] = "iOS"; + compass.getCurrentHeading(successCallback, errorCallback, options); + } else { + // Start watch timer to get headings + timers[id] = window.setInterval(function() { + compass.getCurrentHeading(successCallback, errorCallback); + }, frequency); + } + return id; }, @@ -3517,19 +3497,18 @@ var exec = require('cordova/exec'), clearWatch:function(id) { // Stop javascript timer & remove from timer list if (id && timers[id]) { - if (timers[id] != "iOS") { - clearInterval(timers[id]); - } else { - // is iOS watch by filter so call into device to stop - exec(null, null, "Compass", "stopHeading", []); - } - delete timers[id]; + if (timers[id] != "iOS") { + clearInterval(timers[id]); + } else { + // is iOS watch by filter so call into device to stop + exec(null, null, "Compass", "stopHeading", []); + } + delete timers[id]; } } }; module.exports = compass; - }); // file: lib/common/plugin/contacts.js @@ -3591,7 +3570,6 @@ var contacts = { }; module.exports = contacts; - }); // file: lib/common/plugin/geolocation.js @@ -3655,7 +3633,7 @@ var geolocation = { errorCallback(new PositionError(e.code, e.message)); }; - exec(win, fail, "Geolocation", "getLocation", [options.enableHighAccuracy, options.timeout, options.maximumAge]); + exec(win, fail, "Geolocation", "getLocation", [options.enableHighAccuracy, options.timeout, options.maximumAge]); }, /** * Asynchronously watches the geolocation for changes to geolocation. When a change occurs, @@ -3690,7 +3668,6 @@ var geolocation = { }; module.exports = geolocation; - }); // file: lib/common/plugin/network.js @@ -3755,7 +3732,6 @@ NetworkConnection.prototype.getInfo = function (successCallback, errorCallback) }; module.exports = new NetworkConnection(); - }); // file: lib/common/plugin/notification.js @@ -3816,7 +3792,6 @@ module.exports = { exec(null, null, "Notification", "beep", [count]); } }; - }); // file: lib/playbook/plugin/playbook/device.js @@ -3845,13 +3820,13 @@ channel.onCordovaReady.subscribeOnce(function() { }); module.exports = me; - }); // file: lib/playbook/plugin/playbook/manager.js define("cordova/plugin/playbook/manager", function(require, exports, module) { var webworks = require('cordova/plugin/webworks/manager'), cordova = require('cordova'), + MediaFile = require('cordova/plugin/MediaFile'), /** * Private list of HTML 5 audio objects, indexed by the Cordova media object ids */ @@ -3876,8 +3851,7 @@ var webworks = require('cordova/plugin/webworks/manager'), "isPlugged" : state === 2 }; - if (me._isPlugged !== info.isPlugged - && typeof win === 'function') { + if (me._isPlugged !== info.isPlugged && typeof win === 'function') { win(info); } } @@ -3917,7 +3891,7 @@ var webworks = require('cordova/plugin/webworks/manager'), "name" : blackberry.system.model, "uuid" : blackberry.identity.PIN, "platform" : "PlayBook", - "cordova" : "1.6.1" + "cordova" : "1.7.0rc1" } }; } @@ -4218,13 +4192,13 @@ var requestFileSystem = function(type, size, successCallback, errorCallback) { }; module.exports = requestFileSystem; - }); // file: lib/common/plugin/resolveLocalFileSystemURI.js define("cordova/plugin/resolveLocalFileSystemURI", function(require, exports, module) { var DirectoryEntry = require('cordova/plugin/DirectoryEntry'), FileEntry = require('cordova/plugin/FileEntry'), + FileError = require('cordova/plugin/FileError'), exec = require('cordova/exec'); /** @@ -4283,7 +4257,6 @@ module.exports = { return {"status" : cordova.callbackStatus.CLASS_NOT_FOUND_EXCEPTION, "message" : "Class " + clazz + " cannot be found"}; } }; - }); // file: lib/common/utils.js @@ -4305,12 +4278,12 @@ var _self = { * Does a deep clone of the object. */ clone: function(obj) { - if(!obj) { + if(!obj) { return obj; } - + var retVal, i; - + if(obj instanceof Array){ retVal = []; for(i = 0; i < obj.length; ++i){ @@ -4318,15 +4291,15 @@ var _self = { } return retVal; } - + if (obj instanceof Function) { return obj; } - + if(!(obj instanceof Object)){ return obj; } - + if(obj instanceof Date){ return obj; } @@ -4369,7 +4342,7 @@ var _self = { */ extend: (function() { // proxy used to establish prototype chain - var F = function() {}; + var F = function() {}; // extend Child from Parent return function(Child, Parent) { F.prototype = Parent.prototype; @@ -4392,7 +4365,6 @@ var _self = { }; module.exports = _self; - }); @@ -4403,20 +4375,6 @@ window.cordova = require('cordova'); var channel = require("cordova/channel"), _self = { boot: function () { - //--------------- - // Event handling - //--------------- - - /** - * Listen for DOMContentLoaded and notify our channel subscribers. - */ - document.addEventListener('DOMContentLoaded', function() { - channel.onDOMContentLoaded.fire(); - }, false); - if (document.readyState == 'complete') { - channel.onDOMContentLoaded.fire(); - } - /** * Create all cordova objects once page has fully loaded and native side is ready. */ @@ -4449,11 +4407,11 @@ window.cordova = require('cordova'); channel.join(function() { channel.onDeviceReady.fire(); }, channel.deviceReadyChannelsArray); - + }, [ channel.onDOMContentLoaded, channel.onNativeReady ]); } }; - + // boot up once native side is ready channel.onNativeReady.subscribeOnce(_self.boot); @@ -4465,9 +4423,7 @@ window.cordova = require('cordova'); } }(window)); - // file: lib/scripts/bootstrap-playbook.js require('cordova/channel').onNativeReady.fire(); - -})(); +})(); \ No newline at end of file diff --git a/lib/blackberry/www/cordova-1.6.1.js b/lib/blackberry/sample/www/cordova-1.7.0rc1.js similarity index 95% rename from lib/blackberry/www/cordova-1.6.1.js rename to lib/blackberry/sample/www/cordova-1.7.0rc1.js index 801b37f9..d4680da6 100644 --- a/lib/blackberry/www/cordova-1.6.1.js +++ b/lib/blackberry/sample/www/cordova-1.7.0rc1.js @@ -1,4 +1,6 @@ -// File generated at :: Tue Apr 10 2012 15:32:24 GMT-0500 (CDT) +// commit a42f0ae6245e7609c9bad1eb582777a696201aad + +// File generated at :: Tue Apr 24 2012 15:08:45 GMT-0700 (PDT) /* Licensed to the Apache Software Foundation (ASF) under one @@ -65,10 +67,20 @@ if (typeof module === "object" && typeof require === "function") { module.exports.require = require; module.exports.define = define; } - // file: lib/cordova.js define("cordova", function(require, exports, module) { var channel = require('cordova/channel'); + +/** + * Listen for DOMContentLoaded and notify our channel subscribers. + */ +document.addEventListener('DOMContentLoaded', function() { + channel.onDOMContentLoaded.fire(); +}, false); +if (document.readyState == 'complete') { + channel.onDOMContentLoaded.fire(); +} + /** * Intercept calls to addEventListener + removeEventListener and handle deviceready, * resume, and pause events. @@ -113,13 +125,18 @@ window.addEventListener = function(evt, handler, capture) { }; document.removeEventListener = function(evt, handler, capture) { - var e = evt.toLowerCase(); - // If unsubcribing from an event that is handled by a plugin - if (typeof documentEventHandlers[e] != "undefined") { - documentEventHandlers[e].unsubscribe(handler); - } else { - m_document_removeEventListener.call(document, evt, handler, capture); - } + var e = evt.toLowerCase(); + // Check for pause/resume events first. + if (e == 'resume') { + channel.onResume.unsubscribe(handler); + } else if (e == 'pause') { + channel.onPause.unsubscribe(handler); + // If unsubcribing from an event that is handled by a plugin + } else if (typeof documentEventHandlers[e] != "undefined") { + documentEventHandlers[e].unsubscribe(handler); + } else { + m_document_removeEventListener.call(document, evt, handler, capture); + } }; window.removeEventListener = function(evt, handler, capture) { @@ -147,9 +164,9 @@ function createEvent(type, data) { if(typeof window.console === "undefined") { - window.console = { - log:function(){} - }; + window.console = { + log:function(){} + }; } var cordova = { @@ -290,7 +307,7 @@ var cordova = { console.log("Error: Plugin "+name+" already exists."); } }, - + addConstructor: function(func) { channel.onCordovaReady.subscribeOnce(function() { try { @@ -302,13 +319,16 @@ var cordova = { } }; -/** +/** * Legacy variable for plugin support * TODO: remove in 2.0. */ if (!window.PhoneGap) { window.PhoneGap = cordova; } +if (!window.Cordova) { + window.Cordova = cordova; +} /** * Plugins object @@ -324,6 +344,8 @@ module.exports = cordova; // file: lib/common/builder.js define("cordova/builder", function(require, exports, module) { +var utils = require('cordova/utils'); + function each(objects, func, context) { for (var prop in objects) { if (objects.hasOwnProperty(prop)) { @@ -500,10 +522,10 @@ var Channel = function(type, opts) { /** * cordova Channels that must fire before "deviceready" is fired. - */ + */ deviceReadyChannelsArray: [], deviceReadyChannelsMap: {}, - + /** * Indicate that a feature needs to be initialized before it is ready to be used. * This holds up Cordova's "deviceready" event until the feature has been initialized @@ -540,7 +562,7 @@ var Channel = function(type, opts) { utils = require('cordova/utils'); /** - * Subscribes the given function to the channel. Any time that + * Subscribes the given function to the channel. Any time that * Channel.fire is called so too will the function. * Optionally specify an execution context for the function * and a guid that can be used to stop subscribing to the channel. @@ -585,7 +607,7 @@ Channel.prototype.subscribeOnce = function(f, c) { return g; }; -/** +/** * Unsubscribes the function with the given guid from the channel. */ Channel.prototype.unsubscribe = function(g) { @@ -599,7 +621,7 @@ Channel.prototype.unsubscribe = function(g) { if (this.events.onUnsubscribe) this.events.onUnsubscribe.call(this); }; -/** +/** * Calls all functions subscribed to this channel. */ Channel.prototype.fire = function(e) { @@ -654,7 +676,6 @@ channel.waitForInitialization('onCordovaInfoReady'); channel.waitForInitialization('onCordovaConnectionReady'); module.exports = channel; - }); // file: lib/common/common.js @@ -839,7 +860,6 @@ module.exports = { } } }; - }); // file: lib/blackberry/exec.js @@ -901,7 +921,6 @@ module.exports = function(success, fail, service, action, args) { utils.alert("Error: "+e); } }; - }); // file: lib/blackberry/platform.js @@ -1085,7 +1104,6 @@ module.exports = { } } }; - }); // file: lib/common/plugin/Acceleration.js @@ -1098,7 +1116,6 @@ var Acceleration = function(x, y, z, timestamp) { }; module.exports = Acceleration; - }); // file: lib/common/plugin/Camera.js @@ -1180,35 +1197,34 @@ cameraExport.getPicture = function(successCallback, errorCallback, options) { if (typeof options.encodingType == "number") { encodingType = options.encodingType; } - + var mediaType = Camera.MediaType.PICTURE; if (typeof options.mediaType == "number") { mediaType = options.mediaType; } var allowEdit = false; if (typeof options.allowEdit == "boolean") { - allowEdit = options.allowEdit; + allowEdit = options.allowEdit; } else if (typeof options.allowEdit == "number") { - allowEdit = options.allowEdit <= 0 ? false : true; + allowEdit = options.allowEdit <= 0 ? false : true; } var correctOrientation = false; if (typeof options.correctOrientation == "boolean") { - correctOrientation = options.correctOrientation; + correctOrientation = options.correctOrientation; } else if (typeof options.correctOrientation == "number") { - correctOrientation = options.correctOrientation <=0 ? false : true; + correctOrientation = options.correctOrientation <=0 ? false : true; } var saveToPhotoAlbum = false; - if (typeof options.saveToPhotoAlbum == "boolean") { - saveToPhotoAlbum = options.saveToPhotoAlbum; + if (typeof options.saveToPhotoAlbum == "boolean") { + saveToPhotoAlbum = options.saveToPhotoAlbum; } else if (typeof options.saveToPhotoAlbum == "number") { - saveToPhotoAlbum = options.saveToPhotoAlbum <=0 ? false : true; + saveToPhotoAlbum = options.saveToPhotoAlbum <=0 ? false : true; } exec(successCallback, errorCallback, "Camera", "takePicture", [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType, mediaType, allowEdit, correctOrientation, saveToPhotoAlbum]); -} +}; module.exports = cameraExport; - }); // file: lib/common/plugin/CameraConstants.js @@ -1233,7 +1249,6 @@ module.exports = { SAVEDPHOTOALBUM : 2 // Choose image from picture library (same as PHOTOLIBRARY for Android) } }; - }); // file: lib/common/plugin/CaptureAudioOptions.js @@ -1242,16 +1257,15 @@ define("cordova/plugin/CaptureAudioOptions", function(require, exports, module) * Encapsulates all audio capture operation configuration options. */ var CaptureAudioOptions = function(){ - // Upper limit of sound clips user can record. Value must be equal or greater than 1. - this.limit = 1; - // Maximum duration of a single sound clip in seconds. - this.duration = 0; - // The selected audio mode. Must match with one of the elements in supportedAudioModes array. - this.mode = null; + // Upper limit of sound clips user can record. Value must be equal or greater than 1. + this.limit = 1; + // Maximum duration of a single sound clip in seconds. + this.duration = 0; + // The selected audio mode. Must match with one of the elements in supportedAudioModes array. + this.mode = null; }; module.exports = CaptureAudioOptions; - }); // file: lib/common/plugin/CaptureError.js @@ -1263,7 +1277,7 @@ var CaptureError = function(c) { this.code = c || null; }; -// Camera or microphone failed to capture image or sound. +// Camera or microphone failed to capture image or sound. CaptureError.CAPTURE_INTERNAL_ERR = 0; // Camera application or audio capture application is currently serving other capture request. CaptureError.CAPTURE_APPLICATION_BUSY = 1; @@ -1275,7 +1289,6 @@ CaptureError.CAPTURE_NO_MEDIA_FILES = 3; CaptureError.CAPTURE_NOT_SUPPORTED = 20; module.exports = CaptureError; - }); // file: lib/common/plugin/CaptureImageOptions.js @@ -1284,14 +1297,13 @@ define("cordova/plugin/CaptureImageOptions", function(require, exports, module) * Encapsulates all image capture operation configuration options. */ var CaptureImageOptions = function(){ - // Upper limit of images user can take. Value must be equal or greater than 1. - this.limit = 1; - // The selected image mode. Must match with one of the elements in supportedImageModes array. - this.mode = null; + // Upper limit of images user can take. Value must be equal or greater than 1. + this.limit = 1; + // The selected image mode. Must match with one of the elements in supportedImageModes array. + this.mode = null; }; module.exports = CaptureImageOptions; - }); // file: lib/common/plugin/CaptureVideoOptions.js @@ -1300,16 +1312,15 @@ define("cordova/plugin/CaptureVideoOptions", function(require, exports, module) * Encapsulates all video capture operation configuration options. */ var CaptureVideoOptions = function(){ - // Upper limit of videos user can record. Value must be equal or greater than 1. - this.limit = 1; - // Maximum duration of a single video clip in seconds. - this.duration = 0; - // The selected video mode. Must match with one of the elements in supportedVideoModes array. - this.mode = null; + // Upper limit of videos user can record. Value must be equal or greater than 1. + this.limit = 1; + // Maximum duration of a single video clip in seconds. + this.duration = 0; + // The selected video mode. Must match with one of the elements in supportedVideoModes array. + this.mode = null; }; module.exports = CaptureVideoOptions; - }); // file: lib/common/plugin/CompassError.js @@ -1327,7 +1338,6 @@ CompassError.COMPASS_INTERNAL_ERR = 0; CompassError.COMPASS_NOT_SUPPORTED = 20; module.exports = CompassError; - }); // file: lib/common/plugin/CompassHeading.js @@ -1340,7 +1350,6 @@ var CompassHeading = function(magneticHeading, trueHeading, headingAccuracy, tim }; module.exports = CompassHeading; - }); // file: lib/common/plugin/ConfigurationData.js @@ -1349,18 +1358,17 @@ define("cordova/plugin/ConfigurationData", function(require, exports, module) { * Encapsulates a set of parameters that the capture device supports. */ function ConfigurationData() { - // The ASCII-encoded string in lower case representing the media type. - this.type = null; - // The height attribute represents height of the image or video in pixels. - // In the case of a sound clip this attribute has value 0. + // The ASCII-encoded string in lower case representing the media type. + this.type = null; + // The height attribute represents height of the image or video in pixels. + // In the case of a sound clip this attribute has value 0. this.height = 0; - // The width attribute represents width of the image or video in pixels. + // The width attribute represents width of the image or video in pixels. // In the case of a sound clip this attribute has value 0 this.width = 0; } module.exports = ConfigurationData; - }); // file: lib/common/plugin/Connection.js @@ -1369,15 +1377,14 @@ define("cordova/plugin/Connection", function(require, exports, module) { * Network status */ module.exports = { - UNKNOWN: "unknown", - ETHERNET: "ethernet", - WIFI: "wifi", - CELL_2G: "2g", - CELL_3G: "3g", - CELL_4G: "4g", - NONE: "none" + UNKNOWN: "unknown", + ETHERNET: "ethernet", + WIFI: "wifi", + CELL_2G: "2g", + CELL_3G: "3g", + CELL_4G: "4g", + NONE: "none" }; - }); // file: lib/common/plugin/Contact.js @@ -1398,7 +1405,7 @@ function convertIn(contact) { console.log("Cordova Contact convertIn error: exception creating date."); } return contact; -}; +} /** * Converts Complex objects into primitives @@ -1407,7 +1414,7 @@ function convertIn(contact) { function convertOut(contact) { var value = contact.birthday; - if (value != null) { + if (value !== null) { // try to make it a Date object if it is not already if (!value instanceof Date){ try { @@ -1422,7 +1429,7 @@ function convertOut(contact) { contact.birthday = value; } return contact; -}; +} /** * Contains information about a single contact. @@ -1541,7 +1548,7 @@ Contact.prototype.save = function(successCB, errorCB) { var fail = function(code) { errorCB(new ContactError(code)); }; - var success = function(result) { + var success = function(result) { if (result) { if (typeof successCB === 'function') { var fullContact = require('cordova/plugin/contacts').create(result); @@ -1553,13 +1560,12 @@ Contact.prototype.save = function(successCB, errorCB) { fail(ContactError.UNKNOWN_ERROR); } }; - var dupContact = convertOut(utils.clone(this)); - exec(success, fail, "Contacts", "save", [dupContact]); + var dupContact = convertOut(utils.clone(this)); + exec(success, fail, "Contacts", "save", [dupContact]); }; module.exports = Contact; - }); // file: lib/common/plugin/ContactAddress.js @@ -1589,7 +1595,6 @@ var ContactAddress = function(pref, type, formatted, streetAddress, locality, re }; module.exports = ContactAddress; - }); // file: lib/common/plugin/ContactError.js @@ -1615,7 +1620,6 @@ ContactError.NOT_SUPPORTED_ERROR = 5; ContactError.PERMISSION_DENIED_ERROR = 20; module.exports = ContactError; - }); // file: lib/common/plugin/ContactField.js @@ -1636,7 +1640,6 @@ var ContactField = function(type, value, pref) { }; module.exports = ContactField; - }); // file: lib/common/plugin/ContactFindOptions.js @@ -1654,7 +1657,6 @@ var ContactFindOptions = function(filter, multiple) { }; module.exports = ContactFindOptions; - }); // file: lib/common/plugin/ContactName.js @@ -1679,7 +1681,6 @@ var ContactName = function(formatted, familyName, givenName, middle, prefix, suf }; module.exports = ContactName; - }); // file: lib/common/plugin/ContactOrganization.js @@ -1707,7 +1708,6 @@ var ContactOrganization = function(pref, type, name, dept, title) { }; module.exports = ContactOrganization; - }); // file: lib/common/plugin/Coordinates.js @@ -1755,7 +1755,6 @@ var Coordinates = function(lat, lng, alt, acc, head, vel, altacc) { }; module.exports = Coordinates; - }); // file: lib/common/plugin/DirectoryEntry.js @@ -1763,6 +1762,7 @@ define("cordova/plugin/DirectoryEntry", function(require, exports, module) { var utils = require('cordova/utils'), exec = require('cordova/exec'), Entry = require('cordova/plugin/Entry'), + FileError = require('cordova/plugin/FileError'), DirectoryReader = require('cordova/plugin/DirectoryReader'); /** @@ -1845,7 +1845,8 @@ module.exports = DirectoryEntry; // file: lib/common/plugin/DirectoryReader.js define("cordova/plugin/DirectoryReader", function(require, exports, module) { -var exec = require('cordova/exec'); +var exec = require('cordova/exec'), + FileError = require('cordova/plugin/FileError') ; /** * An interface that lists the files and directories in a directory. @@ -1866,10 +1867,10 @@ DirectoryReader.prototype.readEntries = function(successCallback, errorCallback) for (var i=0; i 0) { - // is an iOS request for watch by filter, no timer needed - timers[id] = "iOS"; - compass.getCurrentHeading(successCallback, errorCallback, options); - } else { - // Start watch timer to get headings - timers[id] = window.setInterval(function() { - compass.getCurrentHeading(successCallback, errorCallback); - }, frequency); - } - + if (filter > 0) { + // is an iOS request for watch by filter, no timer needed + timers[id] = "iOS"; + compass.getCurrentHeading(successCallback, errorCallback, options); + } else { + // Start watch timer to get headings + timers[id] = window.setInterval(function() { + compass.getCurrentHeading(successCallback, errorCallback); + }, frequency); + } + return id; }, @@ -5060,19 +5039,18 @@ var exec = require('cordova/exec'), clearWatch:function(id) { // Stop javascript timer & remove from timer list if (id && timers[id]) { - if (timers[id] != "iOS") { - clearInterval(timers[id]); - } else { - // is iOS watch by filter so call into device to stop - exec(null, null, "Compass", "stopHeading", []); - } - delete timers[id]; + if (timers[id] != "iOS") { + clearInterval(timers[id]); + } else { + // is iOS watch by filter so call into device to stop + exec(null, null, "Compass", "stopHeading", []); + } + delete timers[id]; } } }; module.exports = compass; - }); // file: lib/common/plugin/contacts.js @@ -5134,7 +5112,6 @@ var contacts = { }; module.exports = contacts; - }); // file: lib/common/plugin/geolocation.js @@ -5198,7 +5175,7 @@ var geolocation = { errorCallback(new PositionError(e.code, e.message)); }; - exec(win, fail, "Geolocation", "getLocation", [options.enableHighAccuracy, options.timeout, options.maximumAge]); + exec(win, fail, "Geolocation", "getLocation", [options.enableHighAccuracy, options.timeout, options.maximumAge]); }, /** * Asynchronously watches the geolocation for changes to geolocation. When a change occurs, @@ -5233,7 +5210,6 @@ var geolocation = { }; module.exports = geolocation; - }); // file: lib/common/plugin/network.js @@ -5298,7 +5274,6 @@ NetworkConnection.prototype.getInfo = function (successCallback, errorCallback) }; module.exports = new NetworkConnection(); - }); // file: lib/common/plugin/notification.js @@ -5359,7 +5334,6 @@ module.exports = { exec(null, null, "Notification", "beep", [count]); } }; - }); // file: lib/common/plugin/requestFileSystem.js @@ -5404,13 +5378,13 @@ var requestFileSystem = function(type, size, successCallback, errorCallback) { }; module.exports = requestFileSystem; - }); // file: lib/common/plugin/resolveLocalFileSystemURI.js define("cordova/plugin/resolveLocalFileSystemURI", function(require, exports, module) { var DirectoryEntry = require('cordova/plugin/DirectoryEntry'), FileEntry = require('cordova/plugin/FileEntry'), + FileError = require('cordova/plugin/FileError'), exec = require('cordova/exec'); /** @@ -5469,7 +5443,6 @@ module.exports = { return {"status" : cordova.callbackStatus.CLASS_NOT_FOUND_EXCEPTION, "message" : "Class " + clazz + " cannot be found"}; } }; - }); // file: lib/common/utils.js @@ -5491,12 +5464,12 @@ var _self = { * Does a deep clone of the object. */ clone: function(obj) { - if(!obj) { + if(!obj) { return obj; } - + var retVal, i; - + if(obj instanceof Array){ retVal = []; for(i = 0; i < obj.length; ++i){ @@ -5504,15 +5477,15 @@ var _self = { } return retVal; } - + if (obj instanceof Function) { return obj; } - + if(!(obj instanceof Object)){ return obj; } - + if(obj instanceof Date){ return obj; } @@ -5555,7 +5528,7 @@ var _self = { */ extend: (function() { // proxy used to establish prototype chain - var F = function() {}; + var F = function() {}; // extend Child from Parent return function(Child, Parent) { F.prototype = Parent.prototype; @@ -5578,7 +5551,6 @@ var _self = { }; module.exports = _self; - }); @@ -5589,20 +5561,6 @@ window.cordova = require('cordova'); var channel = require("cordova/channel"), _self = { boot: function () { - //--------------- - // Event handling - //--------------- - - /** - * Listen for DOMContentLoaded and notify our channel subscribers. - */ - document.addEventListener('DOMContentLoaded', function() { - channel.onDOMContentLoaded.fire(); - }, false); - if (document.readyState == 'complete') { - channel.onDOMContentLoaded.fire(); - } - /** * Create all cordova objects once page has fully loaded and native side is ready. */ @@ -5635,11 +5593,11 @@ window.cordova = require('cordova'); channel.join(function() { channel.onDeviceReady.fire(); }, channel.deviceReadyChannelsArray); - + }, [ channel.onDOMContentLoaded, channel.onNativeReady ]); } }; - + // boot up once native side is ready channel.onNativeReady.subscribeOnce(_self.boot); @@ -5652,5 +5610,4 @@ window.cordova = require('cordova'); }(window)); - })(); \ No newline at end of file diff --git a/lib/blackberry/www/ext/cordova.1.6.1.jar b/lib/blackberry/sample/www/ext/cordova.1.7.0rc1.jar similarity index 92% rename from lib/blackberry/www/ext/cordova.1.6.1.jar rename to lib/blackberry/sample/www/ext/cordova.1.7.0rc1.jar index 42ecff8c..a7af983c 100644 Binary files a/lib/blackberry/www/ext/cordova.1.6.1.jar and b/lib/blackberry/sample/www/ext/cordova.1.7.0rc1.jar differ diff --git a/lib/blackberry/sample/www/index.html b/lib/blackberry/sample/www/index.html index 0a017f4f..9ca266e3 100644 --- a/lib/blackberry/sample/www/index.html +++ b/lib/blackberry/sample/www/index.html @@ -4,7 +4,7 @@ - + + + - - - - - - - - - - - - -
Back
-

Cordova: Accelerometer API Specs

-

-

-
    -
    - -
    - - + + Cordova: Accelerometer API Specs + + + + + + + + + + + + + + + + + + + + + + + + + + Back + + diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/all.html b/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/all.html index 289f1edf..cbc2b938 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/all.html +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/all.html @@ -1,81 +1,80 @@ - + - - - - - Cordova: All API Specs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Back
    -

    Cordova: All API Specs

    -

    -

    -
      -
      - -
      - + + Cordova: API Specs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Back + - diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/battery.html b/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/battery.html index 19b1ee68..9bf34312 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/battery.html +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/battery.html @@ -1,54 +1,44 @@ - - - - - Cordova: Battery API Specs - - - - - - - - - - - - - - - - -
      Back
      -

      Cordova: Battery API Specs

      -

      -

      -
        -
        - -
        - + + Cordova: Battery API Specs + + + + + + + + + + + + + + + + + + + + + + + Back + - - - diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/camera.html b/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/camera.html index e83fb5de..8a2f2f47 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/camera.html +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/camera.html @@ -1,54 +1,49 @@ - - - - - Cordova: Camera API Specs - - - - - - - - - - - - - - - - -
        Back
        -

        Cordova: Camera API Specs

        -

        -

        -
          -
          - -
          - - + + Cordova: Camera API Specs + + + + + + + + + + + + + + + + + + + + + + + + + + Back + + diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/capture.html b/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/capture.html index 1f871a02..e65b427b 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/capture.html +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/capture.html @@ -1,54 +1,49 @@ - - - - - Cordova: Capture API Specs - - - - - - - - - - - - - - - - -
          Back
          -

          Cordova: Capture API Specs

          -

          -

          -
            -
            - -
            - - + + Cordova: Capture API Specs + + + + + + + + + + + + + + + + + + + + + + + + + + Back + + diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/compass.html b/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/compass.html index 1623a5e6..75f119b1 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/compass.html +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/compass.html @@ -1,54 +1,49 @@ - - - - - Cordova: Compass API Specs - - - - - - - - - - - - - - - - -
            Back
            -

            Cordova: Compass API Specs

            -

            -

            -
              -
              - -
              - - + + Cordova: Compass API Specs + + + + + + + + + + + + + + + + + + + + + + + + + + Back + + diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/contacts.html b/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/contacts.html index bbd86424..8be8891f 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/contacts.html +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/contacts.html @@ -1,54 +1,49 @@ - - - - - Cordova: Contacts API Specs - - - - - - - - - - - - - - - - -
              Back
              -

              Cordova: Contacts API Specs

              -

              -

              -
                -
                - -
                - - + + Cordova: Contacts API Specs + + + + + + + + + + + + + + + + + + + + + + + + + + Back + + diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/device.html b/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/device.html index 35a71bf2..00b2e9f2 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/device.html +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/device.html @@ -1,54 +1,49 @@ - - - - - Cordova: Device API Specs - - - - - - - - - - - - - - - - -
                Back
                -

                Cordova: Device API Specs

                -

                -

                -
                  -
                  - -
                  - - + + Cordova: Device API Specs + + + + + + + + + + + + + + + + + + + + + + + + + + Back + + diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/file.html b/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/file.html index 4d132001..0317e422 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/file.html +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/file.html @@ -1,54 +1,66 @@ - - - - - Cordova: File API Specs - - - - - - - - - - - - - - - - -
                  Back
                  -

                  Cordova: File API Specs

                  -

                  -

                  -
                    -
                    - -
                    - - + + Cordova: File API Specs + + + + + + + + + + + + + + + + + + + + + + + + + + Back + + diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/geolocation.html b/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/geolocation.html index ff1f290b..57271c7e 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/geolocation.html +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/geolocation.html @@ -1,54 +1,49 @@ - - - - - Cordova: Geolocation API Specs - - - - - - - - - - - - - - - - -
                    Back
                    -

                    Cordova: Geolocation API Specs

                    -

                    -

                    -
                      -
                      - -
                      - - + + Cordova: Geolocation API Specs + + + + + + + + + + + + + + + + + + + + + + + + + + Back + + diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/media.html b/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/media.html index 5c772601..90b22b6e 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/media.html +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/media.html @@ -1,54 +1,49 @@ - - - - - Cordova: Media API Specs - - - - - - - - - - - - - - - - -
                      Back
                      -

                      Cordova: Media API Specs

                      -

                      -

                      -
                        -
                        - -
                        - - + + Cordova: Media API Specs + + + + + + + + + + + + + + + + + + + + + + + + + + Back + + diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/network.html b/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/network.html index 52196fed..db1e41b2 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/network.html +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/network.html @@ -1,54 +1,49 @@ - - - - - Cordova: Network API Specs - - - - - - - - - - - - - - - - -
                        Back
                        -

                        Cordova: Network API Specs

                        -

                        -

                        -
                          -
                          - -
                          - - + + Cordova: Network API Specs + + + + + + + + + + + + + + + + + + + + + + + + + + Back + + diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/notification.html b/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/notification.html index 0b051924..2de92756 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/notification.html +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/notification.html @@ -1,54 +1,49 @@ - - - - - Cordova: Notification API Specs - - - - - - - - - - - - - - - - -
                          Back
                          -

                          Cordova: Notification API Specs

                          -

                          -

                          -
                            -
                            - -
                            - - + + Cordova: Notification API Specs + + + + + + + + + + + + + + + + + + + + + + + + + + Back + + diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/platform.html b/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/platform.html index 8a8545c4..4c5b0a52 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/platform.html +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/platform.html @@ -1,54 +1,49 @@ - - - - - Cordova: Platform API Specs - - - - - - - - - - - - - - - - -
                            Back
                            -

                            Cordova: Platform API Specs

                            -

                            -

                            -
                              -
                              - -
                              - - + + Cordova: Platform API Specs + + + + + + + + + + + + + + + + + + + + + + + + + + Back + + diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/storage.html b/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/storage.html index 9659b480..8512dd36 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/storage.html +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/pages/storage.html @@ -1,54 +1,49 @@ - - - - - Cordova: Storage API Specs - - - - - - - - - - - - - - - - -
                              Back
                              -

                              Cordova: Storage API Specs

                              -

                              -

                              -
                                -
                                - -
                                - - + + Cordova: Storage API Specs + + + + + + + + + + + + + + + + + + + + + + + + + + Back + + diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/test-runner.js b/lib/windows/tests/MobileSpecUnitTests/www/autotest/test-runner.js index 35a4c63e..51851049 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/test-runner.js +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/test-runner.js @@ -1,8 +1,4 @@ -// Prevent QUnit from running when the DOM load event fires -QUnit.config.autostart = false; - if (window.sessionStorage != null) { - window.sessionStorage.clear(); } @@ -10,4 +6,4 @@ if (window.sessionStorage != null) { // time to query the response. This is important for some // Android devices. var Tests = function() {}; -Tests.TEST_TIMEOUT = 2000; +Tests.TEST_TIMEOUT = 7500; diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/accelerometer.tests.js b/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/accelerometer.tests.js index a99d459f..c9a2745b 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/accelerometer.tests.js +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/accelerometer.tests.js @@ -1,55 +1,58 @@ -Tests.prototype.AccelerometerTests = function() { - module('Accelerometer (navigator.accelerometer)'); - test("should exist", function() { - expect(1); - ok(navigator.accelerometer != null, "navigator.accelerometer should not be null."); +describe('Accelerometer (navigator.accelerometer)', function () { + it("should exist", function () { + expect(navigator.accelerometer).toBeDefined(); }); - test("should contain a getCurrentAcceleration function", function() { - expect(2); - ok(typeof navigator.accelerometer.getCurrentAcceleration != 'undefined' && navigator.accelerometer.getCurrentAcceleration != null, "navigator.accelerometer.getCurrentAcceleration should not be null."); - ok(typeof navigator.accelerometer.getCurrentAcceleration == 'function', "navigator.accelerometer.getCurrentAcceleration should be a function."); + + it("should contain a getCurrentAcceleration function", function() { + expect(typeof navigator.accelerometer.getCurrentAcceleration).toBeDefined(); + expect(typeof navigator.accelerometer.getCurrentAcceleration == 'function').toBe(true); }); - test("getCurrentAcceleration success callback should be called with an Acceleration object", function() { - expect(7); - QUnit.stop(Tests.TEST_TIMEOUT); - var win = function(a) { - ok(typeof a == 'object', "Acceleration object returned in getCurrentAcceleration success callback should be of type 'object'."); - ok(a.x != null, "Acceleration object returned in getCurrentAcceleration success callback should have an 'x' property."); - ok(typeof a.x == 'number', "Acceleration object's 'x' property returned in getCurrentAcceleration success callback should be of type 'number'."); - ok(a.y != null, "Acceleration object returned in getCurrentAcceleration success callback should have a 'y' property."); - ok(typeof a.y == 'number', "Acceleration object's 'y' property returned in getCurrentAcceleration success callback should be of type 'number'."); - ok(a.z != null, "Acceleration object returned in getCurrentAcceleration success callback should have a 'z' property."); - ok(typeof a.z == 'number', "Acceleration object's 'z' property returned in getCurrentAcceleration success callback should be of type 'number'."); - start(); - }; - var fail = function() { start(); }; - navigator.accelerometer.getCurrentAcceleration(win, fail); + + it("getCurrentAcceleration success callback should be called with an Acceleration object", function() { + + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(a.x).toBeDefined(); + expect(typeof a.x == 'number').toBe(true); + expect(a.y).toBeDefined(); + expect(typeof a.y == 'number').toBe(true); + expect(a.z).toBeDefined(); + expect(typeof a.z == 'number').toBe(true); + }), + fail = jasmine.createSpy(); + + runs(function () { + navigator.accelerometer.getCurrentAcceleration(win, fail); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); }); - test("should contain a watchAcceleration function", function() { - expect(2); - ok(typeof navigator.accelerometer.watchAcceleration != 'undefined' && navigator.accelerometer.watchAcceleration != null, "navigator.accelerometer.watchAcceleration should not be null."); - ok(typeof navigator.accelerometer.watchAcceleration == 'function', "navigator.accelerometer.watchAcceleration should be a function."); + + it("should contain a watchAcceleration function", function() { + expect(navigator.accelerometer.watchAcceleration).toBeDefined(); + expect(typeof navigator.accelerometer.watchAcceleration == 'function').toBe(true); }); - test("should contain a clearWatch function", function() { - expect(2); - ok(typeof navigator.accelerometer.clearWatch != 'undefined' && navigator.accelerometer.clearWatch != null, "navigator.accelerometer.clearWatch should not be null."); - ok(typeof navigator.accelerometer.clearWatch == 'function', "navigator.accelerometer.clearWatch should be a function!"); + + it("should contain a clearWatch function", function() { + expect(navigator.accelerometer.clearWatch).toBeDefined(); + expect(typeof navigator.accelerometer.clearWatch == 'function').toBe(true); }); - module('Acceleration model'); - test("should be able to define a new Acceleration object with x, y, z and timestamp properties.", function () { - expect(9); - var x = 1; - var y = 2; - var z = 3; - var a = new Acceleration(x, y, z); - ok(a != null, "new Acceleration object should not be null."); - ok(typeof a == 'object', "new Acceleration object should be of type 'object'."); - ok(a.x != null, "new Acceleration object should have an 'x' property."); - equals(a.x, x, "new Acceleration object should have 'x' property equal to first parameter passed in Acceleration constructor."); - ok(a.y != null, "new Acceleration object should have a 'y' property."); - equals(a.y, y, "new Acceleration object should have 'y' property equal to second parameter passed in Acceleration constructor."); - ok(a.z != null, "new Acceleration object should have a 'z' property."); - equals(a.z, z, "new Acceleration object should have 'z' property equal to third parameter passed in Acceleration constructor."); - ok(a.timestamp != null, "new Acceleration object should have a 'timestamp' property."); - }); -}; \ No newline at end of file + + describe('Acceleration model', function () { + it("should be able to define a new Acceleration object with x, y, z and timestamp properties.", function () { + var x = 1; + var y = 2; + var z = 3; + var a = new Acceleration(x, y, z); + expect(a).toBeDefined(); + expect(a.x).toBe(x); + expect(a.y).toBe(y); + expect(a.z).toBe(z); + expect(a.timestamp).toBeDefined(); + }); + }); +}); diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/battery.tests.js b/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/battery.tests.js index faf14e15..7bb25af8 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/battery.tests.js +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/battery.tests.js @@ -1,7 +1,5 @@ -Tests.prototype.BatteryTests = function() { - module('Battery (navigator.battery)'); - test("should exist", function() { - expect(1); - ok(navigator.battery != null, "navigator.battery should not be null."); +describe('Battery (navigator.battery)', function () {; + it("should exist", function() { + expect(navigator.battery).toBeDefined(); }); -}; +}); diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/camera.tests.js b/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/camera.tests.js index 2e55f9db..9b6b04c2 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/camera.tests.js +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/camera.tests.js @@ -1,50 +1,47 @@ -Tests.prototype.CameraTests = function() { - module('Camera (navigator.camera)'); - test("should exist", function() { - expect(1); - ok(navigator.camera !== null, "navigator.camera should not be null."); +describe('Camera (navigator.camera)', function () { + it("should exist", function() { + expect(navigator.camera).toBeDefined(); }); - test("should contain a getPicture function", function() { - expect(2); - ok(typeof navigator.camera.getPicture != 'undefined' && navigator.camera.getPicture !== null, "navigator.camera.getPicture should not be null."); - ok(typeof navigator.camera.getPicture == 'function', "navigator.camera.getPicture should be a function."); + + it("should contain a getPicture function", function() { + expect(navigator.camera.getPicture).toBeDefined(); + expect(typeof navigator.camera.getPicture == 'function').toBe(true); }); +}); + +describe('Camera Constants (window.Camera + navigator.camera)', function () { + it("window.Camera should exist", function() { + expect(window.Camera).toBeDefined(); + }); + + it("should contain two DestinationType constants", function() { + expect(Camera.DestinationType.DATA_URL).toBe(0); + expect(Camera.DestinationType.FILE_URI).toBe(1); + expect(navigator.camera.DestinationType.DATA_URL).toBe(0); + expect(navigator.camera.DestinationType.FILE_URI).toBe(1); + }); + + it("should contain two EncodingType constants", function() { + expect(Camera.EncodingType.JPEG).toBe(0); + expect(Camera.EncodingType.PNG).toBe(1); + expect(navigator.camera.EncodingType.JPEG).toBe(0); + expect(navigator.camera.EncodingType.PNG).toBe(1); + }); - module('Camera Constants (window.Camera + navigator.camera)'); - test("window.Camera should exist", function() { - expect(1); - ok(window.Camera !== null, "window.Camera should not be null."); - }); - test("should contain two DestinationType constants", function() { - expect(4); - equals(Camera.DestinationType.DATA_URL, 0, "Camera.DestinationType.DATA_URL should equal to 0"); - equals(Camera.DestinationType.FILE_URI, 1, "Camera.DestinationType.DATA_URL should equal to 1"); - equals(navigator.camera.DestinationType.DATA_URL, 0, "navigator.camera.DestinationType.DATA_URL should equal to 0"); - equals(navigator.camera.DestinationType.FILE_URI, 1, "navigator.camera.DestinationType.DATA_URL should equal to 1"); - }); - test("should contain two EncodingType constants", function() { - expect(4); - equals(Camera.EncodingType.JPEG, 0, "Camera.EncodingType.JPEG should equal to 0"); - equals(Camera.EncodingType.PNG, 1, "Camera.EncodingType.PNG should equal to 1"); - equals(navigator.camera.EncodingType.JPEG, 0, "navigator.camera.EncodingType.JPEG should equal to 0"); - equals(navigator.camera.EncodingType.PNG, 1, "navigator.camera.EncodingType.PNG should equal to 1"); - }); - test("should contain three MediaType constants", function() { - expect(6); - equals(Camera.MediaType.PICTURE, 0, 'Camera.MediaType.PICTURE should equal to 0'); - equals(Camera.MediaType.VIDEO, 1, 'Camera.MediaType.VIDEO should equal to 1'); - equals(Camera.MediaType.ALLMEDIA, 2, 'Camera.MediaType.ALLMEDIA should equal to 2'); - equals(navigator.camera.MediaType.PICTURE, 0, 'navigator.camera.MediaType.PICTURE should equal to 0'); - equals(navigator.camera.MediaType.VIDEO, 1, 'navigator.camera.MediaType.VIDEO should equal to 1'); - equals(navigator.camera.MediaType.ALLMEDIA, 2, 'navigator.camera.MediaType.ALLMEDIA should equal to 2'); - }); - test("should contain three PictureSourceType constants", function() { - expect(6); - equals(Camera.PictureSourceType.PHOTOLIBRARY, 0, 'Camera.PictureSourceType.PHOTOLIBRARY should equal to 0'); - equals(Camera.PictureSourceType.CAMERA, 1, 'Camera.PictureSourceType.CAMERA should equal to 1'); - equals(Camera.PictureSourceType.SAVEDPHOTOALBUM, 2, 'Camera.PictureSourceType.SAVEDPHOTOALBUM should equal to 2'); - equals(navigator.camera.PictureSourceType.PHOTOLIBRARY, 0, 'navigator.camera.PictureSourceType.PHOTOLIBRARY should equal to 0'); - equals(navigator.camera.PictureSourceType.CAMERA, 1, 'navigator.camera.PictureSourceType.CAMERA should equal to 1'); - equals(navigator.camera.PictureSourceType.SAVEDPHOTOALBUM, 2, 'navigator.camera.PictureSourceType.SAVEDPHOTOALBUM should equal to 2'); - }); -}; + it("should contain three MediaType constants", function() { + expect(Camera.MediaType.PICTURE).toBe(0); + expect(Camera.MediaType.VIDEO).toBe(1); + expect(Camera.MediaType.ALLMEDIA).toBe(2); + expect(navigator.camera.MediaType.PICTURE).toBe(0); + expect(navigator.camera.MediaType.VIDEO).toBe(1); + expect(navigator.camera.MediaType.ALLMEDIA).toBe(2); + }); + it("should contain three PictureSourceType constants", function() { + expect(Camera.PictureSourceType.PHOTOLIBRARY).toBe(0); + expect(Camera.PictureSourceType.CAMERA).toBe(1); + expect(Camera.PictureSourceType.SAVEDPHOTOALBUM).toBe(2); + expect(navigator.camera.PictureSourceType.PHOTOLIBRARY).toBe(0); + expect(navigator.camera.PictureSourceType.CAMERA).toBe(1); + expect(navigator.camera.PictureSourceType.SAVEDPHOTOALBUM).toBe(2); + }); +}); diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/capture.tests.js b/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/capture.tests.js index 594d7d19..bffced84 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/capture.tests.js +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/capture.tests.js @@ -1,97 +1,95 @@ -Tests.prototype.CaptureTests = function() { - module('Capture (navigator.device.capture)'); - test("should exist", function() { - expect(2); - ok(navigator.device !== null, "navigator.device should not be null."); - ok(navigator.device.capture !== null, "navigator.device.capture should not be null."); +describe('Capture (navigator.device.capture)', function () { + it("should exist", function() { + expect(navigator.device).toBeDefined(); + expect(navigator.device.capture).toBeDefined(); }); - test("should have the correct properties ", function() { - expect(3); - ok(typeof navigator.device.capture.supportedAudioModes != 'undefined' && navigator.device.capture.supportedAudioModes !== null , "there should be a supported audio modes property"); - ok(typeof navigator.device.capture.supportedImageModes != 'undefined' && navigator.device.capture.supportedImageModes !== null , "there should be a supported image modes property"); - ok(typeof navigator.device.capture.supportedVideoModes != 'undefined' && navigator.device.capture.supportedVideoModes !== null , "there should be a supported video modes property"); - }); - test("should contain a captureAudio function", function() { - expect(2); - ok(typeof navigator.device.capture.captureAudio != 'undefined' && navigator.device.capture.captureAudio !== null, "navigator.device.capture.captureAudio should not be null."); - ok(typeof navigator.device.capture.captureAudio == 'function', "navigator.device.capture.captureAudio should be a function."); + + it("should have the correct properties ", function() { + expect(navigator.device.capture.supportedAudioModes).toBeDefined(); + expect(navigator.device.capture.supportedImageModes).toBeDefined(); + expect(navigator.device.capture.supportedVideoModes).toBeDefined(); }); - test("should contain a captureImage function", function() { - expect(2); - ok(typeof navigator.device.capture.captureImage != 'undefined' && navigator.device.capture.captureImage !== null, "navigator.device.capture.captureImage should not be null."); - ok(typeof navigator.device.capture.captureImage == 'function', "navigator.device.capture.captureImage should be a function."); + + it("should contain a captureAudio function", function() { + expect(navigator.device.capture.captureAudio).toBeDefined(); + expect(typeof navigator.device.capture.captureAudio == 'function').toBe(true); }); - test("should contain a captureVideo function", function() { - expect(2); - ok(typeof navigator.device.capture.captureVideo != 'undefined' && navigator.device.capture.captureVideo !== null, "navigator.device.capture.captureVideo should not be null."); - ok(typeof navigator.device.capture.captureVideo == 'function', "navigator.device.capture.captureVideo should be a function."); + + it("should contain a captureImage function", function() { + expect(navigator.device.capture.captureImage).toBeDefined(); + expect(typeof navigator.device.capture.captureImage == 'function').toBe(true); }); - module('CaptureAudioOptions'); - test("CaptureAudioOptions constructor should exist", function() { - expect(4); - var options = new CaptureAudioOptions(); - ok(options !== null, "CaptureAudioOptions object should not be null."); - ok(typeof options.limit !== 'undefined', "CaptureAudioOptions object should have a 'limit' property."); - ok(typeof options.duration !== 'undefined', "CaptureAudioOptions object should have a 'duration' property."); - ok(typeof options.mode !== 'undefined', "CaptureAudioOptions object should have a 'mode' property."); + it("should contain a captureVideo function", function() { + expect(navigator.device.capture.captureVideo).toBeDefined(); + expect(typeof navigator.device.capture.captureVideo == 'function').toBe(true); }); - module('CaptureImageOptions'); - test("CaptureImageOptions constructor should exist", function() { - expect(3); - var options = new CaptureImageOptions(); - ok(options !== null, "CaptureImageOptions object should not be null."); - ok(typeof options.limit !== 'undefined', "CaptureImageOptions object should have a 'limit' property."); - ok(typeof options.mode !== 'undefined', "CaptureImageOptions object should have a 'mode' property."); + describe('CaptureAudioOptions', function () { + it("CaptureAudioOptions constructor should exist", function() { + var options = new CaptureAudioOptions(); + expect(options).toBeDefined(); + expect(options.limit).toBeDefined(); + expect(options.duration).toBeDefined(); + expect(options.mode).toBeDefined(); + }); }); - module('CaptureVideoOptions'); - test("CaptureVideoOptions constructor should exist", function() { - expect(4); - var options = new CaptureVideoOptions(); - ok(options !== null, "CaptureVideoOptions object should not be null."); - ok(typeof options.limit !== 'undefined', "CaptureVideoOptions object should have a 'limit' property."); - ok(typeof options.duration !== 'undefined', "CaptureVideoOptions object should have a 'duration' property."); - ok(typeof options.mode !== 'undefined', "CaptureVideoOptions object should have a 'mode' property."); + describe('CaptureImageOptions', function () { + it("CaptureImageOptions constructor should exist", function() { + var options = new CaptureImageOptions(); + expect(options).toBeDefined(); + expect(options.limit).toBeDefined(); + expect(options.mode).toBeDefined(); + }); }); - module('CaptureError interface'); - test("CaptureError constants should be defined", function() { - expect(4); - equal(CaptureError.CAPTURE_INTERNAL_ERR, 0, "CaptureError.CAPTURE_INTERNAL_ERR should be defined"); - equal(CaptureError.CAPTURE_APPLICATION_BUSY, 1, "CaptureError.CAPTURE_APPLICATION_BUSY should be defined"); - equal(CaptureError.CAPTURE_INVALID_ARGUMENT, 2, "CaptureError.CAPTURE_INVALID_ARGUMENT should be defined"); - equal(CaptureError.CAPTURE_NO_MEDIA_FILES, 3, "CaptureError.CAPTURE_NO_MEDIA_FILES should be defined"); + describe('CaptureVideoOptions', function () { + it("CaptureVideoOptions constructor should exist", function() { + var options = new CaptureVideoOptions(); + expect(options).toBeDefined(); + expect(options.limit).toBeDefined(); + expect(options.duration).toBeDefined(); + expect(options.mode).toBeDefined(); + }); }); - test("CaptureError properties should exist", function() { - expect(2); - var error = new CaptureError(); - ok(error !== null, "CaptureError object should not be null."); - ok(typeof error.code !== 'undefined', "CaptureError object should have a 'code' property."); + + describe('CaptureError interface', function () { + it("CaptureError constants should be defined", function() { + expect(CaptureError.CAPTURE_INTERNAL_ERR).toBe(0); + expect(CaptureError.CAPTURE_APPLICATION_BUSY).toBe(1); + expect(CaptureError.CAPTURE_INVALID_ARGUMENT).toBe(2); + expect(CaptureError.CAPTURE_NO_MEDIA_FILES).toBe(3); + }); + + it("CaptureError properties should exist", function() { + var error = new CaptureError(); + expect(error).toBeDefined(); + expect(error.code).toBeDefined(); + }); }); - module('MediaFileData'); - test("MediaFileData constructor should exist", function() { - expect(6); - var fileData = new MediaFileData(); - ok(fileData !== null, "MediaFileData object should not be null."); - ok(typeof fileData.bitrate !== 'undefined', "MediaFileData object should have a 'bitrate' property."); - ok(typeof fileData.codecs !== 'undefined', "MediaFileData object should have a 'codecs' property."); - ok(typeof fileData.duration !== 'undefined', "MediaFileData object should have a 'duration' property."); - ok(typeof fileData.height !== 'undefined', "MediaFileData object should have a 'height' property."); - ok(typeof fileData.width !== 'undefined', "MediaFileData object should have a 'width' property."); + describe('MediaFileData', function () { + it("MediaFileData constructor should exist", function() { + var fileData = new MediaFileData(); + expect(fileData).toBeDefined(); + expect(fileData.bitrate).toBeDefined(); + expect(fileData.codecs).toBeDefined(); + expect(fileData.duration).toBeDefined(); + expect(fileData.height).toBeDefined(); + expect(fileData.width).toBeDefined(); + }); }); - module('MediaFile'); - test("MediaFile constructor should exist", function() { - expect(6); - var fileData = new MediaFile(); - ok(fileData !== null, "MediaFile object should not be null."); - ok(typeof fileData.name !== 'undefined', "MediaFile object should have a 'name' property."); - ok(typeof fileData.fullPath !== 'undefined', "MediaFile object should have a 'fullPath' property."); - ok(typeof fileData.type !== 'undefined', "MediaFile object should have a 'type' property."); - ok(typeof fileData.lastModifiedDate !== 'undefined', "MediaFile object should have a 'lastModifiedDate' property."); - ok(typeof fileData.size !== 'undefined', "MediaFile object should have a 'size' property."); + describe('MediaFile', function () { + it("MediaFile constructor should exist", function() { + var fileData = new MediaFile(); + expect(fileData).toBeDefined(); + expect(fileData.name).toBeDefined(); + expect(fileData.fullPath).toBeDefined(); + expect(fileData.type).toBeDefined(); + expect(fileData.lastModifiedDate).toBeDefined(); + expect(fileData.size).toBeDefined(); + }); }); -}; +}); diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/compass.tests.js b/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/compass.tests.js index b3abf2b1..a16ec0e7 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/compass.tests.js +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/compass.tests.js @@ -1,72 +1,76 @@ -Tests.prototype.CompassTests = function() { - module('Compass (navigator.compass)'); - test("should exist", function() { - expect(1); - ok(navigator.compass !== null, "navigator.compass should not be null."); - }); - test("should contain a getCurrentHeading function", function() { - expect(2); - ok(typeof navigator.compass.getCurrentHeading != 'undefined' && navigator.compass.getCurrentHeading !== null, "navigator.compass.getCurrentHeading should not be null."); - ok(typeof navigator.compass.getCurrentHeading == 'function', "navigator.compass.getCurrentHeading should be a function."); - }); - test("getCurrentHeading success callback should be called with a Heading object", function() { - expect(9); - QUnit.stop(Tests.TEST_TIMEOUT); - var win = function(a) { - ok(a instanceof CompassHeading, "Heading object returned in getCurrentHeading success callback should be an instance of CompassHeading."); - ok(a.magneticHeading !== null, "Heading object returned in getCurrentHeading success callback should have an 'magneticHeading' property."); - ok(typeof a.magneticHeading == 'number', "Heading object's 'magneticHeading' property returned in getCurrentHeading success callback should be of type 'number'."); - ok(a.trueHeading !== undefined, "Heading object returned in getCurrentHeading success callback should have a 'trueHeading' property."); - ok(typeof a.trueHeading == 'number' || a.trueHeading === null, "Heading object's 'trueHeading' property returned in getCurrentHeading success callback should be of type 'number', or should be null if not available."); - ok(a.headingAccuracy !== undefined, "Heading object returned in getCurrentHeading success callback should have a 'headingAccuracy' property."); - ok(typeof a.headingAccuracy == 'number' || a.headingAccuracy === null, "Heading object's 'headingAccuracy' property returned in getCurrentHeading success callback should be of type 'number', or should be null if not available."); - ok(a.timestamp !== null, "Heading object returned in getCurrentHeading success callback should have a 'timestamp' property."); - ok(a.timestamp instanceof Date, "Heading object's 'timestamp' property returned in getCurrentHeading success callback should be of type 'Date'."); - QUnit.start(); - }; - var fail = function() { QUnit.start(); }; - navigator.compass.getCurrentHeading(win, fail); - }); - test("should contain a watchHeading function", function() { - expect(2); - ok(typeof navigator.compass.watchHeading != 'undefined' && navigator.compass.watchHeading !== null, "navigator.compass.watchHeading should not be null."); - ok(typeof navigator.compass.watchHeading == 'function', "navigator.compass.watchHeading should be a function."); +describe('Compass (navigator.compass)', function () { + it("should exist", function() { + expect(navigator.compass).toBeDefined(); + }); + + it("should contain a getCurrentHeading function", function() { + expect(navigator.compass.getCurrentHeading).toBeDefined(); + expect(typeof navigator.compass.getCurrentHeading == 'function').toBe(true); }); - test("should contain a clearWatch function", function() { - expect(2); - ok(typeof navigator.compass.clearWatch != 'undefined' && navigator.compass.clearWatch !== null, "navigator.compass.clearWatch should not be null."); - ok(typeof navigator.compass.clearWatch == 'function', "navigator.compass.clearWatch should be a function!"); + + it("getCurrentHeading success callback should be called with a Heading object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a instanceof CompassHeading).toBe(true); + expect(a.magneticHeading).toBeDefined(); + expect(typeof a.magneticHeading == 'number').toBe(true); + expect(a.trueHeading).not.toBe(undefined); + expect(typeof a.trueHeading == 'number' || a.trueHeading === null).toBe(true); + expect(a.headingAccuracy).not.toBe(undefined); + expect(typeof a.headingAccuracy == 'number' || a.headingAccuracy === null).toBe(true); + expect(typeof a.timestamp == 'number').toBe(true); + }), + fail = jasmine.createSpy(); + + runs(function () { + navigator.compass.getCurrentHeading(win, fail); + }); + + waitsFor(function () { return win.wasCalled; }, "success callback never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + expect(win).toHaveBeenCalled(); + }); }); - module('Compass Constants (window.CompassError)'); - test("CompassError globals should exist", function() { - expect(3); - ok(window.CompassError !== null, 'window.CompassError should not be null'); - equals(window.CompassError.COMPASS_INTERNAL_ERR, 0, 'window.CompassError.COMPASS_INTERNAL_ERR should be 0'); - equals(window.CompassError.COMPASS_NOT_SUPPORTED, 20, 'window.CompassError.COMPASS_NOT_SUPPORTED should be 20'); - }); + it("should contain a watchHeading function", function() { + expect(navigator.compass.watchHeading).toBeDefined(); + expect(typeof navigator.compass.watchHeading == 'function').toBe(true); + }); + + it("should contain a clearWatch function", function() { + expect(navigator.compass.clearWatch).toBeDefined(); + expect(typeof navigator.compass.clearWatch == 'function').toBe(true); + }); + + describe('Compass Constants (window.CompassError)', function () { + it("should exist", function() { + expect(window.CompassError).toBeDefined(); + expect(window.CompassError.COMPASS_INTERNAL_ERR).toBe(0); + expect(window.CompassError.COMPASS_NOT_SUPPORTED).toBe(20); + }); + }); + + describe('Compass Heading model (CompassHeading)', function () { + it("should exist", function() { + expect(CompassHeading).toBeDefined(); + }); + + it("should be able to create a new CompassHeading instance with no parameters", function() { + var h = new CompassHeading(); + expect(h.magneticHeading).toBeDefined(); + expect(h.trueHeading).toBeDefined(); + expect(h.headingAccuracy).toBeDefined(); + expect(typeof h.timestamp == 'number').toBe(true); + }); - module('Compass Heading model (CompassHeading)'); - test("CompassHeading function should exist", function() { - expect(1); - ok(typeof CompassHeading != 'undefined' && CompassHeading !== null, 'CompassHeading should not be null'); - }); - test("Creating a new CompassHeading instance with no parameters", function() { - expect(5); - var h = new CompassHeading(); - equals(h.magneticHeading, null, "CompassHeading instance should have null magneticHeading property by default"); - equals(h.trueHeading, null, "CompassHeading instance should have null trueHeading property by default"); - equals(h.headingAccuracy, null, "CompassHeading instance should have null headingAccuracy property by default"); - ok(h.timestamp !== null, "CompassHeading instance should have timestamp that is not null by default"); - ok(h.timestamp instanceof Date, "CompassHeading instance should have timestamp that is an instance of a Date object."); - }); - test("Creating a new CompassHeading instance with parameters", function() { - expect(5); - var h = new CompassHeading(1,2,3,4); - equals(h.magneticHeading, 1, "CompassHeading instance should have specified magneticHeading."); - equals(h.trueHeading, 2, "CompassHeading instance should have specified trueHeading."); - equals(h.headingAccuracy, 3, "CompassHeading instance should have specified headingAccuracy."); - equals(h.timestamp.valueOf(), 4, "CompassHeading instance should have specified timestamp cast as a Date object"); - ok(h.timestamp instanceof Date, "CompassHeading instance should have timestamp that is an instance of a Date object."); - }); -}; + it("should be able to creat a new CompassHeading instance with parameters", function() { + var h = new CompassHeading(1,2,3,4); + expect(h.magneticHeading).toBe(1); + expect(h.trueHeading).toBe(2); + expect(h.headingAccuracy).toBe(3); + expect(h.timestamp.valueOf()).toBe(4); + expect(typeof h.timestamp == 'number').toBe(true); + }); + }); +}); diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/contacts.tests.js b/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/contacts.tests.js index bfba15c1..959125e1 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/contacts.tests.js +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/contacts.tests.js @@ -12,83 +12,77 @@ var removeContact = function(){ } }; -Tests.prototype.ContactsTests = function() { - module("Contacts (navigator.contacts)"); - test("should exist", function() { - expect(1); - ok(navigator.contacts != null, "navigator.contacts should not be null."); +describe("Contacts (navigator.contacts)", function () { + it("should exist", function() { + expect(navigator.contacts).toBeDefined(); }); - test("should contain a find function", function() { - expect(2); - ok(typeof navigator.contacts.find != 'undefined' && navigator.contacts.find != null, "navigator.contacts.find should not be null."); - ok(typeof navigator.contacts.find == 'function', "navigator.contacts.find should be a function."); - }); - test("contacts.find success callback should be called with an array", function() { - expect(2); - QUnit.stop(15000); - var win = function(result) { - ok(typeof result == 'object', "Object returned in contacts.find success callback is of type 'object' (actually array)."); - ok(typeof result.length == 'number', "Object returned in contacts.find success callback has a length property which is numerical."); - QUnit.start(); - }; - var fail = function() { QUnit.start(); }; - var obj = new ContactFindOptions(); - obj.filter=""; - obj.multiple=true; - navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails"], win, fail, obj); - }); - test("contacts.find success callback should not be null", function() { - expect(1); - var fail = function() {}; - var obj = new ContactFindOptions(); - obj.filter=""; - obj.multiple=true; - try { - navigator.contacts.find(["displayName", "name", "emails", "phoneNumbers"], null, fail, obj); - } catch(e) { - ok(true, "Trying to find with a null success call back should throw TypeError."); - } - }); - test("contacts.find error callback should be called when no fields are specified", function() { - expect(2); - QUnit.stop(Tests.TEST_TIMEOUT); - var win = function(result) { - ok(false, "Success callback should not fire in this test, failed."); - QUnit.start(); - }; - var fail = function(result) { - ok(typeof result == 'object', "Object returned in contact.find failure callback is of type 'object' (actually ContactError)."); - ok(result.code == ContactError.INVALID_ARGUMENT_ERROR, "Object returned in contacts.find failure callback has a code property which equal to ContactError.INVALID_ARGUMENT_ERROR."); - QUnit.start(); - }; - var obj = new ContactFindOptions(); - obj.filter=""; - obj.multiple=true; - navigator.contacts.find([], win, fail, obj); - }); - module("contacts.find with newly-created contact", { - setup:function() {}, - teardown:removeContact + + it("should contain a find function", function() { + expect(navigator.contacts.find).toBeDefined(); + expect(typeof navigator.contacts.find).toBe('function'); }); - test("find a contact by name", function() { - expect(4); - QUnit.stop(7000); - // ---- - // Helper save/create invocations+asserts - // ---- - gContactObj = new Contact(); - gContactObj.name = new ContactName(); - gContactObj.name.familyName = "Delete"; - gContactObj.save( - function(savedContact) { - ok(true, "Contact's save success callback needs to fire for this test to pass"); - // update so contact will get removed - gContactObj = savedContact; - // ---- - // Find asserts - // --- - var findWin = function(object) { - var foundName = function(result) { + + describe("find method", function() { + it("success callback should be called with an array", function() { + var win = jasmine.createSpy().andCallFake(function(result) { + expect(result).toBeDefined(); + expect(result instanceof Array).toBe(true); + }), + fail = jasmine.createSpy(), + obj = new ContactFindOptions(); + + runs(function () { + obj.filter=""; + obj.multiple=true; + navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails"], win, fail, obj); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + + it("should throw an exception if success callback is empty", function() { + var fail = function() {}; + var obj = new ContactFindOptions(); + obj.filter=""; + obj.multiple=true; + + expect(function () { + navigator.contacts.find(["displayName", "name", "emails", "phoneNumbers"], null, fail, obj); + }).toThrow(); + }); + + it("error callback should be called when no fields are specified", function() { + var win = jasmine.createSpy(), + fail = jasmine.createSpy(function(result) { + expect(result).toBeDefined(); + expect(result.code).toBe(ContactError.INVALID_ARGUMENT_ERROR); + }), + obj = new ContactFindOptions(); + + runs(function () { + obj.filter=""; + obj.multiple=true; + navigator.contacts.find([], win, fail, obj); + }); + + waitsFor(function () { return fail.wasCalled; }, Tests.TEST_TIMEOUT); + + runs(function () { + expect(win).not.toHaveBeenCalled(); + expect(fail).toHaveBeenCalled(); + }); + }); + + describe("with newly-created contact", function () { + + afterEach(removeContact); + + it("should be able to find a contact by name", function() { + var foundName = jasmine.createSpy().andCallFake(function(result) { var bFound = false; try { for (var i=0; i < result.length; i++) { @@ -101,325 +95,351 @@ Tests.prototype.ContactsTests = function() { return false; } return bFound; - } - ok(object instanceof Array, "Object returned in contacts.find success callback should be instanceof array."); - ok(object.length >= 1, "length of Object returned in contacts.find success callback should have length property >= 1"); - ok(foundName(object) == true, "returned contact array should contain a contact with familyName of 'Delete'."); - QUnit.start(); - }; - var findFail = function() { - ok(false, "find method's error callback called, test failed."); - QUnit.start(); - }; - var obj = new ContactFindOptions(); - obj.filter="Delete"; - obj.multiple=true; - navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails"], findWin, findFail, obj); - }, - function(e){ - ok(false, "Contact's save error callback fired; this test cannot continue"); - QUnit.start(); + }), + fail = jasmine.createSpy(), + test = jasmine.createSpy().andCallFake(function(savedContact) { + console.log('in test'); + // update so contact will get removed + gContactObj = savedContact; + // ---- + // Find asserts + // --- + var findWin = jasmine.createSpy().andCallFake(function(object) { + console.log('in findwin'); + expect(object instanceof Array).toBe(true); + expect(object.length >= 1).toBe(true); + expect(foundName(object)).toBe(true); + }), + findFail = jasmine.createSpy(), + obj = new ContactFindOptions(); + + obj.filter="Delete"; + obj.multiple=true; + + runs(function () { + navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails"], findWin, findFail, obj); + }); + + waitsFor(function () { return foundName.wasCalled; }, "foundName not done", Tests.TEST_TIMEOUT); + + runs(function () { + expect(findFail).not.toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); + + runs(function () { + gContactObj = new Contact(); + gContactObj.name = new ContactName(); + gContactObj.name.familyName = "Delete"; + gContactObj.save(test, fail); + }); + + waitsFor(function () { return test.wasCalled; }, "test not done", Tests.TEST_TIMEOUT); + }); }); }); - module("Contacts (navigator.contacts)"); - test("should contain a create function", function() { - expect(2); - ok(typeof navigator.contacts.create != 'undefined' && navigator.contacts.create != null, "navigator.contacts.create should not be null."); - ok(typeof navigator.contacts.create == 'function', "navigator.contacts.create should be a function."); - }); - test("contacts.create should return a Contact object", function() { - expect(9); - var bDay = new Date(1976, 7,4); - var obj = navigator.contacts.create({"displayName": "test name", "gender": "male", "note": "my note", "name": {"formatted": "Mr. Test Name"}, "emails": [{"value": "here@there.com"}, {"value": "there@here.com"}], "birthday": bDay}); - ok(obj != 'undefined' && obj != null, "navigator.contacts.create should return a Contact object."); - ok(obj.displayName == 'test name', "Contact should contain a displayName property."); - ok(obj.note == 'my note', "Contact should contain a note property."); - ok(obj.name.formatted == 'Mr. Test Name', "Contact should contain a name.formatted property."); - ok(obj.emails.length == 2, "Contact should contain and array of emails with 2 entries"); - ok(obj.emails[0].value == 'here@there.com', "Contact.emails[1] should contain a value."); - ok(obj.emails[1].value == 'there@here.com', "Contact.emails[2] should contain a value."); - ok(obj.nickname == null, "Contact object should not contain a nickname property."); - ok(obj.birthday instanceof Date && obj.birthday == bDay, "Contact should be a Date object equal to " + bDay); - }); - module("Contact model"); - test("should be able to define a Contact object", function() { - expect(15); - var contact = new Contact("a", "b", new ContactName("a", "b", "c", "d", "e", "f"), "c", [], [], [], [], [], "f", "i", - [], [], []); - ok(contact != null, "new Contact() should not be null."); - ok(typeof contact.id != 'undefined' && contact.id != null && contact.id == "a", "new Contact() should include a 'id' property."); - ok(typeof contact.displayName != 'undefined' && contact.displayName != null && contact.displayName == "b", "new Contact() should include a 'displayName' property."); - ok(typeof contact.name != 'undefined' && contact.name != null && contact.name.formatted == "a", "new Contact() should include a 'name' property."); - ok(typeof contact.nickname != 'undefined' && contact.nickname != null && contact.nickname == "c", "new Contact() should include a 'nickname' property."); - ok(typeof contact.phoneNumbers != 'undefined' && contact.phoneNumbers != null, "new Contact() should include a 'phoneNumbers' property."); - ok(typeof contact.emails != 'undefined' && contact.emails != null, "new Contact() should include a 'emails' property."); - ok(typeof contact.addresses != 'undefined' && contact.addresses != null, "new Contact() should include a 'addresses' property."); - ok(typeof contact.ims != 'undefined' && contact.ims != null, "new Contact() should include a 'ims' property."); - ok(typeof contact.organizations != 'undefined' && contact.organizations != null, "new Contact() should include a 'organizations' property."); - ok(typeof contact.birthday != 'undefined' && contact.birthday != null && contact.birthday == "f", "new Contact() should include a 'birthday' property."); - ok(typeof contact.note != 'undefined' && contact.note != null && contact.note == "i", "new Contact() should include a 'note' property."); - ok(typeof contact.photos != 'undefined' && contact.photos != null, "new Contact() should include a 'photos' property."); - ok(typeof contact.categories != 'undefined' && contact.categories != null, "new Contact() should include a 'categories' property."); - ok(typeof contact.urls != 'undefined' && contact.urls != null, "new Contact() should include a 'urls' property."); - }); - test("should be able to define a ContactName object", function() { - expect(7); - var contactName = new ContactName("Dr. First Last Jr.", "Last", "First", "Middle", "Dr.", "Jr."); - ok(contactName != null, "new ContactName() should not be null."); - ok(typeof contactName.formatted != 'undefined' && contactName.formatted != null && contactName.formatted == "Dr. First Last Jr.", "new ContactName() should include a 'formatted' property."); - ok(typeof contactName.familyName != 'undefined' && contactName.familyName != null && contactName.familyName == "Last", "new ContactName() should include a 'familyName' property."); - ok(typeof contactName.givenName != 'undefined' && contactName.givenName != null && contactName.givenName == "First", "new ContactName() should include a 'givenName' property."); - ok(typeof contactName.middleName != 'undefined' && contactName.middleName != null && contactName.middleName == "Middle", "new ContactName() should include a 'middleName' property."); - ok(typeof contactName.honorificPrefix != 'undefined' && contactName.honorificPrefix != null && contactName.honorificPrefix == "Dr.", "new ContactName() should include a 'honorificPrefix' property."); - ok(typeof contactName.honorificSuffix != 'undefined' && contactName.honorificSuffix != null && contactName.honorificSuffix == "Jr.", "new ContactName() should include a 'honorificSuffix' property."); - }); - test("should be able to define a ContactField object", function() { - expect(4); - var contactField = new ContactField("home", "8005551212", true); - ok(contactField != null, "new ContactField() should not be null."); - ok(typeof contactField.type != 'undefined' && contactField.type != null && contactField.type == "home", "new ContactField() should include a 'type' property."); - ok(typeof contactField.value != 'undefined' && contactField.value != null && contactField.value == "8005551212", "new ContactField() should include a 'value' property."); - ok(typeof contactField.pref != 'undefined' && contactField.pref != null && contactField.pref == true, "new ContactField() should include a 'pref' property."); - }); - test("should be able to define a ContactAddress object", function() { - expect(9); - var contactAddress = new ContactAddress(true, "home", "a","b","c","d","e","f"); - ok(contactAddress != null, "new ContactAddress() should not be null."); - ok(typeof contactAddress.pref != 'undefined' && contactAddress.pref != null && contactAddress.pref == true, "new ContactAddress() should include a 'pref' property."); - ok(typeof contactAddress.type != 'undefined' && contactAddress.type != null && contactAddress.type == "home", "new ContactAddress() should include a 'type' property."); - ok(typeof contactAddress.formatted != 'undefined' && contactAddress.formatted != null && contactAddress.formatted == "a", "new ContactAddress() should include a 'formatted' property."); - ok(typeof contactAddress.streetAddress != 'undefined' && contactAddress.streetAddress != null && contactAddress.streetAddress == "b", "new ContactAddress() should include a 'streetAddress' property."); - ok(typeof contactAddress.locality != 'undefined' && contactAddress.locality != null && contactAddress.locality == "c", "new ContactAddress() should include a 'locality' property."); - ok(typeof contactAddress.region != 'undefined' && contactAddress.region != null && contactAddress.region == "d", "new ContactAddress() should include a 'region' property."); - ok(typeof contactAddress.postalCode != 'undefined' && contactAddress.postalCode != null && contactAddress.postalCode == "e", "new ContactAddress() should include a 'postalCode' property."); - ok(typeof contactAddress.country != 'undefined' && contactAddress.country != null && contactAddress.country == "f", "new ContactAddress() should include a 'country' property."); - }); - test("should be able to define a ContactOrganization object", function() { - expect(6); - var contactOrg = new ContactOrganization(true, "home", "a","b","c","d","e","f","g"); - ok(contactOrg != null, "new ContactOrganization() should not be null."); - ok(typeof contactOrg.pref != 'undefined' && contactOrg.pref != null && contactOrg.pref == true, "new ContactOrganization() should include a 'pref' property."); - ok(typeof contactOrg.type != 'undefined' && contactOrg.type != null && contactOrg.type == "home", "new ContactOrganization() should include a 'type' property."); - ok(typeof contactOrg.name != 'undefined' && contactOrg.name != null && contactOrg.name == "a", "new ContactOrganization() should include a 'name' property."); - ok(typeof contactOrg.department != 'undefined' && contactOrg.department != null && contactOrg.department == "b", "new ContactOrganization() should include a 'department' property."); - ok(typeof contactOrg.title != 'undefined' && contactOrg.title != null && contactOrg.title == "c", "new ContactOrganization() should include a 'title' property."); - }); - test("should be able to define a ContactFindOptions object", function() { - expect(3); - var contactFindOptions = new ContactFindOptions("a", true, "b"); - ok(contactFindOptions != null, "new ContactFindOptions() should not be null."); - ok(typeof contactFindOptions.filter != 'undefined' && contactFindOptions.filter != null && contactFindOptions.filter == "a", "new ContactFindOptions() should include a 'filter' property."); - ok(typeof contactFindOptions.multiple != 'undefined' && contactFindOptions.multiple != null && contactFindOptions.multiple == true, "new ContactFindOptions() should include a 'multiple' property."); - }); - module("Contact Object"); - test("should contain a clone function", function() { - expect(2); - var contact = new Contact(); - ok(typeof contact.clone != 'undefined' && contact.clone != null, "contact.clone should not be null."); - ok(typeof contact.clone == 'function', "contact.clone should be a function."); + + describe('create method', function() { + + it("should exist", function() { + expect(navigator.contacts.create).toBeDefined(); + expect(typeof navigator.contacts.create).toBe('function'); + }); + + it("should return a Contact object", function() { + var bDay = new Date(1976, 7,4); + var obj = navigator.contacts.create({"displayName": "test name", "gender": "male", "note": "my note", "name": {"formatted": "Mr. Test Name"}, "emails": [{"value": "here@there.com"}, {"value": "there@here.com"}], "birthday": bDay}); + + expect(obj).toBeDefined(); + expect(obj.displayName).toBe('test name'); + expect(obj.note).toBe('my note'); + expect(obj.name.formatted).toBe('Mr. Test Name'); + expect(obj.emails.length).toBe(2); + expect(obj.emails[0].value).toBe('here@there.com'); + expect(obj.emails[1].value).toBe('there@here.com'); + expect(obj.nickname).toBe(null); + expect(obj.birthday).toBe(bDay); + }); }); - test("clone function should make deep copy of Contact Object", function() { - expect(8); - var contact = new Contact(); - contact.id=1; - contact.displayName="Test Name"; - contact.nickname="Testy"; - contact.gender="male"; - contact.note="note to be cloned"; - contact.name = new ContactName("Mr. Test Name"); - - var clonedContact = contact.clone(); + + describe("Contact object", function () { + it("should be able to create instance", function() { + var contact = new Contact("a", "b", new ContactName("a", "b", "c", "d", "e", "f"), "c", [], [], [], [], [], "f", "i", + [], [], []); + expect(contact).toBeDefined(); + expect(contact.id).toBe("a"); + expect(contact.displayName).toBe("b"); + expect(contact.name.formatted).toBe("a"); + expect(contact.nickname).toBe("c"); + expect(contact.phoneNumbers).toBeDefined(); + expect(contact.emails).toBeDefined(); + expect(contact.addresses).toBeDefined(); + expect(contact.ims).toBeDefined(); + expect(contact.organizations).toBeDefined(); + expect(contact.birthday).toBe("f"); + expect(contact.note).toBe("i"); + expect(contact.photos).toBeDefined(); + expect(contact.categories).toBeDefined(); + expect(contact.urls).toBeDefined(); + }); + + it("should be able to define a ContactName object", function() { + var contactName = new ContactName("Dr. First Last Jr.", "Last", "First", "Middle", "Dr.", "Jr."); + expect(contactName).toBeDefined(); + expect(contactName.formatted).toBe("Dr. First Last Jr."); + expect(contactName.familyName).toBe("Last"); + expect(contactName.givenName).toBe("First"); + expect(contactName.middleName).toBe("Middle"); + expect(contactName.honorificPrefix).toBe("Dr."); + expect(contactName.honorificSuffix).toBe("Jr."); + }); + + it("should be able to define a ContactField object", function() { + var contactField = new ContactField("home", "8005551212", true); + expect(contactField).toBeDefined(); + expect(contactField.type).toBe("home"); + expect(contactField.value).toBe("8005551212"); + expect(contactField.pref).toBe(true); + }); + + it("should be able to define a ContactAddress object", function() { + var contactAddress = new ContactAddress(true, "home", "a","b","c","d","e","f"); + expect(contactAddress).toBeDefined(); + expect(contactAddress.pref).toBe(true); + expect(contactAddress.type).toBe("home"); + expect(contactAddress.formatted).toBe("a"); + expect(contactAddress.streetAddress).toBe("b"); + expect(contactAddress.locality).toBe("c"); + expect(contactAddress.region).toBe("d"); + expect(contactAddress.postalCode).toBe("e"); + expect(contactAddress.country).toBe("f"); + }); + + it("should be able to define a ContactOrganization object", function() { + var contactOrg = new ContactOrganization(true, "home", "a","b","c","d","e","f","g"); + expect(contactOrg).toBeDefined(); + expect(contactOrg.pref).toBe(true); + expect(contactOrg.type).toBe("home"); + expect(contactOrg.name).toBe("a"); + expect(contactOrg.department).toBe("b"); + expect(contactOrg.title).toBe("c"); + }); + + it("should be able to define a ContactFindOptions object", function() { + var contactFindOptions = new ContactFindOptions("a", true, "b"); + expect(contactFindOptions).toBeDefined(); + expect(contactFindOptions.filter).toBe("a"); + expect(contactFindOptions.multiple).toBe(true); + }); + + it("should contain a clone function", function() { + var contact = new Contact(); + expect(contact.clone).toBeDefined(); + expect(typeof contact.clone).toBe('function'); + }); + + it("clone function should make deep copy of Contact Object", function() { + var contact = new Contact(); + contact.id=1; + contact.displayName="Test Name"; + contact.nickname="Testy"; + contact.gender="male"; + contact.note="note to be cloned"; + contact.name = new ContactName("Mr. Test Name"); + + var clonedContact = contact.clone(); + + expect(contact.id).toBe(1); + expect(clonedContact.id).toBe(null); + expect(clonedContact.displayName).toBe(contact.displayName); + expect(clonedContact.nickname).toBe(contact.nickname); + expect(clonedContact.gender).toBe(contact.gender); + expect(clonedContact.note).toBe(contact.note); + expect(clonedContact.name.formatted).toBe(contact.name.formatted); + expect(clonedContact.connected).toBe(contact.connected); + }); - ok(contact.id == 1, "contact.id should be 1."); - ok(clonedContact.id == null, "clonedContact.id should be null."); - ok(clonedContact.displayName == contact.displayName, "displayName's should be equal"); - ok(clonedContact.nickname == contact.nickname, "nickname's should be equal"); - ok(clonedContact.gender == contact.gender, "gender's should be equal"); - ok(clonedContact.note == contact.note, "note's should be equal"); - ok(clonedContact.name.formatted == contact.name.formatted, "name.formatted's should be equal"); - ok(clonedContact.connected == contact.connected, "connected's should be equal (null)"); - }); - test("should contain a save function", function() { - expect(2); - var contact = new Contact(); - ok(typeof contact.save != 'undefined' && contact.save != null, "contact.save should not be null."); - ok(typeof contact.save == 'function', "contact.save should be a function."); - }); - test("should contain a remove function", function() { - expect(2); - var contact = new Contact(); - ok(typeof contact.remove != 'undefined' && contact.remove != null, "contact.remove should not be null."); - ok(typeof contact.remove == 'function', "contact.remove should be a function."); - }); - module('Contact.save method', { - setup:function(){}, - teardown:function(){} - }); - test("should be able to save a contact", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(9); - - var bDay = new Date(1976, 6,4); - gContactObj = navigator.contacts.create({"gender": "male", "note": "my note", "name": {"familyName": "Delete", "givenName": "Test"}, "emails": [{"value": "here@there.com"}, {"value": "there@here.com"}], "birthday": bDay}); - - var saveSuccess = function(obj) { - ok(obj != 'undefined' && obj != null, "navigator.contacts.save should return a Contact object."); - ok(obj.note == 'my note', "Contact should contain a note property."); - ok(obj.name.familyName == 'Delete', "Contact familyName should equal 'Delete'."); - ok(obj.name.givenName == 'Test', "Contact givenName should equal 'Test'."); - ok(obj.emails.length == 2, "Contact should contain and array of emails with 2 entries."); - ok(obj.emails[0].value == 'here@there.com', "Contact.emails[1] should contain a value."); - ok(obj.emails[1].value == 'there@here.com', "Contact.emails[2] should contain a value."); - ok(obj.birthday instanceof Date && obj.birthday.toDateString() == bDay.toDateString(), "Contact should be a date object equal to " + bDay.toDateString()); - ok(obj.addresses == null, "Contact should return null for addresses."); - // must store returned object in order to have id for update test below - gContactObj = obj; - QUnit.start(); - }; - - gContactObj.save(saveSuccess, function(e) { - ok(false, "save method error callback called, test failed."); - QUnit.start(); + it("should contain a save function", function() { + var contact = new Contact(); + expect(contact.save).toBeDefined(); + expect(typeof contact.save).toBe('function'); + }); + + it("should contain a remove function", function() { + var contact = new Contact(); + expect(contact.remove).toBeDefined(); + expect(typeof contact.remove).toBe('function'); }); - }); - // HACK: there is a reliance between the previous and next test. This is bad form. - test("update a contact", function() { - expect(6); - QUnit.stop(7000); - ok(gContactObj != null, "Contact object from previous test should still exist for this update test to pass."); - - var bDay = new Date(1975, 5,4); - var noteText = "an UPDATED note"; - - var win = function(obj) { - ok(obj != 'undefined' && obj != null, "navigator.contacts.save should return a Contact object."); - ok(obj.id == gContactObj.id, "Contact id should not have changed"); - ok(obj.note == noteText, "Contact should contain a note property."); - ok(obj.birthday instanceof Date && obj.birthday.toDateString() == bDay.toDateString(), "Contact should be a date object equal to " + bDay.toDateString()); - ok(obj.emails.length == 1 && obj.emails[0].value == 'here@there.com', "Contact should contain only one email with value 'here@there.com'"); - removeContact(); // Clean up contact object - QUnit.start(); - }; - var fail = function(obj) { - removeContact(); // Clean up contact object - ok(false, "updating a Contact object then calling .save should not fail. Test failed."); - QUnit.start(); - } - - // remove an email - gContactObj.emails[1].value = ""; - // change birthday - gContactObj.birthday = bDay; - // update note - gContactObj.note = noteText; - gContactObj.save(win, fail); - }); - module('Contact.remove method', { - setup:function(){}, - teardown:removeContact - }); - test("calling remove on a contact has an id of null should return ContactError.UNKNOWN_ERROR", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - var win = function(result) { - ok(false, "Success callback should not be called when calling remove on a Contact object with no ID."); - QUnit.start(); - }; - var fail = function(result) { - ok(typeof result == 'object', "Object returned in contact.remove failure callback is of type 'object' (actually ContactError)."); - ok(result.code == ContactError.UNKNOWN_ERROR, "Object returned in contacts.remove failure callback has a code property which equal to ContactError.UNKNOWN_ERROR."); - QUnit.start(); - }; - var rmContact = new Contact(); - rmContact.remove(win, fail); }); - test("calling remove on a contact that does not exist should return ContactError.UNKNOWN_ERROR", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var win = function(result) { - ok(false, "success callback should never return in this case. Test failed!"); - QUnit.start(); - }; - var fail = function(result) { - ok(typeof result == 'object', "Object returned in contact.remove failure callback is of type 'object' (actually ContactError)."); - ok(result.code == ContactError.UNKNOWN_ERROR, "Object returned in contacts.remove failure callback has a code property which equal to ContactError.UNKNOWN_ERROR."); - QUnit.start(); - }; - // this is a bit risky as some devices may have contact ids that large - var contact = new Contact("this string is supposed to be a unique identifier that will never show up on a device"); - contact.remove(win, fail); + + describe('save method', function () { + it("should be able to save a contact", function() { + var bDay = new Date(1976, 6,4); + gContactObj = navigator.contacts.create({"gender": "male", "note": "my note", "name": {"familyName": "Delete", "givenName": "Test"}, "emails": [{"value": "here@there.com"}, {"value": "there@here.com"}], "birthday": bDay}); + + var saveSuccess = jasmine.createSpy().andCallFake(function(obj) { + expect(obj).toBeDefined(); + expect(obj.note).toBe('my note'); + expect(obj.name.familyName).toBe('Delete'); + expect(obj.name.givenName).toBe('Test'); + expect(obj.emails.length).toBe(2); + expect(obj.emails[0].value).toBe('here@there.com'); + expect(obj.emails[1].value).toBe('there@here.com'); + expect(obj.birthday.toDateString()).toBe(bDay.toDateString()); + expect(obj.addresses).toBe(null); + // must store returned object in order to have id for update test below + gContactObj = obj; + }), + saveFail = jasmine.createSpy(); + + runs(function () { + gContactObj.save(saveSuccess, saveFail); + }); + + waitsFor(function () { return saveSuccess.wasCalled; }, "saveSuccess never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(saveFail).not.toHaveBeenCalled(); + }); + }); + // HACK: there is a reliance between the previous and next test. This is bad form. + it("update a contact", function() { + expect(gContactObj).toBeDefined(); + + var bDay = new Date(1975, 5,4); + var noteText = "an UPDATED note"; + + var win = function(obj) { + expect(obj).toBeDefined(); + expect(obj.id).toBe(gContactObj.id); + expect(obj.note).toBe(noteText); + expect(obj.birthday.toDateString()).toBe(bDay.toDateString()); + expect(obj.emails.length).toBe(1); + expect(obj.emails[0].value).toBe('here@there.com'); + removeContact(); // Clean up contact object + }, fail = jasmine.createSpy().andCallFake(removeContact); + + runs(function () { + // remove an email + gContactObj.emails[1].value = ""; + // change birthday + gContactObj.birthday = bDay; + // update note + gContactObj.note = noteText; + gContactObj.save(win, fail); + }); + + waitsFor(function () { return win.wasCalled; }, "saveSuccess never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); }); - module("Round trip Contact tests (creating + save + delete + find).", { - setup:function(){}, - teardown:removeContact + describe('Contact.remove method', function () { + afterEach(removeContact); + + it("calling remove on a contact has an id of null should return ContactError.UNKNOWN_ERROR", function() { + var win = jasmine.createSpy(); + var fail = jasmine.createSpy().andCallFake(function(result) { + expect(result.code).toBe(ContactError.UNKNOWN_ERROR); + }); + + runs(function () { + var rmContact = new Contact(); + rmContact.remove(win, fail); + }); + + waitsFor(function () { return fail.wasCalled; }, Tests.TEST_TIMEOUT); + + runs(function () { + expect(win).not.toHaveBeenCalled(); + }); + }); + + it("calling remove on a contact that does not exist should return ContactError.UNKNOWN_ERROR", function() { + var win = jasmine.createSpy(); + var fail = jasmine.createSpy().andCallFake(function(result) { + expect(result.code).toBe(ContactError.UNKNOWN_ERROR); + }); + + runs(function () { + var rmContact = new Contact(); + // this is a bit risky as some devices may have contact ids that large + var contact = new Contact("this string is supposed to be a unique identifier that will never show up on a device"); + contact.remove(win, fail); + }); + + waitsFor(function () { return fail.wasCalled; }, Tests.TEST_TIMEOUT); + + runs(function () { + expect(win).not.toHaveBeenCalled(); + }); + }); }); - test("Creating, saving, finding a contact should work, removing it should work, after which we should not be able to find it, and we should not be able to delete it again.", function() { - expect(8); - QUnit.stop(7000); - - gContactObj = new Contact(); - gContactObj.name = new ContactName(); - gContactObj.name.familyName = "DeleteMe"; - gContactObj.save(function(c_obj) { - ok(true, "Contact creation + saving succeeded, proceeding with test."); - var findWin = function(cs) { - ok(true, "contacts.find success callback invoked, proceeding with test."); - equal(cs.length, 1, "contacts.find success callback should return only 1 item (no one has a contact with 'DeleteMe') as a family name."); - //deepEqual(cs[0], gContactObj, "returned Contact object should equal the initially-created Contact object."); - // update to have proper saved id - gContactObj = cs[0]; - gContactObj.remove(function() { - ok(true, "Newly created contact's remove function success callback called, proceeding with test."); - var findWinAgain = function(seas) { - ok(true, "Calling find after deleting contact should be a success, proceeding."); - equal(seas.length, 0, "find post-remove should return zero length array of results."); + + describe("Round trip Contact tests (creating + save + delete + find).", function () { + afterEach(removeContact); + + it("Creating, saving, finding a contact should work, removing it should work, after which we should not be able to find it, and we should not be able to delete it again.", function() { + var done = false; + runs(function () { + gContactObj = new Contact(); + gContactObj.name = new ContactName(); + gContactObj.name.familyName = "DeleteMe"; + gContactObj.save(function(c_obj) { + var findWin = function(cs) { + expect(cs.length).toBe(1); + // update to have proper saved id + gContactObj = cs[0]; gContactObj.remove(function() { - ok(false, "success callback called after non-existent Contact object called remove(). Test failed."); - QUnit.start(); + var findWinAgain = function(seas) { + expect(seas.length).toBe(0); + gContactObj.remove(function() { + throw("success callback called after non-existent Contact object called remove(). Test failed."); + }, function(e) { + expect(e.code).toBe(ContactError.UNKNOWN_ERROR); + done = true; + }); + }; + var findFailAgain = function(e) { + throw("find error callback invoked after delete, test failed."); + }; + var obj = new ContactFindOptions(); + obj.filter="DeleteMe"; + obj.multiple=true; + navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails"], findWinAgain, findFailAgain, obj); }, function(e) { - ok(true, "error callback called after non-existent Contact object called with remove()."); - equal(e.code, ContactError.UNKNOWN_ERROR, "error callback should be called with UNKNOWN_ERROR"); - QUnit.start(); + throw("Newly created contact's remove function invoked error callback. Test failed."); }); }; - var findFailAgain = function(e) { - ok(false, "find error callback invoked after delete, test failed."); - QUnit.start(); + var findFail = function(e) { + throw("Failure callback invoked in navigator.contacts.find call, test failed."); }; var obj = new ContactFindOptions(); obj.filter="DeleteMe"; obj.multiple=true; - navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails"], findWinAgain, findFailAgain, obj); + navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails"], findWin, findFail, obj); }, function(e) { - ok(false, "Newly created contact's remove function invoked error callback. Test failed."); - QUnit.start(); + throw("Contact creation failed, error callback was invoked."); }); - }; - var findFail = function(e) { - ok(false, "Failure callback invoked in navigator.contacts.find call, test failed."); - QUnit.start(); - }; - var obj = new ContactFindOptions(); - obj.filter="DeleteMe"; - obj.multiple=true; - navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails"], findWin, findFail, obj); - }, function(e) { - ok(false, "Contact creation failed, error callback was invoked."); - QUnit.start(); + }); + + waitsFor(function () { return done; }, Tests.TEST_TIMEOUT); }); }); - module('ContactError interface'); - test("ContactError constants should be defined", function() { - expect(7); - equal(ContactError.UNKNOWN_ERROR, 0, "ContactError.UNKNOWN_ERROR should be defined"); - equal(ContactError.INVALID_ARGUMENT_ERROR, 1, "ContactError.INVALID_ARGUMENT_ERROR should be defined"); - equal(ContactError.TIMEOUT_ERROR, 2, "ContactError.TIMEOUT_ERROR should be defined"); - equal(ContactError.PENDING_OPERATION_ERROR, 3, "ContactError.PENDING_OPERATION_ERROR should be defined"); - equal(ContactError.IO_ERROR, 4, "ContactError.IO_ERROR should be defined"); - equal(ContactError.NOT_SUPPORTED_ERROR, 5, "ContactError.NOT_SUPPORTED_ERROR should be defined"); - equal(ContactError.PERMISSION_DENIED_ERROR, 20, "ContactError.PERMISSION_DENIED_ERROR should be defined"); + describe('ContactError interface', function () { + it("ContactError constants should be defined", function() { + expect(ContactError.UNKNOWN_ERROR).toBe(0); + expect(ContactError.INVALID_ARGUMENT_ERROR).toBe(1); + expect(ContactError.TIMEOUT_ERROR).toBe(2); + expect(ContactError.PENDING_OPERATION_ERROR).toBe(3); + expect(ContactError.IO_ERROR).toBe(4); + expect(ContactError.NOT_SUPPORTED_ERROR).toBe(5); + expect(ContactError.PERMISSION_DENIED_ERROR).toBe(20); + }); }); -}; +}); diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/device.tests.js b/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/device.tests.js index b61ded9d..cc322d65 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/device.tests.js +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/device.tests.js @@ -1,37 +1,34 @@ -Tests.prototype.DeviceTests = function () { - module('Device Information (window.device)'); - test("should exist", function () { - console.log("running test 1"); - expect(1); - ok(window.device != null, "window.device should not be null."); - }); - test("should contain a platform specification that is a string", function () { - expect(2); - ok(typeof window.device.platform != 'undefined' && window.device.platform != null, "window.device.platform should not be null.") - ok((new String(window.device.platform)).length > 0, "window.device.platform should contain some sort of description.") - }); - test("should contain a version specification that is a string", function () { - expect(2); - ok(typeof window.device.version != 'undefined' && window.device.version != null, "window.device.version should not be null.") - ok((new String(window.device.version)).length > 0, "window.device.version should contain some kind of description.") - }); - test("should contain a name specification that is a string", function () { - expect(2); - ok(typeof window.device.name != 'undefined' && window.device.name != null, "window.device.name should not be null.") - ok((new String(window.device.name)).length > 0, "window.device.name should contain some kind of description.") - }); - test("should contain a UUID specification that is a string or a number", function () { - expect(2); - ok(typeof window.device.uuid != 'undefined' && window.device.uuid != null, "window.device.uuid should not be null.") - if (typeof window.device.uuid == 'string' || typeof window.device.uuid == 'object') { - ok((new String(window.device.uuid)).length > 0, "window.device.uuid, as a string, should have at least one character.") - } else { - ok(window.device.uuid > 0, "window.device.uuid, as a number, should be greater than 0. (should it, even?)") - } - }); - test("should contain a cordova specification that is a string", function () { - expect(2); - ok(typeof window.device.cordova != 'undefined' && window.device.cordova != null, "window.device.cordova should not be null.") - ok((new String(window.device.cordova)).length > 0, "window.device.cordova should contain some kind of description.") - }); -}; +describe('Device Information (window.device)', function () { + it("should exist", function() { + expect(window.device).toBeDefined(); + }); + + it("should contain a platform specification that is a string", function() { + expect(window.device.platform).toBeDefined(); + expect((new String(window.device.platform)).length > 0).toBe(true); + }); + + it("should contain a version specification that is a string", function() { + expect(window.device.version).toBeDefined(); + expect((new String(window.device.version)).length > 0).toBe(true); + }); + + it("should contain a name specification that is a string", function() { + expect(window.device.name).toBeDefined(); + expect((new String(window.device.name)).length > 0).toBe(true); + }); + + it("should contain a UUID specification that is a string or a number", function() { + expect(window.device.uuid).toBeDefined(); + if (typeof window.device.uuid == 'string' || typeof window.device.uuid == 'object') { + expect((new String(window.device.uuid)).length > 0).toBe(true); + } else { + expect(window.device.uuid > 0).toBe(true); + } + }); + + it("should contain a cordova specification that is a string", function() { + expect(window.device.cordova).toBeDefined(); + expect((new String(window.device.cordova)).length > 0).toBe(true); + }); +}); diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/file.tests.js b/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/file.tests.js index 2370fa5d..e46e51cb 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/file.tests.js +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/file.tests.js @@ -1,2833 +1,3427 @@ -/** - * Retrieves root file system entries once, so they don't have to be - * repeated for every test (file system shouldn't change during test run). - */ -var getFileSystemRoot = (function() { - - // private - var temp_root, persistent_root; - - var onError = function(error) { - console.log('unable to retrieve file system: ' + error.code); +// Used by tests, set in file.html +var root, temp_root, persistent_root; + +describe('File API', function() { + // HELPER FUNCTIONS + + // deletes specified file or directory + var deleteEntry = function(name, success, error) { + // deletes entry, if it exists + window.resolveLocalFileSystemURI(root.toURL() + '/' + name, + function(entry) { + if (entry.isDirectory === true) { + entry.removeRecursively(success, error); + } else { + entry.remove(success, error); + } + }, success); }; - - // one-time retrieval of the root file system entry - var init = function() { - window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, - function(fileSystem) { - persistent_root = fileSystem.root; - }, onError); - window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, - function(fileSystem) { - temp_root = fileSystem.root; - }, onError); + // deletes file, if it exists, then invokes callback + var deleteFile = function(fileName, callback) { + root.getFile(fileName, null, + // remove file system entry + function(entry) { + entry.remove(callback, function() { console.log('[ERROR] deleteFile cleanup method invoked fail callback.'); }); + }, + // doesn't exist + callback); }; - document.addEventListener("deviceready", init, true); - - // public function returns private root entry - return function() { - // When testing, it is a good idea to run the test suite once for each - // file system type. Just change the return value from this function. - //return temp_root; - return persistent_root; + // deletes and re-creates the specified file + var createFile = function(fileName, success, error) { + deleteEntry(fileName, function() { + root.getFile(fileName, {create: true}, success, error); + }, error); + }; + // deletes and re-creates the specified directory + var createDirectory = function(dirName, success, error) { + deleteEntry(dirName, function() { + root.getDirectory(dirName, {create: true}, success, error); + }, error); }; -}()); // execute immediately - -Tests.prototype.FileTests = function() { - module('FileError interface'); - test("FileError constants should be defined", function() { - expect(12); - equal(FileError.NOT_FOUND_ERR, 1, "FileError.NOT_FOUND_ERR should be defined"); - equal(FileError.SECURITY_ERR, 2, "FileError.SECURITY_ERR should be defined"); - equal(FileError.ABORT_ERR, 3, "FileError.ABORT should be defined"); - equal(FileError.NOT_READABLE_ERR, 4, "FileError.NOT_READABLE_ERR should be defined"); - equal(FileError.ENCODING_ERR, 5, "FileError.ENCODING_ERR should be defined"); - equal(FileError.NO_MODIFICATION_ALLOWED_ERR, 6, "FileError.NO_MODIFICATION_ALLOWED_ERR should be defined"); - equal(FileError.INVALID_STATE_ERR, 7, "FileError.INVALID_STATE_ERR should be defined"); - equal(FileError.SYNTAX_ERR, 8, "FileError.SYNTAX_ERR should be defined"); - equal(FileError.INVALID_MODIFICATION_ERR, 9, "FileError.INVALID_MODIFICATION_ERR should be defined"); - equal(FileError.QUOTA_EXCEEDED_ERR, 10, "FileError.QUOTA_EXCEEDED_ERR should be defined"); - equal(FileError.TYPE_MISMATCH_ERR, 11, "FileError.TYPE_MISMATCH_ERR should be defined"); - equal(FileError.PATH_EXISTS_ERR, 12, "FileError.PATH_EXISTS_ERR should be defined"); - }); - module('LocalFileSystem interface', { - // setup function will run before each test - setup: function() { - var that = this; - this.root = getFileSystemRoot(); - this.fail = function(error) { - console.log('file error: ' + error.code); - }; - this.unexpectedSuccess = function() { - console.log('!!! success function called when not expected !!!'); - }; - // deletes specified file or directory - this.deleteEntry = function(name, success, error) { - // deletes entry, if it exists - window.resolveLocalFileSystemURI(that.root.toURL() + '/' + name, - function(entry) { - console.log('Deleting: ' + entry.fullPath); - if (entry.isDirectory === true) { - entry.removeRecursively(success, error); - } - else { - entry.remove(success, error); - } - }, - // doesn't exist - success); - }; - // deletes and re-creates the specified file - this.createFile = function(fileName, success, error) { - that.deleteEntry(fileName, function() { - console.log('Creating file: ' + that.root.fullPath + '/' + fileName); - that.root.getFile(fileName, {create: true}, success, error); - }, error); - }; - // deletes and re-creates the specified directory - this.createDirectory = function(dirName, success, error) { - that.deleteEntry(dirName, function() { - console.log('Creating directory: ' + that.root.fullPath + '/' + dirName); - that.root.getDirectory(dirName, {create: true}, success, error); - }, error); - }; - } - }); - test("window.requestFileSystem function should be defined", function() { - expect(1); - ok(typeof window.requestFileSystem === 'function', "window.requestFileSystem should be a function."); - }); - test("window.resolveLocalFileSystemURI function should be defined", function() { - expect(1); - ok(typeof window.resolveLocalFileSystemURI === 'function', "window.resolveLocalFileSystemURI should be a function."); - }); - test("File system types should be defined", function() { - expect(2); - equal(LocalFileSystem.TEMPORARY, 0, "LocalFileSystem.TEMPORARY should be defined"); - equal(LocalFileSystem.PERSISTENT, 1, "LocalFileSystem.PERSISTENT should be defined"); - }); - test("retrieve PERSISTENT file system", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(4); - - var testPersistent = function(fileSystem) { - ok(typeof fileSystem !== 'undefined' && fileSystem !== null, "window.requestFileSystem should return an object."); - ok(typeof fileSystem.name !== 'undefined' && fileSystem.name !== null, "filesystem should include a 'name' property."); - equal(fileSystem.name, "persistent", "file system 'name' attribute should be set properly"); - ok(typeof fileSystem.root !== 'undefined' && fileSystem.root !== null, "filesystem should include a 'root' property."); - QUnit.start(); - }; - - // retrieve PERSISTENT file system - window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, testPersistent, - function(error) { - console.log('error retrieving file system: ' + error.code); - }); - }); - test("retrieve TEMPORARY file system", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(4); - - var testTemporary = function(fileSystem) { - ok(typeof fileSystem !== 'undefined' && fileSystem !== null, "window.requestFileSystem should return an object."); - ok(typeof fileSystem.name !== 'undefined' && fileSystem.name !== null, "filesystem should include a 'name' property."); - equal(fileSystem.name, "temporary", "file system 'name' attribute should be set properly"); - ok(typeof fileSystem.root !== 'undefined' && fileSystem.root !== null, "filesystem should include a 'root' property."); - QUnit.start(); - }; - - // Request the file system - window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, testTemporary, - function(error) { - console.log('error retrieving file system: ' + error.code); - }); - }); - test("request a file system that is too large", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var failFS = function(error) { - ok(error !== null, "error should not be null."); - equal(error.code, FileError.QUOTA_EXCEEDED_ERR, "Shoud receive error code FileError.QUOTA_EXCEEDED_ERR"); - QUnit.start(); - }; - - // Request the file system - window.requestFileSystem(LocalFileSystem.TEMPORARY, 1000000000000000, null, failFS); - }); - test("request a file system that does not exist", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var failFS = function(error) { - ok(typeof error !== 'undefined' && error !== null, "error should not be null."); - equal(error.code, FileError.SYNTAX_ERR, "Shoud receive error code FileError.SYNTAX_ERR"); - QUnit.start(); - }; - - // Request the file system - window.requestFileSystem(-1, 0, null, failFS); - }); - test("resolve valid file name", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var fileName = "resolve.file.uri", - that = this, - resolveCallback = function(entry) { - // lookup file system entry - window.resolveLocalFileSystemURI(entry.toURI(), testEntry, this.fail); - }, - testEntry = function(fileEntry) { - ok(typeof fileEntry !== 'undefined' && fileEntry !== null, "fileEntry should not be null."); - ok(fileEntry.name == fileName, "fileEntry.name should equal 'resolve.file.uri'"); - - // cleanup - that.deleteEntry(fileName); - QUnit.start(); - }; - - // create a new file entry - this.createFile(fileName, resolveCallback, this.fail); - }); - test("resolve valid file name with parameters", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var fileName = "resolve.file.uri.params", - that = this, - resolveCallback = function(entry) { - // lookup file system entry - window.resolveLocalFileSystemURI(entry.toURI() + "?1234567890", testEntry, this.fail); - }, - testEntry = function(fileEntry) { - ok(typeof fileEntry !== 'undefined' && fileEntry !== null, "fileEntry should not be null."); - ok(fileEntry.name == fileName, "fileEntry.name should equal 'resolve.file.uri.params'"); - - // cleanup - that.deleteEntry(fileName); - QUnit.start(); - }; - - // create a new file entry - this.createFile(fileName, resolveCallback, this.fail); - }); - test("resolve invalid file name", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var failURL = function(error) { - ok(typeof error !== 'undefined' && error !== null, "error should not be null."); - equal(error.code, FileError.NOT_FOUND_ERR, "Shoud receive error code FileError.NOT_FOUND_ERR"); - QUnit.start(); - }; - - // lookup file system entry - window.resolveLocalFileSystemURI("file:///this.is.not.a.valid.file.txt", null, failURL); - }); - test("resolve invalid URL", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var failURL = function(error) { - ok(typeof error !== 'undefined' && error !== null, "error should not be null."); - equal(error.code, FileError.ENCODING_ERR, "Shoud receive an error code FileError.ENCODING_ERR"); - QUnit.start(); - }; - - // lookup file system entry - window.resolveLocalFileSystemURI("/this.is.not.a.valid.url", null, failURL); - }); + var createFail = function(module) { + return jasmine.createSpy().andCallFake(function(err) { + console.log('[ERROR ' + module + '] ' + JSON.stringify(err)); + }); + }; - module('Metadata interface'); - test("Metadata constructor should exist", function() { - expect(2); - var metadata = new Metadata(); - ok(metadata !== null, "Metadata object should not be null."); - ok(typeof metadata.modificationTime !== 'undefined', "Metadata object should have a 'modificationTime' property."); - }); - module('Flags interface'); - test("Flags constructor should exist", function() { - expect(5); - var flags = new Flags(false, true); - ok(flags !== null, "Flags object should not be null."); - ok(typeof flags.create !== 'undefined' && flags.create !== null, "Flags object should have a 'create' property."); - equal(flags.create, false, "Flags.create should be set properly"); - ok(typeof flags.exclusive !== 'undefined' && flags.exclusive !== null, "Flags object should have an 'exclusive' property."); - equal(flags.exclusive, true, "flags.exclusive should be set properly"); - }); - module('FileSystem interface'); - test("FileSystem root should be a DirectoryEntry", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(15); - - var root = getFileSystemRoot(), - testFSRoot = function(entry) { - ok(typeof entry !== 'undefined' && entry !== null, "entry should be non-null"); - equal(entry.isFile, false, "entry.isFile should be false"); - equal(entry.isDirectory, true, "entry.isDirectory should be true"); - ok(typeof entry.name !== 'undefined' && entry.name !== null, "entry should include a 'name' property."); - ok(typeof entry.fullPath !== 'undefined' && entry.fullPath !== null, "entry should include a 'fullPath' property."); - ok(typeof entry.getMetadata === 'function', "entry object should have a 'getMetadata' function."); - ok(typeof entry.moveTo === 'function', "entry object should have a 'moveTo' function."); - ok(typeof entry.copyTo === 'function', "entry object should have a 'copyTo' function."); - ok(typeof entry.toURL === 'function', "entry object should have a 'toURL' function."); - ok(typeof entry.remove === 'function', "entry object should have a 'remove' function."); - ok(typeof entry.getParent === 'function', "entry object should have a 'getParent' function."); - ok(typeof entry.createReader === 'function', "entry object should have a 'createReader' function."); - ok(typeof entry.getFile === 'function', "entry object should have a 'getFile' function."); - ok(typeof entry.getDirectory === 'function', "entry object should have a 'getDirectory' function."); - ok(typeof entry.removeRecursively === 'function', "entry object should have a 'removeRecursively' function."); - QUnit.start(); - }; - - window.resolveLocalFileSystemURI(root.toURL(), testFSRoot, null); + var createWin = function(module) { + return jasmine.createSpy().andCallFake(function() { + console.log('[ERROR ' + module + '] Unexpected success callback'); + }); + }; - }); - module('DirectoryEntry interface', { - // setup function will run before each test - setup: function() { - this.root = getFileSystemRoot(); - this.fail = function(error) { - console.log('file error: ' + error.code); - }; - this.unexpectedSuccess = function() { - console.log('!!! success function called when not expected !!!'); - }; - } - }); - test("DirectoryEntry.getFile: get Entry for file that does not exist", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var fileName = "de.no.file", - filePath = this.root.fullPath + '/' + fileName, - that = this, - testFile = function(error) { - ok(typeof error !== 'undefined' && error !== null, "retrieving a file that does not exist is an error"); - equal(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR"); - - // cleanup - QUnit.start(); - }; - - // create:false, exclusive:false, file does not exist - this.root.getFile(fileName, {create:false}, null, testFile); - }); - test("DirectoryEntry.getFile: create new file", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(5); - - var fileName = "de.create.file", - filePath = this.root.fullPath + '/' + fileName, - that = this, - testFile = function(entry) { - ok(typeof entry !== 'undefined' && entry !== null, "file entry should not be null"); - equal(entry.isFile, true, "entry 'isFile' attribute should be true"); - equal(entry.isDirectory, false, "entry 'isDirectory' attribute should be false"); - equal(entry.name, fileName, "entry 'name' attribute should be set"); - equal(entry.fullPath, filePath, "entry 'fullPath' attribute should be set"); - - // cleanup - entry.remove(null, that.fail); - QUnit.start(); - }; - - // create:true, exclusive:false, file does not exist - this.root.getFile(fileName, {create: true}, testFile, this.fail); - }); - test("DirectoryEntry.getFile: create new file (exclusive)", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(5); - - var fileName = "de.create.exclusive.file", - filePath = this.root.fullPath + '/' + fileName, - that = this, - testFile = function(entry) { - ok(typeof entry !== 'undefined' && entry !== null, "file entry should not be null"); - equal(entry.isFile, true, "entry 'isFile' attribute should be true"); - equal(entry.isDirectory, false, "entry 'isDirectory' attribute should be false"); - equal(entry.name, fileName, "entry 'name' attribute should be set"); - equal(entry.fullPath, filePath, "entry 'fullPath' attribute should be set"); - - // cleanup - entry.remove(null, that.fail); - QUnit.start(); - }; - - // create:true, exclusive:true, file does not exist - this.root.getFile(fileName, {create: true, exclusive:true}, testFile, this.fail); - }); - test("DirectoryEntry.getFile: create file that already exists", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(5); - - var fileName = "de.create.existing.file", - filePath = this.root.fullPath + '/' + fileName, - that = this, - getFile = function(file) { - // create:true, exclusive:false, file exists - that.root.getFile(fileName, {create:true}, testFile, that.fail); - }, - testFile = function(entry) { - ok(typeof entry !== 'undefined' && entry !== null, "file entry should not be null"); - equal(entry.isFile, true, "entry 'isFile' attribute should be true"); - equal(entry.isDirectory, false, "entry 'isDirectory' attribute should be false"); - equal(entry.name, fileName, "entry 'name' attribute should be set"); - equal(entry.fullPath, filePath, "entry 'fullPath' attribute should be set"); - - // cleanup - entry.remove(null, that.fail); - QUnit.start(); - }; - - // create file to kick off test - this.root.getFile(fileName, {create:true}, getFile, this.fail); - }); - test("DirectoryEntry.getFile: create file that already exists (exclusive)", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var fileName = "de.create.exclusive.existing.file", - filePath = this.root.fullPath + '/' + fileName, - that = this, - existingFile, - getFile = function(file) { - existingFile = file; - // create:true, exclusive:true, file exists - that.root.getFile(fileName, {create:true, exclusive:true}, null, testFile); - }, - testFile = function(error) { - ok(typeof error !== 'undefined' && error !== null, "creating exclusive file that already exists is an error"); - equal(error.code, FileError.PATH_EXISTS_ERR, "error code should be FileError.PATH_EXISTS_ERR"); - - // cleanup - existingFile.remove(null, that.fail); - QUnit.start(); - }; - - // create file to kick off test - this.root.getFile(fileName, {create:true}, getFile, this.fail); - }); - test("DirectoryEntry.getFile: get Entry for existing file", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(5); - - var fileName = "de.get.file", - filePath = this.root.fullPath + '/' + fileName, - that = this, - getFile = function(file) { - // create:false, exclusive:false, file exists - that.root.getFile(fileName, {create:false}, testFile, that.fail); - }, - testFile = function(entry) { - ok(typeof entry !== 'undefined' && entry !== null, "file entry should not be null"); - equal(entry.isFile, true, "entry 'isFile' attribute should be true"); - equal(entry.isDirectory, false, "entry 'isDirectory' attribute should be false"); - equal(entry.name, fileName, "entry 'name' attribute should be set"); - equal(entry.fullPath, filePath, "entry 'fullPath' attribute should be set"); - - // cleanup - entry.remove(null, that.fail); - QUnit.start(); - }; - - // create file to kick off test - this.root.getFile(fileName, {create:true}, getFile, this.fail); - }); - test("DirectoryEntry.getFile: get FileEntry for invalid path", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var fileName = "de:invalid:path", - that = this, - testFile = function(error) { - ok(typeof error !== 'undefined' && error !== null, "retrieving a file using an invalid path is an error"); - equal(error.code, FileError.ENCODING_ERR, "error code should be FileError.ENCODING_ERR"); - - // cleanup - QUnit.start(); - }; - - // create:false, exclusive:false, invalid path - this.root.getFile(fileName, {create:false}, null, testFile); - }); - test("DirectoryEntry.getDirectory: get Entry for directory that does not exist", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var dirName = "de.no.dir", - dirPath = this.root.fullPath + '/' + dirName, - that = this, - testDir = function(error) { - ok(typeof error !== 'undefined' && error !== null, "retrieving a directory that does not exist is an error"); - equal(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR"); - - // cleanup - QUnit.start(); - }; + describe('FileError object', function() { + it("should define FileError constants", function() { + expect(FileError.NOT_FOUND_ERR).toBe(1); + expect(FileError.SECURITY_ERR).toBe(2); + expect(FileError.ABORT_ERR).toBe(3); + expect(FileError.NOT_READABLE_ERR).toBe(4); + expect(FileError.ENCODING_ERR).toBe(5); + expect(FileError.NO_MODIFICATION_ALLOWED_ERR).toBe(6); + expect(FileError.INVALID_STATE_ERR).toBe(7); + expect(FileError.SYNTAX_ERR).toBe(8); + expect(FileError.INVALID_MODIFICATION_ERR).toBe(9); + expect(FileError.QUOTA_EXCEEDED_ERR).toBe(10); + expect(FileError.TYPE_MISMATCH_ERR).toBe(11); + expect(FileError.PATH_EXISTS_ERR).toBe(12); + }); + }); + + describe('LocalFileSystem', function() { + + it("should define LocalFileSystem constants", function() { + expect(LocalFileSystem.TEMPORARY).toBe(0); + expect(LocalFileSystem.PERSISTENT).toBe(1); + }); + + describe('window.requestFileSystem', function() { + it("should be defined", function() { + expect(window.requestFileSystem).toBeDefined(); + }); + it("should be able to retrieve a PERSISTENT file system", function() { + var win = jasmine.createSpy().andCallFake(function(fileSystem) { + expect(fileSystem).toBeDefined(); + expect(fileSystem.name).toBeDefined(); + expect(fileSystem.name).toBe("persistent"); + expect(fileSystem.root).toBeDefined(); + }), + fail = createFail('window.requestFileSystem'); + + // retrieve PERSISTENT file system + runs(function() { + window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, win, fail); + }); + + waitsFor(function() { return win.wasCalled; }, "success callback never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(fail).not.toHaveBeenCalled(); + expect(win).toHaveBeenCalled(); + }); + }); + it("should be able to retrieve a TEMPORARY file system", function() { + var win = jasmine.createSpy().andCallFake(function(fileSystem) { + expect(fileSystem).toBeDefined(); + expect(fileSystem.name).toBeDefined(); + expect(fileSystem.name).toBe("temporary"); + expect(fileSystem.root).toBeDefined(); + }), + fail = createFail('window.requestFileSystem'); + + // Request the file system + runs(function() { + window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, win, fail); + }); + + waitsFor(function() { return win.wasCalled; }, "success callback never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(fail).not.toHaveBeenCalled(); + expect(win).toHaveBeenCalled(); + }); + }); + it("should error if you request a file system that is too large", function() { + var fail = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.QUOTA_EXCEEDED_ERR); + }), + win = createWin('window.requestFileSystem'); + + // Request the file system + runs(function() { + window.requestFileSystem(LocalFileSystem.TEMPORARY, 1000000000000000, win, fail); + }); + + waitsFor(function() { return fail.wasCalled; }, "error callback never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(win).not.toHaveBeenCalled(); + expect(fail).toHaveBeenCalled(); + }); + }); + it("should error out if you request a file system that does not exist", function() { + var fail = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.SYNTAX_ERR); + }), + win = createWin('window.requestFileSystem'); + + // Request the file system + runs(function() { + window.requestFileSystem(-1, 0, win, fail); + }); + + waitsFor(function() { return fail.wasCalled; }, "error callback never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(win).not.toHaveBeenCalled(); + expect(fail).toHaveBeenCalled(); + }); + }); + }); + + describe('window.resolveLocalFileSystemURI', function() { + it("should be defined", function() { + expect(window.resolveLocalFileSystemURI).toBeDefined(); + }); + it("should resolve a valid file name", function() { + var fileName = "resolve.file.uri", + win = jasmine.createSpy().andCallFake(function(fileEntry) { + expect(fileEntry).toBeDefined(); + expect(fileEntry.name).toBe(fileName); + + // cleanup + deleteEntry(fileName); + }), + fail = createFail('window.resolveLocalFileSystemURI'); + resolveCallback = jasmine.createSpy().andCallFake(function(entry) { + // lookup file system entry + runs(function() { + window.resolveLocalFileSystemURI(entry.toURL(), win, fail); + }); + + waitsFor(function() { return win.wasCalled; }, "resolveLocalFileSystemURI callback never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(win).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); + + // create a new file entry + runs(function() { + createFile(fileName, resolveCallback, fail); + }); + + waitsFor(function() { return resolveCallback.wasCalled; }, "createFile callback never called", Tests.TEST_TIMEOUT); + }); + it("resolve valid file name with parameters", function() { + var fileName = "resolve.file.uri.params", + win = jasmine.createSpy().andCallFake(function(fileEntry) { + expect(fileEntry).toBeDefined(); + expect(fileEntry.name).toBe(fileName); + + // cleanup + deleteEntry(fileName); + }), + fail = createFail('window.resolveLocalFileSystemURI'); + resolveCallback = jasmine.createSpy().andCallFake(function(entry) { + // lookup file system entry + runs(function() { + window.resolveLocalFileSystemURI(entry.toURL() + "?1234567890", win, fail); + }); + + waitsFor(function() { return win.wasCalled; }, "resolveLocalFileSystemURI callback never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(win).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); + + // create a new file entry + runs(function() { + createFile(fileName, resolveCallback, fail); + }); + + waitsFor(function() { return resolveCallback.wasCalled; }, "createFile callback never called", Tests.TEST_TIMEOUT); + }); + it("should error out when resolving invalid file name", function() { + var fail = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.NOT_FOUND_ERR); + }), + win = createWin('window.resolveLocalFileSystemURI'); - // create:false, exclusive:false, directory does not exist - this.root.getDirectory(dirName, {create:false}, null, testDir); - }); - test("DirectoryEntry.getDirectory: create new dir with space then resolveFileSystemURL", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(5); - - var dirName = "de create dir", - dirPath = this.root.fullPath + '/' + dirName, - that = this, - getDir = function(dirEntry) { + // lookup file system entry + runs(function() { + window.resolveLocalFileSystemURI("file:///this.is.not.a.valid.file.txt", win, fail); + }); + + waitsFor(function() { return fail.wasCalled; }, "error callback never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(fail).toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + }); + }); + it("resolve invalid URL", function() { + var fail = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.ENCODING_ERR); + }), + win = createWin('window.resolveLocalFileSystemURI'); + + // lookup file system entry + runs(function() { + window.resolveLocalFileSystemURI("/this.is.not.a.valid.url", win, fail); + }); + + waitsFor(function() { return fail.wasCalled; }, "error callback never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(fail).toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + }); + }); + }); + }); + + describe('Metadata interface', function() { + it("should exist and have the right properties", function() { + var metadata = new Metadata(); + expect(metadata).toBeDefined(); + expect(metadata.modificationTime).toBeDefined(); + }); + }); + + describe('Flags interface', function() { + it("should exist and have the right properties", function() { + var flags = new Flags(false, true); + expect(flags).toBeDefined(); + expect(flags.create).toBeDefined(); + expect(flags.create).toBe(false); + expect(flags.exclusive).toBeDefined(); + expect(flags.exclusive).toBe(true); + }); + }); + + describe('FileSystem interface', function() { + it("should have a root that is a DirectoryEntry", function() { + var win = jasmine.createSpy().andCallFake(function(entry) { + expect(entry).toBeDefined(); + expect(entry.isFile).toBe(false); + expect(entry.isDirectory).toBe(true); + expect(entry.name).toBeDefined(); + expect(entry.fullPath).toBeDefined(); + expect(entry.getMetadata).toBeDefined(); + expect(entry.moveTo).toBeDefined(); + expect(entry.copyTo).toBeDefined(); + expect(entry.toURL).toBeDefined(); + expect(entry.remove).toBeDefined(); + expect(entry.getParent).toBeDefined(); + expect(entry.createReader).toBeDefined(); + expect(entry.getFile).toBeDefined(); + expect(entry.getDirectory).toBeDefined(); + expect(entry.removeRecursively).toBeDefined(); + }), + fail = createFail('FileSystem'); + + runs(function() { + window.resolveLocalFileSystemURI(root.toURL(), win, fail); + }); + + waitsFor(function() { return win.wasCalled; }, "success callback never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(fail).not.toHaveBeenCalled(); + expect(win).toHaveBeenCalled(); + }); + }); + }); + + describe('DirectoryEntry', function() { + it("getFile: get Entry for file that does not exist", function() { + var fileName = "de.no.file", + filePath = root.fullPath + '/' + fileName, + fail = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.NOT_FOUND_ERR); + }), + win = createWin('DirectoryEntry'); + + // create:false, exclusive:false, file does not exist + runs(function() { + root.getFile(fileName, {create:false}, win, fail); + }); + + waitsFor(function() { return fail.wasCalled; }, "error callback never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(fail).toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + }); + }); + it("etFile: create new file", function() { + var fileName = "de.create.file", + filePath = root.fullPath + '/' + fileName, + win = jasmine.createSpy().andCallFake(function(entry) { + expect(entry).toBeDefined(); + expect(entry.isFile).toBe(true); + expect(entry.isDirectory).toBe(false); + expect(entry.name).toBe(fileName); + expect(entry.fullPath).toBe(filePath); + // cleanup + entry.remove(null, null); + }), + fail = createFail('DirectoryEntry'); + + // create:true, exclusive:false, file does not exist + runs(function() { + root.getFile(fileName, {create: true}, win, fail); + }); + + waitsFor(function() { return win.wasCalled; }, "success callback never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(win).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("getFile: create new file (exclusive)", function() { + var fileName = "de.create.exclusive.file", + filePath = root.fullPath + '/' + fileName, + win = jasmine.createSpy().andCallFake(function(entry) { + expect(entry).toBeDefined(); + expect(entry.isFile).toBe(true); + expect(entry.isDirectory).toBe(false); + expect(entry.name).toBe(fileName); + expect(entry.fullPath).toBe(filePath); + + // cleanup + entry.remove(null, null); + }), + fail = createFail('DirectoryEntry'); + + // create:true, exclusive:true, file does not exist + runs(function() { + root.getFile(fileName, {create: true, exclusive:true}, win, fail); + }); + + waitsFor(function() { return win.wasCalled; }, "success callback never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(win).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("getFile: create file that already exists", function() { + var fileName = "de.create.existing.file", + filePath = root.fullPath + '/' + fileName, + getFile = jasmine.createSpy().andCallFake(function(file) { + // create:true, exclusive:false, file exists + runs(function() { + root.getFile(fileName, {create:true}, win, fail); + }); + + waitsFor(function() { return win.wasCalled; }, "win was never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(win).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }), + fail = createFail('DirectoryEntry'), + win = jasmine.createSpy().andCallFake(function(entry) { + expect(entry).toBeDefined(); + expect(entry.isFile).toBe(true); + expect(entry.isDirectory).toBe(false); + expect(entry.name).toBe(fileName); + expect(entry.fullPath).toBe(filePath); + + // cleanup + entry.remove(null, fail); + }); + // create file to kick off it + runs(function() { + root.getFile(fileName, {create:true}, getFile, fail); + }); + + waitsFor(function() { return getFile.wasCalled; }, "getFile was never called", Tests.TEST_TIMEOUT); + }); + it("getFile: create file that already exists (exclusive)", function() { + var fileName = "de.create.exclusive.existing.file", + filePath = root.fullPath + '/' + fileName, + existingFile, + getFile = jasmine.createSpy().andCallFake(function(file) { + existingFile = file; + // create:true, exclusive:true, file exists + runs(function() { + root.getFile(fileName, {create:true, exclusive:true}, win, fail); + }); + + waitsFor(function() { return fail.wasCalled; }, "fail never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(fail).toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + }); + }), + fail = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.PATH_EXISTS_ERR); + + // cleanup + existingFile.remove(null, fail); + }), + win = createWin('DirectoryEntry'); + + // create file to kick off it + runs(function() { + root.getFile(fileName, {create:true}, getFile, fail); + }); + + waitsFor(function() { return getFile.wasCalled; }, "getFile never called", Tests.TEST_TIMEOUT); + }); + it("getFile: get Entry for existing file", function() { + var fileName = "de.get.file", + filePath = root.fullPath + '/' + fileName, + win = jasmine.createSpy().andCallFake(function(entry) { + expect(entry).toBeDefined(); + expect(entry.isFile).toBe(true); + expect(entry.isDirectory).toBe(false); + expect(entry.name).toBe(fileName); + expect(entry.fullPath).toBe(filePath); - var dirURL = dirEntry.toURL(); - // now encode URL and try to resolve - window.resolveLocalFileSystemURI(dirURL, testDirFromURL, that.fail); + entry.remove(null, fail); //clean up + }), + fail = createFail('DirectoryEntry'), + getFile = jasmine.createSpy().andCallFake(function(file) { + // create:false, exclusive:false, file exists + runs(function() { + root.getFile(fileName, {create:false}, win, fail); + }); + + waitsFor(function() { return win.wasCalled; }, "getFile success callback", Tests.TEST_TIMEOUT); + + runs(function() { + expect(win).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); - }, - testDirFromURL = function(directory) { - ok(typeof directory !== 'undefined' && directory !== null, "directory entry should not be null"); - equal(directory.isFile, false, "directory 'isFile' attribute should be false"); - equal(directory.isDirectory, true, "directory 'isDirectory' attribute should be true"); - equal(directory.name, dirName, "directory 'name' attribute should be set"); - equal(directory.fullPath, dirPath, "directory 'fullPath' attribute should be set"); + // create file to kick off it + runs(function() { + root.getFile(fileName, {create:true}, getFile, fail); + }); + + waitsFor(function() { return getFile.wasCalled; }, "file creation", Tests.TEST_TIMEOUT); + }); + it("DirectoryEntry.getFile: get FileEntry for invalid path", function() { + var fileName = "de:invalid:path", + fail = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.ENCODING_ERR); + }), + win = createWin('DirectoryEntry'); - // cleanup - directory.remove(null, that.fail); - QUnit.start(); - }; - - // create:true, exclusive:false, directory does not exist - this.root.getDirectory(dirName, {create: true}, getDir, this.fail); - }); - test("DirectoryEntry.getDirectory: create new dir with space resolveFileSystemURL with encoded URL", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(5); - - var dirName = "de create dir", - dirPath = this.root.fullPath + '/' + dirName, - that = this, - getDir = function(dirEntry) { + // create:false, exclusive:false, invalid path + runs(function() { + root.getFile(fileName, {create:false}, win, fail); + }); + + waitsFor(function() { return fail.wasCalled; }, "fail never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(fail).toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + }); + + }); + it("DirectoryEntry.getDirectory: get Entry for directory that does not exist", function() { + var dirName = "de.no.dir", + dirPath = root.fullPath + '/' + dirName, + fail = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.NOT_FOUND_ERR); + }), + win = createWin('DirectoryEntry'); + + // create:false, exclusive:false, directory does not exist + runs(function() { + root.getDirectory(dirName, {create:false}, win, fail); + }); + + waitsFor(function() { return fail.wasCalled; }, "fail never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(fail).toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + }); + }); + it("DirectoryEntry.getDirectory: create new dir with space then resolveFileSystemURL", function() { + var dirName = "de create dir", + dirPath = root.fullPath + '/' + dirName, + getDir = jasmine.createSpy().andCallFake(function(dirEntry) { + var dirURL = dirEntry.toURL(); + // now encode URL and try to resolve + runs(function() { + window.resolveLocalFileSystemURI(dirURL, win, fail); + }); + + waitsFor(function() { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(win).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + + }), win = jasmine.createSpy().andCallFake(function(directory) { + expect(directory).toBeDefined(); + expect(directory.isFile).toBe(false); + expect(directory.isDirectory).toBe(true); + expect(directory.name).toBe(dirName); + expect(directory.fullPath).toBe(dirPath); + + // cleanup + directory.remove(null, fail); + }), + fail = createFail('DirectoryEntry'); - var dirURL = dirEntry.toURL(); - // now encode URL and try to resolve - window.resolveLocalFileSystemURI(encodeURI(dirURL), testDirFromURL, that.fail); + // create:true, exclusive:false, directory does not exist + runs(function() { + root.getDirectory(dirName, {create: true}, getDir, fail); + }); + + waitsFor(function() { return getDir.wasCalled; }, "getDir never called", Tests.TEST_TIMEOUT); + }); + it("DirectoryEntry.getDirectory: create new dir with space resolveFileSystemURL with encoded URL", function() { + var dirName = "de create dir", + dirPath = root.fullPath + '/' + dirName, + getDir = jasmine.createSpy().andCallFake(function(dirEntry) { + var dirURL = dirEntry.toURL(); + // now encode URL and try to resolve + runs(function() { + window.resolveLocalFileSystemURI(encodeURI(dirURL), win, fail); + }); + + waitsFor(function() { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(win).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }), + win = jasmine.createSpy().andCallFake(function(directory) { + expect(directory).toBeDefined(); + expect(directory.isFile).toBe(false); + expect(directory.isDirectory).toBe(true); + expect(directory.name).toBe(dirName); + expect(directory.fullPath).toBe(dirPath); + // cleanup + directory.remove(null, fail); + }), + fail = createFail('DirectoryEntry'); - }, - testDirFromURL = function(directory) { - ok(typeof directory !== 'undefined' && directory !== null, "directory entry should not be null"); - equal(directory.isFile, false, "directory 'isFile' attribute should be false"); - equal(directory.isDirectory, true, "directory 'isDirectory' attribute should be true"); - equal(directory.name, dirName, "directory 'name' attribute should be set"); - equal(directory.fullPath, dirPath, "directory 'fullPath' attribute should be set"); - - // cleanup - directory.remove(null, that.fail); - QUnit.start(); - }; - - // create:true, exclusive:false, directory does not exist - this.root.getDirectory(dirName, {create: true}, getDir, this.fail); - }); - - test("DirectoryEntry.getDirectory: create new directory", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(5); - - var dirName = "de.create.dir", - dirPath = this.root.fullPath + '/' + dirName, - that = this, - testDir = function(directory) { - ok(typeof directory !== 'undefined' && directory !== null, "directory entry should not be null"); - equal(directory.isFile, false, "directory 'isFile' attribute should be false"); - equal(directory.isDirectory, true, "directory 'isDirectory' attribute should be true"); - equal(directory.name, dirName, "directory 'name' attribute should be set"); - equal(directory.fullPath, dirPath, "directory 'fullPath' attribute should be set"); - - // cleanup - directory.remove(null, that.fail); - QUnit.start(); - }; - - // create:true, exclusive:false, directory does not exist - this.root.getDirectory(dirName, {create: true}, testDir, this.fail); - }); - - test("DirectoryEntry.getDirectory: create new directory (exclusive)", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(5); - - var dirName = "de.create.exclusive.dir", - dirPath = this.root.fullPath + '/' + dirName, - that = this, - testDir = function(directory) { - ok(typeof directory !== 'undefined' && directory !== null, "directory entry should not be null"); - equal(directory.isFile, false, "directory 'isFile' attribute should be false"); - equal(directory.isDirectory, true, "directory 'isDirectory' attribute should be true"); - equal(directory.name, dirName, "directory 'name' attribute should be set"); - equal(directory.fullPath, dirPath, "directory 'fullPath' attribute should be set"); - - // cleanup - directory.remove(null, that.fail); - QUnit.start(); - }; - - // create:true, exclusive:true, directory does not exist - this.root.getDirectory(dirName, {create: true, exclusive:true}, testDir, this.fail); - }); - test("DirectoryEntry.getDirectory: create directory that already exists", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(5); - - var dirName = "de.create.existing.dir", - dirPath = this.root.fullPath + '/' + dirName, - that = this, - getDir = function(directory) { - // create:true, exclusive:false, directory exists - that.root.getDirectory(dirName, {create:true}, testDir, that.fail); - }, - testDir = function(directory) { - ok(typeof directory !== 'undefined' && directory !== null, "directory entry should not be null"); - equal(directory.isFile, false, "directory 'isFile' attribute should be false"); - equal(directory.isDirectory, true, "directory 'isDirectory' attribute should be true"); - equal(directory.name, dirName, "directory 'name' attribute should be set"); - equal(directory.fullPath, dirPath, "directory 'fullPath' attribute should be set"); - - // cleanup - directory.remove(null, that.fail); - QUnit.start(); - }; - - // create directory to kick off test - this.root.getDirectory(dirName, {create:true}, getDir, this.fail); - }); - test("DirectoryEntry.getDirectory: create directory that already exists (exclusive)", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var dirName = "de.create.exclusive.existing.dir", - dirPath = this.root.fullPath + '/' + dirName, - that = this, - existingDir, - getDir = function(directory) { - existingDir = directory; - // create:true, exclusive:true, directory exists - that.root.getDirectory(dirName, {create:true, exclusive:true}, null, testDir); - }, - testDir = function(error) { - ok(typeof error !== 'undefined' && error !== null, "creating exclusive directory that already exists is an error"); - equal(error.code, FileError.PATH_EXISTS_ERR, "error code should be FileError.PATH_EXISTS_ERR"); - - // cleanup - existingDir.remove(null, that.fail); - QUnit.start(); - }; - - // create directory to kick off test - this.root.getDirectory(dirName, {create:true}, getDir, this.fail); - }); - test("DirectoryEntry.getDirectory: get Entry for existing directory", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(5); - - var dirName = "de.get.dir", - dirPath = this.root.fullPath + '/' + dirName, - that = this, - getDir = function(directory) { - // create:false, exclusive:false, directory exists - that.root.getDirectory(dirName, {create:false}, testDir, that.fail); - }, - testDir = function(directory) { - ok(typeof directory !== 'undefined' && directory !== null, "directory entry should not be null"); - equal(directory.isFile, false, "directory 'isFile' attribute should be false"); - equal(directory.isDirectory, true, "directory 'isDirectory' attribute should be true"); - equal(directory.name, dirName, "directory 'name' attribute should be set"); - equal(directory.fullPath, dirPath, "directory 'fullPath' attribute should be set"); - - // cleanup - directory.remove(null, that.fail); - QUnit.start(); - }; - - // create directory to kick off test - this.root.getDirectory(dirName, {create:true}, getDir, this.fail); - }); - test("DirectoryEntry.getDirectory: get DirectoryEntry for invalid path", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var dirName = "de:invalid:path", - that = this, - testDir = function(error) { - ok(typeof error !== 'undefined' && error !== null, "retrieving a directory using an invalid path is an error"); - equal(error.code, FileError.ENCODING_ERR, "error code should be FileError.ENCODING_ERR"); - - // cleanup - QUnit.start(); - }; - - // create:false, exclusive:false, invalid path - this.root.getDirectory(dirName, {create:false}, null, testDir); - }); - test("DirectoryEntry.getDirectory: get DirectoryEntry for existing file", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var fileName = "de.existing.file", - existingFile, - filePath = this.root.fullPath + '/' + fileName, - that = this, - getDir = function(file) { - existingFile = file; - // create:false, exclusive:false, existing file - that.root.getDirectory(fileName, {create:false}, null, testDir); - }, - testDir = function(error) { - ok(typeof error !== 'undefined' && error !== null, "retrieving directory for existing file is an error"); - equal(error.code, FileError.TYPE_MISMATCH_ERR, "error code should be FileError.TYPE_MISMATCH_ERR"); - - // cleanup - existingFile.remove(null, that.fail); - QUnit.start(); - }; - - // create file to kick off test - this.root.getFile(fileName, {create:true}, getDir, this.fail); - }); - test("DirectoryEntry.getFile: get FileEntry for existing directory", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var dirName = "de.existing.dir", - existingDir, - dirPath = this.root.fullPath + '/' + dirName, - that = this, - getFile = function(directory) { - existingDir = directory; - // create:false, exclusive:false, existing directory - that.root.getFile(dirName, {create:false}, null, testFile); - }, - testFile = function(error) { - ok(typeof error !== 'undefined' && error !== null, "retrieving file for existing directory is an error"); - equal(error.code, FileError.TYPE_MISMATCH_ERR, "error code should be FileError.TYPE_MISMATCH_ERR"); - - // cleanup - existingDir.remove(null, that.fail); - QUnit.start(); - }; - - // create directory to kick off test - this.root.getDirectory(dirName, {create:true}, getFile, this.fail); - }); - test("DirectoryEntry.removeRecursively on directory", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var dirName = "de.removeRecursively", - subDirName = "dir", - dirPath = this.root.fullPath + '/' + dirName, - //subDirPath = this.root.fullPath + '/' + subDirName, - subDirPath = dirPath + '/' + subDirName, - that = this, - entryCallback = function(entry) { - // delete directory - var deleteDirectory = function(directory) { - entry.removeRecursively(testRemove, that.fail); - }; - // create a sub-directory within directory - entry.getDirectory(subDirName, {create: true}, deleteDirectory, that.fail); - }, - testRemove = function() { - // test that removed directory no longer exists - that.root.getDirectory(dirName, {create:false}, null, testDirExists); - }, - testDirExists = function(error){ - ok(typeof error !== 'undefined' && error !== null, "removed directory should not exist"); - equal(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR"); - QUnit.start(); - }; - - // create a new directory entry to kick off test - this.root.getDirectory(dirName, {create:true}, entryCallback, this.fail); - }); - test("DirectoryEntry.createReader: create reader on existing directory", function() { - expect(2); - - // create reader for root directory - var reader = this.root.createReader(); - ok(typeof reader !== 'undefined' && reader !== null, "reader object should not be null"); - ok(typeof reader.readEntries === 'function', "reader object should have a 'readEntries' method"); - }); - module('DirectoryReader interface', { - // setup function will run before each test - setup: function() { - this.root = getFileSystemRoot(); - this.fail = function(error) { - console.log('file error: ' + error.code); - }; - } - }); - test("DirectoryReader.readEntries: read contents of existing directory", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(4); - - var reader, - testEntries = function(entries) { - ok(typeof entries !== 'undefined' && entries !== null, "directory entries should not be null"); - ok(entries.constructor === Array, "readEntries should return an array of entries"); - QUnit.start(); - }; + // create:true, exclusive:false, directory does not exist + runs(function() { + root.getDirectory(dirName, {create: true}, getDir, fail); + }); + + waitsFor(function() { return getDir.wasCalled; }, "getDir never called", Tests.TEST_TIMEOUT); + }); + + it("DirectoryEntry.getDirectory: create new directory", function() { + var dirName = "de.create.dir", + dirPath = root.fullPath + '/' + dirName, + win = jasmine.createSpy().andCallFake(function(directory) { + expect(directory).toBeDefined(); + expect(directory.isFile).toBe(false); + expect(directory.isDirectory).toBe(true); + expect(directory.name).toBe(dirName); + expect(directory.fullPath).toBe(dirPath); + + // cleanup + directory.remove(null, fail); + }), + fail = createFail('DirectoryEntry'); + + // create:true, exclusive:false, directory does not exist + runs(function() { + root.getDirectory(dirName, {create: true}, win, fail); + }); + + waitsFor(function() { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(win).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); + + it("DirectoryEntry.getDirectory: create new directory (exclusive)", function() { + var dirName = "de.create.exclusive.dir", + dirPath = root.fullPath + '/' + dirName, + win = jasmine.createSpy().andCallFake(function(directory) { + expect(directory).toBeDefined(); + expect(directory.isFile).toBe(false); + expect(directory.isDirectory).toBe(true); + expect(directory.name).toBe(dirName); + expect(directory.fullPath).toBe(dirPath); + + // cleanup + directory.remove(null, fail); + }), + fail = createFail('DirectoryEntry'); + // create:true, exclusive:true, directory does not exist + runs(function() { + root.getDirectory(dirName, {create: true, exclusive:true}, win, fail); + }); + + waitsFor(function() { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(win).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("DirectoryEntry.getDirectory: create directory that already exists", function() { + var dirName = "de.create.existing.dir", + dirPath = root.fullPath + '/' + dirName, + getDir = jasmine.createSpy().andCallFake(function(directory) { + // create:true, exclusive:false, directory exists + runs(function() { + root.getDirectory(dirName, {create:true}, win, fail); + }); + + waitsFor(function() { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(win).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }), + win = jasmine.createSpy().andCallFake(function(directory) { + expect(directory).toBeDefined(); + expect(directory.isFile).toBe(false); + expect(directory.isDirectory).toBe(true); + expect(directory.name).toBe(dirName); + expect(directory.fullPath).toBe(dirPath); + + // cleanup + directory.remove(null, fail); + }), + fail = createFail('DirectoryEntry'); + + // create directory to kick off it + runs(function() { + root.getDirectory(dirName, {create:true}, getDir, this.fail); + }); + + waitsFor(function() { return getDir.wasCalled; }, "getDir never called", Tests.TEST_TIMEOUT); + }); + it("DirectoryEntry.getDirectory: create directory that already exists (exclusive)", function() { + var dirName = "de.create.exclusive.existing.dir", + dirPath = root.fullPath + '/' + dirName, + existingDir, + getDir = jasmine.createSpy().andCallFake(function(directory) { + existingDir = directory; + // create:true, exclusive:true, directory exists + runs(function() { + root.getDirectory(dirName, {create:true, exclusive:true}, win, fail); + }); + + waitsFor(function() { return fail.wasCalled; }, "fail never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(fail).toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + }); + }), + fail = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.PATH_EXISTS_ERR); + + // cleanup + existingDir.remove(null, fail); + }), + win = createWin('DirectoryEntry'); + + // create directory to kick off it + runs(function() { + root.getDirectory(dirName, {create:true}, getDir, fail); + }); + + waitsFor(function() { return getDir.wasCalled; }, "getDir never called", Tests.TEST_TIMEOUT); + }); + it("DirectoryEntry.getDirectory: get Entry for existing directory", function() { + var dirName = "de.get.dir", + dirPath = root.fullPath + '/' + dirName, + getDir = jasmine.createSpy().andCallFake(function(directory) { + // create:false, exclusive:false, directory exists + runs(function() { + root.getDirectory(dirName, {create:false}, win, fail); + }); + + waitsFor(function() { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(win).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }), + win = jasmine.createSpy().andCallFake(function(directory) { + expect(directory).toBeDefined(); + expect(directory.isFile).toBe(false); + expect(directory.isDirectory).toBe(true); + expect(directory.name).toBe(dirName); + + expect(directory.fullPath).toBe(dirPath); + + // cleanup + directory.remove(null, fail); + }), + fail = createFail('DirectoryEntry'); + + // create directory to kick off it + root.getDirectory(dirName, {create:true}, getDir, fail); + }); + it("DirectoryEntry.getDirectory: get DirectoryEntry for invalid path", function() { + var dirName = "de:invalid:path", + fail = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.ENCODING_ERR); + }), + win = createWin('DirectoryEntry'); + + // create:false, exclusive:false, invalid path + runs(function() { + root.getDirectory(dirName, {create:false}, win, fail); + }); + + waitsFor(function() { return fail.wasCalled; }, "fail never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(fail).toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + }); + }); + it("DirectoryEntry.getDirectory: get DirectoryEntry for existing file", function() { + var fileName = "de.existing.file", + existingFile, + filePath = root.fullPath + '/' + fileName, + getDir = jasmine.createSpy().andCallFake(function(file) { + existingFile = file; + // create:false, exclusive:false, existing file + runs(function() { + root.getDirectory(fileName, {create:false}, win, fail); + }); + + waitsFor(function() { return fail.wasCalled; }, "fail never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(fail).toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + }); + }), + fail = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.TYPE_MISMATCH_ERR); + + // cleanup + existingFile.remove(null, null); + }), + win = createWin('DirectoryEntry'); + + // create file to kick off it + runs(function() { + root.getFile(fileName, {create:true}, getDir, fail); + }); + + waitsFor(function() { return getDir.wasCalled; }, "getDir was called", Tests.TEST_TIMEOUT); + }); + it("DirectoryEntry.getFile: get FileEntry for existing directory", function() { + var dirName = "de.existing.dir", + existingDir, + dirPath = root.fullPath + '/' + dirName, + getFile = jasmine.createSpy().andCallFake(function(directory) { + existingDir = directory; + // create:false, exclusive:false, existing directory + runs(function() { + root.getFile(dirName, {create:false}, win, fail); + }); + + waitsFor(function() { return fail.wasCalled; }, "fail never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(fail).toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + }); + }), + fail = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.TYPE_MISMATCH_ERR); + + // cleanup + existingDir.remove(null, null); + }), + win = createWin('DirectoryEntry'); + + // create directory to kick off it + runs(function() { + root.getDirectory(dirName, {create:true}, getFile, fail); + }); + + waitsFor(function() { return getFile.wasCalled; }, "getFile never called", Tests.TEST_TIMEOUT); + }); + it("DirectoryEntry.removeRecursively on directory", function() { + var dirName = "de.removeRecursively", + subDirName = "dir", + dirPath = root.fullPath + '/' + dirName, + //subDirPath = this.root.fullPath + '/' + subDirName, + subDirPath = dirPath + '/' + subDirName, + entryCallback = jasmine.createSpy().andCallFake(function(entry) { + // delete directory + var deleteDirectory = jasmine.createSpy().andCallFake(function(directory) { + runs(function() { + entry.removeRecursively(remove, fail); + }); + + waitsFor(function() { return remove.wasCalled; }, "remove never called", Tests.TEST_TIMEOUT); + }); + // create a sub-directory within directory + runs(function() { + entry.getDirectory(subDirName, {create: true}, deleteDirectory, fail); + }); + + waitsFor(function() { return deleteDirectory.wasCalled; }, "deleteDirectory never called", Tests.TEST_TIMEOUT); + }), + remove = jasmine.createSpy().andCallFake(function() { + // it that removed directory no longer exists + runs(function() { + root.getDirectory(dirName, {create:false}, win, dirExists); + }); + + waitsFor(function() { return dirExists.wasCalled; }, "dirExists never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(dirExists).toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + }); + }), + dirExists = jasmine.createSpy().andCallFake(function(error){ + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.NOT_FOUND_ERR); + }), + fail = createFail('DirectoryEntry'), + win = createWin('DirectoryEntry'); + + // create a new directory entry to kick off it + runs(function() { + root.getDirectory(dirName, {create:true}, entryCallback, fail); + }); + + waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT); + }); + it("createReader: create reader on existing directory", function() { + // create reader for root directory + var reader = root.createReader(); + expect(reader).toBeDefined(); + expect(typeof reader.readEntries).toBe('function'); + }); + it("removeRecursively on root file system", function() { + var remove = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.NO_MODIFICATION_ALLOWED_ERR); + }), + win = createWin('DirectoryEntry'); + + // remove root file system + runs(function() { + root.removeRecursively(win, remove); + }); + + waitsFor(function() { return remove.wasCalled; }, "remove never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(win).not.toHaveBeenCalled(); + expect(remove).toHaveBeenCalled(); + }); + }); + }); + + describe('DirectoryReader interface', function() { + describe("readEntries", function() { + it("should read contents of existing directory", function() { + var reader, + win = jasmine.createSpy().andCallFake(function(entries) { + expect(entries).toBeDefined(); + expect(entries instanceof Array).toBe(true); + }), + fail = createFail('DirectoryReader'); - // create reader for root directory - reader = this.root.createReader(); - ok(typeof reader !== 'undefined' && reader !== null, "reader object should not be null"); - ok(typeof reader.readEntries === 'function', "reader object should have a 'readEntries' method"); - - // read entries - reader.readEntries(testEntries, this.fail); - }); - test("DirectoryReader.readEntries: read contents of directory that has been removed", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(4); - - var dirName = "de.createReader.notfound", - dirPath = this.root.fullPath + '/' + dirName, - that = this, - entryCallback = function(directory) { + // create reader for root directory + reader = root.createReader(); // read entries - var readEntries = function() { - var reader = directory.createReader(); - reader.readEntries(null, testReader); - }; - // delete directory - directory.removeRecursively(readEntries, that.fail); - }, - testReader = function(error) { - var testDirectoryExists = function(error) { - ok(typeof error !== 'undefined' && error !== null, "reading entries on a directory that does not exist is an error") - equal(error.code, FileError.NOT_FOUND_ERR, "removed directory should not exist"); - QUnit.start(); - }; - ok(typeof error !== 'undefined' && error !== null, "reading entries on a directory that does not exist is an error") - equal(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR"); - that.root.getDirectory(dirName, {create:false}, null, testDirectoryExists); - }; + runs(function() { + reader.readEntries(win, fail); + }); + + waitsFor(function() { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(win).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("should read contents of directory that has been removed", function() { + var dirName = "de.createReader.notfound", + dirPath = root.fullPath + '/' + dirName, + entryCallback = jasmine.createSpy().andCallFake(function(directory) { + // read entries + var readEntries = jasmine.createSpy().andCallFake(function() { + var reader = directory.createReader(); + + runs(function() { + reader.readEntries(win, itReader); + }); + + waitsFor(function() { return itReader.wasCalled; }, "itReader never called", Tests.TEST_TIMEOUT); + }); + // delete directory + runs(function() { + directory.removeRecursively(readEntries, fail); + }); + + waitsFor(function() { return readEntries.wasCalled; }, "readEntries never called", Tests.TEST_TIMEOUT); + }), + itReader = jasmine.createSpy().andCallFake(function(error) { + var itDirectoryExists = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.NOT_FOUND_ERR); + }); + + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.NOT_FOUND_ERR); + + runs(function() { + root.getDirectory(dirName, {create:false}, win, itDirectoryExists); + }); + + waitsFor(function() { return itDirectoryExists.wasCalled; }, "itDirectoryExists never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(itDirectoryExists).toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + }); + }), + fail = createFail('DirectoryReader'), + win = createWin('DirectoryReader'); + + // create a new directory entry to kick off it + runs(function() { + root.getDirectory(dirName, {create:true}, entryCallback, fail); + }); + + waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT); + }); + }); + }); + + describe('File', function() { + it("constructor should be defined", function() { + expect(File).toBeDefined(); + expect(typeof File).toBe('function'); + }); + it("should be define File attributes", function() { + var file = new File(); + expect(file.name).toBeDefined(); + expect(file.fullPath).toBeDefined(); + expect(file.type).toBeDefined(); + expect(file.lastModifiedDate).toBeDefined(); + expect(file.size).toBeDefined(); + }); + }); + + describe('FileEntry', function() { + it("should be define FileEntry methods", function() { + var fileName = "fe.methods", + itFileEntry = jasmine.createSpy().andCallFake(function(fileEntry) { + expect(fileEntry).toBeDefined(); + expect(typeof fileEntry.createWriter).toBe('function'); + expect(typeof fileEntry.file).toBe('function'); + + // cleanup + fileEntry.remove(null, fail); + }), + fail = createFail('FileEntry'); + + // create a new file entry to kick off it + runs(function() { + root.getFile(fileName, {create:true}, itFileEntry, fail); + }); + + waitsFor(function() { return itFileEntry.wasCalled; }, "itFileEntry never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(itFileEntry).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("createWriter should return a FileWriter object", function() { + var fileName = "fe.createWriter", + itFile, + entryCallback = jasmine.createSpy().andCallFake(function(fileEntry) { + itFile = fileEntry; + + runs(function() { + fileEntry.createWriter(itWriter, fail); + }); + + waitsFor(function() { return itWriter.wasCalled; }, "itWriter", Tests.TEST_TIMEOUT); + + runs(function() { + expect(itWriter).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }), + itWriter = jasmine.createSpy().andCallFake(function(writer) { + expect(writer).toBeDefined(); + expect(writer instanceof FileWriter).toBe(true); + + // cleanup + itFile.remove(null, fail); + }), + fail = createFail('FileEntry'); + + // create a new file entry to kick off it + runs(function() { + root.getFile(fileName, {create:true}, entryCallback, fail); + }); + + waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT); + }); + it("file should return a File object", function() { + var fileName = "fe.file", + newFile, + entryCallback = jasmine.createSpy().andCallFake(function(fileEntry) { + newFile = fileEntry; + + runs(function() { + fileEntry.file(itFile, fail); + }); + + waitsFor(function() { return itFile.wasCalled; }, "itFile never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(itFile).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }), + itFile = jasmine.createSpy().andCallFake(function(file) { + expect(file).toBeDefined(); + expect(file instanceof File).toBe(true); + + // cleanup + newFile.remove(null, fail); + }), + fail = createFail('FileEntry'); + + // create a new file entry to kick off it + runs(function() { + root.getFile(fileName, {create:true}, entryCallback, fail); + }); + + waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT); + }); + it("file: on File that has been removed", function() { + var fileName = "fe.no.file", + entryCallback = jasmine.createSpy().andCallFake(function(fileEntry) { + // create File object + var getFile = jasmine.createSpy().andCallFake(function() { + runs(function() { + fileEntry.file(win, itFile); + }); + + waitsFor(function() { return itFile.wasCalled; }, "itFile never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(itFile).toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + }); + }); + // delete file + runs(function() { + fileEntry.remove(getFile, fail); + }); + + waitsFor(function() { return getFile.wasCalled; }, "getFile never called", Tests.TEST_TIMEOUT); + }), + itFile = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.NOT_FOUND_ERR); + }), + fail = createFail('FileEntry'), + win = createWin('FileEntry'); + + // create a new file entry to kick off it + runs(function() { + root.getFile(fileName, {create:true}, entryCallback, fail); + }); + + waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT); + }); + }); + describe('Entry', function() { + it("Entry object", function() { + var fileName = "entry", + fullPath = root.fullPath + '/' + fileName, + fail = createFail('Entry'), + itEntry = jasmine.createSpy().andCallFake(function(entry) { + expect(entry).toBeDefined(); + expect(entry.isFile).toBe(true); + expect(entry.isDirectory).toBe(false); + expect(entry.name).toBe(fileName); + expect(entry.fullPath).toBe(fullPath); + expect(typeof entry.getMetadata).toBe('function'); + expect(typeof entry.moveTo).toBe('function'); + expect(typeof entry.copyTo).toBe('function'); + expect(typeof entry.toURL).toBe('function'); + expect(typeof entry.remove).toBe('function'); + expect(typeof entry.getParent).toBe('function'); + expect(typeof entry.createWriter).toBe('function'); + expect(typeof entry.file).toBe('function'); - // create a new directory entry to kick off test - this.root.getDirectory(dirName, {create:true}, entryCallback, this.fail); - }); - test("DirectoryEntry.removeRecursively on root file system", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var testRemove = function(error) { - ok(typeof error !== 'undefined' && error !== null, "removing root file system should generate an error"); - equal(error.code, FileError.NO_MODIFICATION_ALLOWED_ERR, "error code should be FileError.NO_MODIFICATION_ALLOWED_ERR"); - QUnit.start(); - }; - - // remove root file system - this.root.removeRecursively(null, testRemove); - }); - module('File interface'); - test("File constructor should be defined", function() { - expect(1); - ok(typeof File === 'function', "File constructor should be a function."); - }); - test("File attributes should be defined", function() { - expect(5); - var file = new File(); - ok(typeof file.name !== 'undefined', "File object should have a 'name' attribute"); - ok(typeof file.fullPath !== 'undefined', "File object should have a 'fullPath' attribute"); - ok(typeof file.type !== 'undefined', "File object should have a 'type' attribute"); - ok(typeof file.lastModifiedDate !== 'undefined', "File object should have a 'lastModifiedDate' attribute"); - ok(typeof file.size !== 'undefined', "File object should have a 'size' attribute"); - }); - module('FileEntry interface', { - // setup function will run before each test - setup: function() { - this.root = getFileSystemRoot(); - this.fail = function(error) { - console.log('file error: ' + error.code); - }; - } - }); - test("FileEntry methods should be defined", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(3); - - var fileName = "fe.methods", - that = this, - testFileEntry = function(fileEntry) { - ok(typeof fileEntry !== 'undefined' && fileEntry !== null, "FileEntry should not be null"); - ok(typeof fileEntry.createWriter === 'function', "FileEntry should have a 'createWriter' method"); - ok(typeof fileEntry.file === 'function', "FileEntry should have a 'file' method"); - - // cleanup - fileEntry.remove(null, that.fail); - QUnit.start(); - }; - - // create a new file entry to kick off test - this.root.getFile(fileName, {create:true}, testFileEntry, this.fail); - }); - test("FileEntry.createWriter should return a FileWriter object", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var fileName = "fe.createWriter", - that = this, - testFile, - entryCallback = function(fileEntry) { - testFile = fileEntry; - fileEntry.createWriter(testWriter, that.fail); - }, - testWriter = function(writer) { - ok(typeof writer !== 'undefined' && writer !== null, "FileWriter object should not be null"); - ok(writer.constructor === FileWriter, "writer should be a FileWriter object"); - - // cleanup - testFile.remove(null, that.fail); - QUnit.start(); - }; - - // create a new file entry to kick off test - this.root.getFile(fileName, {create:true}, entryCallback, this.fail); - }); - test("FileEntry.file should return a File object", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var fileName = "fe.file", - that = this, - newFile, - entryCallback = function(fileEntry) { - newFile = fileEntry; - fileEntry.file(testFile, that.fail); - }, - testFile = function(file) { - ok(typeof file !== 'undefined' && file !== null, "File object should not be null"); - ok(file.constructor === File, "File object should be a File"); - - // cleanup - newFile.remove(null, that.fail); - QUnit.start(); - }; - - // create a new file entry to kick off test - this.root.getFile(fileName, {create:true}, entryCallback, this.fail); - }); - test("FileEntry.file: on File that has been removed", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var fileName = "fe.no.file", - that = this, - entryCallback = function(fileEntry) { - // create File object - var getFile = function() { - fileEntry.file(null, testFile); - }; - // delete file - fileEntry.remove(getFile, that.fail); - }, - testFile = function(error) { - ok(typeof error !== 'undefined' && error !== null, "invoking FileEntry.file on a file that does not exist is an error"); - equal(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR"); - QUnit.start(); - }; - - // create a new file entry to kick off test - this.root.getFile(fileName, {create:true}, entryCallback, this.fail); - }); - module('Entry interface', { - // setup function will run before each test - setup: function() { - var that = this; - this.root = getFileSystemRoot(); - this.fail = function(error) { - console.log('file error: ' + error.code); - }; - this.unexpectedSuccess = function() { - console.log('!!! success function called when not expected !!!'); - }; - // deletes specified file or directory - this.deleteEntry = function(name, success, error) { - // deletes entry, if it exists - window.resolveLocalFileSystemURI(that.root.toURL() + '/' + name, - function(entry) { - console.log('Deleting: ' + entry.fullPath); - if (entry.isDirectory === true) { - entry.removeRecursively(success, error); - } - else { - entry.remove(success, error); - } - }, - // doesn't exist - success); - }; - // deletes and re-creates the specified file - this.createFile = function(fileName, success, error) { - that.deleteEntry(fileName, function() { - console.log('Creating file: ' + that.root.fullPath + '/' + fileName); - that.root.getFile(fileName, {create: true}, success, error); - }, error); - }; - // deletes and re-creates the specified directory - this.createDirectory = function(dirName, success, error) { - that.deleteEntry(dirName, function() { - console.log('Creating directory: ' + that.root.fullPath + '/' + dirName); - that.root.getDirectory(dirName, {create: true}, success, error); - }, error); - }; - } - }); - test("Entry object", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(13); - - var fileName = "entry", - that = this, - fullPath = this.root.fullPath + '/' + fileName, - testEntry = function(entry) { - ok(typeof entry !== 'undefined' && entry !== null, "entry should not be null."); - equal(entry.isFile, true, "entry.isFile should be true"); - equal(entry.isDirectory, false, "entry.isDirectory should be false"); - equal(entry.name, fileName, "entry object 'name' property should be set"); - equal(entry.fullPath, fullPath, "entry object 'fullPath' property should be set"); - ok(typeof entry.getMetadata === 'function', "entry object should have a 'getMetadata' function."); - ok(typeof entry.moveTo === 'function', "entry object should have a 'moveTo' function."); - ok(typeof entry.copyTo === 'function', "entry object should have a 'copyTo' function."); - ok(typeof entry.toURL === 'function', "entry object should have a 'toURL' function."); - ok(typeof entry.remove === 'function', "entry object should have a 'remove' function."); - ok(typeof entry.getParent === 'function', "entry object should have a 'getParent' function."); - ok(typeof entry.createWriter === 'function', "entry object should have a 'createWriter' function."); - ok(typeof entry.file === 'function', "entry object should have a 'file' function."); - - // cleanup - that.deleteEntry(fileName); - QUnit.start(); - }; + // cleanup + deleteEntry(fileName); + }); + + // create a new file entry + runs(function() { + createFile(fileName, itEntry, fail); + }); + + waitsFor(function() { return itEntry.wasCalled; }, "itEntry", Tests.TEST_TIMEOUT); + + runs(function() { + expect(itEntry).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("Entry.getMetadata on file", function() { + var fileName = "entry.metadata.file", + entryCallback = jasmine.createSpy().andCallFake(function(entry) { + runs(function() { + entry.getMetadata(itMetadata, fail); + }); + + waitsFor(function() { return itMetadata.wasCalled; }, "itMetadata never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(itMetadata).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }), + fail = createFail('Entry'), + itMetadata = jasmine.createSpy().andCallFake(function(metadata) { + expect(metadata).toBeDefined(); + expect(metadata.modificationTime instanceof Date).toBe(true); - // create a new file entry - this.createFile(fileName, testEntry, this.fail); - }); - test("Entry.getMetadata on file", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(3); - - var fileName = "entry.metadata.file", - that = this, - entryCallback = function(entry) { - entry.getMetadata(testMetadata, this.fail); - }, - testMetadata = function(metadata) { - ok(typeof metadata !== 'undefined' && metadata !== null, "metadata should not be null."); - ok(metadata.modificationTime instanceof Date, "metadata.modificationTime should be Date object"); - ok(isNaN(metadata.modificationTime.getTime()) !== true, "metadata.modificationTime should not be an Invalid Date"); - - // cleanup - that.deleteEntry(fileName); - QUnit.start(); - }; - - // create a new file entry - this.createFile(fileName, entryCallback, this.fail); - }); - test("Entry.getMetadata on directory", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(3); - - var dirName = "entry.metadata.dir", - that = this, - entryCallback = function(entry) { - entry.getMetadata(testMetadata, this.fail); - }, - testMetadata = function(metadata) { - ok(typeof metadata !== 'undefined' && metadata !== null, "metadata should not be null."); - ok(metadata.modificationTime instanceof Date, "metadata.modificationTime should be Date object"); - ok(isNaN(metadata.modificationTime.getTime()) !== true, "metadata.modificationTime should not be an Invalid Date"); - - // cleanup - that.deleteEntry(dirName); - QUnit.start(); - }; - - // create a new directory entry - this.createDirectory(dirName, entryCallback, this.fail); - }); - test("Entry.getParent on file in root file system", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(3); - - var fileName = "entry.parent.file", - that = this, - rootPath = this.root.fullPath, - entryCallback = function(entry) { - entry.getParent(testParent, this.fail); - }, - testParent = function(parent) { - ok(typeof parent !== 'undefined' && parent !== null, "parent directory should not be null."); - equal(parent.fullPath, rootPath, "parent fullPath should be root file system"); - ok(typeof parent.getParent === 'function', "entry object should have a 'getParent' function."); - - // cleanup - that.deleteEntry(fileName); - QUnit.start(); - }; - - // create a new file entry - this.createFile(fileName, entryCallback, this.fail); - }); - test("Entry.getParent on directory in root file system", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(3); - - var dirName = "entry.parent.dir", - that = this, - rootPath = this.root.fullPath, - entryCallback = function(entry) { - entry.getParent(testParent, this.fail); - }, - testParent = function(parent) { - ok(typeof parent !== 'undefined' && parent !== null, "parent directory should not be null."); - equal(parent.fullPath, rootPath, "parent fullPath should be root file system"); - ok(typeof parent.getParent === 'function', "entry object should have a 'getParent' function."); - - // cleanup - that.deleteEntry(dirName); - QUnit.start(); - }; - - // create a new directory entry - this.createDirectory(dirName, entryCallback, this.fail); - }); - test("Entry.getParent on root file system", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(3); - - var rootPath = this.root.fullPath, - testParent = function(parent) { - ok(typeof parent !== 'undefined' && parent !== null, "parent directory should not be null."); - equal(parent.fullPath, rootPath, "parent fullPath should be root file system"); - ok(typeof parent.getParent === 'function', "entry object should have a 'getParent' function."); - QUnit.start(); - }; - - // create a new directory entry - this.root.getParent(testParent, this.fail); - }); - test("Entry.toURL on file", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var fileName = "entry.uri.file", - that = this, - rootPath = this.root.fullPath, - testURL = function(entry) { - var uri = entry.toURL(); - ok(typeof uri !== 'undefined' && uri !== null, "URL should not be null."); - ok(uri.indexOf(rootPath) !== -1, "URL should contain root file system path"); - - // cleanup - that.deleteEntry(fileName); - QUnit.start(); - }; - - // create a new file entry - this.createFile(fileName, testURL, this.fail); - }); - test("Entry.toURL on directory", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var dirName = "entry.uri.dir", - that = this, - rootPath = this.root.fullPath, - testURL = function(entry) { - var uri = entry.toURL(); - ok(typeof uri !== 'undefined' && uri !== null, "URL should not be null."); - ok(uri.indexOf(rootPath) !== -1, "URL should contain root file system path"); - - // cleanup - that.deleteEntry(dirName); - QUnit.start(); - }; - - // create a new directory entry - this.createDirectory(dirName, testURL, this.fail); - }); - test("Entry.remove on file", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(3); - - var fileName = "entry.rm.file", - that = this, - fullPath = this.root.fullPath + '/' + fileName, - entryCallback = function(entry) { - var checkRemove = function() { - that.root.getFile(fileName, null, that.unexpectedSuccess, testRemove); - }; - ok(typeof entry !== 'undefined' && entry !== null, "entry should not be null."); - entry.remove(checkRemove, that.fail); - }, - testRemove = function(error) { - ok(typeof error !== 'undefined' && error !== null, "file should not exist"); - equal(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR"); - // cleanup - that.deleteEntry(fileName); - QUnit.start(); - }; - - // create a new file entry - this.createFile(fileName, entryCallback, this.fail); - }); - test("Entry.remove on empty directory", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(3); - - var dirName = "entry.rm.dir", - that = this, - fullPath = this.root.fullPath + '/' + dirName, - entryCallback = function(entry) { - var checkRemove = function() { - that.root.getDirectory(dirName, null, that.unexpectedSuccess, testRemove); - }; - ok(typeof entry !== 'undefined' && entry !== null, "entry should not be null."); - entry.remove(checkRemove, that.fail); - }, - testRemove = function(error) { - ok(typeof error !== 'undefined' && error !== null, "directory should not exist"); - equal(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR"); - // cleanup - that.deleteEntry(dirName); - QUnit.start(); - }; - - // create a new directory entry - this.createDirectory(dirName, entryCallback, this.fail); - }); - test("Entry.remove on non-empty directory", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(4); - - var dirName = "entry.rm.dir.not.empty", - that = this, - fullPath = this.root.fullPath + '/' + dirName, - fileName = "remove.txt", - entryCallback = function(entry) { - var checkFile = function(error) { - ok(typeof error !== 'undefined' && error !== null, "removing non-empty directory should generate an error"); - equal(error.code, FileError.INVALID_MODIFICATION_ERR, "error code should be FileError.INVALID_MODIFICATION_ERR"); - // verify that dir still exists - that.root.getDirectory(dirName, null, testRemove, that.fail); - }; - // delete directory - var deleteDirectory = function(fileEntry) { - entry.remove(that.unexpectedSuccess, checkFile); - }; - // create a file within directory, then try to delete directory - entry.getFile(fileName, {create: true}, deleteDirectory, that.fail); - }, - testRemove = function(entry) { - ok(typeof entry !== 'undefined' && entry !== null, "entry should not be null."); - equal(entry.fullPath, fullPath, "dir entry should still exisit"); - // cleanup - that.deleteEntry(dirName); - QUnit.start(); - }; - - // create a new directory entry - this.createDirectory(dirName, entryCallback, this.fail); - }); - test("Entry.remove on root file system", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var testRemove = function(error) { - ok(typeof error !== 'undefined' && error !== null, "removing root file system should generate an error"); - equal(error.code, FileError.NO_MODIFICATION_ALLOWED_ERR, "error code should be FileError.NO_MODIFICATION_ALLOWED_ERR"); - QUnit.start(); - }; - - // remove entry that doesn't exist - this.root.remove(null, testRemove); - }); - test("Entry.copyTo: file", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(10); - - var file1 = "entry.copy.file1", - file2 = "entry.copy.file2", - that = this, - fullPath = this.root.fullPath + '/' + file2, - entryCallback = function(entry) { - // copy file1 to file2 - entry.copyTo(that.root, file2, testCopy, that.fail); - }, - testCopy = function(entry) { - - ok(typeof entry !== 'undefined' && entry !== null, "copied file entry should not be null"); - equals(entry.isFile, true, "entry 'isFile' attribute should be set to true"); - equals(entry.isDirectory, false, "entry 'isDirectory' attribute should be set to false"); - equals(entry.fullPath, fullPath, "entry 'fullPath' should be set correctly"); - equals(entry.name, file2, "entry 'name' attribute should be set correctly"); - that.root.getFile(file2, {create:false}, testFileExists, null); - - }, - testFileExists = function(entry2) { - // a bit redundant since copy returned this entry already - ok(typeof entry2 !== 'undefined' && entry2 !== null, "copied file entry should not be null"); - equals(entry2.isFile, true, "entry 'isFile' attribute should be set to true"); - equals(entry2.isDirectory, false, "entry 'isDirectory' attribute should be set to false"); - equals(entry2.fullPath, fullPath, "entry 'fullPath' should be set correctly"); - equals(entry2.name, file2, "entry 'name' attribute should be set correctly"); - - // cleanup - that.deleteEntry(file1); - that.deleteEntry(file2); - QUnit.start(); - }; - - // create a new file entry to kick off test - this.createFile(file1, entryCallback, this.fail); - }); - test("Entry.copyTo: file onto itself", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var file1 = "entry.copy.fos.file1", - that = this, - entryCallback = function(entry) { - // copy file1 onto itself - entry.copyTo(that.root, null, null, testCopy); - }, - testCopy = function(error) { - ok(typeof error !== 'undefined' && error !== null, "it is an error to copy an entry into its parent if a different name is not specified"); - equal(error.code, FileError.INVALID_MODIFICATION_ERR, "error code should be FileError.INVALID_MODIFICATION_ERR"); - - // cleanup - that.deleteEntry(file1); - QUnit.start(); - }; - - // create a new file entry to kick off test - this.createFile(file1, entryCallback, this.fail); - }); - test("Entry.copyTo: directory", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(15); - - var file1 = "file1", - srcDir = "entry.copy.srcDir", - dstDir = "entry.copy.dstDir", - dstPath = this.root.fullPath + '/' + dstDir, - filePath = dstPath + '/' + file1, - that = this, - entryCallback = function(directory) { - var copyDir = function(fileEntry) { - // copy srcDir to dstDir - directory.copyTo(that.root, dstDir, testCopy, that.fail); - }; - // create a file within new directory - directory.getFile(file1, {create: true}, copyDir, that.fail); - }, - testCopy = function(directory) { - - ok(typeof directory !== 'undefined' && directory !== null, "copied directory entry should not be null"); - equals(directory.isFile, false, "entry 'isFile' attribute should be false"); - equals(directory.isDirectory, true, "entry 'isDirectory' attribute should be true"); - equals(directory.fullPath, dstPath, "entry 'fullPath' should be set correctly"); - equals(directory.name, dstDir, "entry 'name' attribute should be set correctly"); - - that.root.getDirectory(dstDir, {create:false}, testDirExists, that.fail); - }, - testDirExists = function(dirEntry) { - ok(typeof dirEntry !== 'undefined' && dirEntry !== null, "copied directory entry should not be null"); - equals(dirEntry.isFile, false, "entry 'isFile' attribute should be false"); - equals(dirEntry.isDirectory, true, "entry 'isDirectory' attribute should be true"); - equals(dirEntry.fullPath, dstPath, "entry 'fullPath' should be set correctly"); - equals(dirEntry.name, dstDir, "entry 'name' attribute should be set correctly"); - - dirEntry.getFile(file1, {create:false}, testFileExists, that.fail); - - }; - testFileExists = function(fileEntry) { - ok(typeof fileEntry !== 'undefined' && fileEntry !== null, "copied directory entry should not be null"); - equals(fileEntry.isFile, true, "entry 'isFile' attribute should be true"); - equals(fileEntry.isDirectory, false, "entry 'isDirectory' attribute should be false"); - equals(fileEntry.fullPath, filePath, "entry 'fullPath' should be set correctly"); - equals(fileEntry.name, file1, "entry 'name' attribute should be set correctly"); - + // cleanup + deleteEntry(fileName); + }); + + // create a new file entry + createFile(fileName, entryCallback, fail); + }); + it("Entry.getMetadata on directory", function() { + var dirName = "entry.metadata.dir", + entryCallback = jasmine.createSpy().andCallFake(function(entry) { + runs(function() { + entry.getMetadata(itMetadata, fail); + }); + + waitsFor(function() { return itMetadata.wasCalled; }, "itMetadata never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(itMetadata).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }), + fail = createFail('Entry'), + itMetadata = jasmine.createSpy().andCallFake(function(metadata) { + expect(metadata).toBeDefined(); + expect(metadata.modificationTime instanceof Date).toBe(true); - // cleanup - that.deleteEntry(srcDir); - that.deleteEntry(dstDir); - QUnit.start(); - }; + // cleanup + deleteEntry(dirName); + }); + + // create a new directory entry + runs(function() { + createDirectory(dirName, entryCallback, fail); + }); + + waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT); + }); + it("Entry.getParent on file in root file system", function() { + var fileName = "entry.parent.file", + rootPath = root.fullPath, + fail = createFail('Entry'), + entryCallback = jasmine.createSpy().andCallFake(function(entry) { + runs(function() { + entry.getParent(itParent, fail); + }); + + waitsFor(function() { return itParent.wasCalled; }, "itCalled never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(itParent).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }), + itParent = jasmine.createSpy().andCallFake(function(parent) { + expect(parent).toBeDefined(); + expect(parent.fullPath).toBe(rootPath); - // create a new directory entry to kick off test - this.createDirectory(srcDir, entryCallback, this.fail); - }); - test("Entry.copyTo: directory to backup at same root directory", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(15); - - var file1 = "file1", - srcDir = "entry.copy.srcDir", - dstDir = "entry.copy.srcDir-backup", - dstPath = this.root.fullPath + '/' + dstDir, - filePath = dstPath + '/' + file1, - that = this, - entryCallback = function(directory) { - var copyDir = function(fileEntry) { - // copy srcDir to dstDir - directory.copyTo(that.root, dstDir, testCopy, that.fail); - }; - // create a file within new directory - directory.getFile(file1, {create: true}, copyDir, that.fail); - }, - testCopy = function(directory) { - - ok(typeof directory !== 'undefined' && directory !== null, "copied directory entry should not be null"); - equals(directory.isFile, false, "entry 'isFile' attribute should be false"); - equals(directory.isDirectory, true, "entry 'isDirectory' attribute should be true"); - equals(directory.fullPath, dstPath, "entry 'fullPath' should be set correctly"); - equals(directory.name, dstDir, "entry 'name' attribute should be set correctly"); - - that.root.getDirectory(dstDir, {create:false}, testDirExists, that.fail); - }, - testDirExists = function(dirEntry) { - ok(typeof dirEntry !== 'undefined' && dirEntry !== null, "copied directory entry should not be null"); - equals(dirEntry.isFile, false, "entry 'isFile' attribute should be false"); - equals(dirEntry.isDirectory, true, "entry 'isDirectory' attribute should be true"); - equals(dirEntry.fullPath, dstPath, "entry 'fullPath' should be set correctly"); - equals(dirEntry.name, dstDir, "entry 'name' attribute should be set correctly"); + // cleanup + deleteEntry(fileName); + }); + + // create a new file entry + runs(function() { + createFile(fileName, entryCallback, fail); + }); + + waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT); + }); + it("Entry.getParent on directory in root file system", function() { + var dirName = "entry.parent.dir", + rootPath = root.fullPath, + fail = createFail('Entry'), + entryCallback = jasmine.createSpy().andCallFake(function(entry) { + runs(function() { + entry.getParent(itParent, fail); + }); + + waitsFor(function() { return itParent.wasCalled; }, "itParent never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(itParent).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }), + itParent = jasmine.createSpy().andCallFake(function(parent) { + expect(parent).toBeDefined(); + expect(parent.fullPath).toBe(rootPath); + + // cleanup + deleteEntry(dirName); + }); + + // create a new directory entry + runs(function() { + createDirectory(dirName, entryCallback, fail); + }); + + waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT); + }); + it("Entry.getParent on root file system", function() { + var rootPath = root.fullPath, + itParent = jasmine.createSpy().andCallFake(function(parent) { + expect(parent).toBeDefined(); + expect(parent.fullPath).toBe(rootPath); + }), + fail = createFail('Entry'); + + // create a new directory entry + runs(function() { + root.getParent(itParent, fail); + }); + + waitsFor(function() { return itParent.wasCalled; }, "itParent never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(itParent).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("Entry.toURL on file", function() { + var fileName = "entry.uri.file", + rootPath = root.fullPath, + itURL = jasmine.createSpy().andCallFake(function(entry) { + var uri = entry.toURL(); + expect(uri).toBeDefined(); + expect(uri.indexOf(rootPath)).not.toBe(-1); + + // cleanup + deleteEntry(fileName); + }), + fail = createFail('Entry'); + + // create a new file entry + runs(function() { + createFile(fileName, itURL, fail); + }); + + waitsFor(function() { return itURL.wasCalled; }, "itURL never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(itURL).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("Entry.toURL on directory", function() { + var dirName = "entry.uri.dir", + rootPath = root.fullPath, + itURL = jasmine.createSpy().andCallFake(function(entry) { + var uri = entry.toURL(); + expect(uri).toBeDefined(); + expect(uri.indexOf(rootPath)).not.toBe(-1); + + // cleanup + deleteEntry(dirName); + }), + fail = createFail('Entry'); + + // create a new directory entry + runs(function() { + createDirectory(dirName, itURL, fail); + }); + + waitsFor(function() { return itURL.wasCalled; }, "itURL never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(itURL).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("Entry.remove on file", function() { + var fileName = "entry.rm.file", + fullPath = root.fullPath + '/' + fileName, + win = createWin('Entry'), + entryCallback = jasmine.createSpy().andCallFake(function(entry) { + var checkRemove = jasmine.createSpy().andCallFake(function() { + runs(function() { + root.getFile(fileName, null, win, itRemove); + }); + + waitsFor(function() { return itRemove.wasCalled; }, "itRemove never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(win).not.toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + expect(itRemove).toHaveBeenCalled(); + }); + }); + expect(entry).toBeDefined(); + + runs(function() { + entry.remove(checkRemove, fail); + }); + + waitsFor(function() { return checkRemove.wasCalled; }, "checkRemove never called", Tests.TEST_TIMEOUT); + }), + itRemove = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.NOT_FOUND_ERR); + // cleanup + deleteEntry(fileName); + }), + fail = createFail('Entry'); + + // create a new file entry + runs(function() { + createFile(fileName, entryCallback, fail); + }); + + waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT); + }); + it("remove on empty directory", function() { + var dirName = "entry.rm.dir", + fullPath = root.fullPath + '/' + dirName, + entryCallback = jasmine.createSpy().andCallFake(function(entry) { + var checkRemove = jasmine.createSpy().andCallFake(function() { + runs(function() { + root.getDirectory(dirName, null, win, itRemove); + }); + + waitsFor(function() { return itRemove.wasCalled; }, "itRemove never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(itRemove).toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); + + expect(entry).toBeDefined(); + + runs(function() { + entry.remove(checkRemove, fail); + }); + + waitsFor(function() { return checkRemove.wasCalled; }, "checkRemove never called", Tests.TEST_TIMEOUT); + }), + itRemove = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.NOT_FOUND_ERR); + // cleanup + deleteEntry(dirName); + }), + win = createWin('Entry'), + fail = createFail('Entry'); + + // create a new directory entry + runs(function() { + createDirectory(dirName, entryCallback, fail); + }); + + waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT); + }); + it("remove on non-empty directory", function() { + var dirName = "entry.rm.dir.not.empty", + fullPath = root.fullPath + '/' + dirName, + fileName = "remove.txt", + entryCallback = jasmine.createSpy().andCallFake(function(entry) { + var checkFile = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.INVALID_MODIFICATION_ERR); + // verify that dir still exists + runs(function() { + root.getDirectory(dirName, null, itRemove, fail); + }); + + waitsFor(function() { return itRemove.wasCalled; }, "itRemove never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(win).not.toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + expect(itRemove).toHaveBeenCalled(); + }); + }); + // delete directory + var deleteDirectory = jasmine.createSpy().andCallFake(function(fileEntry) { + runs(function() { + entry.remove(win, checkFile); + }); + + waitsFor(function() { return checkFile.wasCalled; }, "checkFile never called", Tests.TEST_TIMEOUT); + }); + // create a file within directory, then try to delete directory + runs(function() { + entry.getFile(fileName, {create: true}, deleteDirectory, fail); + }); + + waitsFor(function() { return deleteDirectory.wasCalled; }, "deleteDirectory never called", Tests.TEST_TIMEOUT); + }), + itRemove = jasmine.createSpy().andCallFake(function(entry) { + expect(entry).toBeDefined(); + expect(entry.fullPath).toBe(fullPath); + // cleanup + deleteEntry(dirName); + }), + win = createWin('Entry'), + fail = createFail('Entry'); + + // create a new directory entry + runs(function() { + createDirectory(dirName, entryCallback, fail); + }); + + waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT); + }); + it("remove on root file system", function() { + var itRemove = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.NO_MODIFICATION_ALLOWED_ERR); + }), + win = createWin('Entry'); + + // remove entry that doesn't exist + runs(function() { + root.remove(win, itRemove); + }); + + waitsFor(function() { return itRemove.wasCalled; }, "itRemove never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(win).not.toHaveBeenCalled(); + expect(itRemove).toHaveBeenCalled(); + }); + }); + it("copyTo: file", function() { + var file1 = "entry.copy.file1", + file2 = "entry.copy.file2", + fullPath = root.fullPath + '/' + file2, + fail = createFail('Entry'), + entryCallback = jasmine.createSpy().andCallFake(function(entry) { + // copy file1 to file2 + runs(function() { + entry.copyTo(root, file2, itCopy, fail); + }); + + waitsFor(function() { return itCopy.wasCalled; }, "itCopy never called", Tests.TEST_TIMEOUT); + }), + itCopy = jasmine.createSpy().andCallFake(function(entry) { + expect(entry).toBeDefined(); + expect(entry.isFile).toBe(true); + expect(entry.isDirectory).toBe(false); + expect(entry.fullPath).toBe(fullPath); + expect(entry.name).toBe(file2); + + runs(function() { + root.getFile(file2, {create:false}, itFileExists, fail); + }); + + waitsFor(function() { return itFileExists.wasCalled; }, "itFileExists never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(fail).not.toHaveBeenCalled(); + expect(itFileExists).toHaveBeenCalled(); + }); + }), + itFileExists = jasmine.createSpy().andCallFake(function(entry2) { + // a bit redundant since copy returned this entry already + expect(entry2).toBeDefined(); + expect(entry2.isFile).toBe(true); + expect(entry2.isDirectory).toBe(false); + expect(entry2.fullPath).toBe(fullPath); + expect(entry2.name).toBe(file2); - dirEntry.getFile(file1, {create:false}, testFileExists, that.fail); - - }; - testFileExists = function(fileEntry) { - ok(typeof fileEntry !== 'undefined' && fileEntry !== null, "copied directory entry should not be null"); - equals(fileEntry.isFile, true, "entry 'isFile' attribute should be true"); - equals(fileEntry.isDirectory, false, "entry 'isDirectory' attribute should be false"); - equals(fileEntry.fullPath, filePath, "entry 'fullPath' should be set correctly"); - equals(fileEntry.name, file1, "entry 'name' attribute should be set correctly"); - + // cleanup + deleteEntry(file1); + deleteEntry(file2); + }); + + // create a new file entry to kick off it + runs(function() { + createFile(file1, entryCallback, fail); + }); + + waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT); + }); + it("copyTo: file onto itself", function() { + var file1 = "entry.copy.fos.file1", + entryCallback = jasmine.createSpy().andCallFake(function(entry) { + // copy file1 onto itself + runs(function() { + entry.copyTo(root, null, win, itCopy); + }); + + waitsFor(function() { return itCopy.wasCalled; }, "itCopy never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(itCopy).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + }); + }), + fail = createFail('Entry'), + win = createWin('Entry'), + itCopy = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.INVALID_MODIFICATION_ERR); - // cleanup - that.deleteEntry(srcDir); - that.deleteEntry(dstDir); - QUnit.start(); - }; + // cleanup + deleteEntry(file1); + }); + + // create a new file entry to kick off it + runs(function() { + createFile(file1, entryCallback, fail); + }); + + waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT); + }); + it("copyTo: directory", function() { + var file1 = "file1", + srcDir = "entry.copy.srcDir", + dstDir = "entry.copy.dstDir", + dstPath = root.fullPath + '/' + dstDir, + filePath = dstPath + '/' + file1, + entryCallback = jasmine.createSpy().andCallFake(function(directory) { + var copyDir = jasmine.createSpy().andCallFake(function(fileEntry) { + // copy srcDir to dstDir + runs(function() { + directory.copyTo(root, dstDir, itCopy, fail); + }); + + waitsFor(function() { return itCopy.wasCalled; }, "itCopy never called", Tests.TEST_TIMEOUT); + }); + + // create a file within new directory + runs(function() { + directory.getFile(file1, {create: true}, copyDir, fail); + }); + + waitsFor(function() { return copyDir.wasCalled; }, "copyDir never called", Tests.TEST_TIMEOUT); + }), + itCopy = jasmine.createSpy().andCallFake(function(directory) { + expect(directory).toBeDefined(); + expect(directory.isFile).toBe(false); + expect(directory.isDirectory).toBe(true); + expect(directory.fullPath).toBe(dstPath); + expect(directory.name).toBe(dstDir); + + runs(function() { + root.getDirectory(dstDir, {create:false}, itDirExists, fail); + }); + + waitsFor(function() { return itDirExists.wasCalled; }, "itDirExists never called", Tests.TEST_TIMEOUT); + }), + itDirExists = jasmine.createSpy().andCallFake(function(dirEntry) { + expect(dirEntry).toBeDefined(); + expect(dirEntry.isFile).toBe(false); + expect(dirEntry.isDirectory).toBe(true); + expect(dirEntry.fullPath).toBe(dstPath); + expect(dirEntry.name).toBe(dstDir); + + runs(function() { + dirEntry.getFile(file1, {create:false}, itFileExists, fail); + }); + + waitsFor(function() { return itFileExists.wasCalled; }, "itFileExists never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(itFileExists).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }), + itFileExists = jasmine.createSpy().andCallFake(function(fileEntry) { + expect(fileEntry).toBeDefined(); + expect(fileEntry.isFile).toBe(true); + expect(fileEntry.isDirectory).toBe(false); + expect(fileEntry.fullPath).toBe(filePath); + expect(fileEntry.name).toBe(file1); - // create a new directory entry to kick off test - this.createDirectory(srcDir, entryCallback, this.fail); - }); - test("Entry.copyTo: directory onto itself", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(6); - - var file1 = "file1", - srcDir = "entry.copy.dos.srcDir", - srcPath = this.root.fullPath + '/' + srcDir, - filePath = srcPath + '/' + file1, - that = this, - entryCallback = function(directory) { - var copyDir = function(fileEntry) { - // copy srcDir onto itself - directory.copyTo(that.root, null, null, testCopy); - }; - // create a file within new directory - directory.getFile(file1, {create: true}, copyDir, that.fail); - }, - testCopy = function(error) { - ok(typeof error !== 'undefined' && error !== null, "it is an error to copy an entry into its parent if a different name is not specified"); - equal(error.code, FileError.INVALID_MODIFICATION_ERR, "error code should be FileError.INVALID_MODIFICATION_ERR"); - - that.root.getDirectory(srcDir, {create:false}, testDirectoryExists, null); - }, - testDirectoryExists = function(dirEntry) { - // returning confirms existence so just check fullPath entry - ok(typeof dirEntry !== 'undefined' && dirEntry !== null, "original directory should exist."); - equals(dirEntry.fullPath, srcPath, "entry 'fullPath' should be set correctly"); + // cleanup + deleteEntry(srcDir); + deleteEntry(dstDir); + }), + fail = createFail('Entry'); + + // create a new directory entry to kick off it + runs(function() { + createDirectory(srcDir, entryCallback, fail); + }); + + waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT); + }); + it("copyTo: directory to backup at same root directory", function() { + var file1 = "file1", + srcDir = "entry.copy.srcDirSame", + dstDir = "entry.copy.srcDirSame-backup", + dstPath = root.fullPath + '/' + dstDir, + filePath = dstPath + '/' + file1, + fail = createFail('Entry copyTo: directory to backup at same root'), + entryCallback = function(directory) { + var copyDir = function(fileEntry) { + // copy srcDir to dstDir + directory.copyTo(root, dstDir, itCopy, fail); + }; + // create a file within new directory + directory.getFile(file1, {create: true}, copyDir, fail); + }, + itCopy = function(directory) { + expect(directory).toBeDefined(); + expect(directory.isFile).toBe(false); + expect(directory.isDirectory).toBe(true); + expect(directory.fullPath).toBe(dstPath); + expect(directory.name).toBe(dstDir); - dirEntry.getFile(file1, {create:false}, testFileExists, null); - }, - testFileExists = function(fileEntry) { - ok(typeof fileEntry !== 'undefined' && fileEntry !== null, "original directory contents should exist."); - equals(fileEntry.fullPath, filePath, "entry 'fullPath' should be set correctly"); - - // cleanup - that.deleteEntry(srcDir); - QUnit.start(); - }; + root.getDirectory(dstDir, {create:false}, itDirExists, fail); + }, + itDirExists = function(dirEntry) { + expect(dirEntry).toBeDefined(); + expect(dirEntry.isFile).toBe(false); + expect(dirEntry.isDirectory).toBe(true); + expect(dirEntry.fullPath).toBe(dstPath); + expect(dirEntry.name).toBe(dstDir); + + dirEntry.getFile(file1, {create:false}, itFileExists, fail); + }, + itFileExists = jasmine.createSpy().andCallFake(function(fileEntry) { + var cleanSrc = jasmine.createSpy(); + var cleanDst = jasmine.createSpy(); + runs(function() { + expect(fileEntry).toBeDefined(); + expect(fileEntry.isFile).toBe(true); + expect(fileEntry.isDirectory).toBe(false); + expect(fileEntry.fullPath).toBe(filePath); + expect(fileEntry.name).toBe(file1); + expect(fail).not.toHaveBeenCalled(); - // create a new directory entry to kick off test - this.createDirectory(srcDir, entryCallback, this.fail); - }); - test("Entry.copyTo: directory into itself", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(4); - - var srcDir = "entry.copy.dis.srcDir", - dstDir = "entry.copy.dis.dstDir", - srcPath = this.root.fullPath + '/' + srcDir, - that = this, - entryCallback = function(directory) { - // copy source directory into itself - directory.copyTo(directory, dstDir, null, testCopy); - }, - testCopy = function(error) { - ok(typeof error !== 'undefined' && error !== null, "it is an error to copy a directory into itself"); - equal(error.code, FileError.INVALID_MODIFICATION_ERR, "error code should be FileError.INVALID_MODIFICATION_ERR"); - - that.root.getDirectory(srcDir, {create:false}, testDirectoryExists, null); - }, - testDirectoryExists = function(dirEntry) { - // returning confirms existence so just check fullPath entry - ok(typeof dirEntry !== 'undefined' && dirEntry !== null, "original directory should exist."); - equals(dirEntry.fullPath, srcPath, "entry 'fullPath' should be set correctly"); - - // cleanup - that.deleteEntry(srcDir); - QUnit.start(); - }; + // cleanup + deleteEntry(srcDir, cleanSrc); + deleteEntry(dstDir, cleanDst); + }); + + waitsFor(function() { return cleanSrc.wasCalled && cleanDst.wasCalled; }, "cleanSrc and cleanDst cleanup methods", Tests.TEST_TIMEOUT); + }); + + // create a new directory entry to kick off it + runs(function() { + createDirectory(srcDir, entryCallback, fail); + }); + + waitsFor(function() { return itFileExists.wasCalled; }, "itFileExists", 10000); + }); + it("copyTo: directory onto itself", function() { + var file1 = "file1", + srcDir = "entry.copy.dos.srcDir", + srcPath = root.fullPath + '/' + srcDir, + filePath = srcPath + '/' + file1, + win = createWin('Entry'), + fail = createFail('Entry copyTo: directory onto itself'), + entryCallback = jasmine.createSpy().andCallFake(function(directory) { + var copyDir = jasmine.createSpy().andCallFake(function(fileEntry) { + // copy srcDir onto itself + runs(function() { + directory.copyTo(root, null, win, itCopy); + }); + + waitsFor(function() { return itCopy.wasCalled; }, "itCopy never called", Tests.TEST_TIMEOUT); + }); + // create a file within new directory + runs(function() { + directory.getFile(file1, {create: true}, copyDir, fail); + }); + + waitsFor(function() { return copyDir.wasCalled; }, "copyDir never called", Tests.TEST_TIMEOUT); + }), + itCopy = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.INVALID_MODIFICATION_ERR); + + runs(function() { + root.getDirectory(srcDir, {create:false}, itDirectoryExists, fail); + }); + + waitsFor(function() { return itDirectoryExists.wasCalled; }, "itDirectoryExists", Tests.TEST_TIMEOUT); + }), + itDirectoryExists = jasmine.createSpy().andCallFake(function(dirEntry) { + // returning confirms existence so just check fullPath entry + expect(dirEntry).toBeDefined(); + expect(dirEntry.fullPath).toBe(srcPath); + + runs(function() { + dirEntry.getFile(file1, {create:false}, itFileExists, fail); + }); + + waitsFor(function() { return itFileExists.wasCalled; }, "itFileExists never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(win).not.toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + expect(itFileExists).toHaveBeenCalled(); + }); + }), + itFileExists = jasmine.createSpy().andCallFake(function(fileEntry) { + expect(fileEntry).toBeDefined(); + expect(fileEntry.fullPath).toBe(filePath); + + // cleanup + deleteEntry(srcDir); + }); + + // create a new directory entry to kick off it + runs(function() { + createDirectory(srcDir, entryCallback, fail); + }); + + waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT); + }); + it("copyTo: directory into itself", function() { + var srcDir = "entry.copy.dis.srcDir", + dstDir = "entry.copy.dis.dstDir", + fail = createFail('Entry'), + win = createWin('Entry'), + srcPath = root.fullPath + '/' + srcDir, + entryCallback = jasmine.createSpy().andCallFake(function(directory) { + // copy source directory into itself + runs(function() { + directory.copyTo(directory, dstDir, win, itCopy); + }); + + waitsFor(function() { return itCopy.wasCalled; }, "itCopy", Tests.TEST_TIMEOUT); + }), + itCopy = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.INVALID_MODIFICATION_ERR); + + runs(function() { + root.getDirectory(srcDir, {create:false}, itDirectoryExists, fail); + }); + + waitsFor(function() { return itDirectoryExists.wasCalled; }, "itDirectoryExists never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(itDirectoryExists).toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }), + itDirectoryExists = jasmine.createSpy().andCallFake(function(dirEntry) { + // returning confirms existence so just check fullPath entry + expect(dirEntry).toBeDefined(); + expect(dirEntry.fullPath).toBe(srcPath); - // create a new directory entry to kick off test - this.createDirectory(srcDir, entryCallback, this.fail); - }); - test("Entry.copyTo: directory that does not exist", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(4); - - var file1 = "entry.copy.dnf.file1", - dstDir = "entry.copy.dnf.dstDir", - filePath = this.root.fullPath + '/' + file1, - dstPath = this.root.fullPath + '/' + dstDir, - that = this, - entryCallback = function(entry) { - // copy file to target directory that does not exist - directory = new DirectoryEntry(); - directory.fullPath = dstPath; - entry.copyTo(directory, null, null, testCopy); - }, - testCopy = function(error) { - ok(typeof error !== 'undefined' && error !== null, "it is an error to copy to a directory that does not exist"); - equal(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR"); - that.root.getFile(file1, {create: false}, testFileExists, null); - }, - testFileExists = function(fileEntry) { - ok(typeof fileEntry !== 'undefined' && fileEntry !== null, "original file should exist"); - equals(fileEntry.fullPath, filePath, "entry 'fullPath' should be set correctly"); - - // cleanup - that.deleteEntry(file1); - QUnit.start(); - }; + // cleanup + deleteEntry(srcDir); + }); + + // create a new directory entry to kick off it + runs(function() { + createDirectory(srcDir, entryCallback, fail); + }); + + waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT); + }); + it("copyTo: directory that does not exist", function() { + var file1 = "entry.copy.dnf.file1", + dstDir = "entry.copy.dnf.dstDir", + filePath = root.fullPath + '/' + file1, + dstPath = root.fullPath + '/' + dstDir, + win = createWin('Entry'), + fail = createFail('Entry'), + entryCallback = jasmine.createSpy().andCallFake(function(entry) { + // copy file to target directory that does not exist + runs(function() { + directory = new DirectoryEntry(); + directory.fullPath = dstPath; + entry.copyTo(directory, null, win, itCopy); + }); + + waitsFor(function() { return itCopy.wasCalled; }, "itCopy never called", Tests.TEST_TIMEOUT); + }), + itCopy = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.NOT_FOUND_ERR); + runs(function() { + root.getFile(file1, {create: false}, itFileExists, fail); + }); + + waitsFor(function() { return itFileExists.wasCalled; }, "itFileExists never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(itFileExists).toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }), + itFileExists = jasmine.createSpy().andCallFake(function(fileEntry) { + expect(fileEntry).toBeDefined(); + expect(fileEntry.fullPath).toBe(filePath); - // create a new file entry to kick off test - this.createFile(file1, entryCallback, this.fail); - }); - test("Entry.copyTo: invalid target name", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var file1 = "entry.copy.itn.file1", - file2 = "bad:file:name", - that = this, - filePath = this.root.fullPath + '/' + file1, - entryCallback = function(entry) { - // copy file1 to file2 - entry.copyTo(that.root, file2, null, testCopy); - }, - testCopy = function(error) { - ok(typeof error !== 'undefined' && error !== null, "invalid file name should result in error"); - equal(error.code, FileError.ENCODING_ERR, "error code should be FileError.ENCODING_ERR"); - - // cleanup - that.deleteEntry(file1); - QUnit.start(); - }; - - // create a new file entry - this.createFile(file1, entryCallback, this.fail); - }); - test("Entry.moveTo: file to same parent", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(9); - - var file1 = "entry.move.fsp.file1", - file2 = "entry.move.fsp.file2", - that = this, - srcPath = this.root.fullPath + '/' + file1, - dstPath = this.root.fullPath + '/' + file2, - entryCallback = function(entry) { - // move file1 to file2 - entry.moveTo(that.root, file2, testMove, that.fail); - }, - testMove = function(entry) { - ok(typeof entry !== 'undefined' && entry !== null, "file entry should not be null"); - equals(entry.isFile, true, "entry 'isFile' attribute should be set to true"); - equals(entry.isDirectory, false, "entry 'isDirectory' attribute should be set to false"); - equals(entry.fullPath, dstPath, "entry 'fullPath' should be set correctly"); - equals(entry.name, file2, "entry 'name' attribute should be set correctly"); + // cleanup + deleteEntry(file1); + }); + + // create a new file entry to kick off it + runs(function() { + createFile(file1, entryCallback, fail); + }); + + waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT); + }); + it("copyTo: invalid target name", function() { + var file1 = "entry.copy.itn.file1", + file2 = "bad:file:name", + filePath = root.fullPath + '/' + file1, + fail = createFail('Entry'), + win = createWin('Entry'), + entryCallback = jasmine.createSpy().andCallFake(function(entry) { + // copy file1 to file2 + runs(function() { + entry.copyTo(root, file2, win, itCopy); + }); + + waitsFor(function() { return itCopy.wasCalled; }, "itCopy never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(fail).not.toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + expect(itCopy).toHaveBeenCalled(); + }); + }), + itCopy = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.ENCODING_ERR); + + // cleanup + deleteEntry(file1); + }); + + // create a new file entry + runs(function() { + createFile(file1, entryCallback, fail); + }); + + waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT); + }); + it("moveTo: file to same parent", function() { + var file1 = "entry.move.fsp.file1", + file2 = "entry.move.fsp.file2", + srcPath = root.fullPath + '/' + file1, + dstPath = root.fullPath + '/' + file2, + fail = createFail('Entry'), + win = createWin('Entry'), + entryCallback = jasmine.createSpy().andCallFake(function(entry) { + // move file1 to file2 + runs(function() { + entry.moveTo(root, file2, itMove, fail); + }); + + waitsFor(function() { return itMove.wasCalled; }, "itMove never called", Tests.TEST_TIMEOUT); + }), + itMove = jasmine.createSpy().andCallFake(function(entry) { + expect(entry).toBeDefined(); + expect(entry.isFile).toBe(true); + expect(entry.isDirectory).toBe(false); + expect(entry.fullPath).toBe(dstPath); + expect(entry.name).toBe(file2); - that.root.getFile(file2, {create:false}, testMovedExists, null); - }, - testMovedExists = function(fileEntry) { - ok(typeof fileEntry !== 'undefined' && fileEntry !== null, "moved file should exist"); - equals(fileEntry.fullPath, dstPath, "entry 'fullPath' should be set correctly"); - - that.root.getFile(file1, {create:false}, null, testOrig); - }, - testOrig = function(error) { - //ok(navigator.fileMgr.testFileExists(srcPath) === false, "original file should not exist."); - ok(typeof error !== 'undefined' && error !== null, "it is an error if original file exists after a move"); - equal(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR"); + runs(function() { + root.getFile(file2, {create:false}, itMovedExists, fail); + }); + + waitsFor(function() { return itMovedExists.wasCalled; }, "itMovedExists never called", Tests.TEST_TIMEOUT); + }), + itMovedExists = jasmine.createSpy().andCallFake(function(fileEntry) { + expect(fileEntry).toBeDefined(); + expect(fileEntry.fullPath).toBe(dstPath); + + runs(function() { + root.getFile(file1, {create:false}, win, itOrig); + }); + + waitsFor(function() { return itOrig.wasCalled; }, "itOrig never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(win).not.toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + expect(itOrig).toHaveBeenCalled(); + }); + }), + itOrig = jasmine.createSpy().andCallFake(function(error) { + //expect(navigator.fileMgr.itFileExists(srcPath) === false, "original file should not exist."); + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.NOT_FOUND_ERR); + // cleanup + deleteEntry(file1); + deleteEntry(file2); + }); + + // create a new file entry to kick off it + runs(function() { + createFile(file1, entryCallback, fail); + }); + + waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT); + }); + it("moveTo: file to new parent", function() { + var file1 = "entry.move.fnp.file1", + dir = "entry.move.fnp.dir", + srcPath = root.fullPath + '/' + file1, + win = createWin('Entry'), + fail = createFail('Entry'), + dstPath = root.fullPath + '/' + dir + '/' + file1, + entryCallback = jasmine.createSpy().andCallFake(function(entry) { + // move file1 to new directory + var moveFile = jasmine.createSpy().andCallFake(function(directory) { + var itMove = jasmine.createSpy().andCallFake(function(entry) { + expect(entry).toBeDefined(); + expect(entry.isFile).toBe(true); + expect(entry.isDirectory).toBe(false); + expect(entry.fullPath).toBe(dstPath); + expect(entry.name).toBe(file1); + // it the moved file exists + runs(function() { + directory.getFile(file1, {create:false}, itMovedExists, fail); + }); + + waitsFor(function() { return itMovedExists.wasCalled; }, "itMovedExists never called", Tests.TEST_TIMEOUT); + }); + // move the file + runs(function() { + entry.moveTo(directory, null, itMove, fail); + }); + + waitsFor(function() { return itMove.wasCalled; }, "itMove never called", Tests.TEST_TIMEOUT); + }); - // cleanup - that.deleteEntry(file1); - that.deleteEntry(file2); - QUnit.start(); - }; - - // create a new file entry to kick off test - this.createFile(file1, entryCallback, this.fail); - }); - test("Entry.moveTo: file to new parent", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(9); - - var file1 = "entry.move.fnp.file1", - dir = "entry.move.fnp.dir", - that = this, - srcPath = this.root.fullPath + '/' + file1, - dstPath = this.root.fullPath + '/' + dir + '/' + file1, - entryCallback = function(entry) { - // move file1 to new directory - var moveFile = function(directory) { + // create a parent directory to move file to + runs(function() { + root.getDirectory(dir, {create: true}, moveFile, fail); + }); + + waitsFor(function() { return moveFile.wasCalled; }, "moveFile never called", Tests.TEST_TIMEOUT); + }), + itMovedExists = jasmine.createSpy().andCallFake(function(fileEntry) { + expect(fileEntry).toBeDefined(); + expect(fileEntry.fullPath).toBe(dstPath); + + runs(function() { + root.getFile(file1, {create:false}, win, itOrig); + }); + + waitsFor(function() { return itOrig.wasCalled; }, "itOrig never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(win).not.toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + expect(itOrig).toHaveBeenCalled(); + }); + }), + itOrig = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.NOT_FOUND_ERR); + + // cleanup + deleteEntry(file1); + deleteEntry(dir); + }); + + // ensure destination directory is cleaned up first + runs(function() { + deleteEntry(dir, function() { + // create a new file entry to kick off it + createFile(file1, entryCallback, fail); + }, fail); + }); + waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT); + }); + it("moveTo: directory to same parent", function() { + var file1 = "file1", + srcDir = "entry.move.dsp.srcDir", + dstDir = "entry.move.dsp.dstDir", + srcPath = root.fullPath + '/' + srcDir, + dstPath = root.fullPath + '/' + dstDir, + filePath = dstPath + '/' + file1, + win = createWin('Entry'), + fail = createFail('Entry'), + entryCallback = jasmine.createSpy().andCallFake(function(directory) { + var moveDir = jasmine.createSpy().andCallFake(function(fileEntry) { + // move srcDir to dstDir + runs(function() { + directory.moveTo(root, dstDir, itMove, fail); + }); + + waitsFor(function() { return itMove.wasCalled; }, "itMove never called", Tests.TEST_TIMEOUT); + }); + // create a file within directory + runs(function() { + directory.getFile(file1, {create: true}, moveDir, fail); + }); + + waitsFor(function() { return moveDir.wasCalled; }, "moveDir never called", Tests.TEST_TIMEOUT); + }), + itMove = jasmine.createSpy().andCallFake(function(directory) { + expect(directory).toBeDefined(); + expect(directory.isFile).toBe(false); + expect(directory.isDirectory).toBe(true); + expect(directory.fullPath).toBe(dstPath); + expect(directory.name).toBe(dstDir); + // it that moved file exists in destination dir - var testMove = function(entry) { - ok(typeof entry !== 'undefined' && entry !== null, "file entry should not be null"); - equals(entry.isFile, true, "entry 'isFile' attribute should be set to true"); - equals(entry.isDirectory, false, "entry 'isDirectory' attribute should be set to false"); - equals(entry.fullPath, dstPath, "entry 'fullPath' should be set correctly"); - equals(entry.name, file1, "entry 'name' attribute should be set correctly"); - // test the moved file exists - directory.getFile(file1, {create:false}, testMovedExists, null); - }; - // move the file - entry.moveTo(directory, null, testMove, that.fail); - }; - - // create a parent directory to move file to - that.root.getDirectory(dir, {create: true}, moveFile, that.fail); - }, - testMovedExists = function(fileEntry) { - ok(typeof fileEntry !== 'undefined' && fileEntry !== null, "moved file should exist"); - equals(fileEntry.fullPath, dstPath, "entry 'fullPath' should be set correctly"); - - that.root.getFile(file1, {create:false}, null, testOrig); - }, - testOrig = function(error) { - ok(typeof error !== 'undefined' && error !== null, "it is an error if original file exists after a move"); - equal(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR"); - - // cleanup - that.deleteEntry(file1); - that.deleteEntry(dir); - QUnit.start(); - }; - - // ensure destination directory is cleaned up before test - this.deleteEntry(dir, function() { - // create a new file entry to kick off test - that.createFile(file1, entryCallback, that.fail); - }, this.fail); - }); - test("Entry.moveTo: directory to same parent", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(9); - - var file1 = "file1", - srcDir = "entry.move.dsp.srcDir", - dstDir = "entry.move.dsp.dstDir", - srcPath = this.root.fullPath + '/' + srcDir, - dstPath = this.root.fullPath + '/' + dstDir, - filePath = dstPath + '/' + file1, - that = this, - entryCallback = function(directory) { - var moveDir = function(fileEntry) { - // move srcDir to dstDir - directory.moveTo(that.root, dstDir, testMove, that.fail); - }; - // create a file within directory - directory.getFile(file1, {create: true}, moveDir, that.fail); - }, - testMove = function(directory) { - ok(typeof directory !== 'undefined' && directory !== null, "new directory entry should not be null"); - equals(directory.isFile, false, "entry 'isFile' attribute should be false"); - equals(directory.isDirectory, true, "entry 'isDirectory' attribute should be true"); - equals(directory.fullPath, dstPath, "entry 'fullPath' should be set correctly"); - equals(directory.name, dstDir, "entry 'name' attribute should be set correctly"); - // test that moved file exists in destination dir - directory.getFile(file1, {create:false}, testMovedExists, null); - }, - testMovedExists = function(fileEntry) { - ok(typeof fileEntry !== 'undefined' && fileEntry !== null, "moved file should exist within moved directory"); - equals(fileEntry.fullPath, filePath, "entry 'fullPath' should be set correctly"); - // test that the moved file no longer exists in original dir - that.root.getFile(file1, {create:false}, null, testOrig); - }, - testOrig = function(error) { - ok(typeof error !== 'undefined' && error !== null, "it is an error if original file exists after a move"); - equal(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR"); - - // cleanup - that.deleteEntry(srcDir); - that.deleteEntry(dstDir); - QUnit.start(); - }; - - // ensure destination directory is cleaned up before test - this.deleteEntry(dstDir, function() { - // create a new directory entry to kick off test - that.createDirectory(srcDir, entryCallback, that.fail); - }, this.fail); - }); - test("Entry.moveTo: directory to same parent with same name", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(9); - - var file1 = "file1", - srcDir = "entry.move.dsp.srcDir", - dstDir = "entry.move.dsp.srcDir-backup", - srcPath = this.root.fullPath + '/' + srcDir, - dstPath = this.root.fullPath + '/' + dstDir, - filePath = dstPath + '/' + file1, - that = this, - entryCallback = function(directory) { - var moveDir = function(fileEntry) { - // move srcDir to dstDir - directory.moveTo(that.root, dstDir, testMove, that.fail); - }; - // create a file within directory - directory.getFile(file1, {create: true}, moveDir, that.fail); - }, - testMove = function(directory) { - ok(typeof directory !== 'undefined' && directory !== null, "new directory entry should not be null"); - equals(directory.isFile, false, "entry 'isFile' attribute should be false"); - equals(directory.isDirectory, true, "entry 'isDirectory' attribute should be true"); - equals(directory.fullPath, dstPath, "entry 'fullPath' should be set correctly"); - equals(directory.name, dstDir, "entry 'name' attribute should be set correctly"); - // test that moved file exists in destination dir - directory.getFile(file1, {create:false}, testMovedExists, null); - }, - testMovedExists = function(fileEntry) { - ok(typeof fileEntry !== 'undefined' && fileEntry !== null, "moved file should exist within moved directory"); - equals(fileEntry.fullPath, filePath, "entry 'fullPath' should be set correctly"); - // test that the moved file no longer exists in original dir - that.root.getFile(file1, {create:false}, null, testOrig); - }, - testOrig = function(error) { - ok(typeof error !== 'undefined' && error !== null, "it is an error if original file exists after a move"); - equal(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR"); - - // cleanup - that.deleteEntry(srcDir); - that.deleteEntry(dstDir); - QUnit.start(); - }; - - // ensure destination directory is cleaned up before test - this.deleteEntry(dstDir, function() { - // create a new directory entry to kick off test - that.createDirectory(srcDir, entryCallback, that.fail); - }, this.fail); - }); - test("Entry.moveTo: directory to new parent", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(9); - - var file1 = "file1", - srcDir = "entry.move.dnp.srcDir", - dstDir = "entry.move.dnp.dstDir", - srcPath = this.root.fullPath + '/' + srcDir, - dstPath = this.root.fullPath + '/' + dstDir, - filePath = dstPath + '/' + file1, - that = this, - entryCallback = function(directory) { - var moveDir = function(fileEntry) { - // move srcDir to dstDir - directory.moveTo(that.root, dstDir, testMove, that.fail); - }; - // create a file within directory - directory.getFile(file1, {create: true}, moveDir, that.fail); - }, - testMove = function(directory) { - ok(typeof directory !== 'undefined' && directory !== null, "new directory entry should not be null"); - equals(directory.isFile, false, "entry 'isFile' attribute should be false"); - equals(directory.isDirectory, true, "entry 'isDirectory' attribute should be true"); - equals(directory.fullPath, dstPath, "entry 'fullPath' should be set correctly"); - equals(directory.name, dstDir, "entry 'name' attribute should be set correctly"); - // test that moved file exists in destination dir - directory.getFile(file1, {create:false}, testMovedExists, null); - }, - testMovedExists = function(fileEntry) { - ok(typeof fileEntry !== 'undefined' && fileEntry !== null, "moved file should exist within moved directory"); - equals(fileEntry.fullPath, filePath, "entry 'fullPath' should be set correctly"); - // test that the moved file no longer exists in original dir - that.root.getFile(file1, {create:false}, null, testOrig); - }, - testOrig = function(error) { - ok(typeof error !== 'undefined' && error !== null, "it is an error if original file exists after a move"); - equal(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR"); - - // cleanup - that.deleteEntry(srcDir); - that.deleteEntry(dstDir); - QUnit.start(); - }; - - // ensure destination directory is cleaned up before test - this.deleteEntry(dstDir, function() { - // create a new directory entry to kick off test - that.createDirectory(srcDir, entryCallback, that.fail); - }, this.fail); - }); - test("Entry.moveTo: directory onto itself", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(6); - - var file1 = "file1", - srcDir = "entry.move.dos.srcDir", - srcPath = this.root.fullPath + '/' + srcDir, - filePath = srcPath + '/' + file1, - that = this, - entryCallback = function(directory) { - var moveDir = function(fileEntry) { - // move srcDir onto itself - directory.moveTo(that.root, null, null, testMove); - }; - // create a file within new directory - directory.getFile(file1, {create: true}, moveDir, that.fail); - }, - testMove = function(error) { - ok(typeof error !== 'undefined' && error !== null, "it is an error to move an entry into its parent if a different name is not specified"); - equal(error.code, FileError.INVALID_MODIFICATION_ERR, "error code should be FileError.INVALID_MODIFICATION_ERR"); - - // test that original dir still exists - that.root.getDirectory(srcDir, {create:false}, testDirectoryExists, null); - }, - testDirectoryExists = function(dirEntry) { - // returning confirms existence so just check fullPath entry - ok(typeof dirEntry !== 'undefined' && dirEntry !== null, "original directory should exist."); - equals(dirEntry.fullPath, srcPath, "entry 'fullPath' should be set correctly"); - - dirEntry.getFile(file1, {create:false}, testFileExists, null); - }, - testFileExists = function(fileEntry) { - ok(typeof fileEntry !== 'undefined' && fileEntry !== null, "original directory contents should exist."); - equals(fileEntry.fullPath, filePath, "entry 'fullPath' should be set correctly"); - - // cleanup - that.deleteEntry(srcDir); - QUnit.start(); - }; - - // create a new directory entry to kick off test - this.createDirectory(srcDir, entryCallback, this.fail); - }); - test("Entry.moveTo: directory into itself", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(4); - - var srcDir = "entry.move.dis.srcDir", - dstDir = "entry.move.dis.dstDir", - srcPath = this.root.fullPath + '/' + srcDir, - that = this, - entryCallback = function(directory) { - // move source directory into itself - directory.moveTo(directory, dstDir, null, testMove); - }, - testMove = function(error) { - ok(typeof error !== 'undefined' && error !== null, "it is an error to move a directory into itself"); - equal(error.code, FileError.INVALID_MODIFICATION_ERR, "error code should be FileError.INVALID_MODIFICATION_ERR"); - // make sure original directory still exists - that.root.getDirectory(srcDir, {create:false}, testDirectoryExists, null); - }, - testDirectoryExists = function(entry) { - ok(typeof entry !== 'undefined' && entry !== null, "original directory should exist."); - equals(entry.fullPath, srcPath, "entry 'fullPath' should be set correctly"); - - // cleanup - that.deleteEntry(srcDir); - QUnit.start(); - }; - - // create a new directory entry to kick off test - this.createDirectory(srcDir, entryCallback, this.fail); - }); - test("Entry.moveTo: file onto itself", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(4); - - var file1 = "entry.move.fos.file1", - filePath = this.root.fullPath + '/' + file1, - that = this, - entryCallback = function(entry) { - // move file1 onto itself - entry.moveTo(that.root, null, null, testMove); - }, - testMove = function(error) { - ok(typeof error !== 'undefined' && error !== null, "it is an error to move an entry into its parent if a different name is not specified"); - equal(error.code, FileError.INVALID_MODIFICATION_ERR, "error code should be FileError.INVALID_MODIFICATION_ERR"); - - //test that original file still exists - that.root.getFile(file1, {create:false}, testFileExists, null); - }, - testFileExists = function(fileEntry) { - ok(typeof fileEntry !== 'undefined' && fileEntry !== null, "original directory contents should exist."); - equals(fileEntry.fullPath, filePath, "entry 'fullPath' should be set correctly"); + runs(function() { + directory.getFile(file1, {create:false}, itMovedExists, fail); + }); + + waitsFor(function() { return itMovedExists.wasCalled; }, "itMovedExists never called", Tests.TEST_TIMEOUT); + }), + itMovedExists = jasmine.createSpy().andCallFake(function(fileEntry) { + expect(fileEntry).toBeDefined(); + expect(fileEntry.fullPath).toBe(filePath); + + // check that the moved file no longer exists in original dir + runs(function() { + root.getFile(file1, {create:false}, win, itOrig); + }); + + waitsFor(function() { return itOrig.wasCalled; }, "itOrig never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(win).not.toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + expect(itOrig).toHaveBeenCalled(); + }); + }), + itOrig = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.NOT_FOUND_ERR); + + // cleanup + deleteEntry(srcDir); + deleteEntry(dstDir); + }); + + // ensure destination directory is cleaned up before it + runs(function() { + deleteEntry(dstDir, function() { + // create a new directory entry to kick off it + createDirectory(srcDir, entryCallback, fail); + }, fail); + }); + + waitsFor(function() { return entryCallback.wasCalled; }, "entryCAllback never called", Tests.TEST_TIMEOUT); + }); + it("moveTo: directory to same parent with same name", function() { + var file1 = "file1", + srcDir = "entry.move.dsp.srcDir", + dstDir = "entry.move.dsp.srcDir-backup", + srcPath = root.fullPath + '/' + srcDir, + dstPath = root.fullPath + '/' + dstDir, + filePath = dstPath + '/' + file1, + win = createWin('Entry'), + fail = createFail('Entry'), + entryCallback = jasmine.createSpy().andCallFake(function(directory) { + var moveDir = jasmine.createSpy().andCallFake(function(fileEntry) { + // move srcDir to dstDir + runs(function() { + directory.moveTo(root, dstDir, itMove, fail); + }); + + waitsFor(function() { return itMove.wasCalled; }, "itMove never called", Tests.TEST_TIMEOUT); + }); + // create a file within directory + runs(function() { + directory.getFile(file1, {create: true}, moveDir, fail); + }); + + waitsFor(function() { return moveDir.wasCalled; }, "moveDir never called", Tests.TEST_TIMEOUT); + }), + itMove = jasmine.createSpy().andCallFake(function(directory) { + expect(directory).toBeDefined(); + expect(directory.isFile).toBe(false); + expect(directory.isDirectory).toBe(true); + expect(directory.fullPath).toBe(dstPath); + expect(directory.name).toBe(dstDir); + // check that moved file exists in destination dir + runs(function() { + directory.getFile(file1, {create:false}, itMovedExists, null); + }); + + waitsFor(function() { return itMovedExists.wasCalled; }, "itMovedExists never called", Tests.TEST_TIMEOUT); + }), + itMovedExists = jasmine.createSpy().andCallFake(function(fileEntry) { + expect(fileEntry).toBeDefined(); + expect(fileEntry.fullPath).toBe(filePath); + // check that the moved file no longer exists in original dir + runs(function() { + root.getFile(file1, {create:false}, win, itOrig); + }); + + waitsFor(function() { return itOrig.wasCalled; }, "itOrig never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(win).not.toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + expect(itOrig).toHaveBeenCalled(); + }); + }), + itOrig = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.NOT_FOUND_ERR); + + // cleanup + deleteEntry(srcDir); + deleteEntry(dstDir); + }); + + // ensure destination directory is cleaned up before it + runs(function() { + deleteEntry(dstDir, function() { + // create a new directory entry to kick off it + createDirectory(srcDir, entryCallback, fail); + }, fail); + }); + + waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT); + }); + it("moveTo: directory to new parent", function() { + var file1 = "file1", + srcDir = "entry.move.dnp.srcDir", + dstDir = "entry.move.dnp.dstDir", + srcPath = root.fullPath + '/' + srcDir, + dstPath = root.fullPath + '/' + dstDir, + filePath = dstPath + '/' + file1, + win = createWin('Entry'), + fail = createFail('Entry'), + entryCallback = jasmine.createSpy().andCallFake(function(directory) { + var moveDir = jasmine.createSpy().andCallFake(function(fileEntry) { + // move srcDir to dstDir + runs(function() { + directory.moveTo(root, dstDir, itMove, fail); + }); + + waitsFor(function() { return itMove.wasCalled; }, "itMove never called", Tests.TEST_TIMEOUT); + }); + // create a file within directory + runs(function() { + directory.getFile(file1, {create: true}, moveDir, fail); + }); + + waitsFor(function() { return moveDir.wasCalled; }, "moveDir never called", Tests.TEST_TIMEOUT); + }), + itMove = jasmine.createSpy().andCallFake(function(directory) { + expect(directory).toBeDefined(); + expect(directory.isFile).toBe(false); + expect(directory.isDirectory).toBe(true); + expect(directory.fullPath).toBe(dstPath); + expect(directory.name).toBe(dstDir); + // it that moved file exists in destination dir + runs(function() { + directory.getFile(file1, {create:false}, itMovedExists, fail); + }); + + waitsFor(function() { return itMovedExists.wasCalled; }, "itMovedExists never called", Tests.TEST_TIMEOUT); + }), + itMovedExists = jasmine.createSpy().andCallFake(function(fileEntry) { + expect(fileEntry).toBeDefined(); + expect(fileEntry.fullPath).toBe(filePath); + // it that the moved file no longer exists in original dir + runs(function() { + root.getFile(file1, {create:false}, win, itOrig); + }); + + waitsFor(function() { return itOrig.wasCalled; }, "itOrig never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(win).not.toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + expect(itOrig).toHaveBeenCalled(); + }); + }), + itOrig = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.NOT_FOUND_ERR); + + // cleanup + deleteEntry(srcDir); + deleteEntry(dstDir); + }); + + // ensure destination directory is cleaned up before it + runs(function() { + deleteEntry(dstDir, function() { + // create a new directory entry to kick off it + createDirectory(srcDir, entryCallback, fail); + }, fail); + }); + + waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT); + }); + it("moveTo: directory onto itself", function() { + var file1 = "file1", + srcDir = "entry.move.dos.srcDir", + srcPath = root.fullPath + '/' + srcDir, + filePath = srcPath + '/' + file1, + fail = createFail('Entry'), + win = createWin('Entry'), + entryCallback = jasmine.createSpy().andCallFake(function(directory) { + var moveDir = jasmine.createSpy().andCallFake(function(fileEntry) { + // move srcDir onto itself + runs(function() { + directory.moveTo(root, null, win, itMove); + }); + + waitsFor(function() { return itMove.wasCalled; }, "itMove never called", Tests.TEST_TIMEOUT); + }); + // create a file within new directory + runs(function() { + directory.getFile(file1, {create: true}, moveDir, fail); + }); + + waitsFor(function() { return moveDir.wasCalled; }, "moveDir never called", Tests.TEST_TIMEOUT); + }), + itMove = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.INVALID_MODIFICATION_ERR); + + // it that original dir still exists + runs(function() { + root.getDirectory(srcDir, {create:false}, itDirectoryExists, fail); + }); + + waitsFor(function() { return itDirectoryExists.wasCalled; }, "itDirectoryExists", Tests.TEST_TIMEOUT); + }), + itDirectoryExists = jasmine.createSpy().andCallFake(function(dirEntry) { + // returning confirms existence so just check fullPath entry + expect(dirEntry).toBeDefined(); + expect(dirEntry.fullPath).toBe(srcPath); + + runs(function() { + dirEntry.getFile(file1, {create:false}, itFileExists, fail); + }); + + waitsFor(function() { return itFileExists.wasCalled; }, "itFileExists never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(itFileExists).toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }), + itFileExists = jasmine.createSpy().andCallFake(function(fileEntry) { + expect(fileEntry).toBeDefined(); + expect(fileEntry.fullPath).toBe(filePath); + + // cleanup + deleteEntry(srcDir); + }); + + // create a new directory entry to kick off it + runs(function() { + createDirectory(srcDir, entryCallback, fail); + }); + + waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT); + }); + it("moveTo: directory into itself", function() { + var srcDir = "entry.move.dis.srcDir", + dstDir = "entry.move.dis.dstDir", + srcPath = root.fullPath + '/' + srcDir, + win = createWin('Entry'), + fail = createFail('Entry'), + entryCallback = jasmine.createSpy().andCallFake(function(directory) { + // move source directory into itself + runs(function() { + directory.moveTo(directory, dstDir, win, itMove); + }); + + waitsFor(function() { return itMove.wasCalled; }, "itMove never called", Tests.TEST_TIMEOUT); + }), + itMove = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.INVALID_MODIFICATION_ERR); + // make sure original directory still exists + runs(function() { + root.getDirectory(srcDir, {create:false}, itDirectoryExists, fail); + }); + + waitsFor(function() { return itDirectoryExists.wasCalled; }, "itDirectoryExists never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(fail).not.toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + expect(itDirectoryExists).toHaveBeenCalled(); + }); + }), + itDirectoryExists = jasmine.createSpy().andCallFake(function(entry) { + expect(entry).toBeDefined(); + expect(entry.fullPath).toBe(srcPath); + + // cleanup + deleteEntry(srcDir); + }); + + // create a new directory entry to kick off it + runs(function() { + createDirectory(srcDir, entryCallback, fail); + }); + + waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT); + }); + it("moveTo: file onto itself", function() { + var file1 = "entry.move.fos.file1", + filePath = root.fullPath + '/' + file1, + win = createWin('Entry'), + fail = createFail('Entry'), + entryCallback = jasmine.createSpy().andCallFake(function(entry) { + // move file1 onto itself + runs(function() { + entry.moveTo(root, null, win, itMove); + }); + + waitsFor(function() { return itMove.wasCalled; }, "itMove never called", Tests.TEST_TIMEOUT); + }), + itMove = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.INVALID_MODIFICATION_ERR); + + //it that original file still exists + runs(function() { + root.getFile(file1, {create:false}, itFileExists, fail); + }); + + waitsFor(function() { return itFileExists.wasCalled; }, "itFileExists never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(itFileExists).toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }), + itFileExists = jasmine.createSpy().andCallFake(function(fileEntry) { + expect(fileEntry).toBeDefined(); + expect(fileEntry.fullPath).toBe(filePath); - // cleanup - that.deleteEntry(file1); - QUnit.start(); - }; - - // create a new file entry to kick off test - this.createFile(file1, entryCallback, this.fail); - }); - test("Entry.moveTo: file onto existing directory", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(6); - - var file1 = "entry.move.fod.file1", - dstDir = "entry.move.fod.dstDir", - subDir = "subDir", - dirPath = this.root.fullPath + '/' + dstDir + '/' + subDir, - filePath = this.root.fullPath + '/' + file1, - that = this, - entryCallback = function(entry) { - var createSubDirectory = function(directory) { - var moveFile = function(subDirectory) { - var testMove = function(error) { - ok(typeof error !== 'undefined' && error !== null, "it is an error to move a file onto an existing directory"); - equal(error.code, FileError.INVALID_MODIFICATION_ERR, "error code should be FileError.INVALID_MODIFICATION_ERR"); - // test that original dir still exists - directory.getDirectory(subDir, {create:false}, testDirectoryExists, null); + // cleanup + deleteEntry(file1); + }); + + // create a new file entry to kick off it + runs(function() { + createFile(file1, entryCallback, fail); + }); + + waitsFor(function() { return entryCallback.wasCalled; }, "entryCAllback never called", Tests.TEST_TIMEOUT); + }); + it("moveTo: file onto existing directory", function() { + var file1 = "entry.move.fod.file1", + dstDir = "entry.move.fod.dstDir", + subDir = "subDir", + dirPath = root.fullPath + '/' + dstDir + '/' + subDir, + filePath = root.fullPath + '/' + file1, + win = createWin('Entry'), + fail = createFail('Entry'), + entryCallback = function(entry) { + var createSubDirectory = function(directory) { + var moveFile = function(subDirectory) { + var itMove = function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.INVALID_MODIFICATION_ERR); + // check that original dir still exists + directory.getDirectory(subDir, {create:false}, itDirectoryExists, fail); + }; + // move file1 onto sub-directory + entry.moveTo(directory, subDir, win, itMove); }; - // move file1 onto sub-directory - entry.moveTo(directory, subDir, null, testMove); + // create sub-directory + directory.getDirectory(subDir, {create: true}, moveFile, fail); }; - // create sub-directory - directory.getDirectory(subDir, {create: true}, moveFile, that.fail); - }; - // create top level directory - that.root.getDirectory(dstDir, {create: true}, createSubDirectory, that.fail); - }, - testDirectoryExists = function(dirEntry) { - ok(typeof dirEntry !== 'undefined' && dirEntry !== null, "original directory contents should exist."); - equals(dirEntry.fullPath, dirPath, "entry 'fullPath' should be set correctly"); - // test that original file still exists - that.root.getFile(file1, {create:false},testFileExists, null); - }, - testFileExists = function(fileEntry) { - ok(typeof fileEntry !== 'undefined' && fileEntry !== null, "original directory contents should exist."); - equals(fileEntry.fullPath, filePath, "entry 'fullPath' should be set correctly"); - - // cleanup - that.deleteEntry(file1); - that.deleteEntry(dstDir); - QUnit.start(); - }; - - // ensure destination directory is cleaned up before test - this.deleteEntry(dstDir, function() { - // create a new file entry to kick off test - that.createFile(file1, entryCallback, that.fail); - }, this.fail); - }); - test("Entry.moveTo: directory onto existing file", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(6); - - var file1 = "entry.move.dof.file1", - srcDir = "entry.move.dof.srcDir", - dirPath = this.root.fullPath + '/' + srcDir, - filePath = this.root.fullPath + '/' + file1, - that = this, - entryCallback = function(entry) { + // create top level directory + root.getDirectory(dstDir, {create: true}, createSubDirectory, fail); + }, + itDirectoryExists = function(dirEntry) { + expect(dirEntry).toBeDefined(); + expect(dirEntry.fullPath).toBe(dirPath); + // check that original file still exists + root.getFile(file1, {create:false},itFileExists, fail); + }, + itFileExists = jasmine.createSpy().andCallFake(function(fileEntry) { + expect(fileEntry).toBeDefined(); + expect(fileEntry.fullPath).toBe(filePath); + + // cleanup + deleteEntry(file1); + deleteEntry(dstDir); + }); + + // ensure destination directory is cleaned up before it + runs(function() { + deleteEntry(dstDir, function() { + // create a new file entry to kick off it + createFile(file1, entryCallback, fail); + }, fail); + }); + + waitsFor(function() { return itFileExists.wasCalled; }, "itFileExists never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(itFileExists).toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("moveTo: directory onto existing file", function() { + var file1 = "entry.move.dof.file1", + srcDir = "entry.move.dof.srcDir", + dirPath = root.fullPath + '/' + srcDir, + filePath = root.fullPath + '/' + file1, + win = createWin('Entry'), + fail = createFail('Entry'), + entryCallback = function(entry) { var moveDir = function(fileEntry) { // move directory onto file - entry.moveTo(that.root, file1, null, testMove); + entry.moveTo(root, file1, win, itMove); }; - // create file - that.root.getFile(file1, {create: true}, moveDir, that.fail); - }, - testMove = function(error) { - ok(typeof error !== 'undefined' && error !== null, "it is an error to move a directory onto an existing file"); - equal(error.code, FileError.INVALID_MODIFICATION_ERR, "error code should be FileError.INVALID_MODIFICATION_ERR"); - // test that original directory exists - that.root.getDirectory(srcDir, {create:false}, testDirectoryExists, null); - }, - testDirectoryExists = function(dirEntry) { - // returning confirms existence so just check fullPath entry - ok(typeof dirEntry !== 'undefined' && dirEntry !== null, "original directory should exist."); - equals(dirEntry.fullPath, dirPath, "entry 'fullPath' should be set correctly"); - // test that original file exists - that.root.getFile(file1, {create:false}, testFileExists, null); - }, - testFileExists = function(fileEntry) { - ok(typeof fileEntry !== 'undefined' && fileEntry !== null, "original directory contents should exist."); - equals(fileEntry.fullPath, filePath, "entry 'fullPath' should be set correctly"); - + // create file + root.getFile(file1, {create: true}, moveDir, fail); + }, + itMove = function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.INVALID_MODIFICATION_ERR); + // it that original directory exists + root.getDirectory(srcDir, {create:false}, itDirectoryExists, fail); + }, + itDirectoryExists = function(dirEntry) { + // returning confirms existence so just check fullPath entry + expect(dirEntry).toBeDefined(); + expect(dirEntry.fullPath).toBe(dirPath); + // it that original file exists + root.getFile(file1, {create:false}, itFileExists, fail); + }, + itFileExists = jasmine.createSpy().andCallFake(function(fileEntry) { + expect(fileEntry).toBeDefined(); + expect(fileEntry.fullPath).toBe(filePath); - // cleanup - that.deleteEntry(file1); - that.deleteEntry(srcDir); - QUnit.start(); - }; - - // create a new directory entry to kick off test - this.createDirectory(srcDir, entryCallback, this.fail); - }); - test("Entry.copyTo: directory onto existing file", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(6); - - var file1 = "entry.copy.dof.file1", - srcDir = "entry.copy.dof.srcDir", - dirPath = this.root.fullPath + '/' + srcDir, - filePath = this.root.fullPath + '/' + file1, - that = this, - entryCallback = function(entry) { + // cleanup + deleteEntry(file1); + deleteEntry(srcDir); + }); + + // create a new directory entry to kick off it + runs(function() { + createDirectory(srcDir, entryCallback, fail); + }); + + waitsFor(function() { return itFileExists.wasCalled; }, "itFileExists never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(itFileExists).toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("copyTo: directory onto existing file", function() { + var file1 = "entry.copy.dof.file1", + srcDir = "entry.copy.dof.srcDir", + dirPath = root.fullPath + '/' + srcDir, + filePath = root.fullPath + '/' + file1, + win = createWin('Entry'), + fail = createFail('Entry'), + entryCallback = function(entry) { var copyDir = function(fileEntry) { // move directory onto file - entry.copyTo(that.root, file1, null, testMove); - }; - // create file - that.root.getFile(file1, {create: true}, copyDir, that.fail); - }, - testMove = function(error) { - ok(typeof error !== 'undefined' && error !== null, "it is an error to copy a directory onto an existing file"); - equal(error.code, FileError.INVALID_MODIFICATION_ERR, "error code should be FileError.INVALID_MODIFICATION_ERR"); - //test that original dir still exists - that.root.getDirectory(srcDir, {create:false}, testDirectoryExists, null); - }, - testDirectoryExists = function(dirEntry) { - // returning confirms existence so just check fullPath entry - ok(typeof dirEntry !== 'undefined' && dirEntry !== null, "original directory should exist."); - equals(dirEntry.fullPath, dirPath, "entry 'fullPath' should be set correctly"); - // test that original file still exists - that.root.getFile(file1, {create:false}, testFileExists, null); - }, - testFileExists = function(fileEntry) { - ok(typeof fileEntry !== 'undefined' && fileEntry !== null, "original directory contents should exist."); - equals(fileEntry.fullPath, filePath, "entry 'fullPath' should be set correctly"); - - // cleanup - that.deleteEntry(file1); - that.deleteEntry(srcDir); - QUnit.start(); - }; - - // create a new directory entry to kick off test - this.createDirectory(srcDir, entryCallback, this.fail); - }); - test("Entry.moveTo: directory onto directory that is not empty", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(6); - - var srcDir = "entry.move.dod.srcDir", - dstDir = "entry.move.dod.dstDir", - subDir = "subDir", - srcPath = this.root.fullPath + '/' + srcDir, - dstPath = this.root.fullPath + '/' + dstDir + '/' + subDir, - that = this, - entryCallback = function(entry) { - var createSubDirectory = function(directory) { - var moveDir = function(subDirectory) { - // move srcDir onto dstDir (not empty) - entry.moveTo(that.root, dstDir, null, testMove); + entry.copyTo(root, file1, win, itMove); }; - var testMove = function(error) { - ok(typeof error !== 'undefined' && error !== null, "it is an error to move a directory onto a directory that is not empty"); - equal(error.code, FileError.INVALID_MODIFICATION_ERR, "error code should be FileError.INVALID_MODIFICATION_ERR"); + // create file + root.getFile(file1, {create: true}, copyDir, fail); + }, + itMove = function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.INVALID_MODIFICATION_ERR); + //check that original dir still exists + root.getDirectory(srcDir, {create:false}, itDirectoryExists, fail); + }, + itDirectoryExists = function(dirEntry) { + // returning confirms existence so just check fullPath entry + expect(dirEntry).toBeDefined(); + expect(dirEntry.fullPath).toBe(dirPath); + // it that original file still exists + root.getFile(file1, {create:false}, itFileExists, fail); + }, + itFileExists = jasmine.createSpy().andCallFake(function(fileEntry) { + expect(fileEntry).toBeDefined(); + expect(fileEntry.fullPath).toBe(filePath); - // test that destination directory still exists - directory.getDirectory(subDir, {create:false}, testDirectoryExists, null); + // cleanup + deleteEntry(file1); + deleteEntry(srcDir); + }); + + // create a new directory entry to kick off it + runs(function() { + createDirectory(srcDir, entryCallback, fail); + }); + + waitsFor(function() { return itFileExists.wasCalled; }, "itFileExists never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(itFileExists).toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("moveTo: directory onto directory that is not empty", function() { + var srcDir = "entry.move.dod.srcDir", + dstDir = "entry.move.dod.dstDir", + subDir = "subDir", + srcPath = root.fullPath + '/' + srcDir, + dstPath = root.fullPath + '/' + dstDir + '/' + subDir, + win = createWin('Entry'), + fail = createFail('Entry'), + entryCallback = function(entry) { + var createSubDirectory = function(directory) { + var moveDir = function(subDirectory) { + // move srcDir onto dstDir (not empty) + entry.moveTo(root, dstDir, win, itMove); + }; + var itMove = function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.INVALID_MODIFICATION_ERR); + + // it that destination directory still exists + directory.getDirectory(subDir, {create:false}, itDirectoryExists, fail); + }; + // create sub-directory + directory.getDirectory(subDir, {create: true}, moveDir, fail); }; - // create sub-directory - directory.getDirectory(subDir, {create: true}, moveDir, that.fail); - }; - // create top level directory - that.root.getDirectory(dstDir, {create: true}, createSubDirectory, that.fail); - }, - testDirectoryExists = function(dirEntry) { - // returning confirms existence so just check fullPath entry - ok(typeof dirEntry !== 'undefined' && dirEntry !== null, "original directory should exist."); - equals(dirEntry.fullPath, dstPath, "entry 'fullPath' should be set correctly"); - // test that source directory exists - that.root.getDirectory(srcDir,{create:false}, testSrcDirectoryExists, null); - }, - testSrcDirectoryExists = function(srcEntry){ - ok(typeof srcEntry !== 'undefined' && srcEntry !== null, "original directory should exist."); - equals(srcEntry.fullPath, srcPath, "entry 'fullPath' should be set correctly"); - // cleanup - that.deleteEntry(srcDir); - that.deleteEntry(dstDir); - QUnit.start(); - }; - - // ensure destination directory is cleaned up before test - this.deleteEntry(dstDir, function() { - // create a new file entry to kick off test - that.createDirectory(srcDir, entryCallback, that.fail); - }, this.fail); - }); - test("Entry.moveTo: file replace existing file", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(9); - - var file1 = "entry.move.frf.file1", - file2 = "entry.move.frf.file2", - file1Path = this.root.fullPath + '/' + file1, - file2Path = this.root.fullPath + '/' + file2, - that = this, - entryCallback = function(entry) { + // create top level directory + root.getDirectory(dstDir, {create: true}, createSubDirectory, fail); + }, + itDirectoryExists = function(dirEntry) { + // returning confirms existence so just check fullPath entry + expect(dirEntry).toBeDefined(); + expect(dirEntry.fullPath).toBe(dstPath); + // it that source directory exists + root.getDirectory(srcDir,{create:false}, itSrcDirectoryExists, fail); + }, + itSrcDirectoryExists = jasmine.createSpy().andCallFake(function(srcEntry){ + expect(srcEntry).toBeDefined(); + expect(srcEntry.fullPath).toBe(srcPath); + // cleanup + deleteEntry(srcDir); + deleteEntry(dstDir); + }); + + // ensure destination directory is cleaned up before it + runs(function() { + deleteEntry(dstDir, function() { + // create a new file entry to kick off it + createDirectory(srcDir, entryCallback, fail); + }, fail); + }); + + waitsFor(function() { return itSrcDirectoryExists.wasCalled; }, "itSrcDirectoryExists never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(itSrcDirectoryExists).toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("moveTo: file replace existing file", function() { + var file1 = "entry.move.frf.file1", + file2 = "entry.move.frf.file2", + file1Path = root.fullPath + '/' + file1, + file2Path = root.fullPath + '/' + file2, + win = createWin('Entry'), + fail = createFail('Entry'), + entryCallback = function(entry) { var moveFile = function(fileEntry) { // replace file2 with file1 - entry.moveTo(that.root, file2, testMove, that.fail); + entry.moveTo(root, file2, itMove, fail); }; - // create file - that.root.getFile(file2, {create: true}, moveFile, that.fail); - }, - testMove = function(entry) { - ok(typeof entry !== 'undefined' && entry !== null, "file entry should not be null") - equals(entry.isFile, true, "entry 'isFile' attribute should be true"); - equals(entry.isDirectory, false, "entry 'isDirectory' attribute should be false"); - equals(entry.fullPath, file2Path, "entry 'fullPath' should be set correctly"); - equals(entry.name, file2, "entry 'name' attribute should be set correctly"); - - // test that old file does not exists - that.root.getFile(file1, {create:false}, null, testFileMoved); - }, - testFileMoved = function(error){ - ok(typeof error !== 'undefined' && error !== null, "it is an error if original file exists after a move"); - equal(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR"); - // test that new file exists - that.root.getFile(file2, {create:false}, testFileExists, null); - }, - testFileExists = function(fileEntry) { - ok(typeof fileEntry !== 'undefined' && fileEntry !== null, "original directory contents should exist."); - equals(fileEntry.fullPath, file2Path, "entry 'fullPath' should be set correctly"); - - // cleanup - that.deleteEntry(file1); - that.deleteEntry(file2); - QUnit.start(); - }; - - // create a new directory entry to kick off test - this.createFile(file1, entryCallback, this.fail); - }); - test("Entry.moveTo: directory replace empty directory", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(9); - - var file1 = "file1", - srcDir = "entry.move.drd.srcDir", - dstDir = "entry.move.drd.dstDir", - srcPath = this.root.fullPath + '/' + srcDir, - dstPath = this.root.fullPath + '/' + dstDir, - filePath = dstPath + '/' + file1, - that = this, - entryCallback = function(directory) { - var mkdir = function(fileEntry) { - // create destination directory - that.root.getDirectory(dstDir, {create: true}, moveDir, that.fail); - }; - var moveDir = function(fileEntry) { - // move srcDir to dstDir - directory.moveTo(that.root, dstDir, testMove, that.fail); - }; - // create a file within source directory - directory.getFile(file1, {create: true}, mkdir, that.fail); - }, - testMove = function(directory) { - ok(typeof directory !== 'undefined' && directory !== null, "new directory entry should not be null"); - equals(directory.isFile, false, "entry 'isFile' attribute should be false"); - equals(directory.isDirectory, true, "entry 'isDirectory' attribute should be true"); - equals(directory.fullPath, dstPath, "entry 'fullPath' should be set correctly"); - equals(directory.name, dstDir, "entry 'name' attribute should be set correctly"); - // test that old directory contents have been moved - directory.getFile(file1, {create:false}, testFileExists, null); - }, - testFileExists = function(fileEntry) { - ok(typeof fileEntry !== 'undefined' && fileEntry !== null, "original directory contents should exist."); - equals(fileEntry.fullPath, filePath, "entry 'fullPath' should be set correctly"); + // create file + root.getFile(file2, {create: true}, moveFile,fail); + }, + itMove = function(entry) { + expect(entry).toBeDefined(); + expect(entry.isFile).toBe(true); + expect(entry.isDirectory).toBe(false); + expect(entry.fullPath).toBe(file2Path); + expect(entry.name).toBe(file2); + + // it that old file does not exists + root.getFile(file1, {create:false}, win, itFileMoved); + }, + itFileMoved = function(error){ + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.NOT_FOUND_ERR); + // it that new file exists + root.getFile(file2, {create:false}, itFileExists, fail); + }, + itFileExists = jasmine.createSpy().andCallFake(function(fileEntry) { + expect(fileEntry).toBeDefined(); + expect(fileEntry.fullPath).toBe(file2Path); - // test that old directory no longer exists - that.root.getDirectory(srcDir, {create:false}, null, testRemoved); - }, - testRemoved = function(error){ - ok(typeof error !== 'undefined' && error !== null, "it is an error if original file exists after a move"); - equal(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR"); - - // cleanup - that.deleteEntry(srcDir); - that.deleteEntry(dstDir); - QUnit.start(); - }; - - // ensure destination directory is cleaned up before test - this.deleteEntry(dstDir, function() { - // create a new directory entry to kick off test - that.createDirectory(srcDir, entryCallback, that.fail); - }, this.fail); - }); - test("Entry.moveTo: directory that does not exist", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var file1 = "entry.move.dnf.file1", - dstDir = "entry.move.dnf.dstDir", - filePath = this.root.fullPath + '/' + file1, - dstPath = this.root.fullPath + '/' + dstDir, - that = this, - entryCallback = function(entry) { - // move file to directory that does not exist - directory = new DirectoryEntry(); - directory.fullPath = dstPath; - entry.moveTo(directory, null, null, testMove); - }, - testMove = function(error) { - ok(typeof error !== 'undefined' && error !== null, "it is an error to move to a directory that does not exist"); - equal(error.code, FileError.NOT_FOUND_ERR, "error code should be FileError.NOT_FOUND_ERR"); - - // cleanup - that.deleteEntry(file1); - QUnit.start(); - }; - - // create a new file entry to kick off test - this.createFile(file1, entryCallback, this.fail); - }); - test("Entry.moveTo: invalid target name", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var file1 = "entry.move.itn.file1", - file2 = "bad:file:name", - that = this, - filePath = this.root.fullPath + '/' + file1, - entryCallback = function(entry) { - // move file1 to file2 - entry.moveTo(that.root, file2, null, testMove); - }, - testMove = function(error) { - ok(typeof error !== 'undefined' && error !== null, "invalid file name should result in error"); - equal(error.code, FileError.ENCODING_ERR, "error code should be FileError.ENCODING_ERR"); - - // cleanup - that.deleteEntry(file1); - QUnit.start(); - }; - - // create a new file entry to kick off test - this.createFile(file1, entryCallback, this.fail); - }); - module('FileReader model'); - test("FileReader object should have correct methods", function() { - expect(6); - var reader = new FileReader(); - ok(reader !== null, "new FileReader() should not be null."); - ok(typeof reader.readAsBinaryString === 'function', "FileReader object should have a readAsBinaryString function."); - ok(typeof reader.readAsDataURL === 'function', "FileReader object should have a readAsDataURL function."); - ok(typeof reader.readAsText === 'function', "FileReader object should have a readAsText function."); - ok(typeof reader.readAsArrayBuffer === 'function', "FileReader object should have a readAsArrayBuffer function."); - ok(typeof reader.abort === 'function', "FileReader object should have an abort function."); - }); - module('FileReader read', { - setup: function() { - this.root = getFileSystemRoot(); - this.fail = function(error) { - console.log('file error: ' + error.code); - }; - } - }); - test("should read file properly, File object", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(1); + // cleanup + deleteEntry(file1); + deleteEntry(file2); + }); + + // create a new directory entry to kick off it + runs(function() { + createFile(file1, entryCallback, fail); + }); + + waitsFor(function() { return itFileExists.wasCalled; }, "itFileExists never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(itFileExists).toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("moveTo: directory replace empty directory", function() { + var file1 = "file1", + srcDir = "entry.move.drd.srcDir", + dstDir = "entry.move.drd.dstDir", + srcPath = root.fullPath + '/' + srcDir, + dstPath = root.fullPath + '/' + dstDir, + win = createWin('Entry'), + fail = createFail('Entry'), + filePath = dstPath + '/' + file1, + entryCallback = function(directory) { + var mkdir = function(fileEntry) { + // create destination directory + root.getDirectory(dstDir, {create: true}, moveDir, fail); + }; + var moveDir = function(fileEntry) { + // move srcDir to dstDir + directory.moveTo(root, dstDir, itMove, fail); + }; + // create a file within source directory + directory.getFile(file1, {create: true}, mkdir, fail); + }, + itMove = function(directory) { + expect(directory).toBeDefined(); + expect(directory.isFile).toBe(false); + expect(directory.isDirectory).toBe(true); + expect(directory.fullPath).toBe(dstPath); + expect(directory.name).toBe(dstDir); + // check that old directory contents have been moved + directory.getFile(file1, {create:false}, itFileExists, fail); + }, + itFileExists = function(fileEntry) { + expect(fileEntry).toBeDefined(); + expect(fileEntry.fullPath).toBe(filePath); + + // check that old directory no longer exists + root.getDirectory(srcDir, {create:false}, win, itRemoved); + }, + itRemoved = jasmine.createSpy().andCallFake(function(error){ + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.NOT_FOUND_ERR); + + // cleanup + deleteEntry(srcDir); + deleteEntry(dstDir); + }); + + // ensure destination directory is cleaned up before it + runs(function() { + deleteEntry(dstDir, function() { + // create a new directory entry to kick off it + createDirectory(srcDir, entryCallback, fail); + }, fail); + }); + + waitsFor(function() { return itRemoved.wasCalled; }, "itRemoved never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(itRemoved).toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("moveTo: directory that does not exist", function() { + var file1 = "entry.move.dnf.file1", + dstDir = "entry.move.dnf.dstDir", + filePath = root.fullPath + '/' + file1, + dstPath = root.fullPath + '/' + dstDir, + win = createWin('Entry'), + fail = createFail('Entry'), + entryCallback = function(entry) { + // move file to directory that does not exist + directory = new DirectoryEntry(); + directory.fullPath = dstPath; + entry.moveTo(directory, null, win, itMove); + }, + itMove = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.NOT_FOUND_ERR); + // cleanup + deleteEntry(file1); + }); + + // create a new file entry to kick off it + runs(function() { + createFile(file1, entryCallback, fail); + }); + + waitsFor(function() { return itMove.wasCalled; }, "itMove never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(itMove).toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("moveTo: invalid target name", function() { + var file1 = "entry.move.itn.file1", + file2 = "bad:file:name", + filePath = root.fullPath + '/' + file1, + win = createWin('Entry'), + fail = createFail('Entry'), + entryCallback = function(entry) { + // move file1 to file2 + entry.moveTo(root, file2, win, itMove); + }, + itMove = jasmine.createSpy().andCallFake(function(error) { + expect(error).toBeDefined(); + expect(error.code).toBe(FileError.ENCODING_ERR); + + // cleanup + deleteEntry(file1); + }); + + // create a new file entry to kick off it + runs(function() { + createFile(file1,entryCallback, fail); + }); + + waitsFor(function() { return itMove.wasCalled; }, "itMove never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(itMove).toHaveBeenCalled(); + expect(win).not.toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); + }); + + describe('FileReader', function() { + it("should have correct methods", function() { + var reader = new FileReader(); + expect(reader).toBeDefined(); + expect(typeof reader.readAsBinaryString).toBe('function'); + expect(typeof reader.readAsDataURL).toBe('function'); + expect(typeof reader.readAsText).toBe('function'); + expect(typeof reader.readAsArrayBuffer).toBe('function'); + expect(typeof reader.abort).toBe('function'); + }); + }); + + describe('read method', function(){ + it("should read file properly, File object", function() { // path of file - var fileName = "reader.txt", - filePath = this.root.fullPath + '/' + fileName; - // file content - rule = "There is an exception to every rule. Except this one.", - // creates a FileWriter object - create_writer = function(fileEntry) { - fileEntry.createWriter(write_file, this.fail); - }, - // writes file and reads it back in - write_file = function(writer) { - writer.onwriteend = read_file; - writer.write(rule); - }, - // reads file and compares content to what was written - read_file = function(evt) { - var reader = new FileReader(); - reader.onloadend = function(evt) { - console.log("read success"); - console.log(evt.target.result); - ok(evt.target.result === rule, "reader.result should be equal to the text written."); - QUnit.start(); + var fileName = "reader.txt", + // file content + rule = "There is an exception to every rule. Except this one.", + verifier = jasmine.createSpy().andCallFake(function(evt) { + expect(evt).toBeDefined(); + expect(evt.target.result).toBe(rule); + }), + fail = createFail('FileReader'), + filePath = root.fullPath + '/' + fileName; + // creates a FileWriter object + create_writer = function(fileEntry) { + fileEntry.createWriter(write_file, fail); + }, + // writes file and reads it back in + write_file = function(writer) { + writer.onwriteend = read_file; + writer.write(rule); + }, + // reads file and compares content to what was written + read_file = function(evt) { + var reader = new FileReader(); + reader.onloadend = verifier; + var myFile = new File(); + + myFile.fullPath = filePath; + reader.readAsText(myFile); }; - var myFile = new File(); - myFile.fullPath = filePath; - reader.readAsText(myFile); - }; - - // create a file, write to it, and read it in again - this.root.getFile(fileName, {create: true}, create_writer, this.fail); - }); - test("should read file properly in Chinese Traditional , File object", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(1); + // create a file, write to it, and read it in again + runs(function() { + root.getFile(fileName, {create: true}, create_writer, fail); + }); + + waitsFor(function() { return verifier.wasCalled; }, "verifier never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(fail).not.toHaveBeenCalled(); + expect(verifier).toHaveBeenCalled(); + }); + }); + it("should read empty file properly", function() { // path of file - var fileName = "reader.txt", - filePath = this.root.fullPath + '/' + fileName; - // file content - rule = "每個規則有一個例外。除了這一個", - // creates a FileWriter object - create_writer = function(fileEntry) { - fileEntry.createWriter(write_file, this.fail); - }, - // writes file and reads it back in - write_file = function(writer) { - writer.onwriteend = read_file; - writer.write(rule); - }, - // reads file and compares content to what was written - read_file = function(evt) { - var reader = new FileReader(); - reader.onloadend = function(evt) { - console.log("read success"); - console.log(evt.target.result); - ok(evt.target.result === rule, "reader.result should be equal to the text written."); - QUnit.start(); + var fileName = "empty.txt", + filePath = root.fullPath + '/' + fileName; + // file content + rule = "", + fail = createFail('FileReader'), + verifier = jasmine.createSpy().andCallFake(function(evt) { + expect(evt).toBeDefined(); + expect(evt.target.result).toBe(rule); + }), + // reads file and compares content to what was written + read_file = function(evt) { + var reader = new FileReader(); + reader.onloadend = verifier; + var myFile = new File(); + myFile.fullPath = filePath; + reader.readAsText(myFile); }; - var myFile = new File(); - myFile.fullPath = filePath; - reader.readAsText(myFile); - }; - - // create a file, write to it, and read it in again - this.root.getFile(fileName, {create: true}, create_writer, this.fail); - }); - - test("should read empty file properly", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(1); - // path of file - var fileName = "empty.txt", - filePath = this.root.fullPath + '/' + fileName; - // file content - rule = "", - // reads file and compares content to what was written - read_file = function(evt) { - var reader = new FileReader(); - reader.onloadend = function(evt) { - console.log("read success"); - console.log(evt.target.result); - ok(evt.target.result === rule, "reader.result should be equal to the empty string."); - QUnit.start(); - }; - var myFile = new File(); - myFile.fullPath = filePath; + // create a file, write to it, and read it in again + runs(function() { + root.getFile(fileName, {create: true}, read_file, fail); + }); + + waitsFor(function() { return verifier.wasCalled; }, "verifier never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(fail).not.toHaveBeenCalled(); + expect(verifier).toHaveBeenCalled(); + }); + }); + it("should error out on non-existent file", function() { + var reader = new FileReader(); + var verifier = jasmine.createSpy().andCallFake(function(evt) { + expect(evt).toBeDefined(); + expect(evt.target.error.code).toBe(FileError.NOT_FOUND_ERR); + }); + reader.onerror = verifier; + var myFile = new File(); + myFile.fullPath = root.fullPath + '/' + "doesnotexist.err"; + + runs(function() { reader.readAsText(myFile); - }; - - // create a file, write to it, and read it in again - this.root.getFile(fileName, {create: true}, read_file, this.fail); - }); - test("should error out on non-existent file", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(1); - - var reader = new FileReader(); - reader.onerror = function(evt) { - console.log("Properly got a file error as no file exists."); - ok(evt.target.error.code === 1, "Should throw a NOT_FOUND_ERR."); - QUnit.start(); - } - var myFile = new File(); - myFile.fullPath = this.root.fullPath + '/' + "doesnotexist.err"; - reader.readAsText(myFile); - }); - test("should read file properly, Data URL", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(1); - + }); + + waitsFor(function() { return verifier.wasCalled; }, "verifier never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(verifier).toHaveBeenCalled(); + }); + }); + it("should read file properly, Data URL", function() { // path of file - var fileName = "reader.txt", - filePath = this.root.fullPath + '/' + fileName; - // file content - rule = "There is an exception to every rule. Except this one.", - // creates a FileWriter object - create_writer = function(fileEntry) { - fileEntry.createWriter(write_file, this.fail); - }, - // writes file and reads it back in - write_file = function(writer) { - writer.onwriteend = read_file; - writer.write(rule); - }, - // reads file and compares content to what was written - read_file = function(evt) { - var reader = new FileReader(); - reader.onloadend = function(evt) { - console.log("read success"); - console.log(evt.target.result); - ok(evt.target.result.substr(0,23) === "data:text/plain;base64,", "reader.result should be base64 encoded."); - QUnit.start(); - }; - var myFile = new File(); - myFile.fullPath = filePath; - reader.readAsDataURL(myFile); - }; - - // create a file, write to it, and read it in again - this.root.getFile(fileName, {create: true}, create_writer, this.fail); - }); - module('FileWriter model', { - // setup function will run before each test - setup: function() { - var that = this; - this.root = getFileSystemRoot(); - this.fail = function(error) { - console.log('file error: ' + error.code); - }; - // deletes file, if it exists, then invokes callback - this.deleteFile = function(fileName, callback) { - that.root.getFile(fileName, null, - // remove file system entry - function(entry) { - entry.remove(callback, that.fail); - }, - // doesn't exist - callback); - }; - // deletes and re-creates the specified file, then invokes callback - this.createFile = function(fileName, callback) { - // creates file - var create_file = function() { - that.root.getFile(fileName, {create: true}, callback, that.fail); + var fileName = "reader.txt", + filePath = root.fullPath + '/' + fileName, + fail = createFail('FileReader'), + // file content + rule = "There is an exception to every rule. Except this one.", + // creates a FileWriter object + create_writer = function(fileEntry) { + fileEntry.createWriter(write_file, fail); + }, + // writes file and reads it back in + write_file = function(writer) { + writer.onwriteend = read_file; + writer.write(rule); + }, + verifier = jasmine.createSpy().andCallFake(function(evt) { + expect(evt).toBeDefined(); + expect(evt.target.result.substr(0,23)).toBe("data:text/plain;base64,"); + }), + // reads file and compares content to what was written + read_file = function(evt) { + var reader = new FileReader(); + reader.onloadend = verifier; + var myFile = new File(); + myFile.fullPath = filePath; + reader.readAsDataURL(myFile); }; - - // deletes file, then re-creates it - that.deleteFile(fileName, create_file); - }; - } - }); - test("FileWriter object should have correct methods", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(5); - - // retrieve a FileWriter object - var fileName = "writer.methods", - that = this, - test_writer = function(fileEntry) { - fileEntry.createWriter(function(writer) { - ok(typeof writer !== 'undefined' && writer !== null, "FileEntry.createWriter should return a FileWriter object."); - ok(typeof writer.write === 'function', "FileWriter object should have a write function."); - ok(typeof writer.seek === 'function', "FileWriter object should have a seek function."); - ok(typeof writer.truncate === 'function', "FileWriter object should have a truncate function."); - ok(typeof writer.abort === 'function', "FileWriter object should have an abort function."); + + // create a file, write to it, and read it in again + runs(function() { + root.getFile(fileName, {create: true}, create_writer, fail); + }); + + waitsFor(function() { return verifier.wasCalled; }, "verifier never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(fail).not.toHaveBeenCalled(); + expect(verifier).toHaveBeenCalled(); + }); + }); + }); + + describe('FileWriter', function(){ + it("should have correct methods", function() { + // retrieve a FileWriter object + var fileName = "writer.methods", + fail = createFail('FileWriter'), + verifier = jasmine.createSpy().andCallFake(function(writer) { + expect(writer).toBeDefined(); + expect(typeof writer.write).toBe('function'); + expect(typeof writer.seek).toBe('function'); + expect(typeof writer.truncate).toBe('function'); + expect(typeof writer.abort).toBe('function'); // cleanup - that.deleteFile(fileName); - QUnit.start(); - }, this.fail); - }; + deleteFile(fileName); + }), + it_writer = function(fileEntry) { + fileEntry.createWriter(verifier, fail); + }; - // test FileWriter - this.root.getFile(fileName, {create: true}, test_writer, this.fail); - }); - test("should be able to write and append to file, createWriter", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(4); - - var that = this, - fileName = "writer.append", - filePath = this.root.fullPath + '/' + fileName, - // file content - rule = "There is an exception to every rule.", - // for testing file length - length = rule.length, - // writes initial file content - write_file = function(fileEntry) { - fileEntry.createWriter(function(writer) { - writer.onwriteend = function(evt) { - ok(writer.length === length, "should have written " + length + " bytes"); - ok(writer.position === length, "position should be at " + length); - append_file(writer); - }; - writer.write(rule); - }, that.fail); - }, - // appends to file - append_file = function(writer) { - var exception = " Except this one."; - writer.onwriteend = function(evt) { - ok(writer.length === length, "file length should be " + length); - ok(writer.position === length, "position should be at " + length); + // it FileWriter + runs(function() { + root.getFile(fileName, {create: true}, it_writer, fail); + }); + + waitsFor(function() { return verifier.wasCalled; }, "verifier never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(fail).not.toHaveBeenCalled(); + expect(verifier).toHaveBeenCalled(); + }); + }); + it("should be able to write and append to file, createWriter", function() { + var fileName = "writer.append", + theWriter, + filePath = root.fullPath + '/' + fileName, + // file content + rule = "There is an exception to every rule.", + // for checkin file length + length = rule.length, + fail = createFail('FileWriter'), + verifier = jasmine.createSpy().andCallFake(function(evt) { + expect(theWriter.length).toBe(length); + expect(theWriter.position).toBe(length); + + // append some more stuff + var exception = " Except this one."; + theWriter.onwriteend = anotherVerifier; + length += exception.length; + theWriter.seek(theWriter.length); + theWriter.write(exception); + }), + anotherVerifier = jasmine.createSpy().andCallFake(function(evt) { + expect(theWriter.length).toBe(length); + expect(theWriter.position).toBe(length); // cleanup - that.deleteFile(fileName); - QUnit.start(); + deleteFile(fileName); + }), + // writes initial file content + write_file = function(fileEntry) { + fileEntry.createWriter(function(writer) { + theWriter = writer; + writer.onwriteend = verifier; + writer.write(rule); + }, fail); }; - length += exception.length; - writer.seek(writer.length); - writer.write(exception); - }; - - // create file, then write and append to it - this.createFile(fileName, write_file); - }); - test("should be able to write and append to file in Chinese Traditional, createWriter", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(4); - - var that = this, - fileName = "writer.append", - filePath = this.root.fullPath + '/' + fileName, - // file content - rule = "每個規則有一個例外。", - // for testing file length - length = rule.length, - // writes initial file content - write_file = function(fileEntry) { - fileEntry.createWriter(function(writer) { - writer.onwriteend = function(evt) { - ok(writer.length === length, "should have written " + length + " bytes"); - ok(writer.position === length, "position should be at " + length); - append_file(writer); - }; - writer.write(rule); - }, that.fail); - }, - // appends to file - append_file = function(writer) { - var exception = " 除了這一個"; - writer.onwriteend = function(evt) { - ok(writer.length === length, "file length should be " + length); - ok(writer.position === length, "position should be at " + length); + + // create file, then write and append to it + runs(function() { + createFile(fileName, write_file); + }); + + waitsFor(function() { return anotherVerifier.wasCalled; }, "verifier never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(fail).not.toHaveBeenCalled(); + expect(verifier).toHaveBeenCalled(); + expect(anotherVerifier).toHaveBeenCalled(); + }); + }); + it("should be able to write and append to file, File object", function() { + var fileName = "writer.append", + theWriter, + filePath = root.fullPath + '/' + fileName, + // file content + rule = "There is an exception to every rule.", + // for checking file length + length = rule.length, + verifier = jasmine.createSpy().andCallFake(function(evt) { + expect(theWriter.length).toBe(length); + expect(theWriter.position).toBe(length); + + // append some more stuff + var exception = " Except this one."; + theWriter.onwriteend = anotherVerifier; + length += exception.length; + theWriter.seek(theWriter.length); + theWriter.write(exception); + }), + anotherVerifier = jasmine.createSpy().andCallFake(function(evt) { + expect(theWriter.length).toBe(length); + expect(theWriter.position).toBe(length); // cleanup - that.deleteFile(fileName); - QUnit.start(); + deleteFile(fileName); + }), + // writes initial file content + write_file = function(file) { + theWriter = new FileWriter(file); + theWriter.onwriteend = verifier; + theWriter.write(rule); }; - length += exception.length; - writer.seek(writer.length); - writer.write(exception); - }; - - // create file, then write and append to it - this.createFile(fileName, write_file); - }); - - test("should be able to write and append to file, File object", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(4); - - var that = this, - fileName = "writer.append", - filePath = this.root.fullPath + '/' + fileName, - // file content - rule = "There is an exception to every rule.", - // for testing file length - length = rule.length, - // writes initial file content - write_file = function(file) { - var writer = new FileWriter(file); - writer.onwriteend = function(evt) { - ok(writer.length === length, "should have written " + length + " bytes"); - ok(writer.position === length, "position should be at " + length); - append_file(writer); - }; - writer.write(rule); - }, - // appends to file - append_file = function(writer) { - var exception = " Except this one."; - writer.onwriteend = function(evt) { - ok(writer.length === length, "file length should be " + length); - ok(writer.position === length, "position should be at " + length); + + // create file, then write and append to it + runs(function() { + var file = new File(); + file.fullPath = filePath; + write_file(file); + }); + + waitsFor(function() { return anotherVerifier.wasCalled; }, "verifier", Tests.TEST_TIMEOUT); + + runs(function() { + expect(verifier).toHaveBeenCalled(); + expect(anotherVerifier).toHaveBeenCalled(); + }); + }); + it("should be able to seek to the middle of the file and write more data than file.length", function() { + var fileName = "writer.seek.write", + filePath = root.fullPath + '/' + fileName, + theWriter, + // file content + rule = "This is our sentence.", + // for iting file length + length = rule.length, + fail = createFail('FileWriter'), + verifier = jasmine.createSpy().andCallFake(function(evt) { + expect(theWriter.length).toBe(length); + expect(theWriter.position).toBe(length); + + // append some more stuff + var exception = "newer sentence."; + theWriter.onwriteend = anotherVerifier; + length = 12 + exception.length; + theWriter.seek(12); + theWriter.write(exception); + }), + anotherVerifier = jasmine.createSpy().andCallFake(function(evt) { + expect(theWriter.length).toBe(length); + expect(theWriter.position).toBe(length); // cleanup - that.deleteFile(fileName); - QUnit.start(); + deleteFile(fileName); + }), + // writes initial file content + write_file = function(fileEntry) { + fileEntry.createWriter(function(writer) { + theWriter = writer; + theWriter.onwriteend = verifier; + theWriter.write(rule); + }, fail); }; - length += exception.length; - writer.seek(writer.length); - writer.write(exception); - }; - - // create file, then write and append to it - var file = new File(); - file.fullPath = filePath; - write_file(file); - }); - test("should be able to seek to the middle of the file and write more data than file.length", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(4); - - var that = this, - fileName = "writer.seek.write", - filePath = this.root.fullPath + '/' + fileName, - // file content - rule = "This is our sentence.", - // for testing file length - length = rule.length, - // writes initial file content - write_file = function(fileEntry) { - fileEntry.createWriter(function(writer) { - writer.onwriteend = function(evt) { - ok(writer.length === length, "should have written " + length + " bytes"); - ok(writer.position === length, "position should be at " + length); - append_file(writer); - }; - writer.write(rule); - }, that.fail); - }, - // appends to file - append_file = function(writer) { - var exception = "newer sentence."; - writer.onwriteend = function(evt) { - ok(writer.length === length, "file length should be " + length); - ok(writer.position === length, "position should be at " + length); + + // create file, then write and append to it + runs(function() { + createFile(fileName, write_file); + }); + + waitsFor(function() { return anotherVerifier.wasCalled; }, "verifier never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(verifier).toHaveBeenCalled(); + expect(anotherVerifier).toHaveBeenCalled(); + }); + }); + it("should be able to seek to the middle of the file and write less data than file.length", function() { + var fileName = "writer.seek.write2", + filePath = root.fullPath + '/' + fileName, + // file content + rule = "This is our sentence.", + theWriter, + fail = createFail('FileWriter'), + // for iting file length + length = rule.length, + verifier = jasmine.createSpy().andCallFake(function(evt) { + expect(theWriter.length).toBe(length); + expect(theWriter.position).toBe(length); + + // append some more stuff + var exception = "new."; + theWriter.onwriteend = anotherVerifier; + length = 8 + exception.length; + theWriter.seek(8); + theWriter.write(exception); + }), + anotherVerifier = jasmine.createSpy().andCallFake(function(evt) { + expect(theWriter.length).toBe(length); + expect(theWriter.position).toBe(length); // cleanup - that.deleteFile(fileName); - QUnit.start(); + deleteFile(fileName); + }), + // writes initial file content + write_file = function(fileEntry) { + fileEntry.createWriter(function(writer) { + theWriter = writer; + theWriter.onwriteend = verifier; + theWriter.write(rule); + }, fail); }; - length = 12 + exception.length; - writer.seek(12); - writer.write(exception); - }; - - // create file, then write and append to it - this.createFile(fileName, write_file); - }); - test("should be able to seek to the middle of the file and write less data than file.length", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(4); - - var that = this, - fileName = "writer.seek.write2", - filePath = this.root.fullPath + '/' + fileName, - // file content - rule = "This is our sentence.", - // for testing file length - length = rule.length, - // writes initial file content - write_file = function(fileEntry) { - fileEntry.createWriter(function(writer) { - writer.onwriteend = function(evt) { - ok(writer.length === length, "should have written " + length + " bytes"); - ok(writer.position === length, "position should be at " + length); - append_file(writer); - }; - writer.write(rule); - }, that.fail); - }, - // appends to file - append_file = function(writer) { - var exception = "new."; - writer.onwriteend = function(evt) { - ok(writer.length === length, "file length should be " + length); - ok(writer.position === length, "position should be at " + length); + + // create file, then write and append to it + runs(function() { + createFile(fileName, write_file); + }); + + waitsFor(function() { return anotherVerifier.wasCalled; }, "verifier never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(verifier).toHaveBeenCalled(); + expect(anotherVerifier).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("should be able to write XML data", function() { + var fileName = "writer.xml", + filePath = root.fullPath + '/' + fileName, + fail = createFail('FileWriter'), + theWriter, + // file content + rule = '\n\nData\n\n', + // for iting file length + length = rule.length, + verifier = jasmine.createSpy().andCallFake(function(evt) { + expect(theWriter.length).toBe(length); + expect(theWriter.position).toBe(length); // cleanup - that.deleteFile(fileName); - QUnit.start(); + deleteFile(fileName); + }), + // writes file content + write_file = function(fileEntry) { + fileEntry.createWriter(function(writer) { + theWriter = writer; + theWriter.onwriteend = verifier; + theWriter.write(rule); + }, fail); }; - length = 8 + exception.length; - writer.seek(8); - writer.write(exception); - }; - - // create file, then write and append to it - this.createFile(fileName, write_file); - }); - test("should be able to write XML data", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var that = this, - fileName = "writer.xml", - filePath = this.root.fullPath + '/' + fileName, - // file content - rule = '\n\nData\n\n', - // for testing file length - length = rule.length, - // writes file content - write_file = function(fileEntry) { - fileEntry.createWriter(function(writer) { - writer.onwriteend = function(evt) { - ok(writer.length === length, "should have written " + length + " bytes"); - ok(writer.position === length, "position should be at " + length); + + // creates file, then write XML data + runs(function() { + createFile(fileName, write_file); + }); + + waitsFor(function() { return verifier.wasCalled; }, "verifier", Tests.TEST_TIMEOUT); + + runs(function() { + expect(verifier).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("should be able to write JSON data", function() { + var fileName = "writer.json", + filePath = root.fullPath + '/' + fileName, + theWriter, + // file content + rule = '{ "name": "Guy Incognito", "email": "here@there.com" }', + fail = createFail('FileWriter'), + // for iting file length + length = rule.length, + verifier = jasmine.createSpy().andCallFake(function(evt) { + expect(theWriter.length).toBe(length); + expect(theWriter.position).toBe(length); - // cleanup - that.deleteFile(fileName); - QUnit.start(); - }; - writer.write(rule); - }, that.fail); - }; + // cleanup + deleteFile(fileName); + }), + // writes file content + write_file = function(fileEntry) { + fileEntry.createWriter(function(writer) { + theWriter = writer; + theWriter.onwriteend = verifier; + theWriter.write(rule); + }, fail); + }; - // creates file, then write XML data - this.createFile(fileName, write_file); - }); - test("should be able to write JSON data", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var that = this, - fileName = "writer.json", - filePath = this.root.fullPath + '/' + fileName, - // file content - rule = '{ "name": "Guy Incognito", "email": "here@there.com" }', - // for testing file length - length = rule.length, - // writes file content - write_file = function(fileEntry) { - fileEntry.createWriter(function(writer) { - writer.onwriteend = function(evt) { - ok(writer.length === length, "should have written " + length + " bytes"); - ok(writer.position === length, "position should be at " + length); - - // cleanup - that.deleteFile(fileName); - QUnit.start(); - }; - writer.write(rule); - }, that.fail); - }; - - // creates file, then write JSON content - this.createFile(fileName, write_file); - }); - test("should write and read special characters", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(1); - - var that = this, - // path of file - fileName = "reader.txt", - filePath = this.root.fullPath + '/' + fileName, - // file content - rule = "H\u00EBll\u00F5 Euro \u20AC\u00A1", - // creates a FileWriter object - create_writer = function(fileEntry) { - fileEntry.createWriter(write_file, this.fail); - }, - // writes file and reads it back in - write_file = function(writer) { - writer.onwriteend = read_file; - writer.write(rule); - }, - // reads file and compares content to what was written - read_file = function(evt) { - var reader = new FileReader(); - reader.onloadend = function(evt) { - console.log("read success"); - console.log(evt.target.result); - ok(evt.target.result === rule, "reader.result should be equal to the text written."); + // creates file, then write JSON content + runs(function() { + createFile(fileName, write_file); + }); + + waitsFor(function() { return verifier.wasCalled; }, "verifier", Tests.TEST_TIMEOUT); + + runs(function() { + expect(verifier).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("should write and read special characters", function() { + var fileName = "reader.txt", + filePath = root.fullPath + '/' + fileName, + theWriter, + // file content + rule = "H\u00EBll\u00F5 Euro \u20AC\u00A1", + fail = createFail('FileWriter'), + // creates a FileWriter object + create_writer = function(fileEntry) { + fileEntry.createWriter(write_file, fail); + }, + verifier = jasmine.createSpy().andCallFake(function(evt) { + expect(evt).toBeDefined(); + expect(evt.target.result).toBe(rule); // cleanup - that.deleteFile(fileName); - QUnit.start(); + deleteFile(fileName); + }), + // writes file and reads it back in + write_file = function(writer) { + theWriter = writer; + theWriter.onwriteend = read_file; + theWriter.write(rule); + }, + // reads file and compares content to what was written + read_file = function(evt) { + var reader = new FileReader(); + reader.onloadend = verifier; + var myFile = new File(); + myFile.fullPath = filePath; + reader.readAsText(myFile); }; - var myFile = new File(); - myFile.fullPath = filePath; - reader.readAsText(myFile); - }; - - // create a file, write to it, and read it in again - this.createFile(fileName, create_writer, this.fail); - }); - test("should be able to seek", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(5); - - var that = this, - fileName = "writer.seek", - // file content - rule = "There is an exception to every rule. Except this one.", - // for testing file length - length = rule.length, - // writes file content and tests writer.seek - seek_file = function(fileEntry) { - fileEntry.createWriter(function(writer) { - writer.onwriteend = function(evt) { - ok(writer.position == length, "position should be at " + length); - writer.seek(-5); - ok(writer.position == (length-5), "position should be at " + (length-5)); - writer.seek(100); - ok(writer.position == length, "position should be at " + length); - writer.seek(10); - ok(writer.position == 10, "position should be at 10"); - // cleanup - that.deleteFile(fileName); - QUnit.start(); - }; - writer.seek(-100); - ok(writer.position == 0, "position should be at 0"); - writer.write(rule); - }, that.fail); - }; - - // creates file, then write JSON content - this.createFile(fileName, seek_file); - }); - test("should be able to truncate", function() { - QUnit.stop(Tests.TEST_TIMEOUT); - expect(2); - - var that = this, - fileName = "writer.truncate", - rule = "There is an exception to every rule. Except this one.", - // writes file content - write_file = function(fileEntry) { - fileEntry.createWriter(function(writer) { - writer.onwriteend = function(evt) { - truncate_file(writer); - }; - writer.write(rule); - }, that.fail); - }, - // and tests writer.truncate - truncate_file = function(writer) { - writer.onwriteend = function(evt) { - ok(writer.length == 36, "file length should be 36"); - ok(writer.position == 36, "position should be at 36"); + // create a file, write to it, and read it in again + runs(function() { + createFile(fileName, create_writer, fail); + }); + + waitsFor(function() { return verifier.wasCalled; }, "verifier never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(verifier).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("should be able to seek", function() { + var fileName = "writer.seek", + // file content + rule = "There is an exception to every rule. Except this one.", + theWriter, + // for iting file length + length = rule.length, + fail = createFail('FileWriter'), + verifier = jasmine.createSpy().andCallFake(function(evt) { + expect(theWriter.position).toBe(length); + theWriter.seek(-5); + expect(theWriter.position).toBe(length-5); + theWriter.seek(length + 100); + expect(theWriter.position).toBe(length); + theWriter.seek(10); + expect(theWriter.position).toBe(10); + + // cleanup + deleteFile(fileName); + }), + // writes file content and its writer.seek + seek_file = function(fileEntry) { + fileEntry.createWriter(function(writer) { + theWriter = writer; + theWriter.onwriteend = verifier; + theWriter.seek(-100); + expect(theWriter.position).toBe(0); + theWriter.write(rule); + }, fail); + }; + + // creates file, then write JSON content + runs(function() { + createFile(fileName, seek_file); + }); + + waitsFor(function() { return verifier.wasCalled; }, "verifier never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(verifier).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("should be able to truncate", function() { + var fileName = "writer.truncate", + rule = "There is an exception to every rule. Except this one.", + fail = createFail('FileWRiter'), + theWriter, + // writes file content + write_file = function(fileEntry) { + fileEntry.createWriter(function(writer) { + theWriter = writer; + theWriter.onwriteend = function(evt) { + truncate_file(theWriter); + }; + theWriter.write(rule); + }, fail); + }, + verifier = jasmine.createSpy().andCallFake(function(evt) { + expect(theWriter.length).toBe(36); + expect(theWriter.position).toBe(36); // cleanup - that.deleteFile(fileName); - QUnit.start(); - }; - writer.truncate(36); - }; - - // creates file, writes to it, then truncates it - this.createFile(fileName, write_file); + deleteFile(fileName); + }), + // and its writer.truncate + truncate_file = function(writer) { + writer.onwriteend = verifier; + writer.truncate(36); + }; + + // creates file, writes to it, then truncates it + runs(function() { + createFile(fileName, write_file); + }); + + waitsFor(function() { return verifier.wasCalled; }, "verifier never called", Tests.TEST_TIMEOUT); + + runs(function() { + expect(verifier).toHaveBeenCalled(); + expect(fail).not.toHaveBeenCalled(); + }); + }); }); -}; +}); diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/geolocation.tests.js b/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/geolocation.tests.js index 7890b40f..718d582e 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/geolocation.tests.js +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/geolocation.tests.js @@ -1,90 +1,100 @@ -Tests.prototype.GeoLocationTests = function() { - module('Geolocation (navigator.geolocation)'); - test("should exist", function() { - expect(1); - ok(navigator.geolocation != null, "navigator.geolocation should not be null."); +describe('Geolocation (navigator.geolocation)', function () { + it("should exist", function() { + expect(navigator.geolocation).toBeDefined(); }); - test("should contain a getCurrentPosition function", function() { - expect(2); - ok(typeof navigator.geolocation.getCurrentPosition != 'undefined' && navigator.geolocation.getCurrentPosition != null, "navigator.geolocation.getCurrentPosition should not be null."); - ok(typeof navigator.geolocation.getCurrentPosition == 'function', "navigator.geolocation.getCurrentPosition should be a function."); + + it("should contain a getCurrentPosition function", function() { + expect(typeof navigator.geolocation.getCurrentPosition).toBeDefined(); + expect(typeof navigator.geolocation.getCurrentPosition == 'function').toBe(true); }); - test("should contain a watchPosition function", function() { - expect(2); - ok(typeof navigator.geolocation.watchPosition != 'undefined' && navigator.geolocation.watchPosition != null, "navigator.geolocation.watchPosition should not be null."); - ok(typeof navigator.geolocation.watchPosition == 'function', "navigator.geolocation.watchPosition should be a function."); + + it("should contain a watchPosition function", function() { + expect(typeof navigator.geolocation.watchPosition).toBeDefined(); + expect(typeof navigator.geolocation.watchPosition == 'function').toBe(true); }); - test("should contain a clearWatch function", function() { - expect(2); - ok(typeof navigator.geolocation.clearWatch != 'undefined' && navigator.geolocation.clearWatch != null, "navigator.geolocation.watchPosition should not be null."); - ok(typeof navigator.geolocation.clearWatch == 'function', "navigator.geolocation.clearWatch should be a function."); + + it("should contain a clearWatch function", function() { + expect(typeof navigator.geolocation.clearWatch).toBeDefined(); + expect(typeof navigator.geolocation.clearWatch == 'function').toBe(true); }); - test("getCurrentPosition success callback should be called with a Position object", function() { - expect(2); - QUnit.stop(15000); - var win = function(p) { - ok(p.coords != null, "Position object returned in getCurrentPosition success callback has a 'coords' property."); - ok(p.timestamp != null, "Position object returned in getCurrentPosition success callback has a 'timestamp' property."); - QUnit.start(); - }; - var fail = function() { - ok(false, "Error callback fired, test failed."); - QUnit.start(); - }; - navigator.geolocation.getCurrentPosition(win, fail, { - maximumAge:300000 // 5 minutes maximum age of cached position - }); + + it("getCurrentPosition success callback should be called with a Position object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(p.coords).not.toBe(null); + expect(p.timestamp).not.toBe(null); + }), + fail = jasmine.createSpy(); + + runs(function () { + navigator.geolocation.getCurrentPosition(win, fail, { + maximumAge:300000 // 5 minutes maximum age of cached position + }); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); }); - test("getCurrentPosition success callback should be called with a cached Position", function() { - expect(1); - QUnit.stop(Tests.TEST_TIMEOUT); - var win = function(p) { - ok(p.coords instanceof Position, "Position object returned is an instance of Position"); - QUnit.start(); - }; - var fail = function(e) { - ok(false, "Error callback called, test failed."); - }; - navigator.geolocation.getCurrentPosition(win, fail, { - maximumAge:300000 // 5 minutes - }); - }); - test("getCurrentPosition error callback should be called if we set timeout to 0 and maximumAge to a very small number", function() { - expect(1); - QUnit.stop(Tests.TEST_TIMEOUT); - var win = function(p) { - ok(false, "success callback called, test failed."); - QUnit.start(); - }; - var fail = function(e) { - ok(true, "error callback called"); - QUnit.start(); - }; - navigator.geolocation.getCurrentPosition(win, fail, { - maximumAge: 0, - timeout: 0 + + it("getCurrentPosition success callback should be called with a cached Position", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(p.coords instanceof Position).toBe(true); + }), + fail = jasmine.createSpy(); + + runs(function () { + navigator.geolocation.getCurrentPosition(win, fail, { + maximumAge:300000 // 5 minutes + }); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + + it("getCurrentPosition error callback should be called if we set timeout to 0 and maximumAge to a very small number", function() { + var win = jasmine.createSpy(), + fail = jasmine.createSpy(); + + runs(function () { + navigator.geolocation.getCurrentPosition(win, fail, { + maximumAge: 0, + timeout: 0 + }); + }); + + waitsFor(function () { return fail.wasCalled; }, "fail never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(win).not.toHaveBeenCalled(); + }); }); - }); + // TODO: Need to test error callback... how? // TODO: Need to test watchPosition success callback, test that makes sure clearPosition works (how to test that a timer is getting cleared?) - module('Geolocation model'); - test("should be able to define a Position object with coords and timestamp properties", function() { - expect(3); - var pos = new Position({}, new Date()); - ok(pos != null, "new Position() should not be null."); - ok(typeof pos.coords != 'undefined' && pos.coords != null, "new Position() should include a 'coords' property."); - ok(typeof pos.timestamp != 'undefined' && pos.timestamp != null, "new Position() should include a 'timestamp' property."); - }); - test("should be able to define a Coordinates object with latitude, longitude, accuracy, altitude, heading, speed and altitudeAccuracy properties", function() { - expect(8); - var coords = new Coordinates(1,2,3,4,5,6,7); - ok(coords != null, "new Coordinates() should not be null."); - ok(typeof coords.latitude != 'undefined' && coords.latitude != null, "new Coordinates() should include a 'latitude' property."); - ok(typeof coords.longitude != 'undefined' && coords.longitude != null, "new Coordinates() should include a 'longitude' property."); - ok(typeof coords.accuracy != 'undefined' && coords.accuracy != null, "new Coordinates() should include a 'accuracy' property."); - ok(typeof coords.altitude != 'undefined' && coords.altitude != null, "new Coordinates() should include a 'altitude' property."); - ok(typeof coords.heading != 'undefined' && coords.heading != null, "new Coordinates() should include a 'heading' property."); - ok(typeof coords.speed != 'undefined' && coords.speed != null, "new Coordinates() should include a 'speed' property."); - ok(typeof coords.altitudeAccuracy != 'undefined' && coords.altitudeAccuracy != null, "new Coordinates() should include a 'altitudeAccuracy' property."); - }); -}; + describe("Geolocation model", function () { + it("should be able to define a Position object with coords and timestamp properties", function() { + var pos = new Position({}, new Date()); + expect(pos).toBeDefined(); + expect(pos.coords).toBeDefined(); + expect(pos.timestamp).toBeDefined(); + }); + + it("should be able to define a Coordinates object with latitude, longitude, accuracy, altitude, heading, speed and altitudeAccuracy properties", function() { + var coords = new Coordinates(1,2,3,4,5,6,7); + expect(coords).toBeDefined(); + expect(coords.latitude).toBeDefined(); + expect(coords.longitude).toBeDefined(); + expect(coords.accuracy).toBeDefined(); + expect(coords.altitude).toBeDefined(); + expect(coords.heading).toBeDefined(); + expect(coords.speed).toBeDefined(); + expect(coords.altitudeAccuracy).toBeDefined(); + }); + }); +}); diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/media.tests.js b/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/media.tests.js index cf6ded41..d0e6c4f2 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/media.tests.js +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/media.tests.js @@ -1,152 +1,144 @@ -Tests.prototype.MediaTests = function() { - module('Media'); - test("should exist", function() { - expect(1); - ok(typeof Media === "function" || typeof Media === "object", "'Media' should be defined as a function in global scope."); +describe('Media', function () { + it("should exist", function() { + expect(Media).toBeDefined(); + expect(typeof Media).toBe("function"); }); - test("should have the following properties", function() { + + it("should have the following properties", function() { var media1 = new Media("dummy"); - expect(4); - ok(typeof media1.id != 'undefined' && media1.id != null, "'Media' should have an id property."); - ok(typeof media1.src != 'undefined', "'Media' should have an src property."); - ok(typeof media1._duration != 'undefined' && media1._duration != null, "'Media' should have an _duration property."); - ok(typeof media1._position != 'undefined' && media1._position != null, "'Media' should have an _position property."); + expect(media1.id).toBeDefined(); + expect(media1.src).toBeDefined(); + expect(media1._duration).toBeDefined(); + expect(media1._position).toBeDefined(); media1.release(); }); - test("should define constants for Media errors", function() { - expect(6); - ok(MediaError != null && typeof MediaError != 'undefined', "MediaError object exists in global scope."); - equals(MediaError.MEDIA_ERR_NONE_ACTIVE, 0, "MediaError.MEDIA_ERR_NONE_ACTIVE is equal to 0."); - equals(MediaError.MEDIA_ERR_ABORTED, 1, "MediaError.MEDIA_ERR_ABORTED is equal to 1."); - equals(MediaError.MEDIA_ERR_NETWORK, 2, "MediaError.MEDIA_ERR_NETWORK is equal to 2."); - equals(MediaError.MEDIA_ERR_DECODE, 3, "MediaError.MEDIA_ERR_DECODE is equal to 3."); - equals(MediaError.MEDIA_ERR_NONE_SUPPORTED, 4, "MediaError.MEDIA_ERR_NONE_SUPPORTED is equal to 4."); + + it("should define constants for Media errors", function() { + expect(MediaError).toBeDefined(); + expect(MediaError.MEDIA_ERR_NONE_ACTIVE).toBe(0); + expect(MediaError.MEDIA_ERR_ABORTED).toBe(1); + expect(MediaError.MEDIA_ERR_NETWORK).toBe(2); + expect(MediaError.MEDIA_ERR_DECODE).toBe(3); + expect(MediaError.MEDIA_ERR_NONE_SUPPORTED).toBe(4); }); - test("should contain a play function", function() { + + it("should contain a play function", function() { var media1 = new Media(); - expect(2); - ok(typeof media1.play != 'undefined' && media1.play != null, "Media.play should not be null."); - ok(typeof media1.play == 'function', "Media.play should be a function."); + expect(media1.play).toBeDefined(); + expect(typeof media1.play).toBe('function'); media1.release(); }); - test("should contain a stop function", function() { + + it("should contain a stop function", function() { var media1 = new Media(); - expect(2); - ok(typeof media1.stop != 'undefined' && media1.stop != null, "Media.stop should not be null."); - ok(typeof media1.stop == 'function', "Media.stop should be a function."); + expect(media1.stop).toBeDefined(); + expect(typeof media1.stop).toBe('function'); media1.release(); }); - test("should contain a seekTo function", function() { + + it("should contain a seekTo function", function() { var media1 = new Media(); - expect(2); - ok(typeof media1.seekTo != 'undefined' && media1.seekTo != null, "Media.seekTo should not be null."); - ok(typeof media1.seekTo == 'function', "Media.seekTo should be a function."); + expect(media1.seekTo).toBeDefined(); + expect(typeof media1.seekTo).toBe('function'); media1.release(); }); - test("should contain a pause function", function() { + + it("should contain a pause function", function() { var media1 = new Media(); - expect(2); - ok(typeof media1.pause != 'undefined' && media1.pause != null, "Media.pause should not be null."); - ok(typeof media1.pause == 'function', "Media.pause should be a function."); + expect(media1.pause).toBeDefined(); + expect(typeof media1.pause).toBe('function'); media1.release(); }); - test("should contain a getDuration function", function() { + + it("should contain a getDuration function", function() { var media1 = new Media(); - expect(2); - ok(typeof media1.getDuration != 'undefined' && media1.getDuration != null, "Media.getDuration should not be null."); - ok(typeof media1.getDuration == 'function', "Media.getDuration should be a function."); + expect(media1.getDuration).toBeDefined(); + expect(typeof media1.getDuration).toBe('function'); media1.release(); }); - test("should contain a getCurrentPosition function", function() { + + it("should contain a getCurrentPosition function", function() { var media1 = new Media(); - expect(2); - ok(typeof media1.getCurrentPosition != 'undefined' && media1.getCurrentPosition != null, "Media.getCurrentPosition should not be null."); - ok(typeof media1.getCurrentPosition == 'function', "Media.getCurrentPosition should be a function."); + expect(media1.getCurrentPosition).toBeDefined(); + expect(typeof media1.getCurrentPosition).toBe('function'); media1.release(); }); - test("should contain a startRecord function", function() { + + it("should contain a startRecord function", function() { var media1 = new Media(); - expect(2); - ok(typeof media1.startRecord != 'undefined' && media1.startRecord != null, "Media.startRecord should not be null."); - ok(typeof media1.startRecord == 'function', "Media.startRecord should be a function."); + expect(media1.startRecord).toBeDefined(); + expect(typeof media1.startRecord).toBe('function'); media1.release(); }); - test("should contain a stopRecord function", function() { + + it("should contain a stopRecord function", function() { var media1 = new Media(); - expect(2); - ok(typeof media1.stopRecord != 'undefined' && media1.stopRecord != null, "Media.stopRecord should not be null."); - ok(typeof media1.stopRecord == 'function', "Media.stopRecord should be a function."); + expect(media1.stopRecord).toBeDefined(); + expect(typeof media1.stopRecord).toBe('function'); media1.release(); }); - test("should contain a release function", function() { + + it("should contain a release function", function() { var media1 = new Media(); - expect(2); - ok(typeof media1.release != 'undefined' && media1.release != null, "Media.release should not be null."); - ok(typeof media1.release == 'function', "Media.release should be a function."); + expect(media1.release).toBeDefined(); + expect(typeof media1.release).toBe('function'); media1.release(); }); - test("should contain a setVolume function", function() { + + it("should contain a setVolume function", function() { var media1 = new Media(); - expect(2); - ok(typeof media1.setVolume != 'undefined' && media1.setVolume != null, "Media.setVolume should not be null."); - ok(typeof media1.setVolume == 'function', "Media.setVolume should be a function."); + expect(media1.setVolume).toBeDefined(); + expect(typeof media1.setVolume).toBe('function'); media1.release(); }); - test("should return MediaError for bad filename", function() { - expect(2); - QUnit.stop(10000); - var badMedia = null; - var releaseMedia = function() { - badMedia.release(); - }; - var win = function() { - ok(0, "should NOT succeed with bad media file name"); - releaseMedia(); - QUnit.start(); - }; - var fail = function(result){ - ok(typeof result == 'object', "Object returned in media.play failure callback is of type 'object' (actually MediaError)."); - ok(result.code == MediaError.MEDIA_ERR_ABORTED, "Object returned in media.find failure callback has a code property which equal to MediaError.MEDIA_ERR_ABORTED"); - releaseMedia(); - QUnit.start(); - }; - badMedia = new Media("invalid.file.name", win,fail); - badMedia.play(); + + it("should return MediaError for bad filename", function() { + var badMedia = null, + win = jasmine.createSpy(), + fail = jasmine.createSpy().andCallFake(function (result) { + expect(result).toBeDefined(); + expect(result.code).toBe(MediaError.MEDIA_ERR_ABORTED); + }); + + runs(function () { + badMedia = new Media("invalid.file.name", win,fail); + badMedia.play(); + }); + + waitsFor(function () { return fail.wasCalled; }, Tests.TEST_TIMEOUT); + + runs(function () { + expect(win).not.toHaveBeenCalled(); + badMedia.release(); + }); }); - test("position should be set properly", function() { - var media1 = new Media("http://audio.ibeat.org/content/p1rj1s/p1rj1s_-_rockGuitar.mp3"); + + it("position should be set properly", function() { + var media1 = new Media("http://audio.ibeat.org/content/p1rj1s/p1rj1s_-_rockGuitar.mp3"), + test = jasmine.createSpy().andCallFake(function(position) { + console.log("position = " + position); + expect(position).toBeGreaterThan(0.0); + media1.stop() + media1.release(); + }); + media1.play(); - expect(1); - QUnit.stop(15000); - setTimeout( - function() { - media1.getCurrentPosition( - function(position) { - console.log("position = " + position); - ok(position >= 0.0, "position should not be -1"); - QUnit.start(); - media1.stop() - media1.release(); - }, - function(e) { - QUnit.start(); - } - ); - } - , 5000); + + waits(5000); + + runs(function () { + media1.getCurrentPosition(test, function () {}); + }); + + waitsFor(function () { return test.wasCalled; }, Tests.TEST_TIMEOUT); }); - test("duration should be set properly", function() { + + it("duration should be set properly", function() { var media1 = new Media("http://audio.ibeat.org/content/p1rj1s/p1rj1s_-_rockGuitar.mp3"); media1.play(); - expect(1); - QUnit.stop(15000); - setTimeout( - function() { - ok(media1.getDuration() >= 0.0, "duration should not be -1"); - QUnit.start(); - media1.stop() - media1.release(); - } - , 5000); + waits(5000); + runs(function () { + expect(media1.getDuration()).toBeGreaterThan(0.0); + }); }); -}; \ No newline at end of file +}); diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/network.tests.js b/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/network.tests.js index af87d731..780097f3 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/network.tests.js +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/network.tests.js @@ -1,26 +1,25 @@ -Tests.prototype.NetworkTests = function() { - module('Network (navigator.network)'); - test("should exist", function() { - expect(1); - ok(navigator.network != null, "navigator.network should not be null."); +describe('Network (navigator.network)', function () { + it("should exist", function() { + expect(navigator.network).toBeDefined(); }); - module('Network Information API'); - test("connection should exist", function() { - expect(1); - ok(navigator.network.connection != null, "navigator.network.connection should not be null."); + + describe('Network Information API', function () { + it("connection should exist", function() { + expect(navigator.network.connection).toBeDefined(); + }); + + it("should contain connection properties", function() { + expect(navigator.network.connection.type).toBeDefined(); + }); + + it("should define constants for connection status", function() { + expect(Connection.UNKNOWN).toBe("unknown"); + expect(Connection.ETHERNET).toBe("ethernet"); + expect(Connection.WIFI).toBe("wifi"); + expect(Connection.CELL_2G).toBe("2g"); + expect(Connection.CELL_3G).toBe("3g"); + expect(Connection.CELL_4G).toBe("4g"); + expect(Connection.NONE).toBe("none"); + }); }); - test("should contain connection properties", function() { - expect(1); - ok(typeof navigator.network.connection.type != 'undefined', "navigator.network.connection.type is defined."); - }); - test("should define constants for connection status", function() { - expect(7); - equals(Connection.UNKNOWN, "unknown", "Connection.UNKNOWN is equal to 'unknown'."); - equals(Connection.ETHERNET, "ethernet", "Connection.ETHERNET is equal to 'ethernet'."); - equals(Connection.WIFI, "wifi", "Connection.WIFI is equal to 'wifi'."); - equals(Connection.CELL_2G, "2g", "Connection.CELL_2G is equal to '2g'."); - equals(Connection.CELL_3G, "3g", "Connection.CELL_3G is equal to '3g'."); - equals(Connection.CELL_4G, "4g", "Connection.CELL_4G is equal to '4g'."); - equals(Connection.NONE, "none", "Connection.NONE is equal to 'none'."); - }); -}; \ No newline at end of file +}); diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/notification.tests.js b/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/notification.tests.js index 03e3885e..61c795db 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/notification.tests.js +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/notification.tests.js @@ -1,22 +1,20 @@ -Tests.prototype.NotificationTests = function() { - module('Notification (navigator.notification)'); - test("should exist", function() { - expect(1); - ok(navigator.notification != null, "navigator.notification should not be null."); +describe('Notification (navigator.notification)', function () { + it("should exist", function() { + expect(navigator.notification).toBeDefined(); }); - test("should contain a vibrate function", function() { - expect(2); - ok(typeof navigator.notification.vibrate != 'undefined' && navigator.notification.vibrate != null, "navigator.notification.vibrate should not be null."); - ok(typeof navigator.notification.vibrate == 'function', "navigator.notification.vibrate should be a function."); + + it("should contain a vibrate function", function() { + expect(typeof navigator.notification.vibrate).toBeDefined(); + expect(typeof navigator.notification.vibrate).toBe("function"); }); - test("should contain a beep function", function() { - expect(2); - ok(typeof navigator.notification.beep != 'undefined' && navigator.notification.beep != null, "navigator.notification.beep should not be null."); - ok(typeof navigator.notification.beep == 'function', "navigator.notification.beep should be a function."); + + it("should contain a beep function", function() { + expect(typeof navigator.notification.beep).toBeDefined(); + expect(typeof navigator.notification.beep).toBe("function"); }); - test("should contain a alert function", function() { - expect(2); - ok(typeof navigator.notification.alert != 'undefined' && navigator.notification.alert != null, "navigator.notification.alert should not be null."); - ok(typeof navigator.notification.alert == 'function', "navigator.notification.alert should be a function."); + + it("should contain a alert function", function() { + expect(typeof navigator.notification.alert).toBeDefined(); + expect(typeof navigator.notification.alert).toBe("function"); }); -}; \ No newline at end of file +}); diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/platform.tests.js b/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/platform.tests.js index 67fb28cf..6b1a0eda 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/platform.tests.js +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/platform.tests.js @@ -1,37 +1,35 @@ -Tests.prototype.PlatformTests = function() { - module('Platform (cordova)'); - test("should exist", function() { - expect(1); - ok(typeof cordova != 'undefined' && cordova != null, "cordova should not be null."); +describe('Platform (cordova)', function () { + it("should exist", function() { + expect(cordova).toBeDefined(); }); - module('Platform (Cordova)'); - test("should not exist", function() { - expect(1); - ok(typeof Cordova == 'undefined', "Cordova should be null."); + describe('Platform (Cordova)', function () { + it("should not exist", function() { + expect(window.Cordova).not.toBeDefined(); + }); }); - module('Platform (PhoneGap)'); - test("should exist", function() { - expect(1); - ok(typeof PhoneGap != 'undefined' && PhoneGap != null, "PhoneGap should not be null."); + describe('Platform (PhoneGap)', function () { + it("should exist", function() { + expect(PhoneGap).toBeDefined(); + }); + + it("exec method should exist", function() { + expect(PhoneGap.exec).toBeDefined(); + expect(typeof PhoneGap.exec).toBe('function'); + }); + + it("addPlugin method should exist", function() { + expect(PhoneGap.addPlugin).toBeDefined(); + expect(typeof PhoneGap.addPlugin).toBe('function'); + }); + + it("addConstructor method should exist", function() { + expect(PhoneGap.addConstructor).toBeDefined(); + expect(typeof PhoneGap.addConstructor).toBe('function'); + }); }); - test("exec method should exist", function() { - expect(2); - ok(typeof PhoneGap.exec != 'undefined' && PhoneGap.exec != null, "PhoneGap.exec should not be null."); - ok(typeof PhoneGap.exec == 'function', "PhoneGap.exec should be a function."); + describe('Platform (window.plugins)', function () { + it("should exist", function() { + expect(window.plugins).toBeDefined(); + }); }); - test("addPlugin method should exist", function() { - expect(2); - ok(typeof PhoneGap.addPlugin != 'undefined' && PhoneGap.addPlugin != null, "PhoneGap.addPlugin should not be null."); - ok(typeof PhoneGap.addPlugin == 'function', "PhoneGap.addPlugin should be a function."); - }); - test("addConstructor method should exist", function() { - expect(2); - ok(typeof PhoneGap.addConstructor != 'undefined' && PhoneGap.addConstructor != null, "PhoneGap.addConstructor should not be null."); - ok(typeof PhoneGap.addConstructor == 'function', "PhoneGap.addConstructor should be a function."); - }); - module('Platform (window.plugins)'); - test("should exist", function() { - expect(1); - ok(typeof window.plugins != 'undefined' && window.plugins != null, "window.plugins should not be null."); - }); -}; \ No newline at end of file +}); diff --git a/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/storage.tests.js b/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/storage.tests.js index 41476d84..a921de3b 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/storage.tests.js +++ b/lib/windows/tests/MobileSpecUnitTests/www/autotest/tests/storage.tests.js @@ -1,170 +1,161 @@ -Tests.prototype.StorageTests = function() -{ - module("Session Storage"); - test("should exist", function() { - expect(7); - ok(window.sessionStorage != null, "sessionStorage is defined"); - ok(typeof window.sessionStorage.length != 'undefined', "sessionStorage.length is defined"); - ok(typeof(window.sessionStorage.key) == "function", "sessionStorage.key is defined"); - ok(typeof(window.sessionStorage.getItem) == "function", "sessionStorage.getItem is defined"); - ok(typeof(window.sessionStorage.setItem) == "function", "sessionStorage.setItem is defined"); - ok(typeof(window.sessionStorage.removeItem) == "function", "sessionStorage.removeItem is defined"); - ok(typeof(window.sessionStorage.clear) == "function", "sessionStorage.clear is defined"); - }); - test("check length", function() { - expect(3); - ok(window.sessionStorage.length == 0, "length should be 0"); - window.sessionStorage.setItem("key","value"); - ok(window.sessionStorage.length == 1, "length should be 1"); - window.sessionStorage.removeItem("key"); - ok(window.sessionStorage.length == 0, "length should be 0"); - }); - test("check key", function() { - expect(3); - ok(window.sessionStorage.key(0) == null, "key should be null"); - window.sessionStorage.setItem("test","value"); - ok(window.sessionStorage.key(0) == "test", "key should be 'test'"); - window.sessionStorage.removeItem("test"); - ok(window.sessionStorage.key(0) == null, "key should be null"); - }); - test("check getItem", function() { - expect(3); - ok(window.sessionStorage.getItem("item") == null, "item should be null"); - window.sessionStorage.setItem("item","value"); - ok(window.sessionStorage.getItem("item") == "value", "The value of the item should be 'value'"); - window.sessionStorage.removeItem("item"); - ok(window.sessionStorage.getItem("item") == null, "item should be null"); - }); - test("check setItem", function() { - expect(4); - ok(window.sessionStorage.getItem("item") == null, "item should be null"); - window.sessionStorage.setItem("item","value"); - ok(window.sessionStorage.getItem("item") == "value", "The value of the item should be 'value'"); - window.sessionStorage.setItem("item","newval"); - ok(window.sessionStorage.getItem("item") == "newval", "The value of the item should be 'newval'"); - window.sessionStorage.removeItem("item"); - ok(window.sessionStorage.getItem("item") == null, "item should be null"); - }); - test("check removeItem", function() { - expect(3); - ok(window.sessionStorage.getItem("item") == null, "item should be null"); - window.sessionStorage.setItem("item","value"); - ok(window.sessionStorage.getItem("item") == "value", "The value of the item should be 'value'"); - window.sessionStorage.removeItem("item"); - ok(window.sessionStorage.getItem("item") == null, "item should be null"); - }); - test("check clear", function() { - expect(11); - ok(window.sessionStorage.getItem("item1") == null, "item1 should be null"); - ok(window.sessionStorage.getItem("item2") == null, "item2 should be null"); - ok(window.sessionStorage.getItem("item3") == null, "item3 should be null"); - window.sessionStorage.setItem("item1","value"); - window.sessionStorage.setItem("item2","value"); - window.sessionStorage.setItem("item3","value"); - ok(window.sessionStorage.getItem("item1") == "value", "item1 should be null"); - ok(window.sessionStorage.getItem("item2") == "value", "item2 should be null"); - ok(window.sessionStorage.getItem("item3") == "value", "item3 should be null"); - ok(window.sessionStorage.length == 3, "length should be 3"); - window.sessionStorage.clear(); - ok(window.sessionStorage.length == 0, "length should be 0"); - ok(window.sessionStorage.getItem("item1") == null, "item1 should be null"); - ok(window.sessionStorage.getItem("item2") == null, "item2 should be null"); - ok(window.sessionStorage.getItem("item3") == null, "item3 should be null"); - }); - test("check dot notation", function() { - expect(3); - ok(window.sessionStorage.item == null, "item should be null"); - window.sessionStorage.item = "value"; - ok(window.sessionStorage.item == "value", "The value of the item should be 'value'"); - window.sessionStorage.removeItem("item"); - ok(window.sessionStorage.item == null, "item should be null"); - }); - module("Local Storage"); - test("should exist", function() { - expect(7); - ok(window.localStorage != null, "localStorage is defined"); - ok(typeof window.localStorage.length != 'undefined', "localStorage.length is defined"); - ok(typeof(window.localStorage.key) == "function", "localStorage.key is defined"); - ok(typeof(window.localStorage.getItem) == "function", "localStorage.getItem is defined"); - ok(typeof(window.localStorage.setItem) == "function", "localStorage.setItem is defined"); - ok(typeof(window.localStorage.removeItem) == "function", "localStorage.removeItem is defined"); - ok(typeof(window.localStorage.clear) == "function", "localStorage.clear is defined"); - }); - test("check length", function() { - expect(3); - ok(window.localStorage.length == 0, "length should be 0"); - window.localStorage.setItem("key","value"); - ok(window.localStorage.length == 1, "length should be 1"); - window.localStorage.removeItem("key"); - ok(window.localStorage.length == 0, "length should be 0"); - }); - test("check key", function() { - expect(3); - ok(window.localStorage.key(0) == null, "key should be null"); - window.localStorage.setItem("test","value"); - ok(window.localStorage.key(0) == "test", "key should be 'test'"); - window.localStorage.removeItem("test"); - ok(window.localStorage.key(0) == null, "key should be null"); - }); - test("check getItem", function() { - expect(3); - ok(window.localStorage.getItem("item") == null, "item should be null"); - window.localStorage.setItem("item","value"); - ok(window.localStorage.getItem("item") == "value", "The value of the item should be 'value'"); - window.localStorage.removeItem("item"); - ok(window.localStorage.getItem("item") == null, "item should be null"); - }); - test("check setItem", function() { - expect(4); - ok(window.localStorage.getItem("item") == null, "item should be null"); - window.localStorage.setItem("item","value"); - ok(window.localStorage.getItem("item") == "value", "The value of the item should be 'value'"); - window.localStorage.setItem("item","newval"); - ok(window.localStorage.getItem("item") == "newval", "The value of the item should be 'newval'"); - window.localStorage.removeItem("item"); - ok(window.localStorage.getItem("item") == null, "item should be null"); - }); - test("check removeItem", function() { - expect(3); - ok(window.localStorage.getItem("item") == null, "item should be null"); - window.localStorage.setItem("item","value"); - ok(window.localStorage.getItem("item") == "value", "The value of the item should be 'value'"); - window.localStorage.removeItem("item"); - ok(window.localStorage.getItem("item") == null, "item should be null"); - }); - test("check clear", function() { - expect(11); - ok(window.localStorage.getItem("item1") == null, "item1 should be null"); - ok(window.localStorage.getItem("item2") == null, "item2 should be null"); - ok(window.localStorage.getItem("item3") == null, "item3 should be null"); - window.localStorage.setItem("item1","value"); - window.localStorage.setItem("item2","value"); - window.localStorage.setItem("item3","value"); - ok(window.localStorage.getItem("item1") == "value", "item1 should be null"); - ok(window.localStorage.getItem("item2") == "value", "item2 should be null"); - ok(window.localStorage.getItem("item3") == "value", "item3 should be null"); - ok(window.localStorage.length == 3, "length should be 3"); - window.localStorage.clear(); - ok(window.localStorage.length == 0, "length should be 0"); - ok(window.localStorage.getItem("item1") == null, "item1 should be null"); - ok(window.localStorage.getItem("item2") == null, "item2 should be null"); - ok(window.localStorage.getItem("item3") == null, "item3 should be null"); - }); - test("check dot notation", function() { - expect(3); - ok(window.localStorage.item == null, "item should be null"); - window.localStorage.item = "value"; - ok(window.localStorage.item == "value", "The value of the item should be 'value'"); - window.localStorage.removeItem("item"); - ok(window.localStorage.item == null, "item should be null"); - }); - module("HTML 5 Storage"); - test("should exist", function() { - expect(1); - ok(typeof(window.openDatabase) == "function", "Database is defined"); - }); - test("Should open a database", function() { - var db = openDatabase("Database", "1.0", "HTML5 Database API example", 200000); - ok(db != null, "Database should be opened"); - }); -} +describe("Session Storage", function () { + it("should exist", function () { + expect(window.sessionStorage).toBeDefined(); + expect(typeof window.sessionStorage.length).not.toBe('undefined'); + expect(typeof(window.sessionStorage.key)).toBe('function'); + expect(typeof(window.sessionStorage.getItem)).toBe('function'); + expect(typeof(window.sessionStorage.setItem)).toBe('function'); + expect(typeof(window.sessionStorage.removeItem)).toBe('function'); + expect(typeof(window.sessionStorage.clear)).toBe('function'); + }); + + it("check length", function () { + expect(window.sessionStorage.length).toBe(0); + window.sessionStorage.setItem("key","value"); + expect(window.sessionStorage.length).toBe(1); + window.sessionStorage.removeItem("key"); + expect(window.sessionStorage.length).toBe(0); + }); + + it("check key", function () { + expect(window.sessionStorage.key(0)).toBe(null); + window.sessionStorage.setItem("test","value"); + expect(window.sessionStorage.key(0)).toBe("test"); + window.sessionStorage.removeItem("test"); + expect(window.sessionStorage.key(0)).toBe(null); + }); + + it("check getItem", function() { + expect(window.sessionStorage.getItem("item")).toBe(null); + window.sessionStorage.setItem("item","value"); + expect(window.sessionStorage.getItem("item")).toBe("value"); + window.sessionStorage.removeItem("item"); + expect(window.sessionStorage.getItem("item")).toBe(null); + }); + + it("check setItem", function() { + expect(window.sessionStorage.getItem("item")).toBe(null); + window.sessionStorage.setItem("item","value"); + expect(window.sessionStorage.getItem("item")).toBe("value"); + window.sessionStorage.setItem("item","newval"); + expect(window.sessionStorage.getItem("item")).toBe("newval"); + window.sessionStorage.removeItem("item"); + expect(window.sessionStorage.getItem("item")).toBe(null); + }); + + it("can remove an item", function () { + expect(window.sessionStorage.getItem("item")).toBe(null); + window.sessionStorage.setItem("item","value"); + expect(window.sessionStorage.getItem("item")).toBe("value"); + window.sessionStorage.removeItem("item"); + expect(window.sessionStorage.getItem("item")).toBe(null); + }); + + it("check clear", function() { + window.sessionStorage.setItem("item1","value"); + window.sessionStorage.setItem("item2","value"); + window.sessionStorage.setItem("item3","value"); + expect(window.sessionStorage.length).toBe(3); + window.sessionStorage.clear(); + expect(window.sessionStorage.length).toBe(0); + }); + + it("check dot notation", function() { + expect(window.sessionStorage.item).not.toBeDefined(); + window.sessionStorage.item = "value"; + expect(window.sessionStorage.item).toBe("value"); + window.sessionStorage.removeItem("item"); + expect(window.sessionStorage.item).not.toBeDefined(); + }); + + describe("Local Storage", function () { + it("should exist", function() { + expect(window.localStorage).toBeDefined(); + expect(window.localStorage.length).toBeDefined(); + expect(typeof window.localStorage.key).toBe("function"); + expect(typeof window.localStorage.getItem).toBe("function"); + expect(typeof window.localStorage.setItem).toBe("function"); + expect(typeof window.localStorage.removeItem).toBe("function"); + expect(typeof window.localStorage.clear).toBe("function"); + }); + + it("check length", function() { + expect(window.localStorage.length).toBe(0); + window.localStorage.setItem("key","value"); + expect(window.localStorage.length).toBe(1); + window.localStorage.removeItem("key"); + expect(window.localStorage.length).toBe(0); + }); + + it("check key", function() { + expect(window.localStorage.key(0)).toBe(null); + window.localStorage.setItem("test","value"); + expect(window.localStorage.key(0)).toBe("test"); + window.localStorage.removeItem("test"); + expect(window.localStorage.key(0)).toBe(null); + }); + + it("check getItem", function() { + expect(window.localStorage.getItem("item")).toBe(null); + window.localStorage.setItem("item","value"); + expect(window.localStorage.getItem("item")).toBe("value"); + window.localStorage.removeItem("item"); + expect(window.localStorage.getItem("item")).toBe(null); + }); + + it("check setItem", function() { + expect(window.localStorage.getItem("item")).toBe(null); + window.localStorage.setItem("item","value"); + expect(window.localStorage.getItem("item")).toBe("value"); + window.localStorage.setItem("item","newval"); + expect(window.localStorage.getItem("item")).toBe("newval"); + window.localStorage.removeItem("item"); + expect(window.localStorage.getItem("item")).toBe(null); + }); + + it("check removeItem", function() { + expect(window.localStorage.getItem("item")).toBe(null); + window.localStorage.setItem("item","value"); + expect(window.localStorage.getItem("item")).toBe("value"); + window.localStorage.removeItem("item"); + expect(window.localStorage.getItem("item")).toBe(null); + }); + + it("check clear", function() { + expect(window.localStorage.getItem("item1")).toBe(null); + expect(window.localStorage.getItem("item2")).toBe(null); + expect(window.localStorage.getItem("item3")).toBe(null); + window.localStorage.setItem("item1","value"); + window.localStorage.setItem("item2","value"); + window.localStorage.setItem("item3","value"); + expect(window.localStorage.getItem("item1")).toBe("value"); + expect(window.localStorage.getItem("item2")).toBe("value"); + expect(window.localStorage.getItem("item3")).toBe("value"); + expect(window.localStorage.length).toBe(3); + window.localStorage.clear(); + expect(window.localStorage.length).toBe(0); + expect(window.localStorage.getItem("item1")).toBe(null); + expect(window.localStorage.getItem("item2")).toBe(null); + expect(window.localStorage.getItem("item3")).toBe(null); + }); + + it("check dot notation", function() { + expect(window.localStorage.item).not.toBeDefined(); + window.localStorage.item = "value"; + expect(window.localStorage.item).toBe("value"); + window.localStorage.removeItem("item"); + expect(window.localStorage.item).not.toBeDefined(); + }); + }); + + describe("HTML 5 Storage", function () { + it("should exist", function() { + expect(window.openDatabase); + }); + + it("Should open a database", function() { + var db = openDatabase("Database", "1.0", "HTML5 Database API example", 200000); + expect(db).toBeDefined(); + }); + }); +}); diff --git a/lib/windows/templates/full/www/cordova-1.6.1.js b/lib/windows/tests/MobileSpecUnitTests/www/cordova-1.6.1.js similarity index 100% rename from lib/windows/templates/full/www/cordova-1.6.1.js rename to lib/windows/tests/MobileSpecUnitTests/www/cordova-1.6.1.js diff --git a/lib/windows/tests/MobileSpecUnitTests/www/misc/index.html b/lib/windows/tests/MobileSpecUnitTests/www/misc/index.html index 023678d3..ce47b742 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/misc/index.html +++ b/lib/windows/tests/MobileSpecUnitTests/www/misc/index.html @@ -43,12 +43,18 @@

                                Display Other Content

                                Action

                                Call 411
                                +<<<<<<< HEAD + Send Mail + Send SMS + Load Web Site +======= Send Mail Send SMS Load Web Site +>>>>>>> fixed html errors, and various html tweaks, doctype,   javascript: - Load another PhoneGap page + Load another PhoneGap page

                                Android Only

                                Map IBM Search Android market diff --git a/lib/windows/tests/MobileSpecUnitTests/www/misc/page2.html b/lib/windows/tests/MobileSpecUnitTests/www/misc/page2.html index ee6c398d..c38e2c7a 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/misc/page2.html +++ b/lib/windows/tests/MobileSpecUnitTests/www/misc/page2.html @@ -20,6 +20,10 @@

                                Name:

                                Width: , Height: , Color Depth:

                                +<<<<<<< HEAD +
                                +=======
                                +>>>>>>> fixed html errors, and various html tweaks, doctype,   javascript: diff --git a/lib/windows/tests/MobileSpecUnitTests/www/phonegap.js b/lib/windows/tests/MobileSpecUnitTests/www/phonegap.js index 044a06b3..bba56008 100644 --- a/lib/windows/tests/MobileSpecUnitTests/www/phonegap.js +++ b/lib/windows/tests/MobileSpecUnitTests/www/phonegap.js @@ -1,6 +1,6 @@ -document.write(''); -document.write(''); -document.write(''); +document.write(''); +document.write(''); +document.write(''); function backHome() {