Commit bd1d1dbc authored by Alex Newcomer's avatar Alex Newcomer Committed by Commit Bot

cros: merge behavior of Simple Render and Enhanced Clipboard

We will eventually remove the flag, but due to dogfood messaging we
will keep it around for a bit longer.

Bug: 1138674
Change-Id: I544fe687f5077e2779e7924e5697c6ce1d9d351f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2500022
Commit-Queue: Alex Newcomer <newcomer@chromium.org>
Reviewed-by: default avatarAndrew Xu <andrewxu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821451}
parent fec42fc2
...@@ -124,7 +124,7 @@ TEST_F(ClipboardHistoryResourceManagerTest, GetLabel) { ...@@ -124,7 +124,7 @@ TEST_F(ClipboardHistoryResourceManagerTest, GetLabel) {
// Populate a builder with all the data formats that we expect to handle. // Populate a builder with all the data formats that we expect to handle.
ClipboardHistoryItemBuilder builder; ClipboardHistoryItemBuilder builder;
builder.SetText("Text") builder.SetText("Text")
.SetMarkup("Markup") .SetMarkup("<img Markup")
.SetRtf("Rtf") .SetRtf("Rtf")
.SetBookmarkTitle("Bookmark Title") .SetBookmarkTitle("Bookmark Title")
.SetBitmap(gfx::test::CreateBitmap(10, 10)) .SetBitmap(gfx::test::CreateBitmap(10, 10))
...@@ -139,7 +139,7 @@ TEST_F(ClipboardHistoryResourceManagerTest, GetLabel) { ...@@ -139,7 +139,7 @@ TEST_F(ClipboardHistoryResourceManagerTest, GetLabel) {
// In the absence of bitmap data, HTML data takes precedence. // In the absence of bitmap data, HTML data takes precedence.
EXPECT_EQ(resource_manager()->GetLabel(builder.Build()), EXPECT_EQ(resource_manager()->GetLabel(builder.Build()),
base::UTF8ToUTF16("Markup")); base::UTF8ToUTF16("<img Markup"));
builder.ClearMarkup(); builder.ClearMarkup();
...@@ -173,9 +173,9 @@ TEST_F(ClipboardHistoryResourceManagerTest, GetLabel) { ...@@ -173,9 +173,9 @@ TEST_F(ClipboardHistoryResourceManagerTest, GetLabel) {
base::UTF8ToUTF16("File.txt, Other File.txt")); base::UTF8ToUTF16("File.txt, Other File.txt"));
} }
// Tests that Render is called once when an eligible item is added // Tests that Render is called once when an eligible <img> is added
// to ClipboardHistory. // to ClipboardHistory.
TEST_F(ClipboardHistoryResourceManagerTest, BasicCachedImageModel) { TEST_F(ClipboardHistoryResourceManagerTest, BasicImgCachedImageModel) {
ui::ImageModel expected_image_model = GetRandomImageModel(); ui::ImageModel expected_image_model = GetRandomImageModel();
ON_CALL(*mock_image_factory(), Render) ON_CALL(*mock_image_factory(), Render)
.WillByDefault(testing::WithArg<2>( .WillByDefault(testing::WithArg<2>(
...@@ -188,7 +188,31 @@ TEST_F(ClipboardHistoryResourceManagerTest, BasicCachedImageModel) { ...@@ -188,7 +188,31 @@ TEST_F(ClipboardHistoryResourceManagerTest, BasicCachedImageModel) {
// Write a basic ClipboardData which is eligible to render HTML. // Write a basic ClipboardData which is eligible to render HTML.
{ {
ui::ScopedClipboardWriter scw(ui::ClipboardBuffer::kCopyPaste); ui::ScopedClipboardWriter scw(ui::ClipboardBuffer::kCopyPaste);
scw.WriteHTML(base::UTF8ToUTF16("test"), "source_url"); scw.WriteHTML(base::UTF8ToUTF16("<img test>"), "source_url");
}
FlushMessageLoop();
EXPECT_EQ(expected_image_model, resource_manager()->GetImageModel(
clipboard_history()->GetItems().front()));
}
// Tests that Render is called once when an eligible <table> is added
// to ClipboardHistory.
TEST_F(ClipboardHistoryResourceManagerTest, BasicTableCachedImageModel) {
ui::ImageModel expected_image_model = GetRandomImageModel();
ON_CALL(*mock_image_factory(), Render)
.WillByDefault(testing::WithArg<2>(
[&](ClipboardImageModelFactory::ImageModelCallback callback) {
std::move(callback).Run(expected_image_model);
}));
EXPECT_CALL(*mock_image_factory(), CancelRequest).Times(0);
EXPECT_CALL(*mock_image_factory(), Render).Times(1);
// Write a basic ClipboardData which is eligible to render HTML.
{
ui::ScopedClipboardWriter scw(ui::ClipboardBuffer::kCopyPaste);
scw.WriteHTML(base::UTF8ToUTF16("<table test>"), "source_url");
} }
FlushMessageLoop(); FlushMessageLoop();
...@@ -197,6 +221,27 @@ TEST_F(ClipboardHistoryResourceManagerTest, BasicCachedImageModel) { ...@@ -197,6 +221,27 @@ TEST_F(ClipboardHistoryResourceManagerTest, BasicCachedImageModel) {
clipboard_history()->GetItems().front())); clipboard_history()->GetItems().front()));
} }
// Tests that Render is not called ineligble html is added to ClipboarHistory
TEST_F(ClipboardHistoryResourceManagerTest, BasicIneligibleCachedImageModel) {
ui::ImageModel expected_image_model = GetRandomImageModel();
ON_CALL(*mock_image_factory(), Render)
.WillByDefault(testing::WithArg<2>(
[&](ClipboardImageModelFactory::ImageModelCallback callback) {
std::move(callback).Run(expected_image_model);
}));
EXPECT_CALL(*mock_image_factory(), CancelRequest).Times(0);
EXPECT_CALL(*mock_image_factory(), Render).Times(0);
// Write a basic ClipboardData which is eligible to render HTML.
{
ui::ScopedClipboardWriter scw(ui::ClipboardBuffer::kCopyPaste);
scw.WriteHTML(base::UTF8ToUTF16("html with no img or table tag"),
"source_url");
}
FlushMessageLoop();
}
// Tests that copying duplicate HTML to the buffer results in only one render // Tests that copying duplicate HTML to the buffer results in only one render
// request, and that that request is canceled once when the item is forgotten. // request, and that that request is canceled once when the item is forgotten.
TEST_F(ClipboardHistoryResourceManagerTest, DuplicateHTML) { TEST_F(ClipboardHistoryResourceManagerTest, DuplicateHTML) {
...@@ -214,7 +259,7 @@ TEST_F(ClipboardHistoryResourceManagerTest, DuplicateHTML) { ...@@ -214,7 +259,7 @@ TEST_F(ClipboardHistoryResourceManagerTest, DuplicateHTML) {
for (int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i) {
{ {
ui::ScopedClipboardWriter scw(ui::ClipboardBuffer::kCopyPaste); ui::ScopedClipboardWriter scw(ui::ClipboardBuffer::kCopyPaste);
scw.WriteHTML(base::UTF8ToUTF16("test"), "source_url"); scw.WriteHTML(base::UTF8ToUTF16("<img test>"), "source_url");
} }
FlushMessageLoop(); FlushMessageLoop();
} }
...@@ -242,12 +287,12 @@ TEST_F(ClipboardHistoryResourceManagerTest, DifferentHTML) { ...@@ -242,12 +287,12 @@ TEST_F(ClipboardHistoryResourceManagerTest, DifferentHTML) {
EXPECT_CALL(*mock_image_factory(), CancelRequest).Times(0); EXPECT_CALL(*mock_image_factory(), CancelRequest).Times(0);
{ {
ui::ScopedClipboardWriter scw(ui::ClipboardBuffer::kCopyPaste); ui::ScopedClipboardWriter scw(ui::ClipboardBuffer::kCopyPaste);
scw.WriteHTML(base::UTF8ToUTF16("test"), "source_url"); scw.WriteHTML(base::UTF8ToUTF16("<img test>"), "source_url");
} }
FlushMessageLoop(); FlushMessageLoop();
{ {
ui::ScopedClipboardWriter scw(ui::ClipboardBuffer::kCopyPaste); ui::ScopedClipboardWriter scw(ui::ClipboardBuffer::kCopyPaste);
scw.WriteHTML(base::UTF8ToUTF16("different"), "source_url"); scw.WriteHTML(base::UTF8ToUTF16("<img different>"), "source_url");
} }
FlushMessageLoop(); FlushMessageLoop();
......
...@@ -731,7 +731,8 @@ bool IsClipboardHistoryNudgeSessionResetEnabled() { ...@@ -731,7 +731,8 @@ bool IsClipboardHistoryNudgeSessionResetEnabled() {
} }
bool IsClipboardHistorySimpleRenderEnabled() { bool IsClipboardHistorySimpleRenderEnabled() {
return base::FeatureList::IsEnabled(kClipboardHistorySimpleRender); return base::FeatureList::IsEnabled(kClipboardHistory) ||
base::FeatureList::IsEnabled(kClipboardHistorySimpleRender);
} }
bool IsPhoneHubEnabled() { bool IsPhoneHubEnabled() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment