2013-01-03 18:24:24 +01:00
|
|
|
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
|
2012-10-18 00:45:49 +02:00
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2021-06-17 22:08:01 +02:00
|
|
|
#include "include/base/cef_callback.h"
|
2016-11-15 18:56:02 +01:00
|
|
|
#include "include/cef_file_util.h"
|
2012-10-18 00:45:49 +02:00
|
|
|
#include "include/cef_task.h"
|
|
|
|
#include "include/cef_trace.h"
|
2016-11-15 22:18:41 +01:00
|
|
|
#include "include/cef_waitable_event.h"
|
2014-07-15 20:10:40 +02:00
|
|
|
#include "include/wrapper/cef_closure_task.h"
|
2016-11-18 18:31:21 +01:00
|
|
|
#include "tests/ceftests/test_handler.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/gtest/include/gtest/gtest.h"
|
2017-08-04 00:55:19 +02:00
|
|
|
#include "tests/shared/browser/file_util.h"
|
2012-10-18 00:45:49 +02:00
|
|
|
|
2016-03-16 03:55:59 +01:00
|
|
|
// Use the CEF version of the TRACE_* macros instead of the Chromium version.
|
|
|
|
#undef USING_CHROMIUM_INCLUDES
|
|
|
|
#include "include/base/cef_trace_event.h"
|
|
|
|
|
2012-10-18 00:45:49 +02:00
|
|
|
enum TracingTestType {
|
2014-07-11 22:10:05 +02:00
|
|
|
TT_TRACE_EVENT0,
|
|
|
|
TT_TRACE_EVENT1,
|
|
|
|
TT_TRACE_EVENT2,
|
|
|
|
TT_TRACE_EVENT_INSTANT0,
|
|
|
|
TT_TRACE_EVENT_INSTANT1,
|
|
|
|
TT_TRACE_EVENT_INSTANT2,
|
|
|
|
TT_TRACE_EVENT_BEGIN0,
|
|
|
|
TT_TRACE_EVENT_BEGIN1,
|
|
|
|
TT_TRACE_EVENT_BEGIN2,
|
|
|
|
TT_TRACE_EVENT_END0,
|
|
|
|
TT_TRACE_EVENT_END1,
|
|
|
|
TT_TRACE_EVENT_END2,
|
|
|
|
TT_TRACE_COUNTER1,
|
|
|
|
TT_TRACE_COUNTER2,
|
|
|
|
TT_TRACE_COUNTER_ID1,
|
|
|
|
TT_TRACE_COUNTER_ID2,
|
|
|
|
TT_TRACE_EVENT_ASYNC_BEGIN0,
|
|
|
|
TT_TRACE_EVENT_ASYNC_BEGIN1,
|
|
|
|
TT_TRACE_EVENT_ASYNC_BEGIN2,
|
|
|
|
TT_TRACE_EVENT_ASYNC_STEP_INTO0,
|
|
|
|
TT_TRACE_EVENT_ASYNC_STEP_INTO1,
|
|
|
|
TT_TRACE_EVENT_ASYNC_STEP_PAST0,
|
|
|
|
TT_TRACE_EVENT_ASYNC_STEP_PAST1,
|
|
|
|
TT_TRACE_EVENT_ASYNC_END0,
|
|
|
|
TT_TRACE_EVENT_ASYNC_END1,
|
|
|
|
TT_TRACE_EVENT_ASYNC_END2,
|
2012-10-18 00:45:49 +02:00
|
|
|
};
|
|
|
|
|
2018-11-30 23:21:07 +01:00
|
|
|
const char kTraceTestCategory[] = "cef.client";
|
2012-10-18 00:45:49 +02:00
|
|
|
|
2014-02-05 21:35:45 +01:00
|
|
|
class TracingTestHandler : public CefEndTracingCallback,
|
|
|
|
public CefCompletionCallback {
|
2012-10-18 00:45:49 +02:00
|
|
|
public:
|
|
|
|
TracingTestHandler(TracingTestType type, const char* trace_type)
|
2017-05-17 11:29:28 +02:00
|
|
|
: trace_type_(trace_type), type_(type) {
|
2016-11-15 22:18:41 +01:00
|
|
|
completion_event_ = CefWaitableEvent::CreateWaitableEvent(true, false);
|
2012-10-18 00:45:49 +02:00
|
|
|
}
|
|
|
|
|
2019-02-04 22:36:13 +01:00
|
|
|
void ExecuteTest() {
|
|
|
|
// Run the test.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI,
|
|
|
|
base::BindOnce(&TracingTestHandler::BeginTracing, this));
|
2013-12-17 23:04:35 +01:00
|
|
|
|
2019-02-04 22:36:13 +01:00
|
|
|
// Wait for the test to complete.
|
|
|
|
completion_event_->Wait();
|
2012-10-18 00:45:49 +02:00
|
|
|
|
2019-02-04 22:36:13 +01:00
|
|
|
// Verify the results.
|
|
|
|
EXPECT_TRUE(!trace_data_.empty());
|
2020-01-15 14:34:01 +01:00
|
|
|
EXPECT_TRUE(trace_type_ != nullptr);
|
|
|
|
EXPECT_TRUE(strstr(trace_data_.c_str(), trace_type_) != nullptr);
|
2012-10-18 00:45:49 +02:00
|
|
|
}
|
|
|
|
|
2019-02-04 22:36:13 +01:00
|
|
|
void BeginTracing() {
|
2014-02-05 21:35:45 +01:00
|
|
|
EXPECT_UI_THREAD();
|
2013-12-17 23:04:35 +01:00
|
|
|
|
2019-02-04 22:36:13 +01:00
|
|
|
// Results in a call to OnComplete.
|
|
|
|
CefBeginTracing(kTraceTestCategory, this);
|
2013-12-17 23:04:35 +01:00
|
|
|
}
|
|
|
|
|
2019-02-04 22:36:13 +01:00
|
|
|
void OnComplete() override {
|
2014-02-05 21:35:45 +01:00
|
|
|
EXPECT_UI_THREAD();
|
2013-12-17 23:04:35 +01:00
|
|
|
|
2019-02-04 22:36:13 +01:00
|
|
|
// Add some delay to avoid timing-related test failures.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostDelayedTask(
|
|
|
|
TID_UI, base::BindOnce(&TracingTestHandler::TestTracing, this), 50);
|
2014-02-05 21:35:45 +01:00
|
|
|
}
|
|
|
|
|
2019-02-04 22:36:13 +01:00
|
|
|
void TestTracing() {
|
2014-02-05 21:35:45 +01:00
|
|
|
EXPECT_UI_THREAD();
|
2012-10-18 00:45:49 +02:00
|
|
|
|
|
|
|
switch (type_) {
|
2014-07-11 22:10:05 +02:00
|
|
|
case TT_TRACE_EVENT0: {
|
|
|
|
TRACE_EVENT0(kTraceTestCategory, "TT_TRACE_EVENT0");
|
2017-05-17 11:29:28 +02:00
|
|
|
} break;
|
2014-07-11 22:10:05 +02:00
|
|
|
case TT_TRACE_EVENT1: {
|
|
|
|
TRACE_EVENT1(kTraceTestCategory, "TT_TRACE_EVENT1", "arg1", 1);
|
2017-05-17 11:29:28 +02:00
|
|
|
} break;
|
2014-07-11 22:10:05 +02:00
|
|
|
case TT_TRACE_EVENT2: {
|
2017-05-17 11:29:28 +02:00
|
|
|
TRACE_EVENT2(kTraceTestCategory, "TT_TRACE_EVENT2", "arg1", 1, "arg2",
|
|
|
|
2);
|
|
|
|
} break;
|
2014-07-11 22:10:05 +02:00
|
|
|
case TT_TRACE_EVENT_INSTANT0:
|
2017-05-17 11:29:28 +02:00
|
|
|
TRACE_EVENT_INSTANT0(kTraceTestCategory, "TT_TRACE_EVENT_INSTANT0");
|
2012-10-18 00:45:49 +02:00
|
|
|
break;
|
2014-07-11 22:10:05 +02:00
|
|
|
case TT_TRACE_EVENT_INSTANT1:
|
|
|
|
TRACE_EVENT_INSTANT1(kTraceTestCategory, "TT_TRACE_EVENT_INSTANT1",
|
|
|
|
"arg1", 1);
|
2012-10-18 00:45:49 +02:00
|
|
|
break;
|
2014-07-11 22:10:05 +02:00
|
|
|
case TT_TRACE_EVENT_INSTANT2:
|
|
|
|
TRACE_EVENT_INSTANT2(kTraceTestCategory, "TT_TRACE_EVENT_INSTANT2",
|
|
|
|
"arg1", 1, "arg2", 2);
|
2012-10-18 00:45:49 +02:00
|
|
|
break;
|
2014-07-11 22:10:05 +02:00
|
|
|
case TT_TRACE_EVENT_BEGIN0:
|
|
|
|
TRACE_EVENT_BEGIN0(kTraceTestCategory, "TT_TRACE_EVENT_BEGIN0");
|
2012-10-18 00:45:49 +02:00
|
|
|
break;
|
2014-07-11 22:10:05 +02:00
|
|
|
case TT_TRACE_EVENT_BEGIN1:
|
2017-05-17 11:29:28 +02:00
|
|
|
TRACE_EVENT_BEGIN1(kTraceTestCategory, "TT_TRACE_EVENT_BEGIN1", "arg1",
|
|
|
|
1);
|
2012-10-18 00:45:49 +02:00
|
|
|
break;
|
2014-07-11 22:10:05 +02:00
|
|
|
case TT_TRACE_EVENT_BEGIN2:
|
2017-05-17 11:29:28 +02:00
|
|
|
TRACE_EVENT_BEGIN2(kTraceTestCategory, "TT_TRACE_EVENT_BEGIN2", "arg1",
|
|
|
|
1, "arg2", 2);
|
2012-10-18 00:45:49 +02:00
|
|
|
break;
|
2014-07-11 22:10:05 +02:00
|
|
|
case TT_TRACE_EVENT_END0:
|
2020-02-10 18:10:17 +01:00
|
|
|
TRACE_EVENT_BEGIN0(kTraceTestCategory, "TT_TRACE_EVENT_END0");
|
2014-07-11 22:10:05 +02:00
|
|
|
TRACE_EVENT_END0(kTraceTestCategory, "TT_TRACE_EVENT_END0");
|
2012-10-18 00:45:49 +02:00
|
|
|
break;
|
2014-07-11 22:10:05 +02:00
|
|
|
case TT_TRACE_EVENT_END1:
|
2020-02-10 18:10:17 +01:00
|
|
|
TRACE_EVENT_BEGIN1(kTraceTestCategory, "TT_TRACE_EVENT_END1", "arg1",
|
|
|
|
1);
|
2017-05-17 11:29:28 +02:00
|
|
|
TRACE_EVENT_END1(kTraceTestCategory, "TT_TRACE_EVENT_END1", "arg1", 1);
|
2012-10-18 00:45:49 +02:00
|
|
|
break;
|
2014-07-11 22:10:05 +02:00
|
|
|
case TT_TRACE_EVENT_END2:
|
2020-02-10 18:10:17 +01:00
|
|
|
TRACE_EVENT_BEGIN2(kTraceTestCategory, "TT_TRACE_EVENT_END2", "arg1", 1,
|
|
|
|
"arg2", 2);
|
2017-05-17 11:29:28 +02:00
|
|
|
TRACE_EVENT_END2(kTraceTestCategory, "TT_TRACE_EVENT_END2", "arg1", 1,
|
|
|
|
"arg2", 2);
|
2014-07-11 22:10:05 +02:00
|
|
|
break;
|
|
|
|
case TT_TRACE_COUNTER1:
|
|
|
|
TRACE_COUNTER1(kTraceTestCategory, "TT_TRACE_COUNTER1", 5);
|
|
|
|
break;
|
|
|
|
case TT_TRACE_COUNTER2:
|
|
|
|
TRACE_COUNTER2(kTraceTestCategory, "TT_TRACE_COUNTER2", "val1", 5,
|
|
|
|
"val2", 10);
|
|
|
|
break;
|
|
|
|
case TT_TRACE_COUNTER_ID1:
|
|
|
|
TRACE_COUNTER_ID1(kTraceTestCategory, "TT_TRACE_COUNTER_ID1", 100, 5);
|
|
|
|
break;
|
|
|
|
case TT_TRACE_COUNTER_ID2:
|
|
|
|
TRACE_COUNTER_ID2(kTraceTestCategory, "TT_TRACE_COUNTER_ID2", 100,
|
|
|
|
"val1", 5, "val2", 10);
|
2012-10-18 00:45:49 +02:00
|
|
|
break;
|
2014-07-11 22:10:05 +02:00
|
|
|
case TT_TRACE_EVENT_ASYNC_BEGIN0:
|
|
|
|
TRACE_EVENT_ASYNC_BEGIN0(kTraceTestCategory,
|
|
|
|
"TT_TRACE_EVENT_ASYNC_BEGIN0", 100);
|
|
|
|
break;
|
|
|
|
case TT_TRACE_EVENT_ASYNC_BEGIN1:
|
|
|
|
TRACE_EVENT_ASYNC_BEGIN1(kTraceTestCategory,
|
|
|
|
"TT_TRACE_EVENT_ASYNC_BEGIN1", 100, "arg1", 1);
|
|
|
|
break;
|
|
|
|
case TT_TRACE_EVENT_ASYNC_BEGIN2:
|
|
|
|
TRACE_EVENT_ASYNC_BEGIN2(kTraceTestCategory,
|
2017-05-17 11:29:28 +02:00
|
|
|
"TT_TRACE_EVENT_ASYNC_BEGIN2", 100, "arg1", 1,
|
|
|
|
"arg2", 2);
|
2014-07-11 22:10:05 +02:00
|
|
|
break;
|
|
|
|
case TT_TRACE_EVENT_ASYNC_STEP_INTO0:
|
|
|
|
TRACE_EVENT_ASYNC_STEP_INTO0(
|
|
|
|
kTraceTestCategory, "TT_TRACE_EVENT_ASYNC_STEP_INTO0", 100, 1000);
|
|
|
|
break;
|
|
|
|
case TT_TRACE_EVENT_ASYNC_STEP_INTO1:
|
2017-05-17 11:29:28 +02:00
|
|
|
TRACE_EVENT_ASYNC_STEP_INTO1(kTraceTestCategory,
|
|
|
|
"TT_TRACE_EVENT_ASYNC_STEP_INTO1", 100,
|
|
|
|
1000, "arg1", 1);
|
2012-10-18 00:45:49 +02:00
|
|
|
break;
|
2014-07-11 22:10:05 +02:00
|
|
|
case TT_TRACE_EVENT_ASYNC_STEP_PAST0:
|
|
|
|
TRACE_EVENT_ASYNC_STEP_PAST0(
|
|
|
|
kTraceTestCategory, "TT_TRACE_EVENT_ASYNC_STEP_PAST0", 100, 1000);
|
2013-10-29 18:53:18 +01:00
|
|
|
break;
|
2014-07-11 22:10:05 +02:00
|
|
|
case TT_TRACE_EVENT_ASYNC_STEP_PAST1:
|
2017-05-17 11:29:28 +02:00
|
|
|
TRACE_EVENT_ASYNC_STEP_PAST1(kTraceTestCategory,
|
|
|
|
"TT_TRACE_EVENT_ASYNC_STEP_PAST1", 100,
|
|
|
|
1000, "arg1", 1);
|
2013-10-29 18:53:18 +01:00
|
|
|
break;
|
2014-07-11 22:10:05 +02:00
|
|
|
case TT_TRACE_EVENT_ASYNC_END0:
|
2021-03-04 23:36:57 +01:00
|
|
|
TRACE_EVENT_ASYNC_BEGIN0(kTraceTestCategory,
|
|
|
|
"TT_TRACE_EVENT_ASYNC_END0", 100);
|
2017-05-17 11:29:28 +02:00
|
|
|
TRACE_EVENT_ASYNC_END0(kTraceTestCategory, "TT_TRACE_EVENT_ASYNC_END0",
|
|
|
|
100);
|
2014-07-11 22:10:05 +02:00
|
|
|
break;
|
|
|
|
case TT_TRACE_EVENT_ASYNC_END1:
|
2021-03-04 23:36:57 +01:00
|
|
|
TRACE_EVENT_ASYNC_BEGIN1(kTraceTestCategory,
|
|
|
|
"TT_TRACE_EVENT_ASYNC_END1", 100, "arg1", 1);
|
2017-05-17 11:29:28 +02:00
|
|
|
TRACE_EVENT_ASYNC_END1(kTraceTestCategory, "TT_TRACE_EVENT_ASYNC_END1",
|
|
|
|
100, "arg1", 1);
|
2014-07-11 22:10:05 +02:00
|
|
|
break;
|
|
|
|
case TT_TRACE_EVENT_ASYNC_END2:
|
2021-03-04 23:36:57 +01:00
|
|
|
TRACE_EVENT_ASYNC_BEGIN2(kTraceTestCategory,
|
|
|
|
"TT_TRACE_EVENT_ASYNC_END2", 100, "arg1", 1,
|
|
|
|
"arg2", 2);
|
2017-05-17 11:29:28 +02:00
|
|
|
TRACE_EVENT_ASYNC_END2(kTraceTestCategory, "TT_TRACE_EVENT_ASYNC_END2",
|
|
|
|
100, "arg1", 1, "arg2", 2);
|
2018-03-20 21:15:08 +01:00
|
|
|
break;
|
2012-10-18 00:45:49 +02:00
|
|
|
}
|
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
// Results in a call to OnEndTracingComplete.
|
2014-02-05 21:35:45 +01:00
|
|
|
CefEndTracing(CefString(), this);
|
2012-10-18 00:45:49 +02:00
|
|
|
}
|
|
|
|
|
2019-02-04 22:36:13 +01:00
|
|
|
void OnEndTracingComplete(const CefString& tracing_file) override {
|
|
|
|
EXPECT_UI_THREAD();
|
2012-10-18 00:45:49 +02:00
|
|
|
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_FILE_USER_VISIBLE,
|
|
|
|
base::BindOnce(&TracingTestHandler::ReadTracingFile, this,
|
|
|
|
tracing_file));
|
2019-02-04 22:36:13 +01:00
|
|
|
}
|
2013-12-17 23:04:35 +01:00
|
|
|
|
2019-02-04 22:36:13 +01:00
|
|
|
void ReadTracingFile(const std::string& file_path) {
|
|
|
|
EXPECT_FILE_THREAD();
|
|
|
|
|
|
|
|
EXPECT_TRUE(client::file_util::ReadFileToString(file_path, &trace_data_));
|
|
|
|
EXPECT_TRUE(CefDeleteFile(file_path, false));
|
|
|
|
|
|
|
|
completion_event_->Signal();
|
2012-10-18 00:45:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2024-01-20 18:00:09 +01:00
|
|
|
~TracingTestHandler() override = default;
|
2012-10-18 00:45:49 +02:00
|
|
|
|
|
|
|
// Handle used to notify when the test is complete.
|
2016-11-15 22:18:41 +01:00
|
|
|
CefRefPtr<CefWaitableEvent> completion_event_;
|
2012-10-18 00:45:49 +02:00
|
|
|
|
|
|
|
const char* trace_type_;
|
|
|
|
TracingTestType type_;
|
|
|
|
std::string trace_data_;
|
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(TracingTestHandler);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Helper for defining tracing tests.
|
2017-05-17 11:29:28 +02:00
|
|
|
#define TRACING_TEST(name, test_type) \
|
|
|
|
TEST(TracingTest, name) { \
|
|
|
|
CefRefPtr<TracingTestHandler> handler = \
|
|
|
|
new TracingTestHandler(test_type, #test_type); \
|
|
|
|
handler->ExecuteTest(); \
|
|
|
|
}
|
2012-10-18 00:45:49 +02:00
|
|
|
|
|
|
|
// Define the tests.
|
2019-03-13 22:27:37 +01:00
|
|
|
TRACING_TEST(TraceEvent0, TT_TRACE_EVENT0)
|
|
|
|
TRACING_TEST(TraceEvent1, TT_TRACE_EVENT1)
|
|
|
|
TRACING_TEST(TraceEvent2, TT_TRACE_EVENT2)
|
|
|
|
TRACING_TEST(TraceEventInstant0, TT_TRACE_EVENT_INSTANT0)
|
|
|
|
TRACING_TEST(TraceEventInstant1, TT_TRACE_EVENT_INSTANT1)
|
|
|
|
TRACING_TEST(TraceEventInstant2, TT_TRACE_EVENT_INSTANT2)
|
|
|
|
TRACING_TEST(TraceEventBegin0, TT_TRACE_EVENT_BEGIN0)
|
|
|
|
TRACING_TEST(TraceEventBegin1, TT_TRACE_EVENT_BEGIN1)
|
|
|
|
TRACING_TEST(TraceEventBegin2, TT_TRACE_EVENT_BEGIN2)
|
|
|
|
TRACING_TEST(TraceEventEnd0, TT_TRACE_EVENT_END0)
|
|
|
|
TRACING_TEST(TraceEventEnd1, TT_TRACE_EVENT_END1)
|
|
|
|
TRACING_TEST(TraceEventEnd2, TT_TRACE_EVENT_END2)
|
|
|
|
TRACING_TEST(TraceCounter1, TT_TRACE_COUNTER1)
|
|
|
|
TRACING_TEST(TraceCounter2, TT_TRACE_COUNTER2)
|
|
|
|
TRACING_TEST(TraceCounterId1, TT_TRACE_COUNTER_ID1)
|
|
|
|
TRACING_TEST(TraceCounterId2, TT_TRACE_COUNTER_ID2)
|
|
|
|
TRACING_TEST(TraceEventAsyncBegin0, TT_TRACE_EVENT_ASYNC_BEGIN0)
|
|
|
|
TRACING_TEST(TraceEventAsyncBegin1, TT_TRACE_EVENT_ASYNC_BEGIN1)
|
|
|
|
TRACING_TEST(TraceEventAsyncBegin2, TT_TRACE_EVENT_ASYNC_BEGIN2)
|
|
|
|
TRACING_TEST(TraceEventAsyncStepInto0, TT_TRACE_EVENT_ASYNC_STEP_INTO0)
|
|
|
|
TRACING_TEST(TraceEventAsyncStepInto1, TT_TRACE_EVENT_ASYNC_STEP_INTO1)
|
|
|
|
TRACING_TEST(TraceEventAsyncStepPast0, TT_TRACE_EVENT_ASYNC_STEP_PAST0)
|
|
|
|
TRACING_TEST(TraceEventAsyncStepPast1, TT_TRACE_EVENT_ASYNC_STEP_PAST1)
|
|
|
|
TRACING_TEST(TraceEventAsyncEnd0, TT_TRACE_EVENT_ASYNC_END0)
|
|
|
|
TRACING_TEST(TraceEventAsyncEnd1, TT_TRACE_EVENT_ASYNC_END1)
|
|
|
|
TRACING_TEST(TraceEventAsyncEnd2, TT_TRACE_EVENT_ASYNC_END2)
|
2013-03-15 20:57:20 +01:00
|
|
|
|
|
|
|
TEST(TracingTest, NowFromSystemTraceTime) {
|
2023-06-01 16:06:15 +02:00
|
|
|
int64_t val = CefNowFromSystemTraceTime();
|
2013-03-15 20:57:20 +01:00
|
|
|
EXPECT_NE(val, 0);
|
|
|
|
}
|