Skip to content

Commit

Permalink
[unseasoned-pdf] Add a test PdfViewWebPluginTest.ChangeTextSelection.
Browse files Browse the repository at this point in the history
Add a unit test PdfViewWebPluginTest.ChangeTextSelection, which
exercises SetSelectedText(), HasSelection(), SelectionAsText() and
SelectionAsMarkup().

Bug: 1199558
Change-Id: I681a7a6b26a68644be8be8ed78d83b4940edb43f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2889914
Commit-Queue: Hui Yingst <nigi@chromium.org>
Reviewed-by: K. Moon <kmoon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#882785}
  • Loading branch information
Hui Yingst authored and Chromium LUCI CQ committed May 14, 2021
1 parent e7b242c commit 0d127b1
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions pdf/pdf_view_web_plugin_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "pdf/pdf_view_web_plugin.h"

#include <memory>
#include <string>
#include <utility>

#include "cc/paint/paint_canvas.h"
Expand All @@ -14,6 +15,7 @@
#include "pdf/test/test_helpers.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/public/platform/web_text_input_type.h"
#include "third_party/blink/public/web/web_associated_url_loader.h"
#include "third_party/blink/public/web/web_plugin_params.h"
Expand Down Expand Up @@ -67,6 +69,10 @@ SkBitmap GenerateExpectedBitmapForPaint(float device_scale,
return expected_bitmap;
}

MATCHER_P(EqualsWebString, selected_string, "") {
return arg.Utf8() == selected_string;
}

class FakeContainerWrapper final : public PdfViewWebPlugin::ContainerWrapper {
public:
explicit FakeContainerWrapper(PdfViewWebPlugin* web_plugin)
Expand Down Expand Up @@ -282,6 +288,31 @@ TEST_F(PdfViewWebPluginTest, PaintSnapshots) {
}
}

TEST_F(PdfViewWebPluginTest, ChangeTextSelection) {
ASSERT_FALSE(plugin_->HasSelection());
ASSERT_TRUE(plugin_->SelectionAsText().IsEmpty());
ASSERT_TRUE(plugin_->SelectionAsMarkup().IsEmpty());

testing::InSequence s;
static constexpr char kSelectedText[] = "1234";
EXPECT_CALL(*wrapper_ptr_,
TextSelectionChanged(EqualsWebString(kSelectedText), 0,
gfx::Range(0, 4)));

plugin_->SetSelectedText(kSelectedText);
EXPECT_TRUE(plugin_->HasSelection());
EXPECT_EQ(kSelectedText, plugin_->SelectionAsText().Utf8());
EXPECT_EQ(kSelectedText, plugin_->SelectionAsMarkup().Utf8());

static constexpr char kEmptyText[] = "";
EXPECT_CALL(*wrapper_ptr_, TextSelectionChanged(EqualsWebString(kEmptyText),
0, gfx::Range(0, 0)));
plugin_->SetSelectedText(kEmptyText);
EXPECT_FALSE(plugin_->HasSelection());
EXPECT_TRUE(plugin_->SelectionAsText().IsEmpty());
EXPECT_TRUE(plugin_->SelectionAsMarkup().IsEmpty());
}

TEST_F(PdfViewWebPluginTest, FormTextFieldFocusChangeUpdatesTextInputType) {
ASSERT_EQ(blink::WebTextInputType::kWebTextInputTypeNone,
wrapper_ptr_->widget_text_input_type());
Expand Down

0 comments on commit 0d127b1

Please sign in to comment.