[M120 Migration][MM] Support W3C EME
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / unittest / utc_blink_ewk_intercept_request_response_body_set_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_body_set
10     : public utc_blink_ewk_intercept_request_response_base {
11  protected:
12   std::string get_js_title_test() override {
13     return std::string(body_ajax_test_);
14   }
15
16   void pos_func(Ewk_Intercept_Request* intercept_request) override {}
17
18   bool neg_func(Ewk_Intercept_Request* intercept_request) override {
19     return ewk_intercept_request_response_body_set(
20         intercept_request, body_ajax_response_, body_ajax_length_);
21   }
22
23   const char* body_ajax_test_ =
24       "document.title = this.responseText + ': ' + this.responseText.length;";
25
26   int body_ajax_length_;
27 };
28
29 /**
30  * @brief Tests if headers are correctly added from header map.
31  */
32 TEST_F(utc_blink_ewk_intercept_request_response_body_set,
33        POS_TEST_RESPONSE_BODY_SET) {
34   body_ajax_response_ = "HELLO EWK API";
35   pos_test();
36   // title set in JS after ajax response:
37   // <AJAX_RESPONSE>: length(<AJAX_RESPONSE>)
38   EXPECT_STREQ("HELLO EWK API: 13", ewk_view_title_get(GetEwkWebView()));
39 }
40
41 /**
42  * @brief Tests if EINA_FALSE is returned for NULL body
43  */
44 TEST_F(utc_blink_ewk_intercept_request_response_body_set, NEG_TEST_NULL_BODY) {
45   body_ajax_response_ = nullptr;
46   // some positive value, so safety checks for length won't interfere
47   body_ajax_length_ = 1;
48   neg_test();
49 }
50
51 /**
52  * @brief Tests if EINA_FALSE is returned for negative body length
53  */
54 TEST_F(utc_blink_ewk_intercept_request_response_body_set,
55        NEG_TEST_NEGATIVE_BODY_LENGTH) {
56   body_ajax_length_ = -1;
57   neg_test();
58 }
59
60 /**
61  * @brief Tests if EINA_FALSE is returned for null intercept request.
62  */
63 TEST_F(utc_blink_ewk_intercept_request_response_body_set,
64        NEG_TEST_NULL_INTERCEPT_RESPONSE) {
65   intercept_request_null_ = true;
66   body_ajax_length_ = strlen(body_ajax_response_);
67   neg_test();
68 }