Skip to content

Commit

Permalink
[pdf] Migrate DocumentHasUnsupportedFeature() tests
Browse files Browse the repository at this point in the history
Migrates tests exercising PdfViewPluginBase's
DocumentHasUnsupportedFeature() method.

Bug: 1323307
Change-Id: I6fa71c619c0f0a430b314f4078fca8970a7e08d2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3689708
Reviewed-by: Nigi <nigi@chromium.org>
Auto-Submit: K. Moon <kmoon@chromium.org>
Commit-Queue: K. Moon <kmoon@chromium.org>
Commit-Queue: Nigi <nigi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1011047}
  • Loading branch information
kmoon-work authored and Chromium LUCI CQ committed Jun 6, 2022
1 parent 7f557a6 commit 18742cc
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 72 deletions.
6 changes: 0 additions & 6 deletions pdf/pdf_view_plugin_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "base/callback.h"
#include "base/check.h"
#include "base/check_op.h"
#include "base/containers/contains.h"
#include "base/containers/fixed_flat_map.h"
#include "base/containers/flat_set.h"
#include "base/containers/span.h"
Expand Down Expand Up @@ -602,11 +601,6 @@ AccessibilityDocInfo PdfViewPluginBase::GetAccessibilityDocInfo() const {
return doc_info;
}

bool PdfViewPluginBase::UnsupportedFeatureIsReportedForTesting(
const std::string& feature) const {
return base::Contains(unsupported_features_reported_, feature);
}

void PdfViewPluginBase::InitializeEngineForTesting(
std::unique_ptr<PDFiumEngine> engine) {
DCHECK(engine);
Expand Down
6 changes: 0 additions & 6 deletions pdf/pdf_view_plugin_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,6 @@ class PdfViewPluginBase : public PDFEngine::Client,
// Gets the accessibility doc info based on the information from `engine_`.
AccessibilityDocInfo GetAccessibilityDocInfo() const;

bool UnsupportedFeatureIsReportedForTesting(const std::string& feature) const;

bool GetNotifiedBrowserAboutUnsupportedFeatureForTesting() const {
return notified_browser_about_unsupported_feature_;
}

void InitializeEngineForTesting(std::unique_ptr<PDFiumEngine> engine);

void set_full_frame_for_testing(bool full_frame) { full_frame_ = full_frame; }
Expand Down
60 changes: 0 additions & 60 deletions pdf/pdf_view_plugin_base_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -346,66 +346,6 @@ TEST_F(PdfViewPluginBaseWithoutDocInfoTest,
fake_plugin_.sent_messages()[0]);
}

TEST_F(PdfViewPluginBaseTest, DocumentHasUnsupportedFeatureInFullFrame) {
fake_plugin_.set_full_frame_for_testing(true);
ASSERT_TRUE(fake_plugin_.full_frame());

// Arbitrary feature names and their matching metric names.
static constexpr char kFeature1[] = "feature1";
static constexpr char kMetric1[] = "PDF_Unsupported_feature1";
static constexpr char kFeature2[] = "feature2";
static constexpr char kMetric2[] = "PDF_Unsupported_feature2";

// Find unsupported `kFeature1` for the first time.
EXPECT_FALSE(fake_plugin_.UnsupportedFeatureIsReportedForTesting(kMetric1));
EXPECT_FALSE(
fake_plugin_.GetNotifiedBrowserAboutUnsupportedFeatureForTesting());
EXPECT_CALL(fake_plugin_, NotifyUnsupportedFeature());
EXPECT_CALL(fake_plugin_, UserMetricsRecordAction(kMetric1));

fake_plugin_.DocumentHasUnsupportedFeature(kFeature1);
EXPECT_TRUE(fake_plugin_.UnsupportedFeatureIsReportedForTesting(kMetric1));
EXPECT_TRUE(
fake_plugin_.GetNotifiedBrowserAboutUnsupportedFeatureForTesting());

// Find unsupported `kFeature2` for the first time.
EXPECT_FALSE(fake_plugin_.UnsupportedFeatureIsReportedForTesting(kMetric2));
EXPECT_CALL(fake_plugin_, UserMetricsRecordAction(kMetric2));

fake_plugin_.DocumentHasUnsupportedFeature(kFeature2);
EXPECT_TRUE(fake_plugin_.UnsupportedFeatureIsReportedForTesting(kMetric2));
EXPECT_TRUE(
fake_plugin_.GetNotifiedBrowserAboutUnsupportedFeatureForTesting());

// Find unsupported `kFeature1` for the second time.
fake_plugin_.DocumentHasUnsupportedFeature(kFeature1);
EXPECT_TRUE(fake_plugin_.UnsupportedFeatureIsReportedForTesting(kMetric1));
EXPECT_TRUE(
fake_plugin_.GetNotifiedBrowserAboutUnsupportedFeatureForTesting());
}

TEST_F(PdfViewPluginBaseTest, DocumentHasUnsupportedFeatureWithoutFullFrame) {
ASSERT_FALSE(fake_plugin_.full_frame());

// An arbitrary feature name and its matching metric name.
static constexpr char kFeature[] = "feature";
static constexpr char kMetric[] = "PDF_Unsupported_feature";

EXPECT_FALSE(fake_plugin_.UnsupportedFeatureIsReportedForTesting(kMetric));
EXPECT_FALSE(
fake_plugin_.GetNotifiedBrowserAboutUnsupportedFeatureForTesting());

// NotifyUnsupportedFeature() should never be called if the viewer doesn't
// occupy the whole frame, but the metrics should still be recorded.
EXPECT_CALL(fake_plugin_, NotifyUnsupportedFeature()).Times(0);
EXPECT_CALL(fake_plugin_, UserMetricsRecordAction(kMetric));

fake_plugin_.DocumentHasUnsupportedFeature(kFeature);
EXPECT_TRUE(fake_plugin_.UnsupportedFeatureIsReportedForTesting(kMetric));
EXPECT_FALSE(
fake_plugin_.GetNotifiedBrowserAboutUnsupportedFeatureForTesting());
}

TEST_F(PdfViewPluginBaseWithEngineTest, HandleInputEvent) {
auto* engine = static_cast<TestPDFiumEngine*>(fake_plugin_.engine());
EXPECT_CALL(*engine, HandleInputEvent)
Expand Down
57 changes: 57 additions & 0 deletions pdf/pdf_view_web_plugin_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,63 @@ TEST_F(PdfViewWebPluginFullFrameTest, DocumentLoadFailed) {
plugin_->document_load_state_for_testing());
}

TEST_F(PdfViewWebPluginTest, DocumentHasUnsupportedFeature) {
EXPECT_CALL(*client_ptr_, RecordComputedAction).Times(AnyNumber());
EXPECT_CALL(*client_ptr_, RecordComputedAction("PDF_Unsupported_feature1"));
EXPECT_CALL(*client_ptr_, RecordComputedAction("PDF_Unsupported_feature2"));

// `HasUnsupportedFeature()` is not called if the viewer is not full-frame.
EXPECT_CALL(pdf_service_, HasUnsupportedFeature).Times(0);

plugin_->DocumentHasUnsupportedFeature("feature1");
plugin_->DocumentHasUnsupportedFeature("feature2");

pdf_receiver_.FlushForTesting();
}

TEST_F(PdfViewWebPluginTest, DocumentHasUnsupportedFeatureWithRepeatedFeature) {
// Metrics should only be recorded once per feature.
EXPECT_CALL(*client_ptr_, RecordComputedAction).Times(AnyNumber());
EXPECT_CALL(*client_ptr_, RecordComputedAction("PDF_Unsupported_feature"));

// `HasUnsupportedFeature()` is not called if the viewer is not full-frame.
EXPECT_CALL(pdf_service_, HasUnsupportedFeature).Times(0);

plugin_->DocumentHasUnsupportedFeature("feature");
plugin_->DocumentHasUnsupportedFeature("feature");

pdf_receiver_.FlushForTesting();
}

TEST_F(PdfViewWebPluginFullFrameTest, DocumentHasUnsupportedFeature) {
EXPECT_CALL(*client_ptr_, RecordComputedAction).Times(AnyNumber());
EXPECT_CALL(*client_ptr_, RecordComputedAction("PDF_Unsupported_feature1"));
EXPECT_CALL(*client_ptr_, RecordComputedAction("PDF_Unsupported_feature2"));

// `HasUnsupportedFeature()` is called once for all features.
EXPECT_CALL(pdf_service_, HasUnsupportedFeature);

plugin_->DocumentHasUnsupportedFeature("feature1");
plugin_->DocumentHasUnsupportedFeature("feature2");

pdf_receiver_.FlushForTesting();
}

TEST_F(PdfViewWebPluginFullFrameTest,
DocumentHasUnsupportedFeatureWithRepeatedFeature) {
// Metrics should only be recorded once per feature.
EXPECT_CALL(*client_ptr_, RecordComputedAction).Times(AnyNumber());
EXPECT_CALL(*client_ptr_, RecordComputedAction("PDF_Unsupported_feature"));

// `HasUnsupportedFeature()` is called once for all features.
EXPECT_CALL(pdf_service_, HasUnsupportedFeature);

plugin_->DocumentHasUnsupportedFeature("feature");
plugin_->DocumentHasUnsupportedFeature("feature");

pdf_receiver_.FlushForTesting();
}

TEST_F(PdfViewWebPluginTest, UpdateGeometrySetsPluginRect) {
EXPECT_CALL(*engine_ptr_, ZoomUpdated(2.0f));
TestUpdateGeometrySetsPluginRect(
Expand Down

0 comments on commit 18742cc

Please sign in to comment.