summaryrefslogtreecommitdiff
path: root/chromium/base/test
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/base/test')
-rw-r--r--chromium/base/test/BUILD.gn29
-rw-r--r--chromium/base/test/OWNERS4
-rw-r--r--chromium/base/test/generate_fontconfig_caches.cc16
-rw-r--r--chromium/base/test/gtest_links.cc44
-rw-r--r--chromium/base/test/gtest_links.h28
-rw-r--r--chromium/base/test/gtest_links_unittest.cc24
-rw-r--r--chromium/base/test/gtest_util.h9
-rw-r--r--chromium/base/test/gtest_xml_unittest_result_printer.cc51
-rw-r--r--chromium/base/test/gtest_xml_unittest_result_printer.h14
-rw-r--r--chromium/base/test/gtest_xml_unittest_result_printer_unittest.cc51
-rw-r--r--chromium/base/test/gtest_xml_util.cc32
-rw-r--r--chromium/base/test/power_monitor_test_base.cc20
-rw-r--r--chromium/base/test/power_monitor_test_base.h19
-rw-r--r--chromium/base/test/scoped_feature_list.cc2
-rw-r--r--chromium/base/test/scoped_run_loop_timeout.cc1
-rw-r--r--chromium/base/test/test_file_util_win.cc22
-rw-r--r--chromium/base/test/test_pending_task.h2
-rw-r--r--chromium/base/test/test_pending_task_unittest.cc5
-rw-r--r--chromium/base/test/test_suite.cc13
-rw-r--r--chromium/base/test/test_suite.h14
-rw-r--r--chromium/base/test/test_switches.cc3
-rw-r--r--chromium/base/test/test_switches.h1
-rw-r--r--chromium/base/test/test_timeouts.cc45
-rw-r--r--chromium/base/test/test_timeouts.h18
-rw-r--r--chromium/base/test/trace_event_analyzer.cc1
-rw-r--r--chromium/base/test/trace_event_analyzer.h2
-rw-r--r--chromium/base/test/with_feature_override.h17
27 files changed, 396 insertions, 91 deletions
diff --git a/chromium/base/test/BUILD.gn b/chromium/base/test/BUILD.gn
index 86b11128e51..4d8906aa2dd 100644
--- a/chromium/base/test/BUILD.gn
+++ b/chromium/base/test/BUILD.gn
@@ -5,6 +5,7 @@
import("//build/compiled_action.gni")
import("//build/config/nacl/config.gni")
import("//build/config/ui.gni")
+import("//build_overrides/build.gni")
# Reset sources_assignment_filter for the BUILD.gn file to prevent
# regression during the migration of Chromium away from the feature.
@@ -46,13 +47,14 @@ static_library("test_support") {
"../task/sequence_manager/test/test_task_time_observer.h",
"../timer/mock_timer.cc",
"../timer/mock_timer.h",
- "../trace_event/trace_config_memory_test_util.h",
"bind_test_util.cc",
"bind_test_util.h",
"copy_only_int.cc",
"copy_only_int.h",
"gmock_callback_support.h",
"gmock_move_support.h",
+ "gtest_links.cc",
+ "gtest_links.h",
"gtest_util.cc",
"gtest_util.h",
"gtest_xml_unittest_result_printer.cc",
@@ -138,10 +140,6 @@ static_library("test_support") {
"test_waitable_event.h",
"thread_test_helper.cc",
"thread_test_helper.h",
- "trace_event_analyzer.cc",
- "trace_event_analyzer.h",
- "trace_to_file.cc",
- "trace_to_file.h",
"values_test_util.cc",
"values_test_util.h",
"with_feature_override.cc",
@@ -281,8 +279,6 @@ static_library("test_support") {
"test_file_util_posix.cc",
"test_suite.cc",
"test_suite.h",
- "trace_to_file.cc",
- "trace_to_file.h",
]
public_deps -= [ "//base:i18n" ]
deps -= [
@@ -303,6 +299,20 @@ static_library("test_support") {
"multiprocess_test.cc",
]
}
+
+ if (enable_base_tracing) {
+ sources += [
+ "../trace_event/trace_config_memory_test_util.h",
+ "trace_event_analyzer.cc",
+ "trace_event_analyzer.h",
+ ]
+ if (!is_nacl_nonsfi) {
+ sources += [
+ "trace_to_file.cc",
+ "trace_to_file.h",
+ ]
+ }
+ }
}
config("base_test_implementation") {
@@ -429,10 +439,7 @@ if (is_linux) {
# be listed in deps, not data_deps (https://crbug.com/919422).
deps = [ "//third_party/test_fonts" ]
args = []
- outputs = [
- "$root_out_dir/fontconfig_caches/fb5c91b2895aa445d23aebf7f9e2189c-le64.cache-7",
- "$root_out_dir/test_fonts/.uuid",
- ]
+ outputs = [ "$root_out_dir/fontconfig_caches/fb5c91b2895aa445d23aebf7f9e2189c-le64.cache-7" ]
}
}
}
diff --git a/chromium/base/test/OWNERS b/chromium/base/test/OWNERS
index 08d2b4c340d..11bba8aa90f 100644
--- a/chromium/base/test/OWNERS
+++ b/chromium/base/test/OWNERS
@@ -11,5 +11,9 @@ per-file *_win*=file://base/win/OWNERS
per-file *android*=file://base/test/android/OWNERS
per-file BUILD.gn=file://base/test/android/OWNERS
+# For iOS-specific changes:
+per-file *ios*=file://base/test/ios/OWNERS
+per-file BUILD.gn=file://base/test/ios/OWNERS
+
# Linux fontconfig changes
per-file *fontconfig*=file://base/nix/OWNERS
diff --git a/chromium/base/test/generate_fontconfig_caches.cc b/chromium/base/test/generate_fontconfig_caches.cc
index cd01d551ef0..84eac2b5c1c 100644
--- a/chromium/base/test/generate_fontconfig_caches.cc
+++ b/chromium/base/test/generate_fontconfig_caches.cc
@@ -25,16 +25,14 @@
// determinism. We have no way of guaranteeing that this produces correct
// results, or even has the intended effect.
int main() {
- // fontconfig generates a random uuid and uses it to match font folders with
- // the font cache. Rather than letting fontconfig generate a random uuid,
- // which introduces build non-determinism, we place a fixed uuid in the font
- // folder, which fontconfig will use to generate the cache.
base::FilePath dir_module;
base::PathService::Get(base::DIR_MODULE, &dir_module);
- base::FilePath uuid_file_path =
- dir_module.Append("test_fonts").Append(".uuid");
- const char uuid[] = "fb5c91b2895aa445d23aebf7f9e2189c";
- WriteFile(uuid_file_path, uuid);
+
+ // This is the MD5 hash of "/test_fonts", which is used as the key of the
+ // fontconfig cache.
+ // $ echo -n /test_fonts | md5sum
+ // fb5c91b2895aa445d23aebf7f9e2189c -
+ static const char kCacheKey[] = "fb5c91b2895aa445d23aebf7f9e2189c";
// fontconfig writes the mtime of the test_fonts directory into the cache. It
// presumably checks this later to ensure that the cache is still up to date.
@@ -61,6 +59,6 @@ int main() {
// Check existence of intended fontconfig cache file.
CHECK(base::PathExists(
- fontconfig_caches.Append(base::StrCat({uuid, "-le64.cache-7"}))));
+ fontconfig_caches.Append(base::StrCat({kCacheKey, "-le64.cache-7"}))));
return 0;
}
diff --git a/chromium/base/test/gtest_links.cc b/chromium/base/test/gtest_links.cc
new file mode 100644
index 00000000000..2174f464744
--- /dev/null
+++ b/chromium/base/test/gtest_links.cc
@@ -0,0 +1,44 @@
+// Copyright 2020 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 "base/test/gtest_links.h"
+
+#include "base/check.h"
+#include "base/strings/string_util.h"
+#include "base/test/gtest_xml_unittest_result_printer.h"
+
+namespace base {
+namespace {
+
+bool IsValidUrl(const std::string& url) {
+ // https://www.ietf.org/rfc/rfc3986.txt
+ std::set<char> valid_characters{'-', '.', '_', '~', ':', '/', '?', '#',
+ '[', ']', '@', '!', '$', '&', '\'', '(',
+ ')', '*', '+', ',', ';', '%', '='};
+ for (const char& c : url) {
+ if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
+ (c >= '0' && c <= '9') ||
+ valid_characters.find(c) != valid_characters.end()))
+ return false;
+ }
+ return true;
+}
+
+bool IsValidName(const std::string& name) {
+ for (const char& c : name) {
+ if (!(IsAsciiAlpha(c) || IsAsciiDigit(c) || c == '/' || c == '_'))
+ return false;
+ }
+ return true;
+}
+
+} // namespace
+
+void AddLinkToTestResult(const std::string& name, const std::string& url) {
+ DCHECK(IsValidName(name)) << name << " is not a valid name";
+ DCHECK(IsValidUrl(url)) << url << " is not a valid link";
+ XmlUnitTestResultPrinter::Get()->AddLink(name, url);
+}
+
+} // namespace base
diff --git a/chromium/base/test/gtest_links.h b/chromium/base/test/gtest_links.h
new file mode 100644
index 00000000000..bece31ea023
--- /dev/null
+++ b/chromium/base/test/gtest_links.h
@@ -0,0 +1,28 @@
+// Copyright 2020 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.
+
+#ifndef BASE_TEST_GTEST_LINKS_H_
+#define BASE_TEST_GTEST_LINKS_H_
+
+#include <string>
+
+namespace base {
+
+// Add a link in the gtest xml output.
+// Only call this from a gtest test body with the same thread as the test.
+// Only works on desktop.
+// A test can call this function when the test generates a link and save it
+// as part of the test result.
+// Example: AddLinkToTestResult("image_link",
+// "https://example_googlestorage/test.png") can mean a test generates an image
+// with the url.
+// |name| is the link name. It should be unique in one test case. Name will
+// be displayed on test result page(Milo). |name| should only contains
+// ascii-letters, ascii-digits, '/' and '_'.
+// |url| the actual url.
+void AddLinkToTestResult(const std::string& name, const std::string& url);
+
+} // namespace base
+
+#endif // BASE_TEST_GTEST_LINKS_H_
diff --git a/chromium/base/test/gtest_links_unittest.cc b/chromium/base/test/gtest_links_unittest.cc
new file mode 100644
index 00000000000..1810ae8de6a
--- /dev/null
+++ b/chromium/base/test/gtest_links_unittest.cc
@@ -0,0 +1,24 @@
+// Copyright 2020 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 "base/test/gtest_links.h"
+
+#include "base/test/gtest_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace base {
+
+TEST(GtestLinksTest, AddInvalidLink) {
+ EXPECT_DCHECK_DEATH(AddLinkToTestResult("unique_link", "invalid`"));
+}
+
+TEST(GtestLinksTest, AddInvalidName) {
+ EXPECT_DCHECK_DEATH(AddLinkToTestResult("invalid-name", "http://google.com"));
+}
+
+TEST(GtestLinksTest, AddValidLink) {
+ AddLinkToTestResult("name", "http://google.com");
+}
+
+} // namespace base
diff --git a/chromium/base/test/gtest_util.h b/chromium/base/test/gtest_util.h
index 1db1fae1e2d..443fa1ad829 100644
--- a/chromium/base/test/gtest_util.h
+++ b/chromium/base/test/gtest_util.h
@@ -9,8 +9,8 @@
#include <utility>
#include <vector>
+#include "base/check_op.h"
#include "base/compiler_specific.h"
-#include "base/logging.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -27,15 +27,8 @@
// is part of the error message), but intentionally do not expose the gtest
// death test's full |regex| parameter to avoid users having to verify the exact
// syntax of the error message produced by the DCHECK.
-
-// Official builds will eat stream parameters, so don't check the error message.
-#if defined(OFFICIAL_BUILD) && defined(NDEBUG)
-#define EXPECT_DCHECK_DEATH(statement) EXPECT_DEATH(statement, "")
-#define ASSERT_DCHECK_DEATH(statement) ASSERT_DEATH(statement, "")
-#else
#define EXPECT_DCHECK_DEATH(statement) EXPECT_DEATH(statement, "Check failed")
#define ASSERT_DCHECK_DEATH(statement) ASSERT_DEATH(statement, "Check failed")
-#endif // defined(OFFICIAL_BUILD) && defined(NDEBUG)
#else
// DCHECK_IS_ON() && defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID)
diff --git a/chromium/base/test/gtest_xml_unittest_result_printer.cc b/chromium/base/test/gtest_xml_unittest_result_printer.cc
index 709450b5329..c7f29ce701d 100644
--- a/chromium/base/test/gtest_xml_unittest_result_printer.cc
+++ b/chromium/base/test/gtest_xml_unittest_result_printer.cc
@@ -8,7 +8,9 @@
#include "base/check.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
+#include "base/strings/string_util.h"
#include "base/test/test_switches.h"
+#include "base/threading/thread_checker.h"
#include "base/time/time.h"
namespace base {
@@ -19,12 +21,29 @@ const int kDefaultTestPartResultsLimit = 10;
const char kTestPartLesultsLimitExceeded[] =
"Test part results limit exceeded. Use --test-launcher-test-part-limit to "
"increase or disable limit.";
+
+std::string EscapeUrl(const std::string& url) {
+ std::string escaped_url;
+ ReplaceChars(url, "&", "&amp;", &escaped_url);
+ ReplaceChars(escaped_url, "<", "&lt;", &escaped_url);
+ ReplaceChars(escaped_url, ">", "&gt;", &escaped_url);
+ ReplaceChars(escaped_url, "'", "&apos;", &escaped_url);
+ ReplaceChars(escaped_url, "\"", "&quot;", &escaped_url);
+ return escaped_url;
+}
+
} // namespace
-XmlUnitTestResultPrinter::XmlUnitTestResultPrinter()
- : output_file_(nullptr), open_failed_(false) {}
+XmlUnitTestResultPrinter* XmlUnitTestResultPrinter::instance_ = nullptr;
+
+XmlUnitTestResultPrinter::XmlUnitTestResultPrinter() {
+ DCHECK_EQ(instance_, nullptr);
+ instance_ = this;
+}
XmlUnitTestResultPrinter::~XmlUnitTestResultPrinter() {
+ DCHECK_EQ(instance_, this);
+ instance_ = nullptr;
if (output_file_ && !open_failed_) {
fprintf(output_file_, "</testsuites>\n");
fflush(output_file_);
@@ -32,6 +51,34 @@ XmlUnitTestResultPrinter::~XmlUnitTestResultPrinter() {
}
}
+XmlUnitTestResultPrinter* XmlUnitTestResultPrinter::Get() {
+ DCHECK(instance_);
+ DCHECK(instance_->thread_checker_.CalledOnValidThread());
+ return instance_;
+}
+
+void XmlUnitTestResultPrinter::AddLink(const std::string& name,
+ const std::string& url) {
+ DCHECK(output_file_);
+ DCHECK(!open_failed_);
+ // Escape the url so it's safe to save in xml file.
+ const std::string escaped_url = EscapeUrl(url);
+ const testing::TestInfo* info =
+ testing::UnitTest::GetInstance()->current_test_info();
+ // When this function is not called from a gtest test body, it will
+ // return null. E.g. call from Chromium itself or from test launcher.
+ // But when that happens, the previous two DCHECK won't pass. So in
+ // theory it should not be possible to reach here and the info is null.
+ DCHECK(info);
+
+ fprintf(output_file_,
+ " <link name=\"%s\" classname=\"%s\" "
+ "link_name=\"%s\">%s</link>\n",
+ info->name(), info->test_case_name(), name.c_str(),
+ escaped_url.c_str());
+ fflush(output_file_);
+}
+
bool XmlUnitTestResultPrinter::Initialize(const FilePath& output_file_path) {
DCHECK(!output_file_);
output_file_ = OpenFile(output_file_path, "w");
diff --git a/chromium/base/test/gtest_xml_unittest_result_printer.h b/chromium/base/test/gtest_xml_unittest_result_printer.h
index 93403822cfa..39d7d6d4339 100644
--- a/chromium/base/test/gtest_xml_unittest_result_printer.h
+++ b/chromium/base/test/gtest_xml_unittest_result_printer.h
@@ -9,6 +9,7 @@
#include "base/compiler_specific.h"
#include "base/macros.h"
+#include "base/threading/thread_checker.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
@@ -22,6 +23,13 @@ class XmlUnitTestResultPrinter : public testing::EmptyTestEventListener {
XmlUnitTestResultPrinter();
~XmlUnitTestResultPrinter() override;
+ static XmlUnitTestResultPrinter* Get();
+
+ // Add link in the gtest xml output.
+ // Please see AddLinkToTestResult in gtest_links.h for detailed
+ // explanation and usage.
+ void AddLink(const std::string& name, const std::string& url);
+
// Must be called before adding as a listener. Returns true on success.
bool Initialize(const FilePath& output_file_path) WARN_UNUSED_RESULT;
@@ -44,8 +52,10 @@ class XmlUnitTestResultPrinter : public testing::EmptyTestEventListener {
const std::string& summary,
const std::string& message);
- FILE* output_file_;
- bool open_failed_;
+ static XmlUnitTestResultPrinter* instance_;
+ FILE* output_file_{nullptr};
+ bool open_failed_{false};
+ ThreadChecker thread_checker_;
DISALLOW_COPY_AND_ASSIGN(XmlUnitTestResultPrinter);
};
diff --git a/chromium/base/test/gtest_xml_unittest_result_printer_unittest.cc b/chromium/base/test/gtest_xml_unittest_result_printer_unittest.cc
new file mode 100644
index 00000000000..7743ee4fde8
--- /dev/null
+++ b/chromium/base/test/gtest_xml_unittest_result_printer_unittest.cc
@@ -0,0 +1,51 @@
+// Copyright 2020 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 "base/test/gtest_xml_unittest_result_printer.h"
+
+#include "base/base64.h"
+#include "base/command_line.h"
+#include "base/files/file_util.h"
+#include "base/strings/strcat.h"
+#include "base/test/test_switches.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace base {
+
+TEST(XmlUnitTestResultPrinterTest, LinkInXmlFile) {
+ XmlUnitTestResultPrinter::Get()->AddLink("unique_link", "http://google.com");
+ std::string file_path =
+ base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+ switches::kTestLauncherOutput);
+ std::string content;
+ ASSERT_TRUE(
+ base::ReadFileToString(FilePath::FromUTF8Unsafe(file_path), &content));
+ std::string expected_content =
+ base::StrCat({"<link name=\"LinkInXmlFile\" "
+ "classname=\"XmlUnitTestResultPrinterTest\" "
+ "link_name=\"unique_link\">",
+ "http://google.com", "</link>"});
+ EXPECT_TRUE(content.find(expected_content) != std::string::npos)
+ << expected_content << " not found in " << content;
+}
+
+TEST(XmlUnitTestResultPrinterTest, EscapedLinkInXmlFile) {
+ XmlUnitTestResultPrinter::Get()->AddLink(
+ "unique_link", "http://google.com/path?id=\"'<>&\"");
+ std::string file_path =
+ base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+ switches::kTestLauncherOutput);
+ std::string content;
+ ASSERT_TRUE(
+ base::ReadFileToString(FilePath::FromUTF8Unsafe(file_path), &content));
+ std::string expected_content = base::StrCat(
+ {"<link name=\"EscapedLinkInXmlFile\" "
+ "classname=\"XmlUnitTestResultPrinterTest\" "
+ "link_name=\"unique_link\">",
+ "http://google.com/path?id=&quot;&apos;&lt;&gt;&amp;&quot;", "</link>"});
+ EXPECT_TRUE(content.find(expected_content) != std::string::npos)
+ << expected_content << " not found in " << content;
+}
+
+} // namespace base
diff --git a/chromium/base/test/gtest_xml_util.cc b/chromium/base/test/gtest_xml_util.cc
index 1bac5a6b1d2..620d9bafcee 100644
--- a/chromium/base/test/gtest_xml_util.cc
+++ b/chromium/base/test/gtest_xml_util.cc
@@ -32,6 +32,17 @@ static void XmlErrorFunc(void *context, const char *message, ...) {
} // namespace
+struct Link {
+ // The name of the test case.
+ std::string name;
+ // The name of the classname of the test.
+ std::string classname;
+ // The name of the link.
+ std::string link_name;
+ // The actual link.
+ std::string link;
+};
+
bool ProcessGTestOutput(const base::FilePath& output_file,
std::vector<TestResult>* results,
bool* crashed) {
@@ -58,6 +69,8 @@ bool ProcessGTestOutput(const base::FilePath& output_file,
STATE_END,
} state = STATE_INIT;
+ std::vector<Link> links;
+
while (xml_reader.Read()) {
xml_reader.SkipToElement();
std::string node_name(xml_reader.NodeName());
@@ -137,7 +150,26 @@ bool ProcessGTestOutput(const base::FilePath& output_file,
results->pop_back();
}
+ for (const Link& link : links) {
+ if (link.name == test_name && link.classname == test_case_name) {
+ result.AddLink(link.link_name, link.link);
+ }
+ }
+ links.clear();
results->push_back(result);
+ } else if (node_name == "link" && !xml_reader.IsClosingElement()) {
+ Link link;
+ if (!xml_reader.NodeAttribute("name", &link.name))
+ return false;
+ if (!xml_reader.NodeAttribute("classname", &link.classname))
+ return false;
+ if (!xml_reader.NodeAttribute("link_name", &link.link_name))
+ return false;
+ if (!xml_reader.ReadElementContent(&link.link))
+ return false;
+ links.push_back(link);
+ } else if (node_name == "link" && xml_reader.IsClosingElement()) {
+ // Deliberately empty.
} else if (node_name == "failure" && !xml_reader.IsClosingElement()) {
std::string failure_message;
if (!xml_reader.NodeAttribute("message", &failure_message))
diff --git a/chromium/base/test/power_monitor_test_base.cc b/chromium/base/test/power_monitor_test_base.cc
index f37fb579688..6dbc3aef745 100644
--- a/chromium/base/test/power_monitor_test_base.cc
+++ b/chromium/base/test/power_monitor_test_base.cc
@@ -11,14 +11,18 @@
namespace base {
-PowerMonitorTestSource::PowerMonitorTestSource()
- : test_on_battery_power_(false) {
+PowerMonitorTestSource::PowerMonitorTestSource() {
DCHECK(MessageLoopCurrent::Get())
<< "PowerMonitorTestSource requires a MessageLoop.";
}
PowerMonitorTestSource::~PowerMonitorTestSource() = default;
+PowerObserver::DeviceThermalState
+PowerMonitorTestSource::GetCurrentThermalState() {
+ return current_thermal_state_;
+}
+
void PowerMonitorTestSource::GeneratePowerStateEvent(bool on_battery_power) {
test_on_battery_power_ = on_battery_power;
ProcessPowerEvent(POWER_STATE_EVENT);
@@ -39,6 +43,13 @@ bool PowerMonitorTestSource::IsOnBatteryPowerImpl() {
return test_on_battery_power_;
}
+void PowerMonitorTestSource::GenerateThermalThrottlingEvent(
+ PowerObserver::DeviceThermalState new_thermal_state) {
+ ProcessThermalEvent(new_thermal_state);
+ current_thermal_state_ = new_thermal_state;
+ RunLoop().RunUntilIdle();
+}
+
PowerMonitorTestObserver::PowerMonitorTestObserver()
: last_power_state_(false),
power_state_changes_(0),
@@ -62,4 +73,9 @@ void PowerMonitorTestObserver::OnResume() {
resumes_++;
}
+void PowerMonitorTestObserver::OnThermalStateChange(
+ PowerObserver::DeviceThermalState new_state) {
+ last_thermal_state_ = new_state;
+}
+
} // namespace base
diff --git a/chromium/base/test/power_monitor_test_base.h b/chromium/base/test/power_monitor_test_base.h
index 3086bb87496..ac104ff570a 100644
--- a/chromium/base/test/power_monitor_test_base.h
+++ b/chromium/base/test/power_monitor_test_base.h
@@ -14,15 +14,20 @@ class PowerMonitorTestSource : public PowerMonitorSource {
public:
PowerMonitorTestSource();
~PowerMonitorTestSource() override;
+ PowerObserver::DeviceThermalState GetCurrentThermalState() override;
void GeneratePowerStateEvent(bool on_battery_power);
void GenerateSuspendEvent();
void GenerateResumeEvent();
+ void GenerateThermalThrottlingEvent(
+ PowerObserver::DeviceThermalState new_thermal_state);
protected:
bool IsOnBatteryPowerImpl() override;
- bool test_on_battery_power_;
+ bool test_on_battery_power_ = false;
+ PowerObserver::DeviceThermalState current_thermal_state_ =
+ PowerObserver::DeviceThermalState::kUnknown;
};
class PowerMonitorTestObserver : public PowerObserver {
@@ -34,18 +39,24 @@ class PowerMonitorTestObserver : public PowerObserver {
void OnPowerStateChange(bool on_battery_power) override;
void OnSuspend() override;
void OnResume() override;
+ void OnThermalStateChange(
+ PowerObserver::DeviceThermalState new_state) override;
// Test status counts.
bool last_power_state() const { return last_power_state_; }
int power_state_changes() const { return power_state_changes_; }
int suspends() const { return suspends_; }
int resumes() const { return resumes_; }
+ PowerObserver::DeviceThermalState last_thermal_state() const {
+ return last_thermal_state_;
+ }
private:
- bool last_power_state_; // Last power state we were notified of.
+ bool last_power_state_; // Last power state we were notified of.
int power_state_changes_; // Count of OnPowerStateChange notifications.
- int suspends_; // Count of OnSuspend notifications.
- int resumes_; // Count of OnResume notifications.
+ int suspends_; // Count of OnSuspend notifications.
+ int resumes_; // Count of OnResume notifications.
+ PowerObserver::DeviceThermalState last_thermal_state_;
};
} // namespace base
diff --git a/chromium/base/test/scoped_feature_list.cc b/chromium/base/test/scoped_feature_list.cc
index 0e5afdb2e36..dd3dd0ed349 100644
--- a/chromium/base/test/scoped_feature_list.cc
+++ b/chromium/base/test/scoped_feature_list.cc
@@ -271,7 +271,7 @@ void ScopedFeatureList::InitWithFeaturesImpl(
// Restore other field trials. Note: We don't need to do anything for params
// here because the param associator already has the right state, which has
// been backed up via |original_params_| to be restored later.
- FieldTrialList::CreateTrialsFromString(existing_trial_state, {});
+ FieldTrialList::CreateTrialsFromString(existing_trial_state);
OverrideFeatures(current_enabled_features,
FeatureList::OverrideState::OVERRIDE_ENABLE_FEATURE,
diff --git a/chromium/base/test/scoped_run_loop_timeout.cc b/chromium/base/test/scoped_run_loop_timeout.cc
index 5158c5c4c84..cf548973923 100644
--- a/chromium/base/test/scoped_run_loop_timeout.cc
+++ b/chromium/base/test/scoped_run_loop_timeout.cc
@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/location.h"
+#include "base/logging.h"
#include "base/strings/strcat.h"
#include "base/time/time.h"
#include "testing/gtest/include/gtest/gtest.h"
diff --git a/chromium/base/test/test_file_util_win.cc b/chromium/base/test/test_file_util_win.cc
index d2a861b23aa..15f724ea981 100644
--- a/chromium/base/test/test_file_util_win.cc
+++ b/chromium/base/test/test_file_util_win.cc
@@ -36,16 +36,16 @@ struct PermissionInfo {
// |length| is the length of the blob. Zero on failure.
// Returns the blob pointer, or NULL on failure.
void* GetPermissionInfo(const FilePath& path, size_t* length) {
- DCHECK(length != NULL);
+ DCHECK(length);
*length = 0;
- PACL dacl = NULL;
+ PACL dacl = nullptr;
PSECURITY_DESCRIPTOR security_descriptor;
if (GetNamedSecurityInfo(path.value().c_str(), SE_FILE_OBJECT,
- DACL_SECURITY_INFORMATION, NULL, NULL, &dacl, NULL,
- &security_descriptor) != ERROR_SUCCESS) {
- return NULL;
+ DACL_SECURITY_INFORMATION, nullptr, nullptr, &dacl,
+ nullptr, &security_descriptor) != ERROR_SUCCESS) {
+ return nullptr;
}
- DCHECK(dacl != NULL);
+ DCHECK(dacl);
*length = sizeof(PSECURITY_DESCRIPTOR) + dacl->AclSize;
PermissionInfo* info = reinterpret_cast<PermissionInfo*>(new char[*length]);
@@ -68,7 +68,7 @@ bool RestorePermissionInfo(const FilePath& path, void* info, size_t length) {
DWORD rc = SetNamedSecurityInfo(const_cast<wchar_t*>(path.value().c_str()),
SE_FILE_OBJECT, DACL_SECURITY_INFORMATION,
- NULL, NULL, &perm->dacl, NULL);
+ nullptr, nullptr, &perm->dacl, nullptr);
LocalFree(perm->security_descriptor);
char* char_array = reinterpret_cast<char*>(info);
@@ -113,8 +113,8 @@ void SyncPageCacheToDisk() {
bool EvictFileFromSystemCache(const FilePath& file) {
win::ScopedHandle file_handle(
- CreateFile(file.value().c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL,
- OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL));
+ CreateFile(file.value().c_str(), GENERIC_READ | GENERIC_WRITE, 0, nullptr,
+ OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, nullptr));
if (!file_handle.IsValid())
return false;
@@ -175,9 +175,9 @@ bool MakeFileUnwritable(const FilePath& path) {
}
FilePermissionRestorer::FilePermissionRestorer(const FilePath& path)
- : path_(path), info_(NULL), length_(0) {
+ : path_(path), info_(nullptr), length_(0) {
info_ = GetPermissionInfo(path_, &length_);
- DCHECK(info_ != NULL);
+ DCHECK(info_);
DCHECK_NE(0u, length_);
}
diff --git a/chromium/base/test/test_pending_task.h b/chromium/base/test/test_pending_task.h
index dc8eea1fa2f..d85b209e026 100644
--- a/chromium/base/test/test_pending_task.h
+++ b/chromium/base/test/test_pending_task.h
@@ -10,7 +10,7 @@
#include "base/callback.h"
#include "base/location.h"
#include "base/time/time.h"
-#include "base/trace_event/traced_value.h"
+#include "base/trace_event/base_tracing.h"
namespace base {
diff --git a/chromium/base/test/test_pending_task_unittest.cc b/chromium/base/test/test_pending_task_unittest.cc
index ad7723941e4..9771e236fec 100644
--- a/chromium/base/test/test_pending_task_unittest.cc
+++ b/chromium/base/test/test_pending_task_unittest.cc
@@ -5,13 +5,15 @@
#include "base/test/test_pending_task.h"
#include "base/bind.h"
-#include "base/trace_event/trace_event.h"
+#include "base/trace_event/base_tracing.h"
+#include "base/tracing_buildflags.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest-spi.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
+#if BUILDFLAG(ENABLE_BASE_TRACING)
TEST(TestPendingTaskTest, TraceSupport) {
base::TestPendingTask task;
@@ -23,6 +25,7 @@ TEST(TestPendingTaskTest, TraceSupport) {
task.AsValueInto(&task_value);
EXPECT_THAT(task_value.ToJSON(), ::testing::HasSubstr("post_time"));
}
+#endif // BUILDFLAG(ENABLE_BASE_TRACING)
TEST(TestPendingTaskTest, ToString) {
base::TestPendingTask task;
diff --git a/chromium/base/test/test_suite.cc b/chromium/base/test/test_suite.cc
index 7aefd46640a..89046d3f070 100644
--- a/chromium/base/test/test_suite.cc
+++ b/chromium/base/test/test_suite.cc
@@ -42,6 +42,7 @@
#include "base/test/test_timeouts.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
+#include "base/tracing_buildflags.h"
#include "build/build_config.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -590,6 +591,16 @@ void TestSuite::Initialize() {
}
#endif
+#if defined(DCHECK_IS_CONFIGURABLE)
+ // Default the configurable DCHECK level to FATAL when running death tests'
+ // child process, so that they behave as expected.
+ // TODO(crbug.com/1057995): Remove this in favor of the codepath in
+ // FeatureList::SetInstance() when/if OnTestStart() TestEventListeners
+ // are fixed to be invoked in the child process as expected.
+ if (command_line->HasSwitch("gtest_internal_run_death_test"))
+ logging::LOG_DCHECK = logging::LOG_FATAL;
+#endif
+
#if defined(OS_IOS)
InitIOSTestMessageLoop();
#endif // OS_IOS
@@ -650,7 +661,9 @@ void TestSuite::Initialize() {
TestTimeouts::Initialize();
+#if BUILDFLAG(ENABLE_BASE_TRACING)
trace_to_file_.BeginTracingFromCommandLineOptions();
+#endif // BUILDFLAG(ENABLE_BASE_TRACING)
debug::StartProfiling(GetProfileName());
diff --git a/chromium/base/test/test_suite.h b/chromium/base/test/test_suite.h
index 372c5f58a8a..ffad1c77d8b 100644
--- a/chromium/base/test/test_suite.h
+++ b/chromium/base/test/test_suite.h
@@ -13,11 +13,19 @@
#include <string>
#include "base/at_exit.h"
-#include "base/logging.h"
+#include "base/check.h"
#include "base/macros.h"
-#include "base/test/trace_to_file.h"
+#include "base/tracing_buildflags.h"
#include "build/build_config.h"
+#if BUILDFLAG(ENABLE_BASE_TRACING)
+#include "base/test/trace_to_file.h"
+#endif // BUILDFLAG(ENABLE_BASE_TRACING)
+
+namespace logging {
+class ScopedLogAssertHandler;
+}
+
namespace testing {
class TestInfo;
}
@@ -88,7 +96,9 @@ class TestSuite {
// Basic initialization for the test suite happens here.
void PreInitialize();
+#if BUILDFLAG(ENABLE_BASE_TRACING)
test::TraceToFile trace_to_file_;
+#endif // BUILDFLAG(ENABLE_BASE_TRACING)
bool initialized_command_line_ = false;
diff --git a/chromium/base/test/test_switches.cc b/chromium/base/test/test_switches.cc
index ec022ced181..bfbf30cfe50 100644
--- a/chromium/base/test/test_switches.cc
+++ b/chromium/base/test/test_switches.cc
@@ -101,4 +101,7 @@ const char switches::kUiTestActionMaxTimeout[] = "ui-test-action-max-timeout";
// If enabled, runs unittests using the XCTest test runner.
const char switches::kEnableRunIOSUnittestsWithXCTest[] =
"enable-run-ios-unittests-with-xctest";
+// Write a compiled test json file to a location where writable.
+const char switches::kWriteCompiledTestsJsonToWritablePath[] =
+ "write-compiled-tests-json-to-writable-path";
#endif
diff --git a/chromium/base/test/test_switches.h b/chromium/base/test/test_switches.h
index 9e2e627e407..d753deecfdb 100644
--- a/chromium/base/test/test_switches.h
+++ b/chromium/base/test/test_switches.h
@@ -39,6 +39,7 @@ extern const char kUiTestActionMaxTimeout[];
#if defined(OS_IOS)
extern const char kEnableRunIOSUnittestsWithXCTest[];
+extern const char kWriteCompiledTestsJsonToWritablePath[];
#endif
} // namespace switches
diff --git a/chromium/base/test/test_timeouts.cc b/chromium/base/test/test_timeouts.cc
index e77f17569c0..8310f0841c4 100644
--- a/chromium/base/test/test_timeouts.cc
+++ b/chromium/base/test/test_timeouts.cc
@@ -23,16 +23,21 @@ namespace {
// 2) min_value.
// 3) the numerical value given by switch_name on the command line multiplied
// by kTimeoutMultiplier.
-void InitializeTimeout(const char* switch_name, int min_value, int* value) {
+void InitializeTimeout(const char* switch_name,
+ base::TimeDelta min_value,
+ base::TimeDelta* value) {
DCHECK(value);
- int command_line_timeout = 0;
+ base::TimeDelta command_line_timeout;
if (base::CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) {
std::string string_value(base::CommandLine::ForCurrentProcess()->
GetSwitchValueASCII(switch_name));
- if (!base::StringToInt(string_value, &command_line_timeout)) {
+ int command_line_timeout_ms = 0;
+ if (!base::StringToInt(string_value, &command_line_timeout_ms)) {
LOG(FATAL) << "Timeout value \"" << string_value << "\" was parsed as "
- << command_line_timeout;
+ << command_line_timeout_ms;
}
+ command_line_timeout =
+ base::TimeDelta::FromMilliseconds(command_line_timeout_ms);
}
#if defined(MEMORY_SANITIZER)
@@ -80,10 +85,10 @@ bool TestTimeouts::initialized_ = false;
// The timeout values should increase in the order they appear in this block.
// static
-int TestTimeouts::tiny_timeout_ms_ = 100;
-int TestTimeouts::action_timeout_ms_ = 10000;
-int TestTimeouts::action_max_timeout_ms_ = 30000;
-int TestTimeouts::test_launcher_timeout_ms_ = 45000;
+auto TestTimeouts::tiny_timeout_ = base::TimeDelta::FromMilliseconds(100);
+auto TestTimeouts::action_timeout_ = base::TimeDelta::FromSeconds(10);
+auto TestTimeouts::action_max_timeout_ = base::TimeDelta::FromSeconds(30);
+auto TestTimeouts::test_launcher_timeout_ = base::TimeDelta::FromSeconds(45);
// static
void TestTimeouts::Initialize() {
@@ -99,7 +104,8 @@ void TestTimeouts::Initialize() {
// Note that these timeouts MUST be initialized in the correct order as
// per the CHECKS below.
- InitializeTimeout(switches::kTestTinyTimeout, 0, &tiny_timeout_ms_);
+ InitializeTimeout(switches::kTestTinyTimeout, base::TimeDelta(),
+ &tiny_timeout_);
// All timeouts other than the "tiny" one should be set to very large values
// when in a debugger or when run interactively, so that tests will not get
@@ -109,24 +115,23 @@ void TestTimeouts::Initialize() {
// hang (because it's used as a task-posting delay). In particular this
// causes problems for some iOS device tests, which are always run inside a
// debugger (thus BeingDebugged() is true even on the bots).
- int min_ui_test_action_timeout = tiny_timeout_ms_;
+ base::TimeDelta min_ui_test_action_timeout = tiny_timeout_;
if (being_debugged || base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kTestLauncherInteractive)) {
- constexpr int kVeryLargeTimeoutMs = 100'000'000;
- min_ui_test_action_timeout = kVeryLargeTimeoutMs;
+ min_ui_test_action_timeout = base::TimeDelta::FromDays(1);
}
InitializeTimeout(switches::kUiTestActionTimeout, min_ui_test_action_timeout,
- &action_timeout_ms_);
- InitializeTimeout(switches::kUiTestActionMaxTimeout, action_timeout_ms_,
- &action_max_timeout_ms_);
+ &action_timeout_);
+ InitializeTimeout(switches::kUiTestActionMaxTimeout, action_timeout_,
+ &action_max_timeout_);
// Test launcher timeout is independent from anything above action timeout.
- InitializeTimeout(switches::kTestLauncherTimeout, action_timeout_ms_,
- &test_launcher_timeout_ms_);
+ InitializeTimeout(switches::kTestLauncherTimeout, action_timeout_,
+ &test_launcher_timeout_);
// The timeout values should be increasing in the right order.
- CHECK_LE(tiny_timeout_ms_, action_timeout_ms_);
- CHECK_LE(action_timeout_ms_, action_max_timeout_ms_);
- CHECK_LE(action_timeout_ms_, test_launcher_timeout_ms_);
+ CHECK_LE(tiny_timeout_, action_timeout_);
+ CHECK_LE(action_timeout_, action_max_timeout_);
+ CHECK_LE(action_timeout_, test_launcher_timeout_);
}
diff --git a/chromium/base/test/test_timeouts.h b/chromium/base/test/test_timeouts.h
index 1bdda2a157b..1a068adbc77 100644
--- a/chromium/base/test/test_timeouts.h
+++ b/chromium/base/test/test_timeouts.h
@@ -5,7 +5,7 @@
#ifndef BASE_TEST_TEST_TIMEOUTS_H_
#define BASE_TEST_TEST_TIMEOUTS_H_
-#include "base/logging.h"
+#include "base/check.h"
#include "base/macros.h"
#include "base/time/time.h"
@@ -22,14 +22,14 @@ class TestTimeouts {
// like a delay value than a timeout.
static base::TimeDelta tiny_timeout() {
DCHECK(initialized_);
- return base::TimeDelta::FromMilliseconds(tiny_timeout_ms_);
+ return tiny_timeout_;
}
// Timeout to wait for something to happen. If you are not sure
// which timeout to use, this is the one you want.
static base::TimeDelta action_timeout() {
DCHECK(initialized_);
- return base::TimeDelta::FromMilliseconds(action_timeout_ms_);
+ return action_timeout_;
}
// Timeout longer than the above, suitable to wait on success conditions which
@@ -39,23 +39,23 @@ class TestTimeouts {
// actions are compounded in the same test.
static base::TimeDelta action_max_timeout() {
DCHECK(initialized_);
- return base::TimeDelta::FromMilliseconds(action_max_timeout_ms_);
+ return action_max_timeout_;
}
// Timeout for a single test launched used built-in test launcher.
// Do not use outside of the test launcher.
static base::TimeDelta test_launcher_timeout() {
DCHECK(initialized_);
- return base::TimeDelta::FromMilliseconds(test_launcher_timeout_ms_);
+ return test_launcher_timeout_;
}
private:
static bool initialized_;
- static int tiny_timeout_ms_;
- static int action_timeout_ms_;
- static int action_max_timeout_ms_;
- static int test_launcher_timeout_ms_;
+ static base::TimeDelta tiny_timeout_;
+ static base::TimeDelta action_timeout_;
+ static base::TimeDelta action_max_timeout_;
+ static base::TimeDelta test_launcher_timeout_;
DISALLOW_IMPLICIT_CONSTRUCTORS(TestTimeouts);
};
diff --git a/chromium/base/test/trace_event_analyzer.cc b/chromium/base/test/trace_event_analyzer.cc
index 78a6b9b4cae..13af95dd6de 100644
--- a/chromium/base/test/trace_event_analyzer.cc
+++ b/chromium/base/test/trace_event_analyzer.cc
@@ -11,6 +11,7 @@
#include "base/bind.h"
#include "base/json/json_reader.h"
+#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted_memory.h"
#include "base/run_loop.h"
diff --git a/chromium/base/test/trace_event_analyzer.h b/chromium/base/test/trace_event_analyzer.h
index dcdd2e4b5ec..25a5a5372f3 100644
--- a/chromium/base/test/trace_event_analyzer.h
+++ b/chromium/base/test/trace_event_analyzer.h
@@ -100,7 +100,7 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
-#include "base/trace_event/trace_event.h"
+#include "base/trace_event/base_tracing.h"
namespace base {
class Value;
diff --git a/chromium/base/test/with_feature_override.h b/chromium/base/test/with_feature_override.h
index 9a88253c30c..deafd1823f9 100644
--- a/chromium/base/test/with_feature_override.h
+++ b/chromium/base/test/with_feature_override.h
@@ -16,15 +16,18 @@ namespace test {
#define INSTANTIATE_FEATURE_OVERRIDE_TEST_SUITE(test_name) \
INSTANTIATE_TEST_SUITE_P(All, test_name, testing::Values(false, true))
-// Base class for a test fixture that must run with a feature enabled and
-// disabled. Must be the first base class of the test fixture to take effect
-// during the construction of the test fixture itself.
+// Base class for a test fixture that enables running tests twice, once with a
+// feature enabled and once with it disabled. Must be the first base class of
+// the test fixture to take effect during its construction. If
+// WithFeatureOverride is added as a parent to an existing test fixture
+// all of its existing tests need to be migrated to TEST_P.
//
// Example usage:
//
-// class MyTest : public base::WithFeatureOverride, public testing::Test {
+// class MyTest : public base::test::WithFeatureOverride, public testing::Test
+// {
// public:
-// MyTest() : WithFeatureOverride(kMyFeature){}
+// MyTest() : base::test::WithFeatureOverride(kMyFeature){}
// };
//
// TEST_P(MyTest, FooBar) {
@@ -41,8 +44,8 @@ class WithFeatureOverride : public testing::WithParamInterface<bool> {
WithFeatureOverride(const WithFeatureOverride&) = delete;
WithFeatureOverride& operator=(const WithFeatureOverride&) = delete;
- // Use to know if the configured feature provided in the ctor is enabled or
- // not.
+ // Use to know if the configured feature provided in the constructor is
+ // enabled or not.
bool IsParamFeatureEnabled();
private: