Commit 0b6c1db8 authored by Mei Liang's avatar Mei Liang Committed by Commit Bot

Fix blank page after changing theme

Getting the value of a null IntPropertyKey from a PropertyModel returns
0. This behavior causes the StaticLayout not setting the tab correctly
when the tab id is 0, which leads to the blank page issue. This CL fixes
this issue by initializing the TAB_ID IntPropertyKey to
Tab.INVALID_TAB_ID.

Bug: 1108693
Change-Id: I929b16327c2b7f57e7acd698ed235eadfdc0bbe2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2327187Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Commit-Queue: Mei Liang <meiliang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792864}
parent 0a3e0c97
...@@ -145,6 +145,7 @@ public class StaticLayout extends Layout { ...@@ -145,6 +145,7 @@ public class StaticLayout extends Layout {
}); });
mModel = new PropertyModel.Builder(LayoutTab.ALL_KEYS) mModel = new PropertyModel.Builder(LayoutTab.ALL_KEYS)
.with(LayoutTab.TAB_ID, Tab.INVALID_TAB_ID)
.with(LayoutTab.SCALE, 1.0f) .with(LayoutTab.SCALE, 1.0f)
.with(LayoutTab.X, 0.0f) .with(LayoutTab.X, 0.0f)
.with(LayoutTab.Y, 0.0f) .with(LayoutTab.Y, 0.0f)
......
...@@ -60,7 +60,7 @@ import java.util.LinkedList; ...@@ -60,7 +60,7 @@ import java.util.LinkedList;
@RunWith(BaseRobolectricTestRunner.class) @RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE) @Config(manifest = Config.NONE)
public class StaticLayoutUnitTest { public class StaticLayoutUnitTest {
private static final int TAB1_ID = 456; private static final int TAB1_ID = 0;
private static final int TAB2_ID = 789; private static final int TAB2_ID = 789;
private static final int POSITION1 = 0; private static final int POSITION1 = 0;
private static final int POSITION2 = 1; private static final int POSITION2 = 1;
...@@ -181,6 +181,7 @@ public class StaticLayoutUnitTest { ...@@ -181,6 +181,7 @@ public class StaticLayoutUnitTest {
initAndAssertAllDependencies(); initAndAssertAllDependencies();
mStaticLayout.show(System.currentTimeMillis(), false); mStaticLayout.show(System.currentTimeMillis(), false);
initAndAssertAllProperties();
} }
@After @After
...@@ -208,6 +209,23 @@ public class StaticLayoutUnitTest { ...@@ -208,6 +209,23 @@ public class StaticLayoutUnitTest {
mStaticLayout.getBrowserControlsStateProviderForTesting()); mStaticLayout.getBrowserControlsStateProviderForTesting());
} }
private void initAndAssertAllProperties() {
assertEquals(mTab1, mTabModelSelector.getCurrentTab());
assertEquals(TAB1_ID, mModel.get(LayoutTab.TAB_ID));
assertEquals(WIDTH, mModel.get(LayoutTab.ORIGINAL_CONTENT_WIDTH_IN_DP), 0);
assertEquals(HEIGHT, mModel.get(LayoutTab.ORIGINAL_CONTENT_HEIGHT_IN_DP), 0);
assertEquals(WIDTH, mModel.get(LayoutTab.MAX_CONTENT_WIDTH), 0);
assertEquals(HEIGHT, mModel.get(LayoutTab.MAX_CONTENT_HEIGHT), 0);
assertEquals(BACKGROUND_COLOR, mModel.get(LayoutTab.BACKGROUND_COLOR));
assertEquals(TOOLBAR_BACKGROUND_COLOR, mModel.get(LayoutTab.TOOLBAR_BACKGROUND_COLOR));
assertEquals(TEXT_BOX_ALPHA, mModel.get(LayoutTab.TEXT_BOX_ALPHA), 0);
assertEquals(TEXT_BOX_BACKGROUND_COLOR, mModel.get(LayoutTab.TEXT_BOX_BACKGROUND_COLOR));
assertFalse(mModel.get(LayoutTab.IS_INCOGNITO));
assertFalse(mModel.get(LayoutTab.SHOULD_STALL));
assertTrue(mModel.get(LayoutTab.CAN_USE_LIVE_TEXTURE));
}
private Tab prepareTab(int id, String url) { private Tab prepareTab(int id, String url) {
Tab tab = mock(Tab.class); Tab tab = mock(Tab.class);
doReturn(id).when(tab).getId(); doReturn(id).when(tab).getId();
......
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