[M120 Migration][MM] Support W3C EME
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / unittest / utc_blink_ewk_context_new_with_injected_bundle_path_func.cpp
1 // Copyright 2015 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 // See README.md how to run this test in DESKTOP mode.
6
7 #include "utc_blink_ewk_base.h"
8
9 class utc_blink_ewk_context_new_with_injected_bundle_path_func
10     : public utc_blink_ewk_base {
11  protected:
12   utc_blink_ewk_context_new_with_injected_bundle_path_func()
13       : timer(NULL), webview(NULL) {}
14
15   Ecore_Timer* timer;
16   Evas_Object* webview;
17   static const std::string injectedBundlePath;
18
19   static void getPlainText(Evas_Object* webview,
20                            const char* plainText,
21                            void* data) {
22     ASSERT_TRUE(data);
23     utc_blink_ewk_context_new_with_injected_bundle_path_func* owner =
24         static_cast<utc_blink_ewk_context_new_with_injected_bundle_path_func*>(
25             data);
26     owner->EventLoopStop(Success);
27     ASSERT_TRUE(plainText);
28
29     ASSERT_STREQ("DynamicPluginStartSession", plainText);
30   }
31   static Eina_Bool timerCallback(void* data) {
32     utc_blink_ewk_context_new_with_injected_bundle_path_func* owner =
33         static_cast<utc_blink_ewk_context_new_with_injected_bundle_path_func*>(
34             data);
35     ewk_view_plain_text_get(owner->webview, getPlainText, owner);
36     return ECORE_CALLBACK_CANCEL;
37   }
38   void runWithTimer() { timer = ecore_timer_add(1, timerCallback, this); }
39
40   Evas_Object* CreateWindow() {
41     Evas_Object* window = elm_win_add(NULL, "TC Launcher", ELM_WIN_BASIC);
42     return ewk_view_add_with_context(
43         evas_object_evas_get(window),
44         ewk_context_new_with_injected_bundle_path(
45             GetResourcePath(injectedBundlePath.c_str()).c_str()));
46   }
47 };
48
49 const std::string utc_blink_ewk_context_new_with_injected_bundle_path_func::
50     injectedBundlePath =
51         "ewk_context/injected_bundle/chromium/libbundle_sample.so";
52
53 /**
54  * @brief Checking whether context with injected bundle path is returned
55  */
56 TEST_F(utc_blink_ewk_context_new_with_injected_bundle_path_func, POS_TEST) {
57   ASSERT_TRUE(ewk_context_new_with_injected_bundle_path(
58       GetResourcePath(injectedBundlePath.c_str()).c_str()));
59 }
60
61 TEST_F(utc_blink_ewk_context_new_with_injected_bundle_path_func, POS_TEST1) {
62   webview = CreateWindow();
63   const char simpleHTML[] =
64       "<html><body><script>document.write(\"\");</script></body></html>";
65   ewk_context_tizen_app_id_set(ewk_view_context_get(webview), "1");
66   ASSERT_TRUE(ewk_view_html_string_load(webview, simpleHTML, NULL, NULL));
67   runWithTimer();
68   ASSERT_EQ(Success, EventLoopStart());
69 }
70
71 TEST_F(utc_blink_ewk_context_new_with_injected_bundle_path_func, NEG_TEST) {
72   Ewk_Context* context = ewk_context_new_with_injected_bundle_path(0);
73   ASSERT_TRUE(!context);
74 }