Home | History | Annotate | Download | only in src
      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 
      5 #include "public/fpdf_formfill.h"
      6 #include "testing/embedder_test.h"
      7 #include "testing/embedder_test_mock_delegate.h"
      8 #include "testing/embedder_test_timer_handling_delegate.h"
      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 
     15 class FPDFFormFillEmbeddertest : public EmbedderTest {};
     16 
     17 TEST_F(FPDFFormFillEmbeddertest, FirstTest) {
     18   EmbedderTestMockDelegate mock;
     19   EXPECT_CALL(mock, Alert(_, _, _, _)).Times(0);
     20   EXPECT_CALL(mock, UnsupportedHandler(_)).Times(0);
     21   EXPECT_CALL(mock, SetTimer(_, _)).Times(0);
     22   EXPECT_CALL(mock, KillTimer(_)).Times(0);
     23   SetDelegate(&mock);
     24 
     25   EXPECT_TRUE(OpenDocument("hello_world.pdf"));
     26   FPDF_PAGE page = LoadPage(0);
     27   EXPECT_NE(nullptr, page);
     28   UnloadPage(page);
     29 }
     30 
     31 TEST_F(FPDFFormFillEmbeddertest, BUG_487928) {
     32   EmbedderTestTimerHandlingDelegate delegate;
     33   SetDelegate(&delegate);
     34 
     35   EXPECT_TRUE(OpenDocument("bug_487928.pdf"));
     36   FPDF_PAGE page = LoadPage(0);
     37   EXPECT_NE(nullptr, page);
     38   DoOpenActions();
     39   delegate.AdvanceTime(5000);
     40   UnloadPage(page);
     41 }
     42 
     43 TEST_F(FPDFFormFillEmbeddertest, BUG_507316) {
     44   EmbedderTestTimerHandlingDelegate delegate;
     45   SetDelegate(&delegate);
     46 
     47   EXPECT_TRUE(OpenDocument("bug_507316.pdf"));
     48   FPDF_PAGE page = LoadAndCachePage(2);
     49   EXPECT_NE(nullptr, page);
     50   DoOpenActions();
     51   delegate.AdvanceTime(4000);
     52   UnloadPage(page);
     53 }
     54 
     55 TEST_F(FPDFFormFillEmbeddertest, BUG_514690) {
     56   EXPECT_TRUE(OpenDocument("hello_world.pdf"));
     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 }
     66 
     67 TEST_F(FPDFFormFillEmbeddertest, BUG_551248) {
     68   EmbedderTestTimerHandlingDelegate delegate;
     69   SetDelegate(&delegate);
     70 
     71   EXPECT_TRUE(OpenDocument("bug_551248.pdf"));
     72   FPDF_PAGE page = LoadPage(0);
     73   EXPECT_NE(nullptr, page);
     74   DoOpenActions();
     75   delegate.AdvanceTime(5000);
     76   UnloadPage(page);
     77 
     78   const auto& alerts = delegate.GetAlerts();
     79   ASSERT_EQ(1U, alerts.size());
     80 
     81   EXPECT_STREQ(L"hello world", alerts[0].message.c_str());
     82   EXPECT_STREQ(L"Alert", alerts[0].title.c_str());
     83   EXPECT_EQ(0, alerts[0].type);
     84   EXPECT_EQ(0, alerts[0].icon);
     85 }
     86