Merge branch 'CB-7133' of https://github.com/stacic/cordova-mobile-spec into CB-7086
diff --git a/www/accelerometer/index.html b/www/accelerometer/index.html
deleted file mode 100644
index 71000b8..0000000
--- a/www/accelerometer/index.html
+++ /dev/null
@@ -1,51 +0,0 @@
-<!DOCTYPE html>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software 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.
-
--->
-
-<html>
- <head>
- <meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,initial-scale=1.0" />
- <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <!-- ISO-8859-1 -->
- <title>Cordova Mobile Spec</title>
- <link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8">
- <script type="text/javascript" charset="utf-8" src="../cordova-incl.js"></script>
- <script type="text/javascript" charset="utf-8" src="./index.js"></script>
-
- </head>
- <body id="stage" class="theme">
-
- <h1>Acceleration</h1>
- <div id="info">
- <div id="accel_status">Stopped</div>
- <div ><table width="100%">
- <tr><td width="20%">X:</td><td id="x"> </td></tr>
- <tr><td width="20%">Y:</td><td id="y"> </td></tr>
- <tr><td width="20%">Z:</td><td id="z"> </td></tr>
- </table></div>
- </div>
-
- <h2>Action</h2>
- <div class="btn large getAccel">Get Acceleration</div>
- <div class="btn large watchAccel">Start Watch</div>
- <div class="btn large stopAccel">Clear Watch</div>
- <h2> </h2><div class="backBtn">Back</div>
- </body>
-</html>
diff --git a/www/accelerometer/index.js b/www/accelerometer/index.js
deleted file mode 100644
index 946cfe2..0000000
--- a/www/accelerometer/index.js
+++ /dev/null
@@ -1,111 +0,0 @@
-var deviceReady = false;
-
-function roundNumber(num) {
- var dec = 3;
- var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
- return result;
-}
-
-//-------------------------------------------------------------------------
-// Acceleration
-//-------------------------------------------------------------------------
-var watchAccelId = null;
-
-/**
- * Start watching acceleration
- */
-var watchAccel = function() {
- console.log("watchAccel()");
-
- // Success callback
- var success = function(a){
- document.getElementById('x').innerHTML = roundNumber(a.x);
- document.getElementById('y').innerHTML = roundNumber(a.y);
- document.getElementById('z').innerHTML = roundNumber(a.z);
- console.log("watchAccel success callback");
- };
-
- // Fail callback
- var fail = function(e){
- console.log("watchAccel fail callback with error code "+e);
- stopAccel();
- setAccelStatus(Accelerometer.ERROR_MSG[e]);
- };
-
- // Update acceleration every 1 sec
- var opt = {};
- opt.frequency = 1000;
- watchAccelId = navigator.accelerometer.watchAcceleration(success, fail, opt);
-
- setAccelStatus("Running");
-};
-
-/**
- * Stop watching the acceleration
- */
-var stopAccel = function() {
- console.log("stopAccel()");
- setAccelStatus("Stopped");
- if (watchAccelId) {
- navigator.accelerometer.clearWatch(watchAccelId);
- watchAccelId = null;
- }
-};
-
-/**
- * Get current acceleration
- */
-var getAccel = function() {
- console.log("getAccel()");
-
- // Stop accel if running
- stopAccel();
-
- // Success callback
- var success = function(a){
- document.getElementById('x').innerHTML = roundNumber(a.x);
- document.getElementById('y').innerHTML = roundNumber(a.y);
- document.getElementById('z').innerHTML = roundNumber(a.z);
- };
-
- // Fail callback
- var fail = function(e){
- console.log("getAccel fail callback with error code "+e);
- setAccelStatus(Accelerometer.ERROR_MSG[e]);
- };
-
- // Make call
- var opt = {};
- navigator.accelerometer.getCurrentAcceleration(success, fail, opt);
-};
-
-/**
- * Set accelerometer status
- */
-var setAccelStatus = function(status) {
- document.getElementById('accel_status').innerHTML = status;
-};
-
-/**
- * Function called when page has finished loading.
- */
-function init() {
- console.log("accelerometer.init()");
- document.addEventListener("deviceready", function() {
- deviceReady = true;
- console.log("Device="+device.platform+" "+device.version);
- }, false);
- window.setTimeout(function() {
- if (!deviceReady) {
- alert("Error: Apache Cordova did not initialize. Demo will not run correctly.");
- }
- },1000);
-}
-
-window.onload = function() {
- addListenerToClass('getAccel', getAccel);
- addListenerToClass('watchAccel', watchAccel);
- addListenerToClass('stopAccel', stopAccel);
- addListenerToClass('backBtn', backHome);
- init();
-}
diff --git a/www/audio/index.html b/www/audio/index.html
deleted file mode 100644
index a05ea04..0000000
--- a/www/audio/index.html
+++ /dev/null
@@ -1,88 +0,0 @@
-<!DOCTYPE html>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software 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.
-
--->
-
-
-<html>
- <head>
- <meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,initial-scale=1.0" />
- <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <!-- ISO-8859-1 -->
- <title>Cordova Audio Tests</title>
- <link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8"/>
- <script type="text/javascript" charset="utf-8" src="../cordova-incl.js"></script>
- <script type="text/javascript" charset="utf-8" src="./index.js"></script>
-
- </head>
- <body id="stage" class="theme">
-
- <h1>Audio</h1>
- <div id="info">
- <table width="100%">
- <tr><td><b>Status:</b></td><td id="audio_status"> </td></tr>
- <tr><td><b>Duration:</b></td><td id="audio_duration"></td></tr>
- <tr><td><b>Position:</b></td><td id="audio_position"></td></tr>
- </table>
- </div>
- <h2>Action</h2>
- <table style="width:80%;">
- <tr>
- <th colspan=3>Play Sample Audio</th>
- </tr>
- <tr>
- <td><div class="btn wide playAudio">Play</div></td>
- <td><div class="btn wide pauseAudio">Pause</div></td>
- </tr>
- <tr>
- <td><div class="btn wide stopAudio">Stop</div></td>
- <td><div class="btn wide releaseAudio">Release</div></td>
- </tr>
- </table>
-
- <table style="width:80%;">
- <tr>
- <td><div class="btn wide seekAudioBy">Seek By</div></td>
- <td><div class="btn wide seekAudioTo">Seek To</div></td>
- <td>
- <div>
- <input class="input numeric" type="number" id="seekinput" value="in seconds">
- </div>
- </td>
- </tr>
- </table>
-
- <table style="width:80%;">
- <tr>
- <th colspan=3><br><br>Record Audio</th>
- </tr>
- <tr>
- <td colspan=3><div class="btn wide recordAudio">Record Audio for 10 sec</a></td>
- </tr>
- <tr>
- <td><div class="btn wide playRecording">Play</div></td>
- <td><div class="btn wide pauseAudio">Pause</div></td>
- <td><div class="btn wide stopAudio">Stop</div></td>
- </tr>
- </table>
-
- <h2> </h2><div class="backBtn">Back</div>
-
- </body>
-</html>
diff --git a/www/audio/index.js b/www/audio/index.js
deleted file mode 100644
index e7ca9b6..0000000
--- a/www/audio/index.js
+++ /dev/null
@@ -1,356 +0,0 @@
-var defaultaudio = "http://cordova.apache.org/downloads/BlueZedEx.mp3";
-var deviceReady = false;
-
-//-------------------------------------------------------------------------
-// Audio player
-//-------------------------------------------------------------------------
-var media1 = null;
-var media1Timer = null;
-var audioSrc = null;
-var recordSrc = "myRecording.mp3";
-
-/**
- * Play audio
- */
-function playAudio(url) {
- console.log("playAudio()");
- console.log(" -- media="+media1);
-
- var src = defaultaudio;
-
- if (url) {
- src = url;
- }
-
- // Stop playing if src is different from currently playing source
- if (src != audioSrc) {
- if (media1 != null) {
- stopAudio();
- media1 = null;
- }
- }
-
- if (media1 == null) {
-
-
- // TEST STREAMING AUDIO PLAYBACK
- //var src = "http://nunzioweb.com/misc/Bon_Jovi-Crush_Mystery_Train.mp3"; // works
- //var src = "http://nunzioweb.com/misc/Bon_Jovi-Crush_Mystery_Train.m3u"; // doesn't work
- //var src = "http://www.wav-sounds.com/cartoon/bugsbunny1.wav"; // works
- //var src = "http://www.angelfire.com/fl5/html-tutorial/a/couldyou.mid"; // doesn't work
- //var src = "MusicSearch/mp3/train.mp3"; // works
- //var src = "bryce.mp3"; // works
- //var src = "/android_asset/www/bryce.mp3"; // works
-
- media1 = new Media(src,
- function() {
- console.log("playAudio():Audio Success");
- },
- function(err) {
- console.log("playAudio():Audio Error: "+err.code);
- setAudioStatus("Error: " + err.code);
- },
- function(status) {
- console.log("playAudio():Audio Status: "+status);
- setAudioStatus(Media.MEDIA_MSG[status]);
-
- // If stopped, then stop getting current position
- if (Media.MEDIA_STOPPED == status) {
- clearInterval(media1Timer);
- media1Timer = null;
- setAudioPosition("0 sec");
- }
- });
- }
- audioSrc = src;
- document.getElementById('audio_duration').innerHTML = "";
- // Play audio
- media1.play();
- if (media1Timer == null && media1.getCurrentPosition) {
- media1Timer = setInterval(
- function() {
- media1.getCurrentPosition(
- function(position) {
- console.log("Pos="+position);
- if (position >= 0.0) {
- setAudioPosition(position+" sec");
- }
- },
- function(e) {
- console.log("Error getting pos="+e);
- setAudioPosition("Error: "+e);
- }
- );
- },
- 1000
- );
- }
-
- // Get duration
- var counter = 0;
- var timerDur = setInterval(
- function() {
- counter = counter + 100;
- if (counter > 2000) {
- clearInterval(timerDur);
- }
- var dur = media1.getDuration();
- if (dur > 0) {
- clearInterval(timerDur);
- document.getElementById('audio_duration').innerHTML = dur + " sec";
- }
- }, 100);
-}
-
-/**
- * Pause audio playback
- */
-function pauseAudio() {
- console.log("pauseAudio()");
- if (media1) {
- media1.pause();
- }
-}
-
-/**
- * Stop audio
- */
-function stopAudio() {
- console.log("stopAudio()");
- if (media1) {
- media1.stop();
- }
- clearInterval(media1Timer);
- media1Timer = null;
-}
-
-/**
- * Release audio
- */
-function releaseAudio() {
- console.log("releaseAudio()");
- if (media1) {
- media1.stop(); //imlied stop of playback, resets timer
- media1.release();
- }
-}
-
-
-/**
- * Set audio status
- */
-function setAudioStatus(status) {
- document.getElementById('audio_status').innerHTML = status;
-};
-
-/**
- * Set audio position
- */
-function setAudioPosition(position) {
- document.getElementById('audio_position').innerHTML = position;
-};
-
-//-------------------------------------------------------------------------
-// Audio recorder
-//-------------------------------------------------------------------------
-var mediaRec = null;
-var recTime = 0;
-
-/**
- * Record audio
- */
-function recordAudio() {
- console.log("recordAudio()");
- console.log(" -- media="+mediaRec);
- if (mediaRec == null) {
-
- var src = recordSrc;
- mediaRec = new Media(src,
- function() {
- console.log("recordAudio():Audio Success");
- },
- function(err) {
- console.log("recordAudio():Audio Error: "+err.code);
- setAudioStatus("Error: " + err.code);
- },
- function(status) {
- console.log("recordAudio():Audio Status: "+status);
- setAudioStatus(Media.MEDIA_MSG[status]);
- }
- );
- }
-
- navigator.notification.beep(1);
-
- // Record audio
- mediaRec.startRecord();
-
- // Stop recording after 10 sec
- recTime = 0;
- var recInterval = setInterval(function() {
- recTime = recTime + 1;
- setAudioPosition(recTime+" sec");
- if (recTime >= 10) {
- clearInterval(recInterval);
- if (mediaRec.stopAudioRecord){
- mediaRec.stopAudioRecord();
- } else {
- mediaRec.stopRecord();
- }
- console.log("recordAudio(): stop");
- navigator.notification.beep(1);
- }
- }, 1000);
-}
-
-/**
- * Play back recorded audio
- */
-function playRecording() {
- playAudio(recordSrc);
-}
-
-/**
- * Function to create a file for iOS recording
- */
-function getRecordSrc() {
- var fsFail = function(error) {
- console.log("error creating file for iOS recording");
- };
- var gotFile = function(file) {
- recordSrc = file.fullPath;
- //console.log("recording Src: " + recordSrc);
- };
- var gotFS = function(fileSystem) {
- fileSystem.root.getFile("iOSRecording.wav", {create: true}, gotFile, fsFail);
- };
- window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, gotFS, fsFail);
-}
-
-/**
- * Function to create a file for BB recording
- */
-function getRecordSrcBB() {
- var fsFail = function(error) {
- console.log("error creating file for BB recording");
- };
- var gotFile = function(file) {
- recordSrc = file.fullPath;
- };
- var gotFS = function(fileSystem) {
- fileSystem.root.getFile("BBRecording.amr", {create: true}, gotFile, fsFail);
- };
- window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, gotFS, fsFail);
-}
-
-/**
- * Function called when page has finished loading.
- */
-function init() {
- document.addEventListener("deviceready", function() {
- deviceReady = true;
- if (device.platform.indexOf("iOS") !=-1)
- {
- getRecordSrc();
- } else if (typeof blackberry !== 'undefined') {
- getRecordSrcBB();
- }
- console.log("Device="+device.platform+" "+device.version);
- }, false);
- window.setTimeout(function() {
- if (!deviceReady) {
- alert("Error: Apache Cordova did not initialize. Demo will not run correctly.");
- }
- },1000);
-}
-
-/**
- * for forced updates of position after a successful seek
- */
-function updatePosition() {
- media1.getCurrentPosition(
- function(position) {
- console.log("Pos="+position);
- if (position >= 0.0) {
- setAudioPosition(position+" sec");
- }
- },
- function(e) {
- console.log("Error getting pos="+e);
- setAudioPosition("Error: "+e);
- });
-}
-
-/**
- *
- */
-function seekAudio(mode) {
- var time = document.getElementById("seekinput").value;
- if (time == "") {
- time = 5000;
- } else {
- time = time * 1000; //we expect the input to be in seconds
- }
- if (media1 == null) {
- console.log("seekTo requested while media1 is null");
- if (audioSrc == null) {
- audioSrc = defaultaudio;
- }
- media1 = new Media(audioSrc,
- function() {
- console.log("seekToAudio():Audio Success");
- },
- function(err) {
- console.log("seekAudio():Audio Error: "+err.code);
- setAudioStatus("Error: " + err.code);
- },
- function(status) {
- console.log("seekAudio():Audio Status: "+status);
- setAudioStatus(Media.MEDIA_MSG[status]);
-
- // If stopped, then stop getting current position
- if (Media.MEDIA_STOPPED == status) {
- clearInterval(media1Timer);
- media1Timer = null;
- setAudioPosition("0 sec");
- }
- });
- }
-
- media1.getCurrentPosition(
- function (position) {
- var deltat = time;
- if (mode == "by") {
- deltat = time + position * 1000;
- }
- media1.seekTo(deltat,
- function () {
- console.log("seekAudioTo():Audio Success");
- //force an update on the position display
- updatePosition();
- },
- function (err) {
- console.log("seekAudioTo():Audio Error: " + err.code);
- });
- },
- function(e) {
- console.log("Error getting pos="+e);
- setAudioPosition("Error: "+e);
- });
-}
-
-window.onload = function() {
- addListenerToClass('playAudio', function () {
- playAudio();
- });
- addListenerToClass('pauseAudio', pauseAudio);
- addListenerToClass('stopAudio', stopAudio);
- addListenerToClass('releaseAudio', releaseAudio);
- addListenerToClass('seekAudioBy', seekAudio, 'by');
- addListenerToClass('seekAudioTo', seekAudio, 'to');
- addListenerToClass('recordAudio', recordAudio);
- addListenerToClass('playRecording', playRecording);
-
- addListenerToClass('backBtn', backHome);
- init();
-}
diff --git a/www/autotest/pages/accelerometer.html b/www/autotest/pages/accelerometer.html
deleted file mode 100644
index 52b333b..0000000
--- a/www/autotest/pages/accelerometer.html
+++ /dev/null
@@ -1,54 +0,0 @@
-<!DOCTYPE html>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software 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.
-
--->
-
-
-<html>
-<head>
- <title>Cordova: Accelerometer API Specs</title>
-
- <meta name="viewport" content="width=device-width, height=device-height, user-scalable=yes, initial-scale=1.0;" />
-
- <!-- Load jasmine -->
- <link href="../jasmine.css" rel="stylesheet"/>
- <script type="text/javascript" src="../jasmine.js"></script>
- <script type="text/javascript" src="../html/HtmlReporterHelpers.js"></script>
- <script type="text/javascript" src="../html/HtmlReporter.js"></script>
- <script type="text/javascript" src="../html/ReporterView.js"></script>
- <script type="text/javascript" src="../html/SpecView.js"></script>
- <script type="text/javascript" src="../html/SuiteView.js"></script>
- <script type="text/javascript" src="../html/TrivialReporter.js"></script>
-
- <!-- Source -->
- <script type="text/javascript" src="../../cordova-incl.js"></script>
-
- <!-- Load Test Runner -->
- <script type="text/javascript" src="../test-runner.js"></script>
-
- <!-- Tests -->
- <script type="text/javascript" src="../tests/accelerometer.tests.js"></script>
- <script type="text/javascript" charset="utf-8" src="./run-tests.js"></script>
-</head>
-
-<body>
- <a href="javascript:" class="backBtn">Back</a>
-</body>
-</html>
diff --git a/www/autotest/pages/battery.html b/www/autotest/pages/battery.html
deleted file mode 100644
index 2063417..0000000
--- a/www/autotest/pages/battery.html
+++ /dev/null
@@ -1,51 +0,0 @@
-<!DOCTYPE html>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software 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.
-
--->
-
-
-<html>
-<head>
- <title>Cordova: Battery API Specs</title>
-
- <meta name="viewport" content="width=device-width, height=device-height, user-scalable=yes, initial-scale=1.0;" />
-
- <link href="../jasmine.css" rel="stylesheet"/>
- <script type="text/javascript" src="../jasmine.js"></script>
- <script type="text/javascript" src="../html/HtmlReporterHelpers.js"></script>
- <script type="text/javascript" src="../html/HtmlReporter.js"></script>
- <script type="text/javascript" src="../html/ReporterView.js"></script>
- <script type="text/javascript" src="../html/SpecView.js"></script>
- <script type="text/javascript" src="../html/SuiteView.js"></script>
- <script type="text/javascript" src="../html/TrivialReporter.js"></script>
- <script type="text/javascript" src="../../cordova-incl.js"></script>
-
- <!-- Load Test Runner -->
- <script type="text/javascript" src="../test-runner.js"></script>
-
- <!-- Tests -->
- <script type="text/javascript" src="../tests/battery.tests.js"></script>
- <script type="text/javascript" charset="utf-8" src="./run-tests.js"></script>
-</head>
-
-<body>
- <a class="backBtn">Back</a>
-</body>
-</html>
diff --git a/www/autotest/pages/camera.html b/www/autotest/pages/camera.html
deleted file mode 100644
index 91843d7..0000000
--- a/www/autotest/pages/camera.html
+++ /dev/null
@@ -1,55 +0,0 @@
-<!DOCTYPE html>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software 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.
-
--->
-
-
-<html>
-
-<head>
- <title>Cordova: Camera API Specs</title>
-
- <meta name="viewport" content="width=device-width, height=device-height, user-scalable=yes, initial-scale=1.0;" />
-
- <!-- Load jasmine -->
- <link href="../jasmine.css" rel="stylesheet"/>
- <script type="text/javascript" src="../jasmine.js"></script>
- <script type="text/javascript" src="../html/HtmlReporterHelpers.js"></script>
- <script type="text/javascript" src="../html/HtmlReporter.js"></script>
- <script type="text/javascript" src="../html/ReporterView.js"></script>
- <script type="text/javascript" src="../html/SpecView.js"></script>
- <script type="text/javascript" src="../html/SuiteView.js"></script>
- <script type="text/javascript" src="../html/TrivialReporter.js"></script>
-
- <!-- Source -->
- <script type="text/javascript" src="../../cordova-incl.js"></script>
-
- <!-- Load Test Runner -->
- <script type="text/javascript" src="../test-runner.js"></script>
-
- <!-- Tests -->
- <script type="text/javascript" src="../tests/camera.tests.js"></script>
- <script type="text/javascript" charset="utf-8" src="./run-tests.js"></script>
-</head>
-
-<body>
- <a href="javascript:" class="backBtn">Back</a>
-</body>
-</html>
diff --git a/www/autotest/pages/capture.html b/www/autotest/pages/capture.html
deleted file mode 100644
index bac570f..0000000
--- a/www/autotest/pages/capture.html
+++ /dev/null
@@ -1,55 +0,0 @@
-<!DOCTYPE html>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software 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.
-
--->
-
-
-<html>
-
-<head>
- <title>Cordova: Capture API Specs</title>
-
- <meta name="viewport" content="width=device-width, height=device-height, user-scalable=yes, initial-scale=1.0;" />
- <!-- Load jasmine -->
- <link href="../jasmine.css" rel="stylesheet"/>
- <script type="text/javascript" src="../jasmine.js"></script>
- <script type="text/javascript" src="../html/HtmlReporterHelpers.js"></script>
- <script type="text/javascript" src="../html/HtmlReporter.js"></script>
- <script type="text/javascript" src="../html/ReporterView.js"></script>
- <script type="text/javascript" src="../html/SpecView.js"></script>
- <script type="text/javascript" src="../html/SuiteView.js"></script>
- <script type="text/javascript" src="../html/TrivialReporter.js"></script>
-
- <!-- Source -->
- <script type="text/javascript" src="../../cordova-incl.js"></script>
-
- <!-- Load Test Runner -->
- <script type="text/javascript" src="../test-runner.js"></script>
-
- <!-- Tests -->
- <script type="text/javascript" src="../tests/capture.tests.js"></script>
- <script type="text/javascript" charset="utf-8" src="./run-tests.js"></script>
-</head>
-
-<body>
- <a class="backBtn">Back</a>
-</body>
-</html>
-
diff --git a/www/autotest/pages/compass.html b/www/autotest/pages/compass.html
deleted file mode 100644
index 80de16f..0000000
--- a/www/autotest/pages/compass.html
+++ /dev/null
@@ -1,55 +0,0 @@
-<!DOCTYPE html>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software 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.
-
--->
-
-
-<html>
-
-<head>
- <title>Cordova: Compass API Specs</title>
-
- <meta name="viewport" content="width=device-width, height=device-height, user-scalable=yes, initial-scale=1.0;" />
- <!-- Load jasmine -->
- <link href="../jasmine.css" rel="stylesheet"/>
- <script type="text/javascript" src="../jasmine.js"></script>
- <script type="text/javascript" src="../html/HtmlReporterHelpers.js"></script>
- <script type="text/javascript" src="../html/HtmlReporter.js"></script>
- <script type="text/javascript" src="../html/ReporterView.js"></script>
- <script type="text/javascript" src="../html/SpecView.js"></script>
- <script type="text/javascript" src="../html/SuiteView.js"></script>
- <script type="text/javascript" src="../html/TrivialReporter.js"></script>
-
- <!-- Source -->
- <script type="text/javascript" src="../../cordova-incl.js"></script>
-
- <!-- Load Test Runner -->
- <script type="text/javascript" src="../test-runner.js"></script>
-
- <!-- Tests -->
- <script type="text/javascript" src="../tests/compass.tests.js"></script>
- <script type="text/javascript" charset="utf-8" src="./run-tests.js"></script>
-</head>
-
-<body>
- <a href="javascript:" class="backBtn">Back</a>
-</body>
-</html>
-
diff --git a/www/autotest/pages/contacts.html b/www/autotest/pages/contacts.html
deleted file mode 100644
index e8e5fae..0000000
--- a/www/autotest/pages/contacts.html
+++ /dev/null
@@ -1,56 +0,0 @@
-<!DOCTYPE html>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software 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.
-
--->
-
-
-<html>
-
-<head>
- <title>Cordova: Contacts API Specs</title>
-
- <meta name="viewport" content="width=device-width, height=device-height, user-scalable=yes, initial-scale=1.0;" />
- <!-- Load jasmine -->
- <link href="../jasmine.css" rel="stylesheet"/>
- <script type="text/javascript" src="../jasmine.js"></script>
- <script type="text/javascript" src="../html/HtmlReporterHelpers.js"></script>
- <script type="text/javascript" src="../html/HtmlReporter.js"></script>
- <script type="text/javascript" src="../html/ReporterView.js"></script>
- <script type="text/javascript" src="../html/SpecView.js"></script>
- <script type="text/javascript" src="../html/SuiteView.js"></script>
- <script type="text/javascript" src="../html/TrivialReporter.js"></script>
-
- <!-- Source -->
- <script type="text/javascript" src="../../cordova-incl.js"></script>
-
- <!-- Load Test Runner -->
- <script type="text/javascript" src="../test-runner.js"></script>
-
- <!-- Tests -->
- <script type="text/javascript" src="../tests/contacts.tests.js"></script>
-
- <script type="text/javascript" charset="utf-8" src="./run-tests.js"></script>
-</head>
-
-<body>
- <a href="javascript:" class="backBtn" id="backHome">Back</a>
-</body>
-</html>
-
diff --git a/www/autotest/pages/file.html b/www/autotest/pages/file.html
deleted file mode 100644
index d201791..0000000
--- a/www/autotest/pages/file.html
+++ /dev/null
@@ -1,53 +0,0 @@
-<!DOCTYPE html>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software 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.
-
--->
-
-
-<html>
-<head>
- <title>Cordova: File API Specs</title>
-
- <meta name="viewport" content="width=device-width, height=device-height, user-scalable=yes, initial-scale=1.0;" />
- <!-- Load jasmine -->
- <link href="../jasmine.css" rel="stylesheet"/>
- <script type="text/javascript" src="../jasmine.js"></script>
- <script type="text/javascript" src="../html/HtmlReporterHelpers.js"></script>
- <script type="text/javascript" src="../html/HtmlReporter.js"></script>
- <script type="text/javascript" src="../html/ReporterView.js"></script>
- <script type="text/javascript" src="../html/SpecView.js"></script>
- <script type="text/javascript" src="../html/SuiteView.js"></script>
- <script type="text/javascript" src="../html/TrivialReporter.js"></script>
-
- <!-- Source -->
- <script type="text/javascript" src="../../cordova-incl.js"></script>
-
- <!-- Load Test Runner -->
- <script type="text/javascript" src="../test-runner.js"></script>
-
- <!-- Tests -->
- <script type="text/javascript" src="../tests/file.tests.js"></script>
- <script type="text/javascript" charset="utf-8" src="./file.js"></script>
-</head>
-
-<body>
- <a href="javascript:" class="backBtn">Back</a>
-</body>
-</html>
diff --git a/www/autotest/pages/file.js b/www/autotest/pages/file.js
deleted file mode 100644
index 9b1a67a..0000000
--- a/www/autotest/pages/file.js
+++ /dev/null
@@ -1,39 +0,0 @@
-var root, temp_root, persistent_root;
-
-document.addEventListener('deviceready', function () {
- // one-time retrieval of the root file system entry
- var onError = function(e) {
- console.log('[ERROR] Problem setting up root filesystem for test running! Error to follow.');
- console.log(JSON.stringify(e));
- };
-
- window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
- function(fileSystem) {
- console.log('File API test Init: Setting PERSISTENT FS.');
- root = fileSystem.root; // set in file.tests.js
- persistent_root = root;
-
- // Once root is set up, fire off tests
- var jasmineEnv = jasmine.getEnv();
- jasmineEnv.updateInterval = 1000;
-
- var htmlReporter = new jasmine.HtmlReporter();
-
- jasmineEnv.addReporter(htmlReporter);
-
- jasmineEnv.specFilter = function(spec) {
- return htmlReporter.specFilter(spec);
- };
-
- jasmineEnv.execute();
- }, onError);
- window.requestFileSystem(LocalFileSystem.TEMPORARY, 0,
- function(fileSystem) {
- console.log('File API test Init: Setting TEMPORARY FS.');
- temp_root = fileSystem.root; // set in file.tests.js
- }, onError);
-}, false);
-
-window.onload = function() {
- addListenerToClass('backBtn', backHome);
-}
diff --git a/www/autotest/pages/geolocation.html b/www/autotest/pages/geolocation.html
deleted file mode 100644
index b7a0698..0000000
--- a/www/autotest/pages/geolocation.html
+++ /dev/null
@@ -1,55 +0,0 @@
-<!DOCTYPE html>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software 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.
-
--->
-
-
-<html>
-
-<head>
- <title>Cordova: Geolocation API Specs</title>
-
- <meta name="viewport" content="width=device-width, height=device-height, user-scalable=yes, initial-scale=1.0;" />
- <!-- Load jasmine -->
- <link href="../jasmine.css" rel="stylesheet"/>
- <script type="text/javascript" src="../jasmine.js"></script>
- <script type="text/javascript" src="../html/HtmlReporterHelpers.js"></script>
- <script type="text/javascript" src="../html/HtmlReporter.js"></script>
- <script type="text/javascript" src="../html/ReporterView.js"></script>
- <script type="text/javascript" src="../html/SpecView.js"></script>
- <script type="text/javascript" src="../html/SuiteView.js"></script>
- <script type="text/javascript" src="../html/TrivialReporter.js"></script>
-
- <!-- Source -->
- <script type="text/javascript" src="../../cordova-incl.js"></script>
-
- <!-- Load Test Runner -->
- <script type="text/javascript" src="../test-runner.js"></script>
-
- <!-- Tests -->
- <script type="text/javascript" src="../tests/geolocation.tests.js"></script>
- <script type="text/javascript" charset="utf-8" src="./run-tests.js"></script>
-</head>
-
-<body>
- <a href="javascript:" class="backBtn">Back</a>
-</body>
-</html>
-
diff --git a/www/autotest/pages/media.html b/www/autotest/pages/media.html
deleted file mode 100644
index ac1fa75..0000000
--- a/www/autotest/pages/media.html
+++ /dev/null
@@ -1,55 +0,0 @@
-<!DOCTYPE html>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software 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.
-
--->
-
-
-<html>
-
-<head>
- <title>Cordova: Media API Specs</title>
-
- <meta name="viewport" content="width=device-width, height=device-height, user-scalable=yes, initial-scale=1.0;" />
- <!-- Load jasmine -->
- <link href="../jasmine.css" rel="stylesheet"/>
- <script type="text/javascript" src="../jasmine.js"></script>
- <script type="text/javascript" src="../html/HtmlReporterHelpers.js"></script>
- <script type="text/javascript" src="../html/HtmlReporter.js"></script>
- <script type="text/javascript" src="../html/ReporterView.js"></script>
- <script type="text/javascript" src="../html/SpecView.js"></script>
- <script type="text/javascript" src="../html/SuiteView.js"></script>
- <script type="text/javascript" src="../html/TrivialReporter.js"></script>
-
- <!-- Source -->
- <script type="text/javascript" src="../../cordova-incl.js"></script>
-
- <!-- Load Test Runner -->
- <script type="text/javascript" src="../test-runner.js"></script>
-
- <!-- Tests -->
- <script type="text/javascript" src="../tests/media.tests.js"></script>
- <script type="text/javascript" charset="utf-8" src="./run-tests.js"></script>
-</head>
-
-<body>
- <a href="javascript:" class="backBtn">Back</a>
-</body>
-</html>
-
diff --git a/www/autotest/pages/vibration.html b/www/autotest/pages/vibration.html
deleted file mode 100644
index 04db2ec..0000000
--- a/www/autotest/pages/vibration.html
+++ /dev/null
@@ -1,55 +0,0 @@
-<!DOCTYPE html>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software 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.
-
--->
-
-
-<html>
-
-<head>
- <title>Cordova: Vibration API Specs</title>
-
- <meta name="viewport" content="width=device-width, height=device-height, user-scalable=yes, initial-scale=1.0;" />
- <!-- Load jasmine -->
- <link href="../jasmine.css" rel="stylesheet"/>
- <script type="text/javascript" src="../jasmine.js"></script>
- <script type="text/javascript" src="../html/HtmlReporterHelpers.js"></script>
- <script type="text/javascript" src="../html/HtmlReporter.js"></script>
- <script type="text/javascript" src="../html/ReporterView.js"></script>
- <script type="text/javascript" src="../html/SpecView.js"></script>
- <script type="text/javascript" src="../html/SuiteView.js"></script>
- <script type="text/javascript" src="../html/TrivialReporter.js"></script>
-
- <!-- Source -->
- <script type="text/javascript" src="../../cordova-incl.js"></script>
-
- <!-- Load Test Runner -->
- <script type="text/javascript" src="../test-runner.js"></script>
-
- <!-- Tests -->
- <script type="text/javascript" src="../tests/vibration.tests.js"></script>
- <script type="text/javascript" charset="utf-8" src="./run-tests.js"></script>
-</head>
-
-<body>
- <a href="javascript:" class="backBtn">Back</a>
-</body>
-</html>
-
diff --git a/www/autotest/tests/accelerometer.tests.js b/www/autotest/tests/accelerometer.tests.js
deleted file mode 100644
index 029db05..0000000
--- a/www/autotest/tests/accelerometer.tests.js
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software 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.
- *
-*/
-
-describe('Accelerometer (navigator.accelerometer)', function () {
- it("accelerometer.spec.1 should exist", function () {
- expect(navigator.accelerometer).toBeDefined();
- });
-
- describe("getCurrentAcceleration", function() {
- afterEach(function(){
- // wait between testcases to avoid interference
- var flag=false;
- runs(function() {
- setTimeout(function() {flag = true;}, 500);
- });
-
- waitsFor(function() {return flag;}, "flag to be true", Tests.TEST_TIMEOUT);
- });
-
- it("accelerometer.spec.2 should exist", function() {
- expect(typeof navigator.accelerometer.getCurrentAcceleration).toBeDefined();
- expect(typeof navigator.accelerometer.getCurrentAcceleration == 'function').toBe(true);
- });
-
- it("accelerometer.spec.3 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);
- expect(a.timestamp).toBeDefined();
- expect(typeof a.timestamp).toBe('number');
- }),
- 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();
- });
- });
-
- it("accelerometer.spec.4 success callback Acceleration object should have (reasonable) values for x, y and z expressed in m/s^2", function() {
- var reasonableThreshold = 15;
- var win = jasmine.createSpy().andCallFake(function(a) {
- expect(a.x).toBeLessThan(reasonableThreshold);
- expect(a.x).toBeGreaterThan(reasonableThreshold * -1);
- expect(a.y).toBeLessThan(reasonableThreshold);
- expect(a.y).toBeGreaterThan(reasonableThreshold * -1);
- expect(a.z).toBeLessThan(reasonableThreshold);
- expect(a.z).toBeGreaterThan(reasonableThreshold * -1);
- }),
- 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();
- });
- });
-
- it("accelerometer.spec.5 success callback Acceleration object should return a recent timestamp", function() {
- // Check that timestamp returned is within a reasonable window.
- var veryRecently = (new Date()).getTime()-1000; // lower bound - 1 second prior
- var reasonableTimeLimit = veryRecently + 6000; // upper bound - 5 seconds from now
- var win = jasmine.createSpy().andCallFake(function(a) {
- expect(a.timestamp).toBeGreaterThan(veryRecently);
- expect(a.timestamp).toBeLessThan(reasonableTimeLimit);
- }),
- 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();
- });
- });
- });
-
- describe("watchAcceleration", function() {
- var id;
-
- afterEach(function() {
- navigator.accelerometer.clearWatch(id);
- });
-
- it("accelerometer.spec.6 should exist", function() {
- expect(navigator.accelerometer.watchAcceleration).toBeDefined();
- expect(typeof navigator.accelerometer.watchAcceleration == 'function').toBe(true);
- });
- it("accelerometer.spec.7 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);
- expect(a.timestamp).toBeDefined();
- expect(typeof a.timestamp).toBe('number');
- }),
- fail = jasmine.createSpy();
-
- runs(function () {
- id = navigator.accelerometer.watchAcceleration(win, fail, {frequency:500});
- });
-
- waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT);
-
- runs(function () {
- expect(fail).not.toHaveBeenCalled();
- });
- });
-
- it("accelerometer.spec.8 success callback Acceleration object should have (reasonable) values for x, y and z expressed in m/s^2", function() {
- var reasonableThreshold = 15;
- var win = jasmine.createSpy().andCallFake(function(a) {
- expect(a.x).toBeLessThan(reasonableThreshold);
- expect(a.x).toBeGreaterThan(reasonableThreshold * -1);
- expect(a.y).toBeLessThan(reasonableThreshold);
- expect(a.y).toBeGreaterThan(reasonableThreshold * -1);
- expect(a.z).toBeLessThan(reasonableThreshold);
- expect(a.z).toBeGreaterThan(reasonableThreshold * -1);
- }),
- fail = jasmine.createSpy();
-
- runs(function () {
- id = navigator.accelerometer.watchAcceleration(win, fail, {frequency:500});
- });
-
- waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT);
-
- runs(function () {
- expect(fail).not.toHaveBeenCalled();
- });
- });
-
- it("accelerometer.spec.9 success callback Acceleration object should return a recent timestamp", function() {
- // Check that timestamp returned is within a reasonable window.
- var veryRecently = (new Date()).getTime()-1000; // lower bound - 1 second prior
- var reasonableTimeLimit = veryRecently + 6000; // upper bound - 5 seconds from now
- var win = jasmine.createSpy().andCallFake(function(a) {
- expect(a.timestamp).toBeGreaterThan(veryRecently);
- expect(a.timestamp).toBeLessThan(reasonableTimeLimit);
- }),
- fail = jasmine.createSpy();
-
- runs(function () {
- id = navigator.accelerometer.watchAcceleration(win, fail, {frequency:500});
- });
-
- waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT);
-
- runs(function () {
- expect(fail).not.toHaveBeenCalled();
- });
- });
- });
-
- describe("clearWatch", function() {
- it("accelerometer.spec.10 should exist", function() {
- expect(navigator.accelerometer.clearWatch).toBeDefined();
- expect(typeof navigator.accelerometer.clearWatch == 'function').toBe(true);
- });
-
- it("accelerometer.spec.11 should clear an existing watch", function() {
- var id,
- win = jasmine.createSpy();
-
- runs(function() {
- id = navigator.accelerometer.watchAcceleration(win, function() {}, {frequency:100});
- });
-
- waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT);
-
- runs(function() {
- win.reset();
- navigator.accelerometer.clearWatch(id);
- });
-
- waits(201);
-
- runs(function() {
- expect(win).not.toHaveBeenCalled();
- });
- });
- });
-});
diff --git a/www/autotest/tests/battery.tests.js b/www/autotest/tests/battery.tests.js
deleted file mode 100644
index 47a86d4..0000000
--- a/www/autotest/tests/battery.tests.js
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software 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.
- *
-*/
-
-describe('Battery (navigator.battery)', function () {
-
- // used to keep the count of event listeners > 0, in order to avoid battery level being updated with the real value when adding the first listener during test cases
- var dummyOnEvent = jasmine.createSpy();
- beforeEach(function () {
- window.addEventListener("batterycritical", dummyOnEvent, false);
- });
-
- afterEach(function () {
- window.removeEventListener("batterystatus", dummyOnEvent, false);
- });
-
-
- it("battery.spec.1 should exist", function() {
- expect(navigator.battery).toBeDefined();
- });
-
- it("battery.spec.2 should fire batterystatus events", function () {
-
- // batterystatus
- var onEvent;
-
- runs(function () {
- onEvent = jasmine.createSpy().andCallFake(function () {
- window.removeEventListener("batterystatus", onEvent, false);
- });
- window.addEventListener("batterystatus", onEvent, false);
- navigator.battery._status({ level: 30, isPlugged: false });
- });
- waitsFor(function () { return onEvent.wasCalled; }, "batterystatus onEvent was not called", 100);
- runs(function () {
- expect(onEvent).toHaveBeenCalled();
- });
-
- });
-
- it("battery.spec.3 should fire batterylow events", function () {
-
- var onEvent;
-
- // batterylow 30 -> 20
- runs(function () {
- onEvent = jasmine.createSpy().andCallFake(function () {
- //console.log("batterylow fake callback called");
- window.removeEventListener("batterylow", onEvent, false);
- });
- window.addEventListener("batterylow", onEvent, false);
- navigator.battery._status({ level: 20, isPlugged: false });
- });
- waitsFor(function () { return onEvent.wasCalled; }, "batterylow onEvent was not called when level goes from 30->20", 100);
- runs(function () {
- expect(onEvent).toHaveBeenCalled();
- });
-
- // batterylow 30 -> 19
- runs(function () {
- onEvent = jasmine.createSpy().andCallFake(function () {
- //console.log("batterylow fake callback called");
- window.removeEventListener("batterylow", onEvent, false);
- });
- navigator.battery._status({ level: 30, isPlugged: false });
- window.addEventListener("batterylow", onEvent, false);
- navigator.battery._status({ level: 19, isPlugged: false });
- });
- waitsFor(function () { return onEvent.wasCalled; }, "batterylow onEvent was not called when level goes from 30->19", 100);
- runs(function () {
- expect(onEvent).toHaveBeenCalled();
- });
-
- });
-
- it("battery.spec.4 should fire batterycritical events", function () {
-
- var onEvent;
-
- // batterycritical 19->5
- runs(function () {
- onEvent = jasmine.createSpy().andCallFake(function () {
- window.removeEventListener("batterycritical", onEvent, false);
- });
- window.addEventListener("batterycritical", onEvent, false);
- navigator.battery._status({ level: 5, isPlugged: false });
- });
- waitsFor(function () { return onEvent.wasCalled; }, "batterycritical onEvent was not called when level goes from 19->5", 100);
- runs(function () {
- expect(onEvent).toHaveBeenCalled();
- });
-
- // batterycritical 19->4
- runs(function () {
- onEvent = jasmine.createSpy().andCallFake(function () {
- window.removeEventListener("batterycritical", onEvent, false);
- });
- navigator.battery._status({ level: 19, isPlugged: false });
- window.addEventListener("batterycritical", onEvent, false);
- navigator.battery._status({ level: 4, isPlugged: false });
- });
- waitsFor(function () { return onEvent.wasCalled; }, "batterycritical onEvent was not called when level goes from 19->4", 100);
- runs(function () {
- expect(onEvent).toHaveBeenCalled();
- });
- });
-
- it("battery.spec.5 should NOT fire events when charging or level is increasing", function () {
- var onEvent;
- // setup: batterycritical should fire when level decreases (100->4) ( CB-4519 )
- runs(function () {
- onEvent = jasmine.createSpy("onbatterycritical");
- navigator.battery._status({ level: 100, isPlugged: false });
- window.addEventListener("batterycritical", onEvent, false);
- navigator.battery._status({ level: 4, isPlugged: false });
- });
- waits(100);
- runs(function () {
- expect(onEvent).toHaveBeenCalled();
- });
-
- // batterycritical should not fire when level increases (4->5)( CB-4519 )
- runs(function () {
- onEvent = jasmine.createSpy("onbatterycritical");
- navigator.battery._status({ level: 4, isPlugged: false });
- window.addEventListener("batterycritical", onEvent, false);
- navigator.battery._status({ level: 5, isPlugged: false });
- });
- waits(100);
- runs(function () {
- expect(onEvent).not.toHaveBeenCalled();
- });
- // batterylow should not fire when level increases (5->20) ( CB-4519 )
- runs(function () {
- onEvent = jasmine.createSpy("onbatterylow");
- window.addEventListener("batterylow", onEvent, false);
- navigator.battery._status({ level: 20, isPlugged: false });
- });
- waits(100);
- runs(function () {
- expect(onEvent).not.toHaveBeenCalled();
- });
-
- // batterylow should NOT fire if we are charging ( CB-4520 )
- runs(function () {
- onEvent = jasmine.createSpy("onbatterylow");
- navigator.battery._status({ level: 21, isPlugged: true });
- window.addEventListener("batterylow", onEvent, false);
- navigator.battery._status({ level: 20, isPlugged: true });
- });
- waits(100);
- runs(function () {
- expect(onEvent).not.toHaveBeenCalled();
- });
-
- // batterycritical should NOT fire if we are charging ( CB-4520 )
- runs(function () {
- onEvent = jasmine.createSpy("onbatterycritical");
- navigator.battery._status({ level: 6, isPlugged: true });
- window.addEventListener("batterycritical", onEvent, false);
- navigator.battery._status({ level: 5, isPlugged: true });
-
- });
- waits(100);
- runs(function () {
- expect(onEvent).not.toHaveBeenCalled();
- });
- });
-
-});
diff --git a/www/autotest/tests/camera.tests.js b/www/autotest/tests/camera.tests.js
deleted file mode 100644
index ee5bacd..0000000
--- a/www/autotest/tests/camera.tests.js
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software 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.
- *
-*/
-
-describe('Camera (navigator.camera)', function () {
- it("should exist", function() {
- expect(navigator.camera).toBeDefined();
- });
-
- 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("camera.spec.1 window.Camera should exist", function() {
- expect(window.Camera).toBeDefined();
- });
-
- it("camera.spec.2 should contain three DestinationType constants", function() {
- expect(Camera.DestinationType.DATA_URL).toBe(0);
- expect(Camera.DestinationType.FILE_URI).toBe(1);
- expect(Camera.DestinationType.NATIVE_URI).toBe(2);
- expect(navigator.camera.DestinationType.DATA_URL).toBe(0);
- expect(navigator.camera.DestinationType.FILE_URI).toBe(1);
- expect(navigator.camera.DestinationType.NATIVE_URI).toBe(2);
- });
-
- it("camera.spec.3 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);
- });
-
- it("camera.spec.4 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("camera.spec.5 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/www/autotest/tests/capture.tests.js b/www/autotest/tests/capture.tests.js
deleted file mode 100644
index 99ce438..0000000
--- a/www/autotest/tests/capture.tests.js
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software 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.
- *
-*/
-
-describe('Capture (navigator.device.capture)', function () {
- it("capture.spec.1 should exist", function() {
- expect(navigator.device).toBeDefined();
- expect(navigator.device.capture).toBeDefined();
- });
-
- it("capture.spec.2 should have the correct properties ", function() {
- expect(navigator.device.capture.supportedAudioModes).toBeDefined();
- expect(navigator.device.capture.supportedImageModes).toBeDefined();
- expect(navigator.device.capture.supportedVideoModes).toBeDefined();
- });
-
- it("capture.spec.3 should contain a captureAudio function", function() {
- expect(navigator.device.capture.captureAudio).toBeDefined();
- expect(typeof navigator.device.capture.captureAudio == 'function').toBe(true);
- });
-
- it("capture.spec.4 should contain a captureImage function", function() {
- expect(navigator.device.capture.captureImage).toBeDefined();
- expect(typeof navigator.device.capture.captureImage == 'function').toBe(true);
- });
-
- it("capture.spec.5 should contain a captureVideo function", function() {
- expect(navigator.device.capture.captureVideo).toBeDefined();
- expect(typeof navigator.device.capture.captureVideo == 'function').toBe(true);
- });
-
- describe('CaptureAudioOptions', function () {
- it("capture.spec.6 CaptureAudioOptions constructor should exist", function() {
- var options = new CaptureAudioOptions();
- expect(options).toBeDefined();
- expect(options.limit).toBeDefined();
- expect(options.duration).toBeDefined();
- });
- });
-
- describe('CaptureImageOptions', function () {
- it("capture.spec.7 CaptureImageOptions constructor should exist", function() {
- var options = new CaptureImageOptions();
- expect(options).toBeDefined();
- expect(options.limit).toBeDefined();
- });
- });
-
- describe('CaptureVideoOptions', function () {
- it("capture.spec.8 CaptureVideoOptions constructor should exist", function() {
- var options = new CaptureVideoOptions();
- expect(options).toBeDefined();
- expect(options.limit).toBeDefined();
- expect(options.duration).toBeDefined();
- });
- });
-
- describe('CaptureError interface', function () {
- it("capture.spec.9 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("capture.spec.10 CaptureError properties should exist", function() {
- var error = new CaptureError();
- expect(error).toBeDefined();
- expect(error.code).toBeDefined();
- });
- });
-
- describe('MediaFileData', function () {
- it("capture.spec.11 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();
- });
- });
-
- describe('MediaFile', function () {
- it("capture.spec.12 MediaFile constructor should exist", function() {
- var fileData = new MediaFile();
- expect(fileData).toBeDefined();
- expect(fileData.name).toBeDefined();
- expect(fileData.type).toBeDefined();
- expect(fileData.lastModifiedDate).toBeDefined();
- expect(fileData.size).toBeDefined();
- });
- });
-});
diff --git a/www/autotest/tests/compass.tests.js b/www/autotest/tests/compass.tests.js
deleted file mode 100644
index 332daea..0000000
--- a/www/autotest/tests/compass.tests.js
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software 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.
- *
-*/
-
-describe('Compass (navigator.compass)', function () {
- var hardwarefailure = false;
- beforeEach(function() {
- this.addMatchers({
- // check to see if the device has a compass, if it doesn't fail gracefully
- hasHardware: function() {
- var toreturn = true;
-
- try{
- this.actual;
- toreturn = true;
- } catch (error){
- if (error.code == CompassError.COMPASS_NOT_SUPPORTED){
- hardwarefailure = true;
- toreturn = false;
- }
- }
- this.message = function () {
- return "The device does not have compass support. The remaining compass tests will be ignored.";
- }
-
- return toreturn;
- }
- });
- });
-
- afterEach(function () {
- // We want to gracefully fail if there is a hardware failure
- if(this.results_.failedCount > 0 && hardwarefailure == true) {
- //there was a hardware failure, cancelling all tests
- jasmine.Queue.prototype.next_ = function () { this.onComplete();}
- }
- });
-
- it("compass.hardwarecheck is compass supported", function() {
- var f = function(){navigator.compass.getCurrentHeading(function onSuccess(){}, function onError(error) {})};
- expect(f).hasHardware();
- });
-
- it("compass.spec.1 should exist", function() {
- expect(navigator.compass).toBeDefined();
- });
-
- it("compass.spec.2 should contain a getCurrentHeading function", function() {
- expect(navigator.compass.getCurrentHeading).toBeDefined();
- expect(typeof navigator.compass.getCurrentHeading == 'function').toBe(true);
- });
-
- it("compass.spec.3 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();
- });
- });
-
- it("compass.spec.4 should contain a watchHeading function", function() {
- expect(navigator.compass.watchHeading).toBeDefined();
- expect(typeof navigator.compass.watchHeading == 'function').toBe(true);
- });
-
- it("compass.spec.5 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("compass.spec.1 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("compass.spec.1 should exist", function() {
- expect(CompassHeading).toBeDefined();
- });
-
- it("compass.spec.8 should be able to create a new CompassHeading instance with no parameters", function() {
- var h = new CompassHeading();
- expect(h).toBeDefined();
- expect(h.magneticHeading).toBeUndefined();
- expect(h.trueHeading).toBeUndefined();
- expect(h.headingAccuracy).toBeUndefined();
- expect(typeof h.timestamp == 'number').toBe(true);
- });
-
- it("compass.spec.9 should be able to create 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/www/autotest/tests/contacts.tests.js b/www/autotest/tests/contacts.tests.js
deleted file mode 100644
index 73a605c..0000000
--- a/www/autotest/tests/contacts.tests.js
+++ /dev/null
@@ -1,542 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software 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.
- *
-*/
-
-// global to store a contact so it doesn't have to be created or retrieved multiple times
-// all of the setup/teardown test methods can reference the following variables to make sure to do the right cleanup
-var gContactObj = null,
- gContactId = null,
- isWindowsPhone = cordova.platformId == 'windowsphone';
-
-var removeContact = function(){
- if (gContactObj) {
- gContactObj.remove(function(){},function(){
- console.log("[CONTACTS ERROR]: removeContact cleanup method failed to clean up test artifacts.");
- });
- gContactObj = null;
- }
-};
-
-describe("Contacts (navigator.contacts)", function () {
- it("contacts.spec.1 should exist", function() {
- expect(navigator.contacts).toBeDefined();
- });
-
- it("contacts.spec.2 should contain a find function", function() {
- expect(navigator.contacts.find).toBeDefined();
- expect(typeof navigator.contacts.find).toBe('function');
- });
-
- describe("find method", function() {
- it("contacts.spec.3 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("success callback should be called with an array, even if partial ContactFindOptions specified", function () {
- var win = jasmine.createSpy().andCallFake(function (result) {
- expect(result).toBeDefined();
- expect(result instanceof Array).toBe(true);
- }),
- fail = jasmine.createSpy();
-
- runs(function () {
- navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails"], win, fail, {
- multiple: true
- });
- });
-
- waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT);
-
- runs(function () {
- expect(fail).not.toHaveBeenCalled();
- });
- });
-
- it("contacts.spec.4 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("contacts.spec.5 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("contacts.spec.6 should be able to find a contact by name", function() {
-
- // this api requires manual user confirmation on WP7/8 so skip it
- if (isWindowsPhone) return;
-
- var foundName = jasmine.createSpy().andCallFake(function(result) {
- var bFound = false;
- try {
- for (var i=0; i < result.length; i++) {
- if (result[i].name.familyName == "Delete") {
- bFound = true;
- break;
- }
- }
- } catch(e) {
- return false;
- }
- return bFound;
- }),
- 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);
- });
- });
- });
-
- describe('create method', function() {
-
- it("contacts.spec.7 should exist", function() {
- expect(navigator.contacts.create).toBeDefined();
- expect(typeof navigator.contacts.create).toBe('function');
- });
-
- it("contacts.spec.8 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);
- });
- });
-
- describe("Contact object", function () {
- it("contacts.spec.9 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("contacts.spec.10 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("contacts.spec.11 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("contacts.spec.12 ContactField object should coerce type and value properties to strings", function() {
- var contactField = new ContactField(12345678, 12345678, true);
- expect(contactField.type).toBe("12345678");
- expect(contactField.value).toBe("12345678");
- });
-
- it("contacts.spec.13 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("contacts.spec.14 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("contacts.spec.15 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("contacts.spec.16 should contain a clone function", function() {
- var contact = new Contact();
- expect(contact.clone).toBeDefined();
- expect(typeof contact.clone).toBe('function');
- });
-
- it("contacts.spec.17 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);
- });
-
- it("contacts.spec.18 should contain a save function", function() {
- var contact = new Contact();
- expect(contact.save).toBeDefined();
- expect(typeof contact.save).toBe('function');
- });
-
- it("contacts.spec.19 should contain a remove function", function() {
- var contact = new Contact();
- expect(contact.remove).toBeDefined();
- expect(typeof contact.remove).toBe('function');
- });
- });
-
- describe('save method', function () {
- it("contacts.spec.20 should be able to save a contact", function() {
-
- // this api requires manual user confirmation on WP7/8 so skip it
- if (isWindowsPhone) return;
-
- 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();
- if (cordova.platformId !== 'blackberry10') {
- 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("contacts.spec.21 update a contact", function() {
-
- // this api requires manual user confirmation on WP7/8 so skip it
- if (isWindowsPhone) return;
-
- expect(gContactObj).toBeDefined();
-
- var bDay = new Date(1975, 5,4);
- var noteText = "an UPDATED note";
-
- var win = jasmine.createSpy().andCallFake(function(obj) {
- expect(obj).toBeDefined();
- expect(obj.id).toBe(gContactObj.id);
- if (cordova.platformId !== 'blackberry10') {
- 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();
- });
- });
- });
-
- describe('Contact.remove method', function () {
- afterEach(removeContact);
-
- it("contacts.spec.22 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("contacts.spec.23 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();
- });
- });
- });
-
- describe("Round trip Contact tests (creating + save + delete + find).", function () {
- it("contacts.spec.24 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() {
-
- // this api requires manual user confirmation on WP7/8 so skip it
- if (isWindowsPhone) return;
-
- 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() {
- 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) {
- throw("Newly created contact's remove function invoked error callback. Test failed.");
- });
- };
- 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"], findWin, findFail, obj);
- }, function(e) {
- throw("Contact creation failed, error callback was invoked.");
- });
- });
-
- waitsFor(function () { return done; }, Tests.TEST_TIMEOUT);
- });
- });
-
- describe('ContactError interface', function () {
- it("contacts.spec.25 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);
- });
- });
-
- describe("Contacts autotests cleanup", function () {
- it("contacts.spec.26 Cleanup any DeleteMe contacts from Contacts tests.", function() {
- var done = false;
- var obj = new ContactFindOptions();
- obj.filter="DeleteMe";
- obj.multiple=true;
- runs(function () {
- var findSuccess = function (cs) {
- var contactObj = new Contact();
- if (cs.length>0){
- contactObj = cs[0];
- contactObj.remove(function(){
- console.log("[CONTACTS CLEANUP] DeleteMe contact successfully removed");
- navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails"], findSuccess, findFail, obj);
- },function(){
- console.log("[CONTACTS CLEANUP ERROR]: failed to remove DeleteMe contact");
- });
- } else {
- done = true;
- }
- };
- var findFail = function(e) {
- throw("Failure callback invoked in navigator.contacts.find call, test failed.");
- };
- navigator.contacts.find(["displayName", "name", "phoneNumbers", "emails"], findSuccess, findFail, obj);
- });
- waitsFor(function () { return done; }, Tests.TEST_TIMEOUT);
- });
- });
-
-});
diff --git a/www/autotest/tests/file.tests.js b/www/autotest/tests/file.tests.js
deleted file mode 100644
index 50c9e8e..0000000
--- a/www/autotest/tests/file.tests.js
+++ /dev/null
@@ -1,4451 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software 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.
- *
-*/
-
-describe('File API', function() {
- // Adding a Jasmine helper matcher, to report errors when comparing to FileError better.
- var fileErrorMap = {
- 1: 'NOT_FOUND_ERR',
- 2: 'SECURITY_ERR',
- 3: 'ABORT_ERR',
- 4: 'NOT_READABLE_ERR',
- 5: 'ENCODING_ERR',
- 6: 'NO_MODIFICATION_ALLOWED_ERR',
- 7: 'INVALID_STATE_ERR',
- 8: 'SYNTAX_ERR',
- 9: 'INVALID_MODIFICATION_ERR',
- 10:'QUOTA_EXCEEDED_ERR',
- 11:'TYPE_MISMATCH_ERR',
- 12:'PATH_EXISTS_ERR'
- };
- beforeEach(function() {
- this.addMatchers({
- toBeFileError: function(code) {
- var error = this.actual;
- this.message = function(){
- return "Expected FileError with code " + fileErrorMap[error.code] + " (" + error.code + ") to be " + fileErrorMap[code] + "(" + code + ")";
- };
- return (error.code == code);
- },
- toCanonicallyMatch:function(path){
- this.message = function(){
- return "Expected paths to match : " + path + " should be " + this.actual;
- };
-
- var a = path.split("/").join("").split("\\").join("");
- var b = this.actual.split("/").join("").split("\\").join("");
-
- return a == b;
- }
- });
- });
-
- // 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);
- };
- // 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);
- };
- // 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);
- };
-
- var createFail = function(module) {
- return jasmine.createSpy("Fail").andCallFake(function(err) {
- console.log('[ERROR ' + module + '] ' + JSON.stringify(err));
- });
- };
-
- var joinURL = function(base, extension) {
- if (base.charAt(base.length-1) !== '/' && extension.charAt(0) !== '/') {
- return base + '/' + extension;
- }
- if (base.charAt(base.length-1) === '/' && extension.charAt(0) === '/') {
- return base + exension.substring(1);
- }
- return base + extension;
- };
-
- var createWin = function(module) {
- return jasmine.createSpy("Win").andCallFake(function() {
- console.log('[ERROR ' + module + '] Unexpected success callback');
- });
- };
-
- describe('FileError object', function() {
- it("file.spec.1 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("file.spec.2 should define LocalFileSystem constants", function() {
- expect(LocalFileSystem.TEMPORARY).toBe(0);
- expect(LocalFileSystem.PERSISTENT).toBe(1);
- });
-
- describe('window.requestFileSystem', function() {
- it("file.spec.3 should be defined", function() {
- expect(window.requestFileSystem).toBeDefined();
- });
- it("file.spec.4 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();
- expect(fileSystem.root.filesystem).toBeDefined();
- // Shouldn't use cdvfile by default.
- expect(fileSystem.root.toURL()).not.toMatch(/^cdvfile:/);
- // All DirectoryEntry URLs should always have a trailing slash.
- expect(fileSystem.root.toURL()).toMatch(/\/$/);
- }),
- 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("file.spec.5 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();
- expect(fileSystem.root.filesystem).toBeDefined();
- expect(fileSystem.root.filesystem).toBe(fileSystem);
- }),
- 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("file.spec.6 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).toBeFileError(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("file.spec.7 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).toBeFileError(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("file.spec.3 should be defined", function() {
- expect(window.resolveLocalFileSystemURI).toBeDefined();
- });
- it("file.spec.9 should resolve a valid file name", function() {
- var createDirectoryFail = createFail('createDirectory');
- var resolveFail = createFail('resolveLocalFileSystemURI');
- var fileName = 'file.spec.9';
- var win = jasmine.createSpy().andCallFake(function(fileEntry) {
- expect(fileEntry).toBeDefined();
- expect(fileEntry.name).toCanonicallyMatch(fileName);
- expect(fileEntry.toURL()).not.toMatch(/^cdvfile:/, 'should not use cdvfile URL');
- expect(fileEntry.toURL()).not.toMatch(/\/$/, 'URL should not end with a slash');
-
- // cleanup
- deleteEntry(fileName);
- });
- function gotDirectory(entry) {
- // lookup file system entry
- window.resolveLocalFileSystemURL(entry.toURL(), win, resolveFail);
- }
- createFile(fileName, gotDirectory, createDirectoryFail, createDirectoryFail);
- waitsForAny(win, resolveFail, createDirectoryFail);
- });
- it("file.spec.9.5 should resolve a directory", function() {
- var createDirectoryFail = createFail('createDirectory');
- var resolveFail = createFail('resolveLocalFileSystemURI');
- var fileName = 'file.spec.9.5';
- var win = jasmine.createSpy().andCallFake(function(fileEntry) {
- expect(fileEntry).toBeDefined();
- expect(fileEntry.name).toCanonicallyMatch(fileName);
- expect(fileEntry.toURL()).not.toMatch(/^cdvfile:/, 'should not use cdvfile URL');
- expect(fileEntry.toURL()).toMatch(/\/$/, 'URL end with a slash');
-
- // cleanup
- deleteEntry(fileName);
- });
- function gotDirectory(entry) {
- // lookup file system entry
- window.resolveLocalFileSystemURL(entry.toURL(), win, resolveFail);
- }
- createDirectory(fileName, gotDirectory, createDirectoryFail, createDirectoryFail);
- waitsForAny(win, resolveFail, createDirectoryFail);
- });
- it("file.spec.10 resolve valid file name with parameters", function() {
- var fileName = "resolve.file.uri.params",
- win = jasmine.createSpy().andCallFake(function(fileEntry) {
- expect(fileEntry).toBeDefined();
- if (fileEntry.toURL().toLowerCase().substring(0,10) === "cdvfile://") {
- expect(fileEntry.fullPath).toBe("/" + fileName + "?1234567890");
- }
- 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("file.spec.11 should error (NOT_FOUND_ERR) when resolving (non-existent) invalid file name", function() {
- var fileName = joinURL(root.toURL(), "this.is.not.a.valid.file.txt");
- fail = jasmine.createSpy().andCallFake(function(error) {
- expect(error).toBeDefined();
- expect(error).toBeFileError(FileError.NOT_FOUND_ERR);
- }),
- win = createWin('window.resolveLocalFileSystemURI');
-
- // lookup file system entry
- runs(function() {
- window.resolveLocalFileSystemURI(fileName, win, fail);
- });
-
- waitsFor(function() { return fail.wasCalled; }, "error callback never called", Tests.TEST_TIMEOUT);
-
- runs(function() {
- expect(fail).toHaveBeenCalled();
- expect(win).not.toHaveBeenCalled();
- });
- });
- it("file.spec.12 should error (ENCODING_ERR) when resolving invalid URI with leading /", function() {
- var fail = jasmine.createSpy().andCallFake(function(error) {
- expect(error).toBeDefined();
- expect(error).toBeFileError(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("file.spec.13 should exist and have the right properties", function() {
- var metadata = new Metadata();
- expect(metadata).toBeDefined();
- expect(metadata.modificationTime).toBeDefined();
- });
- });
-
- describe('Flags interface', function() {
- it("file.spec.13 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("file.spec.15 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("file.spec.16 getFile: get Entry for file that does not exist", function() {
- var fileName = "de.no.file",
- filePath = joinURL(root.fullPath, fileName),
- fail = jasmine.createSpy().andCallFake(function(error) {
- expect(error).toBeDefined();
- expect(error).toBeFileError(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("file.spec.17 getFile: create new file", function() {
- var fileName = "de.create.file",
- filePath = joinURL(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).toCanonicallyMatch(fileName);
- expect(entry.fullPath).toCanonicallyMatch(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("file.spec.18 getFile: create new file (exclusive)", function() {
- var fileName = "de.create.exclusive.file",
- filePath = joinURL(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).toCanonicallyMatch(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("file.spec.19 getFile: create file that already exists", function() {
- var fileName = "de.create.existing.file",
- filePath = joinURL(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).toCanonicallyMatch(fileName);
- expect(entry.fullPath).toCanonicallyMatch(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("file.spec.20 getFile: create file that already exists (exclusive)", function() {
- var fileName = "de.create.exclusive.existing.file",
- filePath = joinURL(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).toBeFileError(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("file.spec.21 DirectoryEntry.getFile: get Entry for existing file", function() {
- var fileName = "de.get.file",
- filePath = joinURL(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).toCanonicallyMatch(fileName);
- expect(entry.fullPath).toCanonicallyMatch(filePath);
- expect(entry.filesystem).toBeDefined();
- expect(entry.filesystem).toBe(root.filesystem);
- 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();
- });
- });
-
- // 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("file.spec.22 DirectoryEntry.getFile: get FileEntry for invalid path", function() {
- var fileName = "de:invalid:path",
- fail = jasmine.createSpy().andCallFake(function(error) {
- expect(error).toBeDefined();
- expect(error).toBeFileError(FileError.ENCODING_ERR);
- }),
- win = createWin('DirectoryEntry');
-
- // 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("file.spec.23 DirectoryEntry.getDirectory: get Entry for directory that does not exist", function() {
- var dirName = "de.no.dir",
- dirPath = joinURL(root.fullPath, dirName),
- fail = jasmine.createSpy().andCallFake(function(error) {
- expect(error).toBeDefined();
- expect(error).toBeFileError(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("file.spec.24 DirectoryEntry.getDirectory: create new dir with space then resolveFileSystemURI", function() {
- var dirName = "de create dir",
- dirPath = joinURL(root.fullPath, encodeURIComponent(dirName)),
- getDir = jasmine.createSpy().andCallFake(function(dirEntry) {
- expect(dirEntry.filesystem).toBeDefined();
- expect(dirEntry.filesystem).toBe(root.filesystem);
- var dirURI = dirEntry.toURL();
- // now encode URI and try to resolve
- window.resolveLocalFileSystemURI(dirURI, win, fail);
- }),
- win = jasmine.createSpy().andCallFake(function(directory) {
-
- expect(directory).toBeDefined();
- expect(directory.isFile).toBe(false);
- expect(directory.isDirectory).toBe(true);
- expect(directory.name).toCanonicallyMatch(dirName);
- expect(directory.fullPath).toCanonicallyMatch(joinURL(root.fullPath, dirName));
-
- // cleanup
- directory.remove(null, fail);
- }),
- fail = createFail('DirectoryEntry');
-
- // create:true, exclusive:false, directory does not exist
- root.getDirectory(dirName, {create: true}, getDir, fail);
-
- waitsForAny(fail, win);
- });
-
- // This test is excluded, and should probably be removed. Filesystem
- // should always be properly encoded URLs, and *not* raw paths, and it
- // doesn't make sense to double-encode the URLs and expect that to be
- // handled by the implementation.
- // If a particular platform uses paths internally rather than URLs,
- // then that platform should careful to pass them correctly to its
- // backend.
- xit("file.spec.25 DirectoryEntry.getDirectory: create new dir with space resolveFileSystemURI with encoded URI", function() {
- var dirName = "de create dir2",
- dirPath = joinURL(root.fullPath, dirName),
- getDir = jasmine.createSpy().andCallFake(function(dirEntry) {
- var dirURI = dirEntry.toURL();
- // now encode URI and try to resolve
- runs(function() {
- window.resolveLocalFileSystemURI(encodeURI(dirURI), 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).toCanonicallyMatch(dirName);
- expect(directory.fullPath).toCanonicallyMatch(dirPath);
- // cleanup
- directory.remove(null, fail);
- }),
- fail = createFail('DirectoryEntry');
-
- // 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("file.spec.26 DirectoryEntry.getDirectory: create new directory", function() {
- var dirName = "de.create.dir",
- dirPath = joinURL(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).toCanonicallyMatch(dirName);
- expect(directory.fullPath).toCanonicallyMatch(dirPath);
- expect(directory.filesystem).toBeDefined();
- expect(directory.filesystem).toBe(root.filesystem);
-
- // 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("file.spec.27 DirectoryEntry.getDirectory: create new directory (exclusive)", function() {
- var dirName = "de.create.exclusive.dir",
- dirPath = joinURL(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).toCanonicallyMatch(dirName);
- expect(directory.fullPath).toCanonicallyMatch(dirPath);
- expect(directory.filesystem).toBeDefined();
- expect(directory.filesystem).toBe(root.filesystem);
-
- // 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("file.spec.28 DirectoryEntry.getDirectory: create directory that already exists", function() {
- var dirName = "de.create.existing.dir",
- dirPath = joinURL(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).toCanonicallyMatch(dirName);
- expect(directory.fullPath).toCanonicallyMatch(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("file.spec.29 DirectoryEntry.getDirectory: create directory that already exists (exclusive)", function() {
- var dirName = "de.create.exclusive.existing.dir",
- dirPath = joinURL(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).toBeFileError(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("file.spec.30 DirectoryEntry.getDirectory: get Entry for existing directory", function() {
- var dirName = "de.get.dir",
- dirPath = joinURL(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).toCanonicallyMatch(dirName);
-
- expect(directory.fullPath).toCanonicallyMatch(dirPath);
-
- // cleanup
- directory.remove(null, fail);
- }),
- fail = createFail('DirectoryEntry');
-
- // create directory to kick it off
- runs(function() {
- root.getDirectory(dirName, {create:true}, getDir, fail);
- });
- waitsFor(function() { return getDir.wasCalled; }, "getDir never called", Tests.TEST_TIMEOUT);
- });
- it("file.spec.31 DirectoryEntry.getDirectory: get DirectoryEntry for invalid path", function() {
- var dirName = "de:invalid:path",
- fail = jasmine.createSpy().andCallFake(function(error) {
- expect(error).toBeDefined();
- expect(error).toBeFileError(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("file.spec.32 DirectoryEntry.getDirectory: get DirectoryEntry for existing file", function() {
- var fileName = "de.existing.file",
- existingFile,
- filePath = joinURL(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).toBeFileError(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 never called", Tests.TEST_TIMEOUT);
- });
- it("file.spec.33 DirectoryEntry.getFile: get FileEntry for existing directory", function() {
- var dirName = "de.existing.dir",
- existingDir,
- dirPath = joinURL(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).toBeFileError(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("file.spec.34 DirectoryEntry.removeRecursively on directory", function() {
- var dirName = "de.removeRecursively",
- subDirName = "dir",
- dirPath = joinURL(root.fullPath, dirName),
- subDirPath = joinURL(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).toBeFileError(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("file.spec.35 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("file.spec.36 removeRecursively on root file system", function() {
- var remove = jasmine.createSpy().andCallFake(function(error) {
- expect(error).toBeDefined();
- expect(error).toBeFileError(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("file.spec.37 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 = root.createReader();
- // read entries
- 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("file.spec.37.1 should read contents of existing directory", function(done) {
- var fail = createFail('DirectoryReader', done),
- dirName = 'readEntries.dir',
- fileName = 'readeEntries.file';
- root.getDirectory(dirName, {create: true}, function(directory) {
- directory.getFile(fileName, {create: true}, function(fileEntry) {
- var reader = directory.createReader();
- reader.readEntries(function(entries) {
- expect(entries).toBeDefined();
- expect(entries instanceof Array).toBe(true);
- expect(entries.length).toBe(1);
- expect(entries[0].fullPath).toCanonicallyMatch(fileEntry.fullPath);
- expect(entries[0].filesystem).not.toBe(null)
- expect(entries[0].filesystem instanceof FileSystem).toBe(true)
-
- // cleanup
- directory.removeRecursively(done, fail);
- }, fail);
- }, fail);
- }, fail);
- });
- it("file.spec.109 should return an empty entry list on the second call", function() {
- var reader,
- firstWin = jasmine.createSpy().andCallFake(function(entries) {
- expect(entries).toBeDefined();
- expect(entries instanceof Array).toBe(true);
- expect(entries.length).not.toBe(0);
- reader.readEntries(secondWin, fail);
- }),
- secondWin = jasmine.createSpy().andCallFake(function(entries) {
- expect(entries).toBeDefined();
- expect(entries instanceof Array).toBe(true);
- expect(entries.length).toBe(0);
- }),
- fail = createFail('DirectoryReader');
-
- runs(function() {
- // Add a file to ensure the root directory is non-empty and then read the contents of the directory.
- root.getFile('test109.txt', { create: true }, function() {
- reader = root.createReader();
- reader.readEntries(firstWin, fail);
- }, fail);
- });
-
- waitsFor(function() { return secondWin.wasCalled; }, "secondWin never called", Tests.TEST_TIMEOUT);
-
- runs(function() {
- expect(firstWin).toHaveBeenCalled();
- expect(secondWin).toHaveBeenCalled();
- expect(fail).not.toHaveBeenCalled();
-
- // Remove the test file.
- root.getFile('test109.txt', { create: false }, function(fileEntry) {
- fileEntry.remove();
- }, fail);
- });
- });
- it("file.spec.38 should read contents of directory that has been removed", function() {
- var dirName = "de.createReader.notfound",
- dirPath = joinURL(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).toBeFileError(FileError.NOT_FOUND_ERR);
- });
-
- expect(error).toBeDefined();
- expect(error).toBeFileError(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("file.spec.39 constructor should be defined", function() {
- expect(File).toBeDefined();
- expect(typeof File).toBe('function');
- });
- it("file.spec.40 should be define File attributes", function() {
- var file = new File();
- expect(file.name).toBeDefined();
- expect(file.type).toBeDefined();
- expect(file.lastModifiedDate).toBeDefined();
- expect(file.size).toBeDefined();
- });
- });
-
- describe('FileEntry', function() {
- it("file.spec.41 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("file.spec.42 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.spec.43 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.spec.44 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).toBeFileError(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("file.spec.45 Entry object", function() {
- var fileName = "entry",
- fullPath = joinURL(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).toCanonicallyMatch(fileName);
- expect(entry.fullPath).toCanonicallyMatch(fullPath);
- expect(typeof entry.getMetadata).toBe('function');
- expect(typeof entry.setMetadata).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');
-
- // 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("file.spec.46 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);
- expect(isNaN(metadata.modificationTime.getTime())).toBe(false);
- expect(typeof metadata.size).toBe("number");
-
- // 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("file.spec.47 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);
- expect(isNaN(metadata.modificationTime.getTime())).toBe(false);
- expect(typeof metadata.size).toBe("number");
- expect(metadata.size).toBe(0);
-
- // 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("file.spec.48 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).toCanonicallyMatch(rootPath);
-
- // 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("file.spec.49 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).toCanonicallyMatch(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("file.spec.50 Entry.getParent on root file system", function() {
- var rootPath = root.fullPath,
- itParent = jasmine.createSpy().andCallFake(function(parent) {
- expect(parent).toBeDefined();
- expect(parent.fullPath).toCanonicallyMatch(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("file.spec.51 Entry.toURL on file", function() {
- var fileName = "entry.uri.file",
- rootPath = root.fullPath,
- itURI = 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, itURI, fail);
- });
-
- waitsFor(function() { return itURI.wasCalled; }, "itURI never called", Tests.TEST_TIMEOUT);
-
- runs(function() {
- expect(itURI).toHaveBeenCalled();
- expect(fail).not.toHaveBeenCalled();
- });
- });
- it("file.spec.52 Entry.toURL on directory", function() {
- var dirName1 = "num 1",
- dirName2 = "num 2",
- rootPath = root.fullPath,
- fail = createFail('Entry');
-
- createDirectory(dirName1, createNext, fail);
- function createNext(e1) {
- e1.getDirectory(dirName2, {create: true}, check, fail);
- }
- var check = jasmine.createSpy().andCallFake(function(entry) {
- var uri = entry.toURL();
- expect(uri).toBeDefined();
- expect(uri).toContain('/num%201/num%202/');
- expect(uri.indexOf(rootPath)).not.toBe(-1);
- // cleanup
- deleteEntry(dirName1);
- });
- waitsForAny(check, fail);
- });
- it("file.spec.53 Entry.remove on file", function() {
- var fileName = "entr .rm.file",
- fullPath = joinURL(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).toBeFileError(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("file.spec.54 remove on empty directory", function() {
- var dirName = "entry.rm.dir",
- dirPath = joinURL(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).toBeFileError(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("file.spec.55 remove on non-empty directory", function() {
- var dirName = "ent y.rm.dir.not.empty",
- fileName = "re ove.txt",
- fullPath = joinURL(root.fullPath, dirName),
- entryCallback = jasmine.createSpy().andCallFake(function(entry) {
- var checkFile = jasmine.createSpy().andCallFake(function(error) {
- expect(error).toBeDefined();
- expect(error).toBeFileError(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).toCanonicallyMatch(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("file.spec.56 remove on root file system", function() {
- var itRemove = jasmine.createSpy().andCallFake(function(error) {
- expect(error).toBeDefined();
- expect(error).toBeFileError(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("file.spec.57 copyTo: file", function() {
- var file1 = "entry copy.file1",
- file2 = "entry copy.file2",
- fullPath = joinURL(root.fullPath, file2),
- fail = createFail('Entry'),
- entryCallback = function(entry) {
- // copy file1 to file2
- entry.copyTo(root, file2, itCopy, fail);
- },
- itCopy = function(entry) {
- expect(entry).toBeDefined();
- expect(entry.isFile).toBe(true);
- expect(entry.isDirectory).toBe(false);
- expect(entry.fullPath).toCanonicallyMatch(fullPath);
- expect(entry.name).toCanonicallyMatch(file2);
-
- root.getFile(file2, {create:false}, itFileExists, fail);
- },
- 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).toCanonicallyMatch(fullPath);
- expect(entry2.name).toCanonicallyMatch(file2);
-
- // cleanup
- deleteEntry(file1);
- deleteEntry(file2);
- });
-
- // create a new file entry to kick off it
- deleteEntry(file2, function() {
- createFile(file1, entryCallback, fail);
- }, fail);
-
- waitsForAny(itFileExists, fail);
- });
- it("file.spec.58 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).toBeFileError(FileError.INVALID_MODIFICATION_ERR);
-
- // 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("file.spec.59 copyTo: directory", function() {
- var file1 = "file1",
- srcDir = "entry.copy.srcDir",
- dstDir = "entry.copy.dstDir",
- dstPath = joinURL(root.fullPath, dstDir),
- filePath = joinURL(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).toCanonicallyMatch(dstPath);
- expect(directory.name).toCanonicallyMatch(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).toCanonicallyMatch(dstPath);
- expect(dirEntry.name).toCanonicallyMatch(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).toCanonicallyMatch(filePath);
- expect(fileEntry.name).toCanonicallyMatch(file1);
-
- // cleanup
- deleteEntry(srcDir);
- deleteEntry(dstDir);
- }),
- fail = createFail('Entry');
-
- // create a new directory entry to kick off it
- runs(function() {
- deleteEntry(dstDir, function() {
- createDirectory(srcDir, entryCallback, fail);
- }, fail);
- });
-
- waitsFor(function() { return entryCallback.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT);
- });
- it("file.spec.60 copyTo: directory to backup at same root directory", function() {
- var file1 = "file1",
- srcDir = "entry.copy srcDirSame",
- dstDir = "entry.copy srcDirSame-backup",
- dstPath = joinURL(root.fullPath, dstDir),
- filePath = joinURL(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).toCanonicallyMatch(dstPath);
- expect(directory.name).toCanonicallyMatch(dstDir);
-
- 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).toCanonicallyMatch(dstPath);
- expect(dirEntry.name).toCanonicallyMatch(dstDir);
-
- dirEntry.getFile(file1, {create:false}, itFileExists, fail);
- },
- itFileExists = jasmine.createSpy().andCallFake(function(fileEntry) {
- var cleanSrc = jasmine.createSpy();
- var cleanDst = jasmine.createSpy();
- expect(fileEntry).toBeDefined();
- expect(fileEntry.isFile).toBe(true);
- expect(fileEntry.isDirectory).toBe(false);
- expect(fileEntry.fullPath).toCanonicallyMatch(filePath);
- expect(fileEntry.name).toCanonicallyMatch(file1);
- expect(fail).not.toHaveBeenCalled();
-
- // cleanup
- deleteEntry(srcDir, cleanSrc);
- deleteEntry(dstDir, cleanDst);
- });
-
- // create a new directory entry to kick off it
- deleteEntry(dstDir, function() {
- createDirectory(srcDir, entryCallback, fail);
- }, fail);
-
- waitsForAny(itFileExists, fail);
- });
- it("file.spec.61 copyTo: directory onto itself", function() {
- var file1 = "file1",
- srcDir = "entry.copy.dos.srcDir",
- srcPath = joinURL(root.fullPath, srcDir),
- filePath = joinURL(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).toBeFileError(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).toCanonicallyMatch(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).toCanonicallyMatch(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("file.spec.62 copyTo: directory into itself", function() {
- var srcDir = "entry.copy.dis.srcDir",
- dstDir = "entry.copy.dis.dstDir",
- fail = createFail('Entry'),
- win = createWin('Entry'),
- srcPath = joinURL(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).toBeFileError(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).toCanonicallyMatch(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("file.spec.63 copyTo: directory that does not exist", function() {
- var file1 = "entry.copy.dnf.file1";
- var dirName = 'dir-foo';
- var copySucceeded = createFail('copySucceeded');
- var fail = createFail('Entry');
-
- var copyFailed = jasmine.createSpy().andCallFake(function(error) {
- expect(error).toBeDefined();
- expect(error).toBeFileError(FileError.NOT_FOUND_ERR);
- });
-
- function afterCreateFile(fileEntry) {
- createDirectory(dirName, afterDirCreate, fail);
- function afterDirCreate(dirEntry) {
- dirEntry.remove(afterDirRemove, fail);
- function afterDirRemove() {
- fileEntry.copyTo(dirEntry, null, copySucceeded, copyFailed);
- }
- }
- }
- createFile(file1, afterCreateFile, fail);
-
- waitsForAny(fail, copySucceeded, copyFailed);
- });
- it("file.spec.64 copyTo: invalid target name", function() {
- var file1 = "entry.copy.itn.file1",
- file2 = "bad:file:name",
- filePath = joinURL(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).toBeFileError(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("file.spec.65 moveTo: file to same parent", function() {
- var file1 = "entry.move.fsp.file1",
- file2 = "entry.move.fsp.file2",
- srcPath = joinURL(root.fullPath, file1),
- dstPath = joinURL(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).toCanonicallyMatch(dstPath);
- expect(entry.name).toCanonicallyMatch(file2);
-
- 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).toCanonicallyMatch(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).toBeFileError(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("file.spec.66 moveTo: file to new parent", function() {
- var file1 = "entry.move.fnp.file1",
- dir = "entry.move.fnp.dir",
- srcPath = joinURL(root.fullPath, file1),
- win = createWin('Entry'),
- fail = createFail('Entry'),
- dstPath = joinURL(joinURL(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).toCanonicallyMatch(dstPath);
- expect(entry.name).toCanonicallyMatch(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);
- });
-
- // 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).toCanonicallyMatch(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).toBeFileError(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("file.spec.67 moveTo: directory to same parent", function() {
- var file1 = "file1",
- srcDir = "entry.move.dsp.srcDir",
- dstDir = "entry.move.dsp.dstDir",
- srcPath = joinURL(root.fullPath, srcDir),
- dstPath = joinURL(root.fullPath, dstDir),
- filePath = joinURL(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).toCanonicallyMatch(dstPath);
- expect(directory.name).toCanonicallyMatch(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).toCanonicallyMatch(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).toBeFileError(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("file.spec.68 moveTo: directory to same parent with same name", function() {
- var file1 = "file1",
- srcDir = "entry.move.dsp.srcDir",
- dstDir = "entry.move.dsp.srcDir-backup",
- srcPath = joinURL(root.fullPath, srcDir),
- dstPath = joinURL(root.fullPath, dstDir),
- filePath = joinURL(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).toCanonicallyMatch(dstPath);
- expect(directory.name).toCanonicallyMatch(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).toCanonicallyMatch(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).toBeFileError(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("file.spec.69 moveTo: directory to new parent", function() {
- var file1 = "file1",
- srcDir = "entry.move.dnp.srcDir",
- dstDir = "entry.move.dnp.dstDir",
- srcPath = joinURL(root.fullPath, srcDir),
- dstPath = joinURL(root.fullPath, dstDir),
- filePath = joinURL(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).toCanonicallyMatch(dstPath);
- expect(directory.name).toCanonicallyMatch(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).toCanonicallyMatch(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).toBeFileError(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("file.spec.70 moveTo: directory onto itself", function() {
- var file1 = "file1",
- srcDir = "entry.move.dos.srcDir",
- srcPath = joinURL(root.fullPath, srcDir),
- filePath = joinURL(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).toBeFileError(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).toCanonicallyMatch(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).toCanonicallyMatch(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("file.spec.71 moveTo: directory into itself", function() {
- var srcDir = "entry.move.dis.srcDir",
- dstDir = "entry.move.dis.dstDir",
- srcPath = joinURL(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).toBeFileError(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).toCanonicallyMatch(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("file.spec.72 moveTo: file onto itself", function() {
- var file1 = "entry.move.fos.file1",
- filePath = joinURL(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).toBeFileError(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).toCanonicallyMatch(filePath);
-
- // 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("file.spec.73 moveTo: file onto existing directory", function() {
- var file1 = "entry.move.fod.file1",
- dstDir = "entry.move.fod.dstDir",
- subDir = "subDir",
- dirPath = joinURL(joinURL(root.fullPath, dstDir), subDir),
- filePath = joinURL(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).toBeFileError(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);
- };
- // create sub-directory
- directory.getDirectory(subDir, {create: true}, moveFile, fail);
- };
- // create top level directory
- root.getDirectory(dstDir, {create: true}, createSubDirectory, fail);
- },
- itDirectoryExists = function(dirEntry) {
- expect(dirEntry).toBeDefined();
- expect(dirEntry.fullPath).toCanonicallyMatch(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).toCanonicallyMatch(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("file.spec.74 moveTo: directory onto existing file", function() {
- var file1 = "entry.move.dof.file1",
- srcDir = "entry.move.dof.srcDir",
- dirPath = joinURL(root.fullPath, srcDir),
- filePath = joinURL(root.fullPath, file1),
- win = createWin('Entry'),
- fail = createFail('Entry'),
- entryCallback = function(entry) {
- var moveDir = function(fileEntry) {
- // move directory onto file
- entry.moveTo(root, file1, win, itMove);
- };
- // create file
- root.getFile(file1, {create: true}, moveDir, fail);
- },
- itMove = function(error) {
- expect(error).toBeDefined();
- expect(error).toBeFileError(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).toCanonicallyMatch(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).toCanonicallyMatch(filePath);
-
- // 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("file.spec.75 copyTo: directory onto existing file", function() {
- var file1 = "entry.copy.dof.file1",
- srcDir = "entry.copy.dof.srcDir",
- dirPath = joinURL(root.fullPath, srcDir),
- filePath = joinURL(root.fullPath, file1),
- win = createWin('Entry'),
- fail = createFail('Entry'),
- entryCallback = function(entry) {
- var copyDir = function(fileEntry) {
- // move directory onto file
- entry.copyTo(root, file1, win, itMove);
- };
- // create file
- root.getFile(file1, {create: true}, copyDir, fail);
- },
- itMove = function(error) {
- expect(error).toBeDefined();
- expect(error).toBeFileError(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).toCanonicallyMatch(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).toCanonicallyMatch(filePath);
-
- // 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("file.spec.76 moveTo: directory onto directory that is not empty", function() {
- var srcDir = "entry.move.dod.srcDir",
- dstDir = "entry.move.dod.dstDir",
- subDir = "subDir",
- srcPath = joinURL(root.fullPath, srcDir),
- dstPath = joinURL(joinURL(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).toBeFileError(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 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).toCanonicallyMatch(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).toCanonicallyMatch(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("file.spec.77 moveTo: file replace existing file", function() {
- var file1 = "entry.move.frf.file1",
- file2 = "entry.move.frf.file2",
- file1Path = joinURL(root.fullPath, file1),
- file2Path = joinURL(root.fullPath, file2),
- win = createWin('Entry'),
- fail = createFail('Entry'),
- entryCallback = function(entry) {
- var moveFile = function(fileEntry) {
- // replace file2 with file1
- entry.moveTo(root, file2, itMove, fail);
- };
- // 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).toCanonicallyMatch(file2Path);
- expect(entry.name).toCanonicallyMatch(file2);
-
- // it that old file does not exists
- root.getFile(file1, {create:false}, win, itFileMoved);
- },
- itFileMoved = function(error){
- expect(error).toBeDefined();
- expect(error).toBeFileError(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).toCanonicallyMatch(file2Path);
-
- // 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("file.spec.78 moveTo: directory replace empty directory", function() {
- var file1 = "file1",
- srcDir = "entry.move.drd.srcDir",
- dstDir = "entry.move.drd.dstDir",
- srcPath = joinURL(root.fullPath, srcDir),
- dstPath = joinURL(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).toCanonicallyMatch(dstPath);
- expect(directory.name).toCanonicallyMatch(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).toCanonicallyMatch(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).toBeFileError(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("file.spec.79 moveTo: directory that does not exist", function() {
- var file1 = "entry.move.dnf.file1",
- dstDir = "entry.move.dnf.dstDir",
- filePath = joinURL(root.fullPath, file1),
- dstPath = joinURL(root.fullPath, dstDir),
- win = createWin('Entry'),
- fail = createFail('Entry'),
- entryCallback = function(entry) {
- // move file to directory that does not exist
- directory = new DirectoryEntry();
- directory.filesystem = root.filesystem;
- directory.fullPath = dstPath;
- entry.moveTo(directory, null, win, itMove);
- },
- itMove = jasmine.createSpy().andCallFake(function(error) {
- expect(error).toBeDefined();
- expect(error).toBeFileError(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("file.spec.80 moveTo: invalid target name", function() {
- var file1 = "entry.move.itn.file1",
- file2 = "bad:file:name",
- filePath = joinURL(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).toBeFileError(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("file.spec.81 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("file.spec.82 should error out on non-existent file", function() {
- var fileName = "somefile.txt";
- var getFileFail = createFail('create');
- var fileFail = createFail('file');
- var deleteFail = createFail('delete');
- var readWorked = createFail('read');
- var verifier = jasmine.createSpy().andCallFake(function(evt) {
- expect(evt).toBeDefined();
- expect(evt.target.error).toBeFileError(FileError.NOT_FOUND_ERR);
- });
- root.getFile(fileName, {create: true}, afterGetFile, getFileFail);
- function afterGetFile(entry) {
- entry.file(afterFile, fileFail);
- }
- function afterFile(f) {
- deleteEntry(fileName, afterDelete, deleteFail);
- function afterDelete() {
- var reader = new FileReader();
- reader.onerror = verifier;
- reader.onload = readWorked;
- reader.readAsText(f);
- }
- }
- waitsForAny(getFileFail, fileFail, deleteFail, readWorked, verifier);
- });
- it("file.spec.83 should be able to read native blob objects", function() {
- // Skip test if blobs are not supported (e.g.: Android 2.3).
- if (typeof window.Blob == 'undefined' || typeof window.Uint8Array == 'undefined') {
- return;
- }
- var contents = 'asdf';
- var uint8Array = new Uint8Array(contents.length);
- for (var i = 0; i < contents.length; ++i) {
- uint8Array[i] = contents.charCodeAt(i);
- }
- var Builder = window.BlobBuilder || window.WebKitBlobBuilder;
- var blob;
- if (Builder) {
- var builder = new Builder();
- builder.append(uint8Array.buffer);
- builder.append(contents);
- blob = builder.getBlob("text/plain");
- } else {
- try {
- // iOS 6 does not support Views, so pass in the buffer.
- blob = new Blob([uint8Array.buffer, contents]);
- } catch (e) {
- // Skip the test if we can't create a blob (e.g.: iOS 5).
- if (e instanceof TypeError) {
- return;
- }
- throw e;
- }
- }
- var verifier = jasmine.createSpy().andCallFake(function(evt) {
- expect(evt).toBeDefined();
- expect(evt.target.result).toBe('asdfasdf');
- });
- var reader = new FileReader();
- reader.onloadend = verifier;
- reader.readAsText(blob);
-
- waitsFor(function() { return verifier.wasCalled; }, "verifier never called", 300);
- });
-
- function writeDummyFile(writeBinary, callback) {
- var fileName = "dummy.txt",
- fileEntry = null,
- writerFail = createFail('createWriter'),
- getFileFail = createFail('getFile'),
- fileFail = createFail('file'),
- callback = jasmine.createSpy().andCallFake(callback),
- fileData = '\u20AC\xEB - There is an exception to every rule. Except this one.',
- fileDataAsBinaryString = '\xe2\x82\xac\xc3\xab - There is an exception to every rule. Except this one.',
- createWriter = function(fe) {
- fileEntry = fe;
- fileEntry.createWriter(writeFile, writerFail);
- },
- // writes file and reads it back in
- writeFile = function(writer) {
- writer.onwriteend = function() {
- fileEntry.file(function(f) {
- callback(fileEntry, f, fileData, fileDataAsBinaryString);
- }, fileFail);
- };
- writer.write(fileData);
- };
- fileData += writeBinary ? 'bin:\x01\x00' : '';
- fileDataAsBinaryString += writeBinary ? 'bin:\x01\x00' : '';
- // create a file, write to it, and read it in again
- createFile(fileName, createWriter, getFileFail);
- waitsForAny(getFileFail, writerFail, fileFail, callback);
- }
-
- function runReaderTest(funcName, writeBinary, verifierFunc, sliceStart, sliceEnd) {
- writeDummyFile(writeBinary, function(fileEntry, file, fileData, fileDataAsBinaryString) {
- var readWin = jasmine.createSpy().andCallFake(function(evt) {
- expect(evt).toBeDefined();
- verifierFunc(evt, fileData, fileDataAsBinaryString);
- });
-
- var reader = new FileReader();
- var readFail = createFail(funcName);
- reader.onload = readWin;
- reader.onerror = readFail;
- if (sliceEnd !== undefined) {
- file = file.slice(sliceStart, sliceEnd);
- } else if (sliceStart !== undefined) {
- file = file.slice(sliceStart);
- }
- reader[funcName](file);
-
- waitsForAny(readWin, readFail);
- });
- }
-
- function arrayBufferEqualsString(ab, str) {
- var buf = new Uint8Array(ab);
- var match = buf.length == str.length;
-
- for (var i = 0; match && i < buf.length; i++) {
- match = buf[i] == str.charCodeAt(i);
- }
- return match;
- }
-
- it("file.spec.84 should read file properly, readAsText", function() {
- runReaderTest('readAsText', false, function(evt, fileData, fileDataAsBinaryString) {
- expect(evt.target.result).toBe(fileData);
- });
- });
- it("file.spec.85 should read file properly, Data URI", function() {
- runReaderTest('readAsDataURL', true, function(evt, fileData, fileDataAsBinaryString) {
- expect(evt.target.result.substr(0,23)).toBe("data:text/plain;base64,");
- expect(evt.target.result.slice(23)).toBe(atob(fileData));
- });
- });
- it("file.spec.86 should read file properly, readAsBinaryString", function() {
- runReaderTest('readAsBinaryString', true, function(evt, fileData, fileDataAsBinaryString) {
- expect(evt.target.result).toBe(fileDataAsBinaryString);
- });
- });
- it("file.spec.87 should read file properly, readAsArrayBuffer", function() {
- // Skip test if ArrayBuffers are not supported (e.g.: Android 2.3).
- if (typeof window.ArrayBuffer == 'undefined') {
- return;
- }
- runReaderTest('readAsArrayBuffer', true, function(evt, fileData, fileDataAsBinaryString) {
- expect(arrayBufferEqualsString(evt.target.result, fileDataAsBinaryString)).toBe(true);
- });
- });
- it("file.spec.88 should read sliced file: readAsText", function() {
- runReaderTest('readAsText', false, function(evt, fileData, fileDataAsBinaryString) {
- expect(evt.target.result).toBe(fileDataAsBinaryString.slice(10, 40));
- }, 10, 40);
- });
- it("file.spec.89 should read sliced file: slice past eof", function() {
- runReaderTest('readAsText', false, function(evt, fileData, fileDataAsBinaryString) {
- expect(evt.target.result).toBe(fileData.slice(-5, 9999));
- }, -5, 9999);
- });
- it("file.spec.90 should read sliced file: slice to eof", function() {
- runReaderTest('readAsText', false, function(evt, fileData, fileDataAsBinaryString) {
- expect(evt.target.result).toBe(fileData.slice(-5));
- }, -5);
- });
- it("file.spec.91 should read empty slice", function() {
- runReaderTest('readAsText', false, function(evt, fileData, fileDataAsBinaryString) {
- expect(evt.target.result).toBe('');
- }, 0, 0);
- });
- it("file.spec.92 should read sliced file properly, readAsDataURL", function() {
- runReaderTest('readAsDataURL', true, function(evt, fileData, fileDataAsBinaryString) {
- expect(evt.target.result.slice(0, 23)).toBe("data:text/plain;base64,");
- expect(evt.target.result.slice(23)).toBe(atob(fileDataAsBinaryString.slice( 10, -3)));
- }, 10, -3);
- });
- it("file.spec.93 should read sliced file properly, readAsBinaryString", function() {
- runReaderTest('readAsBinaryString', true, function(evt, fileData, fileDataAsBinaryString) {
- expect(evt.target.result).toBe(fileDataAsBinaryString.slice(-10, -5));
- }, -10, -5);
- });
- it("file.spec.94 should read sliced file properly, readAsArrayBuffer", function() {
- // Skip test if ArrayBuffers are not supported (e.g.: Android 2.3).
- if (typeof window.ArrayBuffer == 'undefined') {
- return;
- }
- runReaderTest('readAsArrayBuffer', true, function(evt, fileData, fileDataAsBinaryString) {
- expect(arrayBufferEqualsString(evt.target.result, fileDataAsBinaryString.slice(0, -1))).toBe(true);
- }, 0, -1);
- });
- });
-
- describe('FileWriter', function(){
- it("file.spec.95 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
- deleteFile(fileName);
- }),
- it_writer = function(fileEntry) {
- fileEntry.createWriter(verifier, fail);
- };
-
- // 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("file.spec.96 should be able to write and append to file, createWriter", function() {
- var fileName = "writer.append.createWriter",
- theWriter,
- filePath = joinURL(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
- deleteFile(fileName);
- }),
- // writes initial file content
- write_file = function(fileEntry) {
- fileEntry.createWriter(function(writer) {
- theWriter = writer;
- writer.onwriteend = verifier;
- writer.write(rule);
- }, fail);
- };
-
- // 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("file.spec.97 should be able to write and append to file, File object", function() {
- var fileName = "writer.append.File",
- theWriter,
- // file content
- rule = "There is an exception to every rule.",
- // for checking file length
- length = rule.length,
- createWriterFail = createFail('createWriter'),
- 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
- deleteFile(fileName);
- });
- function afterCreateWriter(w) {
- theWriter = w;
- theWriter.onwriteend = verifier;
- theWriter.write(rule);
- }
- function afterGetFile(fileEntry) {
- fileEntry.createWriter(afterCreateWriter, createWriterFail);
- }
-
- var getFileFail = createFail('create');
- root.getFile(fileName, {create: true}, afterGetFile, getFileFail);
-
- waitsForAny(anotherVerifier, getFileFail, createWriterFail);
- });
- it("file.spec.98 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 = joinURL(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
- deleteFile(fileName);
- }),
- // writes initial file content
- write_file = function(fileEntry) {
- fileEntry.createWriter(function(writer) {
- theWriter = writer;
- theWriter.onwriteend = verifier;
- theWriter.write(rule);
- }, fail);
- };
-
- // 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("file.spec.99 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 = joinURL(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
- deleteFile(fileName);
- }),
- // writes initial file content
- write_file = function(fileEntry) {
- fileEntry.createWriter(function(writer) {
- theWriter = writer;
- theWriter.onwriteend = verifier;
- theWriter.write(rule);
- }, fail);
- };
-
- // 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("file.spec.100 should be able to write XML data", function() {
- var fileName = "writer.xml",
- filePath = joinURL(root.fullPath, fileName),
- fail = createFail('FileWriter'),
- theWriter,
- // file content
- rule = '<?xml version="1.0" encoding="UTF-8"?>\n<it prop="ack">\nData\n</it>\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
- 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
- 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("file.spec.101 should be able to write JSON data", function() {
- var fileName = "writer.json",
- filePath = joinURL(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
- 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 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("file.spec.102 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("file.spec.103 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
- 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();
- });
- });
- it("file.spec.104 should be able to write binary data from an ArrayBuffer", function() {
- // Skip test if ArrayBuffers are not supported (e.g.: Android 2.3).
- if (typeof window.ArrayBuffer == 'undefined') {
- return;
- }
- var fileName = "bufferwriter.bin",
- filePath = joinURL(root.fullPath, fileName),
- theWriter,
- // file content
- data = new ArrayBuffer(32),
- dataView = new Int8Array(data),
- fail = createFail('FileWriter'),
- // for verifying file length
- length = 32,
- verifier = jasmine.createSpy().andCallFake(function(evt) {
- expect(theWriter.length).toBe(length);
- expect(theWriter.position).toBe(length);
-
- // cleanup
- deleteFile(fileName);
- }),
- // writes file content
- write_file = function(fileEntry) {
- fileEntry.createWriter(function(writer) {
- theWriter = writer;
- theWriter.onwriteend = verifier;
- theWriter.write(data);
- }, fail);
- };
-
- for (i=0; i < dataView.length; i++) {
- dataView[i] = i;
- }
-
- // creates file, then write 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("file.spec.105 should be able to write binary data from a Blob", function() {
- // Skip test if Blobs are not supported (e.g.: Android 2.3).
- if ( (typeof window.Blob != 'function' &&
- typeof window.WebKitBlobBuilder == 'undefined') ||
- typeof window.ArrayBuffer == 'undefined') {
- return;
- }
- var fileName = "blobwriter.bin",
- filePath = joinURL(root.fullPath, fileName),
- theWriter,
- fail = createFail('FileWriter'),
- // file content
- data = new ArrayBuffer(32),
- dataView = new Int8Array(data),
- blob,
- // for verifying file length
- length = 32,
- verifier = jasmine.createSpy().andCallFake(function(evt) {
- expect(theWriter.length).toBe(length);
- expect(theWriter.position).toBe(length);
-
- // cleanup
- deleteFile(fileName);
- }),
- // writes file content
- write_file = function(fileEntry) {
- fileEntry.createWriter(function(writer) {
- theWriter = writer;
- theWriter.onwriteend = verifier;
- theWriter.write(blob);
- }, fail);
- };
- for (i=0; i < dataView.length; i++) {
- dataView[i] = i;
- }
- try {
- // Mobile Safari: Use Blob constructor
- blob = new Blob([data], {"type": "application/octet-stream"});
- } catch(e) {
- if (window.WebKitBlobBuilder) {
- // Android Browser: Use deprecated BlobBuilder
- var builder = new WebKitBlobBuilder();
- builder.append(data);
- blob = builder.getBlob('application/octet-stream');
- } else {
- // We have no way defined to create a Blob, so fail
- fail();
- }
- }
-
- if (typeof blob !== 'undefined') {// creates file, then write 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("file.spec.106 should be able to write a File to a FileWriter", function() {
- var dummyFileName = 'dummy.txt',
- outputFileName = 'verify.txt',
- dummyFileText = 'This text should be written to two files',
- fail = createFail('FileWriter'),
- verifier = jasmine.createSpy("verifier").andCallFake(function(outputFileWriter) {
- expect(outputFileWriter.length).toBe(dummyFileText.length);
- expect(outputFileWriter.position).toBe(dummyFileText.length);
- deleteFile(outputFileName);
- }),
- writeFile = function(fileName, fileData, win) {
- var theWriter,
- filePath = joinURL(root.fullPath, fileName),
- // writes file content to new file
- write_file = function(fileEntry) {
- writerEntry = fileEntry;
- fileEntry.createWriter(function(writer) {
- theWriter = writer;
- writer.onwriteend = function(ev) {
- if (typeof fileData.length !== "undefined") {
- expect(theWriter.length).toBe(fileData.length);
- expect(theWriter.position).toBe(fileData.length);
- }
- win(theWriter);
- }
- writer.onerror = fail;
- writer.write(fileData);
- }, fail);
- };
- createFile(fileName, write_file, fail);
- },
-
- openFile = function(fileName, callback) {
- root.getFile(fileName, {create: false}, function(fileEntry) {
- fileEntry.file(callback, fail);
- }, fail);
- };
-
- runs(function() {
- writeFile(dummyFileName, dummyFileText, function(dummyFileWriter) {
- openFile(dummyFileName, function(file) {
- writeFile(outputFileName, file, verifier);
- });
- });
- });
- waitsFor(function() { return (verifier.wasCalled || fail.wasCalled); }, "callbacks never called", Tests.TEST_TIMEOUT);
-
- runs(function() {
- expect(verifier).toHaveBeenCalled();
- expect(fail).not.toHaveBeenCalled();
- });
-
- });
- it("file.spec.107 should be able to write a sliced File to a FileWriter", function() {
- var dummyFileName = 'dummy2.txt',
- outputFileName = 'verify2.txt',
- dummyFileText = 'This text should be written to two files',
- fail = createFail('FileWriter'),
- verifier = jasmine.createSpy("verifier").andCallFake(function(outputFileWriter) {
- expect(outputFileWriter.length).toBe(10);
- expect(outputFileWriter.position).toBe(10);
- deleteFile(outputFileName);
- }),
- writeFile = function(fileName, fileData, win) {
- var theWriter,
- filePath = joinURL(root.fullPath, fileName),
- // writes file content to new file
- write_file = function(fileEntry) {
- writerEntry = fileEntry;
- fileEntry.createWriter(function(writer) {
- theWriter = writer;
- writer.onwriteend = function(ev) {
- if (typeof fileData.length !== "undefined") {
- expect(theWriter.length).toBe(fileData.length);
- expect(theWriter.position).toBe(fileData.length);
- }
- win(theWriter);
- }
- writer.onerror = fail;
- writer.write(fileData);
- }, fail);
- };
- createFile(fileName, write_file, fail);
- },
-
- openFile = function(fileName, callback) {
- root.getFile(fileName, {create: false}, function(fileEntry) {
- fileEntry.file(callback, fail);
- }, fail);
- };
-
- runs(function() {
- writeFile(dummyFileName, dummyFileText, function(dummyFileWriter) {
- openFile(dummyFileName, function(file) {
- writeFile(outputFileName, file.slice(10,20), verifier);
- });
- });
- });
- waitsFor(function() { return (verifier.wasCalled || fail.wasCalled); }, "callbacks never called", Tests.TEST_TIMEOUT);
-
- runs(function() {
- expect(verifier).toHaveBeenCalled();
- expect(fail).not.toHaveBeenCalled();
- });
-
- });
- it("file.spec.108 should be able to write binary data from a File", function() {
- // Skip test if Blobs are not supported (e.g.: Android 2.3).
- if ( (typeof window.Blob != 'function' &&
- typeof window.WebKitBlobBuilder == 'undefined') ||
- typeof window.ArrayBuffer == 'undefined') {
- return;
- }
- var dummyFileName = "blobwriter.bin",
- outputFileName = 'verify.bin',
- fail = createFail('FileWriter'),
- // file content
- data = new ArrayBuffer(32),
- dataView = new Int8Array(data),
- blob,
- // for verifying file length
- length = 32,
- verifier = jasmine.createSpy("verifier").andCallFake(function(outputFileWriter) {
- expect(outputFileWriter.length).toBe(length);
- expect(outputFileWriter.position).toBe(length);
-
- // cleanup
- deleteFile(outputFileName);
- }),
- writeFile = function(fileName, fileData, win) {
- var theWriter,
- filePath = joinURL(root.fullPath, fileName),
- // writes file content to new file
- write_file = function(fileEntry) {
- writerEntry = fileEntry;
- fileEntry.createWriter(function(writer) {
- theWriter = writer;
- writer.onwriteend = function(ev) {
- if (typeof fileData.length !== "undefined") {
- expect(theWriter.length).toBe(fileData.length);
- expect(theWriter.position).toBe(fileData.length);
- }
- win(theWriter);
- }
- writer.onerror = fail;
- writer.write(fileData);
- }, fail);
- };
- createFile(fileName, write_file, fail);
- },
-
- openFile = function(fileName, callback) {
- root.getFile(fileName, {create: false}, function(fileEntry) {
- fileEntry.file(callback, fail);
- }, fail);
- };
-
- for (i=0; i < dataView.length; i++) {
- dataView[i] = i;
- }
- try {
- // Mobile Safari: Use Blob constructor
- blob = new Blob([data], {"type": "application/octet-stream"});
- } catch(e) {
- if (window.WebKitBlobBuilder) {
- // Android Browser: Use deprecated BlobBuilder
- var builder = new WebKitBlobBuilder();
- builder.append(data);
- blob = builder.getBlob('application/octet-stream');
- } else {
- // We have no way defined to create a Blob, so fail
- fail();
- }
- }
-
- if (typeof blob !== 'undefined') {// creates file, then write content
- runs(function() {
- writeFile(dummyFileName, blob, function(dummyFileWriter) {
- openFile(dummyFileName, function(file) {
- writeFile(outputFileName, file, verifier);
- });
- });
- });
- waitsFor(function() { return (verifier.wasCalled || fail.wasCalled); }, "callbacks never called", Tests.TEST_TIMEOUT);
-
- runs(function() {
- expect(verifier).toHaveBeenCalled();
- expect(fail).not.toHaveBeenCalled();
- });
- }
- });
- });
- describe('Backwards compatibility', function() {
- /* These specs exist to test that the File plugin can still recognize file:///
- * URLs, and can resolve them to FileEntry and DirectoryEntry objects.
- * They rely on an undocumented interface to File which provides absolute file
- * paths, which are not used internally anymore.
- * If that interface is not present, then these tests will silently succeed.
- */
- it("file.spec.109 should be able to resolve a file:/// URL", function() {
- var localFilename = 'file.txt';
- var localURL = dirPath = joinURL(root.toURL(), 'file.txt');
- var originalEntry;
-
- var unsupportedOperation = jasmine.createSpy("Operation not supported");
-
- var resolveWin = jasmine.createSpy("resolveWin").andCallFake(function(fileEntry) {
- expect(fileEntry.toURL()).toEqual(originalEntry.toURL());
- // cleanup
- deleteFile(localFilename);
- });
- var resolveFail = createDoNotCallSpy('resolveFail');
- var getFail = createDoNotCallSpy('getFail');
-
- runs(function() {
- root.getFile(localFilename, {create: true}, function(entry) {
- originalEntry = entry;
- /* This is an undocumented interface to File which exists only for testing
- * backwards compatibilty. By obtaining the raw filesystem path of the download
- * location, we can pass that to ft.download() to make sure that previously-stored
- * paths are still valid.
- */
- cordova.exec(function(localPath) {
- window.resolveLocalFileSystemURI("file://" + encodeURI(localPath), resolveWin, resolveFail);
- }, unsupportedOperation, 'File', '_getLocalFilesystemPath', [entry.toURL()]);
- }, getFail);
- });
-
- waitsForAny(resolveWin, resolveFail, getFail, unsupportedOperation);
-
- runs(function() {
- if (!unsupportedOperation.wasCalled) {
- expect(resolveWin).toHaveBeenCalled();
- expect(resolveFail).not.toHaveBeenCalled();
- }
- });
-
- });
- });
- describe('Parent References', function() {
- /* These specs verify that paths with parent references i("..") in them
- * work correctly, and do not cause the application to crash.
- */
- it("file.spec.110 should not throw exception resolving parent refefences", function() {
- /* This is a direct copy of file.spec.9, with the filename changed,
- * as reported in CB-5721.
- */
- var fileName = "resolve.file.uri",
- win = jasmine.createSpy().andCallFake(function(fileEntry) {
- expect(fileEntry).toBeDefined();
- expect(fileEntry.name).toCanonicallyMatch(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("file.spec.111 should not traverse above above the root directory", function() {
- var fileName = "traverse.file.uri",
- win = jasmine.createSpy().andCallFake(function(fileEntry) {
- expect(fileEntry).toBeDefined();
- expect(fileEntry.name).toBe(fileName);
- expect(fileEntry.fullPath).toBe('/' + fileName);
-
- // cleanup
- deleteEntry(fileName);
- }),
- fail = createFail('spec.111'),
- createCallback = jasmine.createSpy().andCallFake(function(entry) {
- // lookup file system entry
- runs(function() {
- root.getFile('../' + fileName, {create: false}, win, fail);
- });
-
- waitsFor(function() { return (win.wasCalled || fail.wasCalled); }, "getFile callback never called", Tests.TEST_TIMEOUT);
-
- runs(function() {
- expect(win).toHaveBeenCalled();
- expect(fail).not.toHaveBeenCalled();
- });
- });
-
- // create a new file entry
- runs(function() {
- createFile(fileName, createCallback, fail);
- });
-
- waitsFor(function() { return createCallback.wasCalled; }, "createFile callback never called", Tests.TEST_TIMEOUT);
- });
-
- it("file.spec.112 should traverse above above the current directory", function() {
- var fileName = "traverse2.file.uri",
- dirName = "traverse2.subdir",
- win = jasmine.createSpy().andCallFake(function(fileEntry) {
- expect(fileEntry).toBeDefined();
- expect(fileEntry.name).toBe(fileName);
- expect(fileEntry.fullPath).toBe('/' + fileName);
-
- // cleanup
- deleteEntry(fileName);
- deleteEntry(dirName);
- }),
- fail = createFail('spec.112'),
- createCallback = jasmine.createSpy().andCallFake(function(entry) {
- // lookup file system entry
- runs(function() {
- entry.getFile('../' + fileName, {create: false}, win, fail);
- });
-
- waitsFor(function() { return (win.wasCalled || fail.wasCalled); }, "getFile callback never called", Tests.TEST_TIMEOUT);
-
- runs(function() {
- expect(win).toHaveBeenCalled();
- expect(fail).not.toHaveBeenCalled();
- });
- });
-
- // create a new directory and a file entry
- runs(function() {
- createFile(fileName, function(entry) {
- createDirectory(dirName, createCallback, fail);
- }, fail);
- });
-
- waitsFor(function() { return createCallback.wasCalled; }, "createFile callback never called", Tests.TEST_TIMEOUT);
- });
-
- it("file.spec.113 getFile: get Entry should error for missing file above root directory", function() {
- var fileName = "../missing.file",
- filePath = joinURL(root.fullPath, fileName),
- fail = jasmine.createSpy().andCallFake(function(error) {
- expect(error).toBeDefined();
- expect(error).toBeFileError(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();
- });
- });
-
- });
- describe('toNativeURL interface', function() {
- /* These specs verify that FileEntries have a toNativeURL method
- * which appears to be sane.
- */
- it("file.spec.114 fileEntry should have a toNativeURL method", function() {
- var fileName = "native.file.uri",
- win = jasmine.createSpy().andCallFake(function(fileEntry) {
- expect(fileEntry).toBeDefined();
- expect(fileEntry.name).toCanonicallyMatch(fileName);
-
- // cleanup
- deleteEntry(fileName);
- }),
- fail = createFail('window.resolveLocalFileSystemURI'),
- createCallback = jasmine.createSpy().andCallFake(function(entry) {
- expect(entry.toNativeURL).toBeDefined();
- expect(typeof entry.toNativeURL).toBe('function');
- var nativeURL = entry.toNativeURL();
- expect(typeof nativeURL).toBe("string");
- expect(nativeURL.substring(0,7)).toEqual("file://");
- expect(nativeURL.substring(nativeURL.length - fileName.length)).toEqual(fileName);
- });
-
- // create a new file entry
- runs(function() {
- createFile(fileName, createCallback, fail);
- });
-
- waitsFor(function() { return createCallback.wasCalled; }, "createFile callback never called", Tests.TEST_TIMEOUT);
- });
- it("file.spec.115 DirectoryReader should return entries with toNativeURL method", function(done) {
- var fail = createFail('DirectoryReader', done),
- dirName = 'nativeEntries.dir',
- fileName = 'nativeEntries.file',
- checkEntries = jasmine.createSpy().andCallFake(function(entries) {
- expect(entries).toBeDefined();
- expect(entries instanceof Array).toBe(true);
- expect(entries.length).toBe(1);
- expect(entries[0].toNativeURL).toBeDefined();
- expect(typeof entries[0].toNativeURL).toBe('function');
- var nativeURL = entries[0].toNativeURL();
- expect(typeof nativeURL).toBe("string");
- expect(nativeURL.substring(0,7)).toEqual("file://");
- expect(nativeURL.substring(nativeURL.length - fileName.length)).toEqual(fileName);
-
- // cleanup
- directory.removeRecursively(done, fail);
- });
- // create a new file entry
- runs(function() {
- root.getDirectory(dirName, {create: true}, function(directory) {
- directory.getFile(fileName, {create: true}, function(fileEntry) {
- var reader = directory.createReader();
- reader.readEntries(checkEntries, fail);
- }, fail);
- }, fail);
- });
-
- waitsFor(function() { return checkEntries.wasCalled; }, "checkEntries callback never called", Tests.TEST_TIMEOUT);
- });
- it("file.spec.116 resolveLocalFileSystemURL should return entries with toNativeURL method", function() {
- var fileName = "native.resolve.uri",
- win = jasmine.createSpy().andCallFake(function(fileEntry) {
- expect(fileEntry).toBeDefined();
- expect(fileEntry.name).toCanonicallyMatch(fileName);
-
- // cleanup
- deleteEntry(fileName);
- }),
- fail = createFail('window.resolveLocalFileSystemURI'),
- checkEntry = jasmine.createSpy().andCallFake(function(entry) {
- expect(entry.toNativeURL).toBeDefined();
- expect(typeof entry.toNativeURL).toBe('function');
- var nativeURL = entry.toNativeURL();
- expect(typeof nativeURL).toBe("string");
- expect(nativeURL.substring(0,7)).toEqual("file://");
- expect(nativeURL.substring(nativeURL.length - fileName.length)).toEqual(fileName);
- });
-
- // create a new file entry
- runs(function() {
- createFile(fileName, function(entry) {
- resolveLocalFileSystemURL(entry.toURL(), checkEntry, fail);
- }, fail);
- });
-
- waitsFor(function() { return checkEntry.wasCalled; }, "checkEntry callback never called", Tests.TEST_TIMEOUT);
- });
- });
- describe('resolveLocalFileSystemURL on file://', function() {
- /* These specs verify that window.resolveLocalFileSystemURL works correctly on file:// URLs
- */
- it("file.spec.117 should not resolve native URLs outside of FS roots", function() {
- var fail = jasmine.createSpy().andCallFake(function(error) {
- expect(error).toBeDefined();
- }),
- win = createWin('window.resolveLocalFileSystemURI');
-
- // lookup file system entry
- runs(function() {
- window.resolveLocalFileSystemURL("file:///this.is.an.invalid.url", win, fail);
- });
-
- waitsFor(function() { return fail.wasCalled; }, "error callback never called", Tests.TEST_TIMEOUT);
-
- runs(function() {
- expect(fail).toHaveBeenCalled();
- expect(win).not.toHaveBeenCalled();
- });
- });
- it("file.spec.118 should not resolve native URLs outside of FS roots", function() {
- var fail = jasmine.createSpy().andCallFake(function(error) {
- expect(error).toBeDefined();
- }),
- win = createWin('window.resolveLocalFileSystemURI');
-
- // lookup file system entry
- runs(function() {
- window.resolveLocalFileSystemURL("file://localhost/this.is.an.invalid.url", win, fail);
- });
-
- waitsFor(function() { return fail.wasCalled; }, "error callback never called", Tests.TEST_TIMEOUT);
-
- runs(function() {
- expect(fail).toHaveBeenCalled();
- expect(win).not.toHaveBeenCalled();
- });
- });
- it("file.spec.119 should not resolve invalid native URLs", function() {
- var fail = jasmine.createSpy().andCallFake(function(error) {
- expect(error).toBeDefined();
- }),
- win = createWin('window.resolveLocalFileSystemURI');
-
- // lookup file system entry
- runs(function() {
- window.resolveLocalFileSystemURL("file://localhost", win, fail);
- });
-
- waitsFor(function() { return fail.wasCalled; }, "error callback never called", Tests.TEST_TIMEOUT);
-
- runs(function() {
- expect(fail).toHaveBeenCalled();
- expect(win).not.toHaveBeenCalled();
- });
- });
- it("file.spec.120 should not resolve invalid native URLs with query strings", function() {
- var fail = jasmine.createSpy().andCallFake(function(error) {
- expect(error).toBeDefined();
- }),
- win = createWin('window.resolveLocalFileSystemURI');
-
- // lookup file system entry
- runs(function() {
- window.resolveLocalFileSystemURL("file://localhost?test/test", win, fail);
- });
-
- waitsFor(function() { return fail.wasCalled; }, "error callback never called", Tests.TEST_TIMEOUT);
-
- runs(function() {
- expect(fail).toHaveBeenCalled();
- expect(win).not.toHaveBeenCalled();
- });
- });
- it("file.spec.121 should resolve native URLs returned by API", function() {
- var fileName = "native.resolve.uri1",
- fail = createFail('window.resolveLocalFileSystemURI'),
- checkEntry = jasmine.createSpy().andCallFake(function(entry) {
- expect(entry.fullPath).toEqual("/" + fileName);
- // cleanup
- deleteEntry(fileName);
- });
-
- // create a new file entry
- runs(function() {
- createFile(fileName, function(entry) {
- resolveLocalFileSystemURL(entry.toNativeURL(), checkEntry, fail);
- }, fail);
- });
-
- waitsFor(function() { return checkEntry.wasCalled; }, "checkEntry callback never called", Tests.TEST_TIMEOUT);
- });
- it("file.spec.122 should resolve native URLs returned by API with localhost", function() {
- var fileName = "native.resolve.uri2",
- fail = createFail('window.resolveLocalFileSystemURI'),
- checkEntry = jasmine.createSpy().andCallFake(function(entry) {
- expect(entry.fullPath).toEqual("/" + fileName);
- // cleanup
- deleteEntry(fileName);
- });
-
- // create a new file entry
- runs(function() {
- createFile(fileName, function(entry) {
- var url = entry.toNativeURL();
- url = url.replace("///","//localhost/");
- resolveLocalFileSystemURL(url, checkEntry, fail);
- }, fail);
- });
-
- waitsFor(function() { return checkEntry.wasCalled; }, "checkEntry callback never called", Tests.TEST_TIMEOUT);
- });
- it("file.spec.123 should resolve native URLs returned by API with query string", function() {
- var fileName = "native.resolve.uri3",
- fail = createFail('window.resolveLocalFileSystemURI'),
- checkEntry = jasmine.createSpy().andCallFake(function(entry) {
- expect(entry.fullPath).toEqual("/" + fileName);
- // cleanup
- deleteEntry(fileName);
- });
-
- // create a new file entry
- runs(function() {
- createFile(fileName, function(entry) {
- var url = entry.toNativeURL();
- url = url + "?test/test";
- resolveLocalFileSystemURL(url, checkEntry, fail);
- }, fail);
- });
-
- waitsFor(function() { return checkEntry.wasCalled; }, "checkEntry callback never called", Tests.TEST_TIMEOUT);
- });
- it("file.spec.124 should resolve native URLs returned by API with localhost and query string", function() {
- var fileName = "native.resolve.uri4",
- fail = createFail('window.resolveLocalFileSystemURI'),
- checkEntry = jasmine.createSpy().andCallFake(function(entry) {
- expect(entry.fullPath).toEqual("/" + fileName);
- // cleanup
- deleteEntry(fileName);
- });
-
- // create a new file entry
- runs(function() {
- createFile(fileName, function(entry) {
- var url = entry.toNativeURL();
- url = url.replace("///","//localhost/") + "?test/test";
- resolveLocalFileSystemURL(url, checkEntry, fail);
- }, fail);
- });
-
- waitsFor(function() { return checkEntry.wasCalled; }, "checkEntry callback never called", Tests.TEST_TIMEOUT);
- });
- });
- describe('cross-file-system copy and move', function() {
- /* These specs verify that Entry.copyTo and Entry.moveTo work correctly
- * when crossing filesystem boundaries.
- */
- it("file.spec.125 copyTo: temporary -> persistent", function() {
- var file1 = "entry.copy.file1a",
- file2 = "entry.copy.file2a",
- sourceEntry,
- fullPath = joinURL(root.fullPath, file2),
- fail = createFail('Entry'),
- validateFile = jasmine.createSpy().andCallFake(function(entry) {
- // a bit redundant since copy returned this entry already
- expect(entry).toBeDefined();
- expect(entry.isFile).toBe(true);
- expect(entry.isDirectory).toBe(false);
- expect(entry.name).toCanonicallyMatch(file2);
- expect(entry.fullPath).toCanonicallyMatch(fullPath);
- expect(entry.filesystem).toBeDefined();
- expect(entry.filesystem.name).toEqual("persistent");
-
- // cleanup
- entry.remove();
- sourceEntry.remove();
- }),
- createSourceAndTransfer = function() {
- temp_root.getFile(file1, {create: true}, function(entry) {
- expect(entry.filesystem).toBeDefined();
- expect(entry.filesystem.name).toEqual("temporary");
- sourceEntry = entry; // Save for later cleanup
- entry.copyTo(persistent_root, file2, validateFile, fail);
- }, fail);
- };
- // Delete any existing file to start things off
- runs(function() {
- persistent_root.getFile(file2, {}, function(entry) {
- entry.remove(createSourceAndTransfer, fail);
- }, createSourceAndTransfer);
- });
-
- waitsFor(function() { return validateFile.wasCalled || fail.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT);
- });
- it("file.spec.126 copyTo: persistent -> temporary", function() {
- var file1 = "entry.copy.file1b",
- file2 = "entry.copy.file2b",
- sourceEntry,
- fullPath = joinURL(root.fullPath, file2),
- fail = createFail('Entry'),
- validateFile = jasmine.createSpy().andCallFake(function(entry) {
- expect(entry).toBeDefined();
- expect(entry.isFile).toBe(true);
- expect(entry.isDirectory).toBe(false);
- expect(entry.name).toCanonicallyMatch(file2);
- expect(entry.fullPath).toCanonicallyMatch(fullPath);
- expect(entry.filesystem.name).toEqual("temporary");
-
- // cleanup
- entry.remove();
- sourceEntry.remove();
- }),
- createSourceAndTransfer = function() {
- persistent_root.getFile(file1, {create: true}, function(entry) {
- expect(entry).toBeDefined();
- expect(entry.filesystem).toBeDefined();
- expect(entry.filesystem.name).toEqual("persistent");
- sourceEntry = entry; // Save for later cleanup
- entry.copyTo(temp_root, file2, validateFile, fail);
- }, fail);
- };
- // Delete any existing file to start things off
- runs(function() {
- temp_root.getFile(file2, {}, function(entry) {
- entry.remove(createSourceAndTransfer, fail);
- }, createSourceAndTransfer);
- });
-
- waitsFor(function() { return validateFile.wasCalled || fail.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT);
-
- runs(function() {
- expect(fail).not.toHaveBeenCalled();
- expect(validateFile).toHaveBeenCalled();
- });
- });
- it("file.spec.127 moveTo: temporary -> persistent", function() {
- var file1 = "entry.copy.file1a",
- file2 = "entry.copy.file2a",
- sourceEntry,
- fullPath = joinURL(root.fullPath, file2),
- fail = createFail('Entry'),
- validateFile = jasmine.createSpy().andCallFake(function(entry) {
- // a bit redundant since copy returned this entry already
- expect(entry).toBeDefined();
- expect(entry.isFile).toBe(true);
- expect(entry.isDirectory).toBe(false);
- expect(entry.name).toCanonicallyMatch(file2);
- expect(entry.fullPath).toCanonicallyMatch(fullPath);
- expect(entry.filesystem).toBeDefined();
- expect(entry.filesystem.name).toEqual("persistent");
-
- // cleanup
- entry.remove();
- sourceEntry.remove();
- }),
- createSourceAndTransfer = function() {
- temp_root.getFile(file1, {create: true}, function(entry) {
- expect(entry.filesystem).toBeDefined();
- expect(entry.filesystem.name).toEqual("temporary");
- sourceEntry = entry; // Save for later cleanup
- entry.moveTo(persistent_root, file2, validateFile, fail);
- }, fail);
- };
- // Delete any existing file to start things off
- runs(function() {
- persistent_root.getFile(file2, {}, function(entry) {
- entry.remove(createSourceAndTransfer, fail);
- }, createSourceAndTransfer);
- });
-
- waitsFor(function() { return validateFile.wasCalled || fail.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT);
- });
- it("file.spec.128 moveTo: persistent -> temporary", function() {
- var file1 = "entry.copy.file1b",
- file2 = "entry.copy.file2b",
- sourceEntry,
- fullPath = joinURL(root.fullPath, file2),
- fail = createFail('Entry'),
- validateFile = jasmine.createSpy().andCallFake(function(entry) {
- expect(entry).toBeDefined();
- expect(entry.isFile).toBe(true);
- expect(entry.isDirectory).toBe(false);
- expect(entry.name).toCanonicallyMatch(file2);
- expect(entry.fullPath).toCanonicallyMatch(fullPath);
- expect(entry.filesystem.name).toEqual("temporary");
-
- // cleanup
- entry.remove();
- sourceEntry.remove();
- }),
- createSourceAndTransfer = function() {
- persistent_root.getFile(file1, {create: true}, function(entry) {
- expect(entry).toBeDefined();
- expect(entry.filesystem).toBeDefined();
- expect(entry.filesystem.name).toEqual("persistent");
- sourceEntry = entry; // Save for later cleanup
- entry.moveTo(temp_root, file2, validateFile, fail);
- }, fail);
- };
- // Delete any existing file to start things off
- runs(function() {
- temp_root.getFile(file2, {}, function(entry) {
- entry.remove(createSourceAndTransfer, fail);
- }, createSourceAndTransfer);
- });
-
- waitsFor(function() { return validateFile.wasCalled || fail.wasCalled; }, "entryCallback never called", Tests.TEST_TIMEOUT);
-
- runs(function() {
- expect(fail).not.toHaveBeenCalled();
- expect(validateFile).toHaveBeenCalled();
- });
- });
- it("file.spec.129 cordova.file.*Directory are set", function() {
- var expectedPaths = [
- 'applicationDirectory',
- 'applicationStorageDirectory',
- 'dataDirectory',
- 'cacheDirectory'
- ];
- if (cordova.platformId == 'android') {
- expectedPaths.push('externalApplicationStorageDirectory', 'externalRootDirectory', 'externalCacheDirectory', 'externalDataDirectory');
- } else if (cordova.platformId == 'ios') {
- expectedPaths.push('syncedDataDirectory', 'documentsDirectory', 'tempDirectory');
- } else {
- console.log('Skipping test due on unsupported platform.');
- return;
- }
- for (var i = 0; i < expectedPaths.length; ++i) {
- expect(typeof cordova.file[expectedPaths[i]]).toBe('string');
- expect(cordova.file[expectedPaths[i]]).toMatch(/\/$/, 'Path should end with a slash');
- }
- });
- });
-});
diff --git a/www/autotest/tests/geolocation.tests.js b/www/autotest/tests/geolocation.tests.js
deleted file mode 100644
index bdb0b53..0000000
--- a/www/autotest/tests/geolocation.tests.js
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software 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.
- *
-*/
-
-describe('Geolocation (navigator.geolocation)', function () {
- it("geolocation.spec.1 should exist", function() {
- expect(navigator.geolocation).toBeDefined();
- });
-
- it("geolocation.spec.2 should contain a getCurrentPosition function", function() {
- expect(typeof navigator.geolocation.getCurrentPosition).toBeDefined();
- expect(typeof navigator.geolocation.getCurrentPosition == 'function').toBe(true);
- });
-
- it("geolocation.spec.3 should contain a watchPosition function", function() {
- expect(typeof navigator.geolocation.watchPosition).toBeDefined();
- expect(typeof navigator.geolocation.watchPosition == 'function').toBe(true);
- });
-
- it("geolocation.spec.4 should contain a clearWatch function", function() {
- expect(typeof navigator.geolocation.clearWatch).toBeDefined();
- expect(typeof navigator.geolocation.clearWatch == 'function').toBe(true);
- });
-
- describe('getCurrentPosition method', function() {
- // this api requires manual user confirmation on windows8 so skip it
- if (cordova.platformId == 'windows8') return;
-
- describe('error callback', function() {
- it("geolocation.spec.5 should be called if we set timeout to 0 and maximumAge to a very small number", function() {
- console.log("Here I am");
- 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", 250); //small timeout as this should fire very fast
-
- runs(function () {
- expect(win).not.toHaveBeenCalled();
- });
- });
- });
-
- describe('success callback', function() {
- it("geolocation.spec.6 should be called with a Position object", function() {
- var providerAvailable=true;
- var win = jasmine.createSpy().andCallFake(function(p) {
- expect(p.coords).toBeDefined();
- expect(p.timestamp).toBeDefined();
- }),
- fail = jasmine.createSpy().andCallFake(function(e) {
- if(e.code == 2) {
- providerAvailable=false;
- }
- });
-
- runs(function () {
- navigator.geolocation.getCurrentPosition(win, fail, {
- maximumAge:300000 // 5 minutes maximum age of cached position
- });
- });
-
- waitsFor(function () { return (win.wasCalled || fail.wasCalled); }, "win/fail never called", 20000);
-
- runs(function () {
- if(providerAvailable) {
- expect(fail).not.toHaveBeenCalled();
- }
- });
- });
- });
- });
-
- describe('watchPosition method', function() {
- // this api requires manual user confirmation on windows8 so skip it
- if (cordova.platformId == 'windows8') return;
-
- describe('error callback', function() {
- var errorWatch = null;
-
- afterEach(function() {
- navigator.geolocation.clearWatch(errorWatch);
- });
- it("geolocation.spec.7 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 () {
- errorWatch = navigator.geolocation.watchPosition(win, fail, {
- maximumAge: 0,
- timeout: 0
- });
- });
-
- waitsFor(function () { return fail.wasCalled; }, "fail never called", 250); // small timeout as this should fire very quickly
-
- runs(function () {
- expect(win).not.toHaveBeenCalled();
- });
- });
- });
-
- describe('success callback', function() {
- var successWatch = null;
-
- afterEach(function() {
- navigator.geolocation.clearWatch(successWatch);
- });
- it("geolocation.spec.8 should be called with a Position object", function() {
- var providerAvailable=true;
- var win = jasmine.createSpy().andCallFake(function(p) {
- expect(p.coords).toBeDefined();
- expect(p.timestamp).toBeDefined();
- }),
- fail = jasmine.createSpy().andCallFake(function(e) {
- if(e.code ==2) {
- providerAvailable=false;
- }
- });
-
- runs(function () {
- successWatch = navigator.geolocation.watchPosition(win, fail, {
- maximumAge:(5 * 60 * 1000) // 5 minutes maximum age of cached position
- });
- });
-
- waitsFor(function () { return (win.wasCalled || fail.wasCalled); }, "win/fail never called", 20000);
-
- runs(function () {
- if(providerAvailable) {
- expect(fail).not.toHaveBeenCalled();
- }
- });
- });
- });
- });
-});
diff --git a/www/autotest/tests/media.tests.js b/www/autotest/tests/media.tests.js
deleted file mode 100644
index 393ca00..0000000
--- a/www/autotest/tests/media.tests.js
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software 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.
- *
-*/
-
-describe('Media', function () {
- it("should exist", function() {
- expect(Media).toBeDefined();
- expect(typeof Media).toBe("function");
- });
-
- it("media.spec.1 should have the following properties", function() {
- var media1 = new Media("dummy");
- expect(media1.id).toBeDefined();
- expect(media1.src).toBeDefined();
- expect(media1._duration).toBeDefined();
- expect(media1._position).toBeDefined();
- media1.release();
- });
-
- it("should define constants for Media status", function() {
- expect(Media).toBeDefined();
- expect(Media.MEDIA_NONE).toBe(0);
- expect(Media.MEDIA_STARTING).toBe(1);
- expect(Media.MEDIA_RUNNING).toBe(2);
- expect(Media.MEDIA_PAUSED).toBe(3);
- expect(Media.MEDIA_STOPPED).toBe(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);
- });
-
- it("media.spec.2 should contain a play function", function() {
- var media1 = new Media();
- expect(media1.play).toBeDefined();
- expect(typeof media1.play).toBe('function');
- media1.release();
- });
-
- it("media.spec.3 should contain a stop function", function() {
- var media1 = new Media();
- expect(media1.stop).toBeDefined();
- expect(typeof media1.stop).toBe('function');
- media1.release();
- });
-
- it("media.spec.4 should contain a seekTo function", function() {
- var media1 = new Media();
- expect(media1.seekTo).toBeDefined();
- expect(typeof media1.seekTo).toBe('function');
- media1.release();
- });
-
- it("media.spec.5 should contain a pause function", function() {
- var media1 = new Media();
- expect(media1.pause).toBeDefined();
- expect(typeof media1.pause).toBe('function');
- media1.release();
- });
-
- it("media.spec.6 should contain a getDuration function", function() {
- var media1 = new Media();
- expect(media1.getDuration).toBeDefined();
- expect(typeof media1.getDuration).toBe('function');
- media1.release();
- });
-
- it("media.spec.7 should contain a getCurrentPosition function", function() {
- var media1 = new Media();
- expect(media1.getCurrentPosition).toBeDefined();
- expect(typeof media1.getCurrentPosition).toBe('function');
- media1.release();
- });
-
- it("media.spec.8 should contain a startRecord function", function() {
- var media1 = new Media();
- expect(media1.startRecord).toBeDefined();
- expect(typeof media1.startRecord).toBe('function');
- media1.release();
- });
-
- it("media.spec.9 should contain a stopRecord function", function() {
- var media1 = new Media();
- expect(media1.stopRecord).toBeDefined();
- expect(typeof media1.stopRecord).toBe('function');
- media1.release();
- });
-
- it("media.spec.10 should contain a release function", function() {
- var media1 = new Media();
- expect(media1.release).toBeDefined();
- expect(typeof media1.release).toBe('function');
- media1.release();
- });
-
- it("media.spec.11 should contain a setVolume function", function() {
- var media1 = new Media();
- expect(media1.setVolume).toBeDefined();
- expect(typeof media1.setVolume).toBe('function');
- media1.release();
- });
-
- 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);
- });
-
- //bb10 dialog pops up, preventing tests from running
- if (cordova.platformId === 'blackberry10') {
- return;
- }
-
- 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();
- });
- });
-
- it("media.spec.12 position should be set properly", function() {
- var playcomplete = jasmine.createSpy();
- var fail = jasmine.createSpy();
- var mediaState=Media.MEDIA_STOPPED;
- var statuschange= function(statusCode){
- mediaState=statusCode;
- };
- var media1 = new Media("http://cordova.apache.org/downloads/BlueZedEx.mp3",playcomplete,fail,statuschange),
- test = jasmine.createSpy().andCallFake(function(position) {
- console.log("position = " + position);
- expect(position).toBeGreaterThan(0.0);
- media1.stop()
- media1.release();
- });
-
- media1.play();
-
- if (cordova.platformId !== 'blackberry10') {
- waitsFor(function () { return mediaState==Media.MEDIA_RUNNING; }, 10000);
- } else {
- waits(5000);
- }
-
- // make sure we are at least one second into the file
- waits(1000);
- runs(function () {
- expect(fail).not.toHaveBeenCalled();
- // note that the file is about 60 seconds long and we kill the play almost immediately
- // as a result, the playcomplete should not happen
- expect(playcomplete).not.toHaveBeenCalled();
- media1.getCurrentPosition(test, function () {});
- });
-
- waitsFor(function () { return test.wasCalled || fail.wasCalled; }, Tests.TEST_TIMEOUT);
- });
-
- it("media.spec.13 duration should be set properly", function() {
-
- if (cordova.platformId === 'blackberry10') {
- return;
- }
-
- var win = jasmine.createSpy();
- var fail = jasmine.createSpy();
- var mediaState=Media.MEDIA_STOPPED;
- var statuschange= function(statusCode){
- mediaState=statusCode;
- };
- var media1 = new Media("http://cordova.apache.org/downloads/BlueZedEx.mp3",win,fail,statuschange);
- media1.play();
- waitsFor(function () { return mediaState==Media.MEDIA_RUNNING; }, 10000);
- runs(function () {
- expect(media1.getDuration()).toBeGreaterThan(0.0);
- expect(fail).not.toHaveBeenCalled();
- });
- });
-});
diff --git a/www/autotest/tests/vibration.tests.js b/www/autotest/tests/vibration.tests.js
deleted file mode 100644
index 18e75f2..0000000
--- a/www/autotest/tests/vibration.tests.js
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software 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.
- *
-*/
-
-describe('Vibration (navigator.notification.vibrate)', function () {
- it("navigator.notification should exist", function() {
- expect(navigator.notification).toBeDefined();
- });
-
- it("should contain a vibrate function", function() {
- expect(typeof navigator.notification.vibrate).toBeDefined();
- expect(typeof navigator.notification.vibrate).toBe("function");
- });
-});
diff --git a/www/camera/index.html b/www/camera/index.html
deleted file mode 100644
index 4f48190..0000000
--- a/www/camera/index.html
+++ /dev/null
@@ -1,60 +0,0 @@
-<!DOCTYPE html>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software 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.
-
--->
-
-
-<html>
- <head>
- <meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,maximum-scale=1.0,initial-scale=1.0" />
- <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <!-- ISO-8859-1 -->
- <title>Cordova Mobile Spec</title>
- <link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8">
- <script type="text/javascript" charset="utf-8" src="../cordova-incl.js"></script>
- <script type="text/javascript" charset="utf-8" src="./index.js"></script>
-
- </head>
- <body id="stage" class="theme">
-
- <h1>Camera</h1>
- <div id="info" style="white-space: pre-wrap">
- <b>Status:</b> <div id="camera_status"></div>
- img: <img width="100" id="camera_image">
- canvas: <canvas id="canvas" width="1" height="1"></canvas>
- </div>
- <h2>Cordova Camera API</h2>
- <div id="image-options"></div>
- <div class="btn large getPicture">camera.getPicture()</div>
- <h2>Native File Inputs</h2>
- <div>input type=file <input type="file" class="testInputTag"></div>
- <div>capture=camera <input type="file" accept="image/*;capture=camera" class="testInputTag"></div>
- <div>capture=camcorder <input type="file" accept="video/*;capture=camcorder" class="testInputTag"></div>
- <div>capture=microphone <input type="file" accept="audio/*;capture=microphone" class="testInputTag"></div>
- <h2>Actions</h2>
- <div class="btn large getFileInfo">Get File Metadata</div>
- <div class="btn large readFile">Read with FileReader</div>
- <div class="btn large copyImage">Copy Image</div>
- <div class="btn large writeImage">Write Image</div>
- <div class="btn large uploadImage">Upload Image</div>
- <div class="btn large displayImageUsingCanvas">Draw Using Canvas</div>
- <div class="btn large removeImage">Remove Image</div>
- <h2> </h2><div class="backBtn">Back</div>
- </body>
-</html>
diff --git a/www/camera/index.js b/www/camera/index.js
deleted file mode 100644
index f9435d0..0000000
--- a/www/camera/index.js
+++ /dev/null
@@ -1,344 +0,0 @@
-var deviceReady = false;
-var platformId = cordova.require('cordova/platform').id;
-var pictureUrl = null;
-var fileObj = null;
-var fileEntry = null;
-var pageStartTime = +new Date();
-
-//default camera options
-var camQualityDefault = ['quality value', 50];
-var camDestinationTypeDefault = ['FILE_URI', 1];
-var camPictureSourceTypeDefault = ['CAMERA', 1];
-var camAllowEditDefault = ['allowEdit', false];
-var camEncodingTypeDefault = ['JPEG', 0];
-var camMediaTypeDefault = ['mediaType', 0];
-var camCorrectOrientationDefault = ['correctOrientation', false];
-var camSaveToPhotoAlbumDefault = ['saveToPhotoAlbum', true];
-
-
-//-------------------------------------------------------------------------
-// Camera
-//-------------------------------------------------------------------------
-
-function log(value) {
- console.log(value);
- document.getElementById('camera_status').textContent += (new Date() - pageStartTime) / 1000 + ': ' + value + '\n';
-}
-
-function clearStatus() {
- document.getElementById('camera_status').innerHTML = '';
- document.getElementById('camera_image').src = 'about:blank';
- var canvas = document.getElementById('canvas');
- canvas.width = canvas.height = 1;
- pictureUrl = null;
- fileObj = null;
- fileEntry = null;
-}
-
-function setPicture(url, callback) {
-try {
- window.atob(url);
- // if we got here it is a base64 string (DATA_URL)
- url = "data:image/jpeg;base64," + url;
-} catch (e) {
- // not DATA_URL
- log('URL: ' + url.slice(0, 100));
-}
-
- pictureUrl = url;
- var img = document.getElementById('camera_image');
- var startTime = new Date();
- img.src = url;
- img.onloadend = function() {
- log('Image tag load time: ' + (new Date() - startTime));
- callback && callback();
- };
-}
-
-function onGetPictureError(e) {
- log('Error getting picture: ' + e.code);
-}
-
-function getPictureWin(data) {
- setPicture(data);
- // TODO: Fix resolveLocalFileSystemURI to work with native-uri.
- if (pictureUrl.indexOf('file:') == 0 || pictureUrl.indexOf('content:') == 0) {
- resolveLocalFileSystemURI(data, function(e) {
- fileEntry = e;
- logCallback('resolveLocalFileSystemURI()', true)(e.toURL());
- }, logCallback('resolveLocalFileSystemURI()', false));
- } else if (pictureUrl.indexOf('data:image/jpeg;base64' == 0)) {
- // do nothing
- } else {
- var path = pictureUrl.replace(/^file:\/\/(localhost)?/, '').replace(/%20/g, ' ');
- fileEntry = new FileEntry('image_name.png', path);
- }
-}
-
-function getPicture() {
- clearStatus();
- var options = extractOptions();
- log('Getting picture with options: ' + JSON.stringify(options));
- var popoverHandle = navigator.camera.getPicture(getPictureWin, onGetPictureError, options);
-
- // Reposition the popover if the orientation changes.
- window.onorientationchange = function() {
- var newPopoverOptions = new CameraPopoverOptions(0, 0, 100, 100, 0);
- popoverHandle.setPosition(newPopoverOptions);
- }
-}
-
-function uploadImage() {
- var ft = new FileTransfer(),
- uploadcomplete=0,
- progress = 0,
- options = new FileUploadOptions();
- options.fileKey="photo";
- options.fileName='test.jpg';
- options.mimeType="image/jpeg";
- ft.onprogress = function(progressEvent) {
- log('progress: ' + progressEvent.loaded + ' of ' + progressEvent.total);
- };
- var server = "http://cordova-filetransfer.jitsu.com";
-
- ft.upload(pictureUrl, server + '/upload', win, fail, options);
- function win(information_back){
- log('upload complete');
- }
- function fail(message) {
- log('upload failed: ' + JSON.stringify(message));
- }
-}
-
-function logCallback(apiName, success) {
- return function() {
- log('Call to ' + apiName + (success ? ' success: ' : ' failed: ') + JSON.stringify([].slice.call(arguments)));
- };
-}
-
-/**
- * Select image from library using a NATIVE_URI destination type
- * This calls FileEntry.getMetadata, FileEntry.setMetadata, FileEntry.getParent, FileEntry.file, and FileReader.readAsDataURL.
- */
-function readFile() {
- function onFileReadAsDataURL(evt) {
- var img = document.getElementById('camera_image');
- img.style.visibility = "visible";
- img.style.display = "block";
- img.src = evt.target.result;
- log("FileReader.readAsDataURL success");
- };
-
- function onFileReceived(file) {
- log('Got file: ' + JSON.stringify(file));
- fileObj = file;
-
- var reader = new FileReader();
- reader.onload = function() {
- log('FileReader.readAsDataURL() - length = ' + reader.result.length);
- };
- reader.onerror = logCallback('FileReader.readAsDataURL', false);
- reader.readAsDataURL(file);
- };
- // Test out onFileReceived when the file object was set via a native <input> elements.
- if (fileObj) {
- onFileReceived(fileObj);
- } else {
- fileEntry.file(onFileReceived, logCallback('FileEntry.file', false));
- }
-}
-function getFileInfo() {
- // Test FileEntry API here.
- fileEntry.getMetadata(logCallback('FileEntry.getMetadata', true), logCallback('FileEntry.getMetadata', false));
- fileEntry.setMetadata(logCallback('FileEntry.setMetadata', true), logCallback('FileEntry.setMetadata', false), { "com.apple.MobileBackup": 1 });
- fileEntry.getParent(logCallback('FileEntry.getParent', true), logCallback('FileEntry.getParent', false));
- fileEntry.getParent(logCallback('FileEntry.getParent', true), logCallback('FileEntry.getParent', false));
-};
-
-/**
- * Copy image from library using a NATIVE_URI destination type
- * This calls FileEntry.copyTo and FileEntry.moveTo.
- */
-function copyImage() {
- var onFileSystemReceived = function(fileSystem) {
- var destDirEntry = fileSystem.root;
-
- // Test FileEntry API here.
- fileEntry.copyTo(destDirEntry, 'copied_file.png', logCallback('FileEntry.copyTo', true), logCallback('FileEntry.copyTo', false));
- fileEntry.moveTo(destDirEntry, 'moved_file.png', logCallback('FileEntry.moveTo', true), logCallback('FileEntry.moveTo', false));
- };
-
- window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, onFileSystemReceived, null);
-};
-
-/**
- * Write image to library using a NATIVE_URI destination type
- * This calls FileEntry.createWriter, FileWriter.write, and FileWriter.truncate.
- */
-function writeImage() {
- var onFileWriterReceived = function(fileWriter) {
- fileWriter.onwrite = logCallback('FileWriter.write', true);
- fileWriter.onerror = logCallback('FileWriter.write', false);
- fileWriter.write("some text!");
- };
-
- var onFileTruncateWriterReceived = function(fileWriter) {
- fileWriter.onwrite = logCallback('FileWriter.truncate', true);
- fileWriter.onerror = logCallback('FileWriter.truncate', false);
- fileWriter.truncate(10);
- };
-
- fileEntry.createWriter(onFileWriterReceived, logCallback('FileEntry.createWriter', false));
- fileEntry.createWriter(onFileTruncateWriterReceived, null);
-};
-
-function displayImageUsingCanvas() {
- var canvas = document.getElementById('canvas');
- var img = document.getElementById('camera_image');
- var w = img.width;
- var h = img.height;
- h = 100 / w * h;
- w = 100;
- canvas.width = w;
- canvas.height= h;
- var context = canvas.getContext('2d');
- context.drawImage(img, 0, 0, w, h);
-};
-
-/**
- * Remove image from library using a NATIVE_URI destination type
- * This calls FileEntry.remove.
- */
-function removeImage() {
- fileEntry.remove(logCallback('FileEntry.remove', true), logCallback('FileEntry.remove', false));
-};
-
-function testInputTag(inputEl) {
- clearStatus();
- // iOS 6 likes to dead-lock in the onchange context if you
- // do any alerts or try to remote-debug.
- window.setTimeout(function() {
- testNativeFile2(inputEl);
- }, 0);
-};
-
-function testNativeFile2(inputEl) {
- if (!inputEl.value) {
- alert('No file selected.');
- return;
- }
- fileObj = inputEl.files[0];
- if (!fileObj) {
- alert('Got value but no file.');
- return;
- }
- var URLApi = window.URL || window.webkitURL;
- if (URLApi) {
- var blobURL = URLApi.createObjectURL(fileObj);
- if (blobURL) {
- setPicture(blobURL, function() {
- URLApi.revokeObjectURL(blobURL);
- });
- } else {
- log('URL.createObjectURL returned null');
- }
- } else {
- log('URL.createObjectURL() not supported.');
- }
-}
-
-function extractOptions() {
- var els = document.querySelectorAll('#image-options select');
- var ret = {};
- for (var i = 0, el; el = els[i]; ++i) {
- var value = el.value;
- if (value === '') continue;
- if (el.isBool) {
- ret[el.keyName] = !!+value;
- } else {
- ret[el.keyName] = +value;
- }
- }
- return ret;
-}
-
-function createOptionsEl(name, values, selectionDefault) {
- var container = document.createElement('div');
- container.style.display = 'inline-block';
- container.appendChild(document.createTextNode(name + ': '));
- var select = document.createElement('select');
- select.keyName = name;
- container.appendChild(select);
-
- // if we didn't get a default value, insert the blank <default> entry
- if (selectionDefault == undefined) {
- var opt = document.createElement('option');
- opt.value = '';
- opt.text = '<default>';
- select.appendChild(opt);
- }
-
- select.isBool = typeof values == 'boolean';
- if (select.isBool) {
- values = {'true': 1, 'false': 0};
- }
-
- for (var k in values) {
- var opt = document.createElement('option');
- opt.value = values[k];
- opt.textContent = k;
- if (selectionDefault) {
- if (selectionDefault[0] == k) {
- opt.selected = true;
- }
- }
- select.appendChild(opt);
- }
- var optionsDiv = document.getElementById('image-options');
- optionsDiv.appendChild(container);
-}
-
-/**
- * Function called when page has finished loading.
- */
-function init() {
- document.addEventListener("deviceready", function() {
- deviceReady = true;
- console.log("Device="+device.platform+" "+device.version);
- createOptionsEl('sourceType', Camera.PictureSourceType, camPictureSourceTypeDefault);
- createOptionsEl('destinationType', Camera.DestinationType, camDestinationTypeDefault);
- createOptionsEl('encodingType', Camera.EncodingType, camEncodingTypeDefault);
- createOptionsEl('mediaType', Camera.MediaType, camMediaTypeDefault);
- createOptionsEl('quality', {'0': 0, '50': 50, '80': 80, '100': 100}, camQualityDefault);
- createOptionsEl('targetWidth', {'50': 50, '200': 200, '800': 800, '2048': 2048});
- createOptionsEl('targetHeight', {'50': 50, '200': 200, '800': 800, '2048': 2048});
- createOptionsEl('allowEdit', true, camAllowEditDefault);
- createOptionsEl('correctOrientation', true, camCorrectOrientationDefault);
- createOptionsEl('saveToPhotoAlbum', true, camSaveToPhotoAlbumDefault);
- createOptionsEl('cameraDirection', Camera.Direction);
-
- }, false);
- window.setTimeout(function() {
- if (!deviceReady) {
- alert("Error: Apache Cordova did not initialize. Demo will not run correctly.");
- }
- },1000);
-};
-
-window.onload = function() {
- addListenerToClass('getPicture', getPicture);
- addListenerToClass('testInputTag', function(e) {
- testInputTag(e.target);
- }, null, 'change', true);
- addListenerToClass('getFileInfo', getFileInfo);
- addListenerToClass('readFile', readFile);
- addListenerToClass('copyImage', copyImage);
- addListenerToClass('writeImage', writeImage);
- addListenerToClass('uploadImage', uploadImage);
- addListenerToClass('displayImageUsingCanvas', displayImageUsingCanvas);
- addListenerToClass('removeImage', removeImage);
-
- addListenerToClass('backBtn', backHome);
- init();
-}
-
diff --git a/www/capture/index.html b/www/capture/index.html
deleted file mode 100644
index 9543341..0000000
--- a/www/capture/index.html
+++ /dev/null
@@ -1,52 +0,0 @@
-<!DOCTYPE html>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software 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.
-
--->
-
-
-<html>
- <head>
- <meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,maximum-scale=1.0,initial-scale=1.0" />
- <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <!-- ISO-8859-1 -->
- <title>Cordova Mobile Spec</title>
- <link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8">
- <script type="text/javascript" charset="utf-8" src="../cordova-incl.js"></script>
- <script type="text/javascript" charset="utf-8" src="./index.js"></script>
- </head>
- <body id="stage" class="theme">
-
- <h1>Capture</h1>
- <div id="info" style="white-space: pre-wrap">
- <b>Status:</b> <div id="camera_status"></div>
- img: <img width="100" id="camera_image">
- video: <div id="video_container"></div>
- </div>
-
- <h2>Cordova Capture API</h2>
- <div id="image-options"></div>
-
- <h2>Actions</h2>
- <div class="btn large getAudio">Capture 10 secs of audio and play</div>
- <div class="btn large getImage">Capture 1 image</div>
- <div class="btn large getVideo">Capture 10 secs of video</div>
- <div class="btn large resolveVideo">Capture 5 secs of video and resolve</div>
- <h2> </h2><div class="backBtn">Back</div>
- </body>
-</html>
diff --git a/www/capture/index.js b/www/capture/index.js
deleted file mode 100644
index 0f98549..0000000
--- a/www/capture/index.js
+++ /dev/null
@@ -1,137 +0,0 @@
-var deviceReady = false;
-var platformId = cordova.require('cordova/platform').id;
-var pageStartTime = +new Date();
-
-//-------------------------------------------------------------------------
-// Camera
-//-------------------------------------------------------------------------
-
-function log(value) {
- console.log(value);
- document.getElementById('camera_status').textContent += (new Date() - pageStartTime) / 1000 + ': ' + value + '\n';
-}
-
-function captureAudioWin(mediaFiles){
- var path = mediaFiles[0].fullPath;
- log('Audio captured: ' + path);
- var m = new Media(path);
- m.play();
-}
-
-function captureAudioFail(e){
- log('Error getting audio: ' + e.code);
-}
-
-function getAudio(){
- clearStatus();
- var options = { limit: 1, duration: 10};
- navigator.device.capture.captureAudio(captureAudioWin, captureAudioFail, options);
-}
-
-function captureImageWin(mediaFiles){
- var path = mediaFiles[0].fullPath;
- log('Image captured: ' + path);
- document.getElementById('camera_image').src = path;
-}
-
-function captureImageFail(e){
- log('Error getting image: ' + e.code);
-}
-
-function getImage(){
- clearStatus();
- var options = { limit: 1 };
- navigator.device.capture.captureImage(captureImageWin, captureImageFail, options);
-}
-
-function captureVideoWin(mediaFiles){
- var path = mediaFiles[0].fullPath;
- log('Video captured: ' + path);
-
- // need to inject the video element into the html
- // doesn't seem to work if you have a pre-existing video element and
- // add in a source tag
- var vid = document.createElement('video');
- vid.id="theVideo";
- vid.width = "320";
- vid.height= "240";
- vid.controls = "true";
- var source_vid = document.createElement('source');
- source_vid.id = "theSource";
- source_vid.src = path;
- vid.appendChild(source_vid);
- document.getElementById('video_container').appendChild(vid);
-}
-
-function captureVideoFail(e){
- log('Error getting video: ' + e.code);
-}
-
-function getVideo(){
- clearStatus();
- var options = { limit: 1, duration: 10 };
- navigator.device.capture.captureVideo(captureVideoWin, captureVideoFail, options);
-}
-
-function resolveMediaFileURL(mediaFile, callback) {
- resolveLocalFileSystemURL(mediaFile.localURL, function(entry) {
- log("Resolved by URL: " + mediaFile.localURL);
- if (callback) callback();
- }, function(err) {
- log("Failed to resolve by URL: " + mediaFile.localURL);
- log("Error: " + JSON.stringify(err));
- if (callback) callback();
- });
-}
-
-function resolveMediaFile(mediaFile, callback) {
- resolveLocalFileSystemURL(mediaFile.fullPath, function(entry) {
- log("Resolved by path: " + mediaFile.fullPath);
- if (callback) callback();
- }, function(err) {
- log("Failed to resolve by path: " + mediaFile.fullPath);
- log("Error: " + JSON.stringify(err));
- if (callback) callback();
- });
-}
-
-function resolveVideo() {
- clearStatus();
- var options = { limit: 1, duration: 5 };
- navigator.device.capture.captureVideo(function(mediaFiles) {
- captureVideoWin(mediaFiles);
- resolveMediaFile(mediaFiles[0], function() {
- resolveMediaFileURL(mediaFiles[0]);
- });
- }, captureVideoFail, options);
-}
-
-function clearStatus() {
- document.getElementById('camera_status').innerHTML = '';
- document.getElementById('camera_image').src = 'about:blank';
-}
-
-/**
- * Function called when page has finished loading.
- */
-function init() {
- document.addEventListener("deviceready", function() {
- deviceReady = true;
- console.log("Device="+device.platform+" "+device.version);
- }, false);
- window.setTimeout(function() {
- if (!deviceReady) {
- alert("Error: Apache Cordova did not initialize. Demo will not run correctly.");
- }
- },1000);
-};
-
-
-window.onload = function() {
- addListenerToClass('getAudio', getAudio);
- addListenerToClass('getImage', getImage);
- addListenerToClass('getVideo', getVideo);
- addListenerToClass('resolveVideo', resolveVideo);
- addListenerToClass('backBtn', backHome);
- init();
-}
diff --git a/www/compass/index.html b/www/compass/index.html
deleted file mode 100644
index 1734caa..0000000
--- a/www/compass/index.html
+++ /dev/null
@@ -1,48 +0,0 @@
-<!DOCTYPE html>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software 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.
-
--->
-
-
-<html>
- <head>
- <meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,maximum-scale=1.0,initial-scale=1.0" />
- <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <!-- ISO-8859-1 -->
- <title>Cordova Mobile Spec</title>
- <link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8">
- <script type="text/javascript" charset="utf-8" src="../cordova-incl.js"></script>
- <script type="text/javascript" charset="utf-8" src="./index.js"></script>
- </head>
- <body id="stage" class="theme">
-
- <h1>Compass</h1>
- <div id="info">
- <b>Status:</b> <span id="compass_status">Stopped</span>
- <table width="100%"><tr>
- <td width="33%">Heading: <span id="compassHeading"> </span></td>
- </tr></table>
- </div>
- <h2>Action</h2>
- <div class="btn large getCompass">Get Compass</div>
- <div class="btn large watchCompass">Start Watching Compass</div>
- <div class="btn large stopCompass">Stop Watching Compass</div>
- <h2> </h2><div class="backBtn">Back</div>
- </body>
-</html>
diff --git a/www/compass/index.js b/www/compass/index.js
deleted file mode 100644
index 0735ab2..0000000
--- a/www/compass/index.js
+++ /dev/null
@@ -1,104 +0,0 @@
-var deviceReady = false;
-
-function roundNumber(num) {
- var dec = 3;
- var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
- return result;
-}
-
-//-------------------------------------------------------------------------
-// Compass
-//-------------------------------------------------------------------------
-var watchCompassId = null;
-
-/**
- * Start watching compass
- */
-var watchCompass = function() {
- console.log("watchCompass()");
-
- // Success callback
- var success = function(a){
- document.getElementById('compassHeading').innerHTML = roundNumber(a.magneticHeading);
- };
-
- // Fail callback
- var fail = function(e){
- console.log("watchCompass fail callback with error code "+e);
- stopCompass();
- setCompassStatus(e);
- };
-
- // Update heading every 1 sec
- var opt = {};
- opt.frequency = 1000;
- watchCompassId = navigator.compass.watchHeading(success, fail, opt);
-
- setCompassStatus("Running");
-};
-
-/**
- * Stop watching the acceleration
- */
-var stopCompass = function() {
- setCompassStatus("Stopped");
- if (watchCompassId) {
- navigator.compass.clearWatch(watchCompassId);
- watchCompassId = null;
- }
-};
-
-/**
- * Get current compass
- */
-var getCompass = function() {
- console.log("getCompass()");
-
- // Stop compass if running
- stopCompass();
-
- // Success callback
- var success = function(a){
- document.getElementById('compassHeading').innerHTML = roundNumber(a.magneticHeading);
- };
-
- // Fail callback
- var fail = function(e){
- console.log("getCompass fail callback with error code "+e);
- setCompassStatus(e);
- };
-
- // Make call
- var opt = {};
- navigator.compass.getCurrentHeading(success, fail, opt);
-};
-
-/**
- * Set compass status
- */
-var setCompassStatus = function(status) {
- document.getElementById('compass_status').innerHTML = status;
-};
-
-/**
- * Function called when page has finished loading.
- */
-function init() {
- document.addEventListener("deviceready", function() {
- deviceReady = true;
- console.log("Device="+device.platform+" "+device.version);
- }, false);
- window.setTimeout(function() {
- if (!deviceReady) {
- alert("Error: Apache Cordova did not initialize. Demo will not run correctly.");
- }
- },1000);
-}
-
-window.onload = function() {
- addListenerToClass('getCompass', getCompass);
- addListenerToClass('watchCompass', watchCompass);
- addListenerToClass('stopCompass', stopCompass);
- addListenerToClass('backBtn', backHome);
- init();
-}
diff --git a/www/contacts/index.html b/www/contacts/index.html
deleted file mode 100644
index 5782713..0000000
--- a/www/contacts/index.html
+++ /dev/null
@@ -1,47 +0,0 @@
-<!DOCTYPE html>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software 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.
-
--->
-
-
-<html>
- <head>
- <meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,maximum-scale=1.0,initial-scale=1.0" />
- <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <!-- ISO-8859-1 -->
- <title>Cordova Mobile Spec</title>
- <link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8">
- <script type="text/javascript" charset="utf-8" src="../cordova-incl.js"></script>
- <script type="text/javascript" charset="utf-8" src="./index.js"></script>
-
- </head>
- <body id="stage" class="theme">
-
- <h1>Contacts</h1>
- <div id="info">
- <b>Results:</b><br>
- <span id="contacts_results"> </span>
- </div>
- <h2>Action</h2>
-
- <div class="btn large getContacts">Get phone's contacts</div>
- <div class="btn large addContact">Add a new contact 'Dooney Evans'</div>
- <h2> </h2><div class="backBtn">Back</div>
- </body>
-</html>
diff --git a/www/contacts/index.js b/www/contacts/index.js
deleted file mode 100644
index d3f3312..0000000
--- a/www/contacts/index.js
+++ /dev/null
@@ -1,90 +0,0 @@
-var deviceReady = false;
-
-//-------------------------------------------------------------------------
-// Contacts
-//-------------------------------------------------------------------------
-function getContacts() {
- obj = new ContactFindOptions();
- // show all contacts, so don't filter
- obj.multiple = true;
- navigator.contacts.find(
- ["displayName", "name", "phoneNumbers", "emails", "urls", "note"],
- function(contacts) {
- var s = "";
- if (contacts.length == 0) {
- s = "No contacts found";
- }
- else {
- s = "Number of contacts: "+contacts.length+"<br><table width='100%'><tr><th>Name</th><td>Phone</td><td>Email</td></tr>";
- for (var i=0; i<contacts.length; i++) {
- var contact = contacts[i];
- s = s + "<tr><td>" + contact.name.formatted + "</td><td>";
- if (contact.phoneNumbers && contact.phoneNumbers.length > 0) {
- s = s + contact.phoneNumbers[0].value;
- }
- s = s + "</td><td>"
- if (contact.emails && contact.emails.length > 0) {
- s = s + contact.emails[0].value;
- }
- s = s + "</td></tr>";
- }
- s = s + "</table>";
- }
- document.getElementById('contacts_results').innerHTML = s;
- },
- function(e) {
- document.getElementById('contacts_results').innerHTML = "Error: "+e.code;
- },
- obj);
-};
-
-function addContact(){
- try{
- var contact = navigator.contacts.create({"displayName": "Dooney Evans"});
- var contactName = {
- formatted: "Dooney Evans",
- familyName: "Evans",
- givenName: "Dooney",
- middleName: ""
- };
-
- contact.name = contactName;
-
- var phoneNumbers = [1];
- phoneNumbers[0] = new ContactField('work', '512-555-1234', true);
- contact.phoneNumbers = phoneNumbers;
-
- contact.save(
- function() { alert("Contact saved.");},
- function(e) { alert("Contact save failed: " + e.code); }
- );
- console.log("you have saved the contact");
- }
- catch (e){
- alert(e);
- }
-
-};
-
-/**
- * Function called when page has finished loading.
- */
-function init() {
- document.addEventListener("deviceready", function() {
- deviceReady = true;
- console.log("Device="+device.platform+" "+device.version);
- }, false);
- window.setTimeout(function() {
- if (!deviceReady) {
- alert("Error: Apache Cordova did not initialize. Demo will not run correctly.");
- }
- },1000);
-}
-
-
-window.onload = function() {
- addListenerToClass('getContacts', getContacts);
- addListenerToClass('addContact', addContact);
- addListenerToClass('backBtn', backHome);
- init();
-}
diff --git a/www/file/index.html b/www/file/index.html
deleted file mode 100644
index 11f7997..0000000
--- a/www/file/index.html
+++ /dev/null
@@ -1,73 +0,0 @@
-<!DOCTYPE html>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software 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.
-
--->
-
-
-<html>
- <head>
- <meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,maximum-scale=1.0,initial-scale=1.0" />
- <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <!-- ISO-8859-1 -->
- <title>Cordova Mobile Spec</title>
- <link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8">
- <script type="text/javascript" charset="utf-8" src="../cordova-incl.js"></script>
- <script type="text/javascript" charset="utf-8" src="./index.js"></script>
-
- </head>
- <body id="stage" class="theme">
-
- <h1>File and File Transfer</h1>
- <h2>File</h2>
- <div class="btn large" id="downloadImgCDV">Download and display img (cdvfile)</div>
- <div class="btn large" id="downloadImgNative">Download and display img (native)</div>
- <div class="btn large" id="downloadVideoCDV">Download and play video (cdvfile)</div>
- <div class="btn large" id="downloadVideoNative">Download and play video (native)</div>
- <div class="btn large" id="testNotModified">Handle 304 status code</div>
-
- <div class="ios platform">
- <h2>iOS Special URL handling</h2>
- <div class="btn large" id="testPrivateURL">Test /private/ URL (iOS)</div>
-
- <h2>iOS Extra File Systems</h2>
- <div class="btn large resolveFs" data-fsname="library">Resolve library FS</div>
- <div class="btn large resolveFs" data-fsname="library-nosync">Resolve library-nosync FS</div>
- <div class="btn large resolveFs" data-fsname="documents">Resolve documents FS</div>
- <div class="btn large resolveFs" data-fsname="documents-nosync">Resolve documents-nosync FS</div>
- <div class="btn large resolveFs" data-fsname="cache">Resolve cache FS</div>
- <div class="btn large resolveFs" data-fsname="bundle">Resolve bundle FS</div>
- <div class="btn large resolveFs" data-fsname="root">Resolve root FS</div>
- </div>
-
- <div class="android platform">
- <h2>Android Extra File Systems</h2>
- <div class="btn large resolveFs" data-fsname="files">Resolve files FS</div>
- <div class="btn large resolveFs" data-fsname="files-external">Resolve files-external FS</div>
- <div class="btn large resolveFs" data-fsname="documents">Resolve documents FS</div>
- <div class="btn large resolveFs" data-fsname="sdcard">Resolve sdcard FS</div>
- <div class="btn large resolveFs" data-fsname="cache">Resolve cache FS</div>
- <div class="btn large resolveFs" data-fsname="cache-external">Resolve cache-external FS</div>
- <div class="btn large resolveFs" data-fsname="root">Resolve root FS</div>
- </div>
-
- <div id="log"></div>
- <div id="output"></div>
- <h2> </h2><div class="backBtn">Back</div>
- </body>
-</html>
diff --git a/www/file/index.js b/www/file/index.js
deleted file mode 100644
index 4bdf045..0000000
--- a/www/file/index.js
+++ /dev/null
@@ -1,171 +0,0 @@
-var deviceReady = false;
-
-var imageURL = "http://apache.org/images/feather-small.gif";
-var videoURL = "http://techslides.com/demos/sample-videos/small.mp4";
-
-/**
- * Function called when page has finished loading.
- */
-function init() {
- document.addEventListener("deviceready", function() {
- deviceReady = true;
- console.log("Device="+device.platform+" "+device.version);
- bindEvents();
- document.body.classList.add(device.platform.toLowerCase() + "-platform");
- }, false);
- window.setTimeout(function() {
- if (!deviceReady) {
- alert("Error: Apache Cordova did not initialize. Demo will not run correctly.");
- }
- },1000);
-}
-
-function bindEvents() {
- document.getElementById('downloadImgCDV').addEventListener('click', downloadImgCDV, false);
- document.getElementById('downloadImgNative').addEventListener('click', downloadImgNative, false);
- document.getElementById('downloadVideoCDV').addEventListener('click', downloadVideoCDV, false);
- document.getElementById('downloadVideoNative').addEventListener('click', downloadVideoNative, false);
- document.getElementById('testPrivateURL').addEventListener('click', testPrivateURL, false);
- document.getElementById('testNotModified').addEventListener('click', testNotModified, false);
- var fsButtons = document.querySelectorAll('.resolveFs');
- for (var i=0; i < fsButtons.length; ++i) {
- fsButtons[i].addEventListener('click', resolveFs, false);
- }
-}
-
-function clearLog() {
- var log = document.getElementById("log");
- log.innerHTML = "";
-}
-
-function logMessage(message, color) {
- var log = document.getElementById("log");
- var logLine = document.createElement('div');
- if (color) {
- logLine.style.color = color;
- }
- logLine.innerHTML = message;
- log.appendChild(logLine);
-}
-
-function logError(serviceName) {
- return function(err) {
- logMessage("ERROR: " + serviceName + " " + JSON.stringify(err), "red");
- };
-}
-
-function downloadImgCDV(ev) {
- ev.preventDefault();
- ev.stopPropagation();
- downloadImg(imageURL, function(entry) { return entry.toURL(); }, new Image());
-}
-
-function downloadImgNative(ev) {
- ev.preventDefault();
- ev.stopPropagation();
- downloadImg(imageURL, function(entry) { return entry.toNativeURL(); }, new Image);
-}
-
-function downloadVideoCDV(ev) {
- ev.preventDefault();
- ev.stopPropagation();
- var videoElement = document.createElement('video');
- videoElement.controls = "controls";
- downloadImg(videoURL, function(entry) { return entry.toURL(); }, videoElement);
-}
-
-function downloadVideoNative(ev) {
- ev.preventDefault();
- ev.stopPropagation();
- var videoElement = document.createElement('video');
- videoElement.controls = "controls";
- downloadImg(videoURL, function(entry) { return entry.toNativeURL(); }, videoElement);
-}
-
-function testNotModified(ev) {
- ev.preventDefault();
- ev.stopPropagation();
- var ft = new FileTransfer();
- var lastModified = new Date();
- var headers = { "If-Modified-Since": lastModified.toUTCString()};
- logMessage("Starting cached download with headers: " + JSON.stringify(headers));
- ft.download(imageURL, "", logError("ft.download"),function (error) {
- if (error.code === 5) {
- logMessage("Success, the file was not modified.", "green");
- } else {
- logError("ft.download")("The error code was " + error.code + ": " + error.exception);
- }
-
- }, false, {headers: headers});
-}
-
-function downloadImg(source, urlFn, element) {
- var filename = source.substring(source.lastIndexOf("/")+1);
- function download(fileSystem) {
- var ft = new FileTransfer();
- logMessage("Starting download");
- ft.download(source, fileSystem.root.toURL() + filename, function(entry) {
- logMessage("Download complete")
- element.src = urlFn(entry)
- logMessage("Src URL is " + element.src, "green");
- logMessage("Inserting element");
- document.getElementById("output").appendChild(element);
- }, logError("ft.download"));
- }
- clearLog();
- logMessage("Requesting filesystem");
- requestFileSystem(TEMPORARY, 0, function(fileSystem) {
- logMessage("Checking for existing file");
- fileSystem.root.getFile(filename, {create: false}, function(entry) {
- logMessage("Removing existing file");
- entry.remove(function() {
- download(fileSystem);
- }, logError("entry.remove"));
- }, function() {
- download(fileSystem);
- });
- }, logError("requestFileSystem"));
-}
-
-function testPrivateURL(ev) {
- ev.preventDefault();
- ev.stopPropagation();
- requestFileSystem(TEMPORARY, 0, function(fileSystem) {
- logMessage("Temporary root is at " + fileSystem.root.toNativeURL());
- fileSystem.root.getFile("testfile", {create: true}, function(entry) {
- logMessage("Temporary file is at " + entry.toNativeURL());
- if (entry.toNativeURL().substring(0,12) == "file:///var/") {
- logMessage("File starts with /var/, trying /private/var");
- var newURL = "file://localhost/private/var/" + entry.toNativeURL().substring(12) + "?and=another_thing";
- //var newURL = entry.toNativeURL();
- logMessage(newURL, 'blue');
- resolveLocalFileSystemURL(newURL, function(newEntry) {
- logMessage("Successfully resolved.", 'green');
- logMessage(newEntry.toURL(), 'blue');
- logMessage(newEntry.toNativeURL(), 'blue');
- }, logError("resolveLocalFileSystemURL"));
- }
- }, logError("getFile"));
- }, logError("requestFileSystem"));
-}
-
-function resolveFs(ev) {
- var fsURL = "cdvfile://localhost/" + ev.target.getAttribute('data-fsname') + "/";
- logMessage("Resolving URL: " + fsURL);
- resolveLocalFileSystemURL(fsURL, function(entry) {
- logMessage("Success", 'green');
- logMessage(entry.toURL(), 'blue');
- logMessage(entry.toInternalURL(), 'blue');
- logMessage("Resolving URL: " + entry.toURL());
- resolveLocalFileSystemURL(entry.toURL(), function(entry2) {
- logMessage("Success", 'green');
- logMessage(entry2.toURL(), 'blue');
- logMessage(entry2.toInternalURL(), 'blue');
- }, logError("resolveLocalFileSystemURL"));
- }, logError("resolveLocalFileSystemURL"));
-}
-
-window.onload = function() {
- addListenerToClass('backBtn', backHome);
- init();
-}
diff --git a/www/index.html b/www/index.html
index 39bc875..45564f7 100644
--- a/www/index.html
+++ b/www/index.html
@@ -41,7 +41,7 @@
Model: <span id="model"> </span>
Width: <span id="width"> </span>, Height: <span id="height"></span>, Color Depth: <span id="colorDepth"></span>
User-Agent: <span id="user-agent"> </span></div>
- <a href="cdvtests/index.html?showBack" class="btn large">New-Style Tests</a>
+ <a href="cdvtests/index.html#?showBack" class="btn large">New-Style Tests</a>
<a href="autotest/index.html" class="btn large">Automatic Test</a>
<a href="accelerometer/index.html" class="btn large">Accelerometer</a>
<a href="audio/index.html" class="btn large">Audio Play/Record</a>
diff --git a/www/location/index.html b/www/location/index.html
deleted file mode 100644
index f0cc7de..0000000
--- a/www/location/index.html
+++ /dev/null
@@ -1,98 +0,0 @@
-<!DOCTYPE html>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software 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.
-
--->
-
-
-<html>
- <head>
- <meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,maximum-scale=1.0,initial-scale=1.0" />
- <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <!-- ISO-8859-1 -->
- <title>Cordova Mobile Spec</title>
- <link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8">
- <script type="text/javascript" charset="utf-8" src="../cordova-incl.js"></script>
- <script type="text/javascript" charset="utf-8" src="./index.js"></script>
- </head>
- <body id="stage" class="theme">
-
- <h1>Location</h1>
- <div id="info">
- <b>Status:</b> <span id="location_status">Stopped</span>
- <table width="100%">
- <tr>
- <td><b>Latitude:</b></td>
- <td id="latitude"> </td>
- <td>(decimal degrees) geographic coordinate [<a href="http://dev.w3.org/geo/api/spec-source.html#lat">#ref]</a></td>
- </tr>
- <tr>
- <td><b>Longitude:</b></td>
- <td id="longitude"> </td>
- <td>(decimal degrees) geographic coordinate [<a href="http://dev.w3.org/geo/api/spec-source.html#lat">#ref]</a></td>
- </tr>
- <tr>
- <td><b>Altitude:</b></td>
- <td id="altitude"> </td>
- <td>null if not supported;<br>
- (meters) height above the [<a href="http://dev.w3.org/geo/api/spec-source.html#ref-wgs">WGS84</a>] ellipsoid. [<a href="http://dev.w3.org/geo/api/spec-source.html#altitude">#ref]</a></td>
- </tr>
- <tr>
- <td><b>Accuracy:</b></td>
- <td id="accuracy"> </td>
- <td>(meters; non-negative; 95% confidence level) the accuracy level of the latitude and longitude coordinates. [<a href="http://dev.w3.org/geo/api/spec-source.html#accuracy">#ref]</a></td>
- </tr>
- <tr>
- <td><b>Heading:</b></td>
- <td id="heading"> </td>
- <td>null if not supported;<br>
- NaN if speed == 0;<br>
- (degrees; 0° ≤ heading < 360°) direction of travel of the hosting device- counting clockwise relative to the true north. [<a href="http://dev.w3.org/geo/api/spec-source.html#heading">#ref]</a></td>
- </tr>
- <tr>
- <td><b>Speed:</b></td>
- <td id="speed"> </td>
- <td>null if not supported;<br>
- (meters per second; non-negative) magnitude of the horizontal component of the hosting device's current velocity. [<a href="http://dev.w3.org/geo/api/spec-source.html#speed">#ref]</a></td>
- </tr>
- <tr>
- <td><b>Altitude Accuracy:</b></td>
- <td id="altitude_accuracy"> </td>
- <td>null if not supported;<br>(meters; non-negative; 95% confidence level) the accuracy level of the altitude. [<a href="http://dev.w3.org/geo/api/spec-source.html#altitude-accuracy">#ref]</a></td>
- </tr>
- <tr>
- <td><b>Time:</b></td>
- <td id="timestamp"> </td>
- <td>(DOMTimeStamp) when the position was acquired [<a href="http://dev.w3.org/geo/api/spec-source.html#timestamp">#ref]</a></td>
- </tr>
- </table>
- </div>
- <h2>Action</h2>
- <h3>Use Built-in WebView navigator.geolocation</h3>
- <a href="javascript:" class="btn large getWebViewLocation">Get Location</a>
- <a href="javascript:" class="btn large watchWebViewLocation">Start Watching Location</a>
- <a href="javascript:" class="btn large stopWebViewLocation">Stop Watching Location</a>
- <a href="javascript:" class="btn large getWebViewLocation30">Get Location Up to 30 Seconds Old</a>
- <h3>Use Cordova Geolocation Plugin</h3>
- <a href="javascript:" class="btn large getLocation">Get Location</a>
- <a href="javascript:" class="btn large watchLocation">Start Watching Location</a>
- <a href="javascript:" class="btn large stopLocation">Stop Watching Location</a>
- <a href="javascript:" class="btn large getLocation30">Get Location Up to 30 Seconds Old</a>
- <h2> </h2><a href="javascript:" class="backBtn"">Back</a>
- </body>
-</html>
diff --git a/www/location/index.js b/www/location/index.js
deleted file mode 100644
index 242919d..0000000
--- a/www/location/index.js
+++ /dev/null
@@ -1,128 +0,0 @@
-var origGeolocation = null;
-var newGeolocation = null;
-
-//-------------------------------------------------------------------------
-// Location
-//-------------------------------------------------------------------------
-var watchLocationId = null;
-
-/**
- * Start watching location
- */
-var watchLocation = function(usePlugin) {
- var geo = usePlugin ? newGeolocation : origGeolocation;
- if (!geo) {
- alert('geolocation object is missing. usePlugin = ' + usePlugin);
- return;
- }
-
- // Success callback
- var success = function(p){
- console.log('watch location success');
- setLocationDetails(p);
- };
-
- // Fail callback
- var fail = function(e){
- console.log("watchLocation fail callback with error code "+e);
- stopLocation(geo);
- };
-
- // Get location
- watchLocationId = geo.watchPosition(success, fail, {enableHighAccuracy: true});
- setLocationStatus("Running");
-};
-
-/**
- * Stop watching the location
- */
-var stopLocation = function(usePlugin) {
- var geo = usePlugin ? newGeolocation : origGeolocation;
- if (!geo) {
- alert('geolocation object is missing. usePlugin = ' + usePlugin);
- return;
- }
- setLocationStatus("Stopped");
- if (watchLocationId) {
- geo.clearWatch(watchLocationId);
- watchLocationId = null;
- }
-};
-
-/**
- * Get current location
- */
-var getLocation = function(usePlugin, opts) {
- var geo = usePlugin ? newGeolocation : origGeolocation;
- if (!geo) {
- alert('geolocation object is missing. usePlugin = ' + usePlugin);
- return;
- }
-
- // Stop location if running
- stopLocation(geo);
-
- // Success callback
- var success = function(p){
- console.log('get location success');
- setLocationDetails(p);
- setLocationStatus("Done");
- };
-
- // Fail callback
- var fail = function(e){
- console.log("getLocation fail callback with error code "+e.code);
- setLocationStatus("Error: "+e.code);
- };
-
- setLocationStatus("Retrieving location...");
-
- // Get location
- geo.getCurrentPosition(success, fail, opts || {enableHighAccuracy: true}); //, {timeout: 10000});
-
-};
-
-/**
- * Set location status
- */
-var setLocationStatus = function(status) {
- document.getElementById('location_status').innerHTML = status;
-};
-var setLocationDetails = function(p) {
-var date = (new Date(p.timestamp));
- document.getElementById('latitude').innerHTML = p.coords.latitude;
- document.getElementById('longitude').innerHTML = p.coords.longitude;
- document.getElementById('altitude').innerHTML = p.coords.altitude;
- document.getElementById('accuracy').innerHTML = p.coords.accuracy;
- document.getElementById('heading').innerHTML = p.coords.heading;
- document.getElementById('speed').innerHTML = p.coords.speed;
- document.getElementById('altitude_accuracy').innerHTML = p.coords.altitudeAccuracy;
- document.getElementById('timestamp').innerHTML = date.toDateString() + " " + date.toTimeString();
-}
-
-/**
- * Function called when page has finished loading.
- */
-function init() {
- document.addEventListener("deviceready", function() {
- newGeolocation = navigator.geolocation;
- origGeolocation = cordova.require('cordova/modulemapper').getOriginalSymbol(window, 'navigator.geolocation');
- if (!origGeolocation) {
- origGeolocation = newGeolocation;
- newGeolocation = null;
- }
- }, false);
-}
-
-window.onload = function() {
- addListenerToClass('getWebViewLocation', getLocation, [false]);
- addListenerToClass('watchWebViewLocation', watchLocation, [false]);
- addListenerToClass('stopWebViewLocation', stopLocation, [false]);
- addListenerToClass('getWebViewLocation30', getLocation, [false, {maximumAge:30000}]);
- addListenerToClass('getLocation', getLocation, [true]);
- addListenerToClass('watchLocation', watchLocation, [true]);
- addListenerToClass('stopLocation', stopLocation, [true]);
- addListenerToClass('getLocation30', getLocation, [true, {maximumAge:30000}]);
- addListenerToClass('backBtn', backHome);
- init();
-}
diff --git a/www/vibration/index.html b/www/vibration/index.html
deleted file mode 100644
index a24110e..0000000
--- a/www/vibration/index.html
+++ /dev/null
@@ -1,43 +0,0 @@
-<!DOCTYPE html>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software 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.
-
--->
-
-
-<html>
- <head>
- <meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,maximum-scale=1.0,initial-scale=1.0" />
- <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <!-- ISO-8859-1 -->
- <title>Cordova Mobile Spec</title>
- <link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8">
- <script type="text/javascript" charset="utf-8" src="../cordova-incl.js"></script>
- <script type="text/javascript" charset="utf-8" src="./index.js"></script>
- </head>
- <body id="stage" class="theme">
-
- <h1>Vibrations</h1>
- <div id="info">
- </div>
-
- <h2>Action</h2>
- <div class="btn large vibrate">Vibrate</div>
- <h2> </h2><div class="backBtn">Back</div>
- </body>
-</html>
diff --git a/www/vibration/index.js b/www/vibration/index.js
deleted file mode 100644
index 0d28902..0000000
--- a/www/vibration/index.js
+++ /dev/null
@@ -1,31 +0,0 @@
-var deviceReady = false;
-
-//-------------------------------------------------------------------------
-// Vibrations
-//-------------------------------------------------------------------------
-
-var vibrate = function(){
- navigator.notification.vibrate(2500);
-};
-
-
-/**
- * Function called when page has finished loading.
- */
-function init() {
- document.addEventListener("deviceready", function() {
- deviceReady = true;
- console.log("Device="+device.platform+" "+device.version);
- }, false);
- window.setTimeout(function() {
- if (!deviceReady) {
- alert("Error: Apache Cordova did not initialize. Demo will not run correctly.");
- }
- },1000);
-}
-
-window.onload = function() {
- addListenerToClass('vibrate', vibrate);
- addListenerToClass('backBtn', backHome);
- init();
-}