1/* 2 Copyright (C) 2012 Samsung Electronics 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public License 15 along with this library; if not, write to the Free Software Foundation, 16 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17*/ 18 19#include "config.h" 20 21#include "UnitTestUtils/EWKTestBase.h" 22#include "UnitTestUtils/EWKTestConfig.h" 23#include <EWebKit.h> 24#include <Ecore.h> 25#include <wtf/OwnPtr.h> 26#include <wtf/PassOwnPtr.h> 27 28using namespace EWKUnitTests; 29 30/** 31 * @brief Checking whether function creates proper menu item. 32 * 33 * This test creates a menu item and checks if all menu item's attributes are 34 * the same as passed to tested function. 35 */ 36TEST_F(EWKTestBase, ewk_context_menu_item_new) 37{ 38 loadUrl(); 39 40 Evas* evas = evas_object_evas_get(webView()); 41 ASSERT_TRUE(evas); 42 43 Evas_Event_Mouse_Down mouseDown; 44 mouseDown.button = 3; 45 mouseDown.output.x = 0; 46 mouseDown.output.y = 0; 47 mouseDown.canvas.x = 0; 48 mouseDown.canvas.y = 0; 49 mouseDown.data = 0; 50 mouseDown.modifiers = const_cast<Evas_Modifier*>(evas_key_modifier_get(evas)); 51 mouseDown.locks = const_cast<Evas_Lock*>(evas_key_lock_get(evas)); 52 mouseDown.flags = EVAS_BUTTON_NONE; 53 mouseDown.timestamp = ecore_loop_time_get(); 54 mouseDown.event_flags = EVAS_EVENT_FLAG_NONE; 55 mouseDown.dev = 0; 56 57 ASSERT_TRUE(ewk_view_context_menu_forward_event(webView(), &mouseDown)); 58 59 Ewk_Context_Menu* contextMenu = ewk_view_context_menu_get(webView()); 60 61 ASSERT_TRUE(contextMenu); 62 63 Ewk_Context_Menu_Item_Type itemType = EWK_ACTION_TYPE; 64 Ewk_Context_Menu_Action itemAction = EWK_CONTEXT_MENU_ITEM_CUSTOM_TAG_NO_ACTION; 65 const char* itemTitle = "Test Item"; 66 bool itemChecked = false; 67 bool itemEnabled = false; 68 69 Ewk_Context_Menu_Item* contextMenuItem = ewk_context_menu_item_new(itemType, itemAction, contextMenu, 0, itemTitle, itemChecked, itemEnabled); 70 71 ASSERT_TRUE(contextMenuItem); 72 73 EXPECT_EQ(itemType, ewk_context_menu_item_type_get(contextMenuItem)); 74 EXPECT_EQ(itemAction, ewk_context_menu_item_action_get(contextMenuItem)); 75 EXPECT_EQ(contextMenu, ewk_context_menu_item_parent_get(contextMenuItem)); 76 EXPECT_STREQ(itemTitle, ewk_context_menu_item_title_get(contextMenuItem)); 77 EXPECT_EQ(itemChecked, ewk_context_menu_item_checked_get(contextMenuItem)); 78 EXPECT_EQ(itemEnabled, ewk_context_menu_item_enabled_get(contextMenuItem)); 79 80 ewk_context_menu_item_free(contextMenuItem); 81} 82 83/** 84 * @brief Checking whether function returns proper parent menu. 85 * 86 * This test creates a context menus, and checks if created context menu's 87 * parent is the same for each of menu items. 88 */ 89TEST_F(EWKTestBase, ewk_context_menu_item_parent_get) 90{ 91 loadUrl(); 92 93 Evas* evas = evas_object_evas_get(webView()); 94 ASSERT_TRUE(evas); 95 96 Evas_Event_Mouse_Down mouseDown; 97 mouseDown.button = 3; 98 mouseDown.output.x = 0; 99 mouseDown.output.y = 0; 100 mouseDown.canvas.x = 0; 101 mouseDown.canvas.y = 0; 102 mouseDown.data = 0; 103 mouseDown.modifiers = const_cast<Evas_Modifier*>(evas_key_modifier_get(evas)); 104 mouseDown.locks = const_cast<Evas_Lock*>(evas_key_lock_get(evas)); 105 mouseDown.flags = EVAS_BUTTON_NONE; 106 mouseDown.timestamp = ecore_loop_time_get(); 107 mouseDown.event_flags = EVAS_EVENT_FLAG_NONE; 108 mouseDown.dev = 0; 109 110 ASSERT_TRUE(ewk_view_context_menu_forward_event(webView(), &mouseDown)); 111 112 Ewk_Context_Menu* contextMenu = ewk_view_context_menu_get(webView()); 113 114 ASSERT_TRUE(contextMenu); 115 116 const Eina_List* contextMenuItems = ewk_context_menu_item_list_get(contextMenu); 117 118 ASSERT_TRUE(contextMenuItems); 119 120 const Eina_List* listIterator; 121 void* data; 122 EINA_LIST_FOREACH(contextMenuItems, listIterator, data) 123 EXPECT_EQ(contextMenu, ewk_context_menu_item_parent_get(static_cast<Ewk_Context_Menu_Item*>(data))); 124} 125