diff options
author | Yvonne Wong <ywong@cyngn.com> | 2015-08-27 12:19:54 -0700 |
---|---|---|
committer | Gerrit Code Review <gerrit@cyanogenmod.org> | 2015-09-25 13:17:19 -0700 |
commit | 05d01294782115b652a0ef28e5cb35ab3a7ad642 (patch) | |
tree | 3c7abc8666e1fd1c17ca68df1c364a81b2e9f651 /tests/src | |
parent | 8fc6affd388f70784e0850ebe4bf8d774389d79c (diff) | |
download | vendor_cmsdk-05d01294782115b652a0ef28e5cb35ab3a7ad642.zip vendor_cmsdk-05d01294782115b652a0ef28e5cb35ab3a7ad642.tar.gz vendor_cmsdk-05d01294782115b652a0ef28e5cb35ab3a7ad642.tar.bz2 |
Add way to migrate CM specific settings to CMSettingsProvider
issue-id: CYNGNOS-829
Change-Id: I08743ebf9ffd3846ae501ed41e396b1556dc41cf
Diffstat (limited to 'tests/src')
-rw-r--r-- | tests/src/org/cyanogenmod/tests/providers/CMSettingsTest.java | 70 |
1 files changed, 64 insertions, 6 deletions
diff --git a/tests/src/org/cyanogenmod/tests/providers/CMSettingsTest.java b/tests/src/org/cyanogenmod/tests/providers/CMSettingsTest.java index d179af8..77299db 100644 --- a/tests/src/org/cyanogenmod/tests/providers/CMSettingsTest.java +++ b/tests/src/org/cyanogenmod/tests/providers/CMSettingsTest.java @@ -17,6 +17,10 @@ package org.cyanogenmod.tests.providers; import android.content.ContentResolver; +import android.database.ContentObserver; +import android.net.Uri; +import android.os.Handler; +import android.os.UserHandle; import android.provider.Settings; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.MediumTest; @@ -24,10 +28,20 @@ import cyanogenmod.providers.CMSettings; public class CMSettingsTest extends AndroidTestCase{ private ContentResolver mContentResolver; + private CMSettingsTestObserver mTestObserver; + + private static boolean sIsOnChangedCalled = false; + private static Uri sExpectedUriChange = null; @Override public void setUp() { mContentResolver = getContext().getContentResolver(); + mTestObserver = new CMSettingsTestObserver(null); + } + + @Override + public void tearDown() { + mContentResolver.unregisterContentObserver(mTestObserver); } @MediumTest @@ -43,6 +57,12 @@ public class CMSettingsTest extends AndroidTestCase{ String actualValue = CMSettings.System.getString(mContentResolver, key); assertEquals(expectedValue, actualValue); + // setup observer + sIsOnChangedCalled = false; + sExpectedUriChange = CMSettings.System.getUriFor(key); + mContentResolver.registerContentObserver(sExpectedUriChange, false, mTestObserver, + UserHandle.USER_ALL); + // replace final String expectedReplaceValue = "systemTestValue2"; isPutSuccessful = CMSettings.System.putString(mContentResolver, key, expectedReplaceValue); @@ -53,9 +73,13 @@ public class CMSettingsTest extends AndroidTestCase{ assertEquals(expectedReplaceValue, actualValue); // delete to clean up - int rowsAffected = mContentResolver.delete(CMSettings.System.CONTENT_URI, Settings.NameValueTable.NAME + " = ?", - new String[]{ key }); + int rowsAffected = mContentResolver.delete(CMSettings.System.CONTENT_URI, + Settings.NameValueTable.NAME + " = ?", new String[]{ key }); assertEquals(1, rowsAffected); + + if (!sIsOnChangedCalled) { + fail("On change was never called or was called with the wrong uri"); + } } @MediumTest @@ -71,6 +95,12 @@ public class CMSettingsTest extends AndroidTestCase{ String actualValue = CMSettings.Secure.getString(mContentResolver, key); assertEquals(expectedValue, actualValue); + // setup observer + sIsOnChangedCalled = false; + sExpectedUriChange = CMSettings.Secure.getUriFor(key); + mContentResolver.registerContentObserver(sExpectedUriChange, false, mTestObserver, + UserHandle.USER_ALL); + // replace final String expectedReplaceValue = "secureTestValue2"; isPutSuccessful = CMSettings.Secure.putString(mContentResolver, key, expectedReplaceValue); @@ -81,9 +111,13 @@ public class CMSettingsTest extends AndroidTestCase{ assertEquals(expectedReplaceValue, actualValue); // delete to clean up - int rowsAffected = mContentResolver.delete(CMSettings.Secure.CONTENT_URI, Settings.NameValueTable.NAME + " = ?", - new String[]{ key }); + int rowsAffected = mContentResolver.delete(CMSettings.Secure.CONTENT_URI, + Settings.NameValueTable.NAME + " = ?", new String[]{ key }); assertEquals(1, rowsAffected); + + if (!sIsOnChangedCalled) { + fail("On change was never called or was called with the wrong uri"); + } } @MediumTest @@ -99,6 +133,12 @@ public class CMSettingsTest extends AndroidTestCase{ String actualValue = CMSettings.Global.getString(mContentResolver, key); assertEquals(expectedValue, actualValue); + // setup observer + sIsOnChangedCalled = false; + sExpectedUriChange = CMSettings.Global.getUriFor(key); + mContentResolver.registerContentObserver(sExpectedUriChange, false, mTestObserver, + UserHandle.USER_OWNER); + // replace final String expectedReplaceValue = "globalTestValue2"; isPutSuccessful = CMSettings.Global.putString(mContentResolver, key, expectedReplaceValue); @@ -109,9 +149,27 @@ public class CMSettingsTest extends AndroidTestCase{ assertEquals(expectedReplaceValue, actualValue); // delete to clean up - int rowsAffected = mContentResolver.delete(CMSettings.Global.CONTENT_URI, Settings.NameValueTable.NAME + " = ?", - new String[]{ key }); + int rowsAffected = mContentResolver.delete(CMSettings.Global.CONTENT_URI, + Settings.NameValueTable.NAME + " = ?", new String[]{ key }); assertEquals(1, rowsAffected); + + if (!sIsOnChangedCalled) { + fail("On change was never called or was called with the wrong uri"); + } + } + + private class CMSettingsTestObserver extends ContentObserver { + + public CMSettingsTestObserver(Handler handler) { + super(handler); + } + + @Override + public void onChange(boolean selfChange, Uri uri) { + if (sExpectedUriChange.equals(uri)) { + sIsOnChangedCalled = true; + } + } } // TODO Add tests for other users |