Commit e36abea9 authored by Jimmy Gong's avatar Jimmy Gong Committed by Commit Bot

Add skeleton PWA for Diagnostics app

- Boiler plate template for the diagnostics app.
- Future CL will covert this to an SWA.

Bug: 1120206
Test: browser_tests
Change-Id: Iae3851ba82859b4a202ea4df1a416c13127b9cda
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2377405Reviewed-by: default avatarSamuel Huang <huangs@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Jimmy Gong <jimmyxgong@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803222}
parent 75cc5300
......@@ -2550,6 +2550,7 @@ static_library("ui") {
"//chromeos/components/bloom/public/cpp",
"//chromeos/components/bloom/public/cpp:bloom_controller_factory",
"//chromeos/components/camera_app_ui",
"//chromeos/components/diagnostics_ui",
"//chromeos/components/help_app_ui",
"//chromeos/components/local_search_service:local_search_service",
"//chromeos/components/media_app_ui",
......
......@@ -195,6 +195,8 @@
#include "chrome/browser/ui/webui/settings/chromeos/os_settings_ui.h"
#include "chromeos/components/camera_app_ui/camera_app_ui.h"
#include "chromeos/components/camera_app_ui/url_constants.h"
#include "chromeos/components/diagnostics_ui/diagnostics_ui.h"
#include "chromeos/components/diagnostics_ui/url_constants.h"
#include "chromeos/components/help_app_ui/help_app_ui.h"
#include "chromeos/components/help_app_ui/url_constants.h"
#include "chromeos/components/media_app_ui/media_app_guest_ui.h"
......@@ -649,6 +651,10 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
return &NewWebUI<chromeos::settings::OSSettingsUI>;
if (url.host_piece() == chrome::kChromeUIPowerHost)
return &NewWebUI<chromeos::PowerUI>;
if (base::FeatureList::IsEnabled(chromeos::features::kDiagnosticsApp) &&
url.host_piece() == chromeos::kChromeUIDiagnosticsAppHost) {
return &NewWebUI<chromeos::DiagnosticsUI>;
}
if (base::FeatureList::IsEnabled(
chromeos::features::kPrintJobManagementApp) &&
url.host_piece() == chromeos::kChromeUIPrintManagementHost)
......
......@@ -45,6 +45,7 @@ source_set("common") {
if (is_chromeos) {
deps += [
"//ash/public/cpp",
"//chromeos/components/diagnostics_ui",
"//chromeos/components/help_app_ui",
"//chromeos/components/media_app_ui",
"//chromeos/components/print_management",
......
......@@ -172,6 +172,7 @@ template("chrome_extra_paks") {
"$root_gen_dir/chrome/nearby_shared_resources_v3.pak",
"$root_gen_dir/chrome/os_settings_resources.pak",
"$root_gen_dir/chromeos/chromeos_camera_app_resources.pak",
"$root_gen_dir/chromeos/chromeos_diagnostics_app_resources.pak",
"$root_gen_dir/chromeos/chromeos_help_app_bundle_resources.pak",
"$root_gen_dir/chromeos/chromeos_help_app_resources.pak",
"$root_gen_dir/chromeos/chromeos_media_app_bundle_resources.pak",
......@@ -194,6 +195,7 @@ template("chrome_extra_paks") {
"//chrome/browser/supervised_user:supervised_user_unscaled_resources",
"//chromeos/resources",
"//chromeos/resources:camera_app_resources",
"//chromeos/resources:diagnostics_app_resources",
"//chromeos/resources:help_app_bundle_resources",
"//chromeos/resources:help_app_resources",
"//chromeos/resources:media_app_bundle_resources",
......
......@@ -338,6 +338,7 @@ if (include_js_tests) {
sources += [
"chromeos/crostini_installer_browsertest.js",
"chromeos/crostini_upgrader_browsertest.js",
"chromeos/diagnostics/diagnostics_browsertest.js",
"chromeos/machine_learning_internals_browsertest.js",
"chromeos/print_management/print_management_browsertest.js",
"chromeos/scanning/scanning_app_browsertest.js",
......
// 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 Test suite for chrome://diagnostics.
*/
GEN_INCLUDE(['//chrome/test/data/webui/polymer_browser_test_base.js']);
GEN('#include "chromeos/constants/chromeos_features.h"');
GEN('#include "content/public/test/browser_test.h"');
[['DiagnosticsApp', 'diagnostics/diagnostics_test.js']].forEach(
test => registerTest(...test));
function registerTest(testName, module) {
const className = `${testName}BrowserTest`;
this[className] = class extends PolymerTest {
/** @override */
get browsePreload() {
return `chrome://diagnostics/test_loader.html?module=chromeos/${module}`;
}
/** @override */
get extraLibraries() {
return [
'//third_party/mocha/mocha.js',
'//chrome/test/data/webui/mocha_adapter.js',
];
}
/** @override */
get featureList() {
return {
enabled: [
'chromeos::features::kDiagnosticsApp',
],
};
}
};
TEST_F(className, 'All', () => mocha.run());
}
// 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.
// TODO(jimmyxgong): Use es6 module for mojo binding (crbug/1004256).
import 'chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js';
import 'chrome://diagnostics/diagnostics_app.js';
suite('DiagnosticsAppTest', () => {
/** @type {?DiagnosticsApp} */
let page = null;
setup(function() {
PolymerTest.clearBody();
page = document.createElement('diagnostics-app');
document.body.appendChild(page);
});
teardown(function() {
page.remove();
page = null;
});
test('LandingPageLoaded', () => {
// TODO(jimmyxgong): Remove this stub test once the page has more
// capabilities to test.
assertEquals('Diagnostics', page.$$('#header').textContent);
});
});
\ No newline at end of file
......@@ -45,6 +45,7 @@ group("closure_compile") {
testonly = true
deps = [
"//chromeos/components/camera_app_ui:closure_compile",
"//chromeos/components/diagnostics_ui:closure_compile",
"//chromeos/components/help_app_ui:closure_compile",
"//chromeos/components/media_app_ui:closure_compile",
"//chromeos/components/multidevice/debug_webui/resources:closure_compile",
......
# 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.
assert(is_chromeos, "Diagnostics App is Chrome OS only")
static_library("diagnostics_ui") {
sources = [
"diagnostics_ui.cc",
"diagnostics_ui.h",
"url_constants.cc",
"url_constants.h",
]
deps = [
"//chromeos/constants",
"//chromeos/resources:diagnostics_app_resources",
"//content/public/browser",
"//ui/resources",
"//ui/webui",
]
}
group("closure_compile") {
deps = [ "resources:closure_compile_module" ]
}
include_rules = [
"-chrome",
"+chromeos/grit/chromeos_diagnostics_app_resources.h",
"+content/public/browser",
"+ui/resources",
"+ui/webui",
]
# Primary OWNERS
baileyberro@chromium.org
jimmyxgong@chromium.org
# Backup OWNERS
zentaro@chromium.org
# COMPONENT: OS>Systems>Health
\ No newline at end of file
// 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 "chromeos/components/diagnostics_ui/diagnostics_ui.h"
#include <string>
#include "base/containers/span.h"
#include "base/memory/ptr_util.h"
#include "chromeos/components/diagnostics_ui/url_constants.h"
#include "chromeos/grit/chromeos_diagnostics_app_resources.h"
#include "chromeos/grit/chromeos_diagnostics_app_resources_map.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
#include "services/network/public/mojom/content_security_policy.mojom.h"
#include "ui/resources/grit/webui_resources.h"
namespace chromeos {
namespace {
constexpr char kGeneratedPath[] =
"@out_folder@/gen/chromeos/components/diagnostics_ui/resources/";
// TODO(jimmyxgong): Replace with webui::SetUpWebUIDataSource() once it no
// longer requires a dependency on //chrome/browser.
void SetUpWebUIDataSource(content::WebUIDataSource* source,
base::span<const GritResourceMap> resources,
const std::string& generated_path,
int default_resource) {
for (const auto& resource : resources) {
std::string path = resource.name;
if (path.rfind(generated_path, 0) == 0)
path = path.substr(generated_path.size());
source->AddResourcePath(path, resource.value);
}
source->SetDefaultResource(default_resource);
source->AddResourcePath("test_loader.html", IDR_WEBUI_HTML_TEST_LOADER);
source->AddResourcePath("test_loader.js", IDR_WEBUI_JS_TEST_LOADER);
}
} // namespace
DiagnosticsUI::DiagnosticsUI(content::WebUI* web_ui)
: ui::MojoWebUIController(web_ui) {
auto html_source = base::WrapUnique(
content::WebUIDataSource::Create(kChromeUIDiagnosticsAppHost));
html_source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::ScriptSrc,
"script-src chrome://resources chrome://test 'self';");
html_source->DisableTrustedTypesCSP();
const auto resources = base::make_span(kChromeosDiagnosticsAppResources,
kChromeosDiagnosticsAppResourcesSize);
SetUpWebUIDataSource(html_source.get(), resources, kGeneratedPath,
IDR_DIAGNOSTICS_APP_INDEX_HTML);
content::WebUIDataSource::Add(web_ui->GetWebContents()->GetBrowserContext(),
html_source.release());
}
DiagnosticsUI::~DiagnosticsUI() = default;
} // namespace chromeos
// 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 CHROMEOS_COMPONENTS_DIAGNOSTICS_UI_DIAGNOSTICS_UI_H_
#define CHROMEOS_COMPONENTS_DIAGNOSTICS_UI_DIAGNOSTICS_UI_H_
#include "ui/webui/mojo_web_ui_controller.h"
namespace content {
class WebUI;
} // namespace content
namespace chromeos {
// The WebUI for chrome://diagnostics.
class DiagnosticsUI : public ui::MojoWebUIController {
public:
explicit DiagnosticsUI(content::WebUI* web_ui);
~DiagnosticsUI() override;
DiagnosticsUI(const DiagnosticsUI&) = delete;
DiagnosticsUI& operator=(const DiagnosticsUI&) = delete;
};
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_DIAGNOSTICS_UI_DIAGNOSTICS_UI_H_
# 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("//third_party/closure_compiler/compile_js.gni")
import("//tools/grit/grit_rule.gni")
import("//tools/grit/repack.gni")
import("//tools/polymer/html_to_js.gni")
js_type_check("closure_compile_module") {
is_polymer3 = true
deps = [ ":diagnostics_app" ]
}
js_library("diagnostics_app") {
deps = [
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
]
}
html_to_js("web_components") {
js_files = [ "diagnostics_app.js" ]
}
<div id="header"></div>
\ No newline at end of file
// 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 {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
/**
* @fileoverview
* 'diagnostics-app' is the main page for viewing telemetric system information
* and running diagnostic tests.
*/
Polymer({
is: 'diagnostics-app',
_template: html`{__html_template__}`,
/** @override */
ready() {
// TODO(jimmyxgong): Remove this once the app has more capabilities.
this.$$('#header').textContent = 'Diagnostics';
},
});
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<grit latest_public_release="0" current_release="1" output_all_resource_defines="false">
<outputs>
<output filename="grit/chromeos_diagnostics_app_resources.h" type="rc_header">
<emit emit_type='prepend'></emit>
</output>
<output filename="grit/chromeos_diagnostics_app_resources_map.cc"
type="resource_file_map_source" />
<output filename="grit/chromeos_diagnostics_app_resources_map.h"
type="resource_map_header" />
<output filename="chromeos_diagnostics_app_resources.pak" type="data_package" />
</outputs>
<release seq="1">
<includes>
<!-- Privileged app host contents. -->
<include name="IDR_DIAGNOSTICS_APP_INDEX_HTML" file="index.html" type="BINDATA" compress="gzip" />
<include name="IDR_DIAGNOSTICS_APP_JS" file="${root_gen_dir}/chromeos/components/diagnostics_ui/resources/diagnostics_app.js" use_base_dir="false" compress="gzip" type="BINDATA"/>
</includes>
</release>
</grit>
\ No newline at end of file
<!-- 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. -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<diagnostics-app></diagnostics-app>
<script type="module" src="diagnostics_app.js"></script>
<!-- Below mojo script required to run browser tests -->
<script src="chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js">
</script>
</body>
</html>
\ No newline at end of file
// 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 "chromeos/components/diagnostics_ui/url_constants.h"
namespace chromeos {
const char kChromeUIDiagnosticsAppHost[] = "diagnostics";
const char kChromeUIDiagnosticsAppUrl[] = "chrome://diagnostics";
} // namespace chromeos
// 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 CHROMEOS_COMPONENTS_DIAGNOSTICS_UI_URL_CONSTANTS_H_
#define CHROMEOS_COMPONENTS_DIAGNOSTICS_UI_URL_CONSTANTS_H_
namespace chromeos {
extern const char kChromeUIDiagnosticsAppHost[];
extern const char kChromeUIDiagnosticsAppUrl[];
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_DIAGNOSTICS_UI_URL_CONSTANTS_H_
......@@ -226,3 +226,24 @@ grit("scanning_app_resources") {
output_dir = "$root_gen_dir/chromeos"
}
grit("diagnostics_app_resources") {
source =
"../components/diagnostics_ui/resources/diagnostics_app_resources.grd"
deps = [ "../components/diagnostics_ui/resources:web_components" ]
outputs = [
"chromeos_diagnostics_app_resources.pak",
"grit/chromeos_diagnostics_app_resources.h",
"grit/chromeos_diagnostics_app_resources_map.cc",
"grit/chromeos_diagnostics_app_resources_map.h",
]
grit_flags = [
"-E",
"root_gen_dir=" + rebase_path(root_gen_dir, root_build_dir),
]
output_dir = "$root_gen_dir/chromeos"
}
......@@ -325,6 +325,9 @@
"chromeos/components/camera_app_ui/resources/src/strings/camera_strings.grd": {
"messages": [2515],
},
"chromeos/components/diagnostics_ui/resources/diagnostics_app_resources.grd": {
"includes": [2517],
},
"chromeos/components/help_app_ui/resources/help_app_resources.grd": {
"includes": [2520],
},
......
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