Commit e70e89be authored by liaoyuke's avatar liaoyuke Committed by Commit bot

Reload with empty navigation manager should not crash

Previously, the app crashes when user tries to reload when navigation
manager is empty.

This CL fixes the issue by adding an earl return to |Reload| in
NavigationManagerImpl so that it does nothing when its empty.

This CL also adds corresponding unit tests to prevent regressions.

BUG=705707

Review-Url: https://codereview.chromium.org/2780703002
Cr-Commit-Position: refs/heads/master@{#460464}
parent a3911c42
......@@ -7,6 +7,7 @@
#include "base/mac/bind_objc_block.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#import "ios/web/public/navigation_manager.h"
#import "ios/web/public/test/web_test_with_web_state.h"
namespace web {
......@@ -74,4 +75,36 @@ TEST_F(WebStateTest, OverridingWebKitObject) {
web_state()->RemoveScriptCommandCallback("test");
}
// Tests that reload with web::ReloadType::NORMAL is no-op when navigation
// manager is empty.
TEST_F(WebStateTest, ReloadWithNormalTypeWithEmptyNavigationManager) {
NavigationManager* navigation_manager = web_state()->GetNavigationManager();
ASSERT_FALSE(navigation_manager->GetTransientItem());
ASSERT_FALSE(navigation_manager->GetPendingItem());
ASSERT_FALSE(navigation_manager->GetLastCommittedItem());
navigation_manager->Reload(web::ReloadType::NORMAL,
false /* check_for_repost */);
ASSERT_FALSE(navigation_manager->GetTransientItem());
ASSERT_FALSE(navigation_manager->GetPendingItem());
ASSERT_FALSE(navigation_manager->GetLastCommittedItem());
}
// Tests that reload with web::ReloadType::ORIGINAL_REQUEST_URL is no-op when
// navigation manager is empty.
TEST_F(WebStateTest, ReloadWithOriginalTypeWithEmptyNavigationManager) {
NavigationManager* navigation_manager = web_state()->GetNavigationManager();
ASSERT_FALSE(navigation_manager->GetTransientItem());
ASSERT_FALSE(navigation_manager->GetPendingItem());
ASSERT_FALSE(navigation_manager->GetLastCommittedItem());
navigation_manager->Reload(web::ReloadType::ORIGINAL_REQUEST_URL,
false /* check_for_repost */);
ASSERT_FALSE(navigation_manager->GetTransientItem());
ASSERT_FALSE(navigation_manager->GetPendingItem());
ASSERT_FALSE(navigation_manager->GetLastCommittedItem());
}
} // namespace web
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