incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject [1/37] spec commit: converted over filetransfer tests to jasmine
Date Wed, 18 Apr 2012 21:49:52 GMT
Updated Branches:
  refs/heads/master 7125e7256 -> 245384dfa


converted over filetransfer tests to jasmine


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/commit/245384df
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/tree/245384df
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/diff/245384df

Branch: refs/heads/master
Commit: 245384dfac45f9dac142217938b1da928589c219
Parents: 19f30b6
Author: Fil Maj <maj.fil@gmail.com>
Authored: Wed Apr 18 14:51:15 2012 -0700
Committer: Fil Maj <maj.fil@gmail.com>
Committed: Wed Apr 18 14:51:15 2012 -0700

----------------------------------------------------------------------
 autotest/pages/all.html              |    3 +
 autotest/pages/file.html             |    2 +
 autotest/pages/filetransfer.html     |  112 ++++++++++++++++-------------
 autotest/tests/file.tests.js         |    3 -
 autotest/tests/filetransfer.tests.js |   74 ++++++++++----------
 5 files changed, 105 insertions(+), 89 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/blob/245384df/autotest/pages/all.html
----------------------------------------------------------------------
diff --git a/autotest/pages/all.html b/autotest/pages/all.html
index 339db4f..7840ebd 100644
--- a/autotest/pages/all.html
+++ b/autotest/pages/all.html
@@ -28,6 +28,7 @@
   <script type="text/javascript" src="../tests/camera.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/media.tests.js"></script>
   <script type="text/javascript" src="../tests/network.tests.js"></script>
@@ -36,6 +37,8 @@
   <script type="text/javascript" src="../tests/storage.tests.js"></script>
 
   <script type="text/javascript">
