[M120 Migration][MM] Support W3C EME
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / unittest / utc_blink_ewk_view_orientation_send_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 #define URL  ("ewk_view/orientation_test.html")
8
9 class utc_blink_ewk_view_orientation_send : public utc_blink_ewk_base
10 {
11 protected:
12   utc_blink_ewk_view_orientation_send()
13     : utc_blink_ewk_base()
14     , g_orientation(0)
15   {
16   }
17
18   void LoadFinished(Evas_Object* webview) override {
19     g_orientation = atol(ewk_view_title_get(GetEwkWebView()));
20     EventLoopStop(utc_blink_ewk_base::Success);
21   }
22
23   void ConsoleMessage(Evas_Object* webview,
24                       const Ewk_Console_Message* msg) override {
25     utc_blink_ewk_base::ConsoleMessage(webview, msg);
26
27     const char* message_text = ewk_console_message_text_get(msg);
28     long int orientation = atol(message_text);
29
30     switch (orientation) {
31     case -90:
32     case 0:
33     case 90:
34     case 180:
35     case 270:
36       g_orientation = orientation;
37       EventLoopStop(utc_blink_ewk_base::Success);
38       break;
39     default:
40       EventLoopStop(utc_blink_ewk_base::Failure);
41       break;
42     }
43
44   }
45
46 protected:
47   long int g_orientation;
48 };
49
50 /**
51  * @brief Checking whether orientation is set to 90 properly.
52  */
53 TEST_F(utc_blink_ewk_view_orientation_send, TEST_90DG)
54 {
55   std::string full_path = GetResourceUrl(URL);
56   ASSERT_FALSE(full_path.empty());
57   ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), full_path.c_str()));
58   ASSERT_EQ(Success, EventLoopStart());
59
60   utc_message("[utc_blink_ewk_view_orientation_send TEST_90DG] :: ewk_view_orientation_send");
61   ewk_view_orientation_send(GetEwkWebView(), 90);
62
63   ASSERT_EQ(Success, EventLoopStart());
64   ASSERT_EQ(g_orientation, 90);
65 }
66
67 /**
68  * @brief Checking whether orientation is set to 180 properly.
69  */
70 TEST_F(utc_blink_ewk_view_orientation_send, TEST_180DG)
71 {
72   std::string full_path = GetResourceUrl(URL);
73   ASSERT_FALSE(full_path.empty());
74   ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), full_path.c_str()));
75   ASSERT_EQ(Success, EventLoopStart());
76
77   utc_message("[utc_blink_ewk_view_orientation_send TEST_180DG] :: ewk_view_orientation_send");
78   ewk_view_orientation_send(GetEwkWebView(), 180);
79
80   ASSERT_EQ(Success, EventLoopStart());
81   ASSERT_EQ(g_orientation, 180);
82 }
83
84 /**
85  * @brief Checking whether orientation is set to 0 properly.
86  */
87 TEST_F(utc_blink_ewk_view_orientation_send, TEST_0DG)
88 {
89   std::string full_path = GetResourceUrl(URL);
90   ASSERT_FALSE(full_path.empty());
91   ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), full_path.c_str()));
92   ASSERT_EQ(Success, EventLoopStart());
93
94   // 0 is default value, so we need to change it before
95   // checking ewk_view_orientation_send with 0 as argument
96   if (g_orientation == 0) {
97     ewk_view_orientation_send(GetEwkWebView(), 90);
98
99     ASSERT_EQ(Success, EventLoopStart());
100     ASSERT_EQ(g_orientation, 90);
101   }
102   utc_message("[utc_blink_ewk_view_orientation_send TEST_0DG] :: ewk_view_orientation_send");
103   ewk_view_orientation_send(GetEwkWebView(), 0);
104
105   ASSERT_EQ(Success, EventLoopStart());
106   ASSERT_EQ(g_orientation, 0);
107 }
108
109 /**
110  * @brief Checking whether orientation is set to 270 properly.
111  */
112 TEST_F(utc_blink_ewk_view_orientation_send, TEST_270DG)
113 {
114   std::string full_path = GetResourceUrl(URL);
115   ASSERT_FALSE(full_path.empty());
116   ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), full_path.c_str()));
117   ASSERT_EQ(Success, EventLoopStart());
118
119   utc_message("[utc_blink_ewk_view_orientation_send TEST_270DG] :: ewk_view_orientation_send");
120   ewk_view_orientation_send(GetEwkWebView(), 270);
121
122   ASSERT_EQ(Success, EventLoopStart());
123   ASSERT_EQ(g_orientation, 270);
124 }
125
126 /**
127  * @brief Checking whether orientation of -90 is transformed to -270 properly.
128  */
129 TEST_F(utc_blink_ewk_view_orientation_send, TEST_MINUS90DG)
130 {
131   std::string full_path = GetResourceUrl(URL);
132   ASSERT_FALSE(full_path.empty());
133   ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), full_path.c_str()));
134   ASSERT_EQ(Success, EventLoopStart());
135
136   utc_message("[utc_blink_ewk_view_orientation_send TEST_MINUS90DG] :: ewk_view_orientation_send");
137   ewk_view_orientation_send(GetEwkWebView(), -90);
138
139   ASSERT_EQ(Success, EventLoopStart());
140   ASSERT_EQ(g_orientation, 270);
141 }
142
143 /**
144  * @brief Checking that invalid orientation is not set.
145  */
146 TEST_F(utc_blink_ewk_view_orientation_send, TEST_40DG)
147 {
148   std::string full_path = GetResourceUrl(URL);
149   ASSERT_FALSE(full_path.empty());
150   ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), full_path.c_str()));
151   ASSERT_EQ(Success, EventLoopStart());
152
153   utc_message("[utc_blink_ewk_view_orientation_send TEST_40DG] :: ewk_view_orientation_send");
154   ewk_view_orientation_send(GetEwkWebView(), 40);
155
156   ASSERT_EQ(Timeout, EventLoopStart(2.0));
157 }
158
159
160 /**
161  * @brief Checking whether function works properly in case of NULL of a webview.
162  */
163 TEST_F(utc_blink_ewk_view_orientation_send, INVALID_ARGS)
164 {
165   std::string full_path = GetResourceUrl(URL);
166   ASSERT_FALSE(full_path.empty());
167   ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), full_path.c_str()));
168   ASSERT_EQ(Success, EventLoopStart());
169
170   ewk_view_orientation_send(NULL, EWK_SCREEN_ORIENTATION_PORTRAIT_PRIMARY);
171   EXPECT_EQ(Timeout, EventLoopStart(2.0));
172
173   ewk_view_orientation_send(GetEwkWebView(), 22);
174   EXPECT_EQ(Timeout, EventLoopStart(2.0));
175 }
176
177 /**
178  * @brief Checking whether function works properly in case of no render widget
179  *        host view object, that is if information about the orientation set
180  *        is not lost when function is called before setting the url.
181  */
182 TEST_F(utc_blink_ewk_view_orientation_send, BEFOREURLSET)
183 {
184   std::string full_path = GetResourceUrl(URL);
185   ASSERT_FALSE(full_path.empty());
186
187   ewk_view_orientation_send(GetEwkWebView(), 90);
188
189   ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), full_path.c_str()));
190   EXPECT_EQ(Success, EventLoopStart());
191   ASSERT_EQ(g_orientation, 90);
192 }