You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2012/11/01 23:09:19 UTC
[15/58] [abbrv] git commit: updated unit tests to the latest version
updated unit tests to the latest version
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp8/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp8/commit/b2eba04a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp8/tree/b2eba04a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp8/diff/b2eba04a
Branch: refs/heads/master
Commit: b2eba04adb566ff188e353f641125e38bccc1c63
Parents: 712e962
Author: Ruslan Kokorev <ru...@bsquare.com>
Authored: Mon Oct 29 15:03:45 2012 +0400
Committer: Ruslan Kokorev <ru...@bsquare.com>
Committed: Mon Oct 29 15:03:45 2012 +0400
----------------------------------------------------------------------
.../CordovaSourceDictionary.xml | 6 +
.../MobileSpecUnitTests/MobileSpecUnitTests.csproj | 6 +
tests/MobileSpecUnitTests/www/autotest/index.html | 3 +
.../www/autotest/pages/all.html | 2 +
.../www/autotest/pages/bridge.html | 71 ++
.../www/autotest/pages/datauri.html | 69 ++
.../www/autotest/pages/globalization.html | 70 ++
.../www/autotest/test-runner.js | 32 +
.../www/autotest/tests/bridge.tests.js | 128 +++
.../www/autotest/tests/datauri.tests.js | 36 +
.../www/autotest/tests/filetransfer.tests.js | 336 ++++---
.../www/autotest/tests/geolocation.tests.js | 25 +-
.../www/autotest/tests/globalization.tests.js | 808 +++++++++++++++
.../www/autotest/tests/storage.tests.js | 19 +-
tests/MobileSpecUnitTests/www/index.html | 3 +-
tests/MobileSpecUnitTests/www/master.css | 7 +-
16 files changed, 1452 insertions(+), 169 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp8/blob/b2eba04a/tests/MobileSpecUnitTests/CordovaSourceDictionary.xml
----------------------------------------------------------------------
diff --git a/tests/MobileSpecUnitTests/CordovaSourceDictionary.xml b/tests/MobileSpecUnitTests/CordovaSourceDictionary.xml
index ef3972d..e5bbf05 100644
--- a/tests/MobileSpecUnitTests/CordovaSourceDictionary.xml
+++ b/tests/MobileSpecUnitTests/CordovaSourceDictionary.xml
@@ -15,14 +15,17 @@
<FilePath Value="www\autotest\pages\accelerometer.html"/>
<FilePath Value="www\autotest\pages\all.html"/>
<FilePath Value="www\autotest\pages\battery.html"/>
+ <FilePath Value="www\autotest\pages\bridge.html"/>
<FilePath Value="www\autotest\pages\camera.html"/>
<FilePath Value="www\autotest\pages\capture.html"/>
<FilePath Value="www\autotest\pages\compass.html"/>
<FilePath Value="www\autotest\pages\contacts.html"/>
+ <FilePath Value="www\autotest\pages\datauri.html"/>
<FilePath Value="www\autotest\pages\device.html"/>
<FilePath Value="www\autotest\pages\file.html"/>
<FilePath Value="www\autotest\pages\filetransfer.html"/>
<FilePath Value="www\autotest\pages\geolocation.html"/>
+ <FilePath Value="www\autotest\pages\globalization.html"/>
<FilePath Value="www\autotest\pages\media.html"/>
<FilePath Value="www\autotest\pages\network.html"/>
<FilePath Value="www\autotest\pages\notification.html"/>
@@ -31,14 +34,17 @@
<FilePath Value="www\autotest\test-runner.js"/>
<FilePath Value="www\autotest\tests\accelerometer.tests.js"/>
<FilePath Value="www\autotest\tests\battery.tests.js"/>
+ <FilePath Value="www\autotest\tests\bridge.tests.js"/>
<FilePath Value="www\autotest\tests\camera.tests.js"/>
<FilePath Value="www\autotest\tests\capture.tests.js"/>
<FilePath Value="www\autotest\tests\compass.tests.js"/>
<FilePath Value="www\autotest\tests\contacts.tests.js"/>
+ <FilePath Value="www\autotest\tests\datauri.tests.js"/>
<FilePath Value="www\autotest\tests\device.tests.js"/>
<FilePath Value="www\autotest\tests\file.tests.js"/>
<FilePath Value="www\autotest\tests\filetransfer.tests.js"/>
<FilePath Value="www\autotest\tests\geolocation.tests.js"/>
+ <FilePath Value="www\autotest\tests\globalization.tests.js"/>
<FilePath Value="www\autotest\tests\media.tests.js"/>
<FilePath Value="www\autotest\tests\network.tests.js"/>
<FilePath Value="www\autotest\tests\notification.tests.js"/>
http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp8/blob/b2eba04a/tests/MobileSpecUnitTests/MobileSpecUnitTests.csproj
----------------------------------------------------------------------
diff --git a/tests/MobileSpecUnitTests/MobileSpecUnitTests.csproj b/tests/MobileSpecUnitTests/MobileSpecUnitTests.csproj
index d0fac05..81bb839 100644
--- a/tests/MobileSpecUnitTests/MobileSpecUnitTests.csproj
+++ b/tests/MobileSpecUnitTests/MobileSpecUnitTests.csproj
@@ -166,14 +166,17 @@
<Content Include="www\autotest\pages\accelerometer.html" />
<Content Include="www\autotest\pages\all.html" />
<Content Include="www\autotest\pages\battery.html" />
+ <Content Include="www\autotest\pages\bridge.html" />
<Content Include="www\autotest\pages\camera.html" />
<Content Include="www\autotest\pages\capture.html" />
<Content Include="www\autotest\pages\compass.html" />
<Content Include="www\autotest\pages\contacts.html" />
+ <Content Include="www\autotest\pages\datauri.html" />
<Content Include="www\autotest\pages\device.html" />
<Content Include="www\autotest\pages\file.html" />
<Content Include="www\autotest\pages\filetransfer.html" />
<Content Include="www\autotest\pages\geolocation.html" />
+ <Content Include="www\autotest\pages\globalization.html" />
<Content Include="www\autotest\pages\media.html" />
<Content Include="www\autotest\pages\network.html" />
<Content Include="www\autotest\pages\notification.html" />
@@ -182,14 +185,17 @@
<Content Include="www\autotest\test-runner.js" />
<Content Include="www\autotest\tests\accelerometer.tests.js" />
<Content Include="www\autotest\tests\battery.tests.js" />
+ <Content Include="www\autotest\tests\bridge.tests.js" />
<Content Include="www\autotest\tests\camera.tests.js" />
<Content Include="www\autotest\tests\capture.tests.js" />
<Content Include="www\autotest\tests\compass.tests.js" />
<Content Include="www\autotest\tests\contacts.tests.js" />
+ <Content Include="www\autotest\tests\datauri.tests.js" />
<Content Include="www\autotest\tests\device.tests.js" />
<Content Include="www\autotest\tests\file.tests.js" />
<Content Include="www\autotest\tests\filetransfer.tests.js" />
<Content Include="www\autotest\tests\geolocation.tests.js" />
+ <Content Include="www\autotest\tests\globalization.tests.js" />
<Content Include="www\autotest\tests\media.tests.js" />
<Content Include="www\autotest\tests\network.tests.js" />
<Content Include="www\autotest\tests\notification.tests.js" />
http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp8/blob/b2eba04a/tests/MobileSpecUnitTests/www/autotest/index.html
----------------------------------------------------------------------
diff --git a/tests/MobileSpecUnitTests/www/autotest/index.html b/tests/MobileSpecUnitTests/www/autotest/index.html
index 70a1eeb..cf1117f 100644
--- a/tests/MobileSpecUnitTests/www/autotest/index.html
+++ b/tests/MobileSpecUnitTests/www/autotest/index.html
@@ -19,15 +19,18 @@
<a href="pages/capture.html" class="btn large" style="width:100%;">Run Capture Tests</a>
<a href="pages/compass.html" class="btn large" style="width:100%;">Run Compass Tests</a>
<a href="pages/contacts.html" class="btn large" style="width:100%;">Run Contacts Tests</a>
+ <a href="pages/datauri.html" class="btn large" style="width:100%;">Run Data URI Tests</a>
<a href="pages/device.html" class="btn large" style="width:100%;">Run Device Tests</a>
<a href="pages/file.html" class="btn large" style="width:100%;">Run File Tests</a>
<a href="pages/filetransfer.html" class="btn large" style="width:100%;">Run FileTransfer Tests</a>
<a href="pages/geolocation.html" class="btn large" style="width:100%;">Run Geolocation Tests</a>
+ <a href="pages/globalization.html" class="btn large" style="width:100%;">Run Globalization Tests</a>
<a href="pages/media.html" class="btn large" style="width:100%;">Run Media Tests</a>
<a href="pages/network.html" class="btn large" style="width:100%;">Run Network Tests</a>
<a href="pages/notification.html" class="btn large" style="width:100%;">Run Notification Tests</a>
<a href="pages/platform.html" class="btn large" style="width:100%;">Run Platform Tests</a>
<a href="pages/storage.html" class="btn large" style="width:100%;">Run Storage Tests</a>
+ <a href="pages/bridge.html" class="btn large" style="width:100%;">Run Bridge Tests</a>
<h2> </h2><div class="backBtn" onclick="backHome();">Back</div>
</body>
http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp8/blob/b2eba04a/tests/MobileSpecUnitTests/www/autotest/pages/all.html
----------------------------------------------------------------------
diff --git a/tests/MobileSpecUnitTests/www/autotest/pages/all.html b/tests/MobileSpecUnitTests/www/autotest/pages/all.html
index f5ed40a..c6cc910 100644
--- a/tests/MobileSpecUnitTests/www/autotest/pages/all.html
+++ b/tests/MobileSpecUnitTests/www/autotest/pages/all.html
@@ -28,10 +28,12 @@
<script type="text/javascript" src="../tests/compass.tests.js"></script>
<script type="text/javascript" src="../tests/contacts.tests.js"></script>
<script type="text/javascript" src="../tests/camera.tests.js"></script>
+ <script type="text/javascript" src="../tests/datauri.tests.js"></script>
<script type="text/javascript" src="../tests/device.tests.js"></script>
<script type="text/javascript" src="../tests/file.tests.js"></script>
<script type="text/javascript" src="../tests/filetransfer.tests.js"></script>
<script type="text/javascript" src="../tests/geolocation.tests.js"></script>
+ <!-- script type="text/javascript" src="../tests/globalization.tests.js"></script -->
<script type="text/javascript" src="../tests/media.tests.js"></script>
<script type="text/javascript" src="../tests/network.tests.js"></script>
<script type="text/javascript" src="../tests/notification.tests.js"></script>
http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp8/blob/b2eba04a/tests/MobileSpecUnitTests/www/autotest/pages/bridge.html
----------------------------------------------------------------------
diff --git a/tests/MobileSpecUnitTests/www/autotest/pages/bridge.html b/tests/MobileSpecUnitTests/www/autotest/pages/bridge.html
new file mode 100644
index 0000000..a1d0a90
--- /dev/null
+++ b/tests/MobileSpecUnitTests/www/autotest/pages/bridge.html
@@ -0,0 +1,71 @@
+<!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: Device 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.js"></script>
+
+ <!-- Load Test Runner -->
+ <script type="text/javascript" src="../test-runner.js"></script>
+
+ <!-- Tests -->
+ <script type="text/javascript" src="../tests/bridge.tests.js"></script>
+
+ <script type="text/javascript">
+ document.addEventListener('deviceready', function () {
+ 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();
+ }, false);
+ </script>
+</head>
+
+<body>
+ <a href="javascript:" class="backBtn" onclick="backHome();">Back</a>
+</body>
+</html>
+
http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp8/blob/b2eba04a/tests/MobileSpecUnitTests/www/autotest/pages/datauri.html
----------------------------------------------------------------------
diff --git a/tests/MobileSpecUnitTests/www/autotest/pages/datauri.html b/tests/MobileSpecUnitTests/www/autotest/pages/datauri.html
new file mode 100644
index 0000000..3d5ffd2
--- /dev/null
+++ b/tests/MobileSpecUnitTests/www/autotest/pages/datauri.html
@@ -0,0 +1,69 @@
+<!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: Data URI tests</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.js"></script>
+
+ <!-- Load Test Runner -->
+ <script type="text/javascript" src="../test-runner.js"></script>
+
+ <!-- Tests -->
+ <script type="text/javascript" src="../tests/datauri.tests.js"></script>
+
+ <script type="text/javascript">
+ document.addEventListener('deviceready', function () {
+ 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();
+ }, false);
+ </script>
+</head>
+
+<body>
+ <a href="javascript:" class="backBtn" onclick="backHome();">Back</a>
+</body>
+</html>
+
http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp8/blob/b2eba04a/tests/MobileSpecUnitTests/www/autotest/pages/globalization.html
----------------------------------------------------------------------
diff --git a/tests/MobileSpecUnitTests/www/autotest/pages/globalization.html b/tests/MobileSpecUnitTests/www/autotest/pages/globalization.html
new file mode 100644
index 0000000..79c5acd
--- /dev/null
+++ b/tests/MobileSpecUnitTests/www/autotest/pages/globalization.html
@@ -0,0 +1,70 @@
+<!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: Globalization 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.js"></script>
+
+ <!-- Load Test Runner -->
+ <script type="text/javascript" src="../test-runner.js"></script>
+
+ <!-- Tests -->
+ <script type="text/javascript" src="../tests/globalization.tests.js"></script>
+
+ <script type="text/javascript">
+ document.addEventListener('deviceready', function () {
+ 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();
+ }, false);
+ </script>
+</head>
+
+<body>
+ <a href="javascript:" class="backBtn" onclick="backHome();">Back</a>
+</body>
+</html>
http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp8/blob/b2eba04a/tests/MobileSpecUnitTests/www/autotest/test-runner.js
----------------------------------------------------------------------
diff --git a/tests/MobileSpecUnitTests/www/autotest/test-runner.js b/tests/MobileSpecUnitTests/www/autotest/test-runner.js
index b8a9417..e85578c 100644
--- a/tests/MobileSpecUnitTests/www/autotest/test-runner.js
+++ b/tests/MobileSpecUnitTests/www/autotest/test-runner.js
@@ -7,3 +7,35 @@ if (window.sessionStorage != null) {
// Android devices.
var Tests = function() {};
Tests.TEST_TIMEOUT = 7500;
+
+// Creates a spy that will fail if called.
+function createDoNotCallSpy(name, opt_extraMessage) {
+ return jasmine.createSpy().andCallFake(function() {
+ var errorMessage = name + ' should not have been called.';
+ if (arguments.length) {
+ errorMessage += ' Got args: ' + JSON.stringify(arguments);
+ }
+ if (opt_extraMessage) {
+ errorMessage += '\n' + opt_extraMessage;
+ }
+ expect(false).toBe(true, errorMessage);
+ });
+}
+
+// Waits for any of the given spys to be called.
+// Last param may be a custom timeout duration.
+function waitsForAny() {
+ var spys = [].slice.call(arguments);
+ var timeout = Tests.TEST_TIMEOUT;
+ if (typeof spys[spys.length - 1] == 'number') {
+ timeout = spys.pop();
+ }
+ waitsFor(function() {
+ for (var i = 0; i < spys.length; ++i) {
+ if (spys[i].wasCalled) {
+ return true;
+ }
+ }
+ return false;
+ }, "Expecting callbacks to be called.", timeout);
+}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp8/blob/b2eba04a/tests/MobileSpecUnitTests/www/autotest/tests/bridge.tests.js
----------------------------------------------------------------------
diff --git a/tests/MobileSpecUnitTests/www/autotest/tests/bridge.tests.js b/tests/MobileSpecUnitTests/www/autotest/tests/bridge.tests.js
new file mode 100644
index 0000000..ec363d7
--- /dev/null
+++ b/tests/MobileSpecUnitTests/www/autotest/tests/bridge.tests.js
@@ -0,0 +1,128 @@
+/*
+ *
+ * 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.
+ *
+*/
+
+/* This test requires some extra code to run, because we want benchmark results */
+
+/*
+ It's never going to be OVER 9000
+ http://youtu.be/SiMHTK15Pik
+*/
+var FENCEPOST = 9000;
+
+var exec = cordova.require('cordova/exec'),
+ echo = cordova.require('cordova/plugin/echo'),
+ startTime,
+ endTime,
+ callCount,
+ durationMs = 1000,
+ asyncEcho,
+ useSetTimeout,
+ payloadSize,
+ payload;
+
+var vanillaWin = function(result) {
+ callCount++;
+ if (result != payload) {
+ console.log('Wrong echo data!');
+ }
+ var elapsedMs = new Date - startTime;
+ if (elapsedMs < durationMs) {
+ if (useSetTimeout) {
+ setTimeout(echoMessage, 0);
+ } else {
+ echoMessage();
+ }
+ } else {
+ endTime = +new Date;
+ }
+}
+
+var reset = function()
+{
+ endTime = null;
+ callCount = 0;
+ useSetTimeout = false;
+ payloadSize = 5;
+ callsPerSecond = 0;
+}
+
+var echoMessage = function()
+{
+ echo(vanillaWin, fail, payload, asyncEcho);
+}
+
+var fail = function() {
+ expect(false).toBe(true);
+};
+
+function createTestCase(jsToNativeModeName, nativeToJsModeName, testAsyncEcho) {
+ it(jsToNativeModeName + '+' + nativeToJsModeName, function() {
+ expect(exec.jsToNativeModes[jsToNativeModeName]).toBeDefined();
+ expect(exec.nativeToJsModes[nativeToJsModeName]).toBeDefined();
+ reset();
+ payload = new Array(payloadSize * 10 + 1).join('012\n\n 6789');
+ asyncEcho = testAsyncEcho;
+ exec.setJsToNativeBridgeMode(exec.jsToNativeModes[jsToNativeModeName]);
+ exec.setNativeToJsBridgeMode(exec.nativeToJsModes[nativeToJsModeName]);
+
+ waits(300);
+ runs(function() {
+ startTime = +new Date,
+ echoMessage();
+ });
+ waitsFor(function() { return endTime; }, "never completed", durationMs * 2);
+ runs(function() {
+ var elapsedMs = endTime - startTime,
+ callsPerSecond = callCount * 1000 / elapsedMs;
+ expect(callsPerSecond).toBeGreaterThan(FENCEPOST);
+ });
+ });
+};
+
+// Wait so that the first benchmark doesn't have contention.
+describe('Wait for page to load.', function() {
+ it('waiting...', function() {
+ waits(1000);
+ });
+});
+
+// Before running on Android, set the following constants in NativeToJsMessagingBridge:
+// - ENABLE_LOCATION_CHANGE_EXEC_MODE = true
+// - DISABLE_EXEC_CHAINING = true
+describe('Android bridge with', function() {
+ var testAsyncEcho = false;
+ createTestCase('PROMPT', 'POLLING', testAsyncEcho);
+ createTestCase('JS_OBJECT', 'POLLING', testAsyncEcho);
+ createTestCase('LOCATION_CHANGE', 'ONLINE_EVENT', testAsyncEcho);
+
+ testAsyncEcho = true;
+ createTestCase('PROMPT', 'POLLING', testAsyncEcho);
+ createTestCase('PROMPT', 'HANGING_GET', testAsyncEcho);
+ createTestCase('PROMPT', 'LOAD_URL', testAsyncEcho);
+ createTestCase('PROMPT', 'ONLINE_EVENT', testAsyncEcho);
+ createTestCase('PROMPT', 'PRIVATE_API', testAsyncEcho);
+
+ createTestCase('JS_OBJECT', 'POLLING', testAsyncEcho);
+ createTestCase('JS_OBJECT', 'HANGING_GET', testAsyncEcho);
+ createTestCase('JS_OBJECT', 'LOAD_URL', testAsyncEcho);
+ createTestCase('JS_OBJECT', 'ONLINE_EVENT', testAsyncEcho);
+ createTestCase('JS_OBJECT', 'PRIVATE_API', testAsyncEcho);
+});
http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp8/blob/b2eba04a/tests/MobileSpecUnitTests/www/autotest/tests/datauri.tests.js
----------------------------------------------------------------------
diff --git a/tests/MobileSpecUnitTests/www/autotest/tests/datauri.tests.js b/tests/MobileSpecUnitTests/www/autotest/tests/datauri.tests.js
new file mode 100644
index 0000000..2e54810
--- /dev/null
+++ b/tests/MobileSpecUnitTests/www/autotest/tests/datauri.tests.js
@@ -0,0 +1,36 @@
+describe('data uris', function () {
+ it("should work with iframes", function() {
+ var gotFoo = false,
+ frame = document.createElement('iframe');
+ function onMessage(msg) {
+ gotFoo = gotFoo || msg.data == 'foo';
+ };
+
+ this.after(function() {
+ document.body.removeChild(frame);
+ window.removeEventListener('message', onMessage, false);
+ });
+
+ window.addEventListener('message', onMessage, false);
+ frame.src = 'data:text/html;charset=utf-8,%3Chtml%3E%3Cscript%3Eparent.postMessage%28%27foo%27%2C%27%2A%27%29%3C%2Fscript%3E%3C%2Fhtml%3E'
+ document.body.appendChild(frame);
+ waitsFor(function() {
+ return gotFoo;
+ }, 'iframe did not load.', 1000);
+ runs(function() {
+ expect(gotFoo).toBe(true);
+ });
+ });
+ it("should work with images", function() {
+ var img = new Image();
+ img.onload = jasmine.createSpy('onLoad');
+ img.onerror = jasmine.createSpy('onError');
+ img.src = 'data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7'
+ waitsFor(function() {
+ return img.onload.wasCalled || img.onerror.wasCalled;
+ }, 'image did not load or error', 1000);
+ runs(function() {
+ expect(img.onload).toHaveBeenCalled();
+ });
+ });
+});
http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp8/blob/b2eba04a/tests/MobileSpecUnitTests/www/autotest/tests/filetransfer.tests.js
----------------------------------------------------------------------
diff --git a/tests/MobileSpecUnitTests/www/autotest/tests/filetransfer.tests.js b/tests/MobileSpecUnitTests/www/autotest/tests/filetransfer.tests.js
index ef67bdb..8c1cd35 100644
--- a/tests/MobileSpecUnitTests/www/autotest/tests/filetransfer.tests.js
+++ b/tests/MobileSpecUnitTests/www/autotest/tests/filetransfer.tests.js
@@ -1,12 +1,31 @@
-describe('FileTransfer', function() {
+/*
+ *
+ * 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('FileTransfer', function() {
// https://github.com/don/cordova-filetransfer
var server = "http://cordova-filetransfer.jitsu.com";
// deletes and re-creates the specified content
var writeFile = function(fileName, fileContent, success, error) {
- var content = fileContent;
- deleteEntry(fileName, function() {
+ deleteFile(fileName, function() {
root.getFile(fileName, {create: true}, function(fileEntry) {
fileEntry.createWriter(function (writer) {
@@ -22,9 +41,20 @@ describe('FileTransfer', function() {
error(evt);
};
- writer.write(content + "\n");
+ writer.write(fileContent + "\n");
}, error);
}, error);
+ });
+ };
+
+ var readFileEntry = function(entry, success, error) {
+ entry.file(function(file) {
+ var reader = new FileReader();
+ reader.onerror = error;
+ reader.onload = function(e) {
+ success(reader.result);
+ };
+ reader.readAsText(file);
}, error);
};
@@ -38,36 +68,19 @@ describe('FileTransfer', function() {
}
};
- // NOTE: copied from file.tests.js
- // 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 and re-creates the specified file
- var createFile = function(fileName, success, error) {
- deleteEntry(fileName, function() {
- root.getFile(fileName, {create: true}, success, error);
- }, error);
- };
// deletes file, if it exists, then invokes callback
var deleteFile = function(fileName, callback) {
+ callback = callback || function() {};
+ var spy = jasmine.createSpy().andCallFake(callback);
root.getFile(fileName, null,
// remove file system entry
function(entry) {
- entry.remove(callback, function() { console.log('[ERROR] deleteFile cleanup method invoked fail callback.'); });
+ entry.remove(spy, spy);
},
// doesn't exist
- callback);
+ spy);
+ waitsFor(function() { return spy.wasCalled; }, Tests.TEST_TIMEOUT);
};
- // end copied from file.tests.js
it("should exist and be constructable", function() {
var ft = new FileTransfer();
@@ -99,80 +112,121 @@ describe('FileTransfer', function() {
// - Item 1 String cordova-filetransfer.jitsu.com
// - Item 2 String *.apache.org
- it("should be able to download a file", function() {
- var fail = jasmine.createSpy();
+ it("should be able to download a file using http", function() {
+ var fail = createDoNotCallSpy('downloadFail');
var remoteFile = server + "/robots.txt"
var localFileName = remoteFile.substring(remoteFile.lastIndexOf('/')+1);
+ var lastProgressEvent = null;
+
var downloadWin = jasmine.createSpy().andCallFake(function(entry) {
expect(entry.name).toBe(localFileName);
- deleteFile(localFileName);
+ expect(lastProgressEvent.loaded).toBeGreaterThan(1);
});
+ this.after(function() {
+ deleteFile(localFileName);
+ });
runs(function() {
var ft = new FileTransfer();
+ ft.onprogress = function(e) {
+ lastProgressEvent = e;
+ };
ft.download(remoteFile, root.fullPath + "/" + localFileName, downloadWin, fail);
});
- waitsFor(function() { return downloadWin.wasCalled; }, "downloadWin", Tests.TEST_TIMEOUT);
+ waitsForAny(downloadWin, fail);
+ });
+ it("should be able to download a file using https", function() {
+ var remoteFile = "https://www.apache.org/licenses/";
+ var localFileName = 'httpstest.html';
+ var downloadFail = createDoNotCallSpy('downloadFail', 'Ensure ' + remoteFile + ' is in the white-list');
+ var fileFail = createDoNotCallSpy('fileFail');
+ var downloadWin = function(entry) {
+ readFileEntry(entry, fileWin, fileFail);
+ };
+ var fileWin = jasmine.createSpy().andCallFake(function(content) {
+ expect(content).toMatch(/The Apache Software Foundation/);
+ });
+ this.after(function() {
+ deleteFile(localFileName);
+ });
runs(function() {
- expect(downloadWin).toHaveBeenCalled();
- expect(fail).not.toHaveBeenCalled();
+ var ft = new FileTransfer();
+ ft.download(remoteFile, root.fullPath + "/" + localFileName, downloadWin, downloadFail);
});
+
+ waitsForAny(fileWin, downloadFail, fileFail);
+ });
+ it("should be stopped by abort() right away", function() {
+ var downloadWin = createDoNotCallSpy('downloadWin');
+ var remoteFile = 'http://audio.ibeat.org/content/p1rj1s/p1rj1s_-_rockGuitar.mp3';
+ var localFileName = remoteFile.substring(remoteFile.lastIndexOf('/')+1);
+ var startTime = +new Date();
+
+ var downloadFail = jasmine.createSpy().andCallFake(function(e) {
+ expect(e.code).toBe(FileTransferError.ABORT_ERR);
+ expect(new Date() - startTime).toBeLessThan(300);
+ });
+
+ this.after(function() {
+ deleteFile(localFileName);
+ });
+ runs(function() {
+ var ft = new FileTransfer();
+ ft.abort(); // should be a no-op.
+ ft.download(remoteFile, root.fullPath + "/" + localFileName, downloadWin, downloadFail);
+ ft.abort();
+ ft.abort(); // should be a no-op.
+ });
+
+ waitsForAny(downloadWin, downloadFail);
});
it("should get http status on failure", function() {
- var downloadWin = jasmine.createSpy();
+ var downloadWin = createDoNotCallSpy('downloadWin');
var remoteFile = server + "/404";
var localFileName = remoteFile.substring(remoteFile.lastIndexOf('/')+1);
var downloadFail = jasmine.createSpy().andCallFake(function(error) {
expect(error.http_status).toBe(404);
expect(error.http_status).not.toBe(401, "Ensure " + remoteFile + " is in the white list");
- deleteFile(localFileName);
});
+ this.after(function() {
+ deleteFile(localFileName);
+ });
runs(function() {
var ft = new FileTransfer();
ft.download(remoteFile, root.fullPath + "/" + localFileName, downloadWin, downloadFail);
});
- waitsFor(function() { return downloadFail.wasCalled; }, "downloadFail", Tests.TEST_TIMEOUT);
-
- runs(function() {
- expect(downloadFail).toHaveBeenCalled();
- expect(downloadWin).not.toHaveBeenCalled();
- });
+ waitsForAny(downloadWin, downloadFail);
});
it("should handle malformed urls", function() {
-
- var downloadWin = jasmine.createSpy();
+ var downloadWin = createDoNotCallSpy('downloadWin');
var remoteFile = getMalformedUrl();
var localFileName = "download_malformed_url.txt";
var downloadFail = jasmine.createSpy().andCallFake(function(error) {
-
// Note: Android needs the bad protocol to be added to the access list
// <access origin=".*"/> won't match because ^https?:// is prepended to the regex
// The bad protocol must begin with http to avoid automatic prefix
expect(error.http_status).not.toBe(401, "Ensure " + remoteFile + " is in the white list");
expect(error.code).toBe(FileTransferError.INVALID_URL_ERR);
- deleteFile(localFileName);
});
+ this.after(function() {
+ deleteFile(localFileName);
+ });
runs(function() {
var ft = new FileTransfer();
ft.download(remoteFile, root.fullPath + "/" + localFileName, downloadWin, downloadFail);
});
- waitsFor(function() { return downloadFail.wasCalled; }, "downloadFail", Tests.TEST_TIMEOUT);
-
- runs(function() {
- expect(downloadFail).toHaveBeenCalled();
- expect(downloadWin).not.toHaveBeenCalled();
- });
+ waitsForAny(downloadWin, downloadFail);
});
it("should handle unknown host", function() {
- var downloadWin = jasmine.createSpy();
+ var downloadWin = createDoNotCallSpy('downloadWin');
var remoteFile = "http://foobar.apache.org/index.html";
var localFileName = remoteFile.substring(remoteFile.lastIndexOf('/')+1);
@@ -185,16 +239,10 @@ describe('FileTransfer', function() {
ft.download(remoteFile, root.fullPath + "/" + localFileName, downloadWin, downloadFail);
});
- waitsFor(function() { return downloadFail.wasCalled; }, "downloadFail", Tests.TEST_TIMEOUT);
-
- runs(function() {
- expect(downloadFail).toHaveBeenCalled();
- expect(downloadWin).not.toHaveBeenCalled();
- });
+ waitsForAny(downloadWin, downloadFail);
});
it("should handle bad file path", function() {
- var fail = jasmine.createSpy();
- var downloadWin = jasmine.createSpy();
+ var downloadWin = createDoNotCallSpy('downloadWin');
var remoteFile = server;
var badFilePath = "c:\\54321";
@@ -207,31 +255,24 @@ describe('FileTransfer', function() {
ft.download(remoteFile, badFilePath, downloadWin, downloadFail);
});
- waitsFor(function() { return downloadFail.wasCalled; }, "downloadFail", Tests.TEST_TIMEOUT);
-
- runs(function() {
- expect(downloadFail).toHaveBeenCalled();
- expect(downloadWin).not.toHaveBeenCalled();
- expect(fail).not.toHaveBeenCalled();
- });
+ waitsForAny(downloadWin, downloadFail);
});
});
describe('upload method', function() {
it("should be able to upload a file", function() {
- var fail = jasmine.createSpy();
- var uploadFail = function() {
- expect(false).toBe(true, "Ensure " + remoteFile + " is in the white list");
- };
-
var remoteFile = server + "/upload";
var localFileName = "upload.txt";
+ var fileContents = 'This file should upload';
+
+ var fileFail = createDoNotCallSpy('fileFail');
+ var uploadFail = createDoNotCallSpy('uploadFail', "Ensure " + remoteFile + " is in the white list");
+ var lastProgressEvent = null;
var uploadWin = jasmine.createSpy().andCallFake(function(uploadResult) {
expect(uploadResult.bytesSent).toBeGreaterThan(0);
expect(uploadResult.responseCode).toBe(200);
- expect(uploadResult.response).toBeDefined();
- deleteEntry(localFileName);
+ expect(uploadResult.response).toMatch(/fields:\s*{\s*value1.*/);
});
var fileWin = function(fileEntry) {
@@ -247,31 +288,76 @@ describe('FileTransfer', function() {
params.value2 = "param";
options.params = params;
+ ft.onprogress = function(e) {
+ expect(e.lengthComputable).toBe(true);
+ expect(e.total).toBeGreaterThan(0);
+ expect(e.loaded).toBeGreaterThan(0);
+ lastProgressEvent = e;
+ };
+
// removing options cause Android to timeout
ft.upload(fileEntry.fullPath, remoteFile, uploadWin, uploadFail, options);
};
+ this.after(function() {
+ deleteFile(localFileName);
+ });
runs(function() {
- writeFile(localFileName, "this file should upload", fileWin, fail);
+ writeFile(localFileName, fileContents, fileWin, fileFail);
});
- waitsFor(function() { return uploadWin.wasCalled; }, "uploadWin", Tests.TEST_TIMEOUT);
+ waitsForAny(uploadWin, uploadFail, fileFail);
+ runs(function() {
+ expect(lastProgressEvent).not.toBeNull('expected progress events');
+ });
+ });
+ it("should be stopped by abort() right away.", function() {
+ var remoteFile = server + "/upload";
+ var localFileName = "upload.txt";
+
+ var fileFail = createDoNotCallSpy('fileFail');
+ var uploadWin = createDoNotCallSpy('uploadWin', 'Should have been aborted');
+ var startTime;
+
+ var uploadFail = jasmine.createSpy().andCallFake(function(e) {
+ expect(e.code).toBe(FileTransferError.ABORT_ERR);
+ expect(new Date() - startTime).toBeLessThan(300);
+ });
+
+ var fileWin = function(fileEntry) {
+ ft = new FileTransfer();
+ var options = new FileUploadOptions();
+ options.fileKey = "file";
+ options.fileName = localFileName;
+ options.mimeType = "text/plain";
+
+ startTime = +new Date();
+ // removing options cause Android to timeout
+ ft.abort(); // should be a no-op.
+ ft.upload(fileEntry.fullPath, remoteFile, uploadWin, uploadFail, options);
+ ft.abort();
+ ft.abort(); // should be a no-op.
+ };
+
+ this.after(function() {
+ deleteFile(localFileName);
+ });
runs(function() {
- expect(uploadWin).toHaveBeenCalled();
- expect(fail).not.toHaveBeenCalled();
+ writeFile(localFileName, new Array(10000).join('aborttest!'), fileWin, fileFail);
});
+
+ waitsForAny(uploadWin, uploadFail, fileFail);
});
it("should get http status on failure", function() {
- var fail = jasmine.createSpy();
- var uploadWin = jasmine.createSpy();
+ var fileFail = createDoNotCallSpy('fileFail');
+ var uploadWin = createDoNotCallSpy('uploadWin');
var remoteFile = server + "/403";
var localFileName = "upload_expect_fail.txt";
var uploadFail = jasmine.createSpy().andCallFake(function(error) {
expect(error.http_status).toBe(403);
expect(error.http_status).not.toBe(401, "Ensure " + remoteFile + " is in the white list");
- deleteEntry(localFileName);
});
var fileWin = function(fileEntry) {
@@ -285,77 +371,65 @@ describe('FileTransfer', function() {
ft.upload(fileEntry.fullPath, remoteFile, uploadWin, uploadFail, options);
};
- runs(function() {
- writeFile(localFileName, "this file should fail to upload", fileWin, fail);
+ this.after(function() {
+ deleteFile(localFileName);
});
-
- waitsFor(function() { return uploadFail.wasCalled; }, "Expecting file upload to fail", Tests.TEST_TIMEOUT);
-
runs(function() {
- expect(uploadFail).toHaveBeenCalled();
- expect(uploadWin).not.toHaveBeenCalled();
- expect(fail).not.toHaveBeenCalled();
+ writeFile(localFileName, "this file should fail to upload", fileWin, fileFail);
});
+
+ waitsForAny(uploadWin, uploadFail, fileFail);
});
it("should handle malformed urls", function() {
- var fail = jasmine.createSpy();
- var uploadWin = jasmine.createSpy();
+ var fileFail = createDoNotCallSpy('fileFail');
+ var uploadWin = createDoNotCallSpy('uploadWin');
var remoteFile = getMalformedUrl();
var localFileName = "malformed_url.txt";
var uploadFail = jasmine.createSpy().andCallFake(function(error) {
expect(error.code).toBe(FileTransferError.INVALID_URL_ERR);
expect(error.http_status).not.toBe(401, "Ensure " + remoteFile + " is in the white list");
- deleteFile(localFileName);
});
var fileWin = function(fileEntry) {
var ft = new FileTransfer();
ft.upload(fileEntry.fullPath, remoteFile, uploadWin, uploadFail, {});
};
- runs(function() {
- writeFile(localFileName, "Some content", fileWin, fail);
+ this.after(function() {
+ deleteFile(localFileName);
});
-
- waitsFor(function() { return uploadFail.wasCalled; }, "uploadFail", Tests.TEST_TIMEOUT);
-
runs(function() {
- expect(uploadFail).toHaveBeenCalled();
- expect(uploadWin).not.toHaveBeenCalled();
- expect(fail).not.toHaveBeenCalled();
+ writeFile(localFileName, "Some content", fileWin, fileFail);
});
+
+ waitsForAny(uploadWin, uploadFail, fileFail);
});
it("should handle unknown host", function() {
- var fail = jasmine.createSpy();
- var uploadWin = jasmine.createSpy();
+ var fileFail = createDoNotCallSpy('fileFail');
+ var uploadWin = createDoNotCallSpy('uploadWin');
var remoteFile = "http://foobar.apache.org/robots.txt";
var localFileName = remoteFile.substring(remoteFile.lastIndexOf('/')+1);
var uploadFail = jasmine.createSpy().andCallFake(function(error) {
expect(error.code).toBe(FileTransferError.CONNECTION_ERR);
expect(error.http_status).not.toBe(401, "Ensure " + remoteFile + " is in the white list");
- deleteFile(localFileName);
});
var fileWin = function(fileEntry) {
var ft = new FileTransfer();
ft.upload(fileEntry.fullPath, remoteFile, uploadWin, uploadFail, {});
};
- runs(function() {
- writeFile(localFileName, "# allow all", fileWin, fail);
+ this.after(function() {
+ deleteFile(localFileName);
});
-
- waitsFor(function() { return uploadFail.wasCalled; }, "uploadFail", Tests.TEST_TIMEOUT);
-
runs(function() {
- expect(uploadFail).toHaveBeenCalled();
- expect(uploadWin).not.toHaveBeenCalled();
- expect(fail).not.toHaveBeenCalled();
+ writeFile(localFileName, "# allow all", fileWin, fileFail);
});
+
+ waitsForAny(uploadWin, uploadFail, fileFail);
});
it("should handle missing file", function() {
- var fail = jasmine.createSpy();
- var uploadWin = jasmine.createSpy();
+ var uploadWin = createDoNotCallSpy('uploadWin');
var remoteFile = server + "/upload";
var localFileName = "does_not_exist.txt";
@@ -366,22 +440,14 @@ describe('FileTransfer', function() {
});
runs(function() {
- deleteFile(localFileName, function() {
- var ft = new FileTransfer();
- ft.upload(root.fullPath + "/" + localFileName, remoteFile, uploadWin, uploadFail);
- }, fail);
+ var ft = new FileTransfer();
+ ft.upload(root.fullPath + "/" + localFileName, remoteFile, uploadWin, uploadFail);
});
- waitsFor(function() { return uploadFail.wasCalled; }, "uploadFail", Tests.TEST_TIMEOUT);
-
- runs(function() {
- expect(uploadFail).toHaveBeenCalled();
- expect(uploadWin).not.toHaveBeenCalled();
- expect(fail).not.toHaveBeenCalled();
- });
+ waitsForAny(uploadWin, uploadFail);
});
it("should handle bad file path", function() {
- var uploadWin = jasmine.createSpy();
+ var uploadWin = createDoNotCallSpy('uploadWin');
var remoteFile = server + "/upload";
@@ -395,28 +461,19 @@ describe('FileTransfer', function() {
ft.upload("/usr/local/bad/file/path.txt", remoteFile, uploadWin, uploadFail);
});
- waitsFor(function() { return uploadFail.wasCalled; }, "uploadFail", Tests.TEST_TIMEOUT);
-
- runs(function() {
- expect(uploadFail).toHaveBeenCalled();
- expect(uploadWin).not.toHaveBeenCalled();
- });
-
+ waitsForAny(uploadWin, uploadFail);
});
it("should be able to set custom headers", function() {
var remoteFile = "http://whatheaders.com";
var localFileName = "upload.txt";
var fileFail = function() {};
- var uploadFail = function() {
- expect(false).toBe(true, "Ensure " + remoteFile + " is in the white list and that Content-Length header is being set.");
- };
+ var uploadFail = createDoNotCallSpy('uploadFail', "Ensure " + remoteFile + " is in the white list and that Content-Length header is being set.");
var uploadWin = jasmine.createSpy().andCallFake(function(uploadResult) {
expect(uploadResult.bytesSent).toBeGreaterThan(0);
expect(uploadResult.responseCode).toBe(200);
expect(uploadResult.response).toBeDefined();
- deleteEntry(localFileName);
var responseHtml = decodeURIComponent(uploadResult.response);
expect(responseHtml).toMatch(/CustomHeader1[\s\S]*CustomValue1/i);
expect(responseHtml).toMatch(/CustomHeader2[\s\S]*CustomValue2[\s\S]*CustomValue3/i, "Should allow array values");
@@ -443,15 +500,14 @@ describe('FileTransfer', function() {
ft.upload(fileEntry.fullPath, remoteFile, uploadWin, uploadFail, options);
};
+ this.after(function() {
+ deleteFile(localFileName);
+ });
runs(function() {
writeFile(localFileName, "this file should upload", fileWin, fileFail);
});
- waitsFor(function() { return uploadWin.wasCalled; }, "uploadWin", Tests.TEST_TIMEOUT);
-
- runs(function() {
- expect(uploadWin).toHaveBeenCalled();
- });
+ waitsForAny(uploadWin, uploadFail);
});
});
});
http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp8/blob/b2eba04a/tests/MobileSpecUnitTests/www/autotest/tests/geolocation.tests.js
----------------------------------------------------------------------
diff --git a/tests/MobileSpecUnitTests/www/autotest/tests/geolocation.tests.js b/tests/MobileSpecUnitTests/www/autotest/tests/geolocation.tests.js
index 685a7d6..7d1d6ce 100644
--- a/tests/MobileSpecUnitTests/www/autotest/tests/geolocation.tests.js
+++ b/tests/MobileSpecUnitTests/www/autotest/tests/geolocation.tests.js
@@ -45,7 +45,6 @@ describe('Geolocation (navigator.geolocation)', function () {
var win = jasmine.createSpy().andCallFake(function(p) {
expect(p.coords).toBeDefined();
expect(p.timestamp).toBeDefined();
- expect(p.timestamp instanceof Date).toBe(true);
}),
fail = jasmine.createSpy();
@@ -100,13 +99,12 @@ describe('Geolocation (navigator.geolocation)', function () {
var win = jasmine.createSpy().andCallFake(function(p) {
expect(p.coords).toBeDefined();
expect(p.timestamp).toBeDefined();
- expect(p.timestamp instanceof Date).toBe(true);
}),
fail = jasmine.createSpy();
runs(function () {
successWatch = navigator.geolocation.watchPosition(win, fail, {
- maximumAge:300000 // 5 minutes maximum age of cached position
+ maximumAge:(5 * 60 * 1000) // 5 minutes maximum age of cached position
});
});
@@ -118,25 +116,4 @@ describe('Geolocation (navigator.geolocation)', function () {
});
});
});
-
- describe("Geolocation model", function () {
- it("should be able to define a Position object with coords and timestamp properties", function() {
- var pos = new Position({}, new Date());
- expect(pos).toBeDefined();
- expect(pos.coords).toBeDefined();
- expect(pos.timestamp).toBeDefined();
- });
-
- it("should be able to define a Coordinates object with latitude, longitude, accuracy, altitude, heading, speed and altitudeAccuracy properties", function() {
- var coords = new Coordinates(1,2,3,4,5,6,7);
- expect(coords).toBeDefined();
- expect(coords.latitude).toBeDefined();
- expect(coords.longitude).toBeDefined();
- expect(coords.accuracy).toBeDefined();
- expect(coords.altitude).toBeDefined();
- expect(coords.heading).toBeDefined();
- expect(coords.speed).toBeDefined();
- expect(coords.altitudeAccuracy).toBeDefined();
- });
- });
});