ui_devtools_unittest_utils.cc 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/ui_devtools/ui_devtools_unittest_utils.h"
  5. #include "base/strings/string_util.h"
  6. #include "third_party/inspector_protocol/crdtp/json.h"
  7. namespace ui_devtools {
  8. MockUIElementDelegate::MockUIElementDelegate() {}
  9. MockUIElementDelegate::~MockUIElementDelegate() {}
  10. FakeFrontendChannel::FakeFrontendChannel() {}
  11. FakeFrontendChannel::~FakeFrontendChannel() {}
  12. int FakeFrontendChannel::CountProtocolNotificationMessageStartsWith(
  13. const std::string& message) {
  14. int count = 0;
  15. for (const std::string& s : protocol_notification_messages_) {
  16. if (base::StartsWith(s, message, base::CompareCase::SENSITIVE))
  17. count++;
  18. }
  19. return count;
  20. }
  21. int FakeFrontendChannel::CountProtocolNotificationMessage(
  22. const std::string& message) {
  23. return std::count(protocol_notification_messages_.begin(),
  24. protocol_notification_messages_.end(), message);
  25. }
  26. void FakeFrontendChannel::SendProtocolNotification(
  27. std::unique_ptr<protocol::Serializable> message) {
  28. EXPECT_TRUE(allow_notifications_);
  29. std::string json;
  30. crdtp::Status status = crdtp::json::ConvertCBORToJSON(
  31. crdtp::SpanFrom(message->Serialize()), &json);
  32. DCHECK(status.ok()) << status.ToASCIIString();
  33. protocol_notification_messages_.push_back(std::move(json));
  34. }
  35. } // namespace ui_devtools