Add some PDF tests in chrome/common.
Add test coverage for IsPdfExtensionOrigin(). With a PDF unit test file in chrome/common, also use it to do some static_asserts to make sure enum values at different layers match. Bug: 702993 Change-Id: Ie9a964c6d08433bff988d92b4eadd7d29d9e7299 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3642970 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: K. Moon <kmoon@chromium.org> Cr-Commit-Position: refs/heads/main@{#1003281}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
989a6a1069
commit
8f13ba1545
@ -75,7 +75,10 @@ include_rules = [
|
||||
]
|
||||
|
||||
specific_include_rules = {
|
||||
"logging_chrome.cc": [
|
||||
"logging_chrome\.cc": [
|
||||
"+ash/constants/ash_switches.h",
|
||||
]
|
||||
],
|
||||
"pdf_util_unittest\.cc": [
|
||||
"+pdf/content_restriction.h",
|
||||
],
|
||||
}
|
||||
|
39
chrome/common/pdf_util_unittest.cc
Normal file
39
chrome/common/pdf_util_unittest.cc
Normal file
@ -0,0 +1,39 @@
|
||||
// Copyright 2022 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 "chrome/common/pdf_util.h"
|
||||
|
||||
#include "chrome/common/content_restriction.h"
|
||||
#include "extensions/buildflags/buildflags.h"
|
||||
#include "pdf/content_restriction.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "url/gurl.h"
|
||||
#include "url/origin.h"
|
||||
|
||||
static_assert(static_cast<int>(CONTENT_RESTRICTION_COPY) ==
|
||||
static_cast<int>(chrome_pdf::kContentRestrictionCopy));
|
||||
static_assert(static_cast<int>(CONTENT_RESTRICTION_CUT) ==
|
||||
static_cast<int>(chrome_pdf::kContentRestrictionCut));
|
||||
static_assert(static_cast<int>(CONTENT_RESTRICTION_PASTE) ==
|
||||
static_cast<int>(chrome_pdf::kContentRestrictionPaste));
|
||||
static_assert(static_cast<int>(CONTENT_RESTRICTION_PRINT) ==
|
||||
static_cast<int>(chrome_pdf::kContentRestrictionPrint));
|
||||
static_assert(static_cast<int>(CONTENT_RESTRICTION_SAVE) ==
|
||||
static_cast<int>(chrome_pdf::kContentRestrictionSave));
|
||||
|
||||
TEST(PdfUtil, IsPdfExtensionOrigin) {
|
||||
EXPECT_FALSE(
|
||||
IsPdfExtensionOrigin(url::Origin::Create(GURL("https://example.com/"))));
|
||||
EXPECT_FALSE(IsPdfExtensionOrigin(
|
||||
url::Origin::Create(GURL("https://mhjfbmdgcfjbbpaeojofohoefgiehjai/"))));
|
||||
EXPECT_FALSE(IsPdfExtensionOrigin(
|
||||
url::Origin::Create(GURL("chrome-extension://foo/"))));
|
||||
#if BUILDFLAG(ENABLE_EXTENSIONS)
|
||||
EXPECT_TRUE(IsPdfExtensionOrigin(url::Origin::Create(
|
||||
GURL("chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/"))));
|
||||
#else
|
||||
EXPECT_FALSE(IsPdfExtensionOrigin(url::Origin::Create(
|
||||
GURL("chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/"))));
|
||||
#endif
|
||||
}
|
@ -8094,6 +8094,11 @@ test("unit_tests") {
|
||||
]
|
||||
}
|
||||
|
||||
if (enable_pdf) {
|
||||
sources += [ "../common/pdf_util_unittest.cc" ]
|
||||
deps += [ "//pdf:content_restriction" ]
|
||||
}
|
||||
|
||||
if (enable_plugins) {
|
||||
sources += [
|
||||
"../browser/plugins/chrome_plugin_service_filter_unittest.cc",
|
||||
|
@ -71,7 +71,6 @@ if (enable_pdf) {
|
||||
"accessibility.cc",
|
||||
"accessibility.h",
|
||||
"chunk_stream.h",
|
||||
"content_restriction.h",
|
||||
"document_attachment_info.cc",
|
||||
"document_attachment_info.h",
|
||||
"document_layout.cc",
|
||||
@ -158,6 +157,7 @@ if (enable_pdf) {
|
||||
deps = [
|
||||
":accessibility",
|
||||
":buildflags",
|
||||
":content_restriction",
|
||||
":features",
|
||||
":ppapi_migration",
|
||||
"//base",
|
||||
@ -201,6 +201,7 @@ if (enable_pdf) {
|
||||
|
||||
deps = [
|
||||
":accessibility",
|
||||
":content_restriction",
|
||||
":internal",
|
||||
":pdf",
|
||||
":ppapi_migration",
|
||||
@ -210,6 +211,11 @@ if (enable_pdf) {
|
||||
]
|
||||
}
|
||||
|
||||
source_set("content_restriction") {
|
||||
# Exists separately to expose this header for testing.
|
||||
public = [ "content_restriction.h" ]
|
||||
}
|
||||
|
||||
source_set("accessibility") {
|
||||
visibility = [
|
||||
":*",
|
||||
@ -383,6 +389,7 @@ if (enable_pdf) {
|
||||
":accessibility",
|
||||
":assert_enums",
|
||||
":buildflags",
|
||||
":content_restriction",
|
||||
":features",
|
||||
":internal",
|
||||
":pdf",
|
||||
|
@ -8,11 +8,8 @@
|
||||
namespace chrome_pdf {
|
||||
|
||||
// Used for disabling browser commands because of restrictions on how the data
|
||||
// is to be used (i.e. can't copy/print).
|
||||
// TODO(crbug.com/702993): Must be kept in sync with `ContentRestriction` in
|
||||
// chrome/common/content_restriction.h. While there's a transitive static
|
||||
// assertion that the enums match, a direct static assertion should be added
|
||||
// when `PP_ContentRestriction` is removed.
|
||||
// is to be used (i.e. can't copy/print). Must be kept in sync with
|
||||
// `ContentRestriction` in chrome/common/content_restriction.h.
|
||||
enum ContentRestriction {
|
||||
kContentRestrictionCopy = 1 << 0,
|
||||
kContentRestrictionCut = 1 << 1,
|
||||
|
Reference in New Issue
Block a user