[iOS] Cleanup after using WK loading

This CL removes the code that was doing the switch for the feature to
use the WKWebView loading property.
The property is enabled to 100%.

Bug: 1006012,767092
Change-Id: Id4a4ca3ad18b24cb97e79c32aece943470d9d0a5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2074641
Auto-Submit: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: Eugene But <eugenebut@chromium.org>
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744967}
diff --git a/ios/chrome/browser/flags/about_flags.mm b/ios/chrome/browser/flags/about_flags.mm
index 6035c91..f3d526a 100644
--- a/ios/chrome/browser/flags/about_flags.mm
+++ b/ios/chrome/browser/flags/about_flags.mm
@@ -538,9 +538,6 @@
      flag_descriptions::kTranslateInfobarMessagesUIName,
      flag_descriptions::kTranslateInfobarMessagesUIDescription,
      flags_ui::kOsIos, FEATURE_VALUE_TYPE(kTranslateInfobarMessagesUI)},
-    {"use-WKWebView-loading", flag_descriptions::kUseWKWebViewLoadingName,
-     flag_descriptions::kUseWKWebViewLoadingDescription, flags_ui::kOsIos,
-     FEATURE_VALUE_TYPE(web::features::kUseWKWebViewLoading)},
     {"autofill-save-card-dismiss-on-navigation",
      flag_descriptions::kAutofillSaveCardDismissOnNavigationName,
      flag_descriptions::kAutofillSaveCardDismissOnNavigationDescription,
diff --git a/ios/chrome/browser/flags/ios_chrome_flag_descriptions.cc b/ios/chrome/browser/flags/ios_chrome_flag_descriptions.cc
index cb14813..0551584 100644
--- a/ios/chrome/browser/flags/ios_chrome_flag_descriptions.cc
+++ b/ios/chrome/browser/flags/ios_chrome_flag_descriptions.cc
@@ -398,11 +398,6 @@
 const char kUseDdljsonApiDescription[] =
     "Enables the new ddljson API to fetch Doodles for the NTP.";
 
-const char kUseWKWebViewLoadingName[] =
-    "Use WKWebView.loading for WebState::IsLoading";
-const char kUseWKWebViewLoadingDescription[] =
-    "Enables using WKWebView.loading for WebState::IsLoading";
-
 const char kWalletServiceUseSandboxName[] = "Use Google Payments sandbox";
 const char kWalletServiceUseSandboxDescription[] =
     "Uses the sandbox service for Google Payments API calls.";
diff --git a/ios/chrome/browser/flags/ios_chrome_flag_descriptions.h b/ios/chrome/browser/flags/ios_chrome_flag_descriptions.h
index 5edd916..ddef0bd 100644
--- a/ios/chrome/browser/flags/ios_chrome_flag_descriptions.h
+++ b/ios/chrome/browser/flags/ios_chrome_flag_descriptions.h
@@ -349,11 +349,6 @@
 extern const char kUseDdljsonApiName[];
 extern const char kUseDdljsonApiDescription[];
 
-// Title and description for the flag to enable using WKWebView.loading for
-// WebState::IsLoading.
-extern const char kUseWKWebViewLoadingName[];
-extern const char kUseWKWebViewLoadingDescription[];
-
 // Title and description for the flag to control if Google Payments API calls
 // should use the sandbox servers.
 extern const char kWalletServiceUseSandboxName[];
diff --git a/ios/chrome/browser/ui/tab_grid/tab_grid_mediator_unittest.mm b/ios/chrome/browser/ui/tab_grid/tab_grid_mediator_unittest.mm
index 40500fe..9ecf6e9 100644
--- a/ios/chrome/browser/ui/tab_grid/tab_grid_mediator_unittest.mm
+++ b/ios/chrome/browser/ui/tab_grid/tab_grid_mediator_unittest.mm
@@ -502,15 +502,11 @@
   ASSERT_TRUE(web_state);
   EXPECT_EQ(web_state->GetBrowserState(), browser_state_.get());
   EXPECT_FALSE(web_state->HasOpener());
-  if (web::features::UseWKWebViewLoading()) {
-    // The URL of pending item (i.e. kChromeUINewTabURL) will not be returned
-    // here because WebState doesn't load the URL until it's visible and
-    // NavigationManager::GetVisibleURL requires WebState::IsLoading to be true
-    // to return pending item's URL.
-    EXPECT_EQ("", web_state->GetVisibleURL().spec());
-  } else {
-    EXPECT_EQ(kChromeUINewTabURL, web_state->GetVisibleURL().spec());
-  }
+  // The URL of pending item (i.e. kChromeUINewTabURL) will not be returned
+  // here because WebState doesn't load the URL until it's visible and
+  // NavigationManager::GetVisibleURL requires WebState::IsLoading to be true
+  // to return pending item's URL.
+  EXPECT_EQ("", web_state->GetVisibleURL().spec());
   NSString* identifier = TabIdTabHelper::FromWebState(web_state)->tab_id();
   EXPECT_FALSE([original_identifiers_ containsObject:identifier]);
   // Consumer checks.
@@ -532,15 +528,11 @@
   ASSERT_TRUE(web_state);
   EXPECT_EQ(web_state->GetBrowserState(), browser_state_.get());
   EXPECT_FALSE(web_state->HasOpener());
-  if (web::features::UseWKWebViewLoading()) {
-    // The URL of pending item (i.e. kChromeUINewTabURL) will not be returned
-    // here because WebState doesn't load the URL until it's visible and
-    // NavigationManager::GetVisibleURL requires WebState::IsLoading to be true
-    // to return pending item's URL.
-    EXPECT_EQ("", web_state->GetVisibleURL().spec());
-  } else {
-    EXPECT_EQ(kChromeUINewTabURL, web_state->GetVisibleURL().spec());
-  }
+  // The URL of pending item (i.e. kChromeUINewTabURL) will not be returned
+  // here because WebState doesn't load the URL until it's visible and
+  // NavigationManager::GetVisibleURL requires WebState::IsLoading to be true
+  // to return pending item's URL.
+  EXPECT_EQ("", web_state->GetVisibleURL().spec());
   NSString* identifier = TabIdTabHelper::FromWebState(web_state)->tab_id();
   EXPECT_FALSE([original_identifiers_ containsObject:identifier]);
   // Consumer checks.
diff --git a/ios/web/common/features.h b/ios/web/common/features.h
index 1ff623a..5f4f9bc8 100644
--- a/ios/web/common/features.h
+++ b/ios/web/common/features.h
@@ -36,9 +36,6 @@
 // Used to enable committed interstitials for SSL errors.
 extern const base::Feature kSSLCommittedInterstitials;
 
-// Used to enable using WKWebView.loading for WebState::IsLoading.
-extern const base::Feature kUseWKWebViewLoading;
-
 // Feature flag enabling persistent downloads.
 extern const base::Feature kEnablePersistentDownloads;
 
@@ -60,10 +57,6 @@
 // subject to an opt-out controlled by prefs::kSafeBrowsingEnabled.
 extern const base::Feature kSafeBrowsingAvailable;
 
-// Use WKWebView.loading to update WebState::IsLoading.
-// TODO(crbug.com/1006012): Clean up this flag after experiment.
-bool UseWKWebViewLoading();
-
 // Level at which battery power is considered low, and some cosmetic features
 // can be turned off.
 const float kLowBatteryLevelThreshold = 0.2;
diff --git a/ios/web/common/features.mm b/ios/web/common/features.mm
index 3d9ac89..eb0aee7 100644
--- a/ios/web/common/features.mm
+++ b/ios/web/common/features.mm
@@ -32,9 +32,6 @@
 const base::Feature kSSLCommittedInterstitials{
     "SSLCommittedInterstitials", base::FEATURE_DISABLED_BY_DEFAULT};
 
-const base::Feature kUseWKWebViewLoading{"UseWKWebViewLoading",
-                                         base::FEATURE_ENABLED_BY_DEFAULT};
-
 const base::Feature kEnablePersistentDownloads{
     "EnablePersistentDownloads", base::FEATURE_DISABLED_BY_DEFAULT};
 
@@ -50,9 +47,5 @@
 const base::Feature kSafeBrowsingAvailable{"SafeBrowsingAvailable",
                                            base::FEATURE_DISABLED_BY_DEFAULT};
 
-bool UseWKWebViewLoading() {
-  return base::FeatureList::IsEnabled(web::features::kUseWKWebViewLoading);
-}
-
 }  // namespace features
 }  // namespace web
