2dc565bec80f2f74267bfe8e5374c305156e51e6
[WebKit-https.git] / Source / WebKit2 / UIProcess / API / efl / tests / test_ewk2_view.cpp
1 /*
2     Copyright (C) 2012 Samsung Electronics
3     Copyright (C) 2012 Intel Corporation. All rights reserved.
4
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Lesser General Public
7     License as published by the Free Software Foundation; either
8     version 2.1 of the License, or (at your option) any later version.
9
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13     Lesser General Public License for more details.
14
15     You should have received a copy of the GNU Lesser General Public License
16     along with this library; if not, write to the Free Software Foundation,
17     Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20 #include "config.h"
21
22 #include "UnitTestUtils/EWK2UnitTestBase.h"
23 #include "UnitTestUtils/EWK2UnitTestServer.h"
24 #include <wtf/text/CString.h>
25 #include <wtf/text/WTFString.h>
26
27 using namespace EWK2UnitTest;
28
29 extern EWK2UnitTestEnvironment* environment;
30
31 static bool fullScreenCallbackCalled;
32 static bool obtainedPageContents = false;
33 static bool scriptExecuteCallbackCalled;
34
35 static struct {
36     const char* expectedMessage;
37     bool called;
38 } alertCallbackData;
39
40 static struct {
41     const char* expectedMessage;
42     bool result;
43     bool called;
44 } confirmCallbackData;
45
46 static struct {
47     const char* expectedMessage;
48     const char* expectedDefaultValue;
49     const char* result;
50     bool called;
51 } promptCallbackData;
52
53 class EWK2ViewTest : public EWK2UnitTestBase {
54 public:
55     struct VibrationCbData {
56         bool didReceiveVibrate; // Whether the vibration event received.
57         bool didReceiveCancelVibration; // Whether the cancel vibration event received.
58         bool testFinished;
59         unsigned vibrateCalledCount; // Vibrate callbacks count.
60         unsigned expectedVibrationTime; // Expected vibration time.
61     };
62
63     static void onLoadFinishedForRedirection(void* userData, Evas_Object*, void*)
64     {
65         int* countLoadFinished = static_cast<int*>(userData);
66         (*countLoadFinished)--;
67     }
68
69     static void serverCallbackNavigation(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
70     {
71         if (message->method != SOUP_METHOD_GET) {
72             soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED);
73             return;
74         }
75
76         soup_message_set_status(message, SOUP_STATUS_OK);
77
78         Eina_Strbuf* body = eina_strbuf_new();
79         eina_strbuf_append_printf(body, "<html><title>%s</title><body>%s</body></html>", path + 1, path + 1);
80         const size_t bodyLength = eina_strbuf_length_get(body);
81         soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, eina_strbuf_string_steal(body), bodyLength);
82         eina_strbuf_free(body);
83
84         soup_message_body_complete(message->response_body);
85     }
86
87     static void onFormAboutToBeSubmitted(void* userData, Evas_Object*, void* eventInfo)
88     {
89         Ewk_Form_Submission_Request* request = static_cast<Ewk_Form_Submission_Request*>(eventInfo);
90         bool* handled = static_cast<bool*>(userData);
91
92         ASSERT_TRUE(request);
93
94         Eina_List* fieldNames = ewk_form_submission_request_field_names_get(request);
95         ASSERT_TRUE(fieldNames);
96         ASSERT_EQ(3, eina_list_count(fieldNames));
97         void* data;
98         EINA_LIST_FREE(fieldNames, data)
99             eina_stringshare_del(static_cast<char*>(data));
100
101         const char* value1 = ewk_form_submission_request_field_value_get(request, "text1");
102         ASSERT_STREQ("value1", value1);
103         eina_stringshare_del(value1);
104         const char* value2 = ewk_form_submission_request_field_value_get(request, "text2");
105         ASSERT_STREQ("value2", value2);
106         eina_stringshare_del(value2);
107         const char* password = ewk_form_submission_request_field_value_get(request, "password");
108         ASSERT_STREQ("secret", password);
109         eina_stringshare_del(password);
110
111         *handled = true;
112     }
113
114     static Eina_Bool fullScreenCallback(Ewk_View_Smart_Data* smartData, Ewk_Security_Origin*)
115     {
116         fullScreenCallbackCalled = true;
117         return false;
118     }
119
120     static Eina_Bool fullScreenExitCallback(Ewk_View_Smart_Data* smartData)
121     {
122         fullScreenCallbackCalled = true;
123         return false;
124     }
125
126     static void checkAlert(Ewk_View_Smart_Data*, const char* message)
127     {
128         alertCallbackData.called = true;
129         EXPECT_STREQ(message, alertCallbackData.expectedMessage);
130     }
131
132     static Eina_Bool checkConfirm(Ewk_View_Smart_Data*, const char* message)
133     {
134         confirmCallbackData.called = true;
135         EXPECT_STREQ(message, confirmCallbackData.expectedMessage);
136         return confirmCallbackData.result;
137     }
138
139     static const char* checkPrompt(Ewk_View_Smart_Data*, const char* message, const char* defaultValue)
140     {
141         promptCallbackData.called = true;
142         EXPECT_STREQ(message, promptCallbackData.expectedMessage);
143         EXPECT_STREQ(defaultValue, promptCallbackData.expectedDefaultValue);
144
145         if (!promptCallbackData.result)
146             return 0;
147
148         return eina_stringshare_add(promptCallbackData.result);
149     }
150
151     static void onTextFound(void* userData, Evas_Object*, void* eventInfo)
152     {
153         int* result = static_cast<int*>(userData);
154         unsigned* matchCount = static_cast<unsigned*>(eventInfo);
155
156         *result = *matchCount;
157     }
158
159     static void onVibrate(void* userData, Evas_Object*, void* eventInfo)
160     {
161         VibrationCbData* data = static_cast<VibrationCbData*>(userData);
162         unsigned* vibrationTime = static_cast<unsigned*>(eventInfo);
163         if (*vibrationTime == data->expectedVibrationTime) {
164             data->didReceiveVibrate = true;
165             data->testFinished = true;
166         }
167         data->vibrateCalledCount++;
168     }
169
170     static void onCancelVibration(void* userData, Evas_Object*, void*)
171     {
172         VibrationCbData* data = static_cast<VibrationCbData*>(userData);
173         data->didReceiveCancelVibration = true;
174         data->testFinished = true;
175     }
176
177     static void loadVibrationHTMLString(Evas_Object* webView, const char* vibrationPattern, VibrationCbData* data)
178     {
179         const char* content =
180             "<html><head><script type='text/javascript'>function vibrate() { navigator.vibrate(%s);"
181             " document.title = \"Loaded\"; }</script></head><body onload='vibrate()'></body></html>";
182
183         data->didReceiveVibrate = false;
184         data->didReceiveCancelVibration = false;
185         data->vibrateCalledCount = 0;
186         data->testFinished = false;
187         Eina_Strbuf* buffer = eina_strbuf_new();
188         eina_strbuf_append_printf(buffer, content, vibrationPattern);
189         ewk_view_html_string_load(webView, eina_strbuf_string_get(buffer), 0, 0);
190         eina_strbuf_free(buffer);
191     }
192
193     static void onContentsSizeChangedPortrait(void* userData, Evas_Object*, void* eventInfo)
194     {
195         bool* result = static_cast<bool*>(userData);
196         Ewk_CSS_Size* size = static_cast<Ewk_CSS_Size*>(eventInfo);
197         if (size->w == 2000 && size->h == 3000)
198             *result = true;
199     }
200
201     static void onContentsSizeChangedLandscape(void* userData, Evas_Object*, void* eventInfo)
202     {
203         bool* result = static_cast<bool*>(userData);
204         Ewk_CSS_Size* size = static_cast<Ewk_CSS_Size*>(eventInfo);
205         if (size->w == 3000 && size->h == 2000)
206             *result = true;
207     }
208
209     static void PageContentsAsMHTMLCallback(Ewk_Page_Contents_Type type, const char* data, void*)
210     {
211         // Check the type
212         ASSERT_EQ(EWK_PAGE_CONTENTS_TYPE_MHTML, type);
213
214         // We should have exactly the same amount of bytes in the file
215         // than those coming from the callback data. We don't compare the
216         // strings read since the 'Date' field and the boundaries will be
217         // different on each case. MHTML functionality will be tested by
218         // layout tests, so checking the amount of bytes is enough.
219         Eina_File* f = eina_file_open(TEST_RESOURCES_DIR "/resultMHTML.mht", false);
220         if (!f)
221             return;
222
223         size_t fileSize = eina_file_size_get(f);
224         // As the day in 'Date' field may be one digit or two digit, the data length may also be varied by one byte.
225         EXPECT_TRUE(String(data).length() == fileSize || String(data).length() == fileSize + 1);
226
227         obtainedPageContents = true;
228         eina_file_close(f);
229     }
230
231     static void PageContentsAsStringCallback(Ewk_Page_Contents_Type type, const char* data, void*)
232     {
233         // Check the type.
234         ASSERT_EQ(EWK_PAGE_CONTENTS_TYPE_STRING, type);
235
236         // The variable data should be "Simple HTML".
237         ASSERT_STREQ("Simple HTML", data);
238
239         obtainedPageContents = true;
240     }
241 };
242
243 TEST_F(EWK2ViewTest, ewk_view_type_check)
244 {
245     ASSERT_FALSE(ewk_view_context_get(0));
246
247     Evas_Object* rectangle = evas_object_rectangle_add(canvas());
248     ASSERT_FALSE(ewk_view_url_set(rectangle, 0));
249 }
250
251 TEST_F(EWK2ViewTest, ewk_view_url_get)
252 {
253     ASSERT_TRUE(loadUrlSync(environment->defaultTestPageUrl()));
254     EXPECT_STREQ(environment->defaultTestPageUrl(), ewk_view_url_get(webView()));
255
256     int countLoadFinished = 2;
257     evas_object_smart_callback_add(webView(), "load,finished", onLoadFinishedForRedirection, &countLoadFinished);
258     ewk_view_url_set(webView(), environment->urlForResource("redirect_url_to_default.html").data());
259     while (countLoadFinished)
260         ecore_main_loop_iterate();
261     evas_object_smart_callback_del(webView(), "load,finished", onLoadFinishedForRedirection);
262     EXPECT_STREQ(environment->defaultTestPageUrl(), ewk_view_url_get(webView()));
263 }
264
265 TEST_F(EWK2ViewTest, ewk_view_device_pixel_ratio)
266 {
267     ASSERT_TRUE(loadUrlSync(environment->defaultTestPageUrl()));
268
269     // Default pixel ratio is 1.0
270     ASSERT_FLOAT_EQ(1, ewk_view_device_pixel_ratio_get(webView()));
271
272     ASSERT_TRUE(ewk_view_device_pixel_ratio_set(webView(), 1.2));
273     ASSERT_FLOAT_EQ(1.2, ewk_view_device_pixel_ratio_get(webView()));
274
275     ASSERT_TRUE(ewk_view_device_pixel_ratio_set(webView(), 1));
276     ASSERT_FLOAT_EQ(1, ewk_view_device_pixel_ratio_get(webView()));
277 }
278
279 TEST_F(EWK2ViewTest, ewk_view_html_string_load)
280 {
281     ewk_view_html_string_load(webView(), "<html><head><title>Foo</title></head><body>Bar</body></html>", 0, 0);
282     ASSERT_TRUE(waitUntilTitleChangedTo("Foo"));
283     ASSERT_STREQ("Foo", ewk_view_title_get(webView()));
284     ewk_view_html_string_load(webView(), "<html><head><title>Bar</title></head><body>Foo</body></html>", 0, 0);
285     ASSERT_TRUE(waitUntilTitleChangedTo("Bar"));
286     ASSERT_STREQ("Bar", ewk_view_title_get(webView()));
287 }
288
289 TEST_F(EWK2ViewTest, ewk_view_navigation)
290 {
291     std::unique_ptr<EWK2UnitTestServer> httpServer = std::make_unique<EWK2UnitTestServer>();
292     httpServer->run(serverCallbackNavigation);
293
294     // Visit Page1
295     ASSERT_TRUE(loadUrlSync(httpServer->getURLForPath("/Page1").data()));
296     ASSERT_STREQ("Page1", ewk_view_title_get(webView()));
297     ASSERT_FALSE(ewk_view_back_possible(webView()));
298     ASSERT_FALSE(ewk_view_forward_possible(webView()));
299
300     // Visit Page2
301     ASSERT_TRUE(loadUrlSync(httpServer->getURLForPath("/Page2").data()));
302     ASSERT_STREQ("Page2", ewk_view_title_get(webView()));
303     ASSERT_TRUE(ewk_view_back_possible(webView()));
304     ASSERT_FALSE(ewk_view_forward_possible(webView()));
305
306     // Go back to Page1
307     ewk_view_back(webView());
308     ASSERT_TRUE(waitUntilTitleChangedTo("Page1"));
309     ASSERT_STREQ("Page1", ewk_view_title_get(webView()));
310     ASSERT_FALSE(ewk_view_back_possible(webView()));
311     ASSERT_TRUE(ewk_view_forward_possible(webView()));
312
313     // Go forward to Page2
314     ewk_view_forward(webView());
315     ASSERT_TRUE(waitUntilTitleChangedTo("Page2"));
316     ASSERT_STREQ("Page2", ewk_view_title_get(webView()));
317     ASSERT_TRUE(ewk_view_back_possible(webView()));
318     ASSERT_FALSE(ewk_view_forward_possible(webView()));
319
320     // Visit Page3
321     ewk_view_url_set(webView(), httpServer->getURLForPath("/Page3").data());
322     ASSERT_TRUE(waitUntilTitleChangedTo("Page3"));
323     ASSERT_STREQ("Page3", ewk_view_title_get(webView()));
324     ASSERT_TRUE(ewk_view_back_possible(webView()));
325     ASSERT_FALSE(ewk_view_forward_possible(webView()));
326
327     Ewk_Back_Forward_List* list = ewk_view_back_forward_list_get(webView());
328     ASSERT_EQ(3, ewk_back_forward_list_count(list));
329
330     // Navigate to Page1
331     ewk_view_navigate_to(webView(), ewk_back_forward_list_item_at_index_get(list, -2));
332     ASSERT_TRUE(waitUntilTitleChangedTo("Page1"));
333     ASSERT_STREQ("Page1", ewk_view_title_get(webView()));
334
335     // Navigate to Page3
336     ewk_view_navigate_to(webView(), ewk_back_forward_list_item_at_index_get(list, 2));
337     ASSERT_TRUE(waitUntilTitleChangedTo("Page3"));
338     ASSERT_STREQ("Page3", ewk_view_title_get(webView()));
339 }
340
341 TEST_F(EWK2ViewTest, ewk_view_custom_encoding)
342 {
343     ASSERT_FALSE(ewk_view_custom_encoding_get(webView()));
344     ASSERT_TRUE(ewk_view_custom_encoding_set(webView(), "UTF-8"));
345     ASSERT_STREQ("UTF-8", ewk_view_custom_encoding_get(webView()));
346     // Set the default charset.
347     ASSERT_TRUE(ewk_view_custom_encoding_set(webView(), 0));
348     ASSERT_FALSE(ewk_view_custom_encoding_get(webView()));
349 }
350
351 TEST_F(EWK2ViewTest, ewk_view_form_submission_request)
352 {
353     const char* formHTML =
354         "<html><head><script type='text/javascript'>function submitForm() { document.getElementById('myform').submit(); }</script></head>"
355         "<body onload='submitForm()'>"
356         " <form id='myform' action='#'>"
357         "  <input type='text' name='text1' value='value1'>"
358         "  <input type='text' name='text2' value='value2'>"
359         "  <input type='password' name='password' value='secret'>"
360         "  <textarea cols='5' rows='5' name='textarea'>Text</textarea>"
361         "  <input type='hidden' name='hidden1' value='hidden1'>"
362         "  <input type='submit' value='Submit'>"
363         " </form>"
364         "</body></html>";
365
366     ewk_view_html_string_load(webView(), formHTML, "file:///", 0);
367     bool handled = false;
368     evas_object_smart_callback_add(webView(), "form,submission,request", onFormAboutToBeSubmitted, &handled);
369     ASSERT_TRUE(waitUntilTrue(handled));
370     evas_object_smart_callback_del(webView(), "form,submission,request", onFormAboutToBeSubmitted);
371 }
372
373 TEST_F(EWK2ViewTest, ewk_view_settings_get)
374 {
375     Ewk_Settings* settings = ewk_view_settings_get(webView());
376     ASSERT_TRUE(settings);
377     ASSERT_EQ(settings, ewk_view_settings_get(webView()));
378 }
379
380 TEST_F(EWK2ViewTest, ewk_view_theme_set)
381 {
382     const char* buttonHTML = "<html><body><input type='button' id='btn'>"
383         "<script>document.title=document.getElementById('btn').clientWidth;</script>"
384         "</body></html>";
385
386     ewk_view_html_string_load(webView(), buttonHTML, "file:///", 0);
387     EXPECT_TRUE(waitUntilTitleChangedTo("30")); // button of default theme has 30px as padding (15 to -16)
388
389     ewk_view_theme_set(webView(), environment->pathForResource("it_does_not_exist.edj").data());
390     ewk_view_html_string_load(webView(), buttonHTML, "file:///", 0);
391     EXPECT_TRUE(waitUntilTitleChangedTo("30")); // the result should be same as default theme
392
393     ewk_view_theme_set(webView(), environment->pathForResource("empty_theme.edj").data());
394     ewk_view_html_string_load(webView(), buttonHTML, "file:///", 0);
395     EXPECT_TRUE(waitUntilTitleChangedTo("30")); // the result should be same as default theme
396
397     ewk_view_theme_set(webView(), environment->pathForTheme("big_button_theme.edj").data());
398     ewk_view_html_string_load(webView(), buttonHTML, "file:///", 0);
399     EXPECT_TRUE(waitUntilTitleChangedTo("299")); // button of big button theme has 299px as padding (15 to -285)
400 }
401
402 TEST_F(EWK2ViewTest, ewk_view_mouse_events_enabled)
403 {
404     ASSERT_TRUE(ewk_view_mouse_events_enabled_set(webView(), EINA_TRUE));
405     ASSERT_TRUE(ewk_view_mouse_events_enabled_get(webView()));
406
407     ASSERT_TRUE(ewk_view_mouse_events_enabled_set(webView(), 2));
408     ASSERT_TRUE(ewk_view_mouse_events_enabled_get(webView()));
409
410     ASSERT_TRUE(ewk_view_mouse_events_enabled_set(webView(), EINA_FALSE));
411     ASSERT_FALSE(ewk_view_mouse_events_enabled_get(webView()));
412 }
413
414 TEST_F(EWK2ViewTest, ewk_view_full_screen_enter)
415 {
416     const char fullscreenHTML[] =
417         "<!doctype html><head><script>function makeFullScreen(){"
418         "var div = document.getElementById(\"fullscreen\");"
419         "div.webkitRequestFullScreen();"
420         "document.title = \"fullscreen entered\";"
421         "}</script></head>"
422         "<body><div id=\"fullscreen\" style=\"width:100px; height:100px\" onclick=\"makeFullScreen()\"></div></body>";
423
424     ewkViewClass()->fullscreen_enter = fullScreenCallback;
425
426     ewk_view_html_string_load(webView(), fullscreenHTML, "file:///", 0);
427     ASSERT_TRUE(waitUntilLoadFinished());
428     mouseClick(50, 50);
429     ASSERT_TRUE(waitUntilTitleChangedTo("fullscreen entered"));
430     ASSERT_TRUE(fullScreenCallbackCalled);
431 }
432
433 TEST_F(EWK2ViewTest, ewk_view_full_screen_exit)
434 {
435     const char fullscreenHTML[] =
436         "<!doctype html><head><script>function makeFullScreenAndExit(){"
437         "var div = document.getElementById(\"fullscreen\");"
438         "div.webkitRequestFullScreen();"
439         "document.webkitCancelFullScreen();"
440         "document.title = \"fullscreen exited\";"
441         "}</script></head>"
442         "<body><div id=\"fullscreen\" style=\"width:100px; height:100px\" onclick=\"makeFullScreenAndExit()\"></div></body>";
443
444     ewkViewClass()->fullscreen_exit = fullScreenExitCallback;
445
446     ewk_view_html_string_load(webView(), fullscreenHTML, "file:///", 0);
447     ASSERT_TRUE(waitUntilLoadFinished());
448     mouseClick(50, 50);
449     ASSERT_TRUE(waitUntilTitleChangedTo("fullscreen exited"));
450     ASSERT_TRUE(fullScreenCallbackCalled);
451 }
452
453 TEST_F(EWK2ViewTest, ewk_view_cancel_full_screen_request)
454 {
455     // FullScreenmanager should skip cancel fullscreen request if fullscreen
456     // mode was not set using FullScreen API.
457     ASSERT_FALSE(ewk_view_fullscreen_exit(webView()));
458 }
459
460 TEST_F(EWK2ViewTest, ewk_view_same_page_navigation)
461 {
462     // Tests that same page navigation updates the page URL.
463     String testUrl = environment->urlForResource("same_page_navigation.html").data();
464     ASSERT_TRUE(loadUrlSync(testUrl.utf8().data()));
465     ASSERT_STREQ(testUrl.utf8().data(), ewk_view_url_get(webView()));
466     mouseClick(50, 50);
467     testUrl = testUrl + '#';
468     ASSERT_TRUE(waitUntilURLChangedTo(testUrl.utf8().data()));
469 }
470
471 TEST_F(EWK2ViewTest, ewk_view_title_changed)
472 {
473     const char* titleChangedHTML =
474         "<!doctype html><head><title>Title before changed</title></head>"
475         "<body onload=\"document.title='Title after changed';\"></body>";
476     ewk_view_html_string_load(webView(), titleChangedHTML, 0, 0);
477     EXPECT_TRUE(waitUntilTitleChangedTo("Title after changed"));
478     EXPECT_STREQ("Title after changed", ewk_view_title_get(webView()));
479
480     titleChangedHTML =
481         "<!doctype html><head><title>Title before changed</title></head>"
482         "<body onload=\"document.title='';\"></body>";
483     ewk_view_html_string_load(webView(), titleChangedHTML, 0, 0);
484     EXPECT_TRUE(waitUntilTitleChangedTo(""));
485     EXPECT_STREQ("", ewk_view_title_get(webView()));
486
487     titleChangedHTML =
488         "<!doctype html><head><title>Title before changed</title></head>"
489         "<body onload=\"document.title=null;\"></body>";
490     ewk_view_html_string_load(webView(), titleChangedHTML, 0, 0);
491     EXPECT_TRUE(waitUntilTitleChangedTo(""));
492     EXPECT_STREQ("", ewk_view_title_get(webView()));
493 }
494
495 TEST_F(EWK2ViewTest, ewk_view_run_javascript_alert)
496 {
497     ewkViewClass()->run_javascript_alert = checkAlert;
498
499     const char* alertHTML = "<!doctype html><body onload=\"alert('Alert message');\"></body>";
500     alertCallbackData.expectedMessage = "Alert message";
501     alertCallbackData.called = false;
502     ewk_view_html_string_load(webView(), alertHTML, 0, 0);
503     EXPECT_TRUE(waitUntilLoadFinished());
504     EXPECT_TRUE(alertCallbackData.called);
505
506     alertHTML = "<!doctype html><body onload=\"alert('');\"></body>";
507     alertCallbackData.expectedMessage = "";
508     alertCallbackData.called = false;
509     ewk_view_html_string_load(webView(), alertHTML, 0, 0);
510     EXPECT_TRUE(waitUntilLoadFinished());
511     EXPECT_TRUE(alertCallbackData.called);
512
513     alertHTML = "<!doctype html><body onload=\"alert(null);\"></body>";
514     alertCallbackData.expectedMessage = "null";
515     alertCallbackData.called = false;
516     ewk_view_html_string_load(webView(), alertHTML, 0, 0);
517     EXPECT_TRUE(waitUntilLoadFinished());
518     EXPECT_TRUE(alertCallbackData.called);
519
520     alertHTML = "<!doctype html><body onload=\"alert();\"></body>";
521     alertCallbackData.expectedMessage = "undefined";
522     alertCallbackData.called = false;
523     ewk_view_html_string_load(webView(), alertHTML, 0, 0);
524     EXPECT_TRUE(waitUntilLoadFinished());
525     EXPECT_TRUE(alertCallbackData.called);
526
527     ewkViewClass()->run_javascript_alert = 0;
528
529     alertCallbackData.called = false;
530     ewk_view_html_string_load(webView(), alertHTML, 0, 0);
531     EXPECT_TRUE(waitUntilLoadFinished());
532     EXPECT_FALSE(alertCallbackData.called);
533 }
534
535 TEST_F(EWK2ViewTest, ewk_view_run_javascript_confirm)
536 {
537     ewkViewClass()->run_javascript_confirm = checkConfirm;
538
539     const char* confirmHTML = "<!doctype html><body onload=\"document.title = confirm('Confirm message');\"></body>";
540     confirmCallbackData.expectedMessage = "Confirm message";
541     confirmCallbackData.result = true;
542     confirmCallbackData.called = false;
543     ewk_view_html_string_load(webView(), confirmHTML, 0, 0);
544     EXPECT_TRUE(waitUntilTitleChangedTo("true"));
545     EXPECT_STREQ("true", ewk_view_title_get(webView()));
546     EXPECT_TRUE(confirmCallbackData.called);
547
548     confirmCallbackData.expectedMessage = "Confirm message";
549     confirmCallbackData.result = false;
550     confirmCallbackData.called = false;
551     ewk_view_html_string_load(webView(), confirmHTML, 0, 0);
552     EXPECT_TRUE(waitUntilTitleChangedTo("false"));
553     EXPECT_STREQ("false", ewk_view_title_get(webView()));
554     EXPECT_TRUE(confirmCallbackData.called);
555
556     confirmHTML = "<!doctype html><body onload=\"document.title = confirm('');\"></body>";
557     confirmCallbackData.expectedMessage = "";
558     confirmCallbackData.result = true;
559     confirmCallbackData.called = false;
560     ewk_view_html_string_load(webView(), confirmHTML, 0, 0);
561     EXPECT_TRUE(waitUntilTitleChangedTo("true"));
562     EXPECT_STREQ("true", ewk_view_title_get(webView()));
563     EXPECT_TRUE(confirmCallbackData.called);
564
565     confirmHTML = "<!doctype html><body onload=\"document.title = confirm(null);\"></body>";
566     confirmCallbackData.expectedMessage = "null";
567     confirmCallbackData.result = true;
568     confirmCallbackData.called = false;
569     ewk_view_html_string_load(webView(), confirmHTML, 0, 0);
570     EXPECT_TRUE(waitUntilTitleChangedTo("true"));
571     EXPECT_STREQ("true", ewk_view_title_get(webView()));
572     EXPECT_TRUE(confirmCallbackData.called);
573
574     confirmHTML = "<!doctype html><body onload=\"document.title = confirm();\"></body>";
575     confirmCallbackData.expectedMessage = "undefined";
576     confirmCallbackData.result = true;
577     confirmCallbackData.called = false;
578     ewk_view_html_string_load(webView(), confirmHTML, 0, 0);
579     EXPECT_TRUE(waitUntilTitleChangedTo("true"));
580     EXPECT_STREQ("true", ewk_view_title_get(webView()));
581     EXPECT_TRUE(confirmCallbackData.called);
582
583     ewkViewClass()->run_javascript_confirm = 0;
584
585     confirmCallbackData.called = false;
586     ewk_view_html_string_load(webView(), confirmHTML, 0, 0);
587     EXPECT_TRUE(waitUntilTitleChangedTo("false"));
588     EXPECT_STREQ("false", ewk_view_title_get(webView()));
589     EXPECT_FALSE(confirmCallbackData.called);
590 }
591
592 TEST_F(EWK2ViewTest, ewk_view_run_javascript_prompt)
593 {
594     static const char promptMessage[] = "Prompt message";
595     static const char promptResult[] = "Prompt result";
596
597     ewkViewClass()->run_javascript_prompt = checkPrompt;
598
599     const char* promptHTML = "<!doctype html><body onload=\"document.title = prompt('Prompt message', 'Prompt default value');\"></body>";
600     promptCallbackData.expectedMessage = promptMessage;
601     promptCallbackData.expectedDefaultValue = "Prompt default value";
602     promptCallbackData.result = promptResult;
603     promptCallbackData.called = false;
604     ewk_view_html_string_load(webView(), promptHTML, 0, 0);
605     EXPECT_TRUE(waitUntilTitleChangedTo(promptResult));
606     EXPECT_STREQ(promptResult, ewk_view_title_get(webView()));
607     EXPECT_TRUE(promptCallbackData.called);
608
609     promptHTML = "<!doctype html><body onload=\"document.title = prompt('Prompt message', '');\"></body>";
610     promptCallbackData.expectedMessage = promptMessage;
611     promptCallbackData.expectedDefaultValue = "";
612     promptCallbackData.result = promptResult;
613     promptCallbackData.called = false;
614     ewk_view_html_string_load(webView(), promptHTML, 0, 0);
615     EXPECT_TRUE(waitUntilTitleChangedTo(promptResult));
616     EXPECT_STREQ(promptResult, ewk_view_title_get(webView()));
617     EXPECT_TRUE(promptCallbackData.called);
618
619     promptHTML = "<!doctype html><body onload=\"document.title = prompt('Prompt message');\"></body>";
620     promptCallbackData.expectedMessage = promptMessage;
621     promptCallbackData.expectedDefaultValue = "";
622     promptCallbackData.result = promptResult;
623     promptCallbackData.called = false;
624     ewk_view_html_string_load(webView(), promptHTML, 0, 0);
625     EXPECT_TRUE(waitUntilTitleChangedTo(promptResult));
626     EXPECT_STREQ(promptResult, ewk_view_title_get(webView()));
627     EXPECT_TRUE(promptCallbackData.called);
628
629     promptHTML = "<!doctype html><body onload=\"document.title = prompt('');\"></body>";
630     promptCallbackData.expectedMessage = "";
631     promptCallbackData.expectedDefaultValue = "";
632     promptCallbackData.result = promptResult;
633     promptCallbackData.called = false;
634     ewk_view_html_string_load(webView(), promptHTML, 0, 0);
635     EXPECT_TRUE(waitUntilTitleChangedTo(promptResult));
636     EXPECT_STREQ(promptResult, ewk_view_title_get(webView()));
637     EXPECT_TRUE(promptCallbackData.called);
638
639     promptHTML = "<!doctype html><body onload=\"document.title = prompt();\"></body>";
640     promptCallbackData.expectedMessage = "undefined";
641     promptCallbackData.expectedDefaultValue = "";
642     promptCallbackData.result = promptResult;
643     promptCallbackData.called = false;
644     ewk_view_html_string_load(webView(), promptHTML, 0, 0);
645     EXPECT_TRUE(waitUntilTitleChangedTo(promptResult));
646     EXPECT_STREQ(promptResult, ewk_view_title_get(webView()));
647     EXPECT_TRUE(promptCallbackData.called);
648
649     promptHTML = "<html><head><title>Default title</title></head>"
650                  "<body onload=\"var promptResult = prompt('Prompt message');"
651                  "if (promptResult == null) document.title='null';"
652                  "else document.title = promptResult;\"></body></html>";
653     promptCallbackData.expectedMessage = promptMessage;
654     promptCallbackData.expectedDefaultValue = "";
655     promptCallbackData.result = "";
656     promptCallbackData.called = false;
657     ewk_view_html_string_load(webView(), promptHTML, 0, 0);
658     EXPECT_TRUE(waitUntilTitleChangedTo(""));
659     EXPECT_STREQ("", ewk_view_title_get(webView()));
660     EXPECT_TRUE(promptCallbackData.called);
661
662     promptCallbackData.expectedMessage = promptMessage;
663     promptCallbackData.expectedDefaultValue = "";
664     promptCallbackData.result = 0;
665     promptCallbackData.called = false;
666     ewk_view_html_string_load(webView(), promptHTML, 0, 0);
667     EXPECT_TRUE(waitUntilTitleChangedTo("null"));
668     EXPECT_STREQ("null", ewk_view_title_get(webView()));
669     EXPECT_TRUE(promptCallbackData.called);
670
671     ewkViewClass()->run_javascript_prompt = 0;
672
673     promptCallbackData.called = false;
674     ewk_view_html_string_load(webView(), promptHTML, 0, 0);
675     EXPECT_TRUE(waitUntilTitleChangedTo("null"));
676     EXPECT_STREQ("null", ewk_view_title_get(webView()));
677     EXPECT_FALSE(promptCallbackData.called);
678 }
679
680 TEST_F(EWK2ViewTest, ewk_view_context_get)
681 {
682     Ewk_Context* context = ewk_view_context_get(webView());
683     ASSERT_TRUE(context);
684     ASSERT_EQ(context, ewk_view_context_get(webView()));
685 }
686
687 TEST_F(EWK2ViewTest, ewk_view_page_group_get)
688 {
689     Ewk_Page_Group* pageGroup = ewk_view_page_group_get(webView());
690     ASSERT_TRUE(pageGroup);
691     ASSERT_EQ(pageGroup, ewk_view_page_group_get(webView()));
692 }
693
694 TEST_F(EWK2ViewTest, ewk_view_feed_touch_event)
695 {
696     Eina_List* points = 0;
697     Ewk_Touch_Point point1 = { 0, 0, 0, EVAS_TOUCH_POINT_DOWN };
698     Ewk_Touch_Point point2 = { 1, 0, 0, EVAS_TOUCH_POINT_DOWN };
699     points = eina_list_append(points, &point1);
700     points = eina_list_append(points, &point2);
701     ASSERT_TRUE(ewk_view_feed_touch_event(webView(), EWK_TOUCH_START, points, evas_key_modifier_get(evas_object_evas_get(webView()))));
702
703     point1.state = EVAS_TOUCH_POINT_STILL;
704     point2.x = 100;
705     point2.y = 100;
706     point2.state = EVAS_TOUCH_POINT_MOVE;
707     ASSERT_TRUE(ewk_view_feed_touch_event(webView(), EWK_TOUCH_MOVE, points, evas_key_modifier_get(evas_object_evas_get(webView()))));
708
709     point2.state = EVAS_TOUCH_POINT_UP;
710     ASSERT_TRUE(ewk_view_feed_touch_event(webView(), EWK_TOUCH_END, points, evas_key_modifier_get(evas_object_evas_get(webView()))));
711     points = eina_list_remove(points, &point2);
712
713     point1.state = EVAS_TOUCH_POINT_CANCEL;
714     ASSERT_TRUE(ewk_view_feed_touch_event(webView(), EWK_TOUCH_CANCEL, points, evas_key_modifier_get(evas_object_evas_get(webView()))));
715     points = eina_list_remove(points, &point1);
716
717     eina_list_free(points);
718 }
719
720 TEST_F(EWK2ViewTest, ewk_view_text_find)
721 {
722     const char textFindHTML[] =
723         "<!DOCTYPE html>"
724         "<body>"
725         "apple apple apple banana banana coconut"
726         "</body>";
727     ewk_view_html_string_load(webView(), textFindHTML, 0, 0);
728     waitUntilLoadFinished();
729
730     int matchCount = -1;
731     evas_object_smart_callback_add(webView(), "text,found", onTextFound, &matchCount);
732
733     ewk_view_text_find(webView(), "apple", EWK_FIND_OPTIONS_SHOW_OVERLAY, 100);
734     while (matchCount < 0)
735         ecore_main_loop_iterate();
736     EXPECT_EQ(3, matchCount);
737
738     matchCount = -1;
739     ewk_view_text_find(webView(), "mango", EWK_FIND_OPTIONS_SHOW_OVERLAY, 100);
740     while (matchCount < 0)
741         ecore_main_loop_iterate();
742     EXPECT_EQ(0, matchCount);
743
744     evas_object_smart_callback_del(webView(), "text,found", onTextFound);
745 }
746
747 TEST_F(EWK2ViewTest, ewk_view_text_matches_count)
748 {
749     const char textFindHTML[] =
750         "<!DOCTYPE html>"
751         "<body>"
752         "apple Apple apple apple banana bananaApple banana coconut"
753         "</body>";
754     ewk_view_html_string_load(webView(), textFindHTML, 0, 0);
755     waitUntilLoadFinished();
756
757     int matchCount = -1;
758     evas_object_smart_callback_add(webView(), "text,found", onTextFound, &matchCount);
759
760     ewk_view_text_matches_count(webView(), "apple", EWK_FIND_OPTIONS_NONE, 100);
761     while (matchCount < 0)
762         ecore_main_loop_iterate();
763     EXPECT_EQ(3, matchCount);
764
765     matchCount = -1;
766     ewk_view_text_matches_count(webView(), "apple", EWK_FIND_OPTIONS_CASE_INSENSITIVE, 100);
767     while (matchCount < 0)
768         ecore_main_loop_iterate();
769     EXPECT_EQ(5, matchCount);
770
771     matchCount = -1;
772     ewk_view_text_matches_count(webView(), "Apple", EWK_FIND_OPTIONS_AT_WORD_STARTS, 100);
773     while (matchCount < 0)
774         ecore_main_loop_iterate();
775     EXPECT_EQ(1, matchCount);
776
777     matchCount = -1;
778     ewk_view_text_matches_count(webView(), "Apple", EWK_FIND_OPTIONS_TREAT_MEDIAL_CAPITAL_AS_WORD_START, 100);
779     while (matchCount < 0)
780         ecore_main_loop_iterate();
781     EXPECT_EQ(2, matchCount);
782
783     matchCount = -1;
784     ewk_view_text_matches_count(webView(), "mango", EWK_FIND_OPTIONS_NONE, 100);
785     while (matchCount < 0)
786         ecore_main_loop_iterate();
787     EXPECT_EQ(0, matchCount);
788
789     // If we have more matches than allowed, -1 is returned as a matched count.
790     matchCount = -2;
791     ewk_view_text_matches_count(webView(), "apple", EWK_FIND_OPTIONS_NONE, 2);
792     while (matchCount < -1)
793         ecore_main_loop_iterate();
794     EXPECT_EQ(-1, matchCount);
795
796     evas_object_smart_callback_del(webView(), "text,found", onTextFound);
797 }
798
799 TEST_F(EWK2ViewTest, ewk_view_touch_events_enabled)
800 {
801     ASSERT_FALSE(ewk_view_touch_events_enabled_get(webView()));
802
803     ASSERT_TRUE(ewk_view_touch_events_enabled_set(webView(), true));
804     ASSERT_TRUE(ewk_view_touch_events_enabled_get(webView()));
805
806     ASSERT_TRUE(ewk_view_touch_events_enabled_set(webView(), 2));
807     ASSERT_TRUE(ewk_view_touch_events_enabled_get(webView()));
808
809     const char* touchHTML =
810         "<!doctype html><body><div style=\"width:100px; height:100px;\" "
811         "ontouchstart=\"document.title='touchstarted' + event.touches.length;\" "
812         "ontouchmove=\"document.title='touchmoved' + event.touches.length;\" "
813         "ontouchend=\"document.title='touchended' + event.touches.length;\">"
814         "</div></body>";
815
816     ewk_view_html_string_load(webView(), touchHTML, "file:///", 0);
817     ASSERT_TRUE(waitUntilLoadFinished());
818
819     mouseDown(10, 10);
820     ASSERT_TRUE(waitUntilTitleChangedTo("touchstarted1"));
821
822     multiDown(1, 30, 30);
823     ASSERT_TRUE(waitUntilTitleChangedTo("touchstarted2"));
824
825     multiMove(1, 40, 40);
826     ASSERT_TRUE(waitUntilTitleChangedTo("touchmoved2"));
827
828     multiUp(1, 40, 40);
829     ASSERT_TRUE(waitUntilTitleChangedTo("touchended1"));
830
831     mouseMove(20, 20);
832     ASSERT_TRUE(waitUntilTitleChangedTo("touchmoved1"));
833
834     mouseUp(20, 20);
835     ASSERT_TRUE(waitUntilTitleChangedTo("touchended0"));
836
837     ASSERT_TRUE(ewk_view_touch_events_enabled_set(webView(), false));
838     ASSERT_FALSE(ewk_view_touch_events_enabled_get(webView()));
839 }
840
841 TEST_F(EWK2ViewTest, window_move_resize)
842 {
843     int x, y, width, height;
844     Ecore_Evas* ee = ecore_evas_ecore_evas_get(evas_object_evas_get(webView()));
845     ecore_evas_geometry_get(ee, 0, 0, &width, &height);
846
847     EXPECT_EQ(800, width);
848     EXPECT_EQ(600, height);
849
850     ewk_view_url_set(webView(), environment->urlForResource("window_move_resize.html").data());
851     ASSERT_TRUE(waitUntilTitleChangedTo("Moved and resized"));
852
853     // Check that the window has been moved and resized.
854     ecore_evas_request_geometry_get(ee, &x, &y, &width, &height);
855     EXPECT_EQ(150, x);
856     EXPECT_EQ(200, y);
857     EXPECT_EQ(200, width);
858     EXPECT_EQ(100, height);
859 }
860
861 TEST_F(EWK2ViewTest, ewk_view_inspector)
862 {
863 #if ENABLE(INSPECTOR)
864     ASSERT_TRUE(ewk_view_inspector_show(webView()));
865     ASSERT_TRUE(ewk_view_inspector_close(webView()));
866 #else
867     ASSERT_FALSE(ewk_view_inspector_show(webView()));
868     ASSERT_FALSE(ewk_view_inspector_close(webView()));
869 #endif
870 }
871
872 TEST_F(EWK2ViewTest, DISABLED_ewk_view_scale)
873 {
874     ASSERT_TRUE(loadUrlSync(environment->defaultTestPageUrl()));
875
876     // Default scale value is 1.0.
877     ASSERT_FLOAT_EQ(1, ewk_view_scale_get(webView()));
878
879     ASSERT_TRUE(ewk_view_scale_set(webView(), 1.2, 0, 0));
880     // Reload page to check the page scale value.
881     ASSERT_TRUE(loadUrlSync(environment->defaultTestPageUrl()));
882     ASSERT_FLOAT_EQ(1.2, ewk_view_scale_get(webView()));
883
884     ASSERT_TRUE(ewk_view_scale_set(webView(), 1.5, 0, 0));
885     ASSERT_TRUE(loadUrlSync(environment->defaultTestPageUrl()));
886     ASSERT_FLOAT_EQ(1.5, ewk_view_scale_get(webView()));
887
888     ASSERT_TRUE(ewk_view_scale_set(webView(), 1, 0, 0));
889     ASSERT_TRUE(loadUrlSync(environment->defaultTestPageUrl()));
890     ASSERT_FLOAT_EQ(1, ewk_view_scale_get(webView()));
891 }
892
893 TEST_F(EWK2ViewTest, ewk_view_pagination)
894 {
895     ASSERT_TRUE(loadUrlSync(environment->defaultTestPageUrl()));
896
897     // Default pagination value is EWK_PAGINATION_MODE_UNPAGINATED
898     ASSERT_EQ(EWK_PAGINATION_MODE_UNPAGINATED, ewk_view_pagination_mode_get(webView()));
899
900     ASSERT_TRUE(ewk_view_pagination_mode_set(webView(), EWK_PAGINATION_MODE_LEFT_TO_RIGHT));
901     // Reload page to check the pagination mode.
902     ASSERT_TRUE(loadUrlSync(environment->defaultTestPageUrl()));
903     ASSERT_EQ(EWK_PAGINATION_MODE_LEFT_TO_RIGHT, ewk_view_pagination_mode_get(webView()));
904
905     ASSERT_TRUE(ewk_view_pagination_mode_set(webView(), EWK_PAGINATION_MODE_RIGHT_TO_LEFT));
906     ASSERT_TRUE(loadUrlSync(environment->defaultTestPageUrl()));
907     ASSERT_EQ(EWK_PAGINATION_MODE_RIGHT_TO_LEFT, ewk_view_pagination_mode_get(webView()));
908
909     ASSERT_TRUE(ewk_view_pagination_mode_set(webView(), EWK_PAGINATION_MODE_TOP_TO_BOTTOM));
910     ASSERT_TRUE(loadUrlSync(environment->defaultTestPageUrl()));
911     ASSERT_EQ(EWK_PAGINATION_MODE_TOP_TO_BOTTOM, ewk_view_pagination_mode_get(webView()));
912
913     ASSERT_TRUE(ewk_view_pagination_mode_set(webView(),  EWK_PAGINATION_MODE_BOTTOM_TO_TOP));
914     ASSERT_TRUE(loadUrlSync(environment->defaultTestPageUrl()));
915     ASSERT_EQ(EWK_PAGINATION_MODE_BOTTOM_TO_TOP, ewk_view_pagination_mode_get(webView()));
916
917     ASSERT_TRUE(ewk_view_pagination_mode_set(webView(), EWK_PAGINATION_MODE_UNPAGINATED));
918     ASSERT_TRUE(loadUrlSync(environment->defaultTestPageUrl()));
919     ASSERT_EQ(EWK_PAGINATION_MODE_UNPAGINATED, ewk_view_pagination_mode_get(webView()));
920 }
921
922 TEST_F(EWK2ViewTest, ewk_context_vibration_client_callbacks_set)
923 {
924     VibrationCbData data = { false, false, false, 0, 5000 };
925     evas_object_smart_callback_add(webView(), "vibrate", onVibrate, &data);
926     evas_object_smart_callback_add(webView(), "cancel,vibration", onCancelVibration, &data);
927
928     // Vibrate for 5 seconds.
929     loadVibrationHTMLString(webView(), "5000", &data);
930     waitUntilTrue(data.testFinished);
931     ASSERT_TRUE(data.didReceiveVibrate && !data.didReceiveCancelVibration);
932
933     // Cancel any existing vibrations.
934     loadVibrationHTMLString(webView(), "0", &data);
935     waitUntilTrue(data.testFinished);
936     ASSERT_TRUE(!data.didReceiveVibrate && data.didReceiveCancelVibration);
937
938     // This case the pattern will cause the device to vibrate for 200 ms, be still for 100 ms, and then vibrate for 5000 ms.
939     loadVibrationHTMLString(webView(), "[200, 100, 5000]", &data);
940     waitUntilTrue(data.testFinished);
941     ASSERT_EQ(2, data.vibrateCalledCount);
942     ASSERT_TRUE(data.didReceiveVibrate && !data.didReceiveCancelVibration);
943
944     // Cancel outstanding vibration pattern.
945     loadVibrationHTMLString(webView(), "[0]", &data);
946     waitUntilTrue(data.testFinished);
947     ASSERT_TRUE(!data.didReceiveVibrate && data.didReceiveCancelVibration);
948
949     // Check that vibration works properly by continuous request.
950     data.expectedVibrationTime = 5;
951     loadVibrationHTMLString(webView(), "5", &data);
952     waitUntilTrue(data.testFinished);
953     ASSERT_TRUE(data.didReceiveVibrate && !data.didReceiveCancelVibration);
954
955     loadVibrationHTMLString(webView(), "5", &data);
956     waitUntilTrue(data.testFinished);
957     ASSERT_EQ(1, data.vibrateCalledCount);
958     ASSERT_TRUE(data.didReceiveVibrate && !data.didReceiveCancelVibration);
959
960     // Stop listening for vibration events, by calling the function with null for the callbacks.
961     evas_object_smart_callback_del(webView(), "vibrate", onVibrate);
962     evas_object_smart_callback_del(webView(), "cancel,vibration", onCancelVibration);
963 }
964
965 TEST_F(EWK2ViewTest, ewk_view_contents_size_changed)
966 {
967     const char contentsSizeHTMLPortrait[] =
968         "<!DOCTYPE html>"
969         "<body style=\"margin:0px;width:2000px;height:3000px\"></body>";
970     const char contentsSizeHTMLLandscape[] =
971         "<!DOCTYPE html>"
972         "<body style=\"margin:0px;width:3000px;height:2000px\"></body>";
973
974     bool sizeChanged = false;
975     evas_object_smart_callback_add(webView(), "contents,size,changed", onContentsSizeChangedPortrait, &sizeChanged);
976     ewk_view_html_string_load(webView(), contentsSizeHTMLPortrait, 0, 0);
977     waitUntilTrue(sizeChanged);
978     evas_object_smart_callback_del(webView(), "contents,size,changed", onContentsSizeChangedPortrait);
979
980     evas_object_smart_callback_add(webView(), "contents,size,changed", onContentsSizeChangedLandscape, &sizeChanged);
981     ewk_view_device_pixel_ratio_set(webView(), 2);
982     ewk_view_html_string_load(webView(), contentsSizeHTMLLandscape, 0, 0);
983     sizeChanged = false;
984     waitUntilTrue(sizeChanged);
985     evas_object_smart_callback_del(webView(), "contents,size,changed", onContentsSizeChangedLandscape);
986
987     evas_object_smart_callback_add(webView(), "contents,size,changed", onContentsSizeChangedPortrait, &sizeChanged);
988     ewk_view_scale_set(webView(), 3, 0, 0);
989     ewk_view_html_string_load(webView(), contentsSizeHTMLPortrait, 0, 0);
990     sizeChanged = false;
991     waitUntilTrue(sizeChanged);
992
993     // Make sure we get signal after loaded the contents having same size with previous one.
994     sizeChanged = false;
995     ewk_view_html_string_load(webView(), contentsSizeHTMLPortrait, 0, 0);
996     waitUntilTrue(sizeChanged);
997
998     evas_object_smart_callback_del(webView(), "contents,size,changed", onContentsSizeChangedPortrait);
999 }
1000
1001 TEST_F(EWK2ViewTest, ewk_view_page_contents_get)
1002 {
1003     const char content[] = "<p>Simple HTML</p>";
1004     ewk_view_html_string_load(webView(), content, 0, 0);
1005     waitUntilLoadFinished();
1006
1007     ASSERT_TRUE(ewk_view_page_contents_get(webView(), EWK_PAGE_CONTENTS_TYPE_MHTML, PageContentsAsMHTMLCallback, 0));
1008     waitUntilTrue(obtainedPageContents);
1009
1010     obtainedPageContents = false;
1011     ASSERT_TRUE(ewk_view_page_contents_get(webView(), EWK_PAGE_CONTENTS_TYPE_STRING, PageContentsAsStringCallback, 0));
1012     waitUntilTrue(obtainedPageContents);
1013 }
1014
1015 TEST_F(EWK2ViewTest, ewk_view_user_agent)
1016 {
1017     const char* defaultUserAgent = eina_stringshare_add(ewk_view_user_agent_get(webView()));
1018     const char customUserAgent[] = "Foo";
1019
1020     ASSERT_TRUE(ewk_view_user_agent_set(webView(), customUserAgent));
1021     ASSERT_STREQ(customUserAgent, ewk_view_user_agent_get(webView()));
1022
1023     // Set the default user agent string.
1024     ASSERT_TRUE(ewk_view_user_agent_set(webView(), 0));
1025     ASSERT_STREQ(defaultUserAgent, ewk_view_user_agent_get(webView()));
1026     eina_stringshare_del(defaultUserAgent);
1027 }
1028
1029 static void scriptExecuteCallback(Evas_Object*, const char* returnValue, void* userData)
1030 {
1031     Eina_Strbuf* buffer = static_cast<Eina_Strbuf*>(userData);
1032     eina_strbuf_reset(buffer);
1033
1034     if (returnValue)
1035         eina_strbuf_append(buffer, returnValue);
1036
1037     scriptExecuteCallbackCalled = true;
1038 }
1039
1040 TEST_F(EWK2UnitTestBase, ewk_view_script_execute)
1041 {
1042     const char scriptExecuteHTML[] =
1043         "<!DOCTYPE html>"
1044         "<body>"
1045         "<p id=\"TestContent\">test content</p>"
1046         "</body>";
1047
1048     ewk_view_html_string_load(webView(), scriptExecuteHTML, 0, 0);
1049     ASSERT_TRUE(waitUntilLoadFinished());
1050
1051     Eina_Strbuf* result = eina_strbuf_new();
1052
1053     // 1. Get the innerHTML for "TestContent"
1054     const char getDataScript[] = "document.getElementById('TestContent').innerHTML";
1055
1056     scriptExecuteCallbackCalled = false;
1057     ASSERT_TRUE(ewk_view_script_execute(webView(), getDataScript, scriptExecuteCallback, static_cast<void*>(result)));
1058     waitUntilTrue(scriptExecuteCallbackCalled);
1059     ASSERT_STREQ("test content", eina_strbuf_string_get(result));
1060
1061     // 2. Change the innerHTML for "TestContent"
1062     const char changeDataScript[] =
1063     "document.getElementById('TestContent').innerHTML = \"test\";";
1064     ASSERT_TRUE(ewk_view_script_execute(webView(), changeDataScript, 0, 0));
1065
1066     // 3. Check the change of the innerHTML.
1067     eina_strbuf_reset(result);
1068     scriptExecuteCallbackCalled = false;
1069     ASSERT_TRUE(ewk_view_script_execute(webView(), getDataScript, scriptExecuteCallback, static_cast<void*>(result)));
1070     waitUntilTrue(scriptExecuteCallbackCalled);
1071     ASSERT_STREQ("test", eina_strbuf_string_get(result));
1072
1073     eina_strbuf_free(result);
1074
1075     ASSERT_FALSE(ewk_view_script_execute(webView(), 0, 0, 0));
1076 }
1077
1078 TEST_F(EWK2ViewTest, ewk_view_layout_fixed)
1079 {
1080     // Fixed layout is not used in webview as default.
1081     EXPECT_FALSE(ewk_view_layout_fixed_get(webView()));
1082
1083     EXPECT_TRUE(ewk_view_layout_fixed_set(webView(), true));
1084     EXPECT_TRUE(ewk_view_layout_fixed_get(webView()));
1085 }