Commit c129ba0f authored by Marcin Wiącek's avatar Marcin Wiącek Committed by Commit Bot

Replace DOM Distiller enums with @IntDef

@IntDef/@StringDef annotation are preferred way for declaring set of String/int values.

1. Patch is migrating FONT_FAMILY and THEME enums to @IntDef generated by java_cpp_enum.py
2. COUNT inside is renamed to NUM_ENTRIES
3. enums in C++ code have prefixes in names (because of NUM_ENTRIES)

BUG=919666

Change-Id: Ie00ea41c0fdbb702192463f63a752cc43bae92c8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1517112
Commit-Queue: Marcin Wiącek <marcin@mwiacek.com>
Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#644531}
parent bb3e3cbe
...@@ -28,7 +28,7 @@ import org.chromium.components.dom_distiller.core.FontFamily; ...@@ -28,7 +28,7 @@ import org.chromium.components.dom_distiller.core.FontFamily;
import org.chromium.components.dom_distiller.core.Theme; import org.chromium.components.dom_distiller.core.Theme;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.EnumMap; import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
...@@ -45,7 +45,7 @@ public class DistilledPagePrefsView extends LinearLayout ...@@ -45,7 +45,7 @@ public class DistilledPagePrefsView extends LinearLayout
private RadioGroup mRadioGroup; private RadioGroup mRadioGroup;
// Buttons for color mode. // Buttons for color mode.
private final Map<Theme, RadioButton> mColorModeButtons; private final Map<Integer /* Theme */, RadioButton> mColorModeButtons;
private final DistilledPagePrefs mDistilledPagePrefs; private final DistilledPagePrefs mDistilledPagePrefs;
...@@ -70,7 +70,7 @@ public class DistilledPagePrefsView extends LinearLayout ...@@ -70,7 +70,7 @@ public class DistilledPagePrefsView extends LinearLayout
super(context, attrs); super(context, attrs);
mDistilledPagePrefs = DomDistillerServiceFactory.getForProfile( mDistilledPagePrefs = DomDistillerServiceFactory.getForProfile(
Profile.getLastUsedProfile()).getDistilledPagePrefs(); Profile.getLastUsedProfile()).getDistilledPagePrefs();
mColorModeButtons = new EnumMap<Theme, RadioButton>(Theme.class); mColorModeButtons = new HashMap<Integer /* Theme */, RadioButton>();
mPercentageFormatter = NumberFormat.getPercentInstance(Locale.getDefault()); mPercentageFormatter = NumberFormat.getPercentInstance(Locale.getDefault());
} }
...@@ -131,10 +131,9 @@ public class DistilledPagePrefsView extends LinearLayout ...@@ -131,10 +131,9 @@ public class DistilledPagePrefsView extends LinearLayout
return overrideTypeFace(view, position); return overrideTypeFace(view, position);
} }
private View overrideTypeFace(View view, int position) { private View overrideTypeFace(View view, @FontFamily int family) {
if (view instanceof TextView) { if (view instanceof TextView) {
TextView textView = (TextView) view; TextView textView = (TextView) view;
FontFamily family = FontFamily.values()[position];
if (family == FontFamily.MONOSPACE) { if (family == FontFamily.MONOSPACE) {
textView.setTypeface(Typeface.MONOSPACE); textView.setTypeface(Typeface.MONOSPACE);
} else if (family == FontFamily.SANS_SERIF) { } else if (family == FontFamily.SANS_SERIF) {
...@@ -149,12 +148,11 @@ public class DistilledPagePrefsView extends LinearLayout ...@@ -149,12 +148,11 @@ public class DistilledPagePrefsView extends LinearLayout
adapter.setDropDownViewResource(R.layout.distilled_page_font_family_spinner); adapter.setDropDownViewResource(R.layout.distilled_page_font_family_spinner);
mFontFamilySpinner.setAdapter(adapter); mFontFamilySpinner.setAdapter(adapter);
mFontFamilySpinner.setSelection(mDistilledPagePrefs.getFontFamily().ordinal()); mFontFamilySpinner.setSelection(mDistilledPagePrefs.getFontFamily());
mFontFamilySpinner.setOnItemSelectedListener(new OnItemSelectedListener() { mFontFamilySpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int family, long id) {
FontFamily family = FontFamily.getFontFamilyForValue(position); if (family >= 0 && family < FontFamily.NUM_ENTRIES) {
if (family != null) {
mDistilledPagePrefs.setFontFamily(family); mDistilledPagePrefs.setFontFamily(family);
} }
} }
...@@ -208,15 +206,15 @@ public class DistilledPagePrefsView extends LinearLayout ...@@ -208,15 +206,15 @@ public class DistilledPagePrefsView extends LinearLayout
// DistilledPagePrefs.Observer // DistilledPagePrefs.Observer
@Override @Override
public void onChangeFontFamily(FontFamily fontFamily) { public void onChangeFontFamily(@FontFamily int fontFamily) {
mFontFamilySpinner.setSelection(fontFamily.ordinal()); mFontFamilySpinner.setSelection(fontFamily);
} }
/** /**
* Changes which button is selected if the theme is changed in another tab. * Changes which button is selected if the theme is changed in another tab.
*/ */
@Override @Override
public void onChangeTheme(Theme theme) { public void onChangeTheme(@Theme int theme) {
mColorModeButtons.get(theme).setChecked(true); mColorModeButtons.get(theme).setChecked(true);
} }
...@@ -249,7 +247,7 @@ public class DistilledPagePrefsView extends LinearLayout ...@@ -249,7 +247,7 @@ public class DistilledPagePrefsView extends LinearLayout
* Initiatializes a Button and selects it if it corresponds to the current * Initiatializes a Button and selects it if it corresponds to the current
* theme. * theme.
*/ */
private RadioButton initializeAndGetButton(int id, final Theme theme) { private RadioButton initializeAndGetButton(int id, final @Theme int theme) {
final RadioButton button = (RadioButton) findViewById(id); final RadioButton button = (RadioButton) findViewById(id);
button.setOnClickListener(new View.OnClickListener() { button.setOnClickListener(new View.OnClickListener() {
@Override @Override
......
...@@ -251,27 +251,27 @@ public class DistilledPagePrefsTest { ...@@ -251,27 +251,27 @@ public class DistilledPagePrefsTest {
} }
private static class TestingObserver implements DistilledPagePrefs.Observer { private static class TestingObserver implements DistilledPagePrefs.Observer {
private FontFamily mFontFamily; private @FontFamily int mFontFamily;
private Theme mTheme; private @Theme int mTheme;
private float mFontScaling; private float mFontScaling;
public TestingObserver() {} public TestingObserver() {}
public FontFamily getFontFamily() { public @FontFamily int getFontFamily() {
return mFontFamily; return mFontFamily;
} }
@Override @Override
public void onChangeFontFamily(FontFamily font) { public void onChangeFontFamily(@FontFamily int font) {
mFontFamily = font; mFontFamily = font;
} }
public Theme getTheme() { public @Theme int getTheme() {
return mTheme; return mTheme;
} }
@Override @Override
public void onChangeTheme(Theme theme) { public void onChangeTheme(@Theme int theme) {
mTheme = theme; mTheme = theme;
} }
...@@ -285,11 +285,11 @@ public class DistilledPagePrefsTest { ...@@ -285,11 +285,11 @@ public class DistilledPagePrefsTest {
} }
} }
private void setFontFamily(final FontFamily font) { private void setFontFamily(final @FontFamily int font) {
TestThreadUtils.runOnUiThreadBlocking(() -> mDistilledPagePrefs.setFontFamily(font)); TestThreadUtils.runOnUiThreadBlocking(() -> mDistilledPagePrefs.setFontFamily(font));
} }
private void setTheme(final Theme theme) { private void setTheme(final @Theme int theme) {
TestThreadUtils.runOnUiThreadBlocking(() -> mDistilledPagePrefs.setTheme(theme)); TestThreadUtils.runOnUiThreadBlocking(() -> mDistilledPagePrefs.setTheme(theme));
} }
......
...@@ -571,7 +571,7 @@ void DomDistillerViewerSourceBrowserTest::PrefTest(bool is_error_page) { ...@@ -571,7 +571,7 @@ void DomDistillerViewerSourceBrowserTest::PrefTest(bool is_error_page) {
browser()->profile())->GetDistilledPagePrefs(); browser()->profile())->GetDistilledPagePrefs();
// Test theme. // Test theme.
distilled_page_prefs->SetTheme(DistilledPagePrefs::DARK); distilled_page_prefs->SetTheme(DistilledPagePrefs::THEME_DARK);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(content::ExecuteScriptAndExtractString( EXPECT_TRUE(content::ExecuteScriptAndExtractString(
contents, kGetBodyClass, &result)); contents, kGetBodyClass, &result));
...@@ -581,7 +581,7 @@ void DomDistillerViewerSourceBrowserTest::PrefTest(bool is_error_page) { ...@@ -581,7 +581,7 @@ void DomDistillerViewerSourceBrowserTest::PrefTest(bool is_error_page) {
EXPECT_EQ(kDarkToolbarThemeColor, contents->GetThemeColor()); EXPECT_EQ(kDarkToolbarThemeColor, contents->GetThemeColor());
// Test font family. // Test font family.
distilled_page_prefs->SetFontFamily(DistilledPagePrefs::SERIF); distilled_page_prefs->SetFontFamily(DistilledPagePrefs::FONT_FAMILY_SERIF);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE( EXPECT_TRUE(
content::ExecuteScriptAndExtractString(contents, kGetBodyClass, &result)); content::ExecuteScriptAndExtractString(contents, kGetBodyClass, &result));
...@@ -624,8 +624,8 @@ IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest, PrefPersist) { ...@@ -624,8 +624,8 @@ IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest, PrefPersist) {
// Set preference. // Set preference.
const double kScale = 1.23; const double kScale = 1.23;
distilled_page_prefs->SetTheme(DistilledPagePrefs::DARK); distilled_page_prefs->SetTheme(DistilledPagePrefs::THEME_DARK);
distilled_page_prefs->SetFontFamily(DistilledPagePrefs::SERIF); distilled_page_prefs->SetFontFamily(DistilledPagePrefs::FONT_FAMILY_SERIF);
distilled_page_prefs->SetFontScaling(kScale); distilled_page_prefs->SetFontScaling(kScale);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
......
...@@ -13,29 +13,12 @@ android_library("dom_distiller_core_java") { ...@@ -13,29 +13,12 @@ android_library("dom_distiller_core_java") {
"java/src/org/chromium/components/dom_distiller/core/DomDistillerUrlUtils.java", "java/src/org/chromium/components/dom_distiller/core/DomDistillerUrlUtils.java",
"java/src/org/chromium/components/dom_distiller/core/DistilledPagePrefs.java", "java/src/org/chromium/components/dom_distiller/core/DistilledPagePrefs.java",
] ]
srcjar_deps = [ ":jni_enums" ]
srcjar_deps = [
":dom_distiller_core_font_family_javagen",
":dom_distiller_core_theme_javagen",
]
}
java_cpp_template("dom_distiller_core_font_family_javagen") {
package_path = "org/chromium/components/dom_distiller/core"
sources = [
"java/src/org/chromium/components/dom_distiller/core/FontFamily.template",
]
inputs = [
"../font_family_list.h",
]
} }
java_cpp_template("dom_distiller_core_theme_javagen") { java_cpp_enum("jni_enums") {
package_path = "org/chromium/components/dom_distiller/core" visibility = [ ":*" ]
sources = [ sources = [
"java/src/org/chromium/components/dom_distiller/core/Theme.template", "//components/dom_distiller/core/distilled_page_prefs.h",
]
inputs = [
"../theme_list.h",
] ]
} }
...@@ -24,8 +24,8 @@ public final class DistilledPagePrefs { ...@@ -24,8 +24,8 @@ public final class DistilledPagePrefs {
* Observer interface for observing DistilledPagePrefs changes. * Observer interface for observing DistilledPagePrefs changes.
*/ */
public interface Observer { public interface Observer {
void onChangeFontFamily(FontFamily font); void onChangeFontFamily(@FontFamily int font);
void onChangeTheme(Theme theme); void onChangeTheme(@Theme int theme);
void onChangeFontScaling(float scaling); void onChangeFontScaling(float scaling);
} }
...@@ -42,14 +42,13 @@ public final class DistilledPagePrefs { ...@@ -42,14 +42,13 @@ public final class DistilledPagePrefs {
} }
@CalledByNative("DistilledPagePrefsObserverWrapper") @CalledByNative("DistilledPagePrefsObserverWrapper")
private void onChangeFontFamily(int fontFamily) { private void onChangeFontFamily(@FontFamily int fontFamily) {
mDistilledPagePrefsObserver.onChangeFontFamily( mDistilledPagePrefsObserver.onChangeFontFamily(fontFamily);
FontFamily.getFontFamilyForValue(fontFamily));
} }
@CalledByNative("DistilledPagePrefsObserverWrapper") @CalledByNative("DistilledPagePrefsObserverWrapper")
private void onChangeTheme(int theme) { private void onChangeTheme(@Theme int theme) {
mDistilledPagePrefsObserver.onChangeTheme(Theme.getThemeForValue(theme)); mDistilledPagePrefsObserver.onChangeTheme(theme);
} }
@CalledByNative("DistilledPagePrefsObserverWrapper") @CalledByNative("DistilledPagePrefsObserverWrapper")
...@@ -103,20 +102,20 @@ public final class DistilledPagePrefs { ...@@ -103,20 +102,20 @@ public final class DistilledPagePrefs {
return true; return true;
} }
public void setFontFamily(FontFamily fontFamily) { public void setFontFamily(@FontFamily int fontFamily) {
nativeSetFontFamily(mDistilledPagePrefsAndroid, fontFamily.asNativeEnum()); nativeSetFontFamily(mDistilledPagePrefsAndroid, fontFamily);
} }
public FontFamily getFontFamily() { public @FontFamily int getFontFamily() {
return FontFamily.getFontFamilyForValue(nativeGetFontFamily(mDistilledPagePrefsAndroid)); return nativeGetFontFamily(mDistilledPagePrefsAndroid);
} }
public void setTheme(Theme theme) { public void setTheme(@Theme int theme) {
nativeSetTheme(mDistilledPagePrefsAndroid, theme.asNativeEnum()); nativeSetTheme(mDistilledPagePrefsAndroid, theme);
} }
public Theme getTheme() { public @Theme int getTheme() {
return Theme.getThemeForValue(nativeGetTheme(mDistilledPagePrefsAndroid)); return nativeGetTheme(mDistilledPagePrefsAndroid);
} }
public void setFontScaling(float scaling) { public void setFontScaling(float scaling) {
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.components.dom_distiller.core;
// An auto-generated enum for Font Family preferences as used by
// org.chromium.components.dom_distiller.core.DistilledPagePrefs and
// the corresponding native class
// dom_distiller::android::DistilledPagePrefsAndroid
public enum FontFamily {
#define DEFINE_FONT_FAMILY(name, value) name(value),
#include "components/dom_distiller/core/font_family_list.h"
#undef DEFINE_FONT_FAMILY
;
private final int mFontFamily;
private FontFamily(int value) {
mFontFamily = value;
}
int asNativeEnum() {
return mFontFamily;
}
public static FontFamily getFontFamilyForValue(int value) {
for (FontFamily fontFamily: FontFamily.values()) {
if (fontFamily.mFontFamily == value) {
return fontFamily;
}
}
return null;
}
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.components.dom_distiller.core;
// An auto-generated enum for Distilled Page Theme preferences as used by
// org.chromium.components.dom_distiller.core.DistilledPagePrefs and
// the corresponding native class
// dom_distiller::android::DistilledPagePrefsAndroid
public enum Theme {
#define DEFINE_THEME(name, value) name(value),
#include "components/dom_distiller/core/theme_list.h"
#undef DEFINE_THEME
;
private final int mValue;
private Theme(int value) {
mValue = value;
}
int asNativeEnum() {
return mValue;
}
static Theme getThemeForValue(int value) {
for (Theme theme: Theme.values()) {
if (theme.mValue == value) {
return theme;
}
}
return null;
}
}
...@@ -27,10 +27,10 @@ DistilledPagePrefs::~DistilledPagePrefs() { ...@@ -27,10 +27,10 @@ DistilledPagePrefs::~DistilledPagePrefs() {
void DistilledPagePrefs::RegisterProfilePrefs( void DistilledPagePrefs::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) { user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterIntegerPref( registry->RegisterIntegerPref(
prefs::kTheme, DistilledPagePrefs::LIGHT, prefs::kTheme, DistilledPagePrefs::THEME_LIGHT,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
registry->RegisterIntegerPref( registry->RegisterIntegerPref(
prefs::kFont, DistilledPagePrefs::SANS_SERIF, prefs::kFont, DistilledPagePrefs::FONT_FAMILY_SANS_SERIF,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
registry->RegisterDoublePref(prefs::kFontScale, 1.0); registry->RegisterDoublePref(prefs::kFontScale, 1.0);
registry->RegisterBooleanPref( registry->RegisterBooleanPref(
...@@ -49,11 +49,12 @@ void DistilledPagePrefs::SetFontFamily( ...@@ -49,11 +49,12 @@ void DistilledPagePrefs::SetFontFamily(
DistilledPagePrefs::FontFamily DistilledPagePrefs::GetFontFamily() { DistilledPagePrefs::FontFamily DistilledPagePrefs::GetFontFamily() {
int font_family = pref_service_->GetInteger(prefs::kFont); int font_family = pref_service_->GetInteger(prefs::kFont);
if (font_family < 0 || font_family >= DistilledPagePrefs::FONT_FAMILY_COUNT) { if (font_family < 0 ||
font_family >= DistilledPagePrefs::FONT_FAMILY_NUM_ENTRIES) {
// Persisted data was incorrect, trying to clean it up by storing the // Persisted data was incorrect, trying to clean it up by storing the
// default. // default.
SetFontFamily(DistilledPagePrefs::SANS_SERIF); SetFontFamily(DistilledPagePrefs::FONT_FAMILY_SANS_SERIF);
return DistilledPagePrefs::SANS_SERIF; return DistilledPagePrefs::FONT_FAMILY_SANS_SERIF;
} }
return static_cast<FontFamily>(font_family); return static_cast<FontFamily>(font_family);
} }
...@@ -67,11 +68,11 @@ void DistilledPagePrefs::SetTheme(DistilledPagePrefs::Theme new_theme) { ...@@ -67,11 +68,11 @@ void DistilledPagePrefs::SetTheme(DistilledPagePrefs::Theme new_theme) {
DistilledPagePrefs::Theme DistilledPagePrefs::GetTheme() { DistilledPagePrefs::Theme DistilledPagePrefs::GetTheme() {
int theme = pref_service_->GetInteger(prefs::kTheme); int theme = pref_service_->GetInteger(prefs::kTheme);
if (theme < 0 || theme >= DistilledPagePrefs::THEME_COUNT) { if (theme < 0 || theme >= DistilledPagePrefs::THEME_NUM_ENTRIES) {
// Persisted data was incorrect, trying to clean it up by storing the // Persisted data was incorrect, trying to clean it up by storing the
// default. // default.
SetTheme(DistilledPagePrefs::LIGHT); SetTheme(DistilledPagePrefs::THEME_LIGHT);
return DistilledPagePrefs::LIGHT; return DistilledPagePrefs::THEME_LIGHT;
} }
return static_cast<Theme>(theme); return static_cast<Theme>(theme);
} }
......
...@@ -21,17 +21,31 @@ namespace dom_distiller { ...@@ -21,17 +21,31 @@ namespace dom_distiller {
class DistilledPagePrefs { class DistilledPagePrefs {
public: public:
// Possible font families for distilled page. // Possible font families for distilled page.
// These must be kept in sync with the resource strings in
// chrome/android/java/res/values/arrays.xml
// Values should start from 0 and can't have gaps.
// A Java counterpart will be generated for this enum.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.components.dom_distiller.core
// GENERATED_JAVA_CLASS_NAME_OVERRIDE: FontFamily
// GENERATED_JAVA_PREFIX_TO_STRIP: FONT_FAMILY_
enum FontFamily { enum FontFamily {
#define DEFINE_FONT_FAMILY(name, value) name = value, FONT_FAMILY_SANS_SERIF = 0,
#include "components/dom_distiller/core/font_family_list.h" FONT_FAMILY_SERIF = 1,
#undef DEFINE_FONT_FAMILY FONT_FAMILY_MONOSPACE = 2,
FONT_FAMILY_NUM_ENTRIES = 3
}; };
// Possible themes for distilled page. // Possible themes for distilled page.
// Values should start from 0 and can't have gaps.
// A Java counterpart will be generated for this enum.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.components.dom_distiller.core
// GENERATED_JAVA_CLASS_NAME_OVERRIDE: Theme
// GENERATED_JAVA_PREFIX_TO_STRIP: THEME_
enum Theme { enum Theme {
#define DEFINE_THEME(name, value) name = value, THEME_LIGHT = 0,
#include "components/dom_distiller/core/theme_list.h" THEME_DARK = 1,
#undef DEFINE_THEME THEME_SEPIA = 2,
THEME_NUM_ENTRIES = 3
}; };
class Observer { class Observer {
......
...@@ -16,8 +16,8 @@ namespace { ...@@ -16,8 +16,8 @@ namespace {
class TestingObserver : public DistilledPagePrefs::Observer { class TestingObserver : public DistilledPagePrefs::Observer {
public: public:
TestingObserver() TestingObserver()
: font_(DistilledPagePrefs::SANS_SERIF), : font_(DistilledPagePrefs::FONT_FAMILY_SANS_SERIF),
theme_(DistilledPagePrefs::LIGHT), theme_(DistilledPagePrefs::THEME_LIGHT),
scaling_(1.0f) {} scaling_(1.0f) {}
void OnChangeFontFamily(DistilledPagePrefs::FontFamily new_font) override { void OnChangeFontFamily(DistilledPagePrefs::FontFamily new_font) override {
...@@ -65,14 +65,15 @@ TEST_F(DistilledPagePrefsTest, TestingOnChangeFontIsBeingCalled) { ...@@ -65,14 +65,15 @@ TEST_F(DistilledPagePrefsTest, TestingOnChangeFontIsBeingCalled) {
TestingObserver obs; TestingObserver obs;
distilled_page_prefs_->AddObserver(&obs); distilled_page_prefs_->AddObserver(&obs);
distilled_page_prefs_->SetFontFamily(DistilledPagePrefs::MONOSPACE); distilled_page_prefs_->SetFontFamily(
EXPECT_EQ(DistilledPagePrefs::SANS_SERIF, obs.GetFontFamily()); DistilledPagePrefs::FONT_FAMILY_MONOSPACE);
EXPECT_EQ(DistilledPagePrefs::FONT_FAMILY_SANS_SERIF, obs.GetFontFamily());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(DistilledPagePrefs::MONOSPACE, obs.GetFontFamily()); EXPECT_EQ(DistilledPagePrefs::FONT_FAMILY_MONOSPACE, obs.GetFontFamily());
distilled_page_prefs_->SetFontFamily(DistilledPagePrefs::SERIF); distilled_page_prefs_->SetFontFamily(DistilledPagePrefs::FONT_FAMILY_SERIF);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(DistilledPagePrefs::SERIF, obs.GetFontFamily()); EXPECT_EQ(DistilledPagePrefs::FONT_FAMILY_SERIF, obs.GetFontFamily());
distilled_page_prefs_->RemoveObserver(&obs); distilled_page_prefs_->RemoveObserver(&obs);
} }
...@@ -82,17 +83,18 @@ TEST_F(DistilledPagePrefsTest, TestingMultipleObserversFont) { ...@@ -82,17 +83,18 @@ TEST_F(DistilledPagePrefsTest, TestingMultipleObserversFont) {
TestingObserver obs2; TestingObserver obs2;
distilled_page_prefs_->AddObserver(&obs2); distilled_page_prefs_->AddObserver(&obs2);
distilled_page_prefs_->SetFontFamily(DistilledPagePrefs::SERIF); distilled_page_prefs_->SetFontFamily(DistilledPagePrefs::FONT_FAMILY_SERIF);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(DistilledPagePrefs::SERIF, obs.GetFontFamily()); EXPECT_EQ(DistilledPagePrefs::FONT_FAMILY_SERIF, obs.GetFontFamily());
EXPECT_EQ(DistilledPagePrefs::SERIF, obs2.GetFontFamily()); EXPECT_EQ(DistilledPagePrefs::FONT_FAMILY_SERIF, obs2.GetFontFamily());
distilled_page_prefs_->RemoveObserver(&obs); distilled_page_prefs_->RemoveObserver(&obs);
distilled_page_prefs_->SetFontFamily(DistilledPagePrefs::MONOSPACE); distilled_page_prefs_->SetFontFamily(
DistilledPagePrefs::FONT_FAMILY_MONOSPACE);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(DistilledPagePrefs::SERIF, obs.GetFontFamily()); EXPECT_EQ(DistilledPagePrefs::FONT_FAMILY_SERIF, obs.GetFontFamily());
EXPECT_EQ(DistilledPagePrefs::MONOSPACE, obs2.GetFontFamily()); EXPECT_EQ(DistilledPagePrefs::FONT_FAMILY_MONOSPACE, obs2.GetFontFamily());
distilled_page_prefs_->RemoveObserver(&obs2); distilled_page_prefs_->RemoveObserver(&obs2);
} }
...@@ -101,14 +103,14 @@ TEST_F(DistilledPagePrefsTest, TestingOnChangeThemeIsBeingCalled) { ...@@ -101,14 +103,14 @@ TEST_F(DistilledPagePrefsTest, TestingOnChangeThemeIsBeingCalled) {
TestingObserver obs; TestingObserver obs;
distilled_page_prefs_->AddObserver(&obs); distilled_page_prefs_->AddObserver(&obs);
distilled_page_prefs_->SetTheme(DistilledPagePrefs::SEPIA); distilled_page_prefs_->SetTheme(DistilledPagePrefs::THEME_SEPIA);
EXPECT_EQ(DistilledPagePrefs::LIGHT, obs.GetTheme()); EXPECT_EQ(DistilledPagePrefs::THEME_LIGHT, obs.GetTheme());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(DistilledPagePrefs::SEPIA, obs.GetTheme()); EXPECT_EQ(DistilledPagePrefs::THEME_SEPIA, obs.GetTheme());
distilled_page_prefs_->SetTheme(DistilledPagePrefs::DARK); distilled_page_prefs_->SetTheme(DistilledPagePrefs::THEME_DARK);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(DistilledPagePrefs::DARK, obs.GetTheme()); EXPECT_EQ(DistilledPagePrefs::THEME_DARK, obs.GetTheme());
distilled_page_prefs_->RemoveObserver(&obs); distilled_page_prefs_->RemoveObserver(&obs);
} }
...@@ -119,17 +121,17 @@ TEST_F(DistilledPagePrefsTest, TestingMultipleObserversTheme) { ...@@ -119,17 +121,17 @@ TEST_F(DistilledPagePrefsTest, TestingMultipleObserversTheme) {
TestingObserver obs2; TestingObserver obs2;
distilled_page_prefs_->AddObserver(&obs2); distilled_page_prefs_->AddObserver(&obs2);
distilled_page_prefs_->SetTheme(DistilledPagePrefs::SEPIA); distilled_page_prefs_->SetTheme(DistilledPagePrefs::THEME_SEPIA);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(DistilledPagePrefs::SEPIA, obs.GetTheme()); EXPECT_EQ(DistilledPagePrefs::THEME_SEPIA, obs.GetTheme());
EXPECT_EQ(DistilledPagePrefs::SEPIA, obs2.GetTheme()); EXPECT_EQ(DistilledPagePrefs::THEME_SEPIA, obs2.GetTheme());
distilled_page_prefs_->RemoveObserver(&obs); distilled_page_prefs_->RemoveObserver(&obs);
distilled_page_prefs_->SetTheme(DistilledPagePrefs::LIGHT); distilled_page_prefs_->SetTheme(DistilledPagePrefs::THEME_LIGHT);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(DistilledPagePrefs::SEPIA, obs.GetTheme()); EXPECT_EQ(DistilledPagePrefs::THEME_SEPIA, obs.GetTheme());
EXPECT_EQ(DistilledPagePrefs::LIGHT, obs2.GetTheme()); EXPECT_EQ(DistilledPagePrefs::THEME_LIGHT, obs2.GetTheme());
distilled_page_prefs_->RemoveObserver(&obs2); distilled_page_prefs_->RemoveObserver(&obs2);
} }
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file intentionally does not have header guards, it's included
// inside a macro to generate enum values.
#ifndef DEFINE_FONT_FAMILY
#error "DEFINE_FONT_FAMILY should be defined before including this file"
#endif
// First argument represents the enum name, second argument represents enum
// value.
// These must be kept in sync with the resource strings in
// chrome/android/java/res/values/arrays.xml
DEFINE_FONT_FAMILY(SANS_SERIF, 0)
DEFINE_FONT_FAMILY(SERIF, 1)
DEFINE_FONT_FAMILY(MONOSPACE, 2)
DEFINE_FONT_FAMILY(FONT_FAMILY_COUNT, 3)
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file intentionally does not have header guards, it's included
// inside a macro to generate enum values.
#ifndef DEFINE_THEME
#error "DEFINE_THEME should be defined before including this file"
#endif
// First argument represents the enum name, second argument represents enum
// value. THEME_COUNT used only by native enum.
DEFINE_THEME(LIGHT, 0)
DEFINE_THEME(DARK, 1)
DEFINE_THEME(SEPIA, 2)
DEFINE_THEME(THEME_COUNT, 3)
...@@ -55,36 +55,36 @@ const char kMonospaceCssClass[] = "monospace"; ...@@ -55,36 +55,36 @@ const char kMonospaceCssClass[] = "monospace";
// Maps themes to JS themes. // Maps themes to JS themes.
const std::string GetJsTheme(DistilledPagePrefs::Theme theme) { const std::string GetJsTheme(DistilledPagePrefs::Theme theme) {
if (theme == DistilledPagePrefs::DARK) if (theme == DistilledPagePrefs::THEME_DARK)
return kDarkJsTheme; return kDarkJsTheme;
if (theme == DistilledPagePrefs::SEPIA) if (theme == DistilledPagePrefs::THEME_SEPIA)
return kSepiaJsTheme; return kSepiaJsTheme;
return kLightJsTheme; return kLightJsTheme;
} }
// Maps themes to CSS classes. // Maps themes to CSS classes.
const std::string GetThemeCssClass(DistilledPagePrefs::Theme theme) { const std::string GetThemeCssClass(DistilledPagePrefs::Theme theme) {
if (theme == DistilledPagePrefs::DARK) if (theme == DistilledPagePrefs::THEME_DARK)
return kDarkCssClass; return kDarkCssClass;
if (theme == DistilledPagePrefs::SEPIA) if (theme == DistilledPagePrefs::THEME_SEPIA)
return kSepiaCssClass; return kSepiaCssClass;
return kLightCssClass; return kLightCssClass;
} }
// Maps font families to JS font families. // Maps font families to JS font families.
const std::string GetJsFontFamily(DistilledPagePrefs::FontFamily font_family) { const std::string GetJsFontFamily(DistilledPagePrefs::FontFamily font_family) {
if (font_family == DistilledPagePrefs::SERIF) if (font_family == DistilledPagePrefs::FONT_FAMILY_SERIF)
return kSerifJsFontFamily; return kSerifJsFontFamily;
if (font_family == DistilledPagePrefs::MONOSPACE) if (font_family == DistilledPagePrefs::FONT_FAMILY_MONOSPACE)
return kMonospaceJsFontFamily; return kMonospaceJsFontFamily;
return kSansSerifJsFontFamily; return kSansSerifJsFontFamily;
} }
// Maps fontFamilies to CSS fontFamily classes. // Maps fontFamilies to CSS fontFamily classes.
const std::string GetFontCssClass(DistilledPagePrefs::FontFamily font_family) { const std::string GetFontCssClass(DistilledPagePrefs::FontFamily font_family) {
if (font_family == DistilledPagePrefs::SERIF) if (font_family == DistilledPagePrefs::FONT_FAMILY_SERIF)
return kSerifCssClass; return kSerifCssClass;
if (font_family == DistilledPagePrefs::MONOSPACE) if (font_family == DistilledPagePrefs::FONT_FAMILY_MONOSPACE)
return kMonospaceCssClass; return kMonospaceCssClass;
return kSansSerifCssClass; return kSansSerifCssClass;
} }
......
...@@ -140,13 +140,13 @@ TEST_F(DomDistillerViewerTest, TestGetDistilledPageThemeJsOutput) { ...@@ -140,13 +140,13 @@ TEST_F(DomDistillerViewerTest, TestGetDistilledPageThemeJsOutput) {
std::string kSepiaJs = "useTheme('sepia');"; std::string kSepiaJs = "useTheme('sepia');";
std::string kLightJs = "useTheme('light');"; std::string kLightJs = "useTheme('light');";
EXPECT_EQ(kDarkJs.compare(viewer::GetDistilledPageThemeJs( EXPECT_EQ(kDarkJs.compare(viewer::GetDistilledPageThemeJs(
DistilledPagePrefs::DARK)), DistilledPagePrefs::THEME_DARK)),
0); 0);
EXPECT_EQ(kLightJs.compare(viewer::GetDistilledPageThemeJs( EXPECT_EQ(kLightJs.compare(viewer::GetDistilledPageThemeJs(
DistilledPagePrefs::LIGHT)), DistilledPagePrefs::THEME_LIGHT)),
0); 0);
EXPECT_EQ(kSepiaJs.compare(viewer::GetDistilledPageThemeJs( EXPECT_EQ(kSepiaJs.compare(viewer::GetDistilledPageThemeJs(
DistilledPagePrefs::SEPIA)), DistilledPagePrefs::THEME_SEPIA)),
0); 0);
} }
...@@ -155,13 +155,13 @@ TEST_F(DomDistillerViewerTest, TestGetDistilledPageFontFamilyJsOutput) { ...@@ -155,13 +155,13 @@ TEST_F(DomDistillerViewerTest, TestGetDistilledPageFontFamilyJsOutput) {
std::string kMonospaceJsFontFamily = "useFontFamily('monospace');"; std::string kMonospaceJsFontFamily = "useFontFamily('monospace');";
std::string kSansSerifJsFontFamily = "useFontFamily('sans-serif');"; std::string kSansSerifJsFontFamily = "useFontFamily('sans-serif');";
EXPECT_EQ(kSerifJsFontFamily.compare(viewer::GetDistilledPageFontFamilyJs( EXPECT_EQ(kSerifJsFontFamily.compare(viewer::GetDistilledPageFontFamilyJs(
DistilledPagePrefs::SERIF)), DistilledPagePrefs::FONT_FAMILY_SERIF)),
0); 0);
EXPECT_EQ(kMonospaceJsFontFamily.compare(viewer::GetDistilledPageFontFamilyJs( EXPECT_EQ(kMonospaceJsFontFamily.compare(viewer::GetDistilledPageFontFamilyJs(
DistilledPagePrefs::MONOSPACE)), DistilledPagePrefs::FONT_FAMILY_MONOSPACE)),
0); 0);
EXPECT_EQ(kSansSerifJsFontFamily.compare(viewer::GetDistilledPageFontFamilyJs( EXPECT_EQ(kSansSerifJsFontFamily.compare(viewer::GetDistilledPageFontFamilyJs(
DistilledPagePrefs::SANS_SERIF)), DistilledPagePrefs::FONT_FAMILY_SANS_SERIF)),
0); 0);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment