0

Make some unit tests less sensitive to hash ordering.

We are trying to change StringHasher's implementation, and some tests
were in effect hard-coding the order of the output of hash tables.
Make them less order-sensitive.

Change-Id: Ic15309468f2a0d38b485fac00ebc5c948130b62d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5676787
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Commit-Queue: Steinar H Gunderson <sesse@chromium.org>
Auto-Submit: Steinar H Gunderson <sesse@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1323442}
This commit is contained in:
Steinar H. Gunderson
2024-07-04 18:53:16 +00:00
committed by Chromium LUCI CQ
parent 68b8e676fa
commit 55ea74ebf3
3 changed files with 21 additions and 20 deletions
third_party/blink/renderer/core

@ -235,6 +235,7 @@ using testing::_;
using testing::ElementsAre;
using testing::Mock;
using testing::Return;
using testing::UnorderedElementsAre;
namespace blink {
@ -1418,7 +1419,7 @@ TEST_F(WebFrameCSSCallbackTest, AuthorStyleSheet) {
RunPendingTasks();
EXPECT_EQ(2, UpdateCount());
EXPECT_THAT(MatchedSelectors(),
ElementsAre("div.initial_off", "div.initial_on"));
UnorderedElementsAre("div.initial_off", "div.initial_on"));
// Check that we can turn off callbacks for certain selectors.
Doc().WatchCSSSelectors(WebVector<WebString>());
@ -1606,7 +1607,7 @@ TEST_F(WebFrameCSSCallbackTest, MultiSelector) {
RunPendingTasks();
EXPECT_EQ(1, UpdateCount());
EXPECT_THAT(MatchedSelectors(), ElementsAre("span", "span, p"));
EXPECT_THAT(MatchedSelectors(), UnorderedElementsAre("span", "span, p"));
}
TEST_F(WebFrameCSSCallbackTest, InvalidSelector) {

@ -23,6 +23,7 @@ namespace {
using base::test::ParseJson;
using testing::ByRef;
using testing::Eq;
using testing::UnorderedElementsAre;
void AssertValueEqualsJSON(const std::unique_ptr<protocol::Value>& actual_value,
const std::string& json_expected) {
@ -389,30 +390,23 @@ TEST_F(InspectorHighlightTest, GridLineNames) {
InspectorGridHighlight(subgrid, InspectorHighlight::DefaultGridConfig());
EXPECT_TRUE(info);
auto CompareLineNames = [](protocol::ListValue* row_or_column_list,
WTF::Vector<WTF::String>& expected_names) -> void {
auto GetLineNames = [](protocol::ListValue* row_or_column_list) {
Vector<String> ret;
for (wtf_size_t i = 0; i < row_or_column_list->size(); ++i) {
protocol::DictionaryValue* current_value =
static_cast<protocol::DictionaryValue*>(row_or_column_list->at(i));
WTF::String string_value;
EXPECT_TRUE(current_value->getString("name", &string_value));
EXPECT_EQ(expected_names[i], string_value);
ret.push_back(string_value);
}
return ret;
};
protocol::ListValue* row_info = info->getArray("rowLineNameOffsets");
EXPECT_EQ(row_info->size(), 6u);
WTF::Vector<WTF::String> expected_row_names = {"d", "e_sub", "e",
"f", "d_sub", "f_sub"};
CompareLineNames(row_info, expected_row_names);
protocol::ListValue* column_info = info->getArray("columnLineNameOffsets");
EXPECT_EQ(column_info->size(), 6u);
WTF::Vector<WTF::String> expected_column_names = {"b", "a_sub", "b_sub",
"c", "a", "c_sub"};
CompareLineNames(column_info, expected_column_names);
EXPECT_THAT(GetLineNames(info->getArray("rowLineNameOffsets")),
UnorderedElementsAre("d", "d_sub", "e", "e_sub", "f", "f_sub"));
EXPECT_THAT(GetLineNames(info->getArray("columnLineNameOffsets")),
UnorderedElementsAre("a", "a_sub", "b", "b_sub", "c", "c_sub"));
}
TEST_F(InspectorHighlightTest, GridAreaNames) {

@ -530,7 +530,7 @@ TEST_P(PrintContextTest, LinkedTarget) {
);
PrintSinglePage(canvas);
const Vector<MockPageContextCanvas::Operation>& operations =
Vector<MockPageContextCanvas::Operation> operations =
canvas.RecordedOperations();
ASSERT_EQ(8u, operations.size());
// The DrawRect operations come from a stable iterator.
@ -544,14 +544,20 @@ TEST_P(PrintContextTest, LinkedTarget) {
EXPECT_SKRECT_EQ(50, 460, 10, 10, operations[3].rect);
// The DrawPoint operations come from an unstable iterator.
std::sort(operations.begin() + 4, operations.begin() + 8,
[](const MockPageContextCanvas::Operation& a,
const MockPageContextCanvas::Operation& b) {
return std::pair(a.rect.x(), a.rect.y()) <
std::pair(b.rect.x(), b.rect.y());
});
EXPECT_EQ(MockPageContextCanvas::kDrawPoint, operations[4].type);
EXPECT_SKRECT_EQ(450, 260, 0, 0, operations[4].rect);
EXPECT_SKRECT_EQ(0, 0, 0, 0, operations[4].rect);
EXPECT_EQ(MockPageContextCanvas::kDrawPoint, operations[5].type);
EXPECT_SKRECT_EQ(0, 0, 0, 0, operations[5].rect);
EXPECT_EQ(MockPageContextCanvas::kDrawPoint, operations[6].type);
EXPECT_SKRECT_EQ(450, 60, 0, 0, operations[6].rect);
EXPECT_EQ(MockPageContextCanvas::kDrawPoint, operations[7].type);
EXPECT_SKRECT_EQ(0, 0, 0, 0, operations[7].rect);
EXPECT_SKRECT_EQ(450, 260, 0, 0, operations[7].rect);
}
TEST_P(PrintContextTest, EmptyLinkedTarget) {