Skip to content

Commit

Permalink
Add nextHopProtocol to PerformanceResourceTiming. (#3769)
Browse files Browse the repository at this point in the history
b/343788007
  • Loading branch information
aee-google authored Jul 8, 2024
1 parent dfd6db9 commit c1e5b30
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 0 deletions.
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 @@ -74,6 +74,7 @@
# 'h5vcc_watchdog_api_test',
'http_cache',
'javascript_profiler',
'performance_resource_timing_test',
'persistent_cookie',
'pointer_event_on_fixed_element_test',
'pointer_event_on_cropped_element_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())
12 changes: 12 additions & 0 deletions cobalt/dom/performance_resource_timing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "cobalt/dom/performance_resource_timing.h"

#include <utility>

#include "cobalt/dom/performance.h"

namespace cobalt {
Expand Down Expand Up @@ -137,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
1 change: 1 addition & 0 deletions cobalt/dom/performance_resource_timing.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,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 @@ -201,6 +201,8 @@ struct NET_EXPORT LoadTimingInfo {

#if defined(STARBOARD)
uint64_t encoded_body_size;
std::string alpn_negotiated_protocol;
std::string connection_info_string;
#endif // defined(STARBOARD)
};

Expand Down
2 changes: 2 additions & 0 deletions net/url_request/url_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,8 @@ void URLRequest::NotifyRequestCompleted() {

#if defined (STARBOARD)
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

0 comments on commit c1e5b30

Please sign in to comment.