diff --git a/ios/web/navigation/crw_web_view_navigation_observer.mm b/ios/web/navigation/crw_web_view_navigation_observer.mm
index 441550e..c5c814d 100644
--- a/ios/web/navigation/crw_web_view_navigation_observer.mm
+++ b/ios/web/navigation/crw_web_view_navigation_observer.mm
@@ -132,9 +132,7 @@
 
 // Called when WKWebView loading state has been changed.
 - (void)webViewLoadingStateDidChange {
-  if (web::features::UseWKWebViewLoading()) {
-    self.webStateImpl->SetIsLoading(self.webView.loading);
-  }
+  self.webStateImpl->SetIsLoading(self.webView.loading);
 
   if (self.webView.loading)
     return;
@@ -272,9 +270,6 @@
       if (!web::IsSafeBrowsingWarningDisplayedInWebView(self.webView))
         return;
 
-      if (!web::features::UseWKWebViewLoading()) {
-        self.webStateImpl->SetIsLoading(false);
-      }
       self.navigationManagerImpl->DiscardNonCommittedItems();
       self.navigationHandler.pendingNavigationInfo = nil;
         // Right after a history navigation that gets cancelled by a tap on
diff --git a/ios/web/navigation/crw_wk_navigation_handler.mm b/ios/web/navigation/crw_wk_navigation_handler.mm
index a91ab9cf..48e1082 100644
--- a/ios/web/navigation/crw_wk_navigation_handler.mm
+++ b/ios/web/navigation/crw_wk_navigation_handler.mm
@@ -318,9 +318,6 @@
             decisionHandler(WKNavigationActionPolicyCancel);
             if (action.targetFrame.mainFrame) {
               [self.pendingNavigationInfo setCancelled:YES];
-              if (!web::features::UseWKWebViewLoading()) {
-                self.webStateImpl->SetIsLoading(false);
-              }
             }
           }
         }));
