[M120 Migration][MM] Support W3C EME
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / unittest / utc_blink_ewk_context_form_autofill_profile_utils.cpp
1 // Copyright 2014 Samsung Electronics. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "utc_blink_ewk_context_form_autofill_profile_utils.h"
6 #include "utc_blink_ewk_base.h"
7 #include "ewk_autofill_profile.h"
8 #include <sstream>
9 #include <stdio.h>
10 #include <iostream>
11
12 Ewk_Autofill_Profile* getTestEwkAutofillProfile() {
13   Ewk_Autofill_Profile* profile = ewk_autofill_profile_new();
14   if (NULL == profile)
15     return profile;
16   std::stringstream stream;
17   stream << TEST_AUTOFILL_PROFILE_ID;
18   std::string id = stream.str();
19   ewk_autofill_profile_data_set(profile, EWK_PROFILE_ID, id.c_str());
20   ewk_autofill_profile_data_set(profile, EWK_PROFILE_NAME, TEST_AUTOFILL_PROFILE_NAME);
21   ewk_autofill_profile_data_set(profile, EWK_PROFILE_COMPANY, TEST_AUTOFILL_PROFILE_COMPANY);
22   ewk_autofill_profile_data_set(profile, EWK_PROFILE_ADDRESS1, TEST_AUTOFILL_PROFILE_ADDRESS1);
23   ewk_autofill_profile_data_set(profile, EWK_PROFILE_ADDRESS2, TEST_AUTOFILL_PROFILE_ADDRESS2);
24   ewk_autofill_profile_data_set(profile, EWK_PROFILE_CITY_TOWN, TEST_AUTOFILL_PROFILE_CITY_TOWN);
25   ewk_autofill_profile_data_set(profile, EWK_PROFILE_STATE_PROVINCE_REGION, TEST_AUTOFILL_PROFILE_STATE_PROVINCE_REGION);
26   ewk_autofill_profile_data_set(profile, EWK_PROFILE_ZIPCODE, TEST_AUTOFILL_PROFILE_ZIPCODE);
27   ewk_autofill_profile_data_set(profile, EWK_PROFILE_COUNTRY, TEST_AUTOFILL_PROFILE_COUNTRY);
28   ewk_autofill_profile_data_set(profile, EWK_PROFILE_PHONE, TEST_AUTOFILL_PROFILE_PHONE);
29   ewk_autofill_profile_data_set(profile, EWK_PROFILE_EMAIL, TEST_AUTOFILL_PROFILE_EMAIL);
30   return profile;
31 }
32
33
34 bool checkOne(Ewk_Autofill_Profile* profileToCheck, const char* reference,
35               Ewk_Autofill_Profile_Data_Type kind, const char* errMessage) {
36   const char* ptr = ewk_autofill_profile_data_get(profileToCheck, kind);
37   if (NULL == ptr) {
38     utc_message("%s, expected: %s obtained: NULL\n", errMessage, reference);
39     return false;
40   } else {
41     utc_message("%s, expected: %s obtained: %s\n", errMessage, reference, ptr);
42   }
43   return (0 == strcmp(reference, ptr));
44 }
45
46 bool checkIfProfileContainsTestData(Ewk_Autofill_Profile* profileToCheck) {
47   if (NULL == profileToCheck) {
48     return false;
49   }
50   bool dataValid = true;
51   if (TEST_AUTOFILL_PROFILE_ID != ewk_autofill_profile_id_get(profileToCheck)) {
52     utc_message("profile ID check failed %i %i", TEST_AUTOFILL_PROFILE_ID, ewk_autofill_profile_id_get(profileToCheck));
53     dataValid = false;
54   }
55   dataValid = checkOne(profileToCheck, TEST_AUTOFILL_PROFILE_NAME, EWK_PROFILE_NAME, "name") && dataValid;
56   dataValid = checkOne(profileToCheck, TEST_AUTOFILL_PROFILE_COMPANY, EWK_PROFILE_COMPANY, "company") && dataValid;
57   dataValid = checkOne(profileToCheck, TEST_AUTOFILL_PROFILE_ADDRESS1, EWK_PROFILE_ADDRESS1, "address1") && dataValid;
58   dataValid = checkOne(profileToCheck, TEST_AUTOFILL_PROFILE_ADDRESS2, EWK_PROFILE_ADDRESS2, "address2") && dataValid;
59   dataValid = checkOne(profileToCheck, TEST_AUTOFILL_PROFILE_CITY_TOWN, EWK_PROFILE_CITY_TOWN, "city") && dataValid;
60   dataValid = checkOne(profileToCheck, TEST_AUTOFILL_PROFILE_STATE_PROVINCE_REGION, EWK_PROFILE_STATE_PROVINCE_REGION, "province") && dataValid;
61   dataValid = checkOne(profileToCheck, TEST_AUTOFILL_PROFILE_ZIPCODE, EWK_PROFILE_ZIPCODE, "zipcode") && dataValid;
62   dataValid = checkOne(profileToCheck, TEST_AUTOFILL_PROFILE_COUNTRY, EWK_PROFILE_COUNTRY, "country") && dataValid;
63   dataValid = checkOne(profileToCheck, TEST_AUTOFILL_PROFILE_PHONE, EWK_PROFILE_PHONE, "phone") && dataValid;
64   dataValid = checkOne(profileToCheck, TEST_AUTOFILL_PROFILE_EMAIL, EWK_PROFILE_EMAIL, "email") && dataValid;
65   return dataValid;
66 }
67
68 void utc_blink_ewk_context_form_autofill_profile_base::PostSetUp() {
69   EventLoopWait(3.0);
70   RemoveTestProfile();
71 }
72
73 void utc_blink_ewk_context_form_autofill_profile_base::PreTearDown() {
74   RemoveTestProfile();
75 }