Merge lp:~marcustomlinson/unity-scopes-api/online_accounts_tests into lp:unity-scopes-api/devel
- online_accounts_tests
- Merge into devel
Status: | Merged |
---|---|
Approved by: | Paweł Stołowski |
Approved revision: | 278 |
Merged at revision: | 502 |
Proposed branch: | lp:~marcustomlinson/unity-scopes-api/online_accounts_tests |
Merge into: | lp:unity-scopes-api/devel |
Prerequisite: | lp:~marcustomlinson/unity-scopes-api/fix_ui_policy |
Diff against target: |
818 lines (+627/-16) 8 files modified
debian/control (+3/-1) include/unity/scopes/OnlineAccountClient.h (+7/-0) include/unity/scopes/internal/OnlineAccountClientImpl.h (+1/-0) src/scopes/internal/OnlineAccountClientImpl.cpp (+17/-6) test/gtest/scopes/OnlineAccountClient/CMakeLists.txt (+8/-0) test/gtest/scopes/OnlineAccountClient/OnlineAccountClient_test.cpp (+544/-9) test/gtest/scopes/OnlineAccountClient/data/TestService.service (+26/-0) valgrind-suppress (+21/-0) |
To merge this branch: | bzr merge lp:~marcustomlinson/unity-scopes-api/online_accounts_tests |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot (community) | continuous-integration | Approve | |
Paweł Stołowski (community) | Approve | ||
Review via email: mp+237571@code.launchpad.net |
This proposal supersedes a proposal from 2014-10-06.
Commit message
Added tests for OnlineAccountClient
Description of the change
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal | # |
Paweł Stołowski (stolowski) wrote : Posted in a previous version of this proposal | # |
LGTM.
- 278. By Marcus Tomlinson
-
Merged fix_ui_policy
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:278
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https:/
http://
Executed test runs:
SUCCESS: http://
FAILURE: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Marcus Tomlinson (marcustomlinson) wrote : | # |
Set a commit message and hit rebuild.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:278
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) : | # |
Preview Diff
1 | === modified file 'debian/control' |
2 | --- debian/control 2014-09-23 08:33:51 +0000 |
3 | +++ debian/control 2014-10-08 11:04:26 +0000 |
4 | @@ -26,6 +26,8 @@ |
5 | libjsoncpp-dev, |
6 | libaccounts-glib-dev, |
7 | libsignon-glib-dev, |
8 | + dbus-test-runner, |
9 | + libdbustest1-dev, |
10 | valgrind, |
11 | Standards-Version: 3.9.5 |
12 | XS-Testsuite: autopkgtest |
13 | @@ -81,4 +83,4 @@ |
14 | Multi-Arch: foreign |
15 | Depends: ${misc:Depends}, |
16 | Description: Documentation for Unity scopes API |
17 | - Library to integrate scopes with the Unity shell (documentation) |
18 | \ No newline at end of file |
19 | + Library to integrate scopes with the Unity shell (documentation) |
20 | |
21 | === modified file 'include/unity/scopes/OnlineAccountClient.h' |
22 | --- include/unity/scopes/OnlineAccountClient.h 2014-10-08 11:04:26 +0000 |
23 | +++ include/unity/scopes/OnlineAccountClient.h 2014-10-08 11:04:26 +0000 |
24 | @@ -37,6 +37,11 @@ |
25 | class OnlineAccountClientImpl; |
26 | } |
27 | |
28 | +namespace testing |
29 | +{ |
30 | +class OnlineAccountClientTest; |
31 | +} |
32 | + |
33 | /** |
34 | \brief A simple interface for integrating online accounts access and monitoring into scopes. |
35 | |
36 | @@ -159,6 +164,8 @@ |
37 | |
38 | private: |
39 | std::unique_ptr<internal::OnlineAccountClientImpl> p; |
40 | + |
41 | + friend class testing::OnlineAccountClientTest; |
42 | }; |
43 | |
44 | } // namespace scopes |
45 | |
46 | === modified file 'include/unity/scopes/internal/OnlineAccountClientImpl.h' |
47 | --- include/unity/scopes/internal/OnlineAccountClientImpl.h 2014-10-08 11:04:26 +0000 |
48 | +++ include/unity/scopes/internal/OnlineAccountClientImpl.h 2014-10-08 11:04:26 +0000 |
49 | @@ -89,6 +89,7 @@ |
50 | std::shared_ptr<AgManager> manager(); |
51 | std::string service_name(); |
52 | OnlineAccountClient::MainLoopSelect main_loop_select(); |
53 | + std::shared_ptr<GMainContext> main_loop_context(); |
54 | |
55 | void callback(AccountInfo const* info, std::string const& error = ""); |
56 | |
57 | |
58 | === modified file 'src/scopes/internal/OnlineAccountClientImpl.cpp' |
59 | --- src/scopes/internal/OnlineAccountClientImpl.cpp 2014-10-08 11:04:26 +0000 |
60 | +++ src/scopes/internal/OnlineAccountClientImpl.cpp 2014-10-08 11:04:26 +0000 |
61 | @@ -193,7 +193,7 @@ |
62 | if (error) |
63 | { |
64 | // Send notification that the authorization session failed |
65 | - info->account_client->callback(info, error->message); |
66 | + info->account_client->callback(info, error->message); // LCOV_EXCL_LINE |
67 | return; |
68 | } |
69 | |
70 | @@ -205,7 +205,7 @@ |
71 | { |
72 | g_variant_builder_add(&builder, "{sv}", |
73 | SIGNON_SESSION_DATA_UI_POLICY, |
74 | - g_variant_new_int32(SIGNON_POLICY_DEFAULT)); |
75 | + g_variant_new_int32(SIGNON_POLICY_DEFAULT)); // LCOV_EXCL_LINE |
76 | } |
77 | else |
78 | { |
79 | @@ -243,7 +243,7 @@ |
80 | if (!account) |
81 | { |
82 | // The account was not found |
83 | - return; |
84 | + return; // LCOV_EXCL_LINE |
85 | } |
86 | // Find the service we're concerned with |
87 | std::shared_ptr<GList> services(ag_account_list_services(account.get()), ag_service_list_free); |
88 | @@ -320,6 +320,7 @@ |
89 | } |
90 | if (!main_loop_is_running_) |
91 | { |
92 | + // LCOV_EXCL_START |
93 | if (main_loop_) |
94 | { |
95 | // Quit the main loop, causing the thread to exit |
96 | @@ -337,6 +338,7 @@ |
97 | { |
98 | throw unity::ResourceException("OnlineAccountClientImpl(): main_loop_thread failed to start."); |
99 | } |
100 | + // LCOV_EXCL_STOP |
101 | } |
102 | } |
103 | else |
104 | @@ -351,6 +353,7 @@ |
105 | std::lock_guard<std::mutex> lock(mutex_); |
106 | if (thread_exception_) |
107 | { |
108 | + // LCOV_EXCL_START |
109 | try |
110 | { |
111 | std::rethrow_exception(thread_exception_); |
112 | @@ -363,6 +366,7 @@ |
113 | { |
114 | std::cerr << "~OnlineAccountClientImpl(): main_loop_thread threw an unknown exception" << std::endl; |
115 | } |
116 | + // LCOV_EXCL_STOP |
117 | } |
118 | } |
119 | |
120 | @@ -394,7 +398,7 @@ |
121 | std::lock_guard<std::mutex> lock(mutex_); |
122 | if (thread_exception_) |
123 | { |
124 | - std::rethrow_exception(thread_exception_); |
125 | + std::rethrow_exception(thread_exception_); // LCOV_EXCL_LINE |
126 | } |
127 | |
128 | std::lock_guard<std::mutex> callback_lock(callback_mutex_); |
129 | @@ -406,7 +410,7 @@ |
130 | std::unique_lock<std::mutex> lock(mutex_); |
131 | if (thread_exception_) |
132 | { |
133 | - std::rethrow_exception(thread_exception_); |
134 | + std::rethrow_exception(thread_exception_); // LCOV_EXCL_LINE |
135 | } |
136 | |
137 | std::shared_ptr<GList> enabled_accounts(ag_manager_list(manager_.get()), ag_manager_list_free); |
138 | @@ -431,7 +435,7 @@ |
139 | std::lock_guard<std::mutex> lock(mutex_); |
140 | if (thread_exception_) |
141 | { |
142 | - std::rethrow_exception(thread_exception_); |
143 | + std::rethrow_exception(thread_exception_); // LCOV_EXCL_LINE |
144 | } |
145 | |
146 | // Return all service statuses |
147 | @@ -577,6 +581,11 @@ |
148 | return main_loop_select_; |
149 | } |
150 | |
151 | +std::shared_ptr<GMainContext> OnlineAccountClientImpl::main_loop_context() |
152 | +{ |
153 | + return main_loop_context_; |
154 | +} |
155 | + |
156 | void OnlineAccountClientImpl::callback(AccountInfo const* info, std::string const& error) |
157 | { |
158 | std::lock_guard<std::mutex> lock(callback_mutex_); |
159 | @@ -642,6 +651,7 @@ |
160 | main_loop_.reset(g_main_loop_new(main_loop_context_.get(), true), g_main_loop_unref); |
161 | g_main_loop_run(main_loop_.get()); |
162 | } |
163 | + // LCOV_EXCL_START |
164 | catch (std::exception const& e) |
165 | { |
166 | std::cerr << "OnlineAccountClientImpl::main_loop_thread(): Thread aborted: " << e.what() << std::endl; |
167 | @@ -654,6 +664,7 @@ |
168 | std::lock_guard<std::mutex> lock(mutex_); |
169 | thread_exception_ = std::current_exception(); |
170 | } |
171 | + // LCOV_EXCL_STOP |
172 | } |
173 | |
174 | void OnlineAccountClientImpl::auth_callback(std::string const& details_json) |
175 | |
176 | === modified file 'test/gtest/scopes/OnlineAccountClient/CMakeLists.txt' |
177 | --- test/gtest/scopes/OnlineAccountClient/CMakeLists.txt 2014-09-10 08:45:38 +0000 |
178 | +++ test/gtest/scopes/OnlineAccountClient/CMakeLists.txt 2014-10-08 11:04:26 +0000 |
179 | @@ -1,4 +1,12 @@ |
180 | add_executable(OnlineAccountClient_test OnlineAccountClient_test.cpp) |
181 | + |
182 | +pkg_check_modules(DBUSTEST REQUIRED dbustest-1) |
183 | +include_directories(${DBUSTEST_INCLUDE_DIRS}) |
184 | +target_link_libraries(OnlineAccountClient_test ${DBUSTEST_LDFLAGS}) |
185 | + |
186 | +add_definitions(-DTEST_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data") |
187 | +add_definitions(-DTEST_DB_DIR="${CMAKE_CURRENT_BINARY_DIR}") |
188 | + |
189 | target_link_libraries(OnlineAccountClient_test ${TESTLIBS}) |
190 | |
191 | add_test(OnlineAccountClient OnlineAccountClient_test) |
192 | |
193 | === modified file 'test/gtest/scopes/OnlineAccountClient/OnlineAccountClient_test.cpp' |
194 | --- test/gtest/scopes/OnlineAccountClient/OnlineAccountClient_test.cpp 2014-10-08 11:04:26 +0000 |
195 | +++ test/gtest/scopes/OnlineAccountClient/OnlineAccountClient_test.cpp 2014-10-08 11:04:26 +0000 |
196 | @@ -16,17 +16,552 @@ |
197 | * Authored by: Marcus Tomlinson <marcus.tomlinson@canonical.com> |
198 | */ |
199 | |
200 | +#include <unity/scopes/OnlineAccountClient.h> |
201 | +#include <unity/scopes/internal/OnlineAccountClientImpl.h> |
202 | + |
203 | +#include <unity/scopes/CategorisedResult.h> |
204 | +#include <unity/scopes/CategoryRenderer.h> |
205 | +#include <unity/scopes/internal/CategoryRegistry.h> |
206 | +#include <unity/scopes/PreviewWidget.h> |
207 | +#include <unity/scopes/Variant.h> |
208 | + |
209 | +#include <boost/filesystem/operations.hpp> |
210 | +#include <condition_variable> |
211 | +#include <functional> |
212 | #include <gtest/gtest.h> |
213 | -#include <unity/scopes/OnlineAccountClient.h> |
214 | - |
215 | +#include <libaccounts-glib/accounts-glib.h> |
216 | +#include <libdbustest/dbus-test.h> |
217 | #include <thread> |
218 | |
219 | +using namespace unity; |
220 | using namespace unity::scopes; |
221 | - |
222 | -TEST(OnlineAccountClient, basic) |
223 | -{ |
224 | - setenv("XDG_RUNTIME_DIR", "/tmp", true); |
225 | - |
226 | - OnlineAccountClient oa_client("com.ubuntu.scopes.youtube_youtube", "sharing", "google"); |
227 | - auto service_statuses = oa_client.get_service_statuses(); |
228 | +using namespace unity::scopes::testing; |
229 | +using namespace unity::scopes::internal; |
230 | + |
231 | +namespace unity |
232 | +{ |
233 | +namespace scopes |
234 | +{ |
235 | +namespace testing |
236 | +{ |
237 | + |
238 | +class OnlineAccountClientTest : public ::testing::Test |
239 | +{ |
240 | +public: |
241 | + OnlineAccountClientTest(OnlineAccountClient::MainLoopSelect main_loop_select = OnlineAccountClient::CreateInternalMainLoop) |
242 | + { |
243 | + boost::filesystem::remove(TEST_DB_DIR "/accounts.db"); |
244 | + |
245 | + setenv("XDG_RUNTIME_DIR", "/tmp", true); |
246 | + setenv("ACCOUNTS", TEST_DB_DIR, false); |
247 | + setenv("AG_SERVICES", TEST_DATA_DIR, false); |
248 | + setenv("AG_SERVICE_TYPES", TEST_DATA_DIR, false); |
249 | + setenv("AG_PROVIDERS", TEST_DATA_DIR, false); |
250 | + |
251 | + oa_client_.reset(new OnlineAccountClient("TestService", "sharing", "TestProvider", main_loop_select)); |
252 | + |
253 | + manager_ = oa_client_->p->manager(); |
254 | + main_loop_context_ = oa_client_->p->main_loop_context(); |
255 | + } |
256 | + |
257 | + ~OnlineAccountClientTest() |
258 | + { |
259 | + account_ = nullptr; |
260 | + manager_ = nullptr; |
261 | + oa_client_ = nullptr; |
262 | + } |
263 | + |
264 | + std::shared_ptr<OnlineAccountClient> oa_client() |
265 | + { |
266 | + return oa_client_; |
267 | + } |
268 | + |
269 | + void create_account() |
270 | + { |
271 | + run_in_main_loop_(std::bind(&OnlineAccountClientTest::create_account_, this)); |
272 | + } |
273 | + |
274 | + void delete_account() |
275 | + { |
276 | + run_in_main_loop_(std::bind(&OnlineAccountClientTest::delete_account_, this)); |
277 | + } |
278 | + |
279 | + void enable_service() |
280 | + { |
281 | + run_in_main_loop_(std::bind(&OnlineAccountClientTest::enable_service_, this)); |
282 | + } |
283 | + |
284 | + void disable_service() |
285 | + { |
286 | + run_in_main_loop_(std::bind(&OnlineAccountClientTest::disable_service_, this)); |
287 | + } |
288 | + |
289 | + void disable_account() |
290 | + { |
291 | + run_in_main_loop_(std::bind(&OnlineAccountClientTest::disable_account_, this)); |
292 | + } |
293 | + |
294 | + void enable_account() |
295 | + { |
296 | + run_in_main_loop_(std::bind(&OnlineAccountClientTest::enable_account_, this)); |
297 | + } |
298 | + |
299 | + void service_update_enabled(OnlineAccountClient::ServiceStatus const& status) |
300 | + { |
301 | + EXPECT_EQ(1, status.account_id); |
302 | + EXPECT_EQ(true, status.service_enabled); |
303 | + EXPECT_EQ(false, status.service_authenticated); |
304 | + EXPECT_EQ("69842936499-sdflkbhslufhgrjamwlicefhb.apps.test.com", status.client_id); |
305 | + EXPECT_EQ("lj3i8iorep0w03994jwjef0j", status.client_secret); |
306 | + EXPECT_EQ("", status.access_token); |
307 | + EXPECT_EQ("", status.token_secret); |
308 | + EXPECT_NE("", status.error); |
309 | + |
310 | + std::lock_guard<std::mutex> lock(mutex_); |
311 | + got_update_ = true; |
312 | + cond_.notify_all(); |
313 | + } |
314 | + |
315 | + void service_update_disabled(OnlineAccountClient::ServiceStatus const& status) |
316 | + { |
317 | + EXPECT_EQ(1, status.account_id); |
318 | + EXPECT_EQ(false, status.service_enabled); |
319 | + EXPECT_EQ(false, status.service_authenticated); |
320 | + EXPECT_EQ("69842936499-sdflkbhslufhgrjamwlicefhb.apps.test.com", status.client_id); |
321 | + EXPECT_EQ("lj3i8iorep0w03994jwjef0j", status.client_secret); |
322 | + EXPECT_EQ("", status.access_token); |
323 | + EXPECT_EQ("", status.token_secret); |
324 | + EXPECT_EQ("", status.error); |
325 | + |
326 | + std::lock_guard<std::mutex> lock(mutex_); |
327 | + got_update_ = true; |
328 | + cond_.notify_all(); |
329 | + } |
330 | + |
331 | + void service_update_none(OnlineAccountClient::ServiceStatus const& status) |
332 | + { |
333 | + EXPECT_EQ(1, status.account_id); |
334 | + EXPECT_EQ(false, status.service_enabled); |
335 | + EXPECT_EQ(false, status.service_authenticated); |
336 | + EXPECT_EQ("", status.client_id); |
337 | + EXPECT_EQ("", status.client_secret); |
338 | + EXPECT_EQ("", status.access_token); |
339 | + EXPECT_EQ("", status.token_secret); |
340 | + EXPECT_EQ("", status.error); |
341 | + |
342 | + std::lock_guard<std::mutex> lock(mutex_); |
343 | + got_update_ = true; |
344 | + cond_.notify_all(); |
345 | + } |
346 | + |
347 | + void service_update_auth(OnlineAccountClient::ServiceStatus const& status) |
348 | + { |
349 | + EXPECT_EQ(1, status.account_id); |
350 | + EXPECT_EQ(true, status.service_enabled); |
351 | + EXPECT_EQ(true, status.service_authenticated); |
352 | + EXPECT_EQ("isuertbiseruy87srkuthksvu", status.client_id); |
353 | + EXPECT_EQ("rytwekfgiodng523dr4", status.client_secret); |
354 | + EXPECT_EQ("sfhgbfgutgi9ugwirheg74", status.access_token); |
355 | + EXPECT_EQ("qwpeurylsfdg83", status.token_secret); |
356 | + EXPECT_EQ("not really an error, but just to test", status.error); |
357 | + |
358 | + std::lock_guard<std::mutex> lock(mutex_); |
359 | + got_update_ = true; |
360 | + cond_.notify_all(); |
361 | + } |
362 | + |
363 | + bool wait_for_service_update() |
364 | + { |
365 | + std::unique_lock<std::mutex> lock(mutex_); |
366 | + EXPECT_TRUE(cond_.wait_for(lock, std::chrono::seconds(1), [this]{ return got_update_; })) << "service update callback not triggered"; |
367 | + bool result = got_update_; |
368 | + got_update_ = false; |
369 | + return result; |
370 | + } |
371 | + |
372 | + void invoke_callback(std::shared_ptr<OnlineAccountClient> oa_client, AccountInfo const* info, std::string const& error) |
373 | + { |
374 | + oa_client->p->callback(info, error); |
375 | + } |
376 | + |
377 | + static void safe_g_error_free_(GError* e) |
378 | + { |
379 | + if (e) |
380 | + { |
381 | + g_error_free(e); |
382 | + } |
383 | + } |
384 | + |
385 | + static void safe_g_variant_free_(GVariant* v) |
386 | + { |
387 | + if (v) |
388 | + { |
389 | + g_variant_unref(v); |
390 | + } |
391 | + } |
392 | + |
393 | +private: |
394 | + std::shared_ptr<OnlineAccountClient> oa_client_; |
395 | + std::shared_ptr<AgManager> manager_; |
396 | + std::shared_ptr<AgAccount> account_; |
397 | + std::shared_ptr<GMainContext> main_loop_context_; |
398 | + |
399 | + bool got_update_; |
400 | + std::mutex mutex_; |
401 | + std::condition_variable cond_; |
402 | + |
403 | +private: |
404 | + void run_in_main_loop_(std::function<void()> func) |
405 | + { |
406 | + auto func_task = [](void* user_data) |
407 | + { |
408 | + auto cb_data = reinterpret_cast<std::pair<std::function<void()>*, GMainLoop*>*>(user_data); |
409 | + auto func = cb_data->first; |
410 | + auto event_loop = cb_data->second; |
411 | + |
412 | + (*func)(); |
413 | + |
414 | + while (!g_main_loop_is_running(event_loop)); |
415 | + g_main_loop_quit(event_loop); |
416 | + |
417 | + return G_SOURCE_REMOVE; |
418 | + }; |
419 | + |
420 | + std::shared_ptr<GMainLoop> event_loop; |
421 | + if (main_loop_context_) |
422 | + { |
423 | + event_loop.reset(g_main_loop_new(main_loop_context_.get(), false), g_main_loop_unref); |
424 | + auto cb_data = std::make_pair(&func, event_loop.get()); |
425 | + g_main_context_invoke(main_loop_context_.get(), func_task, &cb_data); |
426 | + } |
427 | + else |
428 | + { |
429 | + event_loop.reset(g_main_loop_new(nullptr, false), g_main_loop_unref); |
430 | + auto cb_data = std::make_pair(&func, event_loop.get()); |
431 | + g_idle_add(func_task, &cb_data); |
432 | + } |
433 | + g_main_loop_run(event_loop.get()); |
434 | + } |
435 | + |
436 | + void create_account_() |
437 | + { |
438 | + account_.reset(ag_manager_create_account(manager_.get(), "TestProvider"), g_object_unref); |
439 | + ag_account_select_service(account_.get(), nullptr); |
440 | + ag_account_set_enabled(account_.get(), true); |
441 | + |
442 | + GError* error = nullptr; |
443 | + bool stored = ag_account_store_blocking(account_.get(), &error); |
444 | + std::shared_ptr<GError> error_cleanup(error, safe_g_error_free_); |
445 | + |
446 | + EXPECT_TRUE(stored); |
447 | + EXPECT_EQ(nullptr, error); |
448 | + } |
449 | + |
450 | + void delete_account_() |
451 | + { |
452 | + ag_account_delete(account_.get()); |
453 | + |
454 | + GError* error = nullptr; |
455 | + bool stored = ag_account_store_blocking(account_.get(), &error); |
456 | + std::shared_ptr<GError> error_cleanup(error, safe_g_error_free_); |
457 | + |
458 | + account_ = nullptr; |
459 | + |
460 | + EXPECT_TRUE(stored); |
461 | + EXPECT_EQ(nullptr, error); |
462 | + } |
463 | + |
464 | + void enable_service_() |
465 | + { |
466 | + auto service = ag_manager_get_service(manager_.get(), "TestService"); |
467 | + ag_account_select_service(account_.get(), service); |
468 | + ag_account_set_enabled(account_.get(), true); |
469 | + |
470 | + GError* error = nullptr; |
471 | + bool stored = ag_account_store_blocking(account_.get(), &error); |
472 | + std::shared_ptr<GError> error_cleanup(error, safe_g_error_free_); |
473 | + |
474 | + EXPECT_TRUE(stored); |
475 | + EXPECT_EQ(nullptr, error); |
476 | + } |
477 | + |
478 | + void disable_service_() |
479 | + { |
480 | + auto service = ag_manager_get_service(manager_.get(), "TestService"); |
481 | + ag_account_select_service(account_.get(), service); |
482 | + ag_account_set_enabled(account_.get(), false); |
483 | + |
484 | + GError* error = nullptr; |
485 | + bool stored = ag_account_store_blocking(account_.get(), &error); |
486 | + std::shared_ptr<GError> error_cleanup(error, safe_g_error_free_); |
487 | + |
488 | + EXPECT_TRUE(stored); |
489 | + EXPECT_EQ(nullptr, error); |
490 | + } |
491 | + |
492 | + void disable_account_() |
493 | + { |
494 | + ag_account_set_enabled(account_.get(), false); |
495 | + |
496 | + GError* error = nullptr; |
497 | + bool stored = ag_account_store_blocking(account_.get(), &error); |
498 | + std::shared_ptr<GError> error_cleanup(error, safe_g_error_free_); |
499 | + |
500 | + EXPECT_TRUE(stored); |
501 | + EXPECT_EQ(nullptr, error); |
502 | + } |
503 | + |
504 | + void enable_account_() |
505 | + { |
506 | + ag_account_set_enabled(account_.get(), true); |
507 | + |
508 | + GError* error = nullptr; |
509 | + bool stored = ag_account_store_blocking(account_.get(), &error); |
510 | + std::shared_ptr<GError> error_cleanup(error, safe_g_error_free_); |
511 | + |
512 | + EXPECT_TRUE(stored); |
513 | + EXPECT_EQ(nullptr, error); |
514 | + } |
515 | +}; |
516 | + |
517 | +class OnlineAccountClientTestNoMainLoop : public OnlineAccountClientTest |
518 | +{ |
519 | +public: |
520 | + OnlineAccountClientTestNoMainLoop() |
521 | + : OnlineAccountClientTest(OnlineAccountClient::RunInExternalMainLoop) {} |
522 | +}; |
523 | + |
524 | +} // namespace testing |
525 | +} // namespace scopes |
526 | +} // namespace unity |
527 | + |
528 | +TEST_F(OnlineAccountClientTest, register_account_login_result) |
529 | +{ |
530 | + OnlineAccountClient oa_client("test_service_name", "test_service_type", "test_provider"); |
531 | + |
532 | + CategoryRegistry reg; |
533 | + auto cat = reg.register_category("1", "title", "icon", nullptr, CategoryRenderer()); |
534 | + CategorisedResult result(cat); |
535 | + |
536 | + oa_client.register_account_login_item(result, CannedQuery("test"), OnlineAccountClient::InvalidateResults, OnlineAccountClient::DoNothing); |
537 | + |
538 | + EXPECT_TRUE(result.contains("online_account_details")); |
539 | + |
540 | + VariantMap details = result.value("online_account_details").get_dict(); |
541 | + |
542 | + EXPECT_NE(details.end(), details.find("service_name")); |
543 | + EXPECT_NE(details.end(), details.find("service_type")); |
544 | + EXPECT_NE(details.end(), details.find("provider_name")); |
545 | + EXPECT_NE(details.end(), details.find("login_passed_action")); |
546 | + EXPECT_NE(details.end(), details.find("login_failed_action")); |
547 | + |
548 | + EXPECT_EQ("test_service_name", details.at("service_name").get_string()); |
549 | + EXPECT_EQ("test_service_type", details.at("service_type").get_string()); |
550 | + EXPECT_EQ("test_provider", details.at("provider_name").get_string()); |
551 | + EXPECT_EQ(OnlineAccountClient::InvalidateResults, static_cast<OnlineAccountClient::PostLoginAction>(details.at("login_passed_action").get_int())); |
552 | + EXPECT_EQ(OnlineAccountClient::DoNothing, static_cast<OnlineAccountClient::PostLoginAction>(details.at("login_failed_action").get_int())); |
553 | +} |
554 | + |
555 | +TEST_F(OnlineAccountClientTest, register_account_login_widget) |
556 | +{ |
557 | + OnlineAccountClient oa_client("test_service_name", "test_service_type", "test_provider"); |
558 | + |
559 | + PreviewWidget widget("i1", "image"); |
560 | + |
561 | + oa_client.register_account_login_item(widget, OnlineAccountClient::ContinueActivation, OnlineAccountClient::DoNothing); |
562 | + |
563 | + VariantMap values = widget.attribute_values(); |
564 | + |
565 | + EXPECT_NE(values.end(), values.find("online_account_details")); |
566 | + |
567 | + VariantMap details = values.at("online_account_details").get_dict(); |
568 | + |
569 | + EXPECT_NE(details.end(), details.find("service_name")); |
570 | + EXPECT_NE(details.end(), details.find("service_type")); |
571 | + EXPECT_NE(details.end(), details.find("provider_name")); |
572 | + EXPECT_NE(details.end(), details.find("login_passed_action")); |
573 | + EXPECT_NE(details.end(), details.find("login_failed_action")); |
574 | + |
575 | + EXPECT_EQ("test_service_name", details.at("service_name").get_string()); |
576 | + EXPECT_EQ("test_service_type", details.at("service_type").get_string()); |
577 | + EXPECT_EQ("test_provider", details.at("provider_name").get_string()); |
578 | + EXPECT_EQ(OnlineAccountClient::ContinueActivation, static_cast<OnlineAccountClient::PostLoginAction>(details.at("login_passed_action").get_int())); |
579 | + EXPECT_EQ(OnlineAccountClient::DoNothing, static_cast<OnlineAccountClient::PostLoginAction>(details.at("login_failed_action").get_int())); |
580 | +} |
581 | + |
582 | +TEST_F(OnlineAccountClientTest, refresh_services_main_loop) |
583 | +{ |
584 | + auto statuses = oa_client()->get_service_statuses(); |
585 | + EXPECT_EQ(0, statuses.size()); |
586 | + |
587 | + create_account(); |
588 | + oa_client()->refresh_service_statuses(); |
589 | + |
590 | + statuses = oa_client()->get_service_statuses(); |
591 | + EXPECT_EQ(1, statuses.size()); |
592 | + EXPECT_FALSE(statuses[0].service_enabled); |
593 | + |
594 | + enable_service(); |
595 | + oa_client()->refresh_service_statuses(); |
596 | + |
597 | + statuses = oa_client()->get_service_statuses(); |
598 | + EXPECT_TRUE(statuses[0].service_enabled); |
599 | + |
600 | + disable_service(); |
601 | + oa_client()->refresh_service_statuses(); |
602 | + |
603 | + statuses = oa_client()->get_service_statuses(); |
604 | + EXPECT_FALSE(statuses[0].service_enabled); |
605 | + |
606 | + enable_service(); |
607 | + oa_client()->refresh_service_statuses(); |
608 | + |
609 | + statuses = oa_client()->get_service_statuses(); |
610 | + EXPECT_TRUE(statuses[0].service_enabled); |
611 | + |
612 | + disable_account(); |
613 | + oa_client()->refresh_service_statuses(); |
614 | + |
615 | + statuses = oa_client()->get_service_statuses(); |
616 | + EXPECT_FALSE(statuses[0].service_enabled); |
617 | + |
618 | + enable_account(); |
619 | + oa_client()->refresh_service_statuses(); |
620 | + |
621 | + statuses = oa_client()->get_service_statuses(); |
622 | + EXPECT_TRUE(statuses[0].service_enabled); |
623 | + |
624 | + delete_account(); |
625 | + oa_client()->refresh_service_statuses(); |
626 | + |
627 | + statuses = oa_client()->get_service_statuses(); |
628 | + EXPECT_EQ(0, statuses.size()); |
629 | +} |
630 | + |
631 | +TEST_F(OnlineAccountClientTest, service_update_callback) |
632 | +{ |
633 | + auto statuses = oa_client()->get_service_statuses(); |
634 | + EXPECT_EQ(0, statuses.size()); |
635 | + |
636 | + oa_client()->set_service_update_callback(std::bind(&OnlineAccountClientTest::service_update_none, this, std::placeholders::_1)); |
637 | + create_account(); |
638 | + wait_for_service_update(); |
639 | + |
640 | + statuses = oa_client()->get_service_statuses(); |
641 | + EXPECT_EQ(1, statuses.size()); |
642 | + |
643 | + oa_client()->set_service_update_callback(std::bind(&OnlineAccountClientTest::service_update_enabled, this, std::placeholders::_1)); |
644 | + enable_service(); |
645 | + wait_for_service_update(); |
646 | + |
647 | + oa_client()->set_service_update_callback(std::bind(&OnlineAccountClientTest::service_update_disabled, this, std::placeholders::_1)); |
648 | + disable_service(); |
649 | + wait_for_service_update(); |
650 | + |
651 | + oa_client()->set_service_update_callback(std::bind(&OnlineAccountClientTest::service_update_enabled, this, std::placeholders::_1)); |
652 | + enable_service(); |
653 | + wait_for_service_update(); |
654 | + |
655 | + oa_client()->set_service_update_callback(std::bind(&OnlineAccountClientTest::service_update_disabled, this, std::placeholders::_1)); |
656 | + disable_account(); |
657 | + wait_for_service_update(); |
658 | + |
659 | + oa_client()->set_service_update_callback(std::bind(&OnlineAccountClientTest::service_update_enabled, this, std::placeholders::_1)); |
660 | + enable_account(); |
661 | + wait_for_service_update(); |
662 | + |
663 | + oa_client()->set_service_update_callback(std::bind(&OnlineAccountClientTest::service_update_disabled, this, std::placeholders::_1)); |
664 | + delete_account(); |
665 | + wait_for_service_update(); |
666 | + |
667 | + statuses = oa_client()->get_service_statuses(); |
668 | + EXPECT_EQ(0, statuses.size()); |
669 | +} |
670 | + |
671 | +TEST_F(OnlineAccountClientTestNoMainLoop, refresh_services_no_main_loop) |
672 | +{ |
673 | + auto statuses = oa_client()->get_service_statuses(); |
674 | + EXPECT_EQ(0, statuses.size()); |
675 | + |
676 | + create_account(); |
677 | + oa_client()->refresh_service_statuses(); |
678 | + |
679 | + statuses = oa_client()->get_service_statuses(); |
680 | + EXPECT_EQ(1, statuses.size()); |
681 | + EXPECT_FALSE(statuses[0].service_enabled); |
682 | + |
683 | + enable_service(); |
684 | + oa_client()->refresh_service_statuses(); |
685 | + |
686 | + statuses = oa_client()->get_service_statuses(); |
687 | + EXPECT_TRUE(statuses[0].service_enabled); |
688 | + |
689 | + disable_service(); |
690 | + oa_client()->refresh_service_statuses(); |
691 | + |
692 | + statuses = oa_client()->get_service_statuses(); |
693 | + EXPECT_FALSE(statuses[0].service_enabled); |
694 | + |
695 | + enable_service(); |
696 | + oa_client()->refresh_service_statuses(); |
697 | + |
698 | + statuses = oa_client()->get_service_statuses(); |
699 | + EXPECT_TRUE(statuses[0].service_enabled); |
700 | + |
701 | + disable_account(); |
702 | + oa_client()->refresh_service_statuses(); |
703 | + |
704 | + statuses = oa_client()->get_service_statuses(); |
705 | + EXPECT_FALSE(statuses[0].service_enabled); |
706 | + |
707 | + enable_account(); |
708 | + oa_client()->refresh_service_statuses(); |
709 | + |
710 | + statuses = oa_client()->get_service_statuses(); |
711 | + EXPECT_TRUE(statuses[0].service_enabled); |
712 | +} |
713 | + |
714 | +TEST_F(OnlineAccountClientTestNoMainLoop, pub_sub_authentication) |
715 | +{ |
716 | + std::shared_ptr<OnlineAccountClient> shell_oa_client; |
717 | + shell_oa_client.reset(new OnlineAccountClient("TestService", "sharing", "TestProvider", OnlineAccountClient::RunInExternalUiMainLoop)); |
718 | + |
719 | + std::shared_ptr<OnlineAccountClient> scope_oa_client; |
720 | + scope_oa_client.reset(new OnlineAccountClient("TestService", "sharing", "TestProvider", OnlineAccountClient::RunInExternalMainLoop)); |
721 | + |
722 | + create_account(); |
723 | + scope_oa_client->refresh_service_statuses(); |
724 | + |
725 | + std::shared_ptr<AccountInfo> info(new AccountInfo); |
726 | + info->account_id = 1; |
727 | + info->service_enabled = true; |
728 | + { |
729 | + GVariantDict dict; |
730 | + g_variant_dict_init(&dict, nullptr); |
731 | + g_variant_dict_insert(&dict, "ConsumerKey", "s", "isuertbiseruy87srkuthksvu"); |
732 | + g_variant_dict_insert(&dict, "ConsumerSecret", "s", "rytwekfgiodng523dr4"); |
733 | + info->auth_params.reset(g_variant_ref_sink(g_variant_dict_end(&dict)), safe_g_variant_free_); |
734 | + } |
735 | + { |
736 | + GVariantDict dict; |
737 | + g_variant_dict_init(&dict, nullptr); |
738 | + g_variant_dict_insert(&dict, "AccessToken", "s", "sfhgbfgutgi9ugwirheg74"); |
739 | + g_variant_dict_insert(&dict, "TokenSecret", "s", "qwpeurylsfdg83"); |
740 | + info->session_data.reset(g_variant_ref_sink(g_variant_dict_end(&dict)), safe_g_variant_free_); |
741 | + } |
742 | + |
743 | + // Invoke callback on shell_oa_client which should invoke a callback on scope_oa_client via pub/sub |
744 | + scope_oa_client->set_service_update_callback(std::bind(&OnlineAccountClientTest::service_update_auth, this, std::placeholders::_1)); |
745 | + invoke_callback(shell_oa_client, info.get(), "not really an error, but just to test"); |
746 | + wait_for_service_update(); |
747 | +} |
748 | + |
749 | +int main(int argc, char **argv) |
750 | +{ |
751 | + std::shared_ptr<DbusTestService> dbus_test_service; |
752 | + dbus_test_service.reset(dbus_test_service_new(nullptr), g_object_unref); |
753 | + dbus_test_service_run(dbus_test_service.get()); |
754 | + |
755 | + ::testing::InitGoogleTest(&argc, argv); |
756 | + return RUN_ALL_TESTS(); |
757 | } |
758 | |
759 | === added directory 'test/gtest/scopes/OnlineAccountClient/data' |
760 | === added file 'test/gtest/scopes/OnlineAccountClient/data/TestService.service' |
761 | --- test/gtest/scopes/OnlineAccountClient/data/TestService.service 1970-01-01 00:00:00 +0000 |
762 | +++ test/gtest/scopes/OnlineAccountClient/data/TestService.service 2014-10-08 11:04:26 +0000 |
763 | @@ -0,0 +1,26 @@ |
764 | +<?xml version="1.0" encoding="UTF-8" ?> |
765 | +<service id="TestService"> |
766 | + <type>sharing</type> |
767 | + <name>Test Service</name> |
768 | + <provider>TestProvider</provider> |
769 | + <template> |
770 | + <group name="auth"> |
771 | + <setting name="method">oauth2</setting> |
772 | + <setting name="mechanism">web_server</setting> |
773 | + <group name="oauth2"> |
774 | + <group name="web_server"> |
775 | + <setting name="Host">accounts.test.com</setting> |
776 | + |
777 | + <setting name="AuthPath">o/oauth2/auth?access_type=offline</setting> |
778 | + <setting name="TokenPath">o/oauth2/token</setting> |
779 | + <setting name="RedirectUri">https://wiki.ubuntu.com/</setting> |
780 | + <setting name="ResponseType">code</setting> |
781 | + <setting type="as" name="Scope">['https://www.test.com/auth/test.readonly']</setting> |
782 | + <setting name="ClientId">69842936499-sdflkbhslufhgrjamwlicefhb.apps.test.com</setting> |
783 | + <setting name="ClientSecret">lj3i8iorep0w03994jwjef0j</setting> |
784 | + <setting type="as" name="AllowedSchemes">['https','http']</setting> |
785 | + </group> |
786 | + </group> |
787 | + </group> |
788 | + </template> |
789 | +</service> |
790 | |
791 | === modified file 'valgrind-suppress' |
792 | --- valgrind-suppress 2014-09-25 09:43:35 +0000 |
793 | +++ valgrind-suppress 2014-10-08 11:04:26 +0000 |
794 | @@ -212,3 +212,24 @@ |
795 | Memcheck:Cond |
796 | fun:ag_auth_data_unref |
797 | } |
798 | + |
799 | +{ |
800 | + malloc[Memcheck:Leak] |
801 | + Memcheck:Leak |
802 | + fun:malloc |
803 | + fun:g_malloc |
804 | + fun:g_slice_alloc |
805 | + fun:g_slice_alloc0 |
806 | + ... |
807 | + fun:ag_manager_get_service |
808 | + ... |
809 | + fun:ag_manager_list_services_by_type |
810 | + fun:ag_account_list_services |
811 | +} |
812 | + |
813 | +{ |
814 | + operator new(unsigned long)[Memcheck:Leak] |
815 | + Memcheck:Leak |
816 | + fun:_Znwm |
817 | + fun:_ZNSs4_Rep9_S_createEmmRKSaIcE |
818 | +} |
PASSED: Continuous integration, rev:276 jenkins. qa.ubuntu. com/job/ unity-scopes- api-ci/ 472/ jenkins. qa.ubuntu. com/job/ unity-scopes- api-utopic- amd64-ci/ 99 jenkins. qa.ubuntu. com/job/ unity-scopes- api-utopic- armhf-ci/ 99 jenkins. qa.ubuntu. com/job/ unity-scopes- api-utopic- armhf-ci/ 99/artifact/ work/output/ *zip*/output. zip jenkins. qa.ubuntu. com/job/ unity-scopes- api-utopic- i386-ci/ 99
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/unity- scopes- api-ci/ 472/rebuild
http://