01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.user.client.ui;
17:
18: import com.google.gwt.junit.client.GWTTestCase;
19:
20: /**
21: * TODO: document me.
22: */
23: public class TabBarTest extends GWTTestCase {
24:
25: int selected;
26: int beforeSelection;
27:
28: public String getModuleName() {
29: return "com.google.gwt.user.User";
30: }
31:
32: public void testSelect() {
33: // Create a tab bar with three items.
34: final TabBar bar = new TabBar();
35: bar.addTab("foo");
36: bar.addTab("bar");
37: bar.addTab("baz");
38: bar.selectTab(1);
39: assertEquals(1, bar.getSelectedTab());
40: bar.selectTab(2);
41: assertEquals(2, bar.getSelectedTab());
42: bar.selectTab(-1);
43: assertEquals(-1, bar.getSelectedTab());
44: TabListener listener = new TabListener() {
45: public boolean onBeforeTabSelected(SourcesTabEvents sender,
46: int tabIndex) {
47: beforeSelection = tabIndex;
48: if (tabIndex == 1) {
49: return false;
50: } else {
51: return true;
52: }
53: }
54:
55: public void onTabSelected(SourcesTabEvents sender,
56: int tabIndex) {
57: selected = tabIndex;
58: }
59: };
60: bar.addTabListener(listener);
61: boolean result = bar.selectTab(-1);
62: assertEquals(-1, beforeSelection);
63: assertEquals(0, selected);
64: assertTrue(result);
65:
66: result = bar.selectTab(1);
67: assertFalse(result);
68: assertEquals(0, selected);
69: assertEquals(1, beforeSelection);
70:
71: result = bar.selectTab(2);
72: assertTrue(result);
73: assertEquals(2, selected);
74: assertEquals(2, beforeSelection);
75: }
76:
77: public void testGetHTML() {
78: final TabBar bar = new TabBar();
79: bar.addTab("foo");
80: bar.addTab("<b>bar</b>", true);
81: bar.addTab("baz");
82: assertEquals("foo", bar.getTabHTML(0));
83: assertTrue("<b>bar</b>".equalsIgnoreCase(bar.getTabHTML(1)));
84: bar.removeTab(1);
85: assertEquals("baz", bar.getTabHTML(1));
86: }
87: }
|