chromium/chrome/browser/share/qr_code_generator_pixeltest.cc

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/containers/span.h"
#include "base/run_loop.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "chrome/test/base/platform_browser_test.h"
#include "components/qr_code_generator/bitmap_generator.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h"
#include "ui/base/test/skia_gold_pixel_diff.h"

namespace qrcode_generator {
namespace {

class QrCodeGeneratorServicePixelTest : public PlatformBrowserTest {};

IN_PROC_BROWSER_TEST_F(QrCodeGeneratorServicePixelTest,
                       DinoWithRoundQrPixelsAndLocators) {}

IN_PROC_BROWSER_TEST_F(QrCodeGeneratorServicePixelTest,
                       PassKeyWithSquareQrPixelsAndLocators) {}

IN_PROC_BROWSER_TEST_F(QrCodeGeneratorServicePixelTest,
                       ProductLogoWithSquareQrPixelsAndLocators) {}

// This is a regression test for https://crbug.com/1334066.  It tests that the
// QR code generator can handle fairly big inputs (the URL below is more than
// 800 bytes long).
//
// The pixel test verifies that the output of the QR code generator doesn't
// change.  The real verification is checking if the generated QR code can be
// used by a variety of QR code readers (e.g. by Chrome, Safari, etc.) to
// navigate to the https://md5calc.com/hash/crc32/... URL - the result of such
// navigation should show a HTML page that says: CRC32 hash is "9f329afa".
//
// Note that https://www.qrcode.com/en/howto/code.html points out that there
// should be light/white space of 4 or more modules/pixels around the QR code
// but currently that margin is added by higher layers of code.  And therefore
// the verification should be done after embedding or printing the generated
// image onto a light background.
//
// Limits for input sizes at version 40 of QR codes can be found at
// https://www.qrcode.com/en/about/version.html - 2331 is the limit for
// an input containing arbitrary bytes.  In practice though QR codes that are
// so big may not be recognized by QR code readers and therefore the test uses
// a slightly smaller input.
IN_PROC_BROWSER_TEST_F(QrCodeGeneratorServicePixelTest, BigUrl) {}

// This is a regression test for https://crbug.com/1334066.  It tests that the
// QR code generator can handle fairly big inputs (the URL below is 2331 bytes
// long).
//
// The pixel test verifies that the output of the QR code generator doesn't
// change.  The real verification is checking if the generated QR code can be
// used by a variety of QR code readers (e.g. by Chrome, Safari, etc.) to
// navigate to the https://md5calc.com/hash/crc32/... URL - the result of such
// navigation should show a HTML page that says: CRC32 hash is "b6e1c7ad".
// OTOH, a QR code this bug may not be recognized by all QR code readers, so
// it's okay if the "real verification" is skipped for *this* particular test
// (`BigUrl` should still work).
//
// Note that https://www.qrcode.com/en/howto/code.html points out that there
// should be light/white space of 4 or more modules/pixels around the QR code
// but currently that margin is added by higher layers of code.  And therefore
// the verification should be done after embedding or printing the generated
// image onto a light background.
//
// Limits for input sizes at version 40 of QR codes can be found at
// https://www.qrcode.com/en/about/version.html - 2331 is indeed the limit for
// an input containing arbitrary bytes.  In theory, a smart segmentation
// algorithm could support longer URLs, but only if the input consistent of less
// arbitrary bytes, and contained more digits and/or UPPER case alphabetic
// characters.
IN_PROC_BROWSER_TEST_F(QrCodeGeneratorServicePixelTest, HugeUrl) {}

}  // namespace
}  // namespace qrcode_generator