Commit fcca93af authored by David's avatar David Committed by Commit Bot

Migrate crashReportPrivate to chrome/browser/extensions/api.

This is part of a series of changes to improve crash reporting for
chrome://media-app (& incidentally other clients of crashReportPrivate).

Design doc: go/backlight-better-crash-report

We need chrome/ dependencies for
* determining chrome window type (regular, app, SWA).
* solid testing for opening & closing devtools
https://chromium-review.googlesource.com/c/chromium/src/+/2465407/comment/90edd371_2e37132d/
(that cl will be rebased on this)
And once this is ported, it also makes sense to
* grab app locale from the browser process
* grab renderer uptime with a chrome dep

This also ports crashReportPrivate tests from extensions_browsertests
to browser_tests.

Change-Id: I4bc51f0cb69927ffb07d8045a82b180ed308590b
Bug: b/169635499
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2438099
Auto-Submit: David Lei <dlei@google.com>
Reviewed-by: default avatarIan Barkley-Yeung <iby@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarBen Wells <benwells@chromium.org>
Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Commit-Queue: David Lei <dlei@google.com>
Cr-Commit-Position: refs/heads/master@{#819088}
parent 72be9156
...@@ -99,7 +99,6 @@ no_check_targets = [ ...@@ -99,7 +99,6 @@ no_check_targets = [
"//extensions/browser/api/cast_channel:*", # 3 errors "//extensions/browser/api/cast_channel:*", # 3 errors
"//extensions/browser/api/cec_private:*", # 4 errors "//extensions/browser/api/cec_private:*", # 4 errors
"//extensions/browser/api/clipboard:*", # 3 errors "//extensions/browser/api/clipboard:*", # 3 errors
"//extensions/browser/api/crash_report_private:*", # 1 error
"//extensions/browser/api/declarative:*", # 20 errors "//extensions/browser/api/declarative:*", # 20 errors
"//extensions/browser/api/declarative_content:*", # 2 errors "//extensions/browser/api/declarative_content:*", # 2 errors
"//extensions/browser/api/declarative_net_request/filter_list_converter:*", # 1 "//extensions/browser/api/declarative_net_request/filter_list_converter:*", # 1
......
...@@ -947,6 +947,8 @@ static_library("extensions") { ...@@ -947,6 +947,8 @@ static_library("extensions") {
sources += [ sources += [
"api/certificate_provider/certificate_provider_api.cc", "api/certificate_provider/certificate_provider_api.cc",
"api/certificate_provider/certificate_provider_api.h", "api/certificate_provider/certificate_provider_api.h",
"api/crash_report_private/crash_report_private_api.cc",
"api/crash_report_private/crash_report_private_api.h",
"api/enterprise_device_attributes/enterprise_device_attributes_api.cc", "api/enterprise_device_attributes/enterprise_device_attributes_api.cc",
"api/enterprise_device_attributes/enterprise_device_attributes_api.h", "api/enterprise_device_attributes/enterprise_device_attributes_api.h",
"api/enterprise_networking_attributes/enterprise_networking_attributes_api.cc", "api/enterprise_networking_attributes/enterprise_networking_attributes_api.cc",
...@@ -1054,6 +1056,7 @@ static_library("extensions") { ...@@ -1054,6 +1056,7 @@ static_library("extensions") {
"//chromeos/ui/base", "//chromeos/ui/base",
"//components/arc", "//components/arc",
"//components/constrained_window", "//components/constrained_window",
"//components/crash/content/browser/error_reporting",
"//components/drive", "//components/drive",
"//components/user_manager", "//components/user_manager",
"//media/capture:capture_lib", "//media/capture:capture_lib",
......
include_rules = [ include_rules = [
"+components/crash/content/browser/error_reporting",
"+extensions/strings/grit/extensions_strings.h", "+extensions/strings/grit/extensions_strings.h",
"+services/network/public", "+services/network/public",
"+third_party/ink/grit", "+third_party/ink/grit",
......
...@@ -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 "extensions/browser/api/crash_report_private/crash_report_private_api.h" #include "chrome/browser/extensions/api/crash_report_private/crash_report_private_api.h"
#include "base/time/default_clock.h" #include "base/time/default_clock.h"
#include "components/crash/content/browser/error_reporting/javascript_error_report.h" #include "components/crash/content/browser/error_reporting/javascript_error_report.h"
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
// 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 EXTENSIONS_BROWSER_API_CRASH_REPORT_PRIVATE_CRASH_REPORT_PRIVATE_API_H_ #ifndef CHROME_BROWSER_EXTENSIONS_API_CRASH_REPORT_PRIVATE_CRASH_REPORT_PRIVATE_API_H_
#define EXTENSIONS_BROWSER_API_CRASH_REPORT_PRIVATE_CRASH_REPORT_PRIVATE_API_H_ #define CHROME_BROWSER_EXTENSIONS_API_CRASH_REPORT_PRIVATE_CRASH_REPORT_PRIVATE_API_H_
#include <string> #include <string>
#include "chrome/common/extensions/api/crash_report_private.h"
#include "extensions/browser/extension_function.h" #include "extensions/browser/extension_function.h"
#include "extensions/browser/extension_function_histogram_value.h" #include "extensions/browser/extension_function_histogram_value.h"
#include "extensions/common/api/crash_report_private.h"
namespace base { namespace base {
class Clock; class Clock;
...@@ -39,4 +39,4 @@ void SetClockForTesting(base::Clock* clock); ...@@ -39,4 +39,4 @@ void SetClockForTesting(base::Clock* clock);
} // namespace api } // namespace api
} // namespace extensions } // namespace extensions
#endif // EXTENSIONS_BROWSER_API_CRASH_REPORT_PRIVATE_CRASH_REPORT_PRIVATE_API_H_ #endif // CHROME_BROWSER_EXTENSIONS_API_CRASH_REPORT_PRIVATE_CRASH_REPORT_PRIVATE_API_H_
...@@ -4,20 +4,18 @@ ...@@ -4,20 +4,18 @@
#include "base/system/sys_info.h" #include "base/system/sys_info.h"
#include "base/test/simple_test_clock.h" #include "base/test/simple_test_clock.h"
#include "chrome/browser/extensions/api/crash_report_private/crash_report_private_api.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "components/crash/content/browser/error_reporting/mock_crash_endpoint.h" #include "components/crash/content/browser/error_reporting/mock_crash_endpoint.h"
#include "content/public/test/browser_task_environment.h" #include "content/public/test/browser_task_environment.h"
#include "extensions/browser/api/crash_report_private/crash_report_private_api.h" #include "content/public/test/browser_test.h"
#include "extensions/browser/browsertest_util.h"
#include "extensions/common/switches.h" #include "extensions/common/switches.h"
#include "extensions/shell/test/shell_apitest.h"
#include "extensions/test/extension_test_message_listener.h" #include "extensions/test/extension_test_message_listener.h"
#include "extensions/test/test_extension_dir.h" #include "extensions/test/test_extension_dir.h"
#include "testing/gmock/include/gmock/gmock-matchers.h" #include "testing/gmock/include/gmock/gmock-matchers.h"
namespace extensions { namespace extensions {
using browsertest_util::ExecuteScriptInBackgroundPage;
namespace { namespace {
using ::testing::MatchesRegex; using ::testing::MatchesRegex;
...@@ -36,13 +34,13 @@ std::string GetOsVersion() { ...@@ -36,13 +34,13 @@ std::string GetOsVersion() {
} // namespace } // namespace
class CrashReportPrivateApiTest : public ShellApiTest { class CrashReportPrivateApiTest : public ExtensionApiTest {
public: public:
CrashReportPrivateApiTest() = default; CrashReportPrivateApiTest() = default;
~CrashReportPrivateApiTest() override = default; ~CrashReportPrivateApiTest() override = default;
void SetUpOnMainThread() override { void SetUpOnMainThread() override {
ShellApiTest::SetUpOnMainThread(); ExtensionApiTest::SetUpOnMainThread();
constexpr char kKey[] = constexpr char kKey[] =
"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+uU63MD6T82Ldq5wjrDFn5mGmPnnnj" "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+uU63MD6T82Ldq5wjrDFn5mGmPnnnj"
...@@ -75,7 +73,7 @@ class CrashReportPrivateApiTest : public ShellApiTest { ...@@ -75,7 +73,7 @@ class CrashReportPrivateApiTest : public ShellApiTest {
void SetUpCommandLine(base::CommandLine* command_line) override { void SetUpCommandLine(base::CommandLine* command_line) override {
command_line->AppendSwitchASCII( command_line->AppendSwitchASCII(
extensions::switches::kAllowlistedExtensionID, kTestExtensionId); extensions::switches::kAllowlistedExtensionID, kTestExtensionId);
ShellApiTest::SetUpCommandLine(command_line); ExtensionApiTest::SetUpCommandLine(command_line);
} }
protected: protected:
...@@ -97,8 +95,7 @@ IN_PROC_BROWSER_TEST_F(CrashReportPrivateApiTest, Basic) { ...@@ -97,8 +95,7 @@ IN_PROC_BROWSER_TEST_F(CrashReportPrivateApiTest, Basic) {
}, },
() => window.domAutomationController.send("")); () => window.domAutomationController.send(""));
)"; )";
ExecuteScriptInBackgroundPage(browser_context(), extension_->id(), ExecuteScriptInBackgroundPage(extension_->id(), kTestScript);
kTestScript);
const base::Optional<MockCrashEndpoint::Report>& report = last_report(); const base::Optional<MockCrashEndpoint::Report>& report = last_report();
ASSERT_TRUE(report); ASSERT_TRUE(report);
...@@ -127,8 +124,7 @@ IN_PROC_BROWSER_TEST_F(CrashReportPrivateApiTest, ExtraParamsAndStackTrace) { ...@@ -127,8 +124,7 @@ IN_PROC_BROWSER_TEST_F(CrashReportPrivateApiTest, ExtraParamsAndStackTrace) {
}, },
() => window.domAutomationController.send("")); () => window.domAutomationController.send(""));
)-"; )-";
ExecuteScriptInBackgroundPage(browser_context(), extension_->id(), ExecuteScriptInBackgroundPage(extension_->id(), kTestScript);
kTestScript);
const base::Optional<MockCrashEndpoint::Report>& report = last_report(); const base::Optional<MockCrashEndpoint::Report>& report = last_report();
ASSERT_TRUE(report); ASSERT_TRUE(report);
...@@ -160,8 +156,7 @@ IN_PROC_BROWSER_TEST_F(CrashReportPrivateApiTest, StackTraceWithErrorMessage) { ...@@ -160,8 +156,7 @@ IN_PROC_BROWSER_TEST_F(CrashReportPrivateApiTest, StackTraceWithErrorMessage) {
}, },
() => window.domAutomationController.send("")); () => window.domAutomationController.send(""));
)"; )";
ExecuteScriptInBackgroundPage(browser_context(), extension_->id(), ExecuteScriptInBackgroundPage(extension_->id(), kTestScript);
kTestScript);
const base::Optional<MockCrashEndpoint::Report>& report = last_report(); const base::Optional<MockCrashEndpoint::Report>& report = last_report();
ASSERT_TRUE(report); ASSERT_TRUE(report);
...@@ -192,8 +187,7 @@ IN_PROC_BROWSER_TEST_F(CrashReportPrivateApiTest, RedactMessage) { ...@@ -192,8 +187,7 @@ IN_PROC_BROWSER_TEST_F(CrashReportPrivateApiTest, RedactMessage) {
}, },
() => window.domAutomationController.send("")); () => window.domAutomationController.send(""));
)"; )";
ExecuteScriptInBackgroundPage(browser_context(), extension_->id(), ExecuteScriptInBackgroundPage(extension_->id(), kTestScript);
kTestScript);
const base::Optional<MockCrashEndpoint::Report>& report = last_report(); const base::Optional<MockCrashEndpoint::Report>& report = last_report();
ASSERT_TRUE(report); ASSERT_TRUE(report);
...@@ -228,20 +222,17 @@ IN_PROC_BROWSER_TEST_F(CrashReportPrivateApiTest, Throttling) { ...@@ -228,20 +222,17 @@ IN_PROC_BROWSER_TEST_F(CrashReportPrivateApiTest, Throttling) {
api::SetClockForTesting(&test_clock); api::SetClockForTesting(&test_clock);
// Use an exact time for the first API call. // Use an exact time for the first API call.
EXPECT_EQ("", ExecuteScriptInBackgroundPage(browser_context(), EXPECT_EQ("", ExecuteScriptInBackgroundPage(extension_->id(), kTestScript));
extension_->id(), kTestScript));
// API is limited to one call per hr. So pretend the second call is just // API is limited to one call per hr. So pretend the second call is just
// before 1 hr. // before 1 hr.
test_clock.Advance(base::TimeDelta::FromMinutes(59)); test_clock.Advance(base::TimeDelta::FromMinutes(59));
EXPECT_EQ("Too many calls to this API", EXPECT_EQ("Too many calls to this API",
ExecuteScriptInBackgroundPage(browser_context(), extension_->id(), ExecuteScriptInBackgroundPage(extension_->id(), kTestScript));
kTestScript));
// Call again after 1 hr. // Call again after 1 hr.
test_clock.Advance(base::TimeDelta::FromMinutes(2)); test_clock.Advance(base::TimeDelta::FromMinutes(2));
EXPECT_EQ("", ExecuteScriptInBackgroundPage(browser_context(), EXPECT_EQ("", ExecuteScriptInBackgroundPage(extension_->id(), kTestScript));
extension_->id(), kTestScript));
} }
// Ensures that reportError checks user consent for data collection on the // Ensures that reportError checks user consent for data collection on the
...@@ -259,8 +250,7 @@ IN_PROC_BROWSER_TEST_F(CrashReportPrivateApiTest, NoConsent) { ...@@ -259,8 +250,7 @@ IN_PROC_BROWSER_TEST_F(CrashReportPrivateApiTest, NoConsent) {
)"; )";
crash_endpoint_->set_consented(false); crash_endpoint_->set_consented(false);
EXPECT_EQ("", ExecuteScriptInBackgroundPage(browser_context(), EXPECT_EQ("", ExecuteScriptInBackgroundPage(extension_->id(), kTestScript));
extension_->id(), kTestScript));
// The server should not receive any reports. // The server should not receive any reports.
const base::Optional<MockCrashEndpoint::Report>& report = last_report(); const base::Optional<MockCrashEndpoint::Report>& report = last_report();
EXPECT_FALSE(report); EXPECT_FALSE(report);
......
...@@ -261,6 +261,28 @@ ...@@ -261,6 +261,28 @@
"dependencies": ["permission:cookies"], "dependencies": ["permission:cookies"],
"contexts": ["blessed_extension"] "contexts": ["blessed_extension"]
}, },
"crashReportPrivate": [{
"dependencies": ["permission:crashReportPrivate"],
"contexts": ["blessed_extension"],
"default_parent": true
},
{
"channel": "stable",
"contexts": [
"webui"
],
"matches": [
"chrome://media-app/*"
]
},
{
"channel": "stable",
"contexts": ["webui_untrusted"],
"matches": [
"chrome-untrusted://help-app/*",
"chrome-untrusted://media-app/*"
]
}],
"cryptotokenPrivate": { "cryptotokenPrivate": {
"dependencies": ["permission:cryptotokenPrivate"], "dependencies": ["permission:cryptotokenPrivate"],
"contexts": ["blessed_extension"] "contexts": ["blessed_extension"]
......
...@@ -180,6 +180,17 @@ ...@@ -180,6 +180,17 @@
"channel": "stable", "channel": "stable",
"extension_types": ["extension", "legacy_packaged_app"] "extension_types": ["extension", "legacy_packaged_app"]
}, },
"crashReportPrivate": {
"channel": "dev",
"extension_types": ["extension", "legacy_packaged_app", "platform_app"],
"whitelist": [
"0EA6B717932AD64C469C1CCB6911457733295907", // Secure Shell App (stable)
"58B0C2968C335964D5433E89CA4D86628A0E3D4B", // Secure Shell App (dev)
"3BC1ED0B3E6EFDC7BD4D3D1D75D44B52DEE0A226", // Secure Shell Ext (stable)
"38C361D4A0726CE45D3572D65071B6BDB3092371", // Secure Shell Ext (dev)
"06BE211D5F014BAB34BC22D9DDA09C63A81D828E" // http://crbug.com/946241
]
},
"cryptotokenPrivate": { "cryptotokenPrivate": {
"channel": "stable", "channel": "stable",
"extension_types": ["extension"], "extension_types": ["extension"],
......
...@@ -29,6 +29,7 @@ schema_sources_ = [ ...@@ -29,6 +29,7 @@ schema_sources_ = [
"debugger.json", "debugger.json",
"desktop_capture.json", "desktop_capture.json",
"developer_private.idl", "developer_private.idl",
"crash_report_private.idl",
"downloads.idl", "downloads.idl",
"downloads_internal.idl", "downloads_internal.idl",
"enterprise_hardware_platform.idl", "enterprise_hardware_platform.idl",
......
...@@ -6,6 +6,7 @@ autofill_private.idl ...@@ -6,6 +6,7 @@ autofill_private.idl
bookmark_manager_private.json bookmark_manager_private.json
chromeos_info_private.json chromeos_info_private.json
command_line_private.json command_line_private.json
crash_report_private.idl
developer_private.idl developer_private.idl
file_manager_private.idl file_manager_private.idl
file_system_provider.idl file_system_provider.idl
......
...@@ -2085,6 +2085,7 @@ if (!is_android) { ...@@ -2085,6 +2085,7 @@ if (!is_android) {
"../browser/accessibility/accessibility_extension_api_browsertest.cc", "../browser/accessibility/accessibility_extension_api_browsertest.cc",
"../browser/apps/platform_apps/api/arc_apps_private/arc_apps_private_apitest.cc", "../browser/apps/platform_apps/api/arc_apps_private/arc_apps_private_apitest.cc",
"../browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_apitest_chromeos.cc", "../browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_apitest_chromeos.cc",
"../browser/extensions/api/crash_report_private/crash_report_private_apitest.cc",
"../browser/extensions/api/enterprise_device_attributes/enterprise_device_attributes_apitest.cc", "../browser/extensions/api/enterprise_device_attributes/enterprise_device_attributes_apitest.cc",
"../browser/extensions/api/enterprise_networking_attributes/enterprise_networking_attributes_apitest.cc", "../browser/extensions/api/enterprise_networking_attributes/enterprise_networking_attributes_apitest.cc",
"../browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_apitest_nss.cc", "../browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_apitest_nss.cc",
......
...@@ -517,7 +517,6 @@ source_set("browser_tests") { ...@@ -517,7 +517,6 @@ source_set("browser_tests") {
sources += [ sources += [
"api/audio/audio_apitest_chromeos.cc", "api/audio/audio_apitest_chromeos.cc",
"api/cec_private/cec_private_apitest.cc", "api/cec_private/cec_private_apitest.cc",
"api/crash_report_private/crash_report_private_apitest.cc",
"api/media_perception_private/media_perception_private_apitest.cc", "api/media_perception_private/media_perception_private_apitest.cc",
"api/system_power_source/system_power_source_apitest.cc", "api/system_power_source/system_power_source_apitest.cc",
"api/virtual_keyboard/virtual_keyboard_apitest.cc", "api/virtual_keyboard/virtual_keyboard_apitest.cc",
......
...@@ -130,7 +130,6 @@ source_set("api") { ...@@ -130,7 +130,6 @@ source_set("api") {
public_deps += [ public_deps += [
"//extensions/browser/api/cec_private", "//extensions/browser/api/cec_private",
"//extensions/browser/api/clipboard", "//extensions/browser/api/clipboard",
"//extensions/browser/api/crash_report_private",
"//extensions/browser/api/diagnostics", "//extensions/browser/api/diagnostics",
"//extensions/browser/api/system_power_source", "//extensions/browser/api/system_power_source",
"//extensions/browser/api/virtual_keyboard", "//extensions/browser/api/virtual_keyboard",
......
# Copyright 2019 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("//extensions/buildflags/buildflags.gni")
assert(enable_extensions,
"Cannot depend on extensions because enable_extensions=false.")
source_set("crash_report_private") {
sources = [
"crash_report_private_api.cc",
"crash_report_private_api.h",
]
deps = [
"//components/crash/content/browser/error_reporting",
"//content/public/browser",
"//extensions/common/api",
]
}
include_rules = [
"+components/crash/content/browser/error_reporting",
]
...@@ -136,28 +136,6 @@ ...@@ -136,28 +136,6 @@
"clipboard.setImageData": { "clipboard.setImageData": {
"dependencies": ["permission:clipboardWrite"] "dependencies": ["permission:clipboardWrite"]
}, },
"crashReportPrivate": [{
"dependencies": ["permission:crashReportPrivate"],
"contexts": ["blessed_extension"],
"default_parent": true
},
{
"channel": "stable",
"contexts": [
"webui"
],
"matches": [
"chrome://media-app/*"
]
},
{
"channel": "stable",
"contexts": ["webui_untrusted"],
"matches": [
"chrome-untrusted://help-app/*",
"chrome-untrusted://media-app/*"
]
}],
"declarativeNetRequest": { "declarativeNetRequest": {
"dependencies": ["permission:declarativeNetRequest"], "dependencies": ["permission:declarativeNetRequest"],
"contexts": ["blessed_extension"] "contexts": ["blessed_extension"]
......
...@@ -199,17 +199,6 @@ ...@@ -199,17 +199,6 @@
"extension_types": ["platform_app"], "extension_types": ["platform_app"],
"platforms": ["chromeos"] "platforms": ["chromeos"]
}, },
"crashReportPrivate": {
"channel": "dev",
"extension_types": ["extension", "legacy_packaged_app", "platform_app"],
"whitelist": [
"0EA6B717932AD64C469C1CCB6911457733295907", // Secure Shell App (stable)
"58B0C2968C335964D5433E89CA4D86628A0E3D4B", // Secure Shell App (dev)
"3BC1ED0B3E6EFDC7BD4D3D1D75D44B52DEE0A226", // Secure Shell Ext (stable)
"38C361D4A0726CE45D3572D65071B6BDB3092371", // Secure Shell Ext (dev)
"06BE211D5F014BAB34BC22D9DDA09C63A81D828E" // http://crbug.com/946241
]
},
"declarativeNetRequest": { "declarativeNetRequest": {
"channel": "stable", "channel": "stable",
"extension_types": ["extension"], "extension_types": ["extension"],
......
...@@ -5,7 +5,6 @@ automation.idl ...@@ -5,7 +5,6 @@ automation.idl
bluetooth.idl bluetooth.idl
bluetooth_private.idl bluetooth_private.idl
clipboard.idl clipboard.idl
crash_report_private.idl
management.json management.json
metrics_private.json metrics_private.json
mime_handler_private.idl mime_handler_private.idl
......
...@@ -66,7 +66,6 @@ extensions_manifest_only_schema_files_ = [ ...@@ -66,7 +66,6 @@ extensions_manifest_only_schema_files_ = [
if (is_chromeos) { if (is_chromeos) {
extensions_api_schema_files_ += [ extensions_api_schema_files_ += [
"crash_report_private.idl",
"diagnostics.idl", "diagnostics.idl",
"lock_screen_data.idl", "lock_screen_data.idl",
"media_perception_private.idl", "media_perception_private.idl",
......
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