chromium/chrome/browser/error_reporting/webui_js_error_reporting_browsertest.cc

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <memory>

#include "base/containers/contains.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/error_reporting/mock_chrome_js_error_report_processor.h"
#include "chrome/browser/prefs/session_startup_pref.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sessions/session_service_factory.h"
#include "chrome/browser/sessions/session_service_test_helper.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/crash/content/browser/error_reporting/mock_crash_endpoint.h"
#include "components/keep_alive_registry/keep_alive_types.h"
#include "components/keep_alive_registry/scoped_keep_alive.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_response.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/page_transition_types.h"
#include "ui/events/keycodes/dom/dom_code.h"
#include "ui/events/keycodes/dom/dom_key.h"
#include "ui/events/keycodes/keyboard_codes.h"

Contains;
Field;
HasSubstr;
SizeIs;

namespace {
// Must match message in
// chrome/browser/resources/webui_js_error/webui_js_error.js, but with URL
// escapes.
constexpr char kPageLoadMessage[] =;

// A simple webpage that generates a JavaScript error on load.
constexpr char kJavaScriptErrorPage[] =;

// The error message printed by kJavaScriptErrorPage
constexpr char kWebpageErrorMessage[] =;

// Callback for the error_page_test_server_. Tells the server to always return
// the contents of kJavaScriptErrorPage.
std::unique_ptr<net::test_server::HttpResponse> ReturnErrorPage(
    const net::test_server::HttpRequest&) {}

// A class that waits for a log message like
//  [4193947:4193947:0108/114152.942981:INFO:CONSOLE(10)] "special error message
//  for WebUIJSErrorReportingTest", source: http://127.0.0.1:36521/index.html
//  (10)
// to appear and then calls a callback (usually a RunLoop quit closure)
class ScopedLogMessageWatcher {};
ScopedLogMessageWatcher* ScopedLogMessageWatcher::current_handler_ =;
}  // namespace

class WebUIJSErrorReportingTest : public InProcessBrowserTest {};

IN_PROC_BROWSER_TEST_F(WebUIJSErrorReportingTest, ReportsErrors) {}

// Set up a profile with "Continue where you left off". Navigate to the JS error
// page. Ensure that when the browser is closed and reopened, on-page-load
// errors are still reported.
IN_PROC_BROWSER_TEST_F(WebUIJSErrorReportingTest,
                       ReportsErrorsDuringContinueWhereYouLeftOff) {}

// Show that navigating from a WebUI page to a http page that produces
// JavaScript errors on load does not create an error report.
IN_PROC_BROWSER_TEST_F(WebUIJSErrorReportingTest, NoErrorsAfterNavigation) {}

// Test that using the real variation::GetExperimentListString() system works.
// We don't know the list of experiments we are in, so we don't know precisely
// what to expect, but we shouldn't fail to send.
IN_PROC_BROWSER_TEST_F(WebUIJSErrorReportingTest, ExperimentListSmokeTest) {}