@@ -420,26 +417,11 @@
 
       if (!self.beingDestroyed &&
           [self shouldClosePageOnNativeApplicationLoad]) {
-        if (!web::features::UseWKWebViewLoading()) {
-          // Loading was started for user initiated navigations and should be
-          // stopped because no other WKWebView callbacks are called.
-          // TODO(crbug.com/767092): Loading should not start until
-          // webView.loading is changed to YES.
-          self.webStateImpl->SetIsLoading(false);
-        }
         self.webStateImpl->CloseWebState();
         decisionHandler(WKNavigationActionPolicyCancel);
         return;
       }
     }
-
-    if (!web::features::UseWKWebViewLoading() && !self.beingDestroyed) {
-      // Loading was started for user initiated navigations and should be
-      // stopped because no other WKWebView callbacks are called.
-      // TODO(crbug.com/767092): Loading should not start until webView.loading
-      // is changed to YES.
-      self.webStateImpl->SetIsLoading(false);
-    }
   }
 
   // Only try to detect a SafeBrowsing warning if one isn't already displayed,
@@ -480,16 +462,6 @@
             strongSelf.webStateImpl->OnNavigationStarted(context.get());
             strongSelf.webStateImpl->OnNavigationFinished(context.get());
             strongSelf->_safeBrowsingWarningDetectionTimer.Stop();
-            if (!web::features::UseWKWebViewLoading() && !existingContext) {
-              // If there's an existing context, observers will already be aware
-              // of a load in progress. Otherwise, observers need to be notified
-              // here, so that if the user decides to go back to the previous
-              // page (stopping the load), observers will be aware of a possible
-              // URL change and the URL displayed in the omnibox will get
-              // updated.
-              DCHECK(strongWebView.loading);
-              strongSelf.webStateImpl->SetIsLoading(true);
-            }
           }
         }));
   }
@@ -547,13 +519,6 @@
     self.pendingNavigationInfo.cancelled = YES;
   }
 
-  if (!web::features::UseWKWebViewLoading() && !WKResponse.forMainFrame &&
-      !webView.loading) {
-    // This is the terminal callback for iframe navigation and there is no
-    // pending main frame navigation. Last chance to flip IsLoading to false.
-    self.webStateImpl->SetIsLoading(false);
-  }
-
   handler(shouldRenderResponse ? WKNavigationResponsePolicyAllow
                                : WKNavigationResponsePolicyCancel);
 }
@@ -1746,10 +1711,6 @@
               navigationContext->GetUrl());
           return;
         } else if (!PageTransitionIsNewNavigation(transition)) {
-          if (!web::features::UseWKWebViewLoading() &&
-              transition & ui::PAGE_TRANSITION_RELOAD) {
-            self.webStateImpl->SetIsLoading(false);
-          }
           return;
         }
     }
@@ -1770,9 +1731,6 @@
         self.navigationManagerImpl->DiscardNonCommittedItems();
         [self.navigationStates removeNavigation:navigation];
       }
-      if (!web::features::UseWKWebViewLoading()) {
-        self.webStateImpl->SetIsLoading(false);
-      }
       return;
     }
 
@@ -1783,9 +1741,6 @@
         // item and fail the navigation.
         navigationContext->ReleaseItem();
         self.webStateImpl->OnNavigationFinished(navigationContext);
-        if (!web::features::UseWKWebViewLoading()) {
-          self.webStateImpl->SetIsLoading(false);
-        }
         self.webStateImpl->OnPageLoaded(navigationContext->GetUrl(), false);
         return;
       }
@@ -2154,9 +2109,6 @@
         [self.delegate navigationHandler:self
               didCompleteLoadWithSuccess:NO
                               forContext:context];
-        if (!web::features::UseWKWebViewLoading()) {
-          self.webStateImpl->SetIsLoading(false);
-        }
         self.webStateImpl->OnPageLoaded(failingURL, NO);
       }));
 }
