ceftests: Fix CorsTest.IframeNone failures

The same console message is sometimes output multiple times.
This commit is contained in:
Marshall Greenblatt 2023-01-03 13:24:17 -05:00
parent d04b5d4f87
commit a986b1c226

View File

@ -205,8 +205,16 @@ struct TestSetup {
typedef std::vector<Resource*> ResourceList; typedef std::vector<Resource*> ResourceList;
ResourceList resources; ResourceList resources;
struct ConsoleMessage {
std::string message;
// Number of times the message was received. All registered messages are
// expected at least one time.
size_t count = 0;
};
// Used for testing received console messages. // Used for testing received console messages.
std::vector<std::string> console_messages; std::vector<ConsoleMessage> console_messages;
// If true cookies will be cleared after every test run. // If true cookies will be cleared after every test run.
bool clear_cookies = false; bool clear_cookies = false;
@ -219,7 +227,7 @@ struct TestSetup {
void AddConsoleMessage(const std::string& message) { void AddConsoleMessage(const std::string& message) {
DCHECK(!message.empty()); DCHECK(!message.empty());
console_messages.push_back(message); console_messages.push_back({message, 0U});
} }
Resource* GetResource(const std::string& url, Resource* GetResource(const std::string& url,
@ -379,9 +387,10 @@ class CorsTestHandler : public RoutingTestHandler {
} }
setup_->AssertDone(); setup_->AssertDone();
EXPECT_TRUE(setup_->console_messages.empty()) for (const auto& cm : setup_->console_messages) {
<< "Did not receive expected console message: " EXPECT_GT(cm.count, 0U)
<< setup_->console_messages.front(); << "Did not receive expected console message: " << cm.message;
}
RoutingTestHandler::DestroyTest(); RoutingTestHandler::DestroyTest();
} }
@ -478,13 +487,11 @@ class CorsTestHandler : public RoutingTestHandler {
int line) override { int line) override {
bool expected = false; bool expected = false;
if (!setup_->console_messages.empty()) { if (!setup_->console_messages.empty()) {
std::vector<std::string>::iterator it = setup_->console_messages.begin();
for (; it != setup_->console_messages.end(); ++it) {
const std::string& possible = *it;
const std::string& actual = message.ToString(); const std::string& actual = message.ToString();
if (actual.find(possible) == 0U) { for (auto& cm : setup_->console_messages) {
if (actual.find(cm.message) == 0U) {
expected = true; expected = true;
setup_->console_messages.erase(it); cm.count++;
break; break;
} }
} }