Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nextHopProtocol to PerformanceResourceTiming. #4027

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cobalt/black_box_tests/black_box_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
'h5vcc_watchdog_api_test',
'http_cache',
'javascript_profiler',
'performance_resource_timing_test',
'persistent_cookie',
'scroll',
'service_worker_add_to_cache_test',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<!--
Copyright 2024 The Cobalt Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
<script src="black_box_js_test_utils.js"></script>
</head>
<body>
<script>
const checkNextHopProtocol = expectedValues => {
const entries = window.performance.getEntries();
assertEqual(expectedValues.length, entries.length);
expectedValues.forEach((expectedValue, i) => {
assertEqual(expectedValue, entries[i].nextHopProtocol);
});
};

setupFinished();
checkNextHopProtocol([undefined]);
fetch('performance_resource_timing_test.html')
.then(() => {
checkNextHopProtocol([undefined, 'http/1.0']);
}).then(onEndTest).catch(notReached);
</script>
</body>
</html>
28 changes: 28 additions & 0 deletions cobalt/black_box_tests/tests/performance_resource_timing_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2024 The Cobalt Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Test performance.getEntries()."""

from cobalt.black_box_tests import black_box_tests
from cobalt.black_box_tests.threaded_web_server import ThreadedWebServer


class CpuUsageTrackerTest(black_box_tests.BlackBoxTestCase):

def test_performance_resource_timing(self):
with ThreadedWebServer(binding_address=self.GetBindingAddress()) as server:
url = server.GetURL(
file_name='testdata/performance_resource_timing_test.html')
with self.CreateCobaltRunner(url=url) as runner:
runner.WaitForJSTestsSetup()
self.assertTrue(runner.JSTestsSucceeded())
13 changes: 13 additions & 0 deletions cobalt/dom/performance_resource_timing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
// limitations under the License.

#include "cobalt/dom/performance_resource_timing.h"

#include <utility>

#include "cobalt/dom/performance.h"

namespace cobalt {
Expand Down Expand Up @@ -136,6 +139,16 @@ DOMHighResTimeStamp PerformanceResourceTiming::worker_start() const {
time_origin_, timing_info_.service_worker_start_time);
}

std::string PerformanceResourceTiming::next_hop_protocol() const {
// Fallback to connection_info when alpn_negotiated_protocol is unknown.
std::string returnedProtocol =
(timing_info_.alpn_negotiated_protocol == "unknown")
? timing_info_.connection_info_string
: timing_info_.alpn_negotiated_protocol;
// If connection_info is unknown, return the empty string.
return returnedProtocol == "unknown" ? "" : std::move(returnedProtocol);
}

void PerformanceResourceTiming::SetResourceTimingEntry(
const net::LoadTimingInfo& timing_info, const std::string& initiator_type,
const std::string& requested_url, const std::string& cache_mode) {
Expand Down
2 changes: 1 addition & 1 deletion cobalt/dom/performance_resource_timing.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

#include "cobalt/dom/performance_entry.h"
#include "cobalt/dom/performance_high_resolution_time.h"

#include "cobalt/script/wrappable.h"
#include "net/base/load_timing_info.h"

Expand Down Expand Up @@ -58,6 +57,7 @@ class PerformanceResourceTiming : public PerformanceEntry {
uint64_t transfer_size() const;
uint64_t encoded_body_size() const;
DOMHighResTimeStamp worker_start() const;
std::string next_hop_protocol() const;

std::string entry_type() const override { return "resource"; }
PerformanceEntryType EntryTypeEnum() const override {
Expand Down
1 change: 1 addition & 0 deletions cobalt/dom/performance_resource_timing.idl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
[Exposed=Window]
interface PerformanceResourceTiming : PerformanceEntry {
readonly attribute DOMString initiatorType;
readonly attribute DOMString nextHopProtocol;
readonly attribute DOMHighResTimeStamp fetchStart;
readonly attribute DOMHighResTimeStamp domainLookupStart;
readonly attribute DOMHighResTimeStamp domainLookupEnd;
Expand Down
2 changes: 2 additions & 0 deletions net/base/load_timing_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ struct NET_EXPORT LoadTimingInfo {
#if defined(STARBOARD)
uint64_t encoded_body_size;
base::TimeTicks service_worker_start_time;
std::string alpn_negotiated_protocol;
std::string connection_info_string;
#endif // defined(STARBOARD)
};

Expand Down
8 changes: 7 additions & 1 deletion net/url_request/url_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,13 @@ void URLRequest::NotifyRequestCompleted() {
return;

#if defined (STARBOARD)
load_timing_info_.encoded_body_size = static_cast<uint64_t>(GetTotalReceivedBytes());
load_timing_info_.encoded_body_size =
static_cast<uint64_t>(GetTotalReceivedBytes());
load_timing_info_.alpn_negotiated_protocol =
response_info_.alpn_negotiated_protocol;
load_timing_info_.connection_info_string =
HttpResponseInfo::ConnectionInfoToString(
response_info_.connection_info);
if (load_timing_info_callback_) {
load_timing_info_callback_.Run(load_timing_info_);
}
Expand Down
Loading