diff --git a/ios/web/navigation/wk_based_navigation_manager_impl.mm b/ios/web/navigation/wk_based_navigation_manager_impl.mm
index dfd54d38..db7488d 100644
--- a/ios/web/navigation/wk_based_navigation_manager_impl.mm
+++ b/ios/web/navigation/wk_based_navigation_manager_impl.mm
@@ -488,10 +488,9 @@
   if (pending_item) {
     bool is_user_initiated = pending_item->NavigationInitiationType() ==
                              NavigationInitiationType::BROWSER_INITIATED;
-    bool safe_to_show_pending = is_user_initiated && pending_item_index_ == -1;
-    if (web::features::UseWKWebViewLoading()) {
-      safe_to_show_pending = safe_to_show_pending && GetWebState()->IsLoading();
-    }
+    bool safe_to_show_pending = is_user_initiated &&
+                                pending_item_index_ == -1 &&
+                                GetWebState()->IsLoading();
     if (safe_to_show_pending) {
       return pending_item;
     }
diff --git a/ios/web/web_state/ui/crw_web_controller.mm b/ios/web/web_state/ui/crw_web_controller.mm
index 6fbf6b08..77d7586 100644
--- a/ios/web/web_state/ui/crw_web_controller.mm
+++ b/ios/web/web_state/ui/crw_web_controller.mm
@@ -751,9 +751,6 @@
               ui::PageTransition::PAGE_TRANSITION_FORWARD_BACK),
           type == web::NavigationInitiationType::RENDERER_INITIATED);
   context->SetIsSameDocument(true);
-  if (!web::features::UseWKWebViewLoading()) {
-    self.webStateImpl->SetIsLoading(true);
-  }
   self.webStateImpl->OnNavigationStarted(context.get());
   [self setDocumentURL:URL context:context.get()];
   context->SetHasCommitted(true);
@@ -796,9 +793,6 @@
     // navigations.
     context->SetIsSameDocument(true);
   } else {
-    if (!web::features::UseWKWebViewLoading()) {
-      self.webStateImpl->SetIsLoading(true);
-    }
     self.navigationHandler.navigationState = web::WKNavigationState::REQUESTED;
   }
 
diff --git a/ios/web/web_state/ui/crw_web_request_controller.mm b/ios/web/web_state/ui/crw_web_request_controller.mm
index 5d4166dd..aed49085 100644
--- a/ios/web/web_state/ui/crw_web_request_controller.mm
+++ b/ios/web/web_state/ui/crw_web_request_controller.mm
@@ -366,7 +366,7 @@
   if (!IsWKInternalUrl(requestURL) &&
       (base::FeatureList::IsEnabled(web::features::kUseJSForErrorPage) ||
        !placeholderNavigation) &&
-      (!web::features::UseWKWebViewLoading() || !rendererInitiated)) {
+      !rendererInitiated) {
     self.webState->SetIsLoading(true);
   }
 
@@ -414,14 +414,6 @@
     // loading placeholder URL.
     return;
   }
-  if (!web::features::UseWKWebViewLoading()) {
-    if (![self.navigationHandler.navigationStates
-                lastNavigationWithPendingItemInNavigationContext]) {
-      self.webState->SetIsLoading(false);
-    } else {
-      // There is another pending navigation, so the state is still loading.
-    }
-  }
 
   self.webState->OnPageLoaded(currentURL, YES);
 
diff --git a/ios/web/web_state/web_state_observer_inttest.mm b/ios/web/web_state/web_state_observer_inttest.mm
index fd62c04e..839297d 100644
--- a/ios/web/web_state/web_state_observer_inttest.mm
+++ b/ios/web/web_state/web_state_observer_inttest.mm
@@ -189,11 +189,7 @@
   EXPECT_FALSE((*context)->GetError());
   EXPECT_FALSE((*context)->IsRendererInitiated());
   ASSERT_FALSE((*context)->GetResponseHeaders());
-  if (web::features::UseWKWebViewLoading()) {
-    EXPECT_TRUE(web_state->IsLoading());
-  } else {
-    EXPECT_FALSE(web_state->IsLoading());
-  }
+  EXPECT_TRUE(web_state->IsLoading());
   NavigationManager* navigation_manager = web_state->GetNavigationManager();
   NavigationItem* item = navigation_manager->GetLastCommittedItem();
   EXPECT_EQ(url, item->GetURL());
@@ -329,11 +325,7 @@
   EXPECT_FALSE((*context)->GetResponseHeaders());
   EXPECT_TRUE(web_state->ContentIsHTML());
   EXPECT_EQ(mime_type, web_state->GetContentsMimeType());
-  if (web::features::UseWKWebViewLoading()) {
-    EXPECT_TRUE(web_state->IsLoading());
-  } else {
-    EXPECT_FALSE(web_state->IsLoading());
-  }
+  EXPECT_TRUE(web_state->IsLoading());
   NavigationManager* navigation_manager = web_state->GetNavigationManager();
   NavigationItem* item = navigation_manager->GetLastCommittedItem();
   EXPECT_TRUE(!item->GetTimestamp().is_null());
@@ -369,11 +361,7 @@
   EXPECT_EQ(error_code, actual_error_code);
   EXPECT_FALSE((*context)->IsRendererInitiated());
   EXPECT_FALSE((*context)->GetResponseHeaders());
