Commit c588f31a authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Fix open new tab nil BrowserState crash.

When closing the last incognito tab, the incognito TabGridMediator's
TabModel is reset to nil as the incognito BrowserState is being
destroyed.  This can occur by tapping the close button and new tab
button at the same time, or simply by tapping the new tab button when
a tab is closed by JavaScript.  Simultaneous button tapping was disabled
by crrev.com/c/1150634.  This CL adds an extra safeguard to prevent the
creation of WebStates with a nil BrowserState.

Bug: 838961
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Iae669290bb9d8079861d488e46cd59495dc809fb
Reviewed-on: https://chromium-review.googlesource.com/1152454Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579102}
parent 447182f7
...@@ -224,6 +224,13 @@ web::WebState* GetWebStateWithId(WebStateList* web_state_list, ...@@ -224,6 +224,13 @@ web::WebState* GetWebStateWithId(WebStateList* web_state_list,
} }
- (void)insertNewItemAtIndex:(NSUInteger)index { - (void)insertNewItemAtIndex:(NSUInteger)index {
// The incognito mediator's TabModel is briefly set to nil after the last
// incognito tab is closed. This occurs because the incognito BrowserState
// needs to be destroyed to correctly clear incognito browsing data. Don't
// attempt to create a new WebState with a nil BrowserState.
if (!self.tabModel)
return;
DCHECK(self.tabModel.browserState); DCHECK(self.tabModel.browserState);
web::WebState::CreateParams params(self.tabModel.browserState); web::WebState::CreateParams params(self.tabModel.browserState);
std::unique_ptr<web::WebState> webState = web::WebState::Create(params); std::unique_ptr<web::WebState> webState = web::WebState::Create(params);
......
...@@ -336,6 +336,17 @@ TEST_F(TabGridMediatorTest, InsertNewItemCommand) { ...@@ -336,6 +336,17 @@ TEST_F(TabGridMediatorTest, InsertNewItemCommand) {
EXPECT_NSEQ(identifier, consumer_.items[0]); EXPECT_NSEQ(identifier, consumer_.items[0]);
} }
// Tests that |-insertNewItemAtIndex:| is a no-op of the mediator's TabModel
// is nil.
TEST_F(TabGridMediatorTest, InsertNewItemWithNoTabModelCommand) {
mediator_.tabModel = nil;
ASSERT_EQ(3, web_state_list_->count());
ASSERT_EQ(1, web_state_list_->active_index());
[mediator_ insertNewItemAtIndex:0];
EXPECT_EQ(3, web_state_list_->count());
EXPECT_EQ(1, web_state_list_->active_index());
}
// Tests that when |-moveItemFromIndex:toIndex:| is called, there is no change // Tests that when |-moveItemFromIndex:toIndex:| is called, there is no change
// in the item count in |web_state_list_|, but that the constituent web states // in the item count in |web_state_list_|, but that the constituent web states
// have been reordered. // have been reordered.
......
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