Revision: 8465
Author: rj...@google.com
Date: Mon Aug 2 18:45:49 2010
Log: Fixes UiBinder MenuBar parser to allow MenuItemSeparator, and custom
subclasses of MenuItem.
Patch by konstantin.scheg...@gmail.com
Review by rj...@google.com
http://gwt-code-reviews.appspot.com/702803
Fixes gwt issue
http://code.google.com/p/google-web-toolkit/issues/detail?id=4550
Review by: robertvaw...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=8465
Added:
/trunk/user/test/com/google/gwt/uibinder/elementparsers/MenuBarParserTest.java
/trunk/user/test/com/google/gwt/uibinder/elementparsers/MenuItemParserTest.java
Modified:
/trunk/user/src/com/google/gwt/uibinder/elementparsers/MenuBarParser.java
/trunk/user/src/com/google/gwt/uibinder/elementparsers/MenuItemParser.java
/trunk/user/test/com/google/gwt/uibinder/UiBinderJreSuite.java
/trunk/user/test/com/google/gwt/uibinder/test/UiJavaResources.java
===
--- /dev/null
+++
/trunk/user/test/com/google/gwt/uibinder/elementparsers/MenuBarParserTest.java
Mon Aug 2 18:45:49 2010
@@ -0,0 +1,182 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License); you may
not
+ * use this file except in compliance with the License. You may obtain a
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+package com.google.gwt.uibinder.elementparsers;
+
+import com.google.gwt.core.ext.UnableToCompleteException;
+import com.google.gwt.dev.javac.impl.MockJavaResource;
+import com.google.gwt.uibinder.rebind.FieldWriter;
+import com.google.gwt.user.client.ui.MenuItem;
+import com.google.gwt.user.client.ui.MenuItemSeparator;
+
+import junit.framework.TestCase;
+
+import java.util.Iterator;
+
+/**
+ * Test for {...@link MenuBarParser}.
+ */
+public class MenuBarParserTest extends TestCase {
+
+ private static final String PARSED_TYPE
= com.google.gwt.user.client.ui.MenuBar;
+
+ private MenuBarParser parser;
+ private ElementParserTester tester;
+
+ @Override
+ public void setUp() throws Exception {
+super.setUp();
+parser = new MenuBarParser();
+tester = new ElementParserTester(PARSED_TYPE, parser);
+ }
+
+ public void testBadChild_namespace() throws Exception {
+checkBadLine(ui:blah/, MenuBarParser.BAD_CHILD);
+ }
+
+ public void testBadChild_name() throws Exception {
+checkBadLine(g:Button/, MenuBarParser.BAD_CHILD);
+ }
+
+ private void checkBadLine(String badLine, String expectedDied)
+ throws Exception {
+StringBuffer b = new StringBuffer();
+b.append(g:MenuBar);
+b.append( + badLine);
+b.append(/g:MenuBar);
+// parse failed
+try {
+ tester.parse(b.toString());
+ fail();
+} catch (UnableToCompleteException e) {
+ String died = tester.logger.died;
+ assertTrue(died, died.contains(expectedDied));
+}
+ }
+
+ public void test_verticalMenuBar() throws Exception {
+StringBuffer b = new StringBuffer();
+b.append(g:MenuBar vertical='true');
+b.append( g:MenuItem/);
+b.append(/g:MenuBar);
+// parse
+FieldWriter w = tester.parse(b.toString());
+// special initializer for MenuBar
+assertEquals(new com.google.gwt.user.client.ui.MenuBar(true),
+w.getInitializer());
+// usual statement
+assertStatements(fieldName.addItem(g:MenuItem););
+ }
+
+ public void test_MenuItem() throws Exception {
+StringBuffer b = new StringBuffer();
+b.append(g:MenuBar);
+b.append( g:MenuItem text='1'/);
+b.append( g:MenuItem text='2'/);
+b.append(/g:MenuBar);
+// parse
+tester.parse(b.toString());
+// has items
+assertStatements(fieldName.addItem(g:MenuItem text='1');,
+fieldName.addItem(g:MenuItem text='2'););
+ }
+
+ public void test_MenuItemSeparator() throws Exception {
+StringBuffer b = new StringBuffer();
+b.append(g:MenuBar);
+b.append( g:MenuItemSeparator title='1'/);
+b.append( g:MenuItemSeparator title='2'/);
+b.append(/g:MenuBar);
+// parse
+tester.parse(b.toString());
+// has separators
+assertStatements(
+fieldName.addSeparator(g:MenuItemSeparator title='1');,
+fieldName.addSeparator(g:MenuItemSeparator title='2'););
+ }
+
+ /**
+ * Test for using subclass of {...@link MenuItem}.
+ * p
+ * See http://code.google.com/p/google-web-toolkit/issues/detail?id=4550
+ */
+ public void test_customMenuItem() throws Exception {
+MockJavaResource itemSubclass = new MockJavaResource(
+com.google.gwt.user.client.ui.MyItem) {
+ @Override
+ protected CharSequence