Commit 085bbd1a authored by Olivier Robin's avatar Olivier Robin Committed by Commit Bot

Check item in OfflinePageTabHelper::LoadData

Some crash show that item can be nil.

Bug: 942292
Change-Id: I2ab962e02bf09d0224baab62abb2145579a51c8d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1605988
Commit-Queue: Olivier Robin <olivierrobin@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#662130}
parent c4cd49fd
...@@ -116,7 +116,8 @@ void OfflinePageTabHelper::LoadData(int offline_navigation, ...@@ -116,7 +116,8 @@ void OfflinePageTabHelper::LoadData(int offline_navigation,
const GURL& url, const GURL& url,
const std::string& extension, const std::string& extension,
const std::string& data) { const std::string& data) {
if (!web_state_) { if (!web_state_ || !web_state_->GetNavigationManager() ||
!web_state_->GetNavigationManager()->GetLastCommittedItem()) {
// It is possible that the web_state_ has been detached during the page // It is possible that the web_state_ has been detached during the page
// loading. // loading.
return; return;
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "components/reading_list/core/reading_list_model_impl.h" #include "components/reading_list/core/reading_list_model_impl.h"
#include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
#import "ios/web/public/test/fakes/fake_navigation_context.h" #import "ios/web/public/test/fakes/fake_navigation_context.h"
#import "ios/web/public/test/fakes/test_navigation_manager.h"
#import "ios/web/public/test/fakes/test_web_state.h" #import "ios/web/public/test/fakes/test_web_state.h"
#include "ios/web/public/test/web_test.h" #include "ios/web/public/test/web_test.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -153,6 +154,8 @@ class OfflinePageTabHelperTest : public web::WebTest { ...@@ -153,6 +154,8 @@ class OfflinePageTabHelperTest : public web::WebTest {
test_cbs_builder.SetPath(test_data_dir); test_cbs_builder.SetPath(test_data_dir);
chrome_browser_state_ = test_cbs_builder.Build(); chrome_browser_state_ = test_cbs_builder.Build();
test_web_state_.SetBrowserState(chrome_browser_state_.get()); test_web_state_.SetBrowserState(chrome_browser_state_.get());
test_web_state_.SetNavigationManager(
std::make_unique<web::TestNavigationManager>());
reading_list_model_ = std::make_unique<ReadingListModelImpl>( reading_list_model_ = std::make_unique<ReadingListModelImpl>(
/*storage_layer*/ nullptr, /*pref_service*/ nullptr, /*storage_layer*/ nullptr, /*pref_service*/ nullptr,
base::DefaultClock::GetInstance()); base::DefaultClock::GetInstance());
...@@ -180,6 +183,8 @@ class OfflinePageTabHelperDelayedModelTest : public web::WebTest { ...@@ -180,6 +183,8 @@ class OfflinePageTabHelperDelayedModelTest : public web::WebTest {
test_cbs_builder.SetPath(test_data_dir); test_cbs_builder.SetPath(test_data_dir);
chrome_browser_state_ = test_cbs_builder.Build(); chrome_browser_state_ = test_cbs_builder.Build();
test_web_state_.SetBrowserState(chrome_browser_state_.get()); test_web_state_.SetBrowserState(chrome_browser_state_.get());
test_web_state_.SetNavigationManager(
std::make_unique<web::TestNavigationManager>());
fake_reading_list_model_ = std::make_unique<FakeReadingListModel>(); fake_reading_list_model_ = std::make_unique<FakeReadingListModel>();
GURL url(kTestURL); GURL url(kTestURL);
entry_ = std::make_unique<ReadingListEntry>(url, kTestTitle, base::Time()); entry_ = std::make_unique<ReadingListEntry>(url, kTestTitle, base::Time());
...@@ -254,6 +259,10 @@ TEST_F(OfflinePageTabHelperTest, TestLoadReadingListDistilled) { ...@@ -254,6 +259,10 @@ TEST_F(OfflinePageTabHelperTest, TestLoadReadingListDistilled) {
test_web_state_.SetCurrentURL(url); test_web_state_.SetCurrentURL(url);
web::FakeNavigationContext context; web::FakeNavigationContext context;
context.SetHasCommitted(true); context.SetHasCommitted(true);
std::unique_ptr<web::NavigationItem> item = web::NavigationItem::Create();
static_cast<web::TestNavigationManager*>(
test_web_state_.GetNavigationManager())
->SetLastCommittedItem(item.get());
context.SetUrl(url); context.SetUrl(url);
test_web_state_.OnNavigationStarted(&context); test_web_state_.OnNavigationStarted(&context);
test_web_state_.OnNavigationFinished(&context); test_web_state_.OnNavigationFinished(&context);
...@@ -326,6 +335,10 @@ TEST_F(OfflinePageTabHelperDelayedModelTest, TestLateReadingListModelLoading) { ...@@ -326,6 +335,10 @@ TEST_F(OfflinePageTabHelperDelayedModelTest, TestLateReadingListModelLoading) {
web::FakeNavigationContext context; web::FakeNavigationContext context;
context.SetHasCommitted(true); context.SetHasCommitted(true);
std::unique_ptr<web::NavigationItem> item = web::NavigationItem::Create();
static_cast<web::TestNavigationManager*>(
test_web_state_.GetNavigationManager())
->SetLastCommittedItem(item.get());
context.SetUrl(url); context.SetUrl(url);
test_web_state_.OnNavigationStarted(&context); test_web_state_.OnNavigationStarted(&context);
test_web_state_.OnNavigationFinished(&context); test_web_state_.OnNavigationFinished(&context);
......
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