-  if (web::features::UseWKWebViewLoading()) {
-    ASSERT_TRUE(!web_state->IsLoading());
-  } else {
-    ASSERT_TRUE(web_state->IsLoading());
-  }
+  ASSERT_TRUE(!web_state->IsLoading());
   ASSERT_FALSE(web_state->ContentIsHTML());
   NavigationManager* navigation_manager = web_state->GetNavigationManager();
   NavigationItem* item = navigation_manager->GetLastCommittedItem();
@@ -868,10 +856,8 @@
               ShouldAllowRequest(_, RequestInfoMatch(expected_request_info)))
       .WillOnce(Return(true));
 
-  if (web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStopLoading(web_state()));
-    EXPECT_CALL(observer_, DidStartLoading(web_state()));
-  }
+  EXPECT_CALL(observer_, DidStopLoading(web_state()));
+  EXPECT_CALL(observer_, DidStartLoading(web_state()));
 
   EXPECT_CALL(observer_, DidStartNavigation(web_state(), _))
       .WillOnce(VerifyPageConcurrentlyStartedContext(
@@ -882,9 +868,7 @@
       .WillOnce(VerifyNewPageFinishedContext(
           web_state(), first_url, /*mime_type=*/std::string(),
           /*content_is_html=*/false, &context, &nav_id));
-  if (web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStopLoading(web_state()));
-  }
+  EXPECT_CALL(observer_, DidStopLoading(web_state()));
   EXPECT_CALL(observer_,
               PageLoaded(web_state(), PageLoadCompletionStatus::SUCCESS));
 
@@ -892,9 +876,7 @@
   EXPECT_CALL(*decider_,
               ShouldAllowRequest(_, RequestInfoMatch(expected_request_info)))
       .WillOnce(Return(true));
-  if (web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStartLoading(web_state()));
-  }
+  EXPECT_CALL(observer_, DidStartLoading(web_state()));
   EXPECT_CALL(observer_, DidStartNavigation(web_state(), _))
       .WillOnce(VerifyPageStartedContext(
           web_state(), second_url, ui::PageTransition::PAGE_TRANSITION_TYPED,
@@ -983,30 +965,22 @@
           web_state(), url, ui::PageTransition::PAGE_TRANSITION_TYPED, &context,
           &nav_id));
 
-  if (web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStopLoading(web_state()));
-    // Load placeholder by [WKWebView loadRequest].
-    EXPECT_CALL(observer_, DidStartLoading(web_state()));
-    EXPECT_CALL(observer_, DidStopLoading(web_state()));
-  }
+  EXPECT_CALL(observer_, DidStopLoading(web_state()));
+  // Load placeholder by [WKWebView loadRequest].
+  EXPECT_CALL(observer_, DidStartLoading(web_state()));
+  EXPECT_CALL(observer_, DidStopLoading(web_state()));
 
   EXPECT_CALL(observer_, DidFinishNavigation(web_state(), _))
       .WillOnce(VerifyErrorFinishedContext(web_state(), url, &context, &nav_id,
                                            /*committed=*/true,
                                            NSURLErrorNetworkConnectionLost));
 
-  if (!web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStopLoading(web_state()));
-  }
-
   EXPECT_CALL(observer_,
               PageLoaded(web_state(), PageLoadCompletionStatus::FAILURE));
 
-  if (web::features::UseWKWebViewLoading()) {
-    // Load error page HTML by [WKWebView loadHTMLString:baseURL:].
-    EXPECT_CALL(observer_, DidStartLoading(web_state()));
-    EXPECT_CALL(observer_, DidStopLoading(web_state()));
-  }
+  // Load error page HTML by [WKWebView loadHTMLString:baseURL:].
+  EXPECT_CALL(observer_, DidStartLoading(web_state()));
+  EXPECT_CALL(observer_, DidStopLoading(web_state()));
 
   test::LoadUrl(web_state(), url);
 
@@ -1081,28 +1055,21 @@
 
     // WKWebView.URL changes from |url| nil and then to rewritten URL, while
     // WKWebView.loading changes from true to false and then back to true.
-    if (web::features::UseWKWebViewLoading()) {
-      EXPECT_CALL(observer_, DidStopLoading(web_state()));
-      EXPECT_CALL(observer_, DidStartLoading(web_state()));
-    }
+    EXPECT_CALL(observer_, DidStopLoading(web_state()));
+    EXPECT_CALL(observer_, DidStartLoading(web_state()));
 
     EXPECT_CALL(observer_, DidStartNavigation(web_state(), _))
         .WillOnce(VerifyPageStartedContext(
             web_state(), GURL(webkit_rewritten_url_spec),
             ui::PageTransition::PAGE_TRANSITION_TYPED, &context, &nav_id));
 
