Bug 946857 - Part 1: Expose disabled hosts through Password CP r=nalexander

Added a simple robocop test to verify that it is possible to query disabledHosts with PasswordProviders.

MozReview-Commit-ID: K4j4Aczp2xv

--HG--
extra : rebase_source : 284ff094515d674e5e0389b089e3629296231e77
This commit is contained in:
vivek 2015-12-15 19:23:14 +02:00
Родитель c017be875d
Коммит bee345ba8a
3 изменённых файлов: 54 добавлений и 0 удалений

Просмотреть файл

@ -249,6 +249,15 @@ public class BrowserContract {
public static final Uri CONTENT_URI = Uri.withAppendedPath(PASSWORDS_AUTHORITY_URI, "deleted-passwords");
}
@RobocopTarget
public static final class GeckoDisabledHosts {
private GeckoDisabledHosts() {}
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/disabled-hosts";
public static final Uri CONTENT_URI = Uri.withAppendedPath(PASSWORDS_AUTHORITY_URI, "disabled-hosts");
public static final String HOSTNAME = "hostname";
}
public static final class FormHistory {
private FormHistory() {}
public static final Uri CONTENT_URI = Uri.withAppendedPath(FORM_HISTORY_AUTHORITY_URI, "formhistory");

Просмотреть файл

@ -13,6 +13,7 @@ import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.GeckoMessageReceiver;
import org.mozilla.gecko.NSSBridge;
import org.mozilla.gecko.db.BrowserContract.DeletedPasswords;
import org.mozilla.gecko.db.BrowserContract.GeckoDisabledHosts;
import org.mozilla.gecko.db.BrowserContract.Passwords;
import org.mozilla.gecko.mozglue.GeckoLoader;
import org.mozilla.gecko.sqlite.MatrixBlobCursor;
@ -30,11 +31,13 @@ import android.util.Log;
public class PasswordsProvider extends SQLiteBridgeContentProvider {
static final String TABLE_PASSWORDS = "moz_logins";
static final String TABLE_DELETED_PASSWORDS = "moz_deleted_logins";
static final String TABLE_DISABLED_HOSTS = "moz_disabledHosts";
private static final String TELEMETRY_TAG = "SQLITEBRIDGE_PROVIDER_PASSWORDS";
private static final int PASSWORDS = 100;
private static final int DELETED_PASSWORDS = 101;
private static final int DISABLED_HOSTS = 102;
static final String DEFAULT_PASSWORDS_SORT_ORDER = Passwords.HOSTNAME + " ASC";
static final String DEFAULT_DELETED_PASSWORDS_SORT_ORDER = DeletedPasswords.TIME_DELETED + " ASC";
@ -43,6 +46,7 @@ public class PasswordsProvider extends SQLiteBridgeContentProvider {
private static final HashMap<String, String> PASSWORDS_PROJECTION_MAP;
private static final HashMap<String, String> DELETED_PASSWORDS_PROJECTION_MAP;
private static final HashMap<String, String> DISABLED_HOSTS_PROJECTION_MAP;
// this should be kept in sync with the version in toolkit/components/passwordmgr/storage-mozStorage.js
private static final int DB_VERSION = 5;
@ -82,6 +86,11 @@ public class PasswordsProvider extends SQLiteBridgeContentProvider {
DELETED_PASSWORDS_PROJECTION_MAP.put(DeletedPasswords.ID, DeletedPasswords.ID);
DELETED_PASSWORDS_PROJECTION_MAP.put(DeletedPasswords.GUID, DeletedPasswords.GUID);
DELETED_PASSWORDS_PROJECTION_MAP.put(DeletedPasswords.TIME_DELETED, DeletedPasswords.TIME_DELETED);
URI_MATCHER.addURI(BrowserContract.PASSWORDS_AUTHORITY, "disabled-hosts", DISABLED_HOSTS);
DISABLED_HOSTS_PROJECTION_MAP = new HashMap<String, String>();
DISABLED_HOSTS_PROJECTION_MAP.put(GeckoDisabledHosts.HOSTNAME, GeckoDisabledHosts.HOSTNAME);
}
public PasswordsProvider() {
@ -134,6 +143,9 @@ public class PasswordsProvider extends SQLiteBridgeContentProvider {
case DELETED_PASSWORDS:
return DeletedPasswords.CONTENT_TYPE;
case DISABLED_HOSTS:
return GeckoDisabledHosts.CONTENT_TYPE;
default:
throw new UnsupportedOperationException("Unknown type " + uri);
}
@ -149,6 +161,9 @@ public class PasswordsProvider extends SQLiteBridgeContentProvider {
case PASSWORDS:
return TABLE_PASSWORDS;
case DISABLED_HOSTS:
return TABLE_DISABLED_HOSTS;
default:
throw new UnsupportedOperationException("Unknown table " + uri);
}
@ -168,6 +183,9 @@ public class PasswordsProvider extends SQLiteBridgeContentProvider {
case PASSWORDS:
return DEFAULT_PASSWORDS_SORT_ORDER;
case DISABLED_HOSTS:
return null;
default:
throw new UnsupportedOperationException("Unknown URI " + uri);
}
@ -210,6 +228,12 @@ public class PasswordsProvider extends SQLiteBridgeContentProvider {
DBUtils.replaceKey(values, null, Passwords.TIMES_USED, "0");
break;
case DISABLED_HOSTS:
if (!values.containsKey(GeckoDisabledHosts.HOSTNAME)) {
throw new IllegalArgumentException("Must provide a hostname for a disabled host");
}
break;
default:
throw new UnsupportedOperationException("Unknown URI " + uri);
}

Просмотреть файл

@ -6,6 +6,8 @@ package org.mozilla.gecko.tests;
import java.io.File;
import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.db.BrowserContract.GeckoDisabledHosts;
import org.mozilla.gecko.db.BrowserContract.Passwords;
import android.content.ContentResolver;
@ -20,6 +22,8 @@ import android.net.Uri;
* - inserts a password
* - updates a password
* - deletes a password
* - inserts a disabled host
* - queries for disabled host
*/
public class testPasswordProvider extends BaseTest {
private static final String DB_NAME = "signons.sqlite";
@ -65,6 +69,23 @@ public class testPasswordProvider extends BaseTest {
cvs = new ContentValues[0];
c = cr.query(passwordUri, null, null, null, null);
SqliteCompare(c, cvs);
ContentValues values = new ContentValues();
values.put("hostname", "http://www.example.com");
// Attempt to insert into the db.
Uri disabledHostUri = GeckoDisabledHosts.CONTENT_URI;
builder = disabledHostUri.buildUpon();
disabledHostUri = builder.appendQueryParameter("profilePath", mProfile).build();
uri = cr.insert(disabledHostUri, values);
expectedUri = disabledHostUri.buildUpon().appendPath("1").build();
mAsserter.is(uri.toString(), expectedUri.toString(), "Insert returned correct uri");
Cursor cursor = cr.query(disabledHostUri, null, null, null, null);
assertNotNull(cursor);
assertEquals(1, cursor.getCount());
cursor.moveToFirst();
CursorMatches(cursor, values);
}
@Override