Skip to content

Commit

Permalink
Add chrome://webuijsexception debugging page
Browse files Browse the repository at this point in the history
Add a debugging chrome:// URL that loads a page with JavaScript that
just throws some exceptions. This will be used to test the WebUI
JavaScript Error Reporting feature, both manually and in integration
tests.

This page is currently Linux + Chrome OS only. It may be added to
Windows in a future CL if https://crbug.com/1129544 is fixed and
the general WebUI JS Error Reporting feature gets Windows support.

Bug: chromium:1121816

Change-Id: I3d7e29c15d6af9a863b023d900ced5d8c542d12d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2473157
Reviewed-by: Nico Weber <thakis@chromium.org>
Reviewed-by: Kyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Ian Barkley-Yeung <iby@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818036}
  • Loading branch information
ianby authored and Commit Bot committed Oct 16, 2020
1 parent 1c2c60b commit 67d4b9b
Show file tree
Hide file tree
Showing 15 changed files with 319 additions and 0 deletions.
4 changes: 4 additions & 0 deletions chrome/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,10 @@ group("extra_resources") {
]
}

if (is_linux || is_chromeos) {
public_deps += [ "//chrome/browser/resources:webui_js_exception_resources" ]
}

if (!is_android && !is_chromeos) {
public_deps += [
"//chrome/browser/resources:profile_picker_resources",
Expand Down
30 changes: 30 additions & 0 deletions chrome/browser/resources/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ if (enable_js_type_check) {
if (is_win || is_android || is_linux || is_chromeos) {
deps += [ "sandbox_internals:closure_compile" ]
}
if (is_linux || is_chromeos) {
deps += [ "webui_js_exception:closure_compile" ]
}
if (is_chromeos) {
deps += [
"chromeos:closure_compile",
Expand Down Expand Up @@ -690,6 +693,33 @@ if (enable_webui_tab_strip) {
}
}

if (is_linux || is_chromeos) {
grit("webui_js_exception_resources") {
if (optimize_webui) {
source = "webui_js_exception/webui_js_exception_resources_vulcanized.grd"
deps = [ "//chrome/browser/resources/webui_js_exception:build" ]
} else {
source = "webui_js_exception/webui_js_exception_resources.grd"
deps =
[ "//chrome/browser/resources/webui_js_exception:webui_js_exception" ]
}

grit_flags = [
"-E",
"root_gen_dir=" + rebase_path(root_gen_dir, root_build_dir),
]

defines = chrome_grit_defines
outputs = [
"grit/webui_js_exception_resources.h",
"grit/webui_js_exception_resources_map.cc",
"grit/webui_js_exception_resources_map.h",
"webui_js_exception_resources.pak",
]
output_dir = "$root_gen_dir/chrome"
}
}

repack("dev_ui_paks") {
output = "$root_gen_dir/chrome/dev_ui_resources.pak"

Expand Down
54 changes: 54 additions & 0 deletions chrome/browser/resources/webui_js_exception/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 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.

import("//chrome/browser/resources/optimize_webui.gni")
import("//third_party/closure_compiler/compile_js.gni")
import("//tools/grit/grit_rule.gni")
import("//ui/webui/webui_features.gni")

js_library("webui_js_exception") {
}

if (optimize_webui) {
grit("flattened_resources") {
source = "webui_js_exception_resources.grd"

deps = [ ":webui_js_exception" ]

grit_flags = [
"-E",
"root_gen_dir=" + rebase_path(root_gen_dir, root_build_dir),
]

outputs = [
"grit/webui_js_exception_resources.h",
"grit/webui_js_exception_resources_map.cc",
"grit/webui_js_exception_resources_map.h",
"webui_js_exception_resources.pak",
]
output_dir = "$root_gen_dir/chrome/browser/resources/webui_js_exception"
}

unpak("unpak") {
pak_file = "webui_js_exception_resources.pak"
out_folder = "unpak"
deps = [ ":flattened_resources" ]
}

optimize_webui("build") {
host = "webui_js_exception"
input = rebase_path("$target_gen_dir/unpak", root_build_dir)
deps = [
":unpak",
"//ui/webui/resources:modulize",
]
js_module_in_files = [ "webui_js_exception.js" ]
js_out_files = [ "webui_js_exception.rollup.js" ]
excludes = [ "chrome://resources/js/cr.m.js" ]
}
}

js_type_check("closure_compile") {
deps = [ ":webui_js_exception" ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<!-- Title is not localized since this is just a debugging page -->
<title>WebUI JS Exception Page</title>
<style>
html,
body {
height: 100%;
overflow: hidden;
}

body {
margin: 0;
}
</style>
</head>
<body>
<!-- Text not localized since this is just a debugging page -->
This page generates a JavaScript exception on load and then another 3
seconds later.
<script type="module" src="webui_js_exception.js"></script>
</body>
</html>
45 changes: 45 additions & 0 deletions chrome/browser/resources/webui_js_exception/webui_js_exception.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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();
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<grit latest_public_release="0" current_release="1" output_all_resource_defines="false">
<outputs>
<output filename="grit/webui_js_exception_resources.h" type="rc_header">
<emit emit_type='prepend'></emit>
</output>
<output filename="grit/webui_js_exception_resources_map.cc"
type="resource_file_map_source" />
<output filename="grit/webui_js_exception_resources_map.h"
type="resource_map_header" />
<output filename="webui_js_exception_resources.pak" type="data_package" />
</outputs>
<release seq="1">
<structures>
<structure name="IDR_WEBUI_JS_EXCEPTION_UI_WEBUI_JS_EXCEPTION_JS"
file="webui_js_exception.js" type="chrome_html" compress="false" />
<structure name="IDR_WEBUI_JS_EXCEPTION_UI_WEBUI_JS_EXCEPTION_HTML"
file="webui_js_exception.html" type="chrome_html" compress="false" />
</structures>
</release>
</grit>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<grit latest_public_release="0" current_release="1" output_all_resource_defines="false">
<outputs>
<output filename="grit/webui_js_exception_resources.h" type="rc_header">
<emit emit_type='prepend'></emit>
</output>
<output filename="grit/webui_js_exception_resources_map.cc"
type="resource_map_source" />
<output filename="grit/webui_js_exception_resources_map.h"
type="resource_map_header" />
<output filename="webui_js_exception_resources.pak" type="data_package" />
</outputs>
<release seq="1">
<includes>
<include name="IDR_WEBUI_JS_EXCEPTION_UI_WEBUI_JS_EXCEPTION_ROLLUP_JS"
file="${root_gen_dir}/chrome/browser/resources/webui_js_exception/webui_js_exception.rollup.js"
use_base_dir="false" type="BINDATA" />
<include name="IDR_WEBUI_JS_EXCEPTION_UI_WEBUI_JS_EXCEPTION_HTML"
file="webui_js_exception.html" preprocess="true" type="BINDATA" />
</includes>
</release>
</grit>
2 changes: 2 additions & 0 deletions chrome/browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -3296,6 +3296,8 @@ static_library("ui") {
"webui/certificate_viewer_ui.h",
"webui/certificate_viewer_webui.cc",
"webui/certificate_viewer_webui.h",
"webui/webui_js_exception/webui_js_exception_ui.cc",
"webui/webui_js_exception/webui_js_exception_ui.h",
]
if (use_aura) {
deps += [ "//third_party/fontconfig" ]
Expand Down
8 changes: 8 additions & 0 deletions chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@
#include "chrome/browser/ui/webui/app_launcher_page_ui.h"
#endif

#if defined(OS_LINUX) || defined(OS_CHROMEOS)
#include "chrome/browser/ui/webui/webui_js_exception/webui_js_exception_ui.h"
#endif

#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
#include "chrome/browser/ui/sync/sync_promo_ui.h"
#include "chrome/browser/ui/webui/browser_switch/browser_switch_ui.h"
Expand Down Expand Up @@ -751,6 +755,10 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
}
#endif // !defined(OFFICIAL_BUILD)
#endif // defined(OS_CHROMEOS)
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
if (url.host_piece() == chrome::kChromeUIWebUIJsExceptionHost)
return &NewWebUI<WebUIJsExceptionUI>;
#endif
#if defined(OS_ANDROID)
if (url.host_piece() == chrome::kChromeUIExploreSitesInternalsHost &&
!profile->IsOffTheRecord())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// 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.

#include "chrome/browser/ui/webui/webui_js_exception/webui_js_exception_ui.h"

#include <ios>

#include "base/feature_list.h"
#include "base/logging.h"
#include "build/build_config.h"
#include "build/buildflag.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/webui_util.h"
#include "chrome/common/buildflags.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/grit/webui_js_exception_resources.h"
#include "chrome/grit/webui_js_exception_resources_map.h"
#include "content/public/browser/web_ui_data_source.h"
#include "content/public/common/content_features.h"

#if !BUILDFLAG(OPTIMIZE_WEBUI)
namespace {
constexpr char kGeneratedPath[] =
"@out_folder@/gen/chrome/browser/resources/webui_js_exception/";
} // namespace
#endif // !BUILDFLAG(OPTIMIZE_WEBUI)

WebUIJsExceptionUI::WebUIJsExceptionUI(content::WebUI* web_ui)
: content::WebUIController(web_ui) {
#if !defined(OS_WIN) && !defined(OS_FUCHSIA)
VLOG(3) << std::boolalpha << "chrome://webuijsexception loading. "
<< "Experiment state: send javascript errors is "
<< base::FeatureList::IsEnabled(
features::kSendWebUIJavaScriptErrorReports)
<< " and send to prod is "
<< features::kWebUIJavaScriptErrorReportsSendToProductionParam.Get();
#else
VLOG(3) << std::boolalpha << "chrome://webuijsexception loading.";
#endif

content::WebUIDataSource* source =
content::WebUIDataSource::Create(chrome::kChromeUIWebUIJsExceptionHost);
#if BUILDFLAG(OPTIMIZE_WEBUI)
webui::SetupBundledWebUIDataSource(
source, "webui_js_exception.js",
IDR_WEBUI_JS_EXCEPTION_UI_WEBUI_JS_EXCEPTION_ROLLUP_JS,
IDR_WEBUI_JS_EXCEPTION_UI_WEBUI_JS_EXCEPTION_HTML);
#else // if !BUILDFLAG(OPTIMIZE_WEBUI)
webui::SetupWebUIDataSource(
source,
base::make_span(kWebuiJsExceptionResources,
kWebuiJsExceptionResourcesSize),
kGeneratedPath, IDR_WEBUI_JS_EXCEPTION_UI_WEBUI_JS_EXCEPTION_HTML);
#endif // !BUILDFLAG(OPTIMIZE_WEBUI)
Profile* profile = Profile::FromWebUI(web_ui);
content::WebUIDataSource::Add(profile, source);
}

WebUIJsExceptionUI::~WebUIJsExceptionUI() = default;

WEB_UI_CONTROLLER_TYPE_IMPL(WebUIJsExceptionUI)
22 changes: 22 additions & 0 deletions chrome/browser/ui/webui/webui_js_exception/webui_js_exception_ui.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.

#ifndef CHROME_BROWSER_UI_WEBUI_WEBUI_JS_EXCEPTION_WEBUI_JS_EXCEPTION_UI_H_
#define CHROME_BROWSER_UI_WEBUI_WEBUI_JS_EXCEPTION_WEBUI_JS_EXCEPTION_UI_H_

#include "content/public/browser/web_ui_controller.h"

// The WebUI that controls chrome://webuijsexception.
class WebUIJsExceptionUI : public content::WebUIController {
public:
explicit WebUIJsExceptionUI(content::WebUI* web_ui);
~WebUIJsExceptionUI() override;
WebUIJsExceptionUI(const WebUIJsExceptionUI&) = delete;
WebUIJsExceptionUI& operator=(const WebUIJsExceptionUI&) = delete;

private:
WEB_UI_CONTROLLER_TYPE_DECL();
};

#endif // CHROME_BROWSER_UI_WEBUI_WEBUI_JS_EXCEPTION_WEBUI_JS_EXCEPTION_UI_H_
4 changes: 4 additions & 0 deletions chrome/chrome_paks.gni
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ template("chrome_extra_paks") {
]
}
}
if (is_linux || is_chromeos) {
sources += [ "$root_gen_dir/chrome/webui_js_exception_resources.pak" ]
deps += [ "//chrome/browser/resources:webui_js_exception_resources" ]
}
if (!is_android && !is_chromeos) {
sources += [
"$root_gen_dir/chrome/profile_picker_resources.pak",
Expand Down
8 changes: 8 additions & 0 deletions chrome/common/webui_url_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,11 @@ bool IsSystemWebUIHost(base::StringPiece host) {
}
#endif // defined(OS_CHROMEOS)

#if defined(OS_LINUX) || defined(OS_CHROMEOS)
const char kChromeUIWebUIJsExceptionHost[] = "webuijsexception";
const char kChromeUIWebUIJsExceptionURL[] = "chrome://webuijsexception/";
#endif

#if defined(OS_WIN) || defined(OS_MAC) || defined(OS_LINUX) || \
defined(OS_CHROMEOS)
const char kChromeUIDiscardsHost[] = "discards";
Expand Down Expand Up @@ -608,6 +613,9 @@ const char* const kChromeDebugURLs[] = {
#if defined(OS_ANDROID)
content::kChromeUIGpuJavaCrashURL,
kChromeUIJavaCrashURL,
#endif
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
kChromeUIWebUIJsExceptionURL,
#endif
kChromeUIQuitURL,
kChromeUIRestartURL};
Expand Down
5 changes: 5 additions & 0 deletions chrome/common/webui_url_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ bool IsSystemWebUIHost(base::StringPiece host);

#endif // defined(OS_CHROMEOS)

#if defined(OS_LINUX) || defined(OS_CHROMEOS)
extern const char kChromeUIWebUIJsExceptionHost[];
extern const char kChromeUIWebUIJsExceptionURL[];
#endif

#if defined(OS_WIN) || defined(OS_MAC) || defined(OS_LINUX) || \
defined(OS_CHROMEOS)
extern const char kChromeUIDiscardsHost[];
Expand Down
Loading

0 comments on commit 67d4b9b

Please sign in to comment.