New issue
Advanced search Search tips

Issue 775044 link

Starred by 1 user

Issue metadata

Status: Duplicate
Merged: issue 776373
Owner: ----
Closed: Nov 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: iOS
Pri: 3
Type: Task

Blocking:
issue 734150



Sign in to add a comment

WebViewKvoTest.CanGoBackForward crashes with WKBasedNavigationManager

Project Member Reported by ajuma@chromium.org, Oct 16 2017

Issue description

There are a few issues here.

The test fails the EXPECTs on line 64 and 65, so the back_observer and forward_observer aren't working as expected:
../../ios/web_view/test/web_view_kvo_inttest.mm:64: Failure
Value of: [back_observer.lastValue boolValue]
  Actual: true
Expected: false
../../ios/web_view/test/web_view_kvo_inttest.mm:65: Failure
Value of: [forward_observer.lastValue boolValue]
  Actual: false
Expected: true

Then the test crashes while navigating forward to page 2 because NavigationManagerImpl::GoToIndex is called on index 2 when the number of items is 2.

Index 2 is computed by WKBasedNavigationManagerImpl::GetIndexForOffset, so the bug is either in this computation, or that we're missing an item.

Crash stack:
[1016/110034.255775:FATAL:navigation_manager_impl.mm(165)] Check failed: false.
0   ChromeWebView                       0x000000010d83411d base::debug::StackTrace::StackTrace(unsigned long) + 157
1   ChromeWebView                       0x000000010d83415d base::debug::StackTrace::StackTrace(unsigned long) + 29
2   ChromeWebView                       0x000000010d83267c base::debug::StackTrace::StackTrace() + 28
3   ChromeWebView                       0x000000010d8916af logging::LogMessage::~LogMessage() + 479
4   ChromeWebView                       0x000000010d88f205 logging::LogMessage::~LogMessage() + 21
5   ChromeWebView                       0x000000010d3b098f web::NavigationManagerImpl::GoToIndex(int) + 255
6   ChromeWebView                       0x000000010d3bccf0 web::WKBasedNavigationManagerImpl::GoForward() + 48
7   ChromeWebView                       0x000000010d51079a -[CWVWebView goForward] + 138
8   ios_web_view_inttests               0x0000000108b98b6f ios_web_view::WebViewKvoTest_CanGoBackForward_Test::TestBody() + 11807

 

Comment 1 by ajuma@chromium.org, Oct 16 2017

Cc: danyao@chromium.org
Debugging some more, the problem seems to be that the call to goBack on line 62 isn't actually going back, so there's nothing to go forward to in the call to goForward.

In the call to goBack, we start with WKCurrentItemIndex 1 and pending_item_index_ -1, and we call goToIndex(0). That leads to FinishGoToIndex(0), which calls goToBackForwardListItem on WKWebView. But after that call, WKCurrentItemIndex is still 1.

Is the expected behavior of goToBackForardListItem that it changes WKCurrentItemIndex synchronously? If so, the bug is that it isn't changing, and otherwise the bug is that the test is expecting it to change right away.

Comment 2 by ajuma@chromium.org, Oct 16 2017

And trying to understand the test some more, it does wait for loading to become false on the WKWebView after calling goBack, but it's false immediately.

Comment 3 by danyao@chromium.org, Oct 16 2017

Thanks for debugging! I don't think goToBackForwardListItem changes WKCurrentItemIndex synchronously because it's sending an IPC to the WebCore process.

Comment 4 by ajuma@chromium.org, Oct 16 2017

Correcting what I said in Comment 2, the test is waiting for loading to become false CWVWebView, not on WKWebView. It's false on CWVWebView, but isLoading is *true* on WKWebView. So CWVWebView's webStateDidStartLoading method might not be getting called as expected.

Comment 5 by ajuma@chromium.org, Oct 18 2017

webStateDidStartLoading would normally (in the legacy code path) get called during WebStateImpl::LoadCurrentItem which happens in LegacyNavigationManagerImpl::FinishGoToIndex (see the full call stack below). But WKBasedNavigationManagerImpl::FinishGoToIndex skips this logic by navigating using WKWebView's goToBackForwardListItem.

