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