Bump version number
[platform/upstream/libsecret.git] / library / tests / test-remove-password.js
1
2 const Mock = imports.gi.MockService;
3 const Secret = imports.gi.Secret;
4 const GLib = imports.gi.GLib;
5
6 const JsUnit = imports.jsUnit;
7 const assertEquals = JsUnit.assertEquals;
8 const assertRaises = JsUnit.assertRaises;
9 const assertTrue = JsUnit.assertTrue;
10
11 Mock.start("mock-service-normal.py");
12
13 const STORE_SCHEMA = new Secret.Schema.new("org.mock.Schema",
14         Secret.SchemaFlags.NONE,
15         {
16                 "number": Secret.SchemaAttributeType.INTEGER,
17                 "string": Secret.SchemaAttributeType.STRING,
18                 "even": Secret.SchemaAttributeType.BOOLEAN,
19         }
20 );
21
22 /* Synchronous */
23
24 var attributes = { "number": "1", "string": "one", "even": "false" };
25
26 var password = Secret.password_lookup_sync (STORE_SCHEMA, attributes, null);
27 assertEquals("111", password);
28
29 var deleted = Secret.password_remove_sync (STORE_SCHEMA, attributes, null);
30 assertEquals(true, deleted);
31
32 var password = Secret.password_lookup_sync (STORE_SCHEMA, attributes, null);
33 assertEquals(null, password);
34
35 var deleted = Secret.password_remove_sync (STORE_SCHEMA, attributes, null);
36 assertEquals(false, deleted);
37
38 /* Asynchronous */ 
39
40 var attributes = { "number": "2", "string": "two", "even": "true" };
41
42 var password = Secret.password_lookup_sync (STORE_SCHEMA, attributes, null);
43 assertEquals("222", password);
44
45 var loop = new GLib.MainLoop.new(null, false);
46
47 Secret.password_remove (STORE_SCHEMA, attributes,
48                         null, function(source, result) {
49         loop.quit();
50         var deleted = Secret.password_remove_finish(result);
51         assertEquals(true, deleted);
52 });
53
54 loop.run();
55
56 var password = Secret.password_lookup_sync (STORE_SCHEMA, attributes, null);
57 assertEquals(null, password);
58
59 Secret.password_remove (STORE_SCHEMA, attributes,
60         null, function(source, result) {
61         loop.quit();
62         var deleted = Secret.password_remove_finish(result);
63         assertEquals(false, deleted);
64 });
65
66 loop.run();
67
68 Mock.stop();