Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4563)

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/dom_distiller/DistilledPagePrefsTest.java

Issue 403323005: Observer Support for DistilledPagePrefs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changed observerMap type from HashMap to Map Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/javatests/src/org/chromium/chrome/browser/dom_distiller/DistilledPagePrefsTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/dom_distiller/DistilledPagePrefsTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/dom_distiller/DistilledPagePrefsTest.java
index 60e87b154f6646cd6d780cdbaf3964edb601ef90..cf39057a5c7a11356aad0bd2eb3b8f759c22c1d7 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/dom_distiller/DistilledPagePrefsTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/dom_distiller/DistilledPagePrefsTest.java
@@ -7,36 +7,110 @@ package org.chromium.chrome.browser.dom_distiller;
import android.test.suitebuilder.annotation.SmallTest;
import android.test.UiThreadTest;
+import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.shell.ChromeShellTestBase;
import org.chromium.components.dom_distiller.core.DistilledPagePrefs;
import org.chromium.components.dom_distiller.core.DomDistillerService;
import org.chromium.components.dom_distiller.core.Theme;
+import org.chromium.content.browser.test.util.UiUtils;
/**
* Test class for {@link DistilledPagePrefs}.
*/
public class DistilledPagePrefsTest extends ChromeShellTestBase {
+ private DistilledPagePrefs mDistilledPagePrefs;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ startChromeBrowserProcessSync(getInstrumentation().getTargetContext());
+ getDistilledPagePrefs();
+ }
+
+ private void getDistilledPagePrefs() {
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ public void run() {
+ DomDistillerService domDistillerService = DomDistillerServiceFactory.
+ getForProfile(Profile.getLastUsedProfile());
+ mDistilledPagePrefs = domDistillerService.getDistilledPagePrefs();
+ }
+ });
+ }
+
@SmallTest
@UiThreadTest
@Feature({"DomDistiller"})
public void testGetAndSetPrefs() throws InterruptedException {
- startChromeBrowserProcessSync(getInstrumentation().getTargetContext());
- DomDistillerService service = DomDistillerServiceFactory.
- getForProfile(Profile.getLastUsedProfile());
- assertNotNull(service);
- DistilledPagePrefs distilledPagePrefs = service.getDistilledPagePrefs();
- assertNotNull(distilledPagePrefs);
- // Check default theme.
- assertEquals(distilledPagePrefs.getTheme(), Theme.LIGHT);
+ // Check the default theme.
+ assertEquals(mDistilledPagePrefs.getTheme(), Theme.LIGHT);
// Check that theme can be correctly set.
- distilledPagePrefs.setTheme(Theme.DARK);
- assertEquals(Theme.DARK, distilledPagePrefs.getTheme());
- distilledPagePrefs.setTheme(Theme.LIGHT);
- assertEquals(Theme.LIGHT, distilledPagePrefs.getTheme());
- distilledPagePrefs.setTheme(Theme.SEPIA);
- assertEquals(Theme.SEPIA, distilledPagePrefs.getTheme());
+ mDistilledPagePrefs.setTheme(Theme.DARK);
+ assertEquals(Theme.DARK, mDistilledPagePrefs.getTheme());
+ mDistilledPagePrefs.setTheme(Theme.LIGHT);
+ assertEquals(Theme.LIGHT, mDistilledPagePrefs.getTheme());
+ mDistilledPagePrefs.setTheme(Theme.SEPIA);
+ assertEquals(Theme.SEPIA, mDistilledPagePrefs.getTheme());
+ }
+
+ @SmallTest
+ @Feature({"DomDistiller"})
+ public void testSingleObserver() throws InterruptedException {
+ TestingObserver testObserver = new TestingObserver();
+ mDistilledPagePrefs.addObserver(testObserver);
+
+ setTheme(Theme.DARK);
+ // Assumes that callback does not occur immediately.
+ assertNull(testObserver.getTheme());
+ UiUtils.settleDownUI(getInstrumentation());
+ // Check that testObserver's theme has been updated,
+ assertEquals(Theme.DARK, testObserver.getTheme());
+ mDistilledPagePrefs.removeObserver(testObserver);
+ }
+
+ @SmallTest
+ @Feature({"DomDistiller"})
+ public void testMultipleObservers() throws InterruptedException {
+ TestingObserver testObserverOne = new TestingObserver();
+ mDistilledPagePrefs.addObserver(testObserverOne);
+ TestingObserver testObserverTwo = new TestingObserver();
+ mDistilledPagePrefs.addObserver(testObserverTwo);
+
+ setTheme(Theme.SEPIA);
+ UiUtils.settleDownUI(getInstrumentation());
+ assertEquals(Theme.SEPIA, testObserverOne.getTheme());
+ assertEquals(Theme.SEPIA, testObserverTwo.getTheme());
+ mDistilledPagePrefs.removeObserver(testObserverOne);
+
+ setTheme(Theme.DARK);
+ UiUtils.settleDownUI(getInstrumentation());
+ // Check that testObserverOne's theme is not changed but testObserverTwo's is.
+ assertEquals(Theme.SEPIA, testObserverOne.getTheme());
+ assertEquals(Theme.DARK, testObserverTwo.getTheme());
+ mDistilledPagePrefs.removeObserver(testObserverTwo);
+ }
+
+ private static class TestingObserver implements DistilledPagePrefs.Observer {
+ private Theme mTheme;
+
+ public TestingObserver() {}
+
+ public Theme getTheme() {
+ return mTheme;
+ }
+
+ public void onChangeTheme(Theme theme) {
+ mTheme = theme;
+ }
+ }
+
+ private void setTheme(final Theme theme) {
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ public void run() {
+ mDistilledPagePrefs.setTheme(theme);
+ }
+ });
}
}

Powered by Google App Engine
This is Rietveld 408576698