Use upstream tag
[platform/upstream/libsecret.git] / libsecret / test-js-clear.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 attributes = { "number": "1", "string": "one", "even": "false" };
35
36 var password = Secret.password_lookup_sync (STORE_SCHEMA, attributes, null);
37 assertEquals("111", password);
38
39 var deleted = Secret.password_clear_sync (STORE_SCHEMA, attributes, null);
40 assertEquals(true, deleted);
41
42 var password = Secret.password_lookup_sync (STORE_SCHEMA, attributes, null);
43 assertEquals(null, password);
44
45 var deleted = Secret.password_clear_sync (STORE_SCHEMA, attributes, null);
46 assertEquals(false, deleted);
47 */
48
49 /* Asynchronous */
50
51 var attributes = { "number": "2", "string": "two", "even": "true" };
52
53 var password = Secret.password_lookup_sync (STORE_SCHEMA, attributes, null);
54 assertEquals("222", password);
55
56 var loop = new GLib.MainLoop(null, false);
57
58 Secret.password_clear (STORE_SCHEMA, attributes,
59                        null, function(source, result) {
60         loop.quit();
61         var deleted = Secret.password_clear_finish(result);
62         assertEquals(true, deleted);
63 });
64
65 loop.run();
66
67 var password = Secret.password_lookup_sync (STORE_SCHEMA, attributes, null);
68 assertEquals(null, password);
69
70 Secret.password_clear (STORE_SCHEMA, attributes,
71         null, function(source, result) {
72         loop.quit();
73         var deleted = Secret.password_clear_finish(result);
74         assertEquals(false, deleted);
75 });
76
77 loop.run();
78
79 var password = Secret.password_lookup_sync (STORE_SCHEMA, attributes, null);
80 assertEquals(null, password);
81
82 Secret.Service.disconnect();
83 Mock.stop();