[M120 Migration][MM] Support W3C EME
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / unittest / utc_blink_ewk_intercept_request_response_header_map_add_func.cpp
1 // Copyright 2016 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 <string>
6
7 #include "utc_blink_ewk_intercept_request_response_base.h"
8
9 class utc_blink_ewk_intercept_request_response_header_map_add
10     : public utc_blink_ewk_intercept_request_response_base {
11  protected:
12   utc_blink_ewk_intercept_request_response_header_map_add()
13       : header_map_(nullptr) {}
14
15   ~utc_blink_ewk_intercept_request_response_header_map_add() override {
16     if (header_map_)
17       eina_hash_free(header_map_);
18   }
19
20   std::string get_js_title_test() override {
21     return std::string(body_ajax_test_);
22   }
23
24   void pos_func(Ewk_Intercept_Request* intercept_request) override {
25     header_add_map_result_ = ewk_intercept_request_response_header_map_add(
26         intercept_request, header_map_);
27   }
28
29   bool neg_func(Ewk_Intercept_Request* intercept_request) override {
30     return ewk_intercept_request_response_header_map_add(intercept_request,
31                                                          header_map_);
32   }
33
34   void build_header_map() {
35     header_map_ = eina_hash_string_small_new(nullptr);
36     eina_hash_add(header_map_, "TEST_FIELD_1", "TEST_VALUE_1");
37     eina_hash_add(header_map_, "TEST_FIELD_2", "TEST_VALUE_2");
38   }
39
40   const char* body_ajax_test_ =
41       "document.title = 'TEST_FIELD_1: '"
42       "+ this.getResponseHeader('TEST_FIELD_1') + ', TEST_FIELD_2: '"
43       "+ this.getResponseHeader('TEST_FIELD_2');";
44
45   bool header_add_map_result_;
46   Eina_Hash* header_map_;
47 };
48
49 /**
50  * @brief Tests if headers are correctly added from header map.
51  */
52 TEST_F(utc_blink_ewk_intercept_request_response_header_map_add,
53        POS_TEST_RESPONSE_HEADER_ADD) {
54   build_header_map();
55   pos_test();
56   EXPECT_TRUE(header_add_map_result_);
57   /*
58    * title set in JS after ajax response:
59    * TEST_FIELD_1: <header('TEST_FIELD_1')>, \
60    * TEST_FIELD_2: <header('TEST_FIELD_2')>
61    */
62   EXPECT_STREQ("TEST_FIELD_1: TEST_VALUE_1, TEST_FIELD_2: TEST_VALUE_2",
63                ewk_view_title_get(GetEwkWebView()));
64 }
65
66 /**
67  * @brief Tests if EINA_FALSE is returned for null header map.
68  */
69 TEST_F(utc_blink_ewk_intercept_request_response_header_map_add,
70        NEG_TEST_NULL_HEADER_FIELD_NAME) {
71   intercept_request_null_ = false;
72   header_map_ = nullptr;
73   neg_test();
74 }
75
76 /**
77  * @brief Tests if EINA_FALSE is returned for null intercept request.
78  */
79 TEST_F(utc_blink_ewk_intercept_request_response_header_map_add,
80        NEG_TEST_NULL_INTERCEPT_RESPONSE) {
81   intercept_request_null_ = true;
82   build_header_map();
83   neg_test();
84 }