diff --git a/components/invalidation/push_client_channel_unittest.cc b/components/invalidation/push_client_channel_unittest.cc new file mode 100644 index 000000000000..e859ccf7f94b --- /dev/null +++ b/components/invalidation/push_client_channel_unittest.cc @@ -0,0 +1,61 @@ +#include + +#include + +#include "base/compiler_specific.h" +#include "base/memory/ptr_util.h" +#include "components/invalidation/impl/push_client_channel.h" +#include "jingle/notifier/listener/fake_push_client.h" +#include "jingle/notifier/listener/notification_defines.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace syncer { +namespace { + +class PushClientChannelTest + : public ::testing::Test, + public SyncNetworkChannel::Observer { + protected: + PushClientChannelTest() + : fake_push_client_(new notifier::FakePushClient()), + push_client_channel_(base::WrapUnique(fake_push_client_)) { + push_client_channel_.AddObserver(this); + push_client_channel_.SetMessageReceiver( + invalidation::NewPermanentCallback( + this, &PushClientChannelTest::OnIncomingMessage)); + push_client_channel_.SetSystemResources(nullptr); + } + + ~PushClientChannelTest() override { + push_client_channel_.RemoveObserver(this); + } + + void OnNetworkChannelStateChanged( + InvalidatorState invalidator_state) override { + NOTREACHED(); + } + + void OnIncomingMessage(std::string incoming_message) { + NOTREACHED(); + } + + notifier::FakePushClient* fake_push_client_; + PushClientChannel push_client_channel_; +}; + +const char kMessage[] = "message"; +const char kServiceContext[] = "service context"; +const int64_t kSchedulingHash = 100; + +// Simulate an incoming notification. Nothing should happen because +// the channel should not be listening. +TEST_F(PushClientChannelTest, OnIncomingMessage) { + notifier::Notification notification; + notification.data = + PushClientChannel::EncodeMessageForTest( + kMessage, kServiceContext, kSchedulingHash); + fake_push_client_->SimulateIncomingNotification(notification); +} + +} // namespace +} // namespace syncer diff --git a/patches/components-invalidation-impl-push_client_channel.cc.patch b/patches/components-invalidation-impl-push_client_channel.cc.patch new file mode 100644 index 000000000000..ecebda1debe0 --- /dev/null +++ b/patches/components-invalidation-impl-push_client_channel.cc.patch @@ -0,0 +1,20 @@ +diff --git a/components/invalidation/impl/push_client_channel.cc b/components/invalidation/impl/push_client_channel.cc +index 709d8e562c22..9170819bb45e 100644 +--- a/components/invalidation/impl/push_client_channel.cc ++++ b/components/invalidation/impl/push_client_channel.cc +@@ -28,6 +28,7 @@ PushClientChannel::PushClientChannel( + : push_client_(std::move(push_client)), + scheduling_hash_(0), + sent_messages_count_(0) { ++ return; // feature disabled in Brave + push_client_->AddObserver(this); + notifier::Subscription subscription; + subscription.channel = kChannelName; +@@ -43,6 +44,7 @@ PushClientChannel::~PushClientChannel() { + + void PushClientChannel::UpdateCredentials( + const std::string& email, const std::string& token) { ++ return; // feature disabled in Brave + net::NetworkTrafficAnnotationTag traffic_annotation = + net::DefineNetworkTrafficAnnotation("puch_client_channel", R"( + semantics { diff --git a/test/BUILD.gn b/test/BUILD.gn index 1a0f040796ae..2e2536a3079e 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -67,6 +67,7 @@ test("brave_unit_tests") { "//brave/components/brave_webtorrent/browser/net/brave_torrent_redirect_network_delegate_helper_unittest.cc", "//brave/components/invalidation/fcm_unittest.cc", "//brave/components/gcm_driver/gcm_unittest.cc", + "//brave/components/invalidation/push_client_channel_unittest.cc", "//brave/components/omnibox/browser/topsites_provider_unittest.cc", "//brave/components/spellcheck/spellcheck_unittest.cc", "//brave/third_party/libaddressinput/chromium/chrome_metadata_source_unittest.cc",