blob: a03f06d26fc8e67e8e534edb7482c9397d463142 [file] [log] [blame]
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/ui_devtools/ui_devtools_unittest_utils.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_util.h"
#include "third_party/inspector_protocol/crdtp/json.h"
namespace ui_devtools {
MockUIElementDelegate::MockUIElementDelegate() {}
MockUIElementDelegate::~MockUIElementDelegate() {}
FakeFrontendChannel::FakeFrontendChannel() {}
FakeFrontendChannel::~FakeFrontendChannel() {}
int FakeFrontendChannel::CountProtocolNotificationMessageStartsWith(
const std::string& message) {
int count = 0;
for (const std::string& s : protocol_notification_messages_) {
if (base::StartsWith(s, message, base::CompareCase::SENSITIVE))
count++;
}
return count;
}
int FakeFrontendChannel::CountProtocolNotificationMessage(
const std::string& message) {
return base::ranges::count(protocol_notification_messages_, message);
}
void FakeFrontendChannel::SendProtocolNotification(
std::unique_ptr<protocol::Serializable> message) {
EXPECT_TRUE(allow_notifications_);
std::string json;
crdtp::Status status = crdtp::json::ConvertCBORToJSON(
crdtp::SpanFrom(message->Serialize()), &json);
DCHECK(status.ok()) << status.ToASCIIString();
protocol_notification_messages_.push_back(std::move(json));
}
} // namespace ui_devtools