One approach to deal with this would be to do KVO on WKWebView's isLoading to keep CWVWebView's loading up-to-date, but KVO on isLoading is explicitly turned off for the new navigation manager here: 
https://cs.chromium.org/chromium/src/ios/web/web_state/ui/crw_web_controller.mm?rcl=737ab6731d14c91ffb665e837425c8ec98c7be10&l=1044

Another approach would be to directly expose WKWebView's isLoading and have the test wait on that when the new navigation manager is enabled.

Here's the call stack for webStateDidStartLoading get called by the old navigation manager:
  * frame #0: 0x0000000114d62684 ChromeWebView`::-[CWVWebView webStateDidStartLoading:](self=0x00007fb399e0ab70, _cmd="webStateDidStartLoading:", webState=0x00007fb399d3ffc0) at cwv_web_view.mm:264
    frame #1: 0x0000000114d05afb ChromeWebView`web::WebStateObserverBridge::DidStartLoading(this=0x000060000003d2e0) at web_state_observer_bridge.mm:67
    frame #2: 0x0000000114ceef6a ChromeWebView`web::WebStateImpl::SetIsLoading(this=0x00007fb399d3ffc0, is_loading=true) at web_state_impl.mm:225
    frame #3: 0x0000000114c895e4 ChromeWebView`::-[CRWWebController registerLoadRequestForURL:referrer:transition:sameDocumentNavigation:](self=0x00007fb399e08120, _cmd="registerLoadRequestForURL:referrer:transition:sameDocumentNavigation:", requestURL=0x00007fff500d0540, referrer=0x00007fff500d07b8, transition=16777217, sameDocumentNavigation=NO) at crw_web_controller.mm:1476
    frame #4: 0x0000000114cba960 ChromeWebView`::__55-[CRWWebController loadRequestForCurrentNavigationItem]_block_invoke.1137(.block_descriptor=<unavailable>) at crw_web_controller.mm:5178
    frame #5: 0x0000000114cb9977 ChromeWebView`::-[CRWWebController loadRequestForCurrentNavigationItem](self=0x00007fb399e08120, _cmd="loadRequestForCurrentNavigationItem") at crw_web_controller.mm:5203
    frame #6: 0x0000000114c8af2a ChromeWebView`::-[CRWWebController loadCurrentURLInWebView](self=0x00007fb399e08120, _cmd="loadCurrentURLInWebView") at crw_web_controller.mm:1619
    frame #7: 0x0000000114c8e04f ChromeWebView`::-[CRWWebController loadCurrentURL](self=0x00007fb399e08120, _cmd="loadCurrentURL") at crw_web_controller.mm:1868
    frame #8: 0x0000000114cf6bde ChromeWebView`web::WebStateImpl::LoadCurrentItem(this=0x00007fb399d3ffc0) at web_state_impl.mm:775
    frame #9: 0x0000000114bf83bd ChromeWebView`web::LegacyNavigationManagerImpl::FinishGoToIndex(this=0x0000600000272a00, index=0) at legacy_navigation_manager_impl.mm:320
    frame #10: 0x0000000114c017b9 ChromeWebView`web::NavigationManagerImpl::GoToIndex(this=0x0000600000272a00, index=0) at navigation_manager_impl.mm:191
    frame #11: 0x0000000114bf6c10 ChromeWebView`web::LegacyNavigationManagerImpl::GoBack(this=0x0000600000272a00) at legacy_navigation_manager_impl.mm:200
    frame #12: 0x0000000114d614fa ChromeWebView`::-[CWVWebView goBack](self=0x00007fb399e0ab70, _cmd="goBack") at cwv_web_view.mm:162

Comment 6 by danyao@chromium.org, Oct 24 2017

 Issue 775069  has been merged into this issue.

Comment 7 by danyao@chromium.org, Oct 24 2017

 Issue 775076  has been merged into this issue.

Comment 8 by danyao@chromium.org, Nov 10 2017

Mergedinto: 776077
Status: Duplicate (was: Available)

Comment 9 by danyao@chromium.org, Nov 10 2017

Mergedinto: -776077 776373
Actually, this is a duplicate of  crbug.com/776373 .
Verified that this test now passes after crrev.com/c/762176.
Actually, this is a duplicate of  crbug.com/776373 .
Verified that this test now passes after crrev.com/c/762176.

Comment 11 Deleted

Sign in to add a comment