-    if (web::features::UseWKWebViewLoading()) {
-      EXPECT_CALL(observer_, DidStopLoading(web_state()));
-    }
+    EXPECT_CALL(observer_, DidStopLoading(web_state()));
 
     EXPECT_CALL(observer_, DidFinishNavigation(web_state(), _))
         .WillOnce(VerifyErrorFinishedContext(
             web_state(), GURL(webkit_rewritten_url_spec), &context, &nav_id,
             /*committed=*/false, kWebKitErrorCannotShowUrl));
 
-    if (!web::features::UseWKWebViewLoading()) {
-      EXPECT_CALL(observer_, DidStopLoading(web_state()));
-    }
     EXPECT_CALL(observer_,
                 PageLoaded(web_state(), PageLoadCompletionStatus::FAILURE));
 
@@ -1130,30 +1097,22 @@
           web_state(), url, ui::PageTransition::PAGE_TRANSITION_TYPED, &context,
           &nav_id));
 
-  if (web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStopLoading(web_state()));
-    // Load placeholder by [WKWebView loadRequest].
-    EXPECT_CALL(observer_, DidStartLoading(web_state()));
-    EXPECT_CALL(observer_, DidStopLoading(web_state()));
-  }
+  EXPECT_CALL(observer_, DidStopLoading(web_state()));
+  // Load placeholder by [WKWebView loadRequest].
+  EXPECT_CALL(observer_, DidStartLoading(web_state()));
+  EXPECT_CALL(observer_, DidStopLoading(web_state()));
 
   EXPECT_CALL(observer_, DidFinishNavigation(web_state(), _))
       .WillOnce(VerifyErrorFinishedContext(web_state(), url, &context, &nav_id,
                                            /*committed=*/true,
                                            NSURLErrorUnsupportedURL));
 
-  if (!web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStopLoading(web_state()));
-  }
-
   EXPECT_CALL(observer_,
               PageLoaded(web_state(), PageLoadCompletionStatus::FAILURE));
 
-  if (web::features::UseWKWebViewLoading()) {
-    // Load error page HTML by [WKWebView loadHTMLString:baseURL:].
-    EXPECT_CALL(observer_, DidStartLoading(web_state()));
-    EXPECT_CALL(observer_, DidStopLoading(web_state()));
-  }
+  // Load error page HTML by [WKWebView loadHTMLString:baseURL:].
+  EXPECT_CALL(observer_, DidStartLoading(web_state()));
+  EXPECT_CALL(observer_, DidStopLoading(web_state()));
 
   test::LoadUrl(web_state(), url);
   ASSERT_TRUE(test::WaitForWebViewContainingText(
@@ -1183,30 +1142,22 @@
           web_state(), url, ui::PageTransition::PAGE_TRANSITION_TYPED, &context,
           &nav_id));
 
-  if (web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStopLoading(web_state()));
-    // Load placeholder by [WKWebView loadRequest].
-    EXPECT_CALL(observer_, DidStartLoading(web_state()));
-    EXPECT_CALL(observer_, DidStopLoading(web_state()));
-  }
+  EXPECT_CALL(observer_, DidStopLoading(web_state()));
+  // Load placeholder by [WKWebView loadRequest].
+  EXPECT_CALL(observer_, DidStartLoading(web_state()));
+  EXPECT_CALL(observer_, DidStopLoading(web_state()));
 
   EXPECT_CALL(observer_, DidFinishNavigation(web_state(), _))
       .WillOnce(VerifyErrorFinishedContext(web_state(), url, &context, &nav_id,
                                            /*committed=*/true,
                                            web::kWebKitErrorCannotShowUrl));
 
-  if (!web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStopLoading(web_state()));
-  }
-
   EXPECT_CALL(observer_,
               PageLoaded(web_state(), PageLoadCompletionStatus::FAILURE));
 
-  if (web::features::UseWKWebViewLoading()) {
-    // Load error page HTML by [WKWebView loadHTMLString:baseURL:].
-    EXPECT_CALL(observer_, DidStartLoading(web_state()));
-    EXPECT_CALL(observer_, DidStopLoading(web_state()));
-  }
+  // Load error page HTML by [WKWebView loadHTMLString:baseURL:].
+  EXPECT_CALL(observer_, DidStartLoading(web_state()));
+  EXPECT_CALL(observer_, DidStopLoading(web_state()));
 
   test::LoadUrl(web_state(), url);
   ASSERT_TRUE(test::WaitForWebViewContainingText(
@@ -1394,9 +1345,7 @@
       ShouldAllowRequest(_, RequestInfoMatch(hash_url_expected_request_info)))
       .WillOnce(Return(true));
   EXPECT_CALL(observer_, DidChangeBackForwardState(web_state()));
-  if (web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStopLoading(web_state()));
-  }
+  EXPECT_CALL(observer_, DidStopLoading(web_state()));
 
   EXPECT_CALL(observer_, DidStartNavigation(web_state(), _))
       .WillOnce(VerifySameDocumentStartedContext(
@@ -1411,26 +1360,18 @@
           ui::PageTransition::PAGE_TRANSITION_TYPED,
           /*renderer_initiated=*/false));
 
