Commit 1d92c372 authored by Brian Sheedy's avatar Brian Sheedy Committed by Commit Bot

Add Skia Gold killswitch to gtest-based tests

Adds a --bypass-skia-gold-functionality flag to the gtest implementation
of the Skia Gold pixel tests which causes all tests that use Skia Gold
to skip any actual interactions with Gold.

This is meant to be used in the unlikely event that there's a Gold
outage that can't be fixed quickly so that the outage does not block
CLs, etc.

Bug: 1057848
Change-Id: I9aebe7bb4dc460383096306d7ad1b9858eddd433
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2123509Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarSven Zheng <svenzheng@chromium.org>
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#755481}
parent acd2ec63
...@@ -18,20 +18,24 @@ using ::testing::Return; ...@@ -18,20 +18,24 @@ using ::testing::Return;
class MockBrowserSkiaGoldPixelDiff : public BrowserSkiaGoldPixelDiff { class MockBrowserSkiaGoldPixelDiff : public BrowserSkiaGoldPixelDiff {
public: public:
MockBrowserSkiaGoldPixelDiff() {} MockBrowserSkiaGoldPixelDiff() = default;
MOCK_CONST_METHOD2(UploadToSkiaGoldServer, MOCK_CONST_METHOD1(LaunchProcess, int(const base::CommandLine&));
bool(const base::FilePath&, const std::string&));
bool GrabWindowSnapshotInternal(gfx::NativeWindow window, bool GrabWindowSnapshotInternal(gfx::NativeWindow window,
const gfx::Rect& snapshot_bounds, const gfx::Rect& snapshot_bounds,
gfx::Image* image) const { gfx::Image* image) const override {
SkBitmap bitmap; SkBitmap bitmap;
bitmap.allocN32Pixels(10, 10); bitmap.allocN32Pixels(10, 10);
*image = gfx::Image::CreateFrom1xBitmap(bitmap); *image = gfx::Image::CreateFrom1xBitmap(bitmap);
return true; return true;
} }
int LaunchProcess(const base::CommandLine& cmdline) const override { };
return 0;
} class MockBrowserSkiaGoldPixelDiffMockUpload
: public MockBrowserSkiaGoldPixelDiff {
public:
MockBrowserSkiaGoldPixelDiffMockUpload() = default;
MOCK_CONST_METHOD2(UploadToSkiaGoldServer,
bool(const base::FilePath&, const std::string&));
}; };
class BrowserSkiaGoldPixelDiffTest : public views::test::WidgetTest { class BrowserSkiaGoldPixelDiffTest : public views::test::WidgetTest {
...@@ -47,7 +51,7 @@ class BrowserSkiaGoldPixelDiffTest : public views::test::WidgetTest { ...@@ -47,7 +51,7 @@ class BrowserSkiaGoldPixelDiffTest : public views::test::WidgetTest {
TEST_F(BrowserSkiaGoldPixelDiffTest, CompareScreenshotByView) { TEST_F(BrowserSkiaGoldPixelDiffTest, CompareScreenshotByView) {
views::View view; views::View view;
MockBrowserSkiaGoldPixelDiff mock_pixel; MockBrowserSkiaGoldPixelDiffMockUpload mock_pixel;
EXPECT_CALL(mock_pixel, UploadToSkiaGoldServer(_, "Prefix_Demo")) EXPECT_CALL(mock_pixel, UploadToSkiaGoldServer(_, "Prefix_Demo"))
.Times(1) .Times(1)
.WillOnce(Return(true)); .WillOnce(Return(true));
...@@ -57,3 +61,17 @@ TEST_F(BrowserSkiaGoldPixelDiffTest, CompareScreenshotByView) { ...@@ -57,3 +61,17 @@ TEST_F(BrowserSkiaGoldPixelDiffTest, CompareScreenshotByView) {
EXPECT_TRUE(ret); EXPECT_TRUE(ret);
widget->CloseNow(); widget->CloseNow();
} }
TEST_F(BrowserSkiaGoldPixelDiffTest, BypassSkiaGoldFunctionality) {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
"bypass-skia-gold-functionality");
views::View view;
MockBrowserSkiaGoldPixelDiff mock_pixel;
EXPECT_CALL(mock_pixel, LaunchProcess(_)).Times(0);
views::Widget* widget = CreateTopLevelNativeWidget();
mock_pixel.Init(widget, "Prefix");
bool ret = mock_pixel.CompareScreenshot("Demo", &view);
EXPECT_TRUE(ret);
widget->CloseNow();
}
...@@ -45,6 +45,7 @@ const char* kPatchSetKey = "patchset"; ...@@ -45,6 +45,7 @@ const char* kPatchSetKey = "patchset";
const char* kJobIdKey = "jobid"; const char* kJobIdKey = "jobid";
const char* kNoLuciAuth = "no-luci-auth"; const char* kNoLuciAuth = "no-luci-auth";
const char* kBypassSkiaGoldFunctionality = "bypass-skia-gold-functionality";
SkiaGoldPixelDiff::SkiaGoldPixelDiff() = default; SkiaGoldPixelDiff::SkiaGoldPixelDiff() = default;
...@@ -134,6 +135,12 @@ int SkiaGoldPixelDiff::LaunchProcess(const base::CommandLine& cmdline) const { ...@@ -134,6 +135,12 @@ int SkiaGoldPixelDiff::LaunchProcess(const base::CommandLine& cmdline) const {
} }
void SkiaGoldPixelDiff::InitSkiaGold() { void SkiaGoldPixelDiff::InitSkiaGold() {
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
kBypassSkiaGoldFunctionality)) {
LOG(WARNING) << "Bypassing Skia Gold initialization due to "
<< "--bypass-skia-gold-functionality being present.";
return;
}
base::ScopedAllowBlockingForTesting allow_blocking; base::ScopedAllowBlockingForTesting allow_blocking;
base::CommandLine cmd(GetAbsoluteSrcRelativePath(kSkiaGoldCtl)); base::CommandLine cmd(GetAbsoluteSrcRelativePath(kSkiaGoldCtl));
cmd.AppendSwitchPath("work-dir", working_dir_); cmd.AppendSwitchPath("work-dir", working_dir_);
...@@ -207,6 +214,13 @@ void SkiaGoldPixelDiff::Init(const std::string& screenshot_prefix) { ...@@ -207,6 +214,13 @@ void SkiaGoldPixelDiff::Init(const std::string& screenshot_prefix) {
bool SkiaGoldPixelDiff::UploadToSkiaGoldServer( bool SkiaGoldPixelDiff::UploadToSkiaGoldServer(
const base::FilePath& local_file_path, const base::FilePath& local_file_path,
const std::string& remote_golden_image_name) const { const std::string& remote_golden_image_name) const {
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
kBypassSkiaGoldFunctionality)) {
LOG(WARNING) << "Bypassing Skia Gold comparison due to "
<< "--bypass-skia-gold-functionality being present.";
return true;
}
base::ScopedAllowBlockingForTesting allow_blocking; base::ScopedAllowBlockingForTesting allow_blocking;
base::CommandLine cmd(GetAbsoluteSrcRelativePath(kSkiaGoldCtl)); base::CommandLine cmd(GetAbsoluteSrcRelativePath(kSkiaGoldCtl));
cmd.AppendSwitchASCII("test-name", remote_golden_image_name); cmd.AppendSwitchASCII("test-name", remote_golden_image_name);
......
...@@ -5,18 +5,19 @@ ...@@ -5,18 +5,19 @@
#include "ui/base/test/skia_gold_pixel_diff.h" #include "ui/base/test/skia_gold_pixel_diff.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkImageInfo.h" #include "third_party/skia/include/core/SkImageInfo.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
using ::testing::_;
class MockSkiaGoldPixelDiff : public SkiaGoldPixelDiff { class MockSkiaGoldPixelDiff : public SkiaGoldPixelDiff {
public: public:
MockSkiaGoldPixelDiff() {} MockSkiaGoldPixelDiff() = default;
int LaunchProcess(const base::CommandLine& cmdline) const override { MOCK_CONST_METHOD1(LaunchProcess, int(const base::CommandLine&));
return 0;
}
bool UploadToSkiaGoldServer( bool UploadToSkiaGoldServer(
const base::FilePath& local_file_path, const base::FilePath& local_file_path,
const std::string& remote_golden_image_name) const override { const std::string& remote_golden_image_name) const override {
...@@ -48,3 +49,19 @@ TEST_F(SkiaGoldPixelDiffTest, CompareScreenshotBySkBitmap) { ...@@ -48,3 +49,19 @@ TEST_F(SkiaGoldPixelDiffTest, CompareScreenshotBySkBitmap) {
bool ret = mock_pixel.CompareScreenshot("test", bitmap); bool ret = mock_pixel.CompareScreenshot("test", bitmap);
EXPECT_TRUE(ret); EXPECT_TRUE(ret);
} }
TEST_F(SkiaGoldPixelDiffTest, BypassSkiaGoldFunctionality) {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
"bypass-skia-gold-functionality");
SkBitmap bitmap;
SkImageInfo info =
SkImageInfo::Make(10, 10, SkColorType::kBGRA_8888_SkColorType,
SkAlphaType::kPremul_SkAlphaType);
bitmap.allocPixels(info, 10 * 4);
MockSkiaGoldPixelDiff mock_pixel;
EXPECT_CALL(mock_pixel, LaunchProcess(_)).Times(0);
mock_pixel.Init("Prefix");
bool ret = mock_pixel.CompareScreenshot("test", bitmap);
EXPECT_TRUE(ret);
}
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