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

Unified Diff: content/browser/tracing/tracing_controller_browsertest.cc

Issue 1502583003: [Tracing] Add metadata filter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile failure on win Created 5 years 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 | « chrome/common/trace_event_args_whitelist.cc ('k') | content/browser/tracing/tracing_controller_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/tracing/tracing_controller_browsertest.cc
diff --git a/content/browser/tracing/tracing_controller_browsertest.cc b/content/browser/tracing/tracing_controller_browsertest.cc
index 3da54e8b4dbf90a60742096b760024f2c93d9a5a..6ab44ca34c4cec39c9310a98e576e3cc9576def2 100644
--- a/content/browser/tracing/tracing_controller_browsertest.cc
+++ b/content/browser/tracing/tracing_controller_browsertest.cc
@@ -5,6 +5,7 @@
#include "base/files/file_util.h"
#include "base/memory/ref_counted_memory.h"
#include "base/run_loop.h"
+#include "base/strings/pattern.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/tracing_controller.h"
#include "content/public/test/browser_test_utils.h"
@@ -18,6 +19,37 @@ using base::trace_event::TraceConfig;
namespace content {
+namespace {
+
+const char* kMetadataWhitelist[] = {
+ "cpu-brand",
+ "network-type",
+ "os-name",
+ "user-agent"
+};
+
+bool IsMetadataWhitelisted(const std::string& metadata_name) {
+ for (auto key : kMetadataWhitelist) {
+ if (base::MatchPattern(metadata_name, key)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool IsTraceEventArgsWhitelisted(
+ const char* category_group_name,
+ const char* event_name,
+ base::trace_event::ArgumentNameFilterPredicate* arg_filter) {
+ if (base::MatchPattern(category_group_name, "benchmark") &&
+ base::MatchPattern(event_name, "whitelisted")) {
+ return true;
+ }
+ return false;
+}
+
+} // namespace
+
class TracingControllerTestEndpoint
: public TracingController::TraceDataEndpoint {
public:
@@ -91,6 +123,7 @@ class TracingControllerTest : public ContentBrowserTest {
base::RefCountedString* data) {
disable_recording_done_callback_count_++;
last_metadata_.reset(metadata.release());
+ last_data_ = data->data();
EXPECT_TRUE(data->size() > 0);
quit_callback.Run();
}
@@ -163,6 +196,10 @@ class TracingControllerTest : public ContentBrowserTest {
return last_metadata_.get();
}
+ const std::string& last_data() const {
+ return last_data_;
+ }
+
void TestStartAndStopTracingString() {
Navigate(shell());
@@ -196,6 +233,53 @@ class TracingControllerTest : public ContentBrowserTest {
}
}
+ void TestStartAndStopTracingStringWithFilter() {
+ Navigate(shell());
+
+ base::trace_event::TraceLog::GetInstance()->SetArgumentFilterPredicate(
+ base::Bind(&IsTraceEventArgsWhitelisted));
+ TracingController* controller = TracingController::GetInstance();
+
+ {
+ base::RunLoop run_loop;
+ TracingController::StartTracingDoneCallback callback =
+ base::Bind(&TracingControllerTest::StartTracingDoneCallbackTest,
+ base::Unretained(this),
+ run_loop.QuitClosure());
+
+ TraceConfig config = TraceConfig();
+ config.EnableArgumentFilter();
+
+ bool result = controller->StartTracing(config, callback);
+ ASSERT_TRUE(result);
+ run_loop.Run();
+ EXPECT_EQ(enable_recording_done_callback_count(), 1);
+ }
+
+ {
+ base::RunLoop run_loop;
+ base::Callback<void(scoped_ptr<const base::DictionaryValue>,
+ base::RefCountedString*)> callback = base::Bind(
+ &TracingControllerTest::StopTracingStringDoneCallbackTest,
+ base::Unretained(this),
+ run_loop.QuitClosure());
+
+ scoped_refptr<TracingController::TraceDataSink> trace_data_sink =
+ TracingController::CreateStringSink(callback);
+
+ trace_data_sink->SetMetadataFilterPredicate(
+ base::Bind(&IsMetadataWhitelisted));
+ base::DictionaryValue metadata;
+ metadata.SetString("not-whitelisted", "this_not_found");
+ trace_data_sink->AddMetadata(metadata);
+
+ bool result = controller->StopTracing(trace_data_sink);
+ ASSERT_TRUE(result);
+ run_loop.Run();
+ EXPECT_EQ(disable_recording_done_callback_count(), 1);
+ }
+ }
+
void TestStartAndStopTracingCompressed() {
Navigate(shell());
@@ -383,6 +467,7 @@ class TracingControllerTest : public ContentBrowserTest {
base::FilePath last_actual_recording_file_path_;
base::FilePath last_actual_monitoring_file_path_;
scoped_ptr<const base::DictionaryValue> last_metadata_;
+ std::string last_data_;
};
IN_PROC_BROWSER_TEST_F(TracingControllerTest, GetCategories) {
@@ -423,6 +508,44 @@ IN_PROC_BROWSER_TEST_F(TracingControllerTest, DisableRecordingStoresMetadata) {
EXPECT_TRUE(cpu_brand.length() > 0);
}
+IN_PROC_BROWSER_TEST_F(TracingControllerTest, NotWhitelistedMetadataStripped) {
+ TestStartAndStopTracingStringWithFilter();
+ // Check that a number of important keys exist in the metadata dictionary.
+ EXPECT_TRUE(last_metadata() != NULL);
+ std::string cpu_brand;
+ last_metadata()->GetString("cpu-brand", &cpu_brand);
+ EXPECT_TRUE(cpu_brand.length() > 0);
+ EXPECT_TRUE(cpu_brand != "__stripped__");
+ std::string network_type;
+ last_metadata()->GetString("network-type", &network_type);
+ EXPECT_TRUE(network_type.length() > 0);
+ EXPECT_TRUE(network_type != "__stripped__");
+ std::string os_name;
+ last_metadata()->GetString("os-name", &os_name);
+ EXPECT_TRUE(os_name.length() > 0);
+ EXPECT_TRUE(os_name != "__stripped__");
+ std::string user_agent;
+ last_metadata()->GetString("user-agent", &user_agent);
+ EXPECT_TRUE(user_agent.length() > 0);
+ EXPECT_TRUE(user_agent != "__stripped__");
+
+ // Check that the not whitelisted metadata is stripped.
+ std::string not_whitelisted;
+ last_metadata()->GetString("not-whitelisted", &not_whitelisted);
+ EXPECT_TRUE(not_whitelisted.length() > 0);
+ EXPECT_TRUE(not_whitelisted == "__stripped__");
+
+ // Also check the string data.
+ EXPECT_TRUE(last_data().size() > 0);
+ EXPECT_TRUE(last_data().find("cpu-brand") != std::string::npos);
+ EXPECT_TRUE(last_data().find("network-type") != std::string::npos);
+ EXPECT_TRUE(last_data().find("os-name") != std::string::npos);
+ EXPECT_TRUE(last_data().find("user-agent") != std::string::npos);
+
+ EXPECT_TRUE(last_data().find("not-whitelisted") != std::string::npos);
+ EXPECT_TRUE(last_data().find("this_not_found") == std::string::npos);
+}
+
IN_PROC_BROWSER_TEST_F(TracingControllerTest,
EnableAndStopTracingWithFilePath) {
base::FilePath file_path;
« no previous file with comments | « chrome/common/trace_event_args_whitelist.cc ('k') | content/browser/tracing/tracing_controller_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698