-  if (!web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStopLoading(web_state()));
-  }
-
   EXPECT_CALL(observer_,
               PageLoaded(web_state(), PageLoadCompletionStatus::SUCCESS));
   ASSERT_TRUE(LoadUrl(hash_url));
 
-  if (web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStartLoading(web_state()));
-  }
+  EXPECT_CALL(observer_, DidStartLoading(web_state()));
 
   // Perform same-document navigation by going back.
   // No ShouldAllowRequest callback for same-document back-forward navigations.
 
   // Called once each for CanGoBack and CanGoForward.
   EXPECT_CALL(observer_, DidChangeBackForwardState(web_state())).Times(2);
-  if (web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStopLoading(web_state()));
-  }
+  EXPECT_CALL(observer_, DidStopLoading(web_state()));
   ui::PageTransition expected_transition = static_cast<ui::PageTransition>(
       ui::PageTransition::PAGE_TRANSITION_FORWARD_BACK |
       ui::PageTransition::PAGE_TRANSITION_TYPED);
@@ -1496,10 +1437,6 @@
       .WillOnce(Return(true));
   EXPECT_CALL(observer_, DidChangeBackForwardState(web_state()));
 
-  if (!web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStartLoading(web_state()));
-  }
-
   EXPECT_CALL(observer_, DidStartNavigation(web_state(), _))
       .WillOnce(VerifySameDocumentStartedContext(
           web_state(), hash_url, /*has_user_gesture=*/false, &context, &nav_id,
@@ -1512,10 +1449,6 @@
           ui::PageTransition::PAGE_TRANSITION_CLIENT_REDIRECT,
           /*renderer_initiated=*/true));
 
-  if (!web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStopLoading(web_state()));
-  }
-
   EXPECT_CALL(observer_,
               PageLoaded(web_state(), PageLoadCompletionStatus::SUCCESS));
   ExecuteJavaScript(@"window.location.hash = '#1'");
@@ -1999,11 +1932,9 @@
   EXPECT_CALL(observer_,
               PageLoaded(web_state(), PageLoadCompletionStatus::FAILURE));
 
-  if (web::features::UseWKWebViewLoading()) {
-    // Load error page HTML by [WKWebView loadHTMLString:baseURL:].
-    EXPECT_CALL(observer_, DidStartLoading(web_state()));
-    EXPECT_CALL(observer_, DidStopLoading(web_state()));
-  }
+  // Load error page HTML by [WKWebView loadHTMLString:baseURL:].
+  EXPECT_CALL(observer_, DidStartLoading(web_state()));
+  EXPECT_CALL(observer_, DidStopLoading(web_state()));
 
   test::LoadUrl(web_state(), url);
 
@@ -2257,17 +2188,11 @@
                              _, RequestInfoMatch(forward_back_request_info)))
       .WillOnce(Return(true));
 
-  if (web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStopLoading(web_state()));
-  }
+  EXPECT_CALL(observer_, DidStopLoading(web_state()));
 
   EXPECT_CALL(*decider_, ShouldAllowResponse(_, /*for_main_frame=*/false))
       .WillOnce(Return(true));
 
-  if (!web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStopLoading(web_state()));
-  }
-
   web_state()->GetNavigationManager()->GoBack();
   EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForPageLoadTimeout, ^bool {
     id URL = ExecuteJavaScript(@"window.frames[0].location.pathname;");
@@ -2312,31 +2237,22 @@
   EXPECT_CALL(observer_, DidStartLoading(web_state()));
   EXPECT_CALL(*decider_, ShouldAllowRequest(_, _)).WillOnce(Return(true));
   EXPECT_CALL(observer_, DidChangeBackForwardState(web_state()));
-  if (web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStopLoading(web_state()));
-  }
+  EXPECT_CALL(observer_, DidStopLoading(web_state()));
   EXPECT_CALL(observer_, DidStartNavigation(web_state(), _));
   // No ShouldAllowResponse callback for same-document navigations.
   EXPECT_CALL(observer_, DidFinishNavigation(web_state(), _));
-  if (!web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStopLoading(web_state()));
-  }
   EXPECT_CALL(observer_,
               PageLoaded(web_state(), PageLoadCompletionStatus::SUCCESS));
   ASSERT_TRUE(LoadUrl(hash_url));
 
-  if (web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStartLoading(web_state()));
-  }
+  EXPECT_CALL(observer_, DidStartLoading(web_state()));
 
   // Go back to create forward navigation items.
 
   // Called once each for CanGoBack and CanGoForward;
   EXPECT_CALL(observer_, DidChangeBackForwardState(web_state())).Times(2);
 
