blob: c73dc008f7ba753d51d2b16375522f232c8dcd53 [file] [log] [blame]
Tom Sepeza310e002015-02-27 13:03:07 -08001// Copyright 2015 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Lei Zhangb4e7f302015-11-06 15:52:32 -08005#include "public/fpdf_formfill.h"
Wei Li091f7a02015-11-09 12:09:55 -08006#include "testing/embedder_test.h"
7#include "testing/embedder_test_mock_delegate.h"
8#include "testing/embedder_test_timer_handling_delegate.h"
Tom Sepeza310e002015-02-27 13:03:07 -08009#include "testing/gmock/include/gmock/gmock.h"
10#include "testing/gtest/include/gtest/gtest.h"
11
12using testing::_;
13using testing::Return;
14
Nico Weber9d8ec5a2015-08-04 13:00:21 -070015class FPDFFormFillEmbeddertest : public EmbedderTest {};
Tom Sepeza310e002015-02-27 13:03:07 -080016
17TEST_F(FPDFFormFillEmbeddertest, FirstTest) {
18 EmbedderTestMockDelegate mock;
19 EXPECT_CALL(mock, Alert(_, _, _, _)).Times(0);
20 EXPECT_CALL(mock, UnsupportedHandler(_)).Times(0);
Tom Sepez6efc0ad2015-06-02 17:11:18 -070021 EXPECT_CALL(mock, SetTimer(_, _)).Times(0);
22 EXPECT_CALL(mock, KillTimer(_)).Times(0);
Tom Sepeza310e002015-02-27 13:03:07 -080023 SetDelegate(&mock);
24
Wei Li091f7a02015-11-09 12:09:55 -080025 EXPECT_TRUE(OpenDocument("hello_world.pdf"));
Tom Sepeza310e002015-02-27 13:03:07 -080026 FPDF_PAGE page = LoadPage(0);
27 EXPECT_NE(nullptr, page);
Lei Zhangd27acae2015-05-15 15:36:02 -070028 UnloadPage(page);
Tom Sepeza310e002015-02-27 13:03:07 -080029}
Tom Sepez6efc0ad2015-06-02 17:11:18 -070030
31TEST_F(FPDFFormFillEmbeddertest, BUG_487928) {
32 EmbedderTestTimerHandlingDelegate delegate;
33 SetDelegate(&delegate);
34
Wei Li091f7a02015-11-09 12:09:55 -080035 EXPECT_TRUE(OpenDocument("bug_487928.pdf"));
Tom Sepez6efc0ad2015-06-02 17:11:18 -070036 FPDF_PAGE page = LoadPage(0);
37 EXPECT_NE(nullptr, page);
38 DoOpenActions();
39 delegate.AdvanceTime(5000);
40 UnloadPage(page);
41}
Tom Sepez0b133982015-07-28 11:23:22 -070042
Tom Sepez396e8722015-09-09 10:16:08 -070043TEST_F(FPDFFormFillEmbeddertest, BUG_507316) {
44 EmbedderTestTimerHandlingDelegate delegate;
45 SetDelegate(&delegate);
46
Wei Li091f7a02015-11-09 12:09:55 -080047 EXPECT_TRUE(OpenDocument("bug_507316.pdf"));
Tom Sepez396e8722015-09-09 10:16:08 -070048 FPDF_PAGE page = LoadAndCachePage(2);
49 EXPECT_NE(nullptr, page);
50 DoOpenActions();
51 delegate.AdvanceTime(4000);
52 UnloadPage(page);
53}
54
Tom Sepez0b133982015-07-28 11:23:22 -070055TEST_F(FPDFFormFillEmbeddertest, BUG_514690) {
Wei Li091f7a02015-11-09 12:09:55 -080056 EXPECT_TRUE(OpenDocument("hello_world.pdf"));
Tom Sepez0b133982015-07-28 11:23:22 -070057 FPDF_PAGE page = LoadPage(0);
58 EXPECT_NE(nullptr, page);
59
60 // Test that FORM_OnMouseMove() etc. permit null HANDLES and PAGES.
61 FORM_OnMouseMove(nullptr, page, 0, 10.0, 10.0);
62 FORM_OnMouseMove(form_handle(), nullptr, 0, 10.0, 10.0);
63
64 UnloadPage(page);
65}
Lei Zhang79e893a2015-11-04 16:02:47 -080066
Tom Sepez4d071792016-02-04 16:53:26 -080067#ifdef PDF_ENABLE_V8
Lei Zhang79e893a2015-11-04 16:02:47 -080068TEST_F(FPDFFormFillEmbeddertest, BUG_551248) {
69 EmbedderTestTimerHandlingDelegate delegate;
70 SetDelegate(&delegate);
71
Wei Li091f7a02015-11-09 12:09:55 -080072 EXPECT_TRUE(OpenDocument("bug_551248.pdf"));
Lei Zhang79e893a2015-11-04 16:02:47 -080073 FPDF_PAGE page = LoadPage(0);
74 EXPECT_NE(nullptr, page);
75 DoOpenActions();
76 delegate.AdvanceTime(5000);
77 UnloadPage(page);
78
79 const auto& alerts = delegate.GetAlerts();
80 ASSERT_EQ(1U, alerts.size());
81
82 EXPECT_STREQ(L"hello world", alerts[0].message.c_str());
83 EXPECT_STREQ(L"Alert", alerts[0].title.c_str());
84 EXPECT_EQ(0, alerts[0].type);
85 EXPECT_EQ(0, alerts[0].icon);
86}
Tom Sepez4d071792016-02-04 16:53:26 -080087#endif // PDF_ENABLE_V8