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

Side by Side Diff: base/trace_event/trace_event_unittest.cc

Issue 1115343002: Added a whitelist for trace events that are known to be PII-less. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review fixes Created 5 years, 7 months 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <math.h> 5 #include <math.h>
6 #include <cstdlib> 6 #include <cstdlib>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 2187 matching lines...) Expand 10 before | Expand all | Expand 10 after
2198 EXPECT_EQ(0, int_value); 2198 EXPECT_EQ(0, int_value);
2199 2199
2200 dict = FindNamePhase("event15", "X"); 2200 dict = FindNamePhase("event15", "X");
2201 ASSERT_TRUE(dict); 2201 ASSERT_TRUE(dict);
2202 dict->GetDictionary("args", &args_dict); 2202 dict->GetDictionary("args", &args_dict);
2203 ASSERT_TRUE(args_dict); 2203 ASSERT_TRUE(args_dict);
2204 EXPECT_TRUE(args_dict->GetInteger("timeticks_one", &int_value)); 2204 EXPECT_TRUE(args_dict->GetInteger("timeticks_one", &int_value));
2205 EXPECT_EQ(1, int_value); 2205 EXPECT_EQ(1, int_value);
2206 } 2206 }
2207 2207
2208 namespace {
2209
2210 bool IsTraceEventArgsWhitelisted(const char* category_group_name,
2211 const char* event_name) {
2212 if (MatchPattern(category_group_name, "toplevel") &&
2213 MatchPattern(event_name, "*")) {
2214 return true;
2215 }
2216
2217 return false;
2218 }
2219
2220 } // namespace
2221
2222 TEST_F(TraceEventTestFixture, ArgsWhitelisting) {
2223 TraceLog::GetInstance()->SetArgumentFilterPredicate(
2224 base::Bind(&IsTraceEventArgsWhitelisted));
2225
2226 TraceOptions trace_options;
2227 trace_options.enable_argument_filter = true;
2228 TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"),
2229 TraceLog::RECORDING_MODE, trace_options);
2230
2231 TRACE_EVENT1("toplevel", "event1", "int_one", 1);
2232 TRACE_EVENT1("whitewashed", "event2", "int_two", 1);
2233 EndTraceAndFlush();
2234
2235 const DictionaryValue* args_dict = NULL;
2236 DictionaryValue* dict = NULL;
2237 int int_value;
2238
2239 dict = FindNamePhase("event1", "X");
2240 ASSERT_TRUE(dict);
2241 dict->GetDictionary("args", &args_dict);
2242 ASSERT_TRUE(args_dict);
2243 EXPECT_TRUE(args_dict->GetInteger("int_one", &int_value));
2244 EXPECT_EQ(1, int_value);
2245
2246 dict = FindNamePhase("event2", "X");
2247 ASSERT_TRUE(dict);
2248 dict->GetDictionary("args", &args_dict);
2249 ASSERT_TRUE(args_dict);
2250 EXPECT_FALSE(args_dict->GetInteger("int_two", &int_value));
2251 EXPECT_TRUE(args_dict->GetInteger("stripped", &int_value));
2252 }
2253
2208 class TraceEventCallbackTest : public TraceEventTestFixture { 2254 class TraceEventCallbackTest : public TraceEventTestFixture {
2209 public: 2255 public:
2210 void SetUp() override { 2256 void SetUp() override {
2211 TraceEventTestFixture::SetUp(); 2257 TraceEventTestFixture::SetUp();
2212 ASSERT_EQ(NULL, s_instance); 2258 ASSERT_EQ(NULL, s_instance);
2213 s_instance = this; 2259 s_instance = this;
2214 } 2260 }
2215 void TearDown() override { 2261 void TearDown() override {
2216 TraceLog::GetInstance()->SetDisabled(); 2262 TraceLog::GetInstance()->SetDisabled();
2217 ASSERT_TRUE(s_instance); 2263 ASSERT_TRUE(s_instance);
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after
3075 EXPECT_EQ(original_option.record_mode, new_options.record_mode); 3121 EXPECT_EQ(original_option.record_mode, new_options.record_mode);
3076 EXPECT_EQ(original_option.enable_sampling, new_options.enable_sampling); 3122 EXPECT_EQ(original_option.enable_sampling, new_options.enable_sampling);
3077 EXPECT_EQ(original_option.enable_systrace, new_options.enable_systrace); 3123 EXPECT_EQ(original_option.enable_systrace, new_options.enable_systrace);
3078 } 3124 }
3079 } 3125 }
3080 } 3126 }
3081 } 3127 }
3082 3128
3083 } // namespace trace_event 3129 } // namespace trace_event
3084 } // namespace base 3130 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698