Commit 9502a4f8 authored by David Maunder's avatar David Maunder Committed by Commit Bot

Handle uninitialized Tabs in getDomain()

We now do not allow Tab attributes to be acquired on an
uninitialized Tab. We are finding tabs passed to getDomain()
are uninitialized so we should handle this.

Bug: 1116341
Change-Id: I69510196bf47b2b4939450905552a30ccb536d4f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2358050
Commit-Queue: David Maunder <davidjm@chromium.org>
Reviewed-by: default avatarMei Liang <meiliang@chromium.org>
Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798514}
parent 1d69f2c4
......@@ -1332,7 +1332,13 @@ class TabListMediator {
return TextUtils.join(", ", domainNames);
}
private String getDomain(Tab tab) {
@VisibleForTesting
protected static String getDomain(Tab tab) {
// TODO(crbug.com/1116613) Investigate how uninitialized Tabs are appearing
// here.
if (!tab.isInitialized()) {
return "";
}
String domain = UrlUtilities.getDomainAndRegistry(tab.getUrlString(), false);
if (domain.isEmpty()) return tab.getUrlString();
......
......@@ -86,6 +86,7 @@ import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.multiwindow.MultiWindowUtils;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.search_engines.TemplateUrlServiceFactory;
import org.chromium.chrome.browser.tab.MockTab;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabCreationState;
import org.chromium.chrome.browser.tab.TabImpl;
......@@ -2189,6 +2190,13 @@ public class TabListMediatorUnitTest {
mCallbackCaptor.getValue().onResult(mFaviconDrawable);
}
@Test
public void testGetDomainOnDestroyedTab() {
Tab tab = new MockTab(TAB1_ID, false);
tab.destroy();
assertEquals("", TabListMediator.getDomain(tab));
}
private void initAndAssertAllProperties() {
List<Tab> tabs = new ArrayList<>();
for (int i = 0; i < mTabModel.getCount(); i++) {
......
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