2 * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file TestCases_CustomHandlerDAO.cpp
18 * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
20 * @brief This file contains tests for custom handler dao class.
23 #include <dpl/test/test_runner.h>
24 #include <dpl/foreach.h>
25 #include <wrt-commons/custom-handler-dao-rw/custom_handler_dao.h>
26 #include <wrt-commons/custom-handler-dao-ro/common_dao_types.h>
28 using namespace CustomHandlerDB;
30 RUNNER_TEST_GROUP_INIT(DAO)
33 const DPL::String P_TARGET(L"p_target");
34 const DPL::String P_BASE_URL(L"p_base_url");
35 const DPL::String P_URL(L"p_url");
36 const DPL::String P_TITLE(L"p_title");
38 const DPL::String C_TARGET(L"c_target");
39 const DPL::String C_BASE_URL(L"c_base_url");
40 const DPL::String C_URL(L"c_url");
41 const DPL::String C_TITLE(L"c_title");
43 void checkHandlersExistence(CustomHandlerDAOReadOnly& dao,
47 CustomHandlerDB::CustomHandlerPtr handler;
48 handler = dao.getProtocolHandler(P_TARGET, P_URL);
49 RUNNER_ASSERT_MSG((!!handler) == protocol, "Protocol handler check");
50 handler = dao.getContentHandler(C_TARGET, C_URL);
51 RUNNER_ASSERT_MSG((!!handler) == content, "Content handler check");
55 RUNNER_TEST(custom_handler_empty_db_read)
57 CustomHandlerDAOReadOnly dao(DPL::String(L"test"));
60 RUNNER_TEST(custom_handlers)
62 CustomHandlerDAOReadOnly dao_ro(L"test");
63 CustomHandlerDAO dao_rw(L"test");
65 CustomHandlerDB::CustomHandlerPtr handler;
66 CustomHandlerDB::CustomHandler p_handler;
67 p_handler.target = P_TARGET;
68 p_handler.base_url = P_BASE_URL;
69 p_handler.url = P_URL;
70 p_handler.title = P_TITLE;
71 p_handler.user_decision = Agreed;
74 checkHandlersExistence(dao_ro, false, false);
76 // Protocol handler registration
77 dao_rw.registerProtocolHandler(p_handler);
78 checkHandlersExistence(dao_ro, true, false);
80 handler = dao_ro.getProtocolHandler(P_TARGET, P_URL);
81 RUNNER_ASSERT(handler);
82 RUNNER_ASSERT(handler->target == P_TARGET);
83 RUNNER_ASSERT(handler->base_url == P_BASE_URL);
84 RUNNER_ASSERT(handler->url == P_URL);
85 RUNNER_ASSERT(handler->title == P_TITLE);
86 RUNNER_ASSERT(handler->user_decision == Agreed);
88 // Content handler registration
89 CustomHandlerDB::CustomHandler c_handler;
90 c_handler.target = C_TARGET;
91 c_handler.base_url = C_BASE_URL;
92 c_handler.url = C_URL;
93 c_handler.title = C_TITLE;
94 c_handler.user_decision = DeclinedPermanently;
96 dao_rw.registerContentHandler(c_handler);
97 checkHandlersExistence(dao_ro, true, true);
98 handler = dao_ro.getContentHandler(C_TARGET, C_URL);
100 RUNNER_ASSERT(handler);
101 RUNNER_ASSERT(handler->target == C_TARGET);
102 RUNNER_ASSERT(handler->base_url == C_BASE_URL);
103 RUNNER_ASSERT(handler->url == C_URL);
104 RUNNER_ASSERT(handler->title == C_TITLE);
105 RUNNER_ASSERT(handler->user_decision == DeclinedPermanently);
107 // Handler unregistration
108 dao_rw.unregisterProtocolHandler(P_TARGET, P_URL);
109 checkHandlersExistence(dao_ro, false, true);
111 // Nonexistent unregistration
112 dao_rw.unregisterContentHandler(L"blah", L"blah");
113 checkHandlersExistence(dao_ro, false, true);
116 dao_rw.unregisterContentHandler(C_TARGET, C_URL);
117 checkHandlersExistence(dao_ro, false, false);
120 RUNNER_TEST(custom_handler_unregister)
122 CustomHandlerDAOReadOnly dao_ro(L"test");
123 CustomHandlerDAO dao_rw(L"test");
126 checkHandlersExistence(dao_ro, false, false);
128 CustomHandlerDB::CustomHandler p_handler;
129 p_handler.target = P_TARGET;
130 p_handler.base_url = P_BASE_URL;
131 p_handler.url = P_URL;
132 p_handler.title = P_TITLE;
133 p_handler.user_decision = Agreed;
135 // Protocol handler registration
136 dao_rw.registerProtocolHandler(p_handler);
137 checkHandlersExistence(dao_ro, true, false);
139 // Content handler registration
140 CustomHandlerDB::CustomHandler c_handler;
141 c_handler.target = C_TARGET;
142 c_handler.base_url = C_BASE_URL;
143 c_handler.url = C_URL;
144 c_handler.title = C_TITLE;
145 c_handler.user_decision = DeclinedPermanently;
147 dao_rw.registerContentHandler(c_handler);
148 checkHandlersExistence(dao_ro, true, true);
150 // Handler unregistration
151 dao_rw.unregisterProtocolHandler(P_TARGET, P_URL, P_BASE_URL);
152 checkHandlersExistence(dao_ro, false, true);
155 dao_rw.unregisterContentHandler(C_TARGET, C_URL, C_BASE_URL);
156 checkHandlersExistence(dao_ro, false, false);
159 RUNNER_TEST(custom_handler_update)
161 CustomHandlerDAOReadOnly dao_ro(L"test");
162 CustomHandlerDAO dao_rw(L"test");
165 checkHandlersExistence(dao_ro, false, false);
167 CustomHandlerDB::CustomHandler p_handler;
168 p_handler.target = P_TARGET;
169 p_handler.base_url = P_BASE_URL;
170 p_handler.url = P_URL;
171 p_handler.title = P_TITLE;
172 p_handler.user_decision = Agreed;
174 // Protocol handler registration
175 dao_rw.registerProtocolHandler(p_handler);
176 checkHandlersExistence(dao_ro, true, false);
178 // Content handler registration
179 CustomHandlerDB::CustomHandlerPtr handler;
180 CustomHandlerDB::CustomHandler c_handler;
181 c_handler.target = C_TARGET;
182 c_handler.base_url = C_BASE_URL;
183 c_handler.url = C_URL;
184 c_handler.title = C_TITLE;
185 c_handler.user_decision = DeclinedPermanently;
187 dao_rw.registerContentHandler(c_handler);
188 checkHandlersExistence(dao_ro, true, true);
190 p_handler.title = L"newTitle";
191 p_handler.user_decision = AgreedPermanently;
193 // Protocol handler update
194 dao_rw.registerProtocolHandler(p_handler);
196 handler = dao_ro.getProtocolHandler(P_TARGET, P_URL);
197 RUNNER_ASSERT(handler);
198 RUNNER_ASSERT(handler->target == P_TARGET);
199 RUNNER_ASSERT(handler->base_url == P_BASE_URL);
200 RUNNER_ASSERT(handler->url == P_URL);
201 RUNNER_ASSERT(handler->title == L"newTitle");
202 RUNNER_ASSERT(handler->user_decision == AgreedPermanently);
204 c_handler.title = L"newTitle2";
205 c_handler.user_decision = Agreed;
206 // Content handler update
207 dao_rw.registerContentHandler(c_handler);
209 handler = dao_ro.getContentHandler(C_TARGET, C_URL);
211 RUNNER_ASSERT(handler);
212 RUNNER_ASSERT(handler->target == C_TARGET);
213 RUNNER_ASSERT(handler->base_url == C_BASE_URL);
214 RUNNER_ASSERT(handler->url == C_URL);
215 RUNNER_ASSERT(handler->title == L"newTitle2");
216 RUNNER_ASSERT(handler->user_decision == Agreed);
218 // Handler unregistration
219 dao_rw.removeWidgetProtocolHandlers();
220 checkHandlersExistence(dao_ro, false, true);
223 dao_rw.removeWidgetContentHandlers();
224 checkHandlersExistence(dao_ro, false, false);
227 RUNNER_TEST(custom_handler_get_active_protocol)
229 CustomHandlerDAOReadOnly dao_ro(L"test");
230 CustomHandlerDAO dao_rw(L"test");
232 CustomHandlerDB::CustomHandler p_handler;
233 p_handler.target = P_TARGET;
234 p_handler.base_url = P_BASE_URL;
235 p_handler.url = L"url1";
236 p_handler.title = L"title1";
237 p_handler.user_decision = DeclinedPermanently;
238 // Protocol handler registration
239 dao_rw.registerProtocolHandler(p_handler);
241 CustomHandlerDB::CustomHandlerPtr handler = dao_ro.getActivProtocolHandler(P_TARGET);
242 RUNNER_ASSERT(!handler);
244 CustomHandlerDB::CustomHandler p_handler2;
245 p_handler2.target = P_TARGET;
246 p_handler2.base_url = P_BASE_URL;
247 p_handler2.url = L"url2";
248 p_handler2.title = L"title2";
249 p_handler2.user_decision = AgreedPermanently;
250 // Protocol handler registration
251 dao_rw.registerProtocolHandler(p_handler2);
253 handler = dao_ro.getActivProtocolHandler(P_TARGET);
254 RUNNER_ASSERT(handler);
255 RUNNER_ASSERT(handler->target == P_TARGET);
256 RUNNER_ASSERT(handler->base_url == P_BASE_URL);
257 RUNNER_ASSERT(handler->url == L"url2");
258 RUNNER_ASSERT(handler->title == L"title2");
259 RUNNER_ASSERT(handler->user_decision == AgreedPermanently);
261 // Handler unregistration
262 dao_rw.removeWidgetProtocolHandlers();
265 RUNNER_TEST(custom_handler_get_active_content)
267 CustomHandlerDAOReadOnly dao_ro(L"test");
268 CustomHandlerDAO dao_rw(L"test");
270 CustomHandlerDB::CustomHandler c_handler;
271 c_handler.target = C_TARGET;
272 c_handler.base_url = C_BASE_URL;
273 c_handler.url = L"url2";
274 c_handler.title = L"title2";
275 c_handler.user_decision = DeclinedPermanently;
276 // Protocol handler registration
277 dao_rw.registerContentHandler(c_handler);
279 CustomHandlerDB::CustomHandlerPtr handler = dao_ro.getActivProtocolHandler(C_TARGET);
280 RUNNER_ASSERT(!handler);
282 CustomHandlerDB::CustomHandler c_handler2;
283 c_handler2.target = C_TARGET;
284 c_handler2.base_url = C_BASE_URL;
285 c_handler2.url = L"url1";
286 c_handler2.title = C_TITLE;
287 c_handler2.user_decision = Agreed;
288 // Protocol handler registration
289 dao_rw.registerContentHandler(c_handler2);
291 handler = dao_ro.getActivContentHandler(C_TARGET);
292 RUNNER_ASSERT(handler);
293 RUNNER_ASSERT(handler->target == C_TARGET);
294 RUNNER_ASSERT(handler->base_url == C_BASE_URL);
295 RUNNER_ASSERT(handler->url == L"url1");
296 RUNNER_ASSERT(handler->title == C_TITLE);
297 RUNNER_ASSERT(handler->user_decision == Agreed);
299 // Handler unregistration
300 dao_rw.removeWidgetContentHandlers();