Rename the library subdirectory to libsecret
[platform/upstream/libsecret.git] / libsecret / tests / test-store-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": "9", "string": "nine", "even": "false" };
25
26 var password = Secret.password_lookup_sync (STORE_SCHEMA, attributes, null);
27 assertEquals(null, password);
28
29 var stored = Secret.password_store_sync (STORE_SCHEMA, attributes, Secret.COLLECTION_DEFAULT,
30                                          "The number nine", "999", null);
31 assertEquals(true, stored);
32
33 var password = Secret.password_lookup_sync (STORE_SCHEMA, attributes, null);
34 assertEquals("999", password);
35
36
37 /* Asynchronous */ 
38
39 var attributes = { "number": "888", "string": "eight", "even": "true" };
40
41 var password = Secret.password_lookup_sync (STORE_SCHEMA, attributes, null);
42 assertEquals(null, password);
43
44 var loop = new GLib.MainLoop.new(null, false);
45
46 Secret.password_store (STORE_SCHEMA, attributes, null, "The number eight", "888",
47                        null, function(source, result) {
48         loop.quit();
49         var stored = Secret.password_store_finish(result);
50         assertEquals(true, stored);
51 });
52
53 loop.run();
54
55 var password = Secret.password_lookup_sync (STORE_SCHEMA, attributes, null);
56 assertEquals("888", password);
57
58 Mock.stop();