Commit 5cee6c65 authored by Ian Barkley-Yeung's avatar Ian Barkley-Yeung Committed by Commit Bot

WebUI JS Error Reporting: More test hooks

Add the remaining testing hooks needed for the Browser & Tast tests for
the WebUI JS Error Reporting project. In particular, added ability to
log errors (via console.error) and have unhandled promise rejections.

Since the page now does more than just throw exceptions, renamed from
chrome://webuiexception to chrome://webuierror.

Bug: chromium:1121816

Change-Id: I7aed32673569a51a3853594ac5b6e6dc04ef3b83
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2531802Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarPeter Wen <wnwen@chromium.org>
Auto-Submit: Ian Barkley-Yeung <iby@chromium.org>
Commit-Queue: Peter Wen <wnwen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827322}
parent 43cbd300
...@@ -1390,7 +1390,8 @@ group("extra_resources") { ...@@ -1390,7 +1390,8 @@ group("extra_resources") {
} }
if (is_linux || is_chromeos) { if (is_linux || is_chromeos) {
public_deps += [ "//chrome/browser/resources/webui_js_exception:webui_js_exception_resources" ] public_deps +=
[ "//chrome/browser/resources/webui_js_error:webui_js_error_resources" ]
} }
if (!is_android && !is_chromeos) { if (!is_android && !is_chromeos) {
......
...@@ -63,7 +63,7 @@ if (enable_js_type_check) { ...@@ -63,7 +63,7 @@ if (enable_js_type_check) {
deps += [ "sandbox_internals:closure_compile" ] deps += [ "sandbox_internals:closure_compile" ]
} }
if (is_linux || is_chromeos) { if (is_linux || is_chromeos) {
deps += [ "webui_js_exception:closure_compile" ] deps += [ "webui_js_error:closure_compile" ]
} }
if (is_chromeos) { if (is_chromeos) {
deps += [ deps += [
......
...@@ -15,13 +15,12 @@ preprocess_manifest = "preprocessed_manifest.json" ...@@ -15,13 +15,12 @@ preprocess_manifest = "preprocessed_manifest.json"
if (optimize_webui) { if (optimize_webui) {
build_manifest = "build_manifest.json" build_manifest = "build_manifest.json"
optimize_webui("build") { optimize_webui("build") {
host = "webui_js_exception" host = "webui_js_error"
input = rebase_path("$target_gen_dir/$preprocess_folder", root_build_dir) input = rebase_path("$target_gen_dir/$preprocess_folder", root_build_dir)
deps = [ ":preprocess" ] deps = [ ":preprocess" ]
js_module_in_files = [ "webui_js_exception.js" ] js_module_in_files = [ "webui_js_error.js" ]
js_out_files = [ "webui_js_exception.rollup.js" ] js_out_files = [ "webui_js_error.rollup.js" ]
out_manifest = "$target_gen_dir/$build_manifest" out_manifest = "$target_gen_dir/$build_manifest"
} }
} }
...@@ -30,45 +29,48 @@ preprocess_grit("preprocess") { ...@@ -30,45 +29,48 @@ preprocess_grit("preprocess") {
in_folder = "./" in_folder = "./"
out_folder = "$target_gen_dir/$preprocess_folder" out_folder = "$target_gen_dir/$preprocess_folder"
out_manifest = "$target_gen_dir/$preprocess_manifest" out_manifest = "$target_gen_dir/$preprocess_manifest"
in_files = [ "webui_js_exception.js" ] in_files = [ "webui_js_error.js" ]
} }
generate_grd("build_grd") { generate_grd("build_grd") {
input_files = [ "webui_js_exception.html" ] input_files = [ "webui_js_error.html" ]
input_files_base_dir = rebase_path(".", "//") input_files_base_dir = rebase_path(".", "//")
if (optimize_webui) { if (optimize_webui) {
deps = [ ":build" ] deps = [ ":build" ]
resource_path_rewrites = resource_path_rewrites = [ "webui_js_error.rollup.js|webui_js_error.js" ]
[ "webui_js_exception.rollup.js|webui_js_exception.js" ]
manifest_files = [ "$target_gen_dir/$build_manifest" ] manifest_files = [ "$target_gen_dir/$build_manifest" ]
} else { } else {
deps = [ ":preprocess" ] deps = [ ":preprocess" ]
manifest_files = [ "$target_gen_dir/$preprocess_manifest" ] manifest_files = [ "$target_gen_dir/$preprocess_manifest" ]
} }
grd_prefix = "webui_js_exception" grd_prefix = "webui_js_error"
out_grd = "$target_gen_dir/${grd_prefix}_resources.grd" out_grd = "$target_gen_dir/${grd_prefix}_resources.grd"
} }
grit("webui_js_exception_resources") { grit("webui_js_error_resources") {
defines = chrome_grit_defines defines = chrome_grit_defines
# These arguments are needed since the grd is generated at build time. # These arguments are needed since the grd is generated at build time.
enable_input_discovery_for_gn_analyze = false enable_input_discovery_for_gn_analyze = false
source = "$target_gen_dir/webui_js_exception_resources.grd" source = "$target_gen_dir/webui_js_error_resources.grd"
deps = [ ":build_grd" ] deps = [ ":build_grd" ]
outputs = [ outputs = [
"grit/webui_js_exception_resources.h", "grit/webui_js_error_resources.h",
"grit/webui_js_exception_resources_map.cc", "grit/webui_js_error_resources_map.cc",
"grit/webui_js_exception_resources_map.h", "grit/webui_js_error_resources_map.h",
"webui_js_exception_resources.pak", "webui_js_error_resources.pak",
] ]
output_dir = "$root_gen_dir/chrome" output_dir = "$root_gen_dir/chrome"
} }
js_type_check("closure_compile") { js_type_check("closure_compile") {
deps = [ ":webui_js_exception" ] deps = [ ":webui_js_error" ]
} }
js_library("webui_js_exception") { js_library("webui_js_error") {
deps = [
"//ui/webui/resources/js:assert",
"//ui/webui/resources/js:util",
]
} }
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<!-- Title is not localized since this is just a debugging page --> <!-- Title is not localized since this is just a debugging page -->
<title>WebUI JS Exception Page</title> <title>WebUI JS Error Page</title>
<style> <style>
html, html,
body { body {
...@@ -18,8 +18,15 @@ ...@@ -18,8 +18,15 @@
</head> </head>
<body> <body>
<!-- Text not localized since this is just a debugging page --> <!-- Text not localized since this is just a debugging page -->
This page generates a JavaScript exception on load and then another 3 This page generates a JavaScript error on load. Other types of errors can
seconds later. be generated with the buttons: <div>
<script type="module" src="webui_js_exception.js"></script> <!-- Ids are referenced in integration tests, including tast tests -->
<button id="error-button">Log Error</button>
<button id="exception-button">Throw Uncaught Error</button>
<button id="promise-button">Unhandled Promise Rejection</button>
</div>
<script src="chrome://resources/js/assert.js"></script>
<script src="chrome://resources/js/util.js"></script>
<script src="webui_js_error.js"></script>
</body> </body>
</html> </html>
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview This JavaScript prints an error message, throws uncaught
* exceptions, and otherwise does erroneous things for testing.
*
* Note that function names and error text are referenced in integration tests
* (particularly tast tests); do not change them without updating the tests.
*/
/**
* Logs an error when called. This is the "during page load" error.
*/
function logsErrorDuringPageLoad() {
logsErrorDuringPageLoadInner();
}
/**
* Logs an error when called. This is a separate function from
* logsErrorDuringPageLoad() so that we get an interesting stack.
*/
function logsErrorDuringPageLoadInner() {
console.error('WebUI JS Error: printing error on page load');
}
/**
* Logs an error when called. This is the "from button click" error.
*/
function logsErrorFromButtonClick() {
logsErrorFromButtonClickInner();
}
/**
* Logs an error when called. This is a separate function from
* logsErrorFromButtonClick() so that we get an interesting stack.
*/
function logsErrorFromButtonClickInner() {
console.error('WebUI JS Error: printing error on button click');
}
/**
* Throws an exception when called.
*/
function throwException() {
throwExceptionInner();
}
/**
* Throws an exception when called. This is a separate function from
* throwException() so that we get an interesting stack.
*/
function throwExceptionInner() {
throw new Error('WebUI JS Error: exception button clicked');
}
/**
* Success callback for the promise. This should never be called.
*/
function promiseSuccessful() {
console.error('WebUI JS Error: Promise success. This should never happen');
}
/**
* Promise executor. Always rejects the promise.
*/
function promiseRejector(resolve, reject) {
reject('WebUI JS Error: The rejector always rejects!');
}
/**
* Creates a promise which will be rejected and doesn't handle the rejection.
*/
function unhandledPromiseRejection() {
const promise = new Promise(promiseRejector);
promise.then(promiseSuccessful);
}
$('error-button').onclick = logsErrorFromButtonClick;
$('exception-button').onclick = throwException;
$('promise-button').onclick = unhandledPromiseRejection;
logsErrorDuringPageLoad();
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview This JavaScript throws an unhandled exception on page load, and
* then another 3 seconds later.
*
* Note that function names and error text are referenced in integration tests
* (particularly tast tests); do not change them without updating the tests.
*/
/**
* Throws an exception when called. This throws the "after 3 seconds" exception.
*/
function throwExceptionAfterTimeoutFunction() {
throwExceptionAfterTimeoutInner();
}
/**
* Throws an exception when called. This is a separate function from
* throwExceptionAfterTimeoutFunction() so that we get an interesting stack.
*/
function throwExceptionAfterTimeoutInner() {
throw new Error('WebUI JS Exception: timeout expired');
}
/**
* Throws an exception when called. This throws the "during page load"
* exception.
*/
function throwExceptionDuringPageLoadFunction() {
throwExceptionDuringPageLoadInner();
}
/**
* Throws an exception when called. This is a separate function from
* throwExceptionDuringPageLoadFunction() so that we get an interesting stack.
*/
function throwExceptionDuringPageLoadInner() {
throw new Error('WebUI JS Exception: exception on page load');
}
setTimeout(throwExceptionAfterTimeoutFunction, 3000);
throwExceptionDuringPageLoadFunction();
...@@ -3324,8 +3324,8 @@ static_library("ui") { ...@@ -3324,8 +3324,8 @@ static_library("ui") {
"webui/certificate_viewer_ui.h", "webui/certificate_viewer_ui.h",
"webui/certificate_viewer_webui.cc", "webui/certificate_viewer_webui.cc",
"webui/certificate_viewer_webui.h", "webui/certificate_viewer_webui.h",
"webui/webui_js_exception/webui_js_exception_ui.cc", "webui/webui_js_error/webui_js_error_ui.cc",
"webui/webui_js_exception/webui_js_exception_ui.h", "webui/webui_js_error/webui_js_error_ui.h",
] ]
if (use_aura) { if (use_aura) {
deps += [ "//third_party/fontconfig" ] deps += [ "//third_party/fontconfig" ]
......
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
#endif #endif
#if defined(OS_LINUX) || defined(OS_CHROMEOS) #if defined(OS_LINUX) || defined(OS_CHROMEOS)
#include "chrome/browser/ui/webui/webui_js_exception/webui_js_exception_ui.h" #include "chrome/browser/ui/webui/webui_js_error/webui_js_error_ui.h"
#endif #endif
#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
...@@ -809,8 +809,8 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, ...@@ -809,8 +809,8 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
#endif // !defined(OFFICIAL_BUILD) #endif // !defined(OFFICIAL_BUILD)
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
#if defined(OS_LINUX) || defined(OS_CHROMEOS) #if defined(OS_LINUX) || defined(OS_CHROMEOS)
if (url.host_piece() == chrome::kChromeUIWebUIJsExceptionHost) if (url.host_piece() == chrome::kChromeUIWebUIJsErrorHost)
return &NewWebUI<WebUIJsExceptionUI>; return &NewWebUI<WebUIJsErrorUI>;
#endif #endif
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
if (url.host_piece() == chrome::kChromeUIExploreSitesInternalsHost && if (url.host_piece() == chrome::kChromeUIExploreSitesInternalsHost &&
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/ui/webui/webui_js_exception/webui_js_exception_ui.h" #include "chrome/browser/ui/webui/webui_js_error/webui_js_error_ui.h"
#include <ios> #include <ios>
...@@ -13,35 +13,34 @@ ...@@ -13,35 +13,34 @@
#include "chrome/browser/ui/webui/webui_util.h" #include "chrome/browser/ui/webui/webui_util.h"
#include "chrome/common/buildflags.h" #include "chrome/common/buildflags.h"
#include "chrome/common/webui_url_constants.h" #include "chrome/common/webui_url_constants.h"
#include "chrome/grit/webui_js_exception_resources.h" #include "chrome/grit/webui_js_error_resources.h"
#include "chrome/grit/webui_js_exception_resources_map.h" #include "chrome/grit/webui_js_error_resources_map.h"
#include "content/public/browser/web_ui_data_source.h" #include "content/public/browser/web_ui_data_source.h"
#include "content/public/common/content_features.h" #include "content/public/common/content_features.h"
WebUIJsExceptionUI::WebUIJsExceptionUI(content::WebUI* web_ui) WebUIJsErrorUI::WebUIJsErrorUI(content::WebUI* web_ui)
: content::WebUIController(web_ui) { : content::WebUIController(web_ui) {
#if !defined(OS_WIN) && !defined(OS_FUCHSIA) #if !defined(OS_WIN) && !defined(OS_FUCHSIA)
VLOG(3) << std::boolalpha << "chrome://webuijsexception loading. " VLOG(3) << std::boolalpha << "chrome://webuijserror loading. "
<< "Experiment state: send javascript errors is " << "Experiment state: send javascript errors is "
<< base::FeatureList::IsEnabled( << base::FeatureList::IsEnabled(
features::kSendWebUIJavaScriptErrorReports) features::kSendWebUIJavaScriptErrorReports)
<< " and send to prod is " << " and send to prod is "
<< features::kWebUIJavaScriptErrorReportsSendToProductionParam.Get(); << features::kWebUIJavaScriptErrorReportsSendToProductionParam.Get();
#else #else
VLOG(3) << std::boolalpha << "chrome://webuijsexception loading."; VLOG(3) << "chrome://webuijserror loading.";
#endif #endif
content::WebUIDataSource* source = content::WebUIDataSource* source =
content::WebUIDataSource::Create(chrome::kChromeUIWebUIJsExceptionHost); content::WebUIDataSource::Create(chrome::kChromeUIWebUIJsErrorHost);
webui::SetupWebUIDataSource(source, webui::SetupWebUIDataSource(
base::make_span(kWebuiJsExceptionResources, source,
kWebuiJsExceptionResourcesSize), base::make_span(kWebuiJsErrorResources, kWebuiJsErrorResourcesSize),
std::string(), std::string(), IDR_WEBUI_JS_ERROR_WEBUI_JS_ERROR_HTML);
IDR_WEBUI_JS_EXCEPTION_WEBUI_JS_EXCEPTION_HTML);
Profile* profile = Profile::FromWebUI(web_ui); Profile* profile = Profile::FromWebUI(web_ui);
content::WebUIDataSource::Add(profile, source); content::WebUIDataSource::Add(profile, source);
} }
WebUIJsExceptionUI::~WebUIJsExceptionUI() = default; WebUIJsErrorUI::~WebUIJsErrorUI() = default;
WEB_UI_CONTROLLER_TYPE_IMPL(WebUIJsExceptionUI) WEB_UI_CONTROLLER_TYPE_IMPL(WebUIJsErrorUI)
...@@ -2,21 +2,21 @@ ...@@ -2,21 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_WEBUI_WEBUI_JS_EXCEPTION_WEBUI_JS_EXCEPTION_UI_H_ #ifndef CHROME_BROWSER_UI_WEBUI_WEBUI_JS_ERROR_WEBUI_JS_ERROR_UI_H_
#define CHROME_BROWSER_UI_WEBUI_WEBUI_JS_EXCEPTION_WEBUI_JS_EXCEPTION_UI_H_ #define CHROME_BROWSER_UI_WEBUI_WEBUI_JS_ERROR_WEBUI_JS_ERROR_UI_H_
#include "content/public/browser/web_ui_controller.h" #include "content/public/browser/web_ui_controller.h"
// The WebUI that controls chrome://webuijsexception. // The WebUI that controls chrome://webuijserror.
class WebUIJsExceptionUI : public content::WebUIController { class WebUIJsErrorUI : public content::WebUIController {
public: public:
explicit WebUIJsExceptionUI(content::WebUI* web_ui); explicit WebUIJsErrorUI(content::WebUI* web_ui);
~WebUIJsExceptionUI() override; ~WebUIJsErrorUI() override;
WebUIJsExceptionUI(const WebUIJsExceptionUI&) = delete; WebUIJsErrorUI(const WebUIJsErrorUI&) = delete;
WebUIJsExceptionUI& operator=(const WebUIJsExceptionUI&) = delete; WebUIJsErrorUI& operator=(const WebUIJsErrorUI&) = delete;
private: private:
WEB_UI_CONTROLLER_TYPE_DECL(); WEB_UI_CONTROLLER_TYPE_DECL();
}; };
#endif // CHROME_BROWSER_UI_WEBUI_WEBUI_JS_EXCEPTION_WEBUI_JS_EXCEPTION_UI_H_ #endif // CHROME_BROWSER_UI_WEBUI_WEBUI_JS_ERROR_WEBUI_JS_ERROR_UI_H_
...@@ -234,8 +234,10 @@ template("chrome_extra_paks") { ...@@ -234,8 +234,10 @@ template("chrome_extra_paks") {
} }
} }
if (is_linux || is_chromeos) { if (is_linux || is_chromeos) {
sources += [ "$root_gen_dir/chrome/webui_js_exception_resources.pak" ] sources += [ "$root_gen_dir/chrome/webui_js_error_resources.pak" ]
deps += [ "//chrome/browser/resources/webui_js_exception:webui_js_exception_resources" ] deps += [
"//chrome/browser/resources/webui_js_error:webui_js_error_resources",
]
} }
if (!is_android && !is_chromeos) { if (!is_android && !is_chromeos) {
sources += [ sources += [
......
...@@ -341,8 +341,8 @@ bool IsSystemWebUIHost(base::StringPiece host) { ...@@ -341,8 +341,8 @@ bool IsSystemWebUIHost(base::StringPiece host) {
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
#if defined(OS_LINUX) || defined(OS_CHROMEOS) #if defined(OS_LINUX) || defined(OS_CHROMEOS)
const char kChromeUIWebUIJsExceptionHost[] = "webuijsexception"; const char kChromeUIWebUIJsErrorHost[] = "webuijserror";
const char kChromeUIWebUIJsExceptionURL[] = "chrome://webuijsexception/"; const char kChromeUIWebUIJsErrorURL[] = "chrome://webuijserror/";
#endif #endif
#if defined(OS_WIN) || defined(OS_MAC) || defined(OS_LINUX) || \ #if defined(OS_WIN) || defined(OS_MAC) || defined(OS_LINUX) || \
...@@ -617,7 +617,7 @@ const char* const kChromeDebugURLs[] = { ...@@ -617,7 +617,7 @@ const char* const kChromeDebugURLs[] = {
kChromeUIJavaCrashURL, kChromeUIJavaCrashURL,
#endif #endif
#if defined(OS_LINUX) || defined(OS_CHROMEOS) #if defined(OS_LINUX) || defined(OS_CHROMEOS)
kChromeUIWebUIJsExceptionURL, kChromeUIWebUIJsErrorURL,
#endif #endif
kChromeUIQuitURL, kChromeUIQuitURL,
kChromeUIRestartURL}; kChromeUIRestartURL};
......
...@@ -294,8 +294,8 @@ bool IsSystemWebUIHost(base::StringPiece host); ...@@ -294,8 +294,8 @@ bool IsSystemWebUIHost(base::StringPiece host);
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
#if defined(OS_LINUX) || defined(OS_CHROMEOS) #if defined(OS_LINUX) || defined(OS_CHROMEOS)
extern const char kChromeUIWebUIJsExceptionHost[]; extern const char kChromeUIWebUIJsErrorHost[];
extern const char kChromeUIWebUIJsExceptionURL[]; extern const char kChromeUIWebUIJsErrorURL[];
#endif #endif
#if defined(OS_WIN) || defined(OS_MAC) || defined(OS_LINUX) || \ #if defined(OS_WIN) || defined(OS_MAC) || defined(OS_LINUX) || \
......
...@@ -259,9 +259,9 @@ ...@@ -259,9 +259,9 @@
"chrome/browser/resources/webapks/webapks_ui_resources.grd": { "chrome/browser/resources/webapks/webapks_ui_resources.grd": {
"includes": [2220], "includes": [2220],
}, },
"<(SHARED_INTERMEDIATE_DIR)/chrome/browser/resources/webui_js_exception/webui_js_exception_resources.grd": { "<(SHARED_INTERMEDIATE_DIR)/chrome/browser/resources/webui_js_error/webui_js_error_resources.grd": {
"META": {"sizes": {"includes": [10],}}, "META": {"sizes": {"includes": [10],}},
"includes": [2230], "includes": [2230],
}, },
"components/sync/driver/resources.grd": { "components/sync/driver/resources.grd": {
"includes": [2240], "includes": [2240],
......
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