Skip to content

Commit

Permalink
[StartTablet] Fix assert error ReturnToChromeUtil.willAddTab.
Browse files Browse the repository at this point in the history
(cherry picked from commit 2aab169)

Bug: 1450004
Change-Id: I736c2a0a4e7ddad6ce93285dcc120577f432d289
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4574994
Commit-Queue: Xi Han <hanxi@chromium.org>
Reviewed-by: Theresa Sullivan <twellington@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1152024}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4589270
Reviewed-by: Calder Kitagawa <ckitagawa@chromium.org>
Cr-Commit-Position: refs/branch-heads/5790@{#358}
Cr-Branched-From: 1d71a33-refs/heads/main@{#1148114}
  • Loading branch information
Xi Han authored and Chromium LUCI CQ committed Jun 5, 2023
1 parent 637e66f commit 0d05c9c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Expand Up @@ -587,11 +587,25 @@ public static Tab createNewTabAndShowHomeSurfaceUi(@NonNull TabCreator tabCreato
TabModelObserver observer = new TabModelObserver() {
@Override
public void willAddTab(Tab tab, int type) {
assert TextUtils.equals(lastActiveTabUrl, tab.getUrl().getSpec())
: "The URL of first Tab restored doesn't match the URL of the last active Tab read from the Tab state metadata file!";
boolean isTabExpected =
TextUtils.equals(lastActiveTabUrl, tab.getUrl().getSpec());
assert isTabExpected
: "The URL of first Tab restored doesn't match the URL of the last active "
+ "Tab read from the Tab state metadata file! Existing Tab count = %d"
+ tabModelSelector.getModel(false).getCount()
+ ".";
if (!isTabExpected) {
return;
}
showHomeSurfaceUiOnNtp(ntpTab, tab, homeSurfaceTracker);
tabModelSelector.getModel(false).removeObserver(this);
}

@Override
public void restoreCompleted() {
// This would be no-op if the observer has been removed in willAddTab().
tabModelSelector.getModel(false).removeObserver(this);
}
};
tabModelSelector.getModel(false).addObserver(observer);
} else {
Expand Down
Expand Up @@ -828,6 +828,7 @@ public void testColdStartupWithOnlyLastActiveTabUrl() {
mTabCreater, mHomeSurfaceTracker, mTabModelSelector, JUnitTestGURLs.URL_1, null);
verify(mCurrentTabModel).addObserver(mTabModelObserverCaptor.capture());

// Verifies if the added Tab matches the tracking URL, call showHomeSurfaceUi().
mTabModelObserverCaptor.getValue().willAddTab(mTab1, TabLaunchType.FROM_RESTORE);
verify(mNewTabPage).showHomeSurfaceUi(eq(mTab1));
verify(mHomeSurfaceTracker).updateHomeSurfaceAndTrackingTabs(eq(mNtpTab), eq(mTab1));
Expand Down

0 comments on commit 0d05c9c

Please sign in to comment.