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/06 01:38:28 UTC
[6/25] store deviceId in
Windows.Storage.ApplicationData.current.localSettings.values.deviceId,
instead of global documents folder.
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0bdb8350/test/window8/filetransfer.tests.js
----------------------------------------------------------------------
diff --git a/test/window8/filetransfer.tests.js b/test/window8/filetransfer.tests.js
deleted file mode 100644
index b231dc3..0000000
--- a/test/window8/filetransfer.tests.js
+++ /dev/null
@@ -1,72 +0,0 @@
-describe('FileTransfer', function() {
- it("should exist and be constructable", function() {
- var ft = new FileTransfer();
- expect(ft).toBeDefined();
- });
- it("should contain proper functions", function() {
- var ft = new FileTransfer();
- expect(typeof ft.upload).toBe('function');
- expect(typeof ft.download).toBe('function');
- });
- 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);
- });
- });
- describe('download method', function() {
- it("should be able to download a file", function() {
- var fail = jasmine.createSpy();
- var remoteFile = "https://github.com/ajaxorg/cloud9/blob/master/server.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, 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();
- });
- });
- });
- describe('upload method', function () {
- it("should be able to upload a file", function () {
- var fail = jasmine.createSpy();
- var localFileName = "server.js";
- var localFile = root.fullPath + "\\" + localFileName;
- var Url = "http://localhost:5000/upload";
- var uploadWin = jasmine.createSpy().andCallFake(function (entry) {
- expect(entry.responseCode).toBe(200);
- });
- var fileWin = function (fileEntry) {
- console.log("1========");
- var ft = new FileTransfer();
- ft.upload(localFile, Url, uploadWin,fail,null);
- };
-
- // root is defined in the html page containing these tests
- runs(function () {
- root.getFile(localFileName, { create: false }, fileWin, fail);
- });
-
- waitsFor(function () { return uploadWin.wasCalled; }, "uploadWin", Tests.TEST_TIMEOUT);
-
- runs(function () {
- expect(uploadWin).toHaveBeenCalled();
- expect(fail).not.toHaveBeenCalled();
- });
- });
- });
-});
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0bdb8350/test/window8/geolocation.tests.js
----------------------------------------------------------------------
diff --git a/test/window8/geolocation.tests.js b/test/window8/geolocation.tests.js
deleted file mode 100644
index 71e0c2e..0000000
--- a/test/window8/geolocation.tests.js
+++ /dev/null
@@ -1,106 +0,0 @@
-describe('Geolocation (navigator.geolocation)', function () {
- it("should exist", function() {
- expect(navigator.geolocation).toBeDefined();
- });
-
- it("should contain a getCurrentPosition function", function() {
- expect(typeof navigator.geolocation.getCurrentPosition).toBeDefined();
- expect(typeof navigator.geolocation.getCurrentPosition == 'function').toBe(true);
- });
-
- it("should contain a watchPosition function", function() {
- expect(typeof navigator.geolocation.watchPosition).toBeDefined();
- expect(typeof navigator.geolocation.watchPosition == 'function').toBe(true);
- });
-
- it("should contain a clearWatch function", function() {
- expect(typeof navigator.geolocation.clearWatch).toBeDefined();
- expect(typeof navigator.geolocation.clearWatch == 'function').toBe(true);
- });
-
- it("getCurrentPosition success callback should be called with a Position object", function() {
- var win = jasmine.createSpy().andCallFake(function(a) {
- expect(a.coords).not.toBe(null);
- expect(a.timestamp).not.toBe(null);
- }),
- fail = jasmine.createSpy();
-
- runs(function () {
- navigator.geolocation.getCurrentPosition(win, fail, {
- maximumAge:300000 // 5 minutes maximum age of cached position
- });
- });
-
- waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT);
-
- runs(function () {
- expect(fail).not.toHaveBeenCalled();
- });
- });
-
- it("getCurrentPosition success callback should be called with a cached Position", function() {
- var win = jasmine.createSpy().andCallFake(function (a) {
- if (a instanceof Position) {
- expect(a instanceof Position).toBe(true);
- } else {
- expect(a.toString() === '[object Position]').toBe(true);
- }
-
- }),
- fail = jasmine.createSpy();
-
- runs(function () {
- navigator.geolocation.getCurrentPosition(win, fail, {
- maximumAge:300000 // 5 minutes
- });
- });
-
- waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT);
-
- runs(function () {
- expect(fail).not.toHaveBeenCalled();
- });
- });
-
- it("getCurrentPosition error callback should be called if we set timeout to 0 and maximumAge to a very small number", function() {
- var win = jasmine.createSpy(),
- fail = jasmine.createSpy();
-
- runs(function () {
- navigator.geolocation.getCurrentPosition(win, fail, {
- maximumAge: 0,
- timeout: 0
- });
- });
-
- waitsFor(function () { return fail.wasCalled; }, "fail never called", Tests.TEST_TIMEOUT);
-
- runs(function () {
- expect(win).not.toHaveBeenCalled();
- });
- });
-
- // TODO: Need to test error callback... how?
- // You could close your geolocation capability and expect the error code to be 3.(already tested in Win8 Implementation)
- // TODO: Need to test watchPosition success callback, test that makes sure clearPosition works (how to test that a timer is getting cleared?)
- 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();
- });
- });
-});
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0bdb8350/test/window8/media.tests.js
----------------------------------------------------------------------
diff --git a/test/window8/media.tests.js b/test/window8/media.tests.js
deleted file mode 100644
index 1154493..0000000
--- a/test/window8/media.tests.js
+++ /dev/null
@@ -1,137 +0,0 @@
-describe('Media', function () {
- it("should exist", function() {
- expect(Media).toBeDefined();
- expect(typeof Media).toBe("function");
- });
-
- it("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 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("should contain a play function", function() {
- var media1 = new Media();
- expect(media1.play).toBeDefined();
- expect(typeof media1.play).toBe('function');
- media1.release();
- });
-
- it("should contain a stop function", function() {
- var media1 = new Media();
- expect(media1.stop).toBeDefined();
- expect(typeof media1.stop).toBe('function');
- media1.release();
- });
-
- it("should contain a seekTo function", function() {
- var media1 = new Media();
- expect(media1.seekTo).toBeDefined();
- expect(typeof media1.seekTo).toBe('function');
- media1.release();
- });
-
- it("should contain a pause function", function() {
- var media1 = new Media();
- expect(media1.pause).toBeDefined();
- expect(typeof media1.pause).toBe('function');
- media1.release();
- });
-
- it("should contain a getDuration function", function() {
- var media1 = new Media();
- expect(media1.getDuration).toBeDefined();
- expect(typeof media1.getDuration).toBe('function');
- media1.release();
- });
-
- it("should contain a getCurrentPosition function", function() {
- var media1 = new Media();
- expect(media1.getCurrentPosition).toBeDefined();
- expect(typeof media1.getCurrentPosition).toBe('function');
- media1.release();
- });
-
- it("should contain a startRecord function", function() {
- var media1 = new Media();
- expect(media1.startRecord).toBeDefined();
- expect(typeof media1.startRecord).toBe('function');
- media1.release();
- });
-
- it("should contain a stopRecord function", function() {
- var media1 = new Media();
- expect(media1.stopRecord).toBeDefined();
- expect(typeof media1.stopRecord).toBe('function');
- media1.release();
- });
-
- it("should contain a release function", function() {
- var media1 = new Media();
- expect(media1.release).toBeDefined();
- expect(typeof media1.release).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);
- });
-
- 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("position should be set properly", function() {
- var media1 = new Media("http://audio.ibeat.org/content/p1rj1s/p1rj1s_-_rockGuitar.mp3"),
- test = jasmine.createSpy().andCallFake(function(position) {
- console.log("position = " + position);
- expect(position).toBeGreaterThan(0.0);
- media1.stop()
- media1.release();
- });
-
- media1.play();
-
- waits(5000);
-
- runs(function () {
- media1.getCurrentPosition(test, function () {});
- });
-
- waitsFor(function () { return test.wasCalled; }, Tests.TEST_TIMEOUT);
- });
-
- it("duration should be set properly", function() {
- var media1 = new Media("http://audio.ibeat.org/content/p1rj1s/p1rj1s_-_rockGuitar.mp3");
- media1.play();
- waits(5000);
- runs(function () {
- expect(media1.getDuration()).toBeGreaterThan(0.0);
- });
- });
-});
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0bdb8350/test/window8/network.tests.js
----------------------------------------------------------------------
diff --git a/test/window8/network.tests.js b/test/window8/network.tests.js
deleted file mode 100644
index 780097f..0000000
--- a/test/window8/network.tests.js
+++ /dev/null
@@ -1,25 +0,0 @@
-describe('Network (navigator.network)', function () {
- it("should exist", function() {
- expect(navigator.network).toBeDefined();
- });
-
- describe('Network Information API', function () {
- it("connection should exist", function() {
- expect(navigator.network.connection).toBeDefined();
- });
-
- it("should contain connection properties", function() {
- expect(navigator.network.connection.type).toBeDefined();
- });
-
- it("should define constants for connection status", function() {
- expect(Connection.UNKNOWN).toBe("unknown");
- expect(Connection.ETHERNET).toBe("ethernet");
- expect(Connection.WIFI).toBe("wifi");
- expect(Connection.CELL_2G).toBe("2g");
- expect(Connection.CELL_3G).toBe("3g");
- expect(Connection.CELL_4G).toBe("4g");
- expect(Connection.NONE).toBe("none");
- });
- });
-});
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0bdb8350/test/window8/notification.tests.js
----------------------------------------------------------------------
diff --git a/test/window8/notification.tests.js b/test/window8/notification.tests.js
deleted file mode 100644
index 61c795d..0000000
--- a/test/window8/notification.tests.js
+++ /dev/null
@@ -1,20 +0,0 @@
-describe('Notification (navigator.notification)', function () {
- it("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");
- });
-
- it("should contain a beep function", function() {
- expect(typeof navigator.notification.beep).toBeDefined();
- expect(typeof navigator.notification.beep).toBe("function");
- });
-
- it("should contain a alert function", function() {
- expect(typeof navigator.notification.alert).toBeDefined();
- expect(typeof navigator.notification.alert).toBe("function");
- });
-});
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/0bdb8350/test/window8/storage.tests.js
----------------------------------------------------------------------
diff --git a/test/window8/storage.tests.js b/test/window8/storage.tests.js
deleted file mode 100644
index 72ef3a4..0000000
--- a/test/window8/storage.tests.js
+++ /dev/null
@@ -1,405 +0,0 @@
-describe("Session Storage", function () {
- it("should exist", function () {
- expect(window.sessionStorage).toBeDefined();
- expect(typeof window.sessionStorage.length).not.toBe('undefined');
- expect(typeof(window.sessionStorage.key)).toBe('function');
- expect(typeof(window.sessionStorage.getItem)).toBe('function');
- expect(typeof(window.sessionStorage.setItem)).toBe('function');
- expect(typeof(window.sessionStorage.removeItem)).toBe('function');
- expect(typeof(window.sessionStorage.clear)).toBe('function');
- });
-
- it("check length", function () {
- expect(window.sessionStorage.length).toBe(0);
- window.sessionStorage.setItem("key","value");
- expect(window.sessionStorage.length).toBe(1);
- window.sessionStorage.removeItem("key");
- expect(window.sessionStorage.length).toBe(0);
- });
-
- it("check key", function () {
- //expect(window.sessionStorage.key(0)).toBe(null);
- window.sessionStorage.setItem("test","value");
- expect(window.sessionStorage.key(0)).toBe("test");
- window.sessionStorage.removeItem("test");
- //expect(window.sessionStorage.key(0)).toBe(null);
- });
-
- it("check getItem", function() {
- expect(window.sessionStorage.getItem("item")).toBe(null);
- window.sessionStorage.setItem("item","value");
- expect(window.sessionStorage.getItem("item")).toBe("value");
- window.sessionStorage.removeItem("item");
- expect(window.sessionStorage.getItem("item")).toBe(null);
- });
-
- it("check setItem", function() {
- expect(window.sessionStorage.getItem("item")).toBe(null);
- window.sessionStorage.setItem("item","value");
- expect(window.sessionStorage.getItem("item")).toBe("value");
- window.sessionStorage.setItem("item","newval");
- expect(window.sessionStorage.getItem("item")).toBe("newval");
- window.sessionStorage.removeItem("item");
- expect(window.sessionStorage.getItem("item")).toBe(null);
- });
-
- it("can remove an item", function () {
- expect(window.sessionStorage.getItem("item")).toBe(null);
- window.sessionStorage.setItem("item","value");
- expect(window.sessionStorage.getItem("item")).toBe("value");
- window.sessionStorage.removeItem("item");
- expect(window.sessionStorage.getItem("item")).toBe(null);
- });
-
- it("check clear", function() {
- window.sessionStorage.setItem("item1","value");
- window.sessionStorage.setItem("item2","value");
- window.sessionStorage.setItem("item3","value");
- expect(window.sessionStorage.length).toBe(3);
- window.sessionStorage.clear();
- expect(window.sessionStorage.length).toBe(0);
- });
-
- it("check dot notation", function() {
- expect(window.sessionStorage.item).not.toBeDefined();
- window.sessionStorage.item = "value";
- expect(window.sessionStorage.item).toBe("value");
- window.sessionStorage.removeItem("item");
- expect(window.sessionStorage.item).not.toBeDefined();
- });
-
- describe("Local Storage", function () {
- it("should exist", function() {
- expect(window.localStorage).toBeDefined();
- expect(window.localStorage.length).toBeDefined();
- expect(typeof window.localStorage.key).toBe("function");
- expect(typeof window.localStorage.getItem).toBe("function");
- expect(typeof window.localStorage.setItem).toBe("function");
- expect(typeof window.localStorage.removeItem).toBe("function");
- expect(typeof window.localStorage.clear).toBe("function");
- });
-
- it("check length", function() {
- expect(window.localStorage.length).toBe(0);
- window.localStorage.setItem("key","value");
- expect(window.localStorage.length).toBe(1);
- window.localStorage.removeItem("key");
- expect(window.localStorage.length).toBe(0);
- });
-
- it("check key", function () {
-
- //expect(window.localStorage.key(0)).toBe(null);
- window.localStorage.setItem("test", "value");
- //console.log("============" + window.localStorage.key(0));
- expect(window.localStorage.key(0)).toBe("test");
- window.localStorage.removeItem("test");
- //expect(window.localStorage.key(0)).toBe(null);
- });
-
- it("check getItem", function() {
- expect(window.localStorage.getItem("item")).toBe(null);
- window.localStorage.setItem("item","value");
- expect(window.localStorage.getItem("item")).toBe("value");
- window.localStorage.removeItem("item");
- expect(window.localStorage.getItem("item")).toBe(null);
- });
-
- it("check setItem", function() {
- expect(window.localStorage.getItem("item")).toBe(null);
- window.localStorage.setItem("item","value");
- expect(window.localStorage.getItem("item")).toBe("value");
- window.localStorage.setItem("item","newval");
- expect(window.localStorage.getItem("item")).toBe("newval");
- window.localStorage.removeItem("item");
- expect(window.localStorage.getItem("item")).toBe(null);
- });
-
- it("check removeItem", function() {
- expect(window.localStorage.getItem("item")).toBe(null);
- window.localStorage.setItem("item","value");
- expect(window.localStorage.getItem("item")).toBe("value");
- window.localStorage.removeItem("item");
- expect(window.localStorage.getItem("item")).toBe(null);
- });
-
- it("check clear", function() {
- expect(window.localStorage.getItem("item1")).toBe(null);
- expect(window.localStorage.getItem("item2")).toBe(null);
- expect(window.localStorage.getItem("item3")).toBe(null);
- window.localStorage.setItem("item1","value");
- window.localStorage.setItem("item2","value");
- window.localStorage.setItem("item3","value");
- expect(window.localStorage.getItem("item1")).toBe("value");
- expect(window.localStorage.getItem("item2")).toBe("value");
- expect(window.localStorage.getItem("item3")).toBe("value");
- expect(window.localStorage.length).toBe(3);
- window.localStorage.clear();
- expect(window.localStorage.length).toBe(0);
- expect(window.localStorage.getItem("item1")).toBe(null);
- expect(window.localStorage.getItem("item2")).toBe(null);
- expect(window.localStorage.getItem("item3")).toBe(null);
- });
-
- it("check dot notation", function() {
- expect(window.localStorage.item).not.toBeDefined();
- window.localStorage.item = "value";
- expect(window.localStorage.item).toBe("value");
- window.localStorage.removeItem("item");
- expect(window.localStorage.item).not.toBeDefined();
- });
- });
-
- describe("HTML 5 Storage", function () {
-
- it("should exist", function() {
- expect(window.openDatabase);
- });
-
- it("Should open a database", function () {
- var db = openDatabase("Database", "1.0", "HTML5 Database API example", 200000);
- expect(db).toBeDefined();
- });
-
- it("should retrieve a correct database object", function () {
- var db = openDatabase("Database", "1.0", "HTML5 Database API example", 200000);
- expect(db).toBeDefined();
- expect(typeof (db.transaction)).toBe('function');
- //expect(typeof (db.changeVersion)).toBe('function');
- });
-
- it("Should insert data and return SQLResultSet objects", function () {
- function populateDB(tx) {
- tx.executeSql('CREATE TABLE Item (name TEXT, price REAL, id INT PRIMARY KEY)');
- tx.executeSql('INSERT INTO Item (name, price, id) VALUES (?, ?, ?)', ['Apple', 1.2, 1]);
- tx.executeSql('INSERT INTO Item (name, price, id) VALUES (?, ?, ?)', ['Orange', 2.5, 2]);
- tx.executeSql('INSERT INTO Item (name, price, id) VALUES (?, ?, ?)', ['Banana', 3, 3]);
- tx.executeSql('SELECT * FROM Item', null, successCB, errorCB);
- tx.executeSql('DROP TABLE Item');
- }
-
- var errorCB = jasmine.createSpy().andCallFake(function (error) {
- console.log("error callBack , error code:" + error.code);
-
- });
- var successCB = jasmine.createSpy().andCallFake(function (tx, results) {
- expect(tx).toBeDefined();
- expect(results).toBeDefined();
- expect(results.rows.item(0).id).toBe(1);
- expect(results.rows.item(1).id).toBe(2);
- expect(results.rows.item(2).id).toBe(3);
- });
- runs(function () {
- var db = openDatabase("Database", "1.0", "HTML5 Database API example", 200000);
- db.transaction(populateDB, errorCB);
- });
-
- waitsFor(function () { return successCB.wasCalled; }, "Insert callback never called", Tests.TEST_TIMEOUT);
-
- runs(function () {
- expect(successCB).toHaveBeenCalled();
- expect(errorCB).not.toHaveBeenCalled();
- });
- });
-
- it('should return the correct count', function () {
-
- function populateDB(tx) {
- tx.executeSql('CREATE TABLE Item (name TEXT, price REAL, id INT PRIMARY KEY)');
- tx.executeSql('INSERT INTO Item (name, price, id) VALUES (?, ?, ?)', ['Apple', 1.2, 1]);
- tx.executeSql('INSERT INTO Item (name, price, id) VALUES (?, ?, ?)', ['Orange', 2.5, 2]);
- tx.executeSql('INSERT INTO Item (name, price, id) VALUES (?, ?, ?)', ['Banana', 3, 3]);
- tx.executeSql('SELECT COUNT(*) AS count FROM Item', null, successCB, errorCB);
- tx.executeSql('DROP TABLE Item');
- }
- var errorCB = jasmine.createSpy().andCallFake(function (error) {
- console.log("error callBack , error code:" + error.code);
-
- });
- var successCB = jasmine.createSpy().andCallFake(function (tx, results) {
- expect(tx).toBeDefined();
- expect(results).toBeDefined();
- expect(results.rows.item(0).count).toEqual(3);
- });
- runs(function () {
- var db = openDatabase("Database", "1.0", "HTML5 Database API example", 200000);
- db.transaction(populateDB, errorCB);
- });
-
- waitsFor(function () { return successCB.wasCalled; }, "Insert callback never called", Tests.TEST_TIMEOUT);
-
- runs(function () {
- expect(successCB).toHaveBeenCalled();
- expect(errorCB).not.toHaveBeenCalled();
- });
-
- });
-
- it('should return an item by id', function () {
- function populateDB(tx) {
- tx.executeSql('CREATE TABLE Item (name TEXT, price REAL, id INT PRIMARY KEY)');
- tx.executeSql('INSERT INTO Item (name, price, id) VALUES (?, ?, ?)', ['Apple', 1.2, 1]);
- tx.executeSql('INSERT INTO Item (name, price, id) VALUES (?, ?, ?)', ['Orange', 2.5, 2]);
- tx.executeSql('INSERT INTO Item (name, price, id) VALUES (?, ?, ?)', ['Banana', 3, 3]);
- tx.executeSql('SELECT * FROM Item WHERE id = ?', [2], successCB, errorCB);
- tx.executeSql('DROP TABLE Item');
- }
- var errorCB = jasmine.createSpy().andCallFake(function (error) {
- console.log("error callBack , error code:" + error.code);
-
- });
- var successCB = jasmine.createSpy().andCallFake(function (tx, results) {
- expect(tx).toBeDefined();
- expect(results).toBeDefined();
- expect(results.rows.length).toEqual(1);
- expect(results.rows.item(0).name).toEqual('Orange');
- expect(results.rows.item(0).price).toEqual(2.5);
- expect(results.rows.item(0).id).toEqual(2);
- });
- runs(function () {
- var db = openDatabase("Database", "1.0", "HTML5 Database API example", 200000);
- db.transaction(populateDB, errorCB);
- });
-
- waitsFor(function () { return successCB.wasCalled; }, "Insert callback never called", Tests.TEST_TIMEOUT);
-
- runs(function () {
- expect(successCB).toHaveBeenCalled();
- expect(errorCB).not.toHaveBeenCalled();
- });
- });
-
-
- it('should return items with names ending on "e"', function () {
- function populateDB(tx) {
- tx.executeSql('CREATE TABLE Item (name TEXT, price REAL, id INT PRIMARY KEY)');
- tx.executeSql('INSERT INTO Item (name, price, id) VALUES (?, ?, ?)', ['Apple', 1.2, 1]);
- tx.executeSql('INSERT INTO Item (name, price, id) VALUES (?, ?, ?)', ['Orange', 2.5, 2]);
- tx.executeSql('INSERT INTO Item (name, price, id) VALUES (?, ?, ?)', ['Banana', 3, 3]);
- tx.executeSql('SELECT * FROM Item WHERE name LIKE ? ORDER BY id ASC', ['%e'], successCB, errorCB);
- tx.executeSql('DROP TABLE Item');
- }
- var errorCB = jasmine.createSpy().andCallFake(function (error) {
- console.log("error callBack , error code:" + error.code);
-
- });
- var successCB = jasmine.createSpy().andCallFake(function (tx, results) {
- expect(tx).toBeDefined();
- expect(results).toBeDefined();
- expect(results.rows.length).toEqual(2);
- expect(results.rows.item(0).name).toEqual('Apple');
- expect(results.rows.item(1).name).toEqual('Orange');
- expect(results.rows.item(0).id).toEqual(1);
- });
- runs(function () {
- var db = openDatabase("Database", "1.0", "HTML5 Database API example", 200000);
- db.transaction(populateDB, errorCB);
- });
-
- waitsFor(function () { return successCB.wasCalled; }, "Insert callback never called", Tests.TEST_TIMEOUT);
-
- runs(function () {
- expect(successCB).toHaveBeenCalled();
- expect(errorCB).not.toHaveBeenCalled();
- });
-
- });
-
- it('should allow binding null arguments', function () {
- var name = 'Mango';
- function populateDB(tx) {
- tx.executeSql('CREATE TABLE Item (name TEXT, price REAL, id INT PRIMARY KEY)');
- tx.executeSql('INSERT INTO Item (name, price, id) VALUES (?, ?, ?)', [name, null, null]);
- tx.executeSql('SELECT * FROM Item WHERE name = ?', [name], successCB, errorCB);
- tx.executeSql('DROP TABLE Item');
- }
- var errorCB = jasmine.createSpy().andCallFake(function (error) {
- console.log("error callBack , error code:" + error.code);
-
- });
- var successCB = jasmine.createSpy().andCallFake(function (tx, results) {
- expect(tx).toBeDefined();
- expect(results).toBeDefined();
- expect(results.rows.length).toEqual(1);
- expect(results.rows.item(0).name).toEqual(name);
- expect(results.rows.item(0).price).toEqual(null);
- expect(results.rows.item(0).id).toEqual(null);
- });
- runs(function () {
- var db = openDatabase("Database", "1.0", "HTML5 Database API example", 200000);
- db.transaction(populateDB, errorCB);
- });
-
- waitsFor(function () { return successCB.wasCalled; }, "Insert callback never called", Tests.TEST_TIMEOUT);
-
- runs(function () {
- expect(successCB).toHaveBeenCalled();
- expect(errorCB).not.toHaveBeenCalled();
- });
-
- });
-
- it("should error about invalid syntax", function () {
- function populateDB(tx) {
- tx.executeSql('CREATE TABLE11 Item (name TEXT, price REAL, id INT PRIMARY KEY)' , null , successCB , errorCB);
- }
- var successCB = jasmine.createSpy().andCallFake(function (tx, results) {
- expect(tx).toBeDefined();
- expect(results).toBeDefined();
-
- });
-
- var errorCB = jasmine.createSpy().andCallFake(function (error) {
- expect(error).toBeDefined();
- expect(error.code).toBe(5);
- });
-
- runs(function () {
- var db = openDatabase("Database", "1.0", "HTML5 Database API example", 200000);
- db.transaction(populateDB, errorCB);
- });
- waitsFor(function () { return errorCB.wasCalled; }, "error callback never called", Tests.TEST_TIMEOUT);
-
- runs(function () {
- expect(errorCB).toHaveBeenCalled();
- expect(successCB).not.toHaveBeenCalled();
- });
- });
-
-
- it("should error about invalid params", function () {
- function populateDB(tx) {
- tx.executeSql('CREATE TABLE Item (name TEXT, price REAL, id INT PRIMARY KEY)');
- tx.executeSql('INSERT INTO Item (name, price, id) VALUES (?, ?, ?)', ['Apple', 1.2, 1]);
- tx.executeSql('INSERT INTO Item (name, price, id) VALUES (?, ?, ?)', ['Orange', 2.5, 1] , successCB , errorCB);
- tx.executeSql('DROP TABLE Item');
- }
- var successCB = jasmine.createSpy().andCallFake(function (tx, results) {
- expect(tx).toBeDefined();
- expect(results).toBeDefined();
-
- });
-
- var errorCB = jasmine.createSpy().andCallFake(function (error) {
- expect(error).toBeDefined();
- expect(error.code).toBe(5);
- });
- runs(function () {
- var db = openDatabase("Database", "1.0", "HTML5 Database API example", 200000);
- db.transaction(populateDB , errorCB);
- });
-
- waitsFor(function () { return errorCB.wasCalled; }, "error callback never called", Tests.TEST_TIMEOUT);
-
- runs(function () {
- expect(errorCB).toHaveBeenCalled();
- expect(successCB).not.toHaveBeenCalled();
- });
- });
- it('should return null when creating an invalid name', function () {
- var db = openDatabase("invalid::name", "1.0", "HTML5 Database API example", 200000);
- expect(db).toBe(null);
-
- });
- });
-});