~ubuntu-multiseat/ubuntu/saucy/unity-greeter/bug1201122

« back to all changes in this revision

Viewing changes to tests/test.vala

Tags: upstream-12.10.3
ImportĀ upstreamĀ versionĀ 12.10.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
public class Test
 
3
{
 
4
    private static MainWindow setup ()
 
5
    {
 
6
        TestMainWindow main_window = new TestMainWindow ();
 
7
        var list = new TestList (main_window.get_background (), main_window.menubar);
 
8
        main_window.push_list (list);
 
9
        main_window.show_all();
 
10
        // Make sure we are really shown
 
11
        process_events ();
 
12
 
 
13
        return main_window;
 
14
    }
 
15
 
 
16
    private static void process_events ()
 
17
    {
 
18
        while (Gtk.events_pending ())
 
19
            Gtk.main_iteration ();
 
20
    }
 
21
 
 
22
    private static void wait_for_scrolling_end (TestList list)
 
23
    {
 
24
        while (list.is_scrolling ())
 
25
        {
 
26
            process_events ();
 
27
            Posix.usleep (10000);
 
28
        }
 
29
    }
 
30
 
 
31
    // BEGIN This group of functions asume email/password for remote directory servers
 
32
    private static DashEntry remote_directory_entry_email_field (TestList list)
 
33
    {
 
34
        var fixed = list.selected_entry.get_child() as Gtk.Fixed;
 
35
        var grid = fixed.get_children().nth_data(1) as Gtk.Grid;
 
36
        return grid.get_child_at(1, 1) as DashEntry;
 
37
    }
 
38
 
 
39
    private static DashEntry remote_directory_entry_password_field (TestList list)
 
40
    {
 
41
        var fixed = list.selected_entry.get_child() as Gtk.Fixed;
 
42
        var grid = fixed.get_children().nth_data(1) as Gtk.Grid;
 
43
        return grid.get_child_at(1, 2) as DashEntry;
 
44
    }
 
45
    // END This group of functions asume email/password for remote directory servers
 
46
 
 
47
    // BEGIN This group of functions asume domain/username/password for remote login servers
 
48
    private static DashEntry remote_login_entry_domain_field (TestList list)
 
49
    {
 
50
        var fixed = list.selected_entry.get_child() as Gtk.Fixed;
 
51
        var grid = fixed.get_children().nth_data(1) as Gtk.Grid;
 
52
        return grid.get_child_at(1, 1) as DashEntry;
 
53
    }
 
54
 
 
55
    private static DashEntry remote_login_entry_username_field (TestList list)
 
56
    {
 
57
        var fixed = list.selected_entry.get_child() as Gtk.Fixed;
 
58
        var grid = fixed.get_children().nth_data(1) as Gtk.Grid;
 
59
        return grid.get_child_at(1, 2) as DashEntry;
 
60
    }
 
61
 
 
62
    private static DashEntry remote_login_entry_password_field (TestList list)
 
63
    {
 
64
        var fixed = list.selected_entry.get_child() as Gtk.Fixed;
 
65
        var grid = fixed.get_children().nth_data(1) as Gtk.Grid;
 
66
        return grid.get_child_at(1, 3) as DashEntry;
 
67
    }
 
68
    // BEGIN This group of functions asume domain/username/password for remote login servers
 
69
 
 
70
    private static void do_scroll (TestList list, GreeterList.ScrollTarget direction)
 
71
    {
 
72
        process_events ();
 
73
        switch (direction)
 
74
        {
 
75
            case GreeterList.ScrollTarget.START:
 
76
                inject_key (list, Gdk.Key.Page_Up);
 
77
            break;
 
78
            case GreeterList.ScrollTarget.END:
 
79
                inject_key (list, Gdk.Key.Page_Down);
 
80
            break;
 
81
            case GreeterList.ScrollTarget.UP:
 
82
                inject_key (list, Gdk.Key.Up);
 
83
            break;
 
84
            case GreeterList.ScrollTarget.DOWN:
 
85
                inject_key (list, Gdk.Key.Down);
 
86
            break;
 
87
        }
 
88
        wait_for_scrolling_end (list);
 
89
    }
 
90
 
 
91
    private static void scroll_to_remote_login (TestList list)
 
92
    {
 
93
        do_scroll (list, GreeterList.ScrollTarget.END);
 
94
        while (list.selected_entry.id == "*guest")
 
95
        {
 
96
            do_scroll (list, GreeterList.ScrollTarget.END);
 
97
            process_events ();
 
98
            Posix.usleep (10000);
 
99
        }
 
100
    }
 
101
 
 
102
    private static void inject_key (Gtk.Widget w, int keyval)
 
103
    {
 
104
        // Make sure everything is flushed
 
105
        process_events ();
 
106
 
 
107
        Gdk.KeymapKey[] keys;
 
108
 
 
109
        bool success = Gdk.Keymap.get_default ().get_entries_for_keyval (keyval, out keys);
 
110
        GLib.assert (success);
 
111
        Gdk.Event event = new Gdk.Event(Gdk.EventType.KEY_PRESS);
 
112
        event.key.window = w.get_parent_window ();
 
113
        event.key.hardware_keycode = (int16)keys[0].keycode;
 
114
        event.key.keyval = keyval;
 
115
        event.set_device(Gdk.Display.get_default ().get_device_manager ().get_client_pointer ());
 
116
        event.key.time = Gdk.CURRENT_TIME;
 
117
 
 
118
        Gtk.main_do_event (event);
 
119
    }
 
120
 
 
121
    private static void wait_for_focus (Gtk.Widget w)
 
122
    {
 
123
        while (!w.has_focus)
 
124
        {
 
125
            process_events ();
 
126
            Posix.usleep (10000);
 
127
        }
 
128
    }
 
129
 
 
130
    public static void simple_navigation ()
 
131
    {
 
132
        MainWindow mw = setup ();
 
133
        TestList list = mw.stack.top () as TestList;
 
134
 
 
135
        // Wait until remote login appears
 
136
        scroll_to_remote_login (list);
 
137
 
 
138
        GLib.assert (list.num_entries() == 30);
 
139
 
 
140
        // Make sure we are at the beginning of the list
 
141
        do_scroll (list, GreeterList.ScrollTarget.START);
 
142
        GLib.assert (list.selected_entry.id == "active");
 
143
 
 
144
        // Scrolling up does nothing
 
145
        do_scroll (list, GreeterList.ScrollTarget.UP);
 
146
        GLib.assert (list.selected_entry.id == "active");
 
147
 
 
148
        // Scrolling down works
 
149
        do_scroll (list, GreeterList.ScrollTarget.DOWN);
 
150
        GLib.assert (list.selected_entry.id == "auth-error");
 
151
 
 
152
        // Remote Login is at the end;
 
153
        do_scroll (list, GreeterList.ScrollTarget.END);
 
154
        GLib.assert (list.selected_entry.id == "*remote_directory*http://crazyurl.com");
 
155
 
 
156
        mw.hide ();
 
157
    }
 
158
 
 
159
    public static void remote_login ()
 
160
    {
 
161
        MainWindow mw = setup ();
 
162
        TestList list = mw.stack.top () as TestList;
 
163
 
 
164
        // Wait until remote login appears
 
165
        scroll_to_remote_login (list);
 
166
        GLib.assert (list.selected_entry.id == "*remote_directory*http://crazyurl.com");
 
167
        GLib.assert (!list.selected_entry.has_errors);
 
168
 
 
169
        // If we answer without filling in any field -> error
 
170
        list.selected_entry.respond ({});
 
171
        GLib.assert (list.selected_entry.has_errors);
 
172
 
 
173
        // Go to first and back to last to clear the error
 
174
        do_scroll (list, GreeterList.ScrollTarget.START);
 
175
        do_scroll (list, GreeterList.ScrollTarget.END);
 
176
        GLib.assert (!list.selected_entry.has_errors);
 
177
 
 
178
        // Fill in a valid email and password
 
179
        // Check there is no error and we moved to the last logged in server
 
180
        var email = remote_directory_entry_email_field (list);
 
181
        var pwd = remote_directory_entry_password_field (list);
 
182
        email.text = "a@canonical.com";
 
183
        pwd.text = "password";
 
184
        list.selected_entry.respond ({});
 
185
        GLib.assert (!list.selected_entry.has_errors);
 
186
        GLib.assert (list.selected_entry.id == "*remote_login*http://rdpdefaultusername2.com");
 
187
        wait_for_scrolling_end (list);
 
188
 
 
189
        // Go back to the remote_directory entry and write the same password but an invalid email
 
190
        // Check there is error and we did not move anywhere
 
191
        while (!list.selected_entry.id.has_prefix("*remote_directory*http://crazyurl.com"))
 
192
            do_scroll (list, GreeterList.ScrollTarget.UP);
 
193
        email = remote_directory_entry_email_field (list);
 
194
        pwd = remote_directory_entry_password_field (list);
 
195
        email.text = "a @ foobar";
 
196
        pwd.text = "password";
 
197
        list.selected_entry.respond ({});
 
198
        GLib.assert (list.selected_entry.has_errors);
 
199
        GLib.assert (list.selected_entry.id == "*remote_directory*http://crazyurl.com");
 
200
 
 
201
        mw.hide ();
 
202
    }
 
203
 
 
204
    public static void remote_login_servers_updated_signal ()
 
205
    {
 
206
        MainWindow mw = setup ();
 
207
        TestList list = mw.stack.top () as TestList;
 
208
 
 
209
        // Wait until remote login appears
 
210
        scroll_to_remote_login (list);
 
211
 
 
212
        var email = remote_directory_entry_email_field (list);
 
213
        var pwd = remote_directory_entry_password_field (list);
 
214
        email.text = "a@canonical.com";
 
215
        pwd.text = "delay1";
 
216
        list.selected_entry.respond ({});
 
217
        GLib.assert (!list.selected_entry.has_errors);
 
218
        GLib.assert (list.selected_entry.id == "*remote_login*http://rdpdefaultusername2.com");
 
219
 
 
220
        bool done = false;
 
221
        // The delay1 code triggers at 5 seconds
 
222
        Timeout.add (5250, () =>
 
223
            {
 
224
                // If the directory server where were browsing disappears the login servers are removed too
 
225
                // and we get moved to the new directory server
 
226
                wait_for_scrolling_end (list);
 
227
                GLib.assert (list.selected_entry.id == "*remote_directory*http://internalcompayserver.com");
 
228
                done = true;
 
229
                return false;
 
230
            }
 
231
        );
 
232
 
 
233
        while (!done)
 
234
        {
 
235
            process_events ();
 
236
            Posix.usleep (10000);
 
237
        }
 
238
 
 
239
        mw.hide ();
 
240
    }
 
241
 
 
242
    public static void remote_login_servers_updated_signal_focus_not_in_remote_server ()
 
243
    {
 
244
        MainWindow mw = setup ();
 
245
        TestList list = mw.stack.top () as TestList;
 
246
 
 
247
        // Wait until remote login appears
 
248
        scroll_to_remote_login (list);
 
249
 
 
250
        var email = remote_directory_entry_email_field (list);
 
251
        var pwd = remote_directory_entry_password_field (list);
 
252
        email.text = "a@canonical.com";
 
253
        pwd.text = "delay1";
 
254
        list.selected_entry.respond ({});
 
255
        GLib.assert (!list.selected_entry.has_errors);
 
256
        GLib.assert (list.selected_entry.id == "*remote_login*http://rdpdefaultusername2.com");
 
257
        wait_for_scrolling_end (list);
 
258
 
 
259
        while (list.selected_entry.id.has_prefix("*remote_"))
 
260
        {
 
261
            do_scroll (list, GreeterList.ScrollTarget.UP);
 
262
        }
 
263
        string nonRemoteEntry = list.selected_entry.id;
 
264
 
 
265
        bool done = false;
 
266
        // The delay1 code triggers at 5 seconds
 
267
        Timeout.add (5250, () =>
 
268
            {
 
269
                // If we were not in a remote entry we are not moved even if the directory servers change
 
270
                // Moving down we find the new directory server
 
271
                GLib.assert (list.selected_entry.id == nonRemoteEntry);
 
272
                do_scroll (list, GreeterList.ScrollTarget.DOWN);
 
273
                GLib.assert (list.selected_entry.id == "*remote_directory*http://internalcompayserver.com");
 
274
                done = true;
 
275
                return false;
 
276
            }
 
277
        );
 
278
 
 
279
        while (!done)
 
280
        {
 
281
            process_events ();
 
282
            Posix.usleep (10000);
 
283
        }
 
284
 
 
285
        mw.hide ();
 
286
    }
 
287
 
 
288
    public static void remote_login_login_servers_updated_signal ()
 
289
    {
 
290
        MainWindow mw = setup ();
 
291
        TestList list = mw.stack.top () as TestList;
 
292
 
 
293
        // Wait until remote login appears
 
294
        scroll_to_remote_login (list);
 
295
 
 
296
        var email = remote_directory_entry_email_field (list);
 
297
        var pwd = remote_directory_entry_password_field (list);
 
298
        email.text = "a@canonical.com";
 
299
        pwd.text = "delay2";
 
300
        list.selected_entry.respond ({});
 
301
        GLib.assert (!list.selected_entry.has_errors);
 
302
        GLib.assert (list.selected_entry.id == "*remote_login*http://rdpdefaultusername2.com");
 
303
 
 
304
        bool done = false;
 
305
        // The delay2 code triggers at 5 seconds
 
306
        Timeout.add (5250, () =>
 
307
            {
 
308
                // If the login server we were disappears we get moved to a different one
 
309
                wait_for_scrolling_end (list);
 
310
                GLib.assert (list.selected_entry.id == "*remote_login*http://megacoolrdpserver.com");
 
311
                done = true;
 
312
                return false;
 
313
            }
 
314
        );
 
315
 
 
316
        while (!done)
 
317
        {
 
318
            process_events ();
 
319
            Posix.usleep (10000);
 
320
        }
 
321
 
 
322
        mw.hide ();
 
323
    }
 
324
 
 
325
    public static void remote_login_login_servers_updated_signal_focus_not_in_removed_server ()
 
326
    {
 
327
        MainWindow mw = setup ();
 
328
        TestList list = mw.stack.top () as TestList;
 
329
 
 
330
        // Wait until remote login appears
 
331
        scroll_to_remote_login (list);
 
332
 
 
333
        var email = remote_directory_entry_email_field (list);
 
334
        var pwd = remote_directory_entry_password_field (list);
 
335
        email.text = "a@canonical.com";
 
336
        pwd.text = "delay2";
 
337
        list.selected_entry.respond ({});
 
338
        GLib.assert (!list.selected_entry.has_errors);
 
339
        GLib.assert (list.selected_entry.id == "*remote_login*http://rdpdefaultusername2.com");
 
340
 
 
341
        // Move to a server that won't be removed
 
342
        while (list.selected_entry.id != "*remote_login*http://coolrdpserver.com")
 
343
            do_scroll (list, GreeterList.ScrollTarget.UP);
 
344
 
 
345
        bool done = false;
 
346
        // The delay2 code triggers at 5 seconds
 
347
        Timeout.add (5250, () =>
 
348
            {
 
349
                // If the login server we were did not disappear we are still in the same one
 
350
                wait_for_scrolling_end (list);
 
351
                GLib.assert (list.selected_entry.id == "*remote_login*http://coolrdpserver.com");
 
352
                done = true;
 
353
                return false;
 
354
            }
 
355
        );
 
356
 
 
357
        while (!done)
 
358
        {
 
359
            process_events ();
 
360
            Posix.usleep (10000);
 
361
        }
 
362
 
 
363
        mw.hide ();
 
364
    }
 
365
 
 
366
    public static void remote_login_remote_login_changed_signal ()
 
367
    {
 
368
        MainWindow mw = setup ();
 
369
        TestList list = mw.stack.top () as TestList;
 
370
 
 
371
        // Wait until remote login appears
 
372
        scroll_to_remote_login (list);
 
373
 
 
374
        var email = remote_directory_entry_email_field (list);
 
375
        var pwd = remote_directory_entry_password_field (list);
 
376
        email.text = "a@canonical.com";
 
377
        pwd.text = "delay3";
 
378
        list.selected_entry.respond ({});
 
379
        GLib.assert (!list.selected_entry.has_errors);
 
380
        GLib.assert (list.selected_entry.id == "*remote_login*http://rdpdefaultusername2.com");
 
381
 
 
382
        bool done = false;
 
383
        // The delay3 code triggers at 5 seconds
 
384
        Timeout.add (5250, () =>
 
385
            {
 
386
                // If the remote login details change while on one of its servers the login servers are removed
 
387
                // and we get moved to the directory server
 
388
                wait_for_scrolling_end (list);
 
389
                GLib.assert (list.selected_entry.id == "*remote_directory*http://crazyurl.com");
 
390
 
 
391
                do_scroll (list, GreeterList.ScrollTarget.DOWN); // There are no server to log in
 
392
                GLib.assert (list.selected_entry.id == "*remote_directory*http://crazyurl.com");
 
393
 
 
394
                done = true;
 
395
                return false;
 
396
            }
 
397
        );
 
398
 
 
399
        while (!done)
 
400
        {
 
401
            process_events ();
 
402
            Posix.usleep (10000);
 
403
        }
 
404
 
 
405
        mw.hide ();
 
406
    }
 
407
 
 
408
    public static void remote_login_remote_login_changed_signalfocus_not_in_changed_server ()
 
409
    {
 
410
        MainWindow mw = setup ();
 
411
        TestList list = mw.stack.top () as TestList;
 
412
 
 
413
        // Wait until remote login appears
 
414
        scroll_to_remote_login (list);
 
415
 
 
416
        var email = remote_directory_entry_email_field (list);
 
417
        var pwd = remote_directory_entry_password_field (list);
 
418
        email.text = "a@canonical.com";
 
419
        pwd.text = "delay3";
 
420
        list.selected_entry.respond ({});
 
421
        GLib.assert (!list.selected_entry.has_errors);
 
422
        GLib.assert (list.selected_entry.id == "*remote_login*http://rdpdefaultusername2.com");
 
423
        wait_for_scrolling_end (list);
 
424
 
 
425
        while (list.selected_entry.id.has_prefix("*remote_"))
 
426
        {
 
427
            do_scroll (list, GreeterList.ScrollTarget.UP);
 
428
        }
 
429
        string nonRemoteEntry = list.selected_entry.id;
 
430
 
 
431
        bool done = false;
 
432
        // The delay3 code triggers at 5 seconds
 
433
        Timeout.add (5250, () =>
 
434
            {
 
435
                // If we were not in a remote entry we are not moved when we are asked to reauthenticate
 
436
                // What happens is that the login servers of that directory server get removed
 
437
                // Moving down we find the new directory server
 
438
                GLib.assert (list.selected_entry.id == nonRemoteEntry);
 
439
                do_scroll (list, GreeterList.ScrollTarget.DOWN);
 
440
                GLib.assert (list.selected_entry.id == "*remote_directory*http://crazyurl.com");
 
441
 
 
442
                do_scroll (list, GreeterList.ScrollTarget.DOWN); // There are no server to log in
 
443
                GLib.assert (list.selected_entry.id == "*remote_directory*http://crazyurl.com");
 
444
                done = true;
 
445
                return false;
 
446
            }
 
447
        );
 
448
 
 
449
        while (!done)
 
450
        {
 
451
            process_events ();
 
452
            Posix.usleep (10000);
 
453
        }
 
454
 
 
455
        mw.hide ();
 
456
    }
 
457
 
 
458
    public static void remote_login_authentication ()
 
459
    {
 
460
        MainWindow mw = setup ();
 
461
        TestList list = mw.stack.top () as TestList;
 
462
 
 
463
        // Wait until remote login appears
 
464
        scroll_to_remote_login (list);
 
465
        GLib.assert (list.selected_entry.id == "*remote_directory*http://crazyurl.com");
 
466
        GLib.assert (!list.selected_entry.has_errors);
 
467
 
 
468
        // Fill in a valid email and password
 
469
        // Check there is no error and we moved to the last logged in server
 
470
        var email = remote_directory_entry_email_field (list);
 
471
        var pwd = remote_directory_entry_password_field (list);
 
472
        email.text = "a@canonical.com";
 
473
        pwd.text = "password";
 
474
        list.selected_entry.respond ({});
 
475
        GLib.assert (!list.selected_entry.has_errors);
 
476
        GLib.assert (list.selected_entry.id == "*remote_login*http://rdpdefaultusername2.com");
 
477
        wait_for_scrolling_end (list);
 
478
 
 
479
        UnityGreeter.singleton.session_started = false;
 
480
        pwd = remote_login_entry_password_field (list);
 
481
        pwd.text = "password";
 
482
        list.selected_entry.respond ({});
 
483
        GLib.assert (UnityGreeter.singleton.session_started);
 
484
 
 
485
        mw.hide ();
 
486
    }
 
487
 
 
488
    public static void remote_login_cancel_authentication ()
 
489
    {
 
490
        MainWindow mw = setup ();
 
491
        TestList list = mw.stack.top () as TestList;
 
492
 
 
493
        // Wait until remote login appears
 
494
        scroll_to_remote_login (list);
 
495
        GLib.assert (list.selected_entry.id == "*remote_directory*http://crazyurl.com");
 
496
        GLib.assert (!list.selected_entry.has_errors);
 
497
 
 
498
        // Fill in a valid email and password
 
499
        // Check there is no error and we moved to the last logged in server
 
500
        var email = remote_directory_entry_email_field (list);
 
501
        var pwd = remote_directory_entry_password_field (list);
 
502
        email.text = "a@canonical.com";
 
503
        pwd.text = "password";
 
504
        list.selected_entry.respond ({});
 
505
        GLib.assert (!list.selected_entry.has_errors);
 
506
        GLib.assert (list.selected_entry.id == "*remote_login*http://rdpdefaultusername2.com");
 
507
        wait_for_scrolling_end (list);
 
508
 
 
509
        UnityGreeter.singleton.session_started = false;
 
510
        pwd = remote_login_entry_password_field (list);
 
511
        pwd.text = "delay";
 
512
        pwd.activate ();
 
513
        GLib.assert (!list.sensitive); // We are not sensitive because we are waiting for servers answer
 
514
        GLib.assert (pwd.did_respond); // We are showing the spinner
 
515
        list.cancel_authentication ();
 
516
        pwd = remote_login_entry_password_field (list);
 
517
        GLib.assert (list.sensitive); // We are sensitive again because we cancelled the login
 
518
        GLib.assert (!pwd.did_respond); // We are not showing the spinner anymore
 
519
 
 
520
        mw.hide ();
 
521
    }
 
522
 
 
523
    public static void email_autocomplete ()
 
524
    {
 
525
        MainWindow mw = setup ();
 
526
        TestList list = mw.stack.top () as TestList;
 
527
 
 
528
        // Wait until remote login appears
 
529
        scroll_to_remote_login (list);
 
530
 
 
531
        var email = remote_directory_entry_email_field (list);
 
532
 
 
533
        wait_for_focus (email);
 
534
 
 
535
        GLib.assert (email.text.length == 0);
 
536
 
 
537
        inject_key(email, Gdk.Key.a);
 
538
        GLib.assert (email.text == "a");
 
539
 
 
540
        inject_key(email, Gdk.Key.at);
 
541
        GLib.assert (email.text == "a@canonical.com");
 
542
 
 
543
        inject_key(email, Gdk.Key.u);
 
544
        GLib.assert (email.text == "a@ubuntu.org");
 
545
 
 
546
        inject_key(email, Gdk.Key.r);
 
547
        GLib.assert (email.text == "a@urban.net");
 
548
 
 
549
        inject_key(email, Gdk.Key.BackSpace);
 
550
        GLib.assert (email.text == "a@ur");
 
551
 
 
552
        inject_key(email, Gdk.Key.BackSpace);
 
553
        GLib.assert (email.text == "a@u");
 
554
 
 
555
        inject_key(email, Gdk.Key.BackSpace);
 
556
        GLib.assert (email.text == "a@");
 
557
 
 
558
        inject_key(email, Gdk.Key.c);
 
559
        GLib.assert (email.text == "a@canonical.com");
 
560
 
 
561
        inject_key(email, Gdk.Key.a);
 
562
        GLib.assert (email.text == "a@canonical.com");
 
563
 
 
564
        inject_key(email, Gdk.Key.n);
 
565
        GLib.assert (email.text == "a@canonical.com");
 
566
 
 
567
        inject_key(email, Gdk.Key.d);
 
568
        GLib.assert (email.text == "a@candy.com");
 
569
 
 
570
        mw.hide ();
 
571
    }
 
572
 
 
573
    public static void greeter_communcation ()
 
574
    {
 
575
        MainWindow mw = setup ();
 
576
        TestList list = mw.stack.top () as TestList;
 
577
 
 
578
        // Wait until remote login appears
 
579
        scroll_to_remote_login (list);
 
580
 
 
581
        // Fill in a valid email and password
 
582
        // Check there is no error and we moved to the last logged in server
 
583
        var email = remote_directory_entry_email_field (list);
 
584
        var pwd = remote_directory_entry_password_field (list);
 
585
        email.text = "a@canonical.com";
 
586
        pwd.text = "password";
 
587
        list.selected_entry.respond ({});
 
588
        wait_for_scrolling_end (list);
 
589
 
 
590
        while (list.selected_entry.id != "*remote_login*http://coolrdpserver.com")
 
591
            do_scroll (list, GreeterList.ScrollTarget.UP);
 
592
 
 
593
        var domain = remote_login_entry_domain_field (list);
 
594
        var username = remote_login_entry_username_field (list);
 
595
        pwd = remote_login_entry_password_field (list);
 
596
        domain.text = "foo";
 
597
        username.text = "bar";
 
598
        pwd.text = "foobar";
 
599
 
 
600
        UnityGreeter.singleton.show_prompt("remote login:", LightDM.PromptType.QUESTION);
 
601
        GLib.assert (UnityGreeter.singleton.last_respond_response == username.text);
 
602
        UnityGreeter.singleton.show_prompt("remote host:", LightDM.PromptType.QUESTION);
 
603
        GLib.assert (UnityGreeter.singleton.last_respond_response == "http://coolrdpserver.com");
 
604
        UnityGreeter.singleton.show_prompt("domain:", LightDM.PromptType.QUESTION);
 
605
        GLib.assert (UnityGreeter.singleton.last_respond_response == domain.text);
 
606
        UnityGreeter.singleton.show_prompt("password:", LightDM.PromptType.SECRET);
 
607
        GLib.assert (UnityGreeter.singleton.last_respond_response == pwd.text);
 
608
 
 
609
        mw.hide ();
 
610
    }
 
611
 
 
612
    public static void unsupported_server_type ()
 
613
    {
 
614
        MainWindow mw = setup ();
 
615
        TestList list = mw.stack.top () as TestList;
 
616
 
 
617
        // Wait until remote login appears
 
618
        scroll_to_remote_login (list);
 
619
 
 
620
        // Fill in a valid email and password
 
621
        // Check there is no error and we moved to the last logged in server
 
622
        var email = remote_directory_entry_email_field (list);
 
623
        var pwd = remote_directory_entry_password_field (list);
 
624
        email.text = "a@canonical.com";
 
625
        pwd.text = "password";
 
626
        list.selected_entry.respond ({});
 
627
        wait_for_scrolling_end (list);
 
628
 
 
629
        while (list.selected_entry.id != "*remote_login*http://notsupportedserver.com")
 
630
            do_scroll (list, GreeterList.ScrollTarget.UP);
 
631
 
 
632
        GLib.assert (list.selected_entry.has_errors);
 
633
        GLib.assert (!list.selected_entry.sensitive);
 
634
 
 
635
        mw.hide ();
 
636
    }
 
637
 
 
638
    static void setup_gsettings()
 
639
    {
 
640
        try
 
641
        {
 
642
            var dir = GLib.DirUtils.make_tmp ("unity-greeter-test-XXXXXX");
 
643
 
 
644
            var schema_dir = Path.build_filename(dir, "share", "glib-2.0", "schemas");
 
645
            DirUtils.create_with_parents(schema_dir, 0700);
 
646
 
 
647
            var data_dirs = Environment.get_variable("XDG_DATA_DIRS");
 
648
            Environment.set_variable("XDG_DATA_DIRS", "%s:%s".printf(Path.build_filename(dir, "share"), data_dirs), true);
 
649
 
 
650
            if (Posix.system("cp ../data/com.canonical.unity-greeter.gschema.xml %s".printf(schema_dir)) != 0)
 
651
                warning("Could not copy schema to %s", schema_dir);
 
652
 
 
653
            if (Posix.system("glib-compile-schemas %s".printf(schema_dir)) != 0)
 
654
                warning("Could not compile schemas in %s", schema_dir);
 
655
 
 
656
            Environment.set_variable("GSETTINGS_BACKEND", "memory", true);
 
657
        }
 
658
        catch (Error e)
 
659
        {
 
660
            debug ("Error setting up gsettings: %s", e.message);
 
661
        }
 
662
    }
 
663
 
 
664
    public static int main (string[] args)
 
665
    {
 
666
        Gtk.test_init(ref args);
 
667
 
 
668
        setup_gsettings ();
 
669
 
 
670
        UnityGreeter.singleton = new UnityGreeter();
 
671
        UnityGreeter.singleton.test_mode = true;
 
672
 
 
673
        GLib.Test.add_func ("/Simple Navigation", simple_navigation);
 
674
        GLib.Test.add_func ("/Remote Login", remote_login);
 
675
        GLib.Test.add_func ("/Remote Login with Servers Updated signal", remote_login_servers_updated_signal);
 
676
        GLib.Test.add_func ("/Remote Login with Servers Updated signal and not in remote server", remote_login_servers_updated_signal_focus_not_in_remote_server);
 
677
        GLib.Test.add_func ("/Remote Login with Login Servers Updated signal", remote_login_login_servers_updated_signal);
 
678
        GLib.Test.add_func ("/Remote Login with Login Servers Updated signal and not in removed server", remote_login_login_servers_updated_signal_focus_not_in_removed_server);
 
679
        GLib.Test.add_func ("/Remote Login with Remote Login Changed signal", remote_login_remote_login_changed_signal);
 
680
        GLib.Test.add_func ("/Remote Login with Remote Login Changed signal and not in changed server", remote_login_remote_login_changed_signalfocus_not_in_changed_server);
 
681
        GLib.Test.add_func ("/Remote Login authentication", remote_login_authentication);
 
682
        GLib.Test.add_func ("/Remote Login cancel authentication", remote_login_cancel_authentication);
 
683
        GLib.Test.add_func ("/Email Autocomplete", email_autocomplete);
 
684
        GLib.Test.add_func ("/Greeter Communication", greeter_communcation);
 
685
        GLib.Test.add_func ("/Unsupported server type", unsupported_server_type);
 
686
 
 
687
        return GLib.Test.run();
 
688
    }
 
689
 
 
690
}