Commit 74dd3684 authored by Olivier Robin's avatar Olivier Robin Committed by Commit Bot

Fix assist_ranker unittests

ScopedFeatureList must be initialized before testing any feature.
https://cs.chromium.org/chromium/src/base/test/scoped_feature_list.h?l=26

If it is not initialized, any feature is tested in the global
FeatureList, which could lead to bad interaction between tests.

Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Ic2bfba36312cbebb5c0abadaf1074f7eaff37d9a
Reviewed-on: https://chromium-review.googlesource.com/1126102Reviewed-by: default avatarRoger McFarlane <rogerm@chromium.org>
Commit-Queue: Olivier Robin <olivierrobin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#572604}
parent fbdf9ddd
......@@ -100,8 +100,8 @@ std::unique_ptr<FakePredictor> FakePredictor::Create() {
class BasePredictorTest : public ::testing::Test {
protected:
BasePredictorTest() = default;
// Disables Query for the test predictor.
void DisableQuery();
void SetUp() override;
ukm::SourceId GetSourceId();
......@@ -120,16 +120,17 @@ class BasePredictorTest : public ::testing::Test {
DISALLOW_COPY_AND_ASSIGN(BasePredictorTest);
};
void BasePredictorTest::SetUp() {
::testing::Test::SetUp();
scoped_feature_list_.Init();
}
ukm::SourceId BasePredictorTest::GetSourceId() {
ukm::SourceId source_id = ukm::UkmRecorder::GetNewSourceID();
test_ukm_recorder_.UpdateSourceURL(source_id, GURL(kTestNavigationUrl));
return source_id;
}
void BasePredictorTest::DisableQuery() {
scoped_feature_list_.InitWithFeatures({}, {kTestRankerQuery});
}
TEST_F(BasePredictorTest, BaseTest) {
auto predictor = FakePredictor::Create();
EXPECT_EQ(kTestModelName, predictor->GetModelName());
......@@ -139,7 +140,8 @@ TEST_F(BasePredictorTest, BaseTest) {
}
TEST_F(BasePredictorTest, QueryDisabled) {
DisableQuery();
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndDisableFeature(kTestRankerQuery);
auto predictor = FakePredictor::Create();
EXPECT_EQ(kTestModelName, predictor->GetModelName());
EXPECT_EQ(kTestDefaultModelUrl, predictor->GetModelUrl());
......
......@@ -9,6 +9,7 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/feature_list.h"
#include "base/test/scoped_feature_list.h"
#include "components/assist_ranker/fake_ranker_model_loader.h"
#include "components/assist_ranker/proto/ranker_model.pb.h"
#include "components/assist_ranker/ranker_model.h"
......@@ -20,6 +21,8 @@ using ::assist_ranker::testing::FakeRankerModelLoader;
class BinaryClassifierPredictorTest : public ::testing::Test {
public:
void SetUp() override;
std::unique_ptr<BinaryClassifierPredictor> InitPredictor(
std::unique_ptr<RankerModel> ranker_model,
const PredictorConfig& config);
......@@ -33,8 +36,14 @@ class BinaryClassifierPredictorTest : public ::testing::Test {
const std::string feature_ = "feature";
const float weight_ = 1.0;
const float threshold_ = 0.5;
base::test::ScopedFeatureList scoped_feature_list_;
};
void BinaryClassifierPredictorTest::SetUp() {
::testing::Test::SetUp();
scoped_feature_list_.Init();
}
std::unique_ptr<BinaryClassifierPredictor>
BinaryClassifierPredictorTest::InitPredictor(
std::unique_ptr<RankerModel> ranker_model,
......
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