Use upstream tag
[platform/upstream/libsecret.git] / libsecret / test-js-lookup.js
1 /*
2  * Copyright 2012 Red Hat Inc.
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published
6  * by the Free Software Foundation; either version 2.1 of the licence or (at
7  * your option) any later version.
8  *
9  * See the included COPYING file for more information.
10  */
11
12 const Mock = imports.gi.MockService;
13 const Secret = imports.gi.Secret;
14 const GLib = imports.gi.GLib;
15
16 const JsUnit = imports.jsUnit;
17 const assertEquals = JsUnit.assertEquals;
18 const assertRaises = JsUnit.assertRaises;
19 const assertTrue = JsUnit.assertTrue;
20
21 Mock.start("mock-service-normal.py");
22
23 const STORE_SCHEMA = new Secret.Schema("org.mock.Schema",
24         Secret.SchemaFlags.NONE,
25         {
26                 "number": Secret.SchemaAttributeType.INTEGER,
27                 "string": Secret.SchemaAttributeType.STRING,
28                 "even": Secret.SchemaAttributeType.BOOLEAN,
29         }
30 );
31
32 /* Synchronous */
33
34 var password = Secret.password_lookup_sync (STORE_SCHEMA, { "number": "1", "even": "false" }, null);
35 assertEquals("111", password);
36
37 var password = Secret.password_lookup_sync (STORE_SCHEMA, { "number": "5", "even": "true" }, null);
38 assertEquals(null, password);
39
40 /* Asynchronous */
41
42 var loop = new GLib.MainLoop(null, false);
43
44 Secret.password_lookup (STORE_SCHEMA, { "number": "2", "string": "two" },
45                         null, function(source, result) {
46         loop.quit();
47         var password = Secret.password_lookup_finish(result);
48         assertEquals("222", password);
49 });
50
51 loop.run();
52
53 Secret.password_lookup (STORE_SCHEMA, { "number": "7", "string": "five" },
54         null, function(source, result) {
55         loop.quit();
56         var password = Secret.password_lookup_finish(result);
57         assertEquals(null, password);
58 });
59
60 loop.run();
61
62 Secret.Service.disconnect();
63 Mock.stop();