-  if (web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStopLoading(web_state()));
-  }
+  EXPECT_CALL(observer_, DidStopLoading(web_state()));
 
   EXPECT_CALL(observer_, DidStartNavigation(web_state(), _));
   // No ShouldAllowResponse callbacks for same-document back-forward
@@ -2394,14 +2310,12 @@
   int32_t nav_id = 0;
   // Load restore_session.html with session history.
   EXPECT_CALL(observer, DidStartLoading(web_state.get()));
-  if (web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer, DidStopLoading(web_state.get()));
-    // Load restore_session.html with targetUrl=|url|.
-    EXPECT_CALL(observer, DidStartLoading(web_state.get()));
-    EXPECT_CALL(observer, DidStopLoading(web_state.get()));
-    // Load restored |url|.
-    EXPECT_CALL(observer, DidStartLoading(web_state.get()));
-  }
+  EXPECT_CALL(observer, DidStopLoading(web_state.get()));
+  // Load restore_session.html with targetUrl=|url|.
+  EXPECT_CALL(observer, DidStartLoading(web_state.get()));
+  EXPECT_CALL(observer, DidStopLoading(web_state.get()));
+  // Load restored |url|.
+  EXPECT_CALL(observer, DidStartLoading(web_state.get()));
 
   EXPECT_CALL(observer, DidStartNavigation(web_state.get(), _))
       .WillOnce(VerifyRestorationStartedContext(web_state.get(), url, &context,
@@ -2463,9 +2377,7 @@
 
   // Initiate session restoration.
 
-  if (web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStartLoading(web_state()));
-  }
+  EXPECT_CALL(observer_, DidStartLoading(web_state()));
 
   EXPECT_CALL(*decider_, ShouldAllowRequest(_, _)).WillOnce(Return(true));
   EXPECT_CALL(*decider_, ShouldAllowResponse(_, /*for_main_frame=*/true))
@@ -2475,9 +2387,7 @@
   // restoration. Called once each for CanGoBack and CanGoForward.
   EXPECT_CALL(observer_, DidChangeBackForwardState(web_state()));
 
-  if (web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStopLoading(web_state()));
-  }
+  EXPECT_CALL(observer_, DidStopLoading(web_state()));
 
   EXPECT_CALL(observer_, DidChangeBackForwardState(web_state()));
 
@@ -2486,17 +2396,13 @@
               ShouldAllowRequest(URLMatch(CreateRedirectUrl(url1)), _))
       .WillOnce(Return(true));
 
-  if (web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStartLoading(web_state()));
-  }
+  EXPECT_CALL(observer_, DidStartLoading(web_state()));
 
   EXPECT_CALL(*decider_, ShouldAllowResponse(URLMatch(CreateRedirectUrl(url1)),
                                              /*for_main_frame=*/true))
       .WillOnce(Return(true));
 
-  if (web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStopLoading(web_state()));
-  }
+  EXPECT_CALL(observer_, DidStopLoading(web_state()));
 
   // Client-side redirect to |url1|.
   EXPECT_CALL(*decider_, ShouldAllowRequest(URLMatch(url1), _))
@@ -2538,17 +2444,13 @@
                                              /*for_main_frame=*/true))
       .WillOnce(Return(true));
 
-  if (web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStopLoading(web_state()));
-  }
+  EXPECT_CALL(observer_, DidStopLoading(web_state()));
 
   // Client-side redirect to |url0|.
   EXPECT_CALL(*decider_, ShouldAllowRequest(URLMatch(url0), _))
       .WillOnce(Return(true));
 
-  if (web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStartLoading(web_state()));
-  }
+  EXPECT_CALL(observer_, DidStartLoading(web_state()));
 
   EXPECT_CALL(observer_, DidStartNavigation(web_state(), _));
   // No ShouldAllowResponse call because about:blank has no response.
@@ -2682,9 +2584,7 @@
   NSString* html = @"<html><body>foo</body></html>";
   GURL data_url("https://www.chromium.test");
 
-  if (web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStartLoading(web_state()));
-  }
+  EXPECT_CALL(observer_, DidStartLoading(web_state()));
   EXPECT_CALL(*decider_, ShouldAllowRequest(_, _)).WillOnce(Return(true));
   // ShouldAllowResponse is not called on loadData navigation.
   EXPECT_CALL(observer_, DidStartNavigation(web_state(), _))
@@ -2696,9 +2596,7 @@
                                           &context, &nav_id));
   EXPECT_CALL(observer_, TitleWasSet(web_state()))
       .WillOnce(VerifyTitle("https://www.chromium.test"));
-  if (web::features::UseWKWebViewLoading()) {
-    EXPECT_CALL(observer_, DidStopLoading(web_state()));
-  }
+  EXPECT_CALL(observer_, DidStopLoading(web_state()));
   EXPECT_CALL(observer_,
               PageLoaded(web_state(), PageLoadCompletionStatus::SUCCESS));
   web_state()->LoadData([html dataUsingEncoding:NSUTF8StringEncoding],