Commit c3833634 authored by Mahmoud Gawad's avatar Mahmoud Gawad Committed by Commit Bot

[Telemetry SWX] introduce untrusted app resources

Introduce telemetry_extension_ui/test/untrusted_app_resources directory
that represents how untrusted resources should be loaded from disk using
TelemetryExtensionUntrustedSource.

The previously registered resources (i.e. untrusted.html) is no longer
needed to be registered after introducing the capability to load
untrusted resources from disk. See b:156583406

This way, we simulate how 3P could load its resources and make
telemetry requests.

Also, since removing the registered resource untrusted.html would cause
some browsertests to fail, modify the browsertest to load the
registered resource: dpsl.js, instead.

Bug: b:162875543

Change-Id: Ia12c1c010b8150940fb5a4a46163cfac82f17a1b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2337473
Commit-Queue: Mahmoud Gawad <mgawad@google.com>
Reviewed-by: default avatarOleh Lamzin <lamzin@google.com>
Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796329}
parent 9af5c53b
......@@ -23,7 +23,7 @@
namespace {
constexpr char kNonExistentUrlPath[] = "non-existent-url.html";
constexpr char kLoadFromDiskUrlPath[] = "telemetry_extension_test.html";
constexpr char kRegisteredUrlPath[] = "untrusted.html";
constexpr char kRegisteredUrlPath[] = "dpsl.js";
} // namespace
class TelemetryExtensionIntegrationTest : public SystemWebAppIntegrationTest {
......@@ -73,10 +73,6 @@ IN_PROC_BROWSER_TEST_P(
// The |registered_resource_gurl| is a file that is included in the
// TelemteryExtensionUntrustedSource's list of registered resources.
EXPECT_TRUE(content::NavigateToURL(web_contents, registered_resource_gurl));
// Verify that the file loaded from disk has the expected title.
EXPECT_EQ(base::UTF8ToUTF16("Untrusted Telemetry Extension"),
web_contents->GetTitle());
}
INSTANTIATE_TEST_SUITE_P(All,
......
......@@ -13,7 +13,6 @@ group("closure_compile") {
deps = [
":trusted_closure_compile",
":untrusted_closure_compile",
":untrusted_worker_closure_compile",
]
}
......@@ -27,10 +26,6 @@ js_type_check("untrusted_closure_compile") {
deps = [ ":untrusted" ]
}
js_type_check("untrusted_worker_closure_compile") {
deps = [ ":untrusted_worker" ]
}
js_library("trusted") {
sources = [ "trusted.js" ]
deps = [
......@@ -50,6 +45,3 @@ js_library("untrusted") {
js_library("message_types") {
}
js_library("untrusted_worker") {
}
......@@ -2,7 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/** @fileoverview Concatenation of the JS files we use in untrusted.html. */
/**
* @fileoverview Concatenation of the JS files we use in
* chrome-untrusted://telemetry-extension/index.html.
*/
// <include src="../../system_apps/public/js/message_pipe.js">
// <include src="message_types.js">
......
......@@ -4,7 +4,7 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Telemetry Extension</title>
<iframe src="chrome-untrusted://telemetry-extension/untrusted.html"
<iframe src="chrome-untrusted://telemetry-extension/index.html"
style="position:fixed; top:0; left:0; bottom:0; right:0; width:100%; height:100%; border:none; margin:0; padding:0; overflow:hidden; z-index:999999;"></iframe>
<script src="chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js"></script>
......
......@@ -23,9 +23,7 @@
<include name="IDR_TELEMETRY_EXTENSION_PROBE_SERVICE_MOJO_LITE_JS" file="${root_gen_dir}/chromeos/components/telemetry_extension_ui/mojom/probe_service.mojom-lite.js" compress="gzip" use_base_dir="false" type="BINDATA" />
<!-- Untrusted app host contents. -->
<include name="IDR_TELEMETRY_EXTENSION_UNTRUSTED_HTML" file="untrusted.html" type="BINDATA" compress="gzip" />
<include name="IDR_TELEMETRY_EXTENSION_UNTRUSTED_SCRIPTS_JS" file="untrusted_scripts.js" flattenhtml="true" type="BINDATA" compress="gzip" />
<include name="IDR_TELEMETRY_EXTENSION_UNTRUSTED_WORKER_JS" file="untrusted_worker.js" type="BINDATA" compress="gzip" />
<include name="IDR_TELEMETRY_EXTENSION_DPSL_JS" file="dpsl.js" flattenhtml="true" type="BINDATA" compress="gzip" />
</if>
</includes>
</release>
......
......@@ -66,12 +66,7 @@ CreateUntrustedTelemetryExtensionDataSource() {
auto untrusted_source = TelemetryExtensionUntrustedSource::Create(
chromeos::kChromeUIUntrustedTelemetryExtensionURL);
untrusted_source->AddResourcePath("untrusted.html",
IDR_TELEMETRY_EXTENSION_UNTRUSTED_HTML);
untrusted_source->AddResourcePath(
"untrusted_scripts.js", IDR_TELEMETRY_EXTENSION_UNTRUSTED_SCRIPTS_JS);
untrusted_source->AddResourcePath(
"untrusted_worker.js", IDR_TELEMETRY_EXTENSION_UNTRUSTED_WORKER_JS);
untrusted_source->AddResourcePath("dpsl.js", IDR_TELEMETRY_EXTENSION_DPSL_JS);
untrusted_source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::FrameAncestors,
......
......@@ -33,11 +33,13 @@ source_set("browser_test_support") {
"../:telemetry_extension_ui",
"//chrome/test:test_support_ui",
"//chromeos/components/web_applications/test:test_support",
"//chromeos/constants",
"//chromeos/dbus/cros_healthd:cros_healthd",
]
data = [
"trusted_test_requester.js",
"untrusted_app_resources/",
"untrusted_browsertest.js",
"untrusted_test_handlers.js",
]
......@@ -48,6 +50,7 @@ group("closure_compile") {
deps = [
":trusted_browsertest_closure_compile",
":untrusted_browsertest_closure_compile",
"untrusted_app_resources:closure_compile",
]
}
......
......@@ -4,9 +4,12 @@
#include "chromeos/components/telemetry_extension_ui/test/telemetry_extension_ui_browsertest.h"
#include "base/base_paths.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "chromeos/components/telemetry_extension_ui/url_constants.h"
#include "chromeos/components/web_applications/test/sandboxed_web_ui_test_base.h"
#include "chromeos/constants/chromeos_switches.h"
#include "chromeos/dbus/cros_healthd/cros_healthd_client.h"
#include "chromeos/dbus/cros_healthd/fake_cros_healthd_client.h"
......@@ -20,6 +23,10 @@ constexpr base::FilePath::CharType kWebUiTestUtil[] =
constexpr base::FilePath::CharType kCr[] =
FILE_PATH_LITERAL("ui/webui/resources/js/cr.js");
// Folder containing the resources for JS browser tests.
constexpr base::FilePath::CharType kUntrustedAppResources[] = FILE_PATH_LITERAL(
"chromeos/components/telemetry_extension_ui/test/untrusted_app_resources");
// File containing the query handlers for JS unit tests.
constexpr base::FilePath::CharType kUntrustedTestHandlers[] = FILE_PATH_LITERAL(
"chromeos/components/telemetry_extension_ui/test/"
......@@ -41,6 +48,19 @@ TelemetryExtensionUiBrowserTest::TelemetryExtensionUiBrowserTest()
TelemetryExtensionUiBrowserTest::~TelemetryExtensionUiBrowserTest() = default;
void TelemetryExtensionUiBrowserTest::SetUpCommandLine(
base::CommandLine* command_line) {
base::FilePath source_root;
base::PathService::Get(base::DIR_SOURCE_ROOT, &source_root);
base::FilePath file_path(kUntrustedAppResources);
command_line->AppendSwitchASCII(
chromeos::switches::kTelemetryExtensionDirectory,
source_root.Append(file_path).value());
SandboxedWebUiAppTestBase::SetUpCommandLine(command_line);
}
void TelemetryExtensionUiBrowserTest::SetUpOnMainThread() {
{
namespace cros_diagnostics = ::chromeos::cros_healthd::mojom;
......
......@@ -5,8 +5,7 @@
#ifndef CHROMEOS_COMPONENTS_TELEMETRY_EXTENSION_UI_TEST_TELEMETRY_EXTENSION_UI_BROWSERTEST_H_
#define CHROMEOS_COMPONENTS_TELEMETRY_EXTENSION_UI_TEST_TELEMETRY_EXTENSION_UI_BROWSERTEST_H_
#include <string>
#include "base/command_line.h"
#include "chromeos/components/web_applications/test/sandboxed_web_ui_test_base.h"
class TelemetryExtensionUiBrowserTest : public SandboxedWebUiAppTestBase {
......@@ -19,6 +18,8 @@ class TelemetryExtensionUiBrowserTest : public SandboxedWebUiAppTestBase {
TelemetryExtensionUiBrowserTest& operator=(
const TelemetryExtensionUiBrowserTest&) = delete;
// SandboxedWebUiAppTestBase overrides:
void SetUpCommandLine(base::CommandLine* command_line) override;
void SetUpOnMainThread() override;
};
......
# 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")
assert(is_chromeos, "Telemetry Extension is Chrome OS only")
assert(!is_official_build,
"Telemetry Extension is only built for unofficial builds")
group("closure_compile") {
deps = [ ":worker_closure_compile" ]
}
js_type_check("worker_closure_compile") {
deps = [ ":worker" ]
}
js_library("worker") {
sources = [ "worker.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. -->
<!DOCTYPE html>
<meta charset="utf-8">
<title>Untrusted Telemetry Extension</title>
<h1 id='untrusted-title'>Telemetry Extension</h1>
<script src="untrusted_scripts.js"></script>
<!-- This support library is needed so that 3P can access telemetry APIs -->
<script src="chrome-untrusted://telemetry-extension/dpsl.js"></script>
<script src="index.js"></script>
// 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.
window.document.title = 'Third-party Telemetry Extension';
......@@ -10,7 +10,7 @@
*/
const workerUrlPolicy = trustedTypes.createPolicy(
'telemetry-extension-static',
{createScriptURL: () => 'untrusted_worker.js'});
{createScriptURL: () => 'worker.js'});
// Tests that web workers can be spawned from
// chrome-untrusted://telemetry_extension.
......
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