0

Send attachment information based on kPdfPortfolio feature flag

Only sends attachment information to the front end when feature
`kPdfPortfolio` is enabled. This helps put future UI development for
PDF attachment behind the feature flag.

Also parameterizes PdfViewWebPluginWithDocInfoTest so that it can
check if attachment information is sent or not based on whether
`kPdfPortfolio` is enabled.

Bug: 177188
Change-Id: I88be529371532f739319472915f91e32f015c185
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4698674
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Nigi <nigi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1172560}
This commit is contained in:
Hui Yingst
2023-07-19 20:33:59 +00:00
committed by Chromium LUCI CQ
parent 08dab2b6b4
commit 1e1926ecb3
2 changed files with 24 additions and 4 deletions

@ -1106,7 +1106,9 @@ void PdfViewWebPlugin::DocumentLoadComplete() {
RecordDocumentMetrics();
SendAttachments();
if (base::FeatureList::IsEnabled(chrome_pdf::features::kPdfPortfolio)) {
SendAttachments();
}
SendBookmarks();
SendMetadata();

@ -20,6 +20,7 @@
#include "base/strings/string_piece.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/values_test_util.h"
#include "base/time/time.h"
#include "base/values.h"
@ -36,6 +37,7 @@
#include "pdf/mojom/pdf.mojom.h"
#include "pdf/paint_ready_rect.h"
#include "pdf/pdf_accessibility_data_handler.h"
#include "pdf/pdf_features.h"
#include "pdf/test/mock_web_associated_url_loader.h"
#include "pdf/test/test_helpers.h"
#include "pdf/test/test_pdfium_engine.h"
@ -331,7 +333,8 @@ class FakePdfService : public pdf::mojom::PdfService {
} // namespace
class PdfViewWebPluginWithoutInitializeTest : public testing::Test {
class PdfViewWebPluginWithoutInitializeTest
: public testing::TestWithParam<bool> {
protected:
// Custom deleter for `plugin_`. PdfViewWebPlugin must be destroyed by
// PdfViewWebPlugin::Destroy() instead of its destructor.
@ -1724,6 +1727,16 @@ TEST_F(PdfViewWebPluginTest, OnDocumentLoadComplete) {
}
class PdfViewWebPluginWithDocInfoTest : public PdfViewWebPluginTest {
public:
void SetUp() override {
PdfViewWebPluginTest::SetUp();
if (IsPortfolioEnabled()) {
scoped_feature_list_.InitAndEnableFeature(features::kPdfPortfolio);
}
}
bool IsPortfolioEnabled() { return GetParam(); }
protected:
class TestPDFiumEngineWithDocInfo : public TestPDFiumEngine {
public:
@ -1878,21 +1891,26 @@ class PdfViewWebPluginWithDocInfoTest : public PdfViewWebPluginTest {
return engine;
});
}
base::test::ScopedFeatureList scoped_feature_list_;
};
TEST_F(PdfViewWebPluginWithDocInfoTest, OnDocumentLoadComplete) {
TEST_P(PdfViewWebPluginWithDocInfoTest, OnDocumentLoadComplete) {
const base::Value::Dict expect_attachments =
CreateExpectedAttachmentsResponse();
const base::Value::Dict expect_bookmarks =
CreateExpectedBookmarksResponse(engine_ptr_->GetBookmarks());
const base::Value::Dict expect_metadata = CreateExpectedMetadataResponse();
EXPECT_CALL(*client_ptr_, PostMessage);
EXPECT_CALL(*client_ptr_, PostMessage(Eq(std::ref(expect_attachments))));
EXPECT_CALL(*client_ptr_, PostMessage(Eq(std::ref(expect_attachments))))
.Times(IsPortfolioEnabled() ? 1 : 0);
EXPECT_CALL(*client_ptr_, PostMessage(Eq(std::ref(expect_bookmarks))));
EXPECT_CALL(*client_ptr_, PostMessage(Eq(std::ref(expect_metadata))));
plugin_->DocumentLoadComplete();
}
INSTANTIATE_TEST_SUITE_P(All, PdfViewWebPluginWithDocInfoTest, testing::Bool());
class PdfViewWebPluginSaveTest : public PdfViewWebPluginTest {
protected:
static void AddDataToValue(base::span<const uint8_t> data,