[unseasoned-pdf] Add unit tests for DocumentLoadFailed().
Add unit tests for PdfViewPluginBase::DocumentLoadFailed() and set enum class `DocumentLoadState` public so that it can be used for testing. Bug: 1218534 Change-Id: I81eef5f441b9eed3dfe15884278545d9db278adf Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2982662 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Hui Yingst <nigi@chromium.org> Cr-Commit-Position: refs/heads/master@{#895433}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
188c0f6b71
commit
3daf72f6f1
@ -60,6 +60,12 @@ class PdfViewPluginBase : public PDFEngine::Client,
|
||||
public:
|
||||
using PDFEngine::Client::ScheduleTaskOnMainThread;
|
||||
|
||||
enum class DocumentLoadState {
|
||||
kLoading = 0,
|
||||
kComplete,
|
||||
kFailed,
|
||||
};
|
||||
|
||||
// Must match `SaveRequestType` in chrome/browser/resources/pdf/constants.js.
|
||||
enum class SaveRequestType {
|
||||
kAnnotation = 0,
|
||||
@ -145,12 +151,6 @@ class PdfViewPluginBase : public PDFEngine::Client,
|
||||
kLoaded, // Fully loaded.
|
||||
};
|
||||
|
||||
enum class DocumentLoadState {
|
||||
kLoading = 0,
|
||||
kComplete,
|
||||
kFailed,
|
||||
};
|
||||
|
||||
struct BackgroundPart {
|
||||
gfx::Rect location;
|
||||
uint32_t color;
|
||||
|
@ -66,10 +66,12 @@ class TestPDFiumEngine : public PDFiumEngine {
|
||||
class FakePdfViewPluginBase : public PdfViewPluginBase {
|
||||
public:
|
||||
// Public for testing.
|
||||
using PdfViewPluginBase::document_load_state;
|
||||
using PdfViewPluginBase::edit_mode;
|
||||
using PdfViewPluginBase::full_frame;
|
||||
using PdfViewPluginBase::HandleMessage;
|
||||
using PdfViewPluginBase::InitializeEngine;
|
||||
using PdfViewPluginBase::set_document_load_state;
|
||||
using PdfViewPluginBase::set_full_frame;
|
||||
|
||||
MOCK_METHOD(bool, Confirm, (const std::string&), (override));
|
||||
@ -234,6 +236,41 @@ TEST_F(PdfViewPluginBaseTest, CreateUrlLoaderWithoutFullFrame) {
|
||||
EXPECT_FALSE(fake_plugin_.GetDidCallStartLoadingForTesting());
|
||||
}
|
||||
|
||||
TEST_F(PdfViewPluginBaseTest, DocumentLoadFailedWithNotifiedRenderFrame) {
|
||||
// Notify the render frame about document loading.
|
||||
fake_plugin_.set_full_frame(true);
|
||||
ASSERT_TRUE(fake_plugin_.full_frame());
|
||||
fake_plugin_.CreateUrlLoader();
|
||||
|
||||
ASSERT_EQ(PdfViewPluginBase::DocumentLoadState::kLoading,
|
||||
fake_plugin_.document_load_state());
|
||||
EXPECT_TRUE(fake_plugin_.GetDidCallStartLoadingForTesting());
|
||||
|
||||
EXPECT_CALL(fake_plugin_, UserMetricsRecordAction("PDF.LoadFailure"));
|
||||
EXPECT_CALL(fake_plugin_, PluginDidStopLoading());
|
||||
|
||||
fake_plugin_.DocumentLoadFailed();
|
||||
EXPECT_EQ(PdfViewPluginBase::DocumentLoadState::kFailed,
|
||||
fake_plugin_.document_load_state());
|
||||
EXPECT_FALSE(fake_plugin_.GetDidCallStartLoadingForTesting());
|
||||
}
|
||||
|
||||
TEST_F(PdfViewPluginBaseTest, DocumentLoadFailedWithoutNotifiedRenderFrame) {
|
||||
// The render frame has never been notified about document loading before.
|
||||
ASSERT_FALSE(fake_plugin_.full_frame());
|
||||
EXPECT_FALSE(fake_plugin_.GetDidCallStartLoadingForTesting());
|
||||
|
||||
ASSERT_EQ(PdfViewPluginBase::DocumentLoadState::kLoading,
|
||||
fake_plugin_.document_load_state());
|
||||
EXPECT_CALL(fake_plugin_, UserMetricsRecordAction("PDF.LoadFailure"));
|
||||
EXPECT_CALL(fake_plugin_, PluginDidStopLoading()).Times(0);
|
||||
|
||||
fake_plugin_.DocumentLoadFailed();
|
||||
EXPECT_EQ(PdfViewPluginBase::DocumentLoadState::kFailed,
|
||||
fake_plugin_.document_load_state());
|
||||
EXPECT_FALSE(fake_plugin_.GetDidCallStartLoadingForTesting());
|
||||
}
|
||||
|
||||
TEST_F(PdfViewPluginBaseTest, DocumentHasUnsupportedFeatureInFullFrame) {
|
||||
fake_plugin_.set_full_frame(true);
|
||||
ASSERT_TRUE(fake_plugin_.full_frame());
|
||||
|
Reference in New Issue
Block a user