forked from crosswalk-project/chromium-crosswalk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bulk Reports: Fix an infinite loop in ChildTraceMessageFilter::OnSetU…
…MACallback. Also added some unit testing for this file. BUG=555690 Review URL: https://codereview.chromium.org/1447643002 Cr-Commit-Position: refs/heads/master@{#359736} (cherry picked from commit 5ee4455) Review URL: https://codereview.chromium.org/1448093002 . Cr-Commit-Position: refs/branch-heads/2564@{crosswalk-project#9} Cr-Branched-From: 1283eca-refs/heads/master@{#359700}
- Loading branch information
1 parent
290f734
commit 12f9f8e
Showing
4 changed files
with
102 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |