Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TestPad.cs « Gui « NUnit « addins « src « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 96b5f929bb83c8b8ddabc1a85b65c5f38e01c75a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
//
// TestPad.cs
//
// Author:
//   Lluis Sanchez Gual
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

using System;
using System.Collections;
using Gtk;
using Gdk;

using MonoDevelop.Core;
using MonoDevelop.Core.Execution;
using MonoDevelop.Ide.Gui.Pads;
using MonoDevelop.Components.Commands;
using MonoDevelop.NUnit.Commands;
using MonoDevelop.Ide.Gui.Components;
using MonoDevelop.Ide.Execution;
using MonoDevelop.Components.Docking;
using MonoDevelop.Ide;
using MonoDevelop.Projects;
using Mono.TextEditor;
using System.Linq;
using MonoDevelop.Components;
using MonoDevelop.Ide.Commands;
using System.Collections.Generic;

namespace MonoDevelop.NUnit
{
	public class TestPad : TreeViewPad
	{
		NUnitService testService = NUnitService.Instance;
		
		AsyncOperation runningTestOperation;
		VPaned paned;
		TreeView detailsTree;
		ListStore detailsStore;
		HeaderLabel detailLabel;
		TestChart chart;
		UnitTest detailsTest;
		DateTime detailsDate;
		DateTime detailsReferenceDate;
		ButtonNotebook infoBook;
		TextView outputView;
		TextView resultView;
		TreeView regressionTree;
		ListStore regressionStore;
		TreeView failedTree;
		ListStore failedStore;
		
		int TestSummaryPage;
		int TestRegressionsPage;
		int TestFailuresPage;
		int TestResultPage;
		int TestOutputPage;
		
		VBox detailsPad;
		
		ArrayList testNavigationHistory = new ArrayList ();

		Button buttonRunAll, buttonStop;
		
		public override void Initialize (NodeBuilder[] builders, TreePadOption[] options, string menuPath)
		{
			base.Initialize (builders, options, menuPath);
			
			testService.TestSuiteChanged += OnTestSuiteChanged;
			paned = new VPaned ();
			
			VBox vbox = new VBox ();
			DockItemToolbar topToolbar = Window.GetToolbar (PositionType.Top);

			var hbox = new HBox { Spacing = 6 };
			hbox.PackStart (new ImageView (ImageService.GetIcon ("nunit-run", IconSize.Menu)), false, false, 0);
			hbox.PackStart (new Label (GettextCatalog.GetString ("Run All")), false, false, 0);
			buttonRunAll = new Button (hbox);
			buttonRunAll.Clicked += new EventHandler (OnRunAllClicked);
			buttonRunAll.Sensitive = true;
			buttonRunAll.TooltipText = GettextCatalog.GetString ("Run all tests");
			topToolbar.Add (buttonRunAll);
			
			buttonStop = new Button (new Gtk.Image (Ide.Gui.Stock.Stop, IconSize.Menu));
			buttonStop.Clicked += new EventHandler (OnStopClicked);
			buttonStop.Sensitive = false;
			buttonStop.TooltipText = GettextCatalog.GetString ("Cancel running test");
			topToolbar.Add (buttonStop);
			topToolbar.ShowAll ();
			
			vbox.PackEnd (base.Control, true, true, 0);
			vbox.FocusChain = new Gtk.Widget [] { base.Control };
			
			paned.Pack1 (vbox, true, true);
			
			detailsPad = new VBox ();
			
			EventBox eb = new EventBox ();
			HBox header = new HBox ();
			eb.Add (header);

			detailLabel = new HeaderLabel ();
			detailLabel.Padding = 6;
			
			Button hb = new Button (new Gtk.Image ("gtk-close", IconSize.SmallToolbar));
			hb.Relief = ReliefStyle.None;
			hb.Clicked += new EventHandler (OnCloseDetails);
			header.PackEnd (hb, false, false, 0);
			
			hb = new Button (new Gtk.Image ("gtk-go-back", IconSize.SmallToolbar));
			hb.Relief = ReliefStyle.None;
			hb.Clicked += new EventHandler (OnGoBackTest);
			header.PackEnd (hb, false, false, 0);
			
			header.Add (detailLabel);
			Gdk.Color hcol = eb.Style.Background (StateType.Normal);
			hcol.Red = (ushort) (((double)hcol.Red) * 0.9);
			hcol.Green = (ushort) (((double)hcol.Green) * 0.9);
			hcol.Blue = (ushort) (((double)hcol.Blue) * 0.9);
		//	eb.ModifyBg (StateType.Normal, hcol);
			
			detailsPad.PackStart (eb, false, false, 0);
			
			VPaned panedDetails = new VPaned ();
			panedDetails.BorderWidth = 3;
			VBox boxPaned1 = new VBox ();
			
			chart = new TestChart ();
			chart.ButtonPressEvent += OnChartButtonPress;
			chart.SelectionChanged += new EventHandler (OnChartDateChanged);
			chart.HeightRequest = 50;
			
			Toolbar toolbar = new Toolbar ();
			toolbar.IconSize = IconSize.SmallToolbar;
			toolbar.ToolbarStyle = ToolbarStyle.Icons;
			toolbar.ShowArrow = false;
			ToolButton but = new ToolButton ("gtk-zoom-in");
			but.Clicked += new EventHandler (OnZoomIn);
			toolbar.Insert (but, -1);
			
			but = new ToolButton ("gtk-zoom-out");
			but.Clicked += new EventHandler (OnZoomOut);
			toolbar.Insert (but, -1);
			
			but = new ToolButton ("gtk-go-back");
			but.Clicked += new EventHandler (OnChartBack);
			toolbar.Insert (but, -1);
			
			but = new ToolButton ("gtk-go-forward");
			but.Clicked += new EventHandler (OnChartForward);
			toolbar.Insert (but, -1);
			
			but = new ToolButton ("gtk-goto-last");
			but.Clicked += new EventHandler (OnChartLast);
			toolbar.Insert (but, -1);
			
			boxPaned1.PackStart (toolbar, false, false, 0);
			boxPaned1.PackStart (chart, true, true, 0);
			
			panedDetails.Pack1 (boxPaned1, false, false);
			
			// Detailed test information --------
			
			infoBook = new ButtonNotebook ();
			infoBook.PageLoadRequired += new EventHandler (OnPageLoadRequired);
			
			// Info - Group summary
			
			Frame tf = new Frame ();
			ScrolledWindow sw = new ScrolledWindow ();
			detailsTree = new TreeView ();
			
			detailsTree.HeadersVisible = true;
			detailsTree.RulesHint = true;
			detailsStore = new ListStore (typeof(object), typeof(string), typeof (string), typeof (string), typeof (string));
			
			CellRendererText trtest = new CellRendererText ();
			CellRendererText tr;
			
			TreeViewColumn col3 = new TreeViewColumn ();
			col3.Expand = false;
//			col3.Alignment = 0.5f;
			col3.Widget = new ImageView (TestStatusIcon.Success);
			col3.Widget.Show ();
			tr = new CellRendererText ();
//			tr.Xalign = 0.5f;
			col3.PackStart (tr, false);
			col3.AddAttribute (tr, "markup", 2);
			detailsTree.AppendColumn (col3);
			
			TreeViewColumn col4 = new TreeViewColumn ();
			col4.Expand = false;
//			col4.Alignment = 0.5f;
			col4.Widget = new ImageView (TestStatusIcon.Failure);
			col4.Widget.Show ();
			tr = new CellRendererText ();
//			tr.Xalign = 0.5f;
			col4.PackStart (tr, false);
			col4.AddAttribute (tr, "markup", 3);
			detailsTree.AppendColumn (col4);
			
			TreeViewColumn col5 = new TreeViewColumn ();
			col5.Expand = false;
//			col5.Alignment = 0.5f;
			col5.Widget = new ImageView (TestStatusIcon.NotRun);
			col5.Widget.Show ();
			tr = new CellRendererText ();
//			tr.Xalign = 0.5f;
			col5.PackStart (tr, false);
			col5.AddAttribute (tr, "markup", 4);
			detailsTree.AppendColumn (col5);
			
			TreeViewColumn col1 = new TreeViewColumn ();
//			col1.Resizable = true;
//			col1.Expand = true;
			col1.Title = "Test";
			col1.PackStart (trtest, true);
			col1.AddAttribute (trtest, "markup", 1);
			detailsTree.AppendColumn (col1);
			
			detailsTree.Model = detailsStore;
			
			sw.Add (detailsTree);
			tf.Add (sw);
			tf.ShowAll ();
			
			TestSummaryPage = infoBook.AddPage (GettextCatalog.GetString ("Summary"), tf);
			
			// Info - Regressions list
			
			tf = new Frame ();
			sw = new ScrolledWindow ();
			tf.Add (sw);
			regressionTree = new TreeView ();
			regressionTree.HeadersVisible = false;
			regressionTree.RulesHint = true;
			regressionStore = new ListStore (typeof(object), typeof(string), typeof (Xwt.Drawing.Image));
			
			CellRendererText trtest2 = new CellRendererText ();
			var pr = new CellRendererImage ();
			
			TreeViewColumn col = new TreeViewColumn ();
			col.PackStart (pr, false);
			col.AddAttribute (pr, "image", 2);
			col.PackStart (trtest2, false);
			col.AddAttribute (trtest2, "markup", 1);
			regressionTree.AppendColumn (col);
			regressionTree.Model = regressionStore;
			sw.Add (regressionTree);
			tf.ShowAll ();
			
			TestRegressionsPage = infoBook.AddPage (GettextCatalog.GetString ("Regressions"), tf);
			
			// Info - Failed tests list
			
			tf = new Frame ();
			sw = new ScrolledWindow ();
			tf.Add (sw);
			failedTree = new TreeView ();
			failedTree.HeadersVisible = false;
			failedTree.RulesHint = true;
			failedStore = new ListStore (typeof(object), typeof(string), typeof (Xwt.Drawing.Image));
			
			trtest2 = new CellRendererText ();
			pr = new CellRendererImage ();
			
			col = new TreeViewColumn ();
			col.PackStart (pr, false);
			col.AddAttribute (pr, "image", 2);
			col.PackStart (trtest2, false);
			col.AddAttribute (trtest2, "markup", 1);
			failedTree.AppendColumn (col);
			failedTree.Model = failedStore;
			sw.Add (failedTree);
			tf.ShowAll ();
			
			TestFailuresPage = infoBook.AddPage (GettextCatalog.GetString ("Failed tests"), tf);
			
			// Info - results
			
			tf = new Frame ();
			sw = new ScrolledWindow ();
			tf.Add (sw);
			resultView = new TextView ();
			resultView.Editable = false;
			sw.Add (resultView);
			tf.ShowAll ();
			TestResultPage = infoBook.AddPage (GettextCatalog.GetString ("Result"), tf);
			
			// Info - Output
			
			tf = new Frame ();
			sw = new ScrolledWindow ();
			tf.Add (sw);
			outputView = new TextView ();
			outputView.Editable = false;
			sw.Add (outputView);
			tf.ShowAll ();
			TestOutputPage = infoBook.AddPage (GettextCatalog.GetString ("Output"), tf);
			
			panedDetails.Pack2 (infoBook, true, true);
			detailsPad.PackStart (panedDetails, true, true, 0);
			paned.Pack2 (detailsPad, true, true);
			
			paned.ShowAll ();
			
			infoBook.HidePage (TestResultPage);
			infoBook.HidePage (TestOutputPage);
			infoBook.HidePage (TestSummaryPage);
			infoBook.HidePage (TestRegressionsPage);
			infoBook.HidePage (TestFailuresPage);
			
			detailsPad.Sensitive = false;
			detailsPad.Hide ();
			
			detailsTree.RowActivated += new Gtk.RowActivatedHandler (OnTestActivated);
			regressionTree.RowActivated += new Gtk.RowActivatedHandler (OnRegressionTestActivated);
			failedTree.RowActivated += new Gtk.RowActivatedHandler (OnFailedTestActivated);
			
			foreach (UnitTest t in testService.RootTests)
				TreeView.AddChild (t);
		}
		
		void OnTestSuiteChanged (object sender, EventArgs e)
		{
			if (testService.RootTests.Length > 0) {
				var s = TreeView.SaveTreeState ();
				TreeView.Clear ();
				foreach (UnitTest t in testService.RootTests)
					TreeView.AddChild (t);
				TreeView.RestoreTreeState (s);
			}
			else {
				TreeView.Clear ();
				ClearDetails ();
			}
		}
		
		public void SelectTest (UnitTest t)
		{
			ITreeNavigator node = FindTestNode (t);
			if (node != null) {
				node.ExpandToNode ();
				node.Selected = true;
			}
		}
		
		ITreeNavigator FindTestNode (UnitTest t)
		{
			ITreeNavigator nav = TreeView.GetNodeAtObject (t);
			if (nav != null)
				return nav;
			if (t.Parent == null)
				return null;
				
			nav = FindTestNode (t.Parent);
			
			if (nav == null)
				return null;
				
			nav.MoveToFirstChild ();	// Make sure the children are created
			return TreeView.GetNodeAtObject (t);
		}
		
		public override Gtk.Widget Control {
			get {
				return paned;
			}
		}
		
		[CommandHandler (TestCommands.RunTest)]
		protected void OnRunTest ()
		{
			RunSelectedTest (null);
		}
		
		[CommandUpdateHandler (TestCommands.RunTest)]
		protected void OnUpdateRunTest (CommandInfo info)
		{
			info.Enabled = runningTestOperation == null;
		}
		
		[CommandHandler (TestCommands.RunTestWith)]
		protected void OnRunTest (object data)
		{
			IExecutionHandler h = ExecutionModeCommandService.GetExecutionModeForCommand (data);
			if (h != null)
				RunSelectedTest (h);
		}
		
		[CommandUpdateHandler (TestCommands.RunTestWith)]
		protected void OnUpdateRunTest (CommandArrayInfo info)
		{
			UnitTest test = GetSelectedTest ();
			if (test != null) {
				SolutionItem item = test.OwnerObject as SolutionItem;
				ExecutionModeCommandService.GenerateExecutionModeCommands (
				    item,
				    test.CanRun,
				    info);
			}
		}
		
		[CommandHandler (TestCommands.DebugTest)]
		protected void OnDebugTest (object data)
		{
			var debugModeSet = Runtime.ProcessService.GetDebugExecutionMode ();
			var mode = debugModeSet.ExecutionModes.First (m => m.Id == (string)data);
			RunSelectedTest (mode.ExecutionHandler);
		}

		[CommandUpdateHandler (TestCommands.DebugTest)]
		protected void OnUpdateDebugTest (CommandArrayInfo info)
		{
			var debugModeSet = Runtime.ProcessService.GetDebugExecutionMode ();
			if (debugModeSet == null)
				return;

			UnitTest test = GetSelectedTest ();
			if (test == null)
				return;

			foreach (var mode in debugModeSet.ExecutionModes) {
				if (test.CanRun (mode.ExecutionHandler))
					info.Add (GettextCatalog.GetString ("Debug Test ({0})", mode.Name), mode.Id);
			}
			if (info.Count == 1)
				info [0].Text = GettextCatalog.GetString ("Debug Test");
		}

		public TestPad ()
		{
			base.TreeView.CurrentItemActivated += delegate {
				RunSelectedTest (null);
			};
		}
		
		void OnStopClicked (object sender, EventArgs args)
		{
			if (runningTestOperation != null)
				runningTestOperation.Cancel ();
		}
		
		UnitTest GetSelectedTest ()
		{
			ITreeNavigator nav = TreeView.GetSelectedNode ();
			if (nav == null)
				return null;
			return nav.DataItem as UnitTest;
		}

		public AsyncOperation RunTest (UnitTest test, IExecutionHandler mode)
		{
			return RunTest (FindTestNode (test), mode, false);
		}

		AsyncOperation RunTest (ITreeNavigator nav, IExecutionHandler mode, bool bringToFront = true)
		{
			if (nav == null)
				return null;
			UnitTest test = nav.DataItem as UnitTest;
			if (test == null)
				return null;
			NUnitService.ResetResult (test.RootTest);
			
			this.buttonRunAll.Sensitive = false;
			this.buttonStop.Sensitive = true;

			if (bringToFront)
				IdeApp.Workbench.GetPad<TestPad> ().BringToFront ();
			runningTestOperation = testService.RunTest (test, mode);
			runningTestOperation.Task.ContinueWith (t => OnTestSessionCompleted ());
			return runningTestOperation;
		}
		
		void OnRunAllClicked (object sender, EventArgs args)
		{
			RunTest (TreeView.GetRootNode (), null);
		}
		
		void RunSelectedTest (IExecutionHandler mode)
		{
			RunTest (TreeView.GetSelectedNode (), mode);
		}
		
		void OnTestSessionCompleted ()
		{
			RefreshDetails ();
			runningTestOperation = null;
			this.buttonRunAll.Sensitive = true;
			this.buttonStop.Sensitive = false;

		}


		protected override void OnSelectionChanged (object sender, EventArgs args)
		{
			base.OnSelectionChanged (sender, args);
			ITreeNavigator nav = TreeView.GetSelectedNode ();
			if (nav != null) {
				UnitTest test = nav.DataItem as UnitTest;
				if (test != null)
					FillDetails (test, false);
			}
		}
		
		void OnGoBackTest (object sender, EventArgs args)
		{
			int c = testNavigationHistory.Count;
			if (c > 1) {
				UnitTest t = (UnitTest) testNavigationHistory [c - 2];
				testNavigationHistory.RemoveAt (c - 1);
				testNavigationHistory.RemoveAt (c - 2);
				FillDetails (t, true);
			}
		}
		
		void OnCloseDetails (object sender, EventArgs args)
		{
			detailsPad.Hide ();
		}
		
		[CommandHandler (TestCommands.ShowTestDetails)]
		protected void OnShowDetails ()
		{
			if (!detailsPad.Visible) {
				detailsPad.Show ();
				
				ITreeNavigator nav = TreeView.GetSelectedNode ();
				if (nav != null) {
					UnitTest test = (UnitTest) nav.DataItem;
					FillDetails (test, false);
				} else
					ClearDetails ();
			}
		}
		
		void ClearDetails ()
		{
			chart.Clear ();
			detailLabel.Markup = "";
			detailsStore.Clear ();
			if (detailsTest != null)
				detailsTest.TestChanged -= OnDetailsTestChanged;
			detailsTest = null;
			detailsDate = DateTime.MinValue;
			detailsReferenceDate = DateTime.MinValue;
			detailsPad.Sensitive = false;
		}
		
		void RefreshDetails ()
		{
			if (detailsTest != null)
				FillDetails (detailsTest, false);
		}
		
		void FillDetails (UnitTest test, bool selectInTree)
		{
			if (!detailsPad.Visible)
				return;

			detailsPad.Sensitive = true;
			
			if (detailsTest != null)
				detailsTest.TestChanged -= OnDetailsTestChanged;
			
			if (detailsTest != test) {
				detailsTest = test;
				if (selectInTree)
					SelectTest (test);
				testNavigationHistory.Add (test);
				if (testNavigationHistory.Count > 50)
					testNavigationHistory.RemoveAt (0);
			}
			detailsTest.TestChanged += OnDetailsTestChanged;
			
			if (test is UnitTestGroup) {
				infoBook.HidePage (TestResultPage);
				infoBook.HidePage (TestOutputPage);
				infoBook.ShowPage (TestSummaryPage);
				infoBook.ShowPage (TestRegressionsPage);
				infoBook.ShowPage (TestFailuresPage);
			} else {
				infoBook.HidePage (TestSummaryPage);
				infoBook.HidePage (TestRegressionsPage);
				infoBook.HidePage (TestFailuresPage);
				infoBook.ShowPage (TestResultPage);
				infoBook.ShowPage (TestOutputPage);
			}
			detailLabel.Markup = "<b>" + test.Name + "</b>";
			detailsDate = DateTime.MinValue;
			detailsReferenceDate = DateTime.MinValue;
			chart.Fill (test);
			infoBook.Reset ();
		}
		
		void FillTestInformation ()
		{
			if (!detailsPad.Visible)
				return;

			if (detailsTest is UnitTestGroup) {
				UnitTestGroup group = detailsTest as UnitTestGroup;
				if (infoBook.Page == TestSummaryPage) {
					detailsStore.Clear ();
					foreach (UnitTest t in group.Tests) {
						UnitTestResult res = t.Results.GetLastResult (chart.CurrentDate);
						if (res != null)
							detailsStore.AppendValues (t, t.Name, res.Passed.ToString (), res.ErrorsAndFailures.ToString (), res.Ignored.ToString());
						else
							detailsStore.AppendValues (t, t.Name, "", "", "");
					}
				}
				else if (infoBook.Page == TestRegressionsPage) {
					regressionStore.Clear ();
					UnitTestCollection regs = detailsTest.GetRegressions (chart.ReferenceDate, chart.CurrentDate);
					if (regs.Count > 0) {
						foreach (UnitTest t in regs)
							regressionStore.AppendValues (t, t.Name, TestStatusIcon.Failure);
					} else
						regressionStore.AppendValues (null, GettextCatalog.GetString ("No regressions found."));
				}
				else if (infoBook.Page == TestFailuresPage) {
					failedStore.Clear ();
					UnitTestCollection regs = group.GetFailedTests (chart.CurrentDate);
					if (regs.Count > 0) {
						foreach (UnitTest t in regs)
							failedStore.AppendValues (t, t.Name, TestStatusIcon.Failure);
					} else
						failedStore.AppendValues (null, GettextCatalog.GetString ("No failed tests found."));
				}
			} else {
				UnitTestResult res = detailsTest.Results.GetLastResult (chart.CurrentDate);
				if (infoBook.Page == TestOutputPage) {
					outputView.Buffer.Clear ();
					if (res != null)
						outputView.Buffer.InsertAtCursor (res.ConsoleOutput);
				} else if (infoBook.Page == TestResultPage) {
					resultView.Buffer.Clear ();
					if (res != null) {
						string msg = res.Message + "\n\n" + res.StackTrace;
						resultView.Buffer.InsertAtCursor (msg);
					}
				}
			}
		}
		
		void OnDetailsTestChanged (object sender, EventArgs e)
		{
			RefreshDetails ();
		}
		
		void OnChartDateChanged (object sender, EventArgs e)
		{
			if (detailsTest != null && (detailsDate != chart.CurrentDate || detailsReferenceDate != chart.ReferenceDate)) {
				detailsDate = chart.CurrentDate;
				detailsReferenceDate = chart.ReferenceDate;
				FillTestInformation ();
			}
		}
		
		void OnPageLoadRequired (object o, EventArgs args)
		{
			if (detailsTest != null)
				FillTestInformation ();
		}
		
		protected virtual void OnTestActivated (object sender, Gtk.RowActivatedArgs args)
		{
			TreeIter it;
			detailsStore.GetIter (out it, args.Path);
			UnitTest t = (UnitTest) detailsStore.GetValue (it, 0);
			if (t != null)
				FillDetails (t, true);
		}
		
		protected virtual void OnRegressionTestActivated (object sender, Gtk.RowActivatedArgs args)
		{
			TreeIter it;
			regressionStore.GetIter (out it, args.Path);
			UnitTest t = (UnitTest) regressionStore.GetValue (it, 0);
			if (t != null)
				FillDetails (t, true);
		}
		
		protected virtual void OnFailedTestActivated (object sender, Gtk.RowActivatedArgs args)
		{
			TreeIter it;
			failedStore.GetIter (out it, args.Path);
			UnitTest t = (UnitTest) failedStore.GetValue (it, 0);
			if (t != null)
				FillDetails (t, true);
		}
		
		void OnZoomIn (object sender, EventArgs a)
		{
			if (detailsTest != null)
				chart.ZoomIn ();
		}
		
		void OnZoomOut (object sender, EventArgs a)
		{
			if (detailsTest != null)
				chart.ZoomOut ();
		}
		
		void OnChartBack (object sender, EventArgs a)
		{
			if (detailsTest != null)
				chart.GoPrevious ();
		}
		
		void OnChartForward (object sender, EventArgs a)
		{
			if (detailsTest != null)
				chart.GoNext ();
		}
		
		void OnChartLast (object sender, EventArgs a)
		{
			if (detailsTest != null)
				chart.GoLast ();
		}
		
		void OnChartButtonPress (object o, Gtk.ButtonPressEventArgs args)
		{
			if (args.Event.TriggersContextMenu ()) {
				IdeApp.CommandService.ShowContextMenu (Control, args.Event, "/MonoDevelop/NUnit/ContextMenu/TestChart");
				args.RetVal = true;
			}
		}
		
		[CommandHandler (TestChartCommands.ShowResults)]
		protected void OnShowResults ()
		{
			chart.Type = TestChartType.Results;
		}
		
		[CommandUpdateHandler (TestChartCommands.ShowResults)]
		protected void OnUpdateShowResults (CommandInfo info)
		{
			info.Checked = chart.Type == TestChartType.Results;
		}
		
		[CommandHandler (TestChartCommands.ShowTime)]
		protected void OnShowTime ()
		{
			chart.Type = TestChartType.Time;
		}
		
		[CommandUpdateHandler (TestChartCommands.ShowTime)]
		protected void OnUpdateShowTime (CommandInfo info)
		{
			info.Checked = chart.Type == TestChartType.Time;
		}
		
		[CommandHandler (TestChartCommands.UseTimeScale)]
		protected void OnUseTimeScale ()
		{
			chart.UseTimeScale = !chart.UseTimeScale;
		}
		
		[CommandUpdateHandler (TestChartCommands.UseTimeScale)]
		protected void OnUpdateUseTimeScale (CommandInfo info)
		{
			info.Checked = chart.UseTimeScale;
		}
		
		[CommandHandler (TestChartCommands.SingleDayResult)]
		protected void OnSingleDayResult ()
		{
			chart.SingleDayResult = !chart.SingleDayResult;
		}
		
		[CommandUpdateHandler (TestChartCommands.SingleDayResult)]
		protected void OnUpdateSingleDayResult (CommandInfo info)
		{
			info.Checked = chart.SingleDayResult;
		}
		
		[CommandHandler (TestChartCommands.ShowSuccessfulTests)]
		protected void OnShowSuccessfulTests ()
		{
			chart.ShowSuccessfulTests = !chart.ShowSuccessfulTests;
		}
		
		[CommandUpdateHandler (TestChartCommands.ShowSuccessfulTests)]
		protected void OnUpdateShowSuccessfulTests (CommandInfo info)
		{
			info.Enabled = chart.Type == TestChartType.Results;
			info.Checked = chart.ShowSuccessfulTests;
		}
		
		[CommandHandler (TestChartCommands.ShowFailedTests)]
		protected void OnShowFailedTests ()
		{
			chart.ShowFailedTests = !chart.ShowFailedTests;
		}
		
		[CommandUpdateHandler (TestChartCommands.ShowFailedTests)]
		protected void OnUpdateShowFailedTests (CommandInfo info)
		{
			info.Enabled = chart.Type == TestChartType.Results;
			info.Checked = chart.ShowFailedTests;
		}
		
		[CommandHandler (TestChartCommands.ShowIgnoredTests)]
		protected void OnShowIgnoredTests ()
		{
			chart.ShowIgnoredTests = !chart.ShowIgnoredTests;
		}
		
		[CommandUpdateHandler (TestChartCommands.ShowIgnoredTests)]
		protected void OnUpdateShowIgnoredTests (CommandInfo info)
		{
			info.Enabled = chart.Type == TestChartType.Results;
			info.Checked = chart.ShowIgnoredTests;
		}
	}
	
	class ButtonNotebook: Notebook
	{
		ArrayList loadedPages = new ArrayList ();
		
		public void Reset ()
		{
			loadedPages.Clear ();
			OnPageLoadRequired ();
		}
		
		public int AddPage (string text, Widget widget)
		{
			return AppendPage (widget, new Label (text));
		}
		
		public void ShowPage (int n)
		{
			GetNthPage (n).Show ();
		}
		
		public void HidePage (int n)
		{
			GetNthPage (n).Hide ();
		}
		
		protected override void OnSwitchPage (NotebookPage page, uint n)
		{
			base.OnSwitchPage (page, n);
			if (!loadedPages.Contains (Page))
				OnPageLoadRequired ();
		}
		
		void OnPageLoadRequired ()
		{
			loadedPages.Add (Page);
			if (PageLoadRequired != null)
				PageLoadRequired (this, EventArgs.Empty);
		}
		
		public EventHandler PageLoadRequired;
	}
	
	class HeaderLabel: Widget
	{
		string text;
		Pango.Layout layout;
		int padding;
		
		public HeaderLabel ()
		{
			WidgetFlags |= WidgetFlags.NoWindow;
			layout = new Pango.Layout (this.PangoContext);
		}
		
		public string Markup {
			get { return text; }
			set {
				text = value;
				layout.SetMarkup (text);
				QueueDraw ();
			}
		}
		
		public int Padding {
			get { return padding; }
			set { padding = value; }
		}
		
		protected override bool OnExposeEvent (Gdk.EventExpose args)
		{
			Gdk.GC gc = new Gdk.GC (GdkWindow);
			gc.ClipRectangle = Allocation;
			GdkWindow.DrawLayout (gc, padding, padding, layout);
			return true;
		}
	}
}