Commit 416d1fd9 authored by Sven Zheng's avatar Sven Zheng Committed by Commit Bot

Fix pixel diff unit tests

For some trunk builders, they set env var CHROMIUM_TEST_LAUNCHER_BOT_MODE.
For unit test, we need to unset the var to test some scenario.
https://source.chromium.org/chromium/chromium/src/+/master:ui/base/test/skia_gold_pixel_diff.cc;l=153;drc=07e4c76dd0f6b37146a1c35e4a96fae53aff7371

Bug: 1146399
Change-Id: Ifb71831060a4bd779ef48e83ca8d66741e5e57e1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2523555Reviewed-by: default avatarBrian Sheedy <bsheedy@chromium.org>
Reviewed-by: default avatarAlbert J. Wong <ajwong@chromium.org>
Commit-Queue: Sven Zheng <svenzheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825590}
parent 9a899da6
......@@ -11,15 +11,28 @@ namespace test {
ScopedEnvironmentVariableOverride::ScopedEnvironmentVariableOverride(
const std::string& variable_name,
const std::string& value)
const std::string& value,
bool unset_var)
: environment_(Environment::Create()),
variable_name_(variable_name),
overridden_(false),
was_set_(false) {
was_set_ = environment_->GetVar(variable_name, &old_value_);
overridden_ = environment_->SetVar(variable_name, value);
if (unset_var)
overridden_ = environment_->UnSetVar(variable_name);
else
overridden_ = environment_->SetVar(variable_name, value);
}
ScopedEnvironmentVariableOverride::ScopedEnvironmentVariableOverride(
const std::string& variable_name,
const std::string& value)
: ScopedEnvironmentVariableOverride(variable_name, value, false) {}
ScopedEnvironmentVariableOverride::ScopedEnvironmentVariableOverride(
const std::string& variable_name)
: ScopedEnvironmentVariableOverride(variable_name, "", true) {}
ScopedEnvironmentVariableOverride::~ScopedEnvironmentVariableOverride() {
if (overridden_) {
if (was_set_)
......
......@@ -20,6 +20,8 @@ class ScopedEnvironmentVariableOverride final {
public:
ScopedEnvironmentVariableOverride(const std::string& variable_name,
const std::string& value);
// Unset the variable.
explicit ScopedEnvironmentVariableOverride(const std::string& variable_name);
~ScopedEnvironmentVariableOverride();
base::Environment* GetEnv() { return environment_.get(); }
......@@ -27,6 +29,9 @@ class ScopedEnvironmentVariableOverride final {
bool WasSet() { return was_set_; }
private:
ScopedEnvironmentVariableOverride(const std::string& variable_name,
const std::string& value,
bool unset_var);
std::unique_ptr<Environment> environment_;
std::string variable_name_;
bool overridden_;
......
......@@ -6,6 +6,7 @@
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/test/scoped_environment_variable_override.h"
#include "base/test/test_switches.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -108,6 +109,8 @@ TEST_F(SkiaGoldPixelDiffTest, LocalNoLuciAuth) {
MockSkiaGoldPixelDiff mock_pixel;
auto* cmd_line = base::CommandLine::ForCurrentProcess();
cmd_line->RemoveSwitch(switches::kTestLauncherBotMode);
base::test::ScopedEnvironmentVariableOverride env_override(
"CHROMIUM_TEST_LAUNCHER_BOT_MODE");
EXPECT_CALL(mock_pixel, LaunchProcess(_)).Times(AnyNumber());
EXPECT_CALL(mock_pixel, LaunchProcess(AllOf(Property(
......@@ -349,6 +352,8 @@ TEST_F(SkiaGoldPixelDiffTest, MakeGerritCommentInvalidFlag) {
TEST_F(SkiaGoldPixelDiffTest, DryRunLocally) {
auto* cmd_line = base::CommandLine::ForCurrentProcess();
cmd_line->RemoveSwitch(switches::kTestLauncherBotMode);
base::test::ScopedEnvironmentVariableOverride env_override(
"CHROMIUM_TEST_LAUNCHER_BOT_MODE");
MockSkiaGoldPixelDiff mock_pixel;
EXPECT_CALL(mock_pixel, LaunchProcess(_)).Times(AnyNumber());
......
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