4
private static MainWindow setup ()
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
16
private static void process_events ()
18
while (Gtk.events_pending ())
19
Gtk.main_iteration ();
22
private static void wait_for_scrolling_end (TestList list)
24
while (list.is_scrolling ())
31
// BEGIN This group of functions asume email/password for remote directory servers
32
private static DashEntry remote_directory_entry_email_field (TestList list)
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;
39
private static DashEntry remote_directory_entry_password_field (TestList list)
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;
45
// END This group of functions asume email/password for remote directory servers
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)
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;
55
private static DashEntry remote_login_entry_username_field (TestList list)
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;
62
private static DashEntry remote_login_entry_password_field (TestList list)
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;
68
// BEGIN This group of functions asume domain/username/password for remote login servers
70
private static void do_scroll (TestList list, GreeterList.ScrollTarget direction)
75
case GreeterList.ScrollTarget.START:
76
inject_key (list, Gdk.Key.Page_Up);
78
case GreeterList.ScrollTarget.END:
79
inject_key (list, Gdk.Key.Page_Down);
81
case GreeterList.ScrollTarget.UP:
82
inject_key (list, Gdk.Key.Up);
84
case GreeterList.ScrollTarget.DOWN:
85
inject_key (list, Gdk.Key.Down);
88
wait_for_scrolling_end (list);
91
private static void scroll_to_remote_login (TestList list)
93
do_scroll (list, GreeterList.ScrollTarget.END);
94
while (list.selected_entry.id == "*guest")
96
do_scroll (list, GreeterList.ScrollTarget.END);
102
private static void inject_key (Gtk.Widget w, int keyval)
104
// Make sure everything is flushed
107
Gdk.KeymapKey[] keys;
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;
118
Gtk.main_do_event (event);
121
private static void wait_for_focus (Gtk.Widget w)
126
Posix.usleep (10000);
130
public static void simple_navigation ()
132
MainWindow mw = setup ();
133
TestList list = mw.stack.top () as TestList;
135
// Wait until remote login appears
136
scroll_to_remote_login (list);
138
GLib.assert (list.num_entries() == 30);
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");
144
// Scrolling up does nothing
145
do_scroll (list, GreeterList.ScrollTarget.UP);
146
GLib.assert (list.selected_entry.id == "active");
148
// Scrolling down works
149
do_scroll (list, GreeterList.ScrollTarget.DOWN);
150
GLib.assert (list.selected_entry.id == "auth-error");
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");
159
public static void remote_login ()
161
MainWindow mw = setup ();
162
TestList list = mw.stack.top () as TestList;
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);
169
// If we answer without filling in any field -> error
170
list.selected_entry.respond ({});
171
GLib.assert (list.selected_entry.has_errors);
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);
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);
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");
204
public static void remote_login_servers_updated_signal ()
206
MainWindow mw = setup ();
207
TestList list = mw.stack.top () as TestList;
209
// Wait until remote login appears
210
scroll_to_remote_login (list);
212
var email = remote_directory_entry_email_field (list);
213
var pwd = remote_directory_entry_password_field (list);
214
email.text = "a@canonical.com";
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");
221
// The delay1 code triggers at 5 seconds
222
Timeout.add (5250, () =>
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");
236
Posix.usleep (10000);
242
public static void remote_login_servers_updated_signal_focus_not_in_remote_server ()
244
MainWindow mw = setup ();
245
TestList list = mw.stack.top () as TestList;
247
// Wait until remote login appears
248
scroll_to_remote_login (list);
250
var email = remote_directory_entry_email_field (list);
251
var pwd = remote_directory_entry_password_field (list);
252
email.text = "a@canonical.com";
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);
259
while (list.selected_entry.id.has_prefix("*remote_"))
261
do_scroll (list, GreeterList.ScrollTarget.UP);
263
string nonRemoteEntry = list.selected_entry.id;
266
// The delay1 code triggers at 5 seconds
267
Timeout.add (5250, () =>
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");
282
Posix.usleep (10000);
288
public static void remote_login_login_servers_updated_signal ()
290
MainWindow mw = setup ();
291
TestList list = mw.stack.top () as TestList;
293
// Wait until remote login appears
294
scroll_to_remote_login (list);
296
var email = remote_directory_entry_email_field (list);
297
var pwd = remote_directory_entry_password_field (list);
298
email.text = "a@canonical.com";
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");
305
// The delay2 code triggers at 5 seconds
306
Timeout.add (5250, () =>
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");
319
Posix.usleep (10000);
325
public static void remote_login_login_servers_updated_signal_focus_not_in_removed_server ()
327
MainWindow mw = setup ();
328
TestList list = mw.stack.top () as TestList;
330
// Wait until remote login appears
331
scroll_to_remote_login (list);
333
var email = remote_directory_entry_email_field (list);
334
var pwd = remote_directory_entry_password_field (list);
335
email.text = "a@canonical.com";
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");
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);
346
// The delay2 code triggers at 5 seconds
347
Timeout.add (5250, () =>
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");
360
Posix.usleep (10000);
366
public static void remote_login_remote_login_changed_signal ()
368
MainWindow mw = setup ();
369
TestList list = mw.stack.top () as TestList;
371
// Wait until remote login appears
372
scroll_to_remote_login (list);
374
var email = remote_directory_entry_email_field (list);
375
var pwd = remote_directory_entry_password_field (list);
376
email.text = "a@canonical.com";
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");
383
// The delay3 code triggers at 5 seconds
384
Timeout.add (5250, () =>
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");
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");
402
Posix.usleep (10000);
408
public static void remote_login_remote_login_changed_signalfocus_not_in_changed_server ()
410
MainWindow mw = setup ();
411
TestList list = mw.stack.top () as TestList;
413
// Wait until remote login appears
414
scroll_to_remote_login (list);
416
var email = remote_directory_entry_email_field (list);
417
var pwd = remote_directory_entry_password_field (list);
418
email.text = "a@canonical.com";
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);
425
while (list.selected_entry.id.has_prefix("*remote_"))
427
do_scroll (list, GreeterList.ScrollTarget.UP);
429
string nonRemoteEntry = list.selected_entry.id;
432
// The delay3 code triggers at 5 seconds
433
Timeout.add (5250, () =>
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");
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");
452
Posix.usleep (10000);
458
public static void remote_login_authentication ()
460
MainWindow mw = setup ();
461
TestList list = mw.stack.top () as TestList;
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);
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);
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);
488
public static void remote_login_cancel_authentication ()
490
MainWindow mw = setup ();
491
TestList list = mw.stack.top () as TestList;
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);
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);
509
UnityGreeter.singleton.session_started = false;
510
pwd = remote_login_entry_password_field (list);
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
523
public static void email_autocomplete ()
525
MainWindow mw = setup ();
526
TestList list = mw.stack.top () as TestList;
528
// Wait until remote login appears
529
scroll_to_remote_login (list);
531
var email = remote_directory_entry_email_field (list);
533
wait_for_focus (email);
535
GLib.assert (email.text.length == 0);
537
inject_key(email, Gdk.Key.a);
538
GLib.assert (email.text == "a");
540
inject_key(email, Gdk.Key.at);
541
GLib.assert (email.text == "a@canonical.com");
543
inject_key(email, Gdk.Key.u);
544
GLib.assert (email.text == "a@ubuntu.org");
546
inject_key(email, Gdk.Key.r);
547
GLib.assert (email.text == "a@urban.net");
549
inject_key(email, Gdk.Key.BackSpace);
550
GLib.assert (email.text == "a@ur");
552
inject_key(email, Gdk.Key.BackSpace);
553
GLib.assert (email.text == "a@u");
555
inject_key(email, Gdk.Key.BackSpace);
556
GLib.assert (email.text == "a@");
558
inject_key(email, Gdk.Key.c);
559
GLib.assert (email.text == "a@canonical.com");
561
inject_key(email, Gdk.Key.a);
562
GLib.assert (email.text == "a@canonical.com");
564
inject_key(email, Gdk.Key.n);
565
GLib.assert (email.text == "a@canonical.com");
567
inject_key(email, Gdk.Key.d);
568
GLib.assert (email.text == "a@candy.com");
573
public static void greeter_communcation ()
575
MainWindow mw = setup ();
576
TestList list = mw.stack.top () as TestList;
578
// Wait until remote login appears
579
scroll_to_remote_login (list);
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);
590
while (list.selected_entry.id != "*remote_login*http://coolrdpserver.com")
591
do_scroll (list, GreeterList.ScrollTarget.UP);
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);
597
username.text = "bar";
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);
612
public static void unsupported_server_type ()
614
MainWindow mw = setup ();
615
TestList list = mw.stack.top () as TestList;
617
// Wait until remote login appears
618
scroll_to_remote_login (list);
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);
629
while (list.selected_entry.id != "*remote_login*http://notsupportedserver.com")
630
do_scroll (list, GreeterList.ScrollTarget.UP);
632
GLib.assert (list.selected_entry.has_errors);
633
GLib.assert (!list.selected_entry.sensitive);
638
static void setup_gsettings()
642
var dir = GLib.DirUtils.make_tmp ("unity-greeter-test-XXXXXX");
644
var schema_dir = Path.build_filename(dir, "share", "glib-2.0", "schemas");
645
DirUtils.create_with_parents(schema_dir, 0700);
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);
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);
653
if (Posix.system("glib-compile-schemas %s".printf(schema_dir)) != 0)
654
warning("Could not compile schemas in %s", schema_dir);
656
Environment.set_variable("GSETTINGS_BACKEND", "memory", true);
660
debug ("Error setting up gsettings: %s", e.message);
664
public static int main (string[] args)
666
Gtk.test_init(ref args);
670
UnityGreeter.singleton = new UnityGreeter();
671
UnityGreeter.singleton.test_mode = true;
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);
687
return GLib.Test.run();