Commit e835be8e authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[blink] Add ParametrizedModuleTest

The ParametrizedModuleHelper can be used to parametrize existing tests
to run both with kTopLevelAwait enabled and disabled.

Additionally ParamatrizedModuleTestParamName is provided for better
better test names when using the INSTANTIATE_TEST_SUITE_P macro.

Bug: 1022182, v8:9344
Change-Id: Ib263ebe46d523ef7967bd3392546bcf31b4da287
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2105378
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#753352}
parent 37026d99
......@@ -1537,6 +1537,8 @@ jumbo_source_set("unit_test_support") {
sources = [
"testing/core_unit_test_helper.cc",
"testing/core_unit_test_helper.h",
"testing/module_test_base.cc",
"testing/module_test_base.h",
"testing/page_test_base.cc",
"testing/page_test_base.h",
"testing/scoped_fake_plugin_registry.cc",
......
// 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 "third_party/blink/renderer/core/testing/module_test_base.h"
namespace blink {
void ParametrizedModuleTest::SetUp() {
if (UseTopLevelAwait()) {
feature_list_.InitAndEnableFeature(features::kTopLevelAwait);
} else {
feature_list_.InitAndDisableFeature(features::kTopLevelAwait);
}
SetV8Flags(UseTopLevelAwait());
}
void ParametrizedModuleTest::TearDown() {
feature_list_.Reset();
SetV8Flags(base::FeatureList::IsEnabled(features::kTopLevelAwait));
}
void ParametrizedModuleTest::SetV8Flags(bool use_top_level_await) {
if (use_top_level_await) {
v8::V8::SetFlagsFromString("--harmony-top-level-await");
} else {
v8::V8::SetFlagsFromString("--no-harmony-top-level-await");
}
}
} // namespace blink
// 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 THIRD_PARTY_BLINK_RENDERER_CORE_TESTING_MODULE_TEST_BASE_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_TESTING_MODULE_TEST_BASE_H_
#include <gtest/gtest.h>
#include "base/test/scoped_feature_list.h"
#include "third_party/blink/public/common/features.h"
#include "v8/include/v8.h"
namespace blink {
// Helper used to enable or disable top-level await in parametrized tests.
class ParametrizedModuleTest : public testing::WithParamInterface<bool> {
protected:
void SetUp();
void TearDown();
bool UseTopLevelAwait() { return GetParam(); }
base::test::ScopedFeatureList feature_list_;
private:
void SetV8Flags(bool use_top_level_await);
};
// Used in INSTANTIATE_TEST_SUITE_P for returning more readable test names.
struct ParametrizedModuleTestParamName {
std::string operator()(
const testing::TestParamInfo<ParametrizedModuleTest::ParamType>& info) {
return info.param ? "TopLevelAwait" : "noTopLevelAwait";
}
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_TESTING_MODULE_TEST_BASE_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment