[unseasoned-pdf] Add a test PdfViewWebPluginTest.ChangeTextSelection.
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}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
e7b242ce7e
commit
0d127b119f
@ -5,6 +5,7 @@
|
||||
#include "pdf/pdf_view_web_plugin.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "cc/paint/paint_canvas.h"
|
||||
@ -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"
|
||||
@ -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)
|
||||
@ -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());
|
||||
|
Reference in New Issue
Block a user