Commit 69356714 authored by David Maunder's avatar David Maunder Committed by Commit Bot

Don't acquire getTitle() if Tab has been destroyed in PseudoTab

Now with fields such as Title being migrated to UserData objects
we enforce that the attribute cannot be acquired after destroy()
has been called. Unfortunately, in PseuoTab getTitle() was called
after destroy() causing the app to crash which is an invalid
assumption. This CL adds an isInitialized() check before the
getTitle() call.

Bug: 1114564
Change-Id: I064ae7d3601d45116cb198885ef64ff42a2aac7d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2346785Reviewed-by: default avatarYusuf Ozuysal <yusufo@chromium.org>
Commit-Queue: David Maunder <davidjm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796431}
parent 237474bb
...@@ -162,7 +162,7 @@ public class PseudoTab { ...@@ -162,7 +162,7 @@ public class PseudoTab {
* @return The title * @return The title
*/ */
public String getTitle() { public String getTitle() {
if (mTab != null && mTab.get() != null) { if (mTab != null && mTab.get() != null && mTab.get().isInitialized()) {
return mTab.get().getTitle(); return mTab.get().getTitle();
} }
assert mTabId != null; assert mTabId != null;
......
...@@ -427,7 +427,7 @@ public class PseudoTabUnitTest { ...@@ -427,7 +427,7 @@ public class PseudoTabUnitTest {
} }
@Test @Test
public void testTabDestroyed() { public void testTabDestroyedRootId() {
Tab tab = new MockTab(TAB4_ID, false); Tab tab = new MockTab(TAB4_ID, false);
PseudoTab pseudoTab = PseudoTab.fromTab(tab); PseudoTab pseudoTab = PseudoTab.fromTab(tab);
tab.destroy(); tab.destroy();
...@@ -436,4 +436,15 @@ public class PseudoTabUnitTest { ...@@ -436,4 +436,15 @@ public class PseudoTabUnitTest {
// UnsupportedOperationException // UnsupportedOperationException
Assert.assertEquals(Tab.INVALID_TAB_ID, pseudoTab.getRootId()); Assert.assertEquals(Tab.INVALID_TAB_ID, pseudoTab.getRootId());
} }
@Test
public void testTabDestroyedTitle() {
Tab tab = new MockTab(TAB4_ID, false);
PseudoTab pseudoTab = PseudoTab.fromTab(tab);
tab.destroy();
// Title was not set. Without the isInitialized() check,
// pseudoTab.getTitle() would crash here with
// UnsupportedOperationException
Assert.assertEquals("", pseudoTab.getTitle());
}
} }
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