Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Unified Diff: components/tracing/child_trace_message_filter_unittest.cc

Issue 1448093002: Bulk Reports: Fix an infinite loop in ChildTraceMessageFilter::OnSetUMACallback. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2564
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/tracing/child_trace_message_filter.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/tracing/child_trace_message_filter_unittest.cc
diff --git a/components/tracing/child_trace_message_filter_unittest.cc b/components/tracing/child_trace_message_filter_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..75d1ad811a59af27fa389d020965ceb732c07bd9
--- /dev/null
+++ b/components/tracing/child_trace_message_filter_unittest.cc
@@ -0,0 +1,87 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/tracing/child_trace_message_filter.h"
+
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/message_loop/message_loop.h"
+#include "components/tracing/tracing_messages.h"
+#include "ipc/ipc_message.h"
+#include "ipc/ipc_sender.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace tracing {
+
+class FakeSender : public IPC::Sender {
+ public:
+ FakeSender() {}
+
+ ~FakeSender() override {}
+
+ bool Send(IPC::Message* msg) override {
+ last_message_.reset(msg);
+ return true;
+ }
+
+ scoped_ptr<IPC::Message> last_message_;
+};
+
+class ChildTraceMessageFilterTest : public testing::Test {
+ public:
+ ChildTraceMessageFilterTest() {
+ message_filter_ =
+ new tracing::ChildTraceMessageFilter(message_loop_.task_runner().get());
+ message_filter_->SetSenderForTesting(&fake_sender_);
+ }
+
+ void OnSetUMACallback(const std::string& histogram,
+ int low,
+ int high,
+ bool repeat) {
+ fake_sender_.last_message_.reset();
+ message_filter_->OnSetUMACallback(histogram, low, high, repeat);
+ }
+
+ base::MessageLoop message_loop_;
+ FakeSender fake_sender_;
+ scoped_refptr<tracing::ChildTraceMessageFilter> message_filter_;
+};
+
+TEST_F(ChildTraceMessageFilterTest, TestHistogramDoesNotTrigger) {
+ LOCAL_HISTOGRAM_COUNTS("foo1", 10);
+
+ OnSetUMACallback("foo1", 20000, 25000, true);
+
+ message_loop_.RunUntilIdle();
+
+ EXPECT_FALSE(fake_sender_.last_message_);
+}
+
+TEST_F(ChildTraceMessageFilterTest, TestHistogramTriggers) {
+ LOCAL_HISTOGRAM_COUNTS("foo2", 2);
+
+ OnSetUMACallback("foo2", 1, 3, true);
+
+ message_loop_.RunUntilIdle();
+
+ EXPECT_TRUE(fake_sender_.last_message_);
+ EXPECT_EQ(fake_sender_.last_message_->type(),
+ TracingHostMsg_TriggerBackgroundTrace::ID);
+}
+
+TEST_F(ChildTraceMessageFilterTest, TestHistogramAborts) {
+ LOCAL_HISTOGRAM_COUNTS("foo3", 10);
+
+ OnSetUMACallback("foo3", 1, 3, false);
+
+ message_loop_.RunUntilIdle();
+
+ EXPECT_TRUE(fake_sender_.last_message_);
+ EXPECT_EQ(fake_sender_.last_message_->type(),
+ TracingHostMsg_AbortBackgroundTrace::ID);
+}
+
+} // namespace tracing
« no previous file with comments | « components/tracing/child_trace_message_filter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698