Tom Sepez | a310e00 | 2015-02-27 13:03:07 -0800 | [diff] [blame] | 1 | // 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 Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 5 | #include "public/fpdf_formfill.h" |
Wei Li | 091f7a0 | 2015-11-09 12:09:55 -0800 | [diff] [blame] | 6 | #include "testing/embedder_test.h" |
| 7 | #include "testing/embedder_test_mock_delegate.h" |
| 8 | #include "testing/embedder_test_timer_handling_delegate.h" |
Tom Sepez | a310e00 | 2015-02-27 13:03:07 -0800 | [diff] [blame] | 9 | #include "testing/gmock/include/gmock/gmock.h" |
| 10 | #include "testing/gtest/include/gtest/gtest.h" |
| 11 | |
| 12 | using testing::_; |
| 13 | using testing::Return; |
| 14 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 15 | class FPDFFormFillEmbeddertest : public EmbedderTest {}; |
Tom Sepez | a310e00 | 2015-02-27 13:03:07 -0800 | [diff] [blame] | 16 | |
| 17 | TEST_F(FPDFFormFillEmbeddertest, FirstTest) { |
| 18 | EmbedderTestMockDelegate mock; |
| 19 | EXPECT_CALL(mock, Alert(_, _, _, _)).Times(0); |
| 20 | EXPECT_CALL(mock, UnsupportedHandler(_)).Times(0); |
Tom Sepez | 6efc0ad | 2015-06-02 17:11:18 -0700 | [diff] [blame] | 21 | EXPECT_CALL(mock, SetTimer(_, _)).Times(0); |
| 22 | EXPECT_CALL(mock, KillTimer(_)).Times(0); |
Tom Sepez | a310e00 | 2015-02-27 13:03:07 -0800 | [diff] [blame] | 23 | SetDelegate(&mock); |
| 24 | |
Wei Li | 091f7a0 | 2015-11-09 12:09:55 -0800 | [diff] [blame] | 25 | EXPECT_TRUE(OpenDocument("hello_world.pdf")); |
Tom Sepez | a310e00 | 2015-02-27 13:03:07 -0800 | [diff] [blame] | 26 | FPDF_PAGE page = LoadPage(0); |
| 27 | EXPECT_NE(nullptr, page); |
Lei Zhang | d27acae | 2015-05-15 15:36:02 -0700 | [diff] [blame] | 28 | UnloadPage(page); |
Tom Sepez | a310e00 | 2015-02-27 13:03:07 -0800 | [diff] [blame] | 29 | } |
Tom Sepez | 6efc0ad | 2015-06-02 17:11:18 -0700 | [diff] [blame] | 30 | |
| 31 | TEST_F(FPDFFormFillEmbeddertest, BUG_487928) { |
| 32 | EmbedderTestTimerHandlingDelegate delegate; |
| 33 | SetDelegate(&delegate); |
| 34 | |
Wei Li | 091f7a0 | 2015-11-09 12:09:55 -0800 | [diff] [blame] | 35 | EXPECT_TRUE(OpenDocument("bug_487928.pdf")); |
Tom Sepez | 6efc0ad | 2015-06-02 17:11:18 -0700 | [diff] [blame] | 36 | FPDF_PAGE page = LoadPage(0); |
| 37 | EXPECT_NE(nullptr, page); |
| 38 | DoOpenActions(); |
| 39 | delegate.AdvanceTime(5000); |
| 40 | UnloadPage(page); |
| 41 | } |
Tom Sepez | 0b13398 | 2015-07-28 11:23:22 -0700 | [diff] [blame] | 42 | |
Tom Sepez | 396e872 | 2015-09-09 10:16:08 -0700 | [diff] [blame] | 43 | TEST_F(FPDFFormFillEmbeddertest, BUG_507316) { |
| 44 | EmbedderTestTimerHandlingDelegate delegate; |
| 45 | SetDelegate(&delegate); |
| 46 | |
Wei Li | 091f7a0 | 2015-11-09 12:09:55 -0800 | [diff] [blame] | 47 | EXPECT_TRUE(OpenDocument("bug_507316.pdf")); |
Tom Sepez | 396e872 | 2015-09-09 10:16:08 -0700 | [diff] [blame] | 48 | FPDF_PAGE page = LoadAndCachePage(2); |
| 49 | EXPECT_NE(nullptr, page); |
| 50 | DoOpenActions(); |
| 51 | delegate.AdvanceTime(4000); |
| 52 | UnloadPage(page); |
| 53 | } |
| 54 | |
Tom Sepez | 0b13398 | 2015-07-28 11:23:22 -0700 | [diff] [blame] | 55 | TEST_F(FPDFFormFillEmbeddertest, BUG_514690) { |
Wei Li | 091f7a0 | 2015-11-09 12:09:55 -0800 | [diff] [blame] | 56 | EXPECT_TRUE(OpenDocument("hello_world.pdf")); |
Tom Sepez | 0b13398 | 2015-07-28 11:23:22 -0700 | [diff] [blame] | 57 | 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 Zhang | 79e893a | 2015-11-04 16:02:47 -0800 | [diff] [blame] | 66 | |
Tom Sepez | 4d07179 | 2016-02-04 16:53:26 -0800 | [diff] [blame] | 67 | #ifdef PDF_ENABLE_V8 |
Lei Zhang | 79e893a | 2015-11-04 16:02:47 -0800 | [diff] [blame] | 68 | TEST_F(FPDFFormFillEmbeddertest, BUG_551248) { |
| 69 | EmbedderTestTimerHandlingDelegate delegate; |
| 70 | SetDelegate(&delegate); |
| 71 | |
Wei Li | 091f7a0 | 2015-11-09 12:09:55 -0800 | [diff] [blame] | 72 | EXPECT_TRUE(OpenDocument("bug_551248.pdf")); |
Lei Zhang | 79e893a | 2015-11-04 16:02:47 -0800 | [diff] [blame] | 73 | 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 Sepez | 4d07179 | 2016-02-04 16:53:26 -0800 | [diff] [blame] | 87 | #endif // PDF_ENABLE_V8 |