Bug 725052 - Tests for inserting passwords. r=rnewman
authorWes Johnston <wjohnston@mozilla.com>
Mon, 12 Mar 2012 10:09:09 -0700
changeset 88798 709d75c8f5aa4a3f5c2cb3237381f711d310cda2
parent 88797 feb9e85cbf911fd1a03f8ebcd8431f49c93812b6
child 88799 e2d129062b2b13e7cd6ef44806c7b7b53ed7ef86
push id7014
push userwjohnston@mozilla.com
push dateMon, 12 Mar 2012 17:11:43 +0000
treeherdermozilla-inbound@709d75c8f5aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs725052
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 725052 - Tests for inserting passwords. r=rnewman
mobile/android/base/tests/robocop.ini
mobile/android/base/tests/testPasswordUndeletion.java.in
--- a/mobile/android/base/tests/robocop.ini
+++ b/mobile/android/base/tests/robocop.ini
@@ -7,13 +7,14 @@
 [test_bug720538]
 # [testFlingCorrectness] # see bug 727351
 [testOverscroll]
 [testAxisLocking]
 [testAboutPage]
 [testWebContentContextMenu]
 [testPasswordProvider]
 [testPasswordEncrypt]
+[testPasswordUndeletion]
 [testFormHistory]
 
 # Used for Talos, please don't use in mochitest
 #[testPan]
 #[testCheck]
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/tests/testPasswordUndeletion.java.in
@@ -0,0 +1,98 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+ 
+#filter substitution
+package @ANDROID_PACKAGE_NAME@.tests;
+
+import @ANDROID_PACKAGE_NAME@.*;
+import android.app.Activity;
+import android.content.ContentValues;
+import android.content.ContentResolver;
+import android.database.Cursor;
+import android.content.Context;
+import android.net.Uri;
+import java.io.File;
+import android.util.Log;
+import java.util.ArrayList;
+import java.lang.reflect.Method;
+
+public class testPasswordUndeletion extends BaseTest {
+    public void testPasswordUndeletion() {
+        setTestType("mochitest");
+        Context context = (Context) getActivity();
+        ContentResolver cr = context.getContentResolver();
+        ContentValues cvs[] = new ContentValues[1];
+        cvs[0] = new ContentValues();
+  
+        Actions.EventExpecter contentEventExpecter = mActions.expectGeckoEvent("Gecko:Ready");
+        contentEventExpecter.blockForEvent();
+  
+        File db = new File(mProfile, "signons.sqlite");
+        String dbPath = db.getPath();
+  
+        Uri passwordUri;
+        Uri deletedPasswordUri;
+        try {
+            ClassLoader classLoader = getActivity().getClassLoader();
+            Class pwds = classLoader.loadClass("org.mozilla.gecko.db.BrowserContract$Passwords");
+            Class deletedpwds = classLoader.loadClass("org.mozilla.gecko.db.BrowserContract$DeletedPasswords");
+            Class nss = classLoader.loadClass("org.mozilla.gecko.NSSBridge");
+            Class contextClass = classLoader.loadClass("android.content.Context");
+            Class stringClass = classLoader.loadClass("java.lang.String");
+            Class appshell = classLoader.loadClass("org.mozilla.gecko.GeckoAppShell");
+  
+            Method ensureNSSLibsLoaded = appshell.getMethod("ensureNSSLibsLoaded", contextClass, stringClass);
+            Method decrypt = nss.getMethod("decrypt", contextClass, stringClass, stringClass);
+            Method encrypt = nss.getMethod("encrypt", contextClass, stringClass, stringClass);
+    
+            cvs[0].put("guid", "MtaVURdK-eRl");
+  
+            // Attempt to insert into the database.
+            deletedPasswordUri = (Uri) deletedpwds.getField("CONTENT_URI").get(null);
+            deletedPasswordUri = deletedPasswordUri.buildUpon().appendQueryParameter("profilePath", mProfile).build();
+            passwordUri = (Uri) pwds.getField("CONTENT_URI").get(null);
+            passwordUri = passwordUri.buildUpon().appendQueryParameter("profilePath", mProfile).build();
+  
+            Uri uri = cr.insert(deletedPasswordUri, cvs[0]);
+            mAsserter.is(uri, null, "Insert returned null correctly");
+    
+            // This should fail the first time round because there is no pw database.
+            // Wait for gecko to reply and then we'll try again.
+            contentEventExpecter = mActions.expectGeckoEvent("Passwords:Init:Return");
+            contentEventExpecter.blockForEvent();
+            cr.insert(deletedPasswordUri, cvs[0]);
+  
+            // Attempting to insert another item with the same guid should
+            // remove the item from deletedPasswords database.
+            cr.insert(passwordUri, cvs[0]);
+            Cursor c = cr.query(deletedPasswordUri, null, null, null, null);
+            SqliteCompare(c, new ContentValues[0]);
+
+            c = cr.query(passwordUri, null, null, null, null);
+            SqliteCompare(c, cvs);
+  
+        } catch(ClassNotFoundException ex) {
+            mAsserter.ok(false, "Error getting class", ex.toString());
+            return;
+        } catch(NoSuchFieldException ex) {
+            mAsserter.ok(false, "Error getting field", ex.toString());
+            return;
+        } catch(IllegalAccessException ex) {
+            mAsserter.ok(false, "Error using field", ex.toString());
+            return;
+        } catch(java.lang.NoSuchMethodException ex) {
+            mAsserter.ok(false, "Error getting method", ex.toString());
+            return;
+        }
+    }
+
+    public void tearDown() throws Exception {
+        super.tearDown();
+  
+        // remove the entire signons.sqlite file
+        File profile = new File(mProfile);
+        File db = new File(profile, "signons.sqlite");
+        db.delete();
+    }
+}