These classes were hoisted and renamed. This has been replaced in Chromium as well. This is a mechanical change for Brave, done with the following script. ``` git grep -lw 'Value::List' | xargs sed -i 's/\bValue::List\b/ListValue/g' git grep -lw 'Value::Dict' | xargs sed -i 's/\bValue::Dict\b/DictValue/g' git cl format ``` Chromium changes: https://chromium.googlesource.com/chromium/src/+/6bc468d481835992696083e99e556516fb7f5f80 ``` commit 6bc468d481835992696083e99e556516fb7f5f80 Author: Avi Drissman <avi@chromium.org> Date: Thu Jan 29 22:14:50 2026 -0800 Remove aliases for base::DictValue and base::ListValue This removes a few last stragglers as well. Fixed: 478100525 Cq-Include-Trybots: luci.chromium.try:win-official,mac-official,linux-official,android-official,android-desktop-x64-official Change-Id: If92142b8ab0562a82c609b71c6b2a7665cea6ec6 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7513889 Auto-Submit: Avi Drissman <avi@chromium.org> Commit-Queue: Daniel Cheng <dcheng@chromium.org> Owners-Override: Daniel Cheng <dcheng@chromium.org> Reviewed-by: Daniel Cheng <dcheng@chromium.org> Cr-Commit-Position: refs/heads/main@{#1577038} ``` Issue: https://github.com/brave/brave-browser/issues/52435
107 lines
3.9 KiB
C++
107 lines
3.9 KiB
C++
// Copyright (c) 2022 The Brave Authors. All rights reserved.
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
#include "brave/components/p3a/star_randomness_test_util.h"
|
|
|
|
#include <algorithm>
|
|
#include <optional>
|
|
#include <string_view>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
#include "base/base64.h"
|
|
#include "base/i18n/time_formatting.h"
|
|
#include "base/json/json_writer.h"
|
|
#include "base/strings/strcat.h"
|
|
#include "base/strings/string_number_conversions.h"
|
|
#include "base/strings/string_split.h"
|
|
#include "base/test/values_test_util.h"
|
|
#include "brave/components/p3a/constellation/rs/cxx/src/lib.rs.h"
|
|
#include "net/http/http_request_headers.h"
|
|
#include "services/network/public/cpp/resource_request.h"
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
namespace p3a {
|
|
|
|
MetricLogType ValidateURLAndGetMetricLogType(const GURL& url,
|
|
const char* expected_host) {
|
|
std::string url_prefix = base::StrCat({expected_host, "/instances/"});
|
|
|
|
EXPECT_TRUE(url.spec().starts_with(url_prefix));
|
|
|
|
std::vector<std::string> path_segments = base::SplitString(
|
|
url.path(), "/", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
|
|
EXPECT_EQ(path_segments.size(), 4U);
|
|
|
|
std::optional<MetricLogType> log_type =
|
|
StringToMetricLogType(path_segments[2]);
|
|
EXPECT_TRUE(log_type.has_value());
|
|
|
|
return *log_type;
|
|
}
|
|
|
|
std::string HandleRandomnessRequest(const network::ResourceRequest& request,
|
|
uint8_t expected_epoch) {
|
|
EXPECT_EQ(request.method, net::HttpRequestHeaders::kPostMethod);
|
|
std::string_view request_string(request.request_body->elements()
|
|
->at(0)
|
|
.As<network::DataElementBytes>()
|
|
.AsStringPiece());
|
|
|
|
base::DictValue req_parsed_val = base::test::ParseJsonDict(request_string);
|
|
|
|
EXPECT_EQ(*req_parsed_val.FindInt("epoch"), expected_epoch);
|
|
|
|
rust::Vec<constellation::VecU8> req_points_rust;
|
|
const base::ListValue* points_list = req_parsed_val.FindList("points");
|
|
|
|
EXPECT_GE(points_list->size(), 5U);
|
|
EXPECT_LE(points_list->size(), 9U);
|
|
|
|
std::transform(
|
|
points_list->begin(), points_list->end(),
|
|
std::back_inserter(req_points_rust), [](const base::Value& val) {
|
|
constellation::VecU8 point_dec_rust;
|
|
std::vector<uint8_t> point_dec = *base::Base64Decode(val.GetString());
|
|
std::copy(point_dec.cbegin(), point_dec.cend(),
|
|
std::back_inserter(point_dec_rust.data));
|
|
return point_dec_rust;
|
|
});
|
|
|
|
auto rand_result =
|
|
constellation::generate_local_randomness(req_points_rust, expected_epoch);
|
|
|
|
EXPECT_GE(rand_result.points.size(), 5U);
|
|
EXPECT_LE(rand_result.points.size(), 9U);
|
|
|
|
base::ListValue resp_points_list;
|
|
for (const constellation::VecU8& resp_point_rust : rand_result.points) {
|
|
std::vector<uint8_t> resp_point;
|
|
std::copy(resp_point_rust.data.cbegin(), resp_point_rust.data.cend(),
|
|
std::back_inserter(resp_point));
|
|
resp_points_list.Append(base::Base64Encode(resp_point));
|
|
}
|
|
|
|
base::DictValue resp_value;
|
|
resp_value.Set("epoch", base::Value(expected_epoch));
|
|
resp_value.Set("points", std::move(resp_points_list));
|
|
std::string resp_json;
|
|
base::JSONWriter::Write(resp_value, &resp_json);
|
|
return resp_json;
|
|
}
|
|
|
|
std::string HandleInfoRequest(const network::ResourceRequest& request,
|
|
MetricLogType log_type,
|
|
uint8_t current_epoch,
|
|
const char* next_epoch_time) {
|
|
EXPECT_EQ(request.method, net::HttpRequestHeaders::kGetMethod);
|
|
|
|
return base::StrCat(
|
|
{"{\"currentEpoch\":", base::NumberToString(current_epoch),
|
|
", \"nextEpochTime\": \"", next_epoch_time, "\"}"});
|
|
}
|
|
|
|
} // namespace p3a
|