+      var root, temp_root, persistent_root;
+
       document.addEventListener('deviceready', function () {
           // one-time retrieval of the root file system entry
           var onError = function(e) {

http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/blob/245384df/autotest/pages/file.html
----------------------------------------------------------------------
diff --git a/autotest/pages/file.html b/autotest/pages/file.html
index 6cf48a8..d813d22 100644
--- a/autotest/pages/file.html
+++ b/autotest/pages/file.html
@@ -23,6 +23,8 @@
   <script type="text/javascript" src="../tests/file.tests.js"></script>
 
   <script type="text/javascript">
+      var root, temp_root, persistent_root;
+
       document.addEventListener('deviceready', function () {
           // one-time retrieval of the root file system entry
           var onError = function(e) {

http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/blob/245384df/autotest/pages/filetransfer.html
----------------------------------------------------------------------
diff --git a/autotest/pages/filetransfer.html b/autotest/pages/filetransfer.html
index f305a66..9dd9d12 100644
--- a/autotest/pages/filetransfer.html
+++ b/autotest/pages/filetransfer.html
@@ -1,54 +1,68 @@
 <!DOCTYPE html>
 <html>
-  <head>
-    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
-    <meta name="viewport" content="width=device-width, height=device-height, user-scalable=yes,
initial-scale=1.0;" />
-
-    <title>Cordova: FileTransfer API Specs</title>
-
-    <!-- Load QUnit -->
-    <link rel="stylesheet" type="text/css" href="../qunit.css" />
-    <script type="text/javascript" src="../qunit.js"></script>
-
-    <!-- Source -->
-    <script type="text/javascript" src="../../phonegap.js"></script>
-
-    <!-- Load Test Runner -->
-    <script type="text/javascript" src="../test-runner.js"></script>
-
-    <!-- Tests -->
-    <script type="text/javascript" src="../tests/filetransfer.tests.js"></script>
-    <script type="text/javascript">
-      document.addEventListener('deviceready', function() {
-          console.log('running tests');
-          var tests = new Tests();
-
-          // Each group of tests are declared as a function in the object `Tests`.
-          // A group of tests are identified by a name that contains the word 'Tests'.
-          //
-          // Load each group of tests into QUnit
-          for (var t in tests) {
-              if (t.indexOf('Tests') > -1) {
-                  tests[t]();
-              }
-          }
-
-          // Start the QUnit test suite
-          QUnit.start();
-      }, false);
-    </script>
-  </head>
-    <body>
-        <div class="backBtn" onclick="backHome();">Back</div>
-        <h1 id="qunit-header">Cordova: File Transfer API Specs</h1>
-        <h2 id="qunit-banner"></h2>
-        <h2 id="qunit-userAgent"></h2>
-        <ol id="qunit-tests"></ol>
-        <div id="qunit-fixture">
-            <!-- Populated by tests -->
-        </div>
-    </body>
-</html>
+<head>
+  <title>Cordova: File API Specs</title>
+
+  <!-- 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="../../phonegap.js"></script>
+
+  <!-- Load Test Runner -->
+  <script type="text/javascript" src="../test-runner.js"></script>
+
+  <!-- Tests -->
+  <script type="text/javascript" src="../tests/filetransfer.tests.js"></script>
+
+  <script type="text/javascript">
+      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);
+  </script>
+</head>
+
+<body>
+  <a href="javascript:" class="backBtn" onclick="backHome();">Back</a>
+</body>
+</html>
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/blob/245384df/autotest/tests/file.tests.js
----------------------------------------------------------------------
diff --git a/autotest/tests/file.tests.js b/autotest/tests/file.tests.js
index e46e51c..ce8b6cc 100644
--- a/autotest/tests/file.tests.js
+++ b/autotest/tests/file.tests.js
@@ -1,6 +1,3 @@
-// Used by tests, set in file.html
-var root, temp_root, persistent_root;
-
 describe('File API', function() {
     // HELPER FUNCTIONS
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/blob/245384df/autotest/tests/filetransfer.tests.js
----------------------------------------------------------------------
diff --git a/autotest/tests/filetransfer.tests.js b/autotest/tests/filetransfer.tests.js
index 855019f..87ab385 100644
--- a/autotest/tests/filetransfer.tests.js
+++ b/autotest/tests/filetransfer.tests.js
@@ -1,44 +1,44 @@
-Tests.prototype.FileTransferTests = function() {  
-    module('FileTransfer');
-    test("should exist", function() {
-        expect(1);
+describe('FileTransfer', function() {
+    it("should exist and be constructable", function() {
         var ft = new FileTransfer();
-        ok(ft !== null, "FileTransfer should not be null.");
+        expect(ft).toBeDefined();
     });
-    test("should contain proper function", function() {
-        expect(4);
+    it("should contain proper functions", function() {
         var ft = new FileTransfer();
-        ok(typeof ft.upload != 'undefined' && ft.upload !== null, "FileTransfer.upload
should not be null.");
-        ok(typeof ft.upload == 'function', "FileTransfer.upload should be a function.");
-        ok(typeof ft.download != 'undefined' && ft.download !== null, "FileTransfer.download
should not be null.");
-        ok(typeof ft.download == 'function', "FileTransfer.download should be a function.");
+        expect(typeof ft.upload).toBe('function');
+        expect(typeof ft.download).toBe('function');
     });
-    module('FileTransferError interface');
-    test("FileTransferError constants should be defined", function() {
-        expect(3);
-        equal(FileTransferError.FILE_NOT_FOUND_ERR, 1, "FileTransferError.FILE_NOT_FOUND_ERR
should be defined");
-        equal(FileTransferError.INVALID_URL_ERR, 2, "FileTransferError.INVALID_URL_ERR should
be defined");
-        equal(FileTransferError.CONNECTION_ERR, 3, "FileTransferError.CONNECTION_ERR should
be defined");
+    describe('FileTransferError', function() {
+        it("FileTransferError constants should be defined", function() {
+            expect(FileTransferError.FILE_NOT_FOUND_ERR).toBe(1);
+            expect(FileTransferError.INVALID_URL_ERR).toBe(2);
+            expect(FileTransferError.CONNECTION_ERR).toBe(3);
+        });
     });
-    module('FileTransfer.download');
-    test("should be able to download a file", function() {
-        expect(1);
-        QUnit.stop(Tests.TEST_TIMEOUT);
-        var fail = function(error) {
-            ok(false, "This test failed, check to see if you whitelisted 'ajax.googleapis.com'");
-            QUnit.start();
-        };
-        var remoteFile = "https://ajax.googleapis.com/ajax/libs/dojo/1.7.2/dojo/dojo.js";
-        var localFileName = remoteFile.substring(remoteFile.lastIndexOf('/')+1);
-        
-        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
-            fileSystem.root.getFile(localFileName, {create: true, exclusive: false}, function(fileEntry)
{
+    describe('download method', function() {
+        it("should be able to download a file", function() {
+            var fail = jasmine.createSpy();
+            var remoteFile = "https://ajax.googleapis.com/ajax/libs/dojo/1.7.2/dojo/dojo.js";
+            var localFileName = remoteFile.substring(remoteFile.lastIndexOf('/')+1);
+            var downloadWin = jasmine.createSpy().andCallFake(function(entry) {
+                expect(entry.name).toBe(localFileName);
+            });
+            var fileWin = function(fileEntry) {
                 var ft = new FileTransfer();
-                ft.download(remoteFile, fileEntry.fullPath, function(entry) {
-                    ok(entry.name == localFileName, "File name returned should match expected");
-                    QUnit.start();
-                    }, fail);
-            }, fail);
-        }, fail);
+                ft.download(remoteFile, fileEntry.fullPath, downloadWin);
+            };
+            
+            // root is defined in the html page containing these tests
+            runs(function() {
+                root.getFile(localFileName, {create: true, exclusive: false}, fileWin, fail);
+            });
+
+            waitsFor(function() { return downloadWin.wasCalled; }, "downloadWin", Tests.TEST_TIMEOUT);
+
+            runs(function() {
+                expect(downloadWin).toHaveBeenCalled();
+                expect(fail).not.toHaveBeenCalled();
+            });
+        });
     });
-};
+});


Mime
View raw message