[M120 Migration][MM] Support W3C EME
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / unittest / utc_blink_ewk_view_contents_pdf_get_func.cpp
1 // Copyright 2014 Samsung Electronics. 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 "utc_blink_ewk_base.h"
6
7 class utc_blink_ewk_view_contents_pdf_get : public utc_blink_ewk_base
8 {
9  protected:
10   bool file_exists;
11   void PreSetUp() override {
12     file_exists=false;
13     evas_object_smart_callback_add(GetEwkWebView(), "frame,rendered", FrameRendered, this);
14   }
15
16   void PostTearDown() override {
17     evas_object_smart_callback_del(GetEwkWebView(), "frame,rendered", FrameRendered);
18   }
19
20   /* Callback for load finished */
21   void LoadFinished(Evas_Object* webview) override { EventLoopStop(Success); }
22
23   static void FrameRendered(void* data, Evas_Object* obj, void* event_info)
24   {
25     utc_blink_ewk_view_contents_pdf_get*owner=static_cast<utc_blink_ewk_view_contents_pdf_get*>(data);
26     utc_message("[Frame rendered] ::");
27     if(owner)
28       owner->EventLoopStop( Success );
29   }
30
31   static Eina_Bool VerifyFile(void* data)
32   {
33     if(data)
34     {
35       utc_blink_ewk_view_contents_pdf_get*owner=static_cast<utc_blink_ewk_view_contents_pdf_get*>(data);
36       owner->file_exists = ecore_file_exists("/tmp/sample.pdf");
37       owner->EventLoopStop( Success );
38     }
39     return ECORE_CALLBACK_CANCEL;
40   }
41 };
42
43 /**
44  * @brief Positive test case of ewk_view_contents_pdf_get().
45  * Page is loaded and API is called to save pdf file.
46  * Then existence of file is verified by 3 second timer.
47  */
48 TEST_F(utc_blink_ewk_view_contents_pdf_get, POS_TEST)
49 {
50   char htmlBuffer[] = "<html>"
51                         "<head></head>"
52                         "<body>"
53                         "</body>"
54                       "</html>";
55
56   bool result = ewk_view_html_string_load(GetEwkWebView(), htmlBuffer, NULL, NULL);
57   if (!result)
58     utc_fail();
59   if(Success!=EventLoopStart())
60     utc_fail();
61
62   Evas_Coord width = 0;
63   Evas_Coord height = 0;
64   result = ewk_view_contents_size_get(GetEwkWebView(), &width, &height);
65   if(!result || !width || !height)
66     utc_fail();
67
68   result = ewk_view_contents_pdf_get(GetEwkWebView(), width, height, "/tmp/sample.pdf");
69   if (!result)
70     utc_fail();
71  // waiting for 3 seconds to pdf printer to work.
72   ecore_timer_add(3, VerifyFile, this);
73   EventLoopStart();
74
75   utc_check_true(file_exists);
76 }
77
78 /**
79  * @brief Checking whether function works properly in case of NULL of a webview.
80  */
81 TEST_F(utc_blink_ewk_view_contents_pdf_get, NEG_TEST)
82 {
83   bool result = ewk_view_contents_pdf_get(NULL, 200, 200, "/tmp/sample.pdf");
84   utc_check_false(result);
85 }