[ESW] Expand some chrome.webNavigation tests to SWs (1-3 / 23).

This CL expands following webNavigation apitests to workers:
  - WebNavigationApiTestWithContextType.ClientRedirect
  - WebNavigationApiTestWithContextType.Crash
  - WebNavigationApiTestWithContextType.Failures

Currently there are 23 tests that can be expanded to workers and this
CL picks first 3 from them. Subsequent CLs will cover the rest.

This is similar to other WebNaviationApiTest's expansion to workers,
e.g. crrev.com/c/2844543.


Bug: 1205340
Test: None, internal test only change.
Change-Id: If7130f9a65927a203210677d89e883ec0b8821c5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2873140
Reviewed-by: David Bertoni <dbertoni@chromium.org>
Commit-Queue: Istiaque Ahmed <lazyboy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#879482}
diff --git a/chrome/browser/extensions/api/web_navigation/web_navigation_apitest.cc b/chrome/browser/extensions/api/web_navigation/web_navigation_apitest.cc
index 780c4ab..baf89d6 100644
--- a/chrome/browser/extensions/api/web_navigation/web_navigation_apitest.cc
+++ b/chrome/browser/extensions/api/web_navigation/web_navigation_apitest.cc
@@ -263,8 +263,8 @@
                          WebNavigationApiTestWithContextType,
                          testing::Values(ContextType::kServiceWorker));
 
-IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, ClientRedirect) {
-  ASSERT_TRUE(RunExtensionTest("webnavigation/clientRedirect")) << message_;
+IN_PROC_BROWSER_TEST_P(WebNavigationApiTestWithContextType, ClientRedirect) {
+  ASSERT_TRUE(RunTest("webnavigation/clientRedirect")) << message_;
 }
 
 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, ServerRedirect) {
@@ -349,8 +349,8 @@
   ASSERT_TRUE(RunExtensionTest("webnavigation/simpleLoad")) << message_;
 }
 
-IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, Failures) {
-  ASSERT_TRUE(RunExtensionTest("webnavigation/failures")) << message_;
+IN_PROC_BROWSER_TEST_P(WebNavigationApiTestWithContextType, Failures) {
+  ASSERT_TRUE(RunTest("webnavigation/failures")) << message_;
 }
 
 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, FilteredTest) {
@@ -574,12 +574,12 @@
   ASSERT_TRUE(RunExtensionTest("webnavigation/pendingDeletion")) << message_;
 }
 
-IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, Crash) {
+IN_PROC_BROWSER_TEST_P(WebNavigationApiTestWithContextType, Crash) {
   content::ScopedAllowRendererCrashes scoped_allow_renderer_crashes;
   ASSERT_TRUE(StartEmbeddedTestServer());
 
   // Wait for the extension to set itself up and return control to us.
-  ASSERT_TRUE(RunExtensionTest("webnavigation/crash")) << message_;
+  ASSERT_TRUE(RunTest("webnavigation/crash")) << message_;
 
   WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
   EXPECT_TRUE(content::WaitForLoadStop(tab));
diff --git a/chrome/test/data/extensions/api_test/webnavigation/clientRedirect/manifest.json b/chrome/test/data/extensions/api_test/webnavigation/clientRedirect/manifest.json
index 607ba01..907edc3 100644
--- a/chrome/test/data/extensions/api_test/webnavigation/clientRedirect/manifest.json
+++ b/chrome/test/data/extensions/api_test/webnavigation/clientRedirect/manifest.json
@@ -4,7 +4,8 @@
   "manifest_version": 2,
   "description": "Tests the webNavigation API events - clientRedirect.",
   "background": {
-    "page": "test_clientRedirect.html"
+    "scripts": ["test_clientRedirect.js"],
+    "persistent": true
   },
   "permissions": ["webNavigation", "tabs"]
 }
diff --git a/chrome/test/data/extensions/api_test/webnavigation/clientRedirect/test_clientRedirect.html b/chrome/test/data/extensions/api_test/webnavigation/clientRedirect/test_clientRedirect.html
deleted file mode 100644
index dd27a43..0000000
--- a/chrome/test/data/extensions/api_test/webnavigation/clientRedirect/test_clientRedirect.html
+++ /dev/null
@@ -1,2 +0,0 @@
-<script src="_test_resources/api_test/webnavigation/framework.js"></script>
-<script src="test_clientRedirect.js"></script>
diff --git a/chrome/test/data/extensions/api_test/webnavigation/clientRedirect/test_clientRedirect.js b/chrome/test/data/extensions/api_test/webnavigation/clientRedirect/test_clientRedirect.js
index ad878ad..16e1897 100644
--- a/chrome/test/data/extensions/api_test/webnavigation/clientRedirect/test_clientRedirect.js
+++ b/chrome/test/data/extensions/api_test/webnavigation/clientRedirect/test_clientRedirect.js
@@ -2,7 +2,10 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-onload = async function() {
+const scriptUrl = '_test_resources/api_test/webnavigation/framework.js';
+let loadScript = chrome.test.loadScript(scriptUrl);
+
+loadScript.then(async function() {
   let getURL = chrome.extension.getURL;
   let tab = await promise(chrome.tabs.create, {"url": "about:blank"});
   chrome.test.runTests([
@@ -83,4 +86,4 @@
       chrome.tabs.update(tab.id, { url: getURL('a.html') });
     },
   ]);
-};
+});
diff --git a/chrome/test/data/extensions/api_test/webnavigation/crash/manifest.json b/chrome/test/data/extensions/api_test/webnavigation/crash/manifest.json
index 169905a..48046732 100644
--- a/chrome/test/data/extensions/api_test/webnavigation/crash/manifest.json
+++ b/chrome/test/data/extensions/api_test/webnavigation/crash/manifest.json
@@ -4,7 +4,8 @@
   "manifest_version": 2,
   "description": "Tests the webNavigation API events - crash.",
   "background": {
-    "page": "test_crash.html"
+    "scripts": ["test_crash.js"],
+    "persistent": true
   },
   "permissions": ["webNavigation", "tabs"]
 }
diff --git a/chrome/test/data/extensions/api_test/webnavigation/crash/test_crash.html b/chrome/test/data/extensions/api_test/webnavigation/crash/test_crash.html
deleted file mode 100644
index 4bfe706..0000000
--- a/chrome/test/data/extensions/api_test/webnavigation/crash/test_crash.html
+++ /dev/null
@@ -1,2 +0,0 @@
-<script src="_test_resources/api_test/webnavigation/framework.js"></script>
-<script src="test_crash.js"></script>
diff --git a/chrome/test/data/extensions/api_test/webnavigation/crash/test_crash.js b/chrome/test/data/extensions/api_test/webnavigation/crash/test_crash.js
index cfc8c74..faef79a 100644
--- a/chrome/test/data/extensions/api_test/webnavigation/crash/test_crash.js
+++ b/chrome/test/data/extensions/api_test/webnavigation/crash/test_crash.js
@@ -2,7 +2,10 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-onload = async function() {
+const scriptUrl = '_test_resources/api_test/webnavigation/framework.js';
+let loadScript = chrome.test.loadScript(scriptUrl);
+
+loadScript.then(async function() {
   let tab = await promise(chrome.tabs.create, {"url": "about:blank"});
   let config = await promise(chrome.test.getConfig);
   let port = config.testServer.port;
@@ -91,4 +94,4 @@
       chrome.test.notifyPass();
     },
   ]);
-};
+});
diff --git a/chrome/test/data/extensions/api_test/webnavigation/failures/manifest.json b/chrome/test/data/extensions/api_test/webnavigation/failures/manifest.json
index 21955e6..9e670e4 100644
--- a/chrome/test/data/extensions/api_test/webnavigation/failures/manifest.json
+++ b/chrome/test/data/extensions/api_test/webnavigation/failures/manifest.json
@@ -4,7 +4,8 @@
   "manifest_version": 2,
   "description": "Tests the webNavigation API events - failures.",
   "background": {
-    "page": "test_failures.html"
+    "scripts": ["test_failures.js"],
+    "persistent": true
   },
   "permissions": ["webNavigation", "tabs"]
 }
diff --git a/chrome/test/data/extensions/api_test/webnavigation/failures/test_failures.html b/chrome/test/data/extensions/api_test/webnavigation/failures/test_failures.html
deleted file mode 100644
index 7858cf5..0000000
--- a/chrome/test/data/extensions/api_test/webnavigation/failures/test_failures.html
+++ /dev/null
@@ -1,2 +0,0 @@
-<script src="_test_resources/api_test/webnavigation/framework.js"></script>
-<script src="test_failures.js"></script>
diff --git a/chrome/test/data/extensions/api_test/webnavigation/failures/test_failures.js b/chrome/test/data/extensions/api_test/webnavigation/failures/test_failures.js
index 104c09f..dad2ff4 100644
--- a/chrome/test/data/extensions/api_test/webnavigation/failures/test_failures.js
+++ b/chrome/test/data/extensions/api_test/webnavigation/failures/test_failures.js
@@ -2,7 +2,10 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-onload = async function() {
+const scriptUrl = '_test_resources/api_test/webnavigation/framework.js';
+let loadScript = chrome.test.loadScript(scriptUrl);
+
+loadScript.then(async function() {
   var getURL = chrome.extension.getURL;
   let tab = await promise(chrome.tabs.create, {"url": "about:blank"});
 
@@ -226,4 +229,4 @@
       chrome.tabs.update(tab.id, { url: getURL('nonexistent.html') });
     },
   ]);
-};
+});