|
1 package org.mozilla.gecko.tests; |
|
2 |
|
3 import java.io.File; |
|
4 |
|
5 import org.mozilla.gecko.db.BrowserContract.FormHistory; |
|
6 |
|
7 import android.content.ContentResolver; |
|
8 import android.content.ContentValues; |
|
9 import android.content.Context; |
|
10 import android.net.Uri; |
|
11 |
|
12 /** |
|
13 * A basic form history contentprovider test. |
|
14 * - inserts an element in form history when it is not yet set up |
|
15 * - inserts an element in form history |
|
16 * - updates an element in form history |
|
17 * - deletes an element in form history |
|
18 */ |
|
19 public class testFormHistory extends BaseTest { |
|
20 private static final String DB_NAME = "formhistory.sqlite"; |
|
21 |
|
22 public void testFormHistory() { |
|
23 Context context = (Context)getActivity(); |
|
24 ContentResolver cr = context.getContentResolver(); |
|
25 ContentValues[] cvs = new ContentValues[1]; |
|
26 cvs[0] = new ContentValues(); |
|
27 |
|
28 blockForGeckoReady(); |
|
29 |
|
30 Uri formHistoryUri; |
|
31 Uri insertUri; |
|
32 Uri expectedUri; |
|
33 int numUpdated; |
|
34 int numDeleted; |
|
35 |
|
36 cvs[0].put("fieldname", "fieldname"); |
|
37 cvs[0].put("value", "value"); |
|
38 cvs[0].put("timesUsed", "0"); |
|
39 cvs[0].put("guid", "guid"); |
|
40 |
|
41 // Attempt to insert into the db |
|
42 formHistoryUri = FormHistory.CONTENT_URI; |
|
43 Uri.Builder builder = formHistoryUri.buildUpon(); |
|
44 formHistoryUri = builder.appendQueryParameter("profilePath", mProfile).build(); |
|
45 |
|
46 insertUri = cr.insert(formHistoryUri, cvs[0]); |
|
47 expectedUri = formHistoryUri.buildUpon().appendPath("1").build(); |
|
48 mAsserter.is(expectedUri.toString(), insertUri.toString(), "Insert returned correct uri"); |
|
49 SqliteCompare(DB_NAME, "SELECT * FROM moz_formhistory", cvs); |
|
50 |
|
51 cvs[0].put("fieldname", "fieldname2"); |
|
52 cvs[0].putNull("guid"); |
|
53 |
|
54 numUpdated = cr.update(formHistoryUri, cvs[0], null, null); |
|
55 mAsserter.is(1, numUpdated, "Correct number updated"); |
|
56 SqliteCompare(DB_NAME, "SELECT * FROM moz_formhistory", cvs); |
|
57 |
|
58 numDeleted = cr.delete(formHistoryUri, null, null); |
|
59 mAsserter.is(1, numDeleted, "Correct number deleted"); |
|
60 cvs = new ContentValues[0]; |
|
61 SqliteCompare(DB_NAME, "SELECT * FROM moz_formhistory", cvs); |
|
62 |
|
63 cvs = new ContentValues[1]; |
|
64 cvs[0] = new ContentValues(); |
|
65 cvs[0].put("fieldname", "fieldname"); |
|
66 cvs[0].put("value", "value"); |
|
67 cvs[0].put("timesUsed", "0"); |
|
68 cvs[0].putNull("guid"); |
|
69 |
|
70 insertUri = cr.insert(formHistoryUri, cvs[0]); |
|
71 expectedUri = formHistoryUri.buildUpon().appendPath("1").build(); |
|
72 mAsserter.is(expectedUri.toString(), insertUri.toString(), "Insert returned correct uri"); |
|
73 SqliteCompare(DB_NAME, "SELECT * FROM moz_formhistory", cvs); |
|
74 |
|
75 cvs[0].put("guid", "guid"); |
|
76 |
|
77 numUpdated = cr.update(formHistoryUri, cvs[0], null, null); |
|
78 mAsserter.is(1, numUpdated, "Correct number updated"); |
|
79 SqliteCompare(DB_NAME, "SELECT * FROM moz_formhistory", cvs); |
|
80 |
|
81 numDeleted = cr.delete(formHistoryUri, null, null); |
|
82 mAsserter.is(1, numDeleted, "Correct number deleted"); |
|
83 cvs = new ContentValues[0]; |
|
84 SqliteCompare(DB_NAME, "SELECT * FROM moz_formhistory", cvs); |
|
85 } |
|
86 |
|
87 @Override |
|
88 public void tearDown() throws Exception { |
|
89 // remove the entire signons.sqlite file |
|
90 File profile = new File(mProfile); |
|
91 File db = new File(profile, "formhistory.sqlite"); |
|
92 if (db.delete()) { |
|
93 mAsserter.dumpLog("tearDown deleted "+db.toString()); |
|
94 } else { |
|
95 mAsserter.dumpLog("tearDown did not delete "+db.toString()); |
|
96 } |
|
97 |
|
98 super.tearDown(); |
|
99 } |
|
100 } |