Bug 441233 Missing focus events in Thunderbird account wizard dialog r=surkov.alexander
[wine-gecko.git] / storage / test / unit / test_storage_service.js
blob01d71d83f27ebd1abe619f0d7d07420f3bbe91ed
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is Storage Test Code.
16 * The Initial Developer of the Original Code is
17 * Mozilla Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 2007
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
22 * Shawn Wilsher <me@shawnwilsher.com> (Original Author)
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 // This file tests the functions of mozIStorageService except for
39 // openUnsharedDatabase, which is tested by test_storage_service_unshared.js.
41 const BACKUP_FILE_NAME = "test_storage.sqlite.backup";
43 function test_openSpecialDatabase_invalid_arg()
45 try {
46 getService().openSpecialDatabase("abcd");
47 do_throw("We should not get here!");
48 } catch (e) {
49 print(e);
50 print("e.result is " + e.result);
51 do_check_eq(Cr.NS_ERROR_INVALID_ARG, e.result);
55 function test_openDatabase_file_DNE()
57 // the file should be created after calling
58 var db = getTestDB();
59 do_check_false(db.exists());
60 getService().openDatabase(db);
61 do_check_true(db.exists());
64 function test_openDatabase_file_exists()
66 // it should already exist from our last test
67 var db = getTestDB();
68 do_check_true(db.exists());
69 getService().openDatabase(db);
70 do_check_true(db.exists());
73 function test_corrupt_db_throws_with_openDatabase()
75 try {
76 getDatabase(getCorruptDB());
77 do_throw("should not be here");
79 catch (e) {
80 do_check_eq(Cr.NS_ERROR_FILE_CORRUPTED, e.result);
84 function test_backup_not_new_filename()
86 const fname = getTestDB().leafName;
88 var backup = getService().backupDatabaseFile(getTestDB(), fname);
89 do_check_neq(fname, backup.leafName);
91 backup.remove(false);
94 function test_backup_new_filename()
96 var backup = getService().backupDatabaseFile(getTestDB(), BACKUP_FILE_NAME);
97 do_check_eq(BACKUP_FILE_NAME, backup.leafName);
99 backup.remove(false);
102 function test_backup_new_folder()
104 var parentDir = getTestDB().parent;
105 parentDir.append("test_storage_temp");
106 if (parentDir.exists())
107 parentDir.remove(true);
108 parentDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0755);
109 do_check_true(parentDir.exists());
111 var backup = getService().backupDatabaseFile(getTestDB(), BACKUP_FILE_NAME,
112 parentDir);
113 do_check_eq(BACKUP_FILE_NAME, backup.leafName);
114 do_check_true(parentDir.equals(backup.parent));
116 parentDir.remove(true);
119 var tests = [
120 test_openSpecialDatabase_invalid_arg,
121 test_openDatabase_file_DNE,
122 test_openDatabase_file_exists,
123 test_corrupt_db_throws_with_openDatabase,
124 test_backup_not_new_filename,
125 test_backup_new_filename,
126 test_backup_new_folder,
129 function run_test()
131 for (var i = 0; i < tests.length; i++)
132 tests[i]();
134 cleanup();