Commit 449262de authored by Danyao Wang's avatar Danyao Wang Committed by Commit Bot

[Nav Experiment] Fix NativeContent unit test to wait after load.

With WKBasedNavigationManager, native URLs are loaded asynchronously.
Added WebStateObserver to wait for load to finish before asserting in
tests.

Bug: 776467
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I2d0da5770ea09988a57e9af3e3561d1dc5bd3ebf
Reviewed-on: https://chromium-review.googlesource.com/740370
Commit-Queue: Danyao Wang <danyao@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#512519}
parent ebe366eb
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#import "base/test/ios/wait_util.h" #import "base/test/ios/wait_util.h"
#import "ios/testing/ocmock_complex_type_helper.h" #import "ios/testing/ocmock_complex_type_helper.h"
#import "ios/testing/wait_util.h"
#import "ios/web/navigation/crw_session_controller.h" #import "ios/web/navigation/crw_session_controller.h"
#import "ios/web/navigation/navigation_item_impl.h" #import "ios/web/navigation/navigation_item_impl.h"
#import "ios/web/navigation/navigation_manager_impl.h" #import "ios/web/navigation/navigation_manager_impl.h"
...@@ -645,6 +646,7 @@ class CRWWebControllerNativeContentTest : public WebTestWithWebController { ...@@ -645,6 +646,7 @@ class CRWWebControllerNativeContentTest : public WebTestWithWebController {
} }
void Load(const GURL& URL) { void Load(const GURL& URL) {
TestWebStateObserver observer(web_state());
NavigationManagerImpl& navigation_manager = NavigationManagerImpl& navigation_manager =
[web_controller() webStateImpl]->GetNavigationManagerImpl(); [web_controller() webStateImpl]->GetNavigationManagerImpl();
navigation_manager.AddPendingItem( navigation_manager.AddPendingItem(
...@@ -652,6 +654,16 @@ class CRWWebControllerNativeContentTest : public WebTestWithWebController { ...@@ -652,6 +654,16 @@ class CRWWebControllerNativeContentTest : public WebTestWithWebController {
NavigationInitiationType::USER_INITIATED, NavigationInitiationType::USER_INITIATED,
NavigationManager::UserAgentOverrideOption::INHERIT); NavigationManager::UserAgentOverrideOption::INHERIT);
[web_controller() loadCurrentURL]; [web_controller() loadCurrentURL];
// Native URL is loaded asynchronously with WKBasedNavigationManager. Wait
// for navigation to finish before asserting.
if (GetWebClient()->IsSlimNavigationManagerEnabled()) {
TestWebStateObserver* observer_ptr = &observer;
ASSERT_TRUE(testing::WaitUntilConditionOrTimeout(
testing::kWaitForPageLoadTimeout, ^{
return observer_ptr->did_finish_navigation_info() != nullptr;
}));
}
} }
TestNativeContentProvider* mock_native_provider_; TestNativeContentProvider* mock_native_provider_;
......
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