<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>EclipseSource Blog &#187; Tim Buschtöns</title>
	<atom:link href="http://eclipsesource.com/blogs/author/tim/feed/" rel="self" type="application/rss+xml" />
	<link>http://eclipsesource.com/blogs</link>
	<description>Eclipse Equinox OSGi</description>
	<lastBuildDate>Fri, 17 May 2013 13:50:55 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>How to use multiple browser tabs in your RAP 2.1 Application</title>
		<link>http://eclipsesource.com/blogs/2013/05/10/rap-2-1-m2-multi-browser-tabs/</link>
		<comments>http://eclipsesource.com/blogs/2013/05/10/rap-2-1-m2-multi-browser-tabs/#comments</comments>
		<pubDate>Fri, 10 May 2013 09:26:37 +0000</pubDate>
		<dc:creator>Tim Buschtöns</dc:creator>
				<category><![CDATA[EclipseSource News]]></category>
		<category><![CDATA[Planet Eclipse]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[kepler]]></category>
		<category><![CDATA[new and noteworthy]]></category>
		<category><![CDATA[rap]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=15710</guid>
		<description><![CDATA[You can now download RAP 2.1 M2, the final milestone of RAP before the 2.1 (Kepler) release in June. This milstone adds quite a few nice features like bézier curves for Canvas, background-position and -repeat for CSS theming, and (especially) improved multi-tab browsing: It is now possible to host multiple UI-Sessions within the same HTTP-Session, <a href="http://eclipsesource.com/blogs/2013/05/10/rap-2-1-m2-multi-browser-tabs/" style="text-decoration: none;">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>You can now <a href="http://eclipse.org/rap/downloads/">download RAP 2.1 M2</a>, the final milestone of RAP before the 2.1 (Kepler) release in June.</p>
<p>This milstone adds quite a few <a href="http://eclipse.org/rap/noteworthy/2.1/?build=M2">nice features</a> like bézier curves for Canvas, background-position and -repeat for CSS theming, and (especially) improved <b>multi-tab browsing</b>: It is now possible to host multiple UI-Sessions within the same HTTP-Session, meaning that there are no more tricks required to use multiple tabs with RAP applications in the same browser. Lets look at an example how multiple browser tabs can be used within a RAP application by integrating it with the <a href="http://eclipse.org/rap/developers-guide/devguide.php?topic=markup.html&#038;version=2.0#markup">markup</a> and <a href="http://eclipse.org/rap/developers-guide/devguide.php?topic=navigation.html&#038;version=2.0">BrowserNavigation</a> features. </p>
<p>Assuming our application lets the user select a person from a database to edit, the typical setup would be a TableViewer that opens a Dialog on a DefaultSelection event. We want to give the user the additional option to open this dialog in a new browser tab. This tab may run the same EntryPoint, or in this case one designed for this specific purpose only. </p>
<p><img src="http://download.eclipsesource.com/~tbuschto/multitab.png" title="How to use multiple browser tabs in your RAP 2.1 Application" alt="multitab How to use multiple browser tabs in your RAP 2.1 Application" /></p>
<p>We create a TableViewer with markup support:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">viewer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TableViewer<span style="color: #009900;">&#40;</span> parent <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
viewer.<span style="color: #006633;">getTable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setData</span><span style="color: #009900;">&#40;</span> RWT.<span style="color: #006633;">MARKUP_ENABLED</span>, <span style="color: #003399;">Boolean</span>.<span style="color: #000066; font-weight: bold;">TRUE</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Then we insert a link in the last cell of each row, whereby &#8220;edit&#8221; is the name of another EntryPoint:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">viewer.<span style="color: #006633;">setLabelProvider</span><span style="color: #009900;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> CellLabelProvider<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  @Override
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> update<span style="color: #009900;">&#40;</span> ViewerCell cell <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    Person person <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> Person <span style="color: #009900;">&#41;</span>cell.<span style="color: #006633;">getElement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">switch</span><span style="color: #009900;">&#40;</span> cell.<span style="color: #006633;">getColumnIndex</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">case</span> COLUMN_FIRST_NAME<span style="color: #339933;">:</span>
        cell.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span> person.<span style="color: #006633;">name</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">case</span> COLUMN_PLACE_OF_BIRTH<span style="color: #339933;">:</span>
        cell.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span> person.<span style="color: #006633;">nation</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">case</span> COLUMN_LINKS<span style="color: #339933;">:</span>
        <span style="color: #003399;">String</span> url <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;edit#person/&quot;</span> <span style="color: #339933;">+</span> persons.<span style="color: #006633;">indexOf</span><span style="color: #009900;">&#40;</span> person <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        cell.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>  
          <span style="color: #0000ff;">&quot;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> 
          <span style="color: #339933;">+</span> url 
          <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> target=<span style="color: #000099; font-weight: bold;">\&quot;</span>_blank<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;edit&lt;/a&gt;&quot;</span> 
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>In the other EntryPoint, we add deep-link support like this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">BrowserNavigation bn 
  <span style="color: #339933;">=</span> RWT.<span style="color: #006633;">getClient</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getService</span><span style="color: #009900;">&#40;</span> BrowserNavigation.<span style="color: #000000; font-weight: bold;">class</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
bn.<span style="color: #006633;">addBrowserNavigationListener</span><span style="color: #009900;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> BrowserNavigationListener<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  @Override
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> navigated<span style="color: #009900;">&#40;</span> BrowserNavigationEvent event <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">String</span> state <span style="color: #339933;">=</span> event.<span style="color: #006633;">getState</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> state.<span style="color: #006633;">startsWith</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;person/&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">int</span> index <span style="color: #339933;">=</span> <span style="color: #003399;">Integer</span>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span> state.<span style="color: #006633;">substring</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">7</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      editPerson<span style="color: #009900;">&#40;</span> persons.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span> index <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Done. You could also use the <a href="http://eclipse.org/rap/developers-guide/devguide.php?topic=navigation.html&#038;version=2.0#launcher">URLLauncher</a> service to open the tab without using a &#8220;real&#8221; link.</p>
<p><br/><div style="display: inline-block"><a href="https://twitter.com/intent/tweet?source=webclient&amp;text=How+to+use+multiple+browser+tabs+in+your+RAP+2.1+Application&amp;via=eclipsesource&amp;url=http://eclipsesource.com/blogs/2013/05/10/rap-2-1-m2-multi-browser-tabs/" target="_blank" title="Share on Twitter" style="margin-right: 5px;"><img title="Twitter" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/twitter.png" alt="Twitter"/></a><a href="https://plus.google.com/share?url=http://eclipsesource.com/blogs/2013/05/10/rap-2-1-m2-multi-browser-tabs/" target="_blank" title="+1" style="margin-right: 5px;"><img title="Google+" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/google_plus.png" alt="Google+"/></a><a href="http://www.linkedin.com/cws/share?url=http://eclipsesource.com/blogs/2013/05/10/rap-2-1-m2-multi-browser-tabs/" target="_blank" title="Share on LinkedIn" style="margin-right: 5px;"><img title="LinkedIn" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/linkedin.png" alt="LinkedIn"/></a><a href="https://www.facebook.com/sharer/sharer.php?u=http://eclipsesource.com/blogs/2013/05/10/rap-2-1-m2-multi-browser-tabs/&amp;t=How+to+use+multiple+browser+tabs+in+your+RAP+2.1+Application" target="_blank" title="Facebook" style="margin-right: 5px;"><img title="Facebook" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/facebook.png" alt="Facebook"/></a></div><br/><a href="http://eclipsesource.com/blogs/2013/05/10/rap-2-1-m2-multi-browser-tabs/#comments">2 Comments</a>. Tagged with <a href='http://eclipsesource.com/blogs/tag/eclipse/' title='eclipse Tag'>eclipse</a>, <a href='http://eclipsesource.com/blogs/tag/kepler/' title='kepler Tag'>kepler</a>, <a href='http://eclipsesource.com/blogs/tag/new-and-noteworthy/' title='new and noteworthy Tag'>new and noteworthy</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a>, <a href='http://eclipsesource.com/blogs/tag/tutorial/' title='tutorial Tag'>tutorial</a>, <a href='http://eclipsesource.com/blogs/tag/eclipse/' title='eclipse Tag'>eclipse</a>, <a href='http://eclipsesource.com/blogs/tag/kepler/' title='kepler Tag'>kepler</a>, <a href='http://eclipsesource.com/blogs/tag/new-and-noteworthy/' title='new and noteworthy Tag'>new and noteworthy</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a>, <a href='http://eclipsesource.com/blogs/tag/tutorial/' title='tutorial Tag'>tutorial</a></p>]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2013/05/10/rap-2-1-m2-multi-browser-tabs/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The D.I.Y. RAP Client Construction Kit</title>
		<link>http://eclipsesource.com/blogs/2013/04/12/rap-lite/</link>
		<comments>http://eclipsesource.com/blogs/2013/04/12/rap-lite/#comments</comments>
		<pubDate>Fri, 12 Apr 2013 13:01:58 +0000</pubDate>
		<dc:creator>Tim Buschtöns</dc:creator>
				<category><![CDATA[EclipseSource News]]></category>
		<category><![CDATA[Editors choice]]></category>
		<category><![CDATA[Planet Eclipse]]></category>
		<category><![CDATA[eclipseRT]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[rap]]></category>
		<category><![CDATA[Single Sourcing]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=15155</guid>
		<description><![CDATA[Since RAP 2.0 has fully implemented the JSON-based RAP Protocol I was eager to test it&#8217;s full potential myself. The Tabris clients for Android and iOS already exist and others may follow, but as I&#8217;m mostly at home in the browser that&#8217;s where I would like to use it. The Vision My idea was to <a href="http://eclipsesource.com/blogs/2013/04/12/rap-lite/" style="text-decoration: none;">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Since RAP 2.0 has <a href="http://eclipsesource.com/blogs/2012/10/05/rap-2-0-m2-json-protocol-migration-complete/">fully implemented</a> the JSON-based <a href="http://wiki.eclipse.org/RAP/Protocol">RAP Protocol</a> I was eager to test it&#8217;s full potential myself. The <a href="http://eclipsesource.com/en/products/tabris/">Tabris</a> clients for Android and iOS already exist and others may follow, but as I&#8217;m mostly at home in the browser that&#8217;s where I would like to use it.</p>
<h2>The Vision</h2>
<p>My idea was to create a highly modular and especially flexible client that supports only a minimal subset of RAP features, but can very easily be extended and customized. RAP 2.0 introduced a simple JavaScript API for creating custom widgets. This client would go one step further and also allow you to change the presentation of existing widgets to your liking (also using JavaScript). For that you don&#8217;t have to implement a new Java API, the client-server communication is already in place, as is the internal logic of the widget (like selection management). Also, the widget will still be single-sourcing capable. Any RAP widgets or features that you might miss in the client you should easily be able to implement yourself after reading the documentation. It would basically be a D.I.Y. RAP Client construction kit, and not a replacement for the full-blown existing WebClient.</p>
<p>Another noticeable feature of this client would also be its ability to adapt to (and take advantage of) different environments. This would also mean that it breaks with RAPs paradigm of looking and working identically on all supported browsers. If you want to take advantage of exciting HTML5/CSS3 features you can but it won&#8217;t work/look like the same older browser. You could also create a very different presentation if you are on a touchscreen device, or if you want to optimize for performance on older hardware. You could even create a presentation built entirely on SVG, or for other environments than a browser, as long as they run JavaScript.</p>
<p>By the way, most custom widgets and ClientScripting components written for the default WebClient should also still work with this client.</p>
<p>So I went ahead and built a <b>proof-of-concept/experimental</b> version of this web client for RAP. It currently supports 5 widgets and is appropriately titled &#8220;RAP Lite&#8221;. The code can be viewed <a href="https://github.com/tbuschto/rap-lite">here</a>. You can also download it and run the demo but remember that this is strictly a research project and only barely functional.</p>
<h2>What can it currently do?</h2>
<p>First of all, here are two screenshots of the <strong>Demo</strong> application included:</p>
<p><a href="http://eclipsesource.com/blogs/wp-content/uploads/2013/04/rap-lite-vs1.png"><img class="aligncenter size-full wp-image-15269" alt="rap lite vs1 The D.I.Y. RAP Client Construction Kit" src="http://eclipsesource.com/blogs/wp-content/uploads/2013/04/rap-lite-vs1.png" width="647" height="325" title="The D.I.Y. RAP Client Construction Kit" /></a></p>
<p>The screenshot on the left is the default WebClient, while the one on the right is RAP Lite. The first 5 buttons all only change the Label at the top.<br />
So far it looks and works mainly in the same way, except that RAP Lite starts up faster.</p>
<p>&#8220;Visit the other side&#8221; brings a List widget to the front using a nice CSS3 animation in the latest FireFox and Chrome browsers:</p>
<p><a href="http://eclipsesource.com/blogs/wp-content/uploads/2013/04/ani.png"><img class="aligncenter size-full wp-image-15273" alt="ani The D.I.Y. RAP Client Construction Kit" src="http://eclipsesource.com/blogs/wp-content/uploads/2013/04/ani.png" width="600" height="461" title="The D.I.Y. RAP Client Construction Kit" /></a></p>
<p>Clicking on &#8220;Scroll&#8221; will animate the scroll position of the List to a random value. In a modern browser the scrollbar is a subwidget (iScroll) that looks the same on any OS. Let&#8217;s compare that with IE8:</p>
<p><a href="http://eclipsesource.com/blogs/wp-content/uploads/2013/04/scrollbars.png"><img class="aligncenter size-full wp-image-15275" alt="scrollbars The D.I.Y. RAP Client Construction Kit" src="http://eclipsesource.com/blogs/wp-content/uploads/2013/04/scrollbars.png" width="601" height="331" title="The D.I.Y. RAP Client Construction Kit" /></a></p>
<p>In IE (on the right), the List now uses the traditional OS-native scrollbar without animation because the iScroll widget is not supported in IE. Also, the gradients are gone because RAP Lite will not go to the same lengths as the default client to render them. Lets modify the demo to tell the client to use another presentation for buttons:</p>
<p><a href="http://eclipsesource.com/blogs/wp-content/uploads/2013/04/win7buttons.png"><img class="aligncenter size-full wp-image-15278" alt="win7buttons The D.I.Y. RAP Client Construction Kit" src="http://eclipsesource.com/blogs/wp-content/uploads/2013/04/win7buttons.png" width="286" height="312" title="The D.I.Y. RAP Client Construction Kit" /></a></p>
<p>Now RAP Lite uses the native HTML form elements for push buttons, which aren&#8217;t as flexible, but look somewhat better than flat rectangles.</p>
<p>Finally, lets have a look at a cool feature that I didn&#8217;t mention before at all: The ability to run RAP Lite inside of a traditional, static HTML website:</p>
<p><a href="http://eclipsesource.com/blogs/wp-content/uploads/2013/04/raplite-website.png"><img class="aligncenter size-full wp-image-15281" style="border: 1px solid black; padding: 3px;" alt="raplite website The D.I.Y. RAP Client Construction Kit" src="http://eclipsesource.com/blogs/wp-content/uploads/2013/04/raplite-website.png" width="653" height="512" title="The D.I.Y. RAP Client Construction Kit" /></a></p>
<p>This is not RAP running in an iframe. Instead, there is a simple script within that static HTML site that assigns the RAP application a div to run in. However, that&#8217;s not all. Let&#8217;s assume you want to embedd RAP in your website, with some static content <i>between</i> the RAP components. You can do that too. The button at the bottom of the demo opens another Shell which now looks like this:</p>
<p><a href="http://eclipsesource.com/blogs/wp-content/uploads/2013/04/raplite-website2.png"><img class="aligncenter size-full wp-image-15282" style="border: 1px solid black; padding: 3px;" alt="raplite website2 The D.I.Y. RAP Client Construction Kit" src="http://eclipsesource.com/blogs/wp-content/uploads/2013/04/raplite-website2.png" width="650" height="514" title="The D.I.Y. RAP Client Construction Kit" /></a></p>
<p>Notice that the text flows around the new Shell, and even adapts when it changes it size.</p>
<h2>How does it work?</h2>
<p>RAP Lite can be separated into three layers (+libaries):</p>
<p><a href="http://eclipsesource.com/blogs/wp-content/uploads/2013/04/architecture.png"><img class="aligncenter size-full wp-image-15197" alt="architecture The D.I.Y. RAP Client Construction Kit" src="http://eclipsesource.com/blogs/wp-content/uploads/2013/04/architecture.png" width="1449" height="442" title="The D.I.Y. RAP Client Construction Kit" /></a></p>
<p>The first layer provides the core infrastructure for communicating with a RAP server. The code is taken directly from the existing WebClient and could be used to build any kind of JavaScript-based RAP client on top. (This is not quite the case yet, but almost).</p>
<p>The second layer provides the widget data models and internal logic, and connects the models with the first layer. It does not, however, include any HTML/CSS rendering or DOM event handling. As such it should, like the first layer, be able to run in any JavaScript environment, even non-browser.</p>
<p>The third and final layer does the actual presentation. Each widget model is assigned one <b>or more</b> (alternative) views that can render their content. The views use HTML templates and/or subwidgets (standalone widgets not based on a model) to generate the widget representation. DOM Events are pre-processed by the view, then forwarded to the model. The theming is applied using central CSS rules generated at runtime, and every view can contribute it&#8217;s own rules. Most changes in the model are either reflected by adding/removing CSS classes, or by re-rendering all or most of the HTML. While more incremental changes may be more efficient in some cases, this approach keeps the code very simple and the number of DOM operations small.</p>
<p><span style="font-size: 1.5em;">What does it all mean?</span></p>
<p>There are currently no concrete plans for a more &#8220;official&#8221; version of this client. The fact that is&#8217;s based on underscore.js sadly means that it can not become part of the RAP project for legal reasons. However, if I&#8217;m ever involved in creating another web client for RAP, it will most likely look a lot like this experiment.</p>
<p><br/><div style="display: inline-block"><a href="https://twitter.com/intent/tweet?source=webclient&amp;text=The+D.I.Y.+RAP+Client+Construction+Kit&amp;via=eclipsesource&amp;url=http://eclipsesource.com/blogs/2013/04/12/rap-lite/" target="_blank" title="Share on Twitter" style="margin-right: 5px;"><img title="Twitter" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/twitter.png" alt="Twitter"/></a><a href="https://plus.google.com/share?url=http://eclipsesource.com/blogs/2013/04/12/rap-lite/" target="_blank" title="+1" style="margin-right: 5px;"><img title="Google+" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/google_plus.png" alt="Google+"/></a><a href="http://www.linkedin.com/cws/share?url=http://eclipsesource.com/blogs/2013/04/12/rap-lite/" target="_blank" title="Share on LinkedIn" style="margin-right: 5px;"><img title="LinkedIn" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/linkedin.png" alt="LinkedIn"/></a><a href="https://www.facebook.com/sharer/sharer.php?u=http://eclipsesource.com/blogs/2013/04/12/rap-lite/&amp;t=The+D.I.Y.+RAP+Client+Construction+Kit" target="_blank" title="Facebook" style="margin-right: 5px;"><img title="Facebook" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/facebook.png" alt="Facebook"/></a></div><br/><a href="http://eclipsesource.com/blogs/2013/04/12/rap-lite/#comments">Leave a Comment</a>. Tagged with <a href='http://eclipsesource.com/blogs/tag/eclipsert/' title='eclipseRT Tag'>eclipseRT</a>, <a href='http://eclipsesource.com/blogs/tag/javascript/' title='javascript Tag'>javascript</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a>, <a href='http://eclipsesource.com/blogs/tag/single-sourcing/' title='Single Sourcing Tag'>Single Sourcing</a>, <a href='http://eclipsesource.com/blogs/tag/eclipsert/' title='eclipseRT Tag'>eclipseRT</a>, <a href='http://eclipsesource.com/blogs/tag/javascript/' title='javascript Tag'>javascript</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a>, <a href='http://eclipsesource.com/blogs/tag/single-sourcing/' title='Single Sourcing Tag'>Single Sourcing</a></p>]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2013/04/12/rap-lite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing JavaScript Tests with Jasmine for RAP</title>
		<link>http://eclipsesource.com/blogs/2013/04/02/rap-and-jasmine/</link>
		<comments>http://eclipsesource.com/blogs/2013/04/02/rap-and-jasmine/#comments</comments>
		<pubDate>Tue, 02 Apr 2013 08:44:35 +0000</pubDate>
		<dc:creator>Tim Buschtöns</dc:creator>
				<category><![CDATA[EclipseSource News]]></category>
		<category><![CDATA[Planet Eclipse]]></category>
		<category><![CDATA[jasmine]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[rap]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=14233</guid>
		<description><![CDATA[If you are writing unit tests for your Java code, then you should also write them for any other code you wrote for the same project. Otherwise these tests only give you a false sense of security. RAP 2.0 provides a new JavaScript API to extend the framework with custom components, as you can read <a href="http://eclipsesource.com/blogs/2013/04/02/rap-and-jasmine/" style="text-decoration: none;">[...]</a>]]></description>
			<content:encoded><![CDATA[<p><img class="size-full wp-image-14336 alignright" alt="rapjasmine trnsp Writing JavaScript Tests with Jasmine for RAP" src="http://eclipsesource.com/blogs/wp-content/uploads/2013/02/rapjasmine_trnsp.png" width="356" height="240" title="Writing JavaScript Tests with Jasmine for RAP" /></p>
<p>If you are writing unit tests for your Java code, then you should also write them for any other code you wrote for the same project. Otherwise these tests only give you a false sense of security. RAP 2.0 provides a new JavaScript API to extend the framework with custom components, as you can read <a href="http://eclipsesource.com/blogs/2013/02/11/rap-2-0-countdown-55/">here</a>. Using third party JavaScript libaries (<a href="http://jquery.com/">jQuery</a>, <a href="http://d3js.org/">D3</a>, etc) or widgets/applications (like <a href="http://rap.eclipsesource.com/rapdemo/examples#gmaps">GMaps</a>, <a href="http://ckeditor.com/demo">CKEditor</a>&#8230; ) makes the task manageable even if you are not an HTML/CSS/JavaScript expert. But what about tests?</p>
<p>As Java/RCP/RAP developer you may be used to JUnit, and perhaps Mockito (if not: read <a href="http://eclipsesource.com/blogs/2011/09/19/effective-mockito-part-1/">this</a>). Now, Java/JavaScript differences aside, I like <a href="http://pivotal.github.com/jasmine/">Jasmine</a> even better. I used it to test my JavaScript code when porting the CKEditor add-on for RAP (<a href="http://rap.eclipsesource.com/rapdemo/examples#ckeditor">demo</a>, <a href="https://github.com/eclipsesource/rap-ckeditor">download</a>) to RAP 2.0. In this article I will use this project to demonstrate one way to use Jasmine with RAP.<br />
You can look at the editors <a href="https://github.com/eclipsesource/rap-ckeditor/blob/master/com.eclipsesource.widgets.ckeditor/src/com/eclipsesource/widgets/ckeditor/CKEditor.java">Java implementation</a> here, and at the <a href="https://github.com/eclipsesource/rap-ckeditor/blob/master/com.eclipsesource.widgets.ckeditor/src/resources/handler.js">JavaScript code</a> we want to test here.</p>
<h3>Remote API Basics</h3>
<p>To fully understand the examples i&#8217;ll show here, you should be familiar with the RAP Remote API, but you&#8217;ll get the gist of it either way. If you want, you can jump straight to the next chapter.</p>
<p>A brief introduction to Remote API is also given <a href="http://eclipsesource.com/blogs/2013/02/11/rap-2-0-countdown-55/">here</a>. Basically, each side (client and server) have one &#8220;half&#8221; of the custom widget, and a representation of the other side&#8217;s &#8220;half&#8221; as an instance of <code>RemoteObject</code>:</p>
<p><a href="http://eclipsesource.com/blogs/2013/02/01/rap-2-0-countdown-15/"><img class="aligncenter size-full wp-image-14008" alt="half objects Writing JavaScript Tests with Jasmine for RAP" src="http://eclipsesource.com/blogs/wp-content/uploads/2013/02/half-objects.png" width="601" height="215" title="Writing JavaScript Tests with Jasmine for RAP" /></a></p>
<p>Therefore RAP includes a <code>RemoteObject</code> <a href="http://download.eclipse.org/rt/rap/doc/2.0/guide/reference/api/org/eclipse/rap/rwt/remote/RemoteObject.html">implementation for Java</a> and <a href="http://download.eclipse.org/rt/rap/doc/2.0/guide/reference/jsdoc/symbols/RemoteObject.html">one for JavaScript</a>. The main difference is that the server can create new remote objects&#8230;</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">Connection</span> connection <span style="color: #339933;">=</span> RWT.<span style="color: #006633;">getUISession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">RemoteObject</span> remoteObject 
  <span style="color: #339933;">=</span> connection.<span style="color: #006633;">createRemoteObject</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;MyWidget&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><span/></p>
<p>&#8230; while the client can only get existing ones:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">  <span style="color: #000066; font-weight: bold;">var</span> remoteObject <span style="color: #339933;">=</span> rap.<span style="color: #660066;">getRemoteObject</span><span style="color: #009900;">&#40;</span> widgetInstance <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><span/></p>
<p>In addition, the Server can also <a href="http://download.eclipse.org/rt/rap/doc/2.0/guide/reference/api/org/eclipse/rap/rwt/remote/RemoteObject.html#setHandler%28org.eclipse.rap.rwt.remote.OperationHandler%29"> receive remote operations</a> via the remote object, while the client object has to implement methods (especially setter) that can be directly called by the framework.</p>
<p>Typically, a simple custom widgets client-side life cycle looks like this:</p>
<ul>
<li id="typehandler">The client component has to <a href="http://download.eclipse.org/rt/rap/doc/2.0/guide/reference/jsdoc/symbols/rap.html#.registerTypeHandler">register a TypeHandler</a> (once). This is basically the glue between your custom widget and the framework. The type handler consist of a factory for the client object, and a list of properties, methods and events it supports.</li>
<li>The server side creates an <code>RemoteObject</code> instance. With this, a &#8220;create&#8221; operation is send to the client and invokes the type handler&#8217;s factory.</li>
<li>Using the id of a <code>Composite</code> (which the server typically provides in a &#8220;set&#8221; operation), the custom widget can obtain the client side instance and attach itself to it: <code style="white-space: nowrap;">rap.getObject( parentId ).append( htmlElement );</code></li>
<li>All invocations of &#8220;set&#8221; or &#8220;call&#8221; on the server side <code>RemoteObject</code> will cause the matching methods of the client widget to be called. To send messags back, the client widget can itself obtain a <code>RemoteObject</code> to send operations to the server.</li>
<li>When the server remote object is destroyed, so is the client object.</li>
</ul>
<h3>Jasmine at a glance</h3>
<p>The Jasmine project site already gives a good <a href="http://pivotal.github.com/jasmine/">tutorial</a>, so I&#8217;ll try to keep this short. Jasmine allows for Behavior-Driven Development (BDD), which is similar to Test-Driven Development (TDD). It basically means that your tests will read <a href="http://en.wikipedia.org/wiki/Behavior-driven_development#Behavioral_specifications">like a &#8220;story&#8221;</a> written in plain English. (Or any other language, <a href="http://eclipsesource.com/blogs/2012/09/03/js-i18n/">if you&#8217;re crazy</a>.)</p>
<p>For example, a traditional test in JUnit&#8230;</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Math_Test <span style="color: #000000; font-weight: bold;">extends</span> TestCase
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> test_RoundsUp2Point5<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    assertEquals<span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">3</span>, <span style="color: #003399;">Math</span>.<span style="color: #006633;">round</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">2.5</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><span/></p>
<p>&#8230; may look like this in Jasmine:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">describe<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Math&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  it<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;should round 2.5 to 3&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    expect<span style="color: #009900;">&#40;</span> <span style="">Math</span>.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">2.5</span> <span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toBe</span><span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">3</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><span/></p>
<p>As you can see it&#8217;s not that different at first, except it&#8217;s easier to describe what exactly you are testing. The &#8220;describe&#8221; function seems similar to a test class (it is called a &#8220;Suite&#8221;), &#8220;it&#8221; to a test method (actually a &#8220;Spec&#8221;), and &#8220;expect&#8221; looks a bit like Mockitos &#8220;verify&#8221;. The &#8220;setUp&#8221; and &#8220;tearDown&#8221; methods in JUnit would be &#8220;beforeEach&#8221; and &#8220;afterEach&#8221; functions in Jasmine.</p>
<p>However, the advantage is that unlike JUnit tests, &#8220;describe&#8221; functions can be nested. And what I personally love about that, is that each can have it&#8217;s very own beforeEach/afterEach functions, and they are executed for all the &#8220;describe&#8221; functions the &#8220;it&#8221; is in. That made my tests a lot more readable. In JUnit I would often have a lot of similar setup code at the beginning for each test, and multiple asserts the end. Sure, there ways to reduce it, but I think it&#8217;s a pain. My Jasmine Specs on the other hand are usually around three lines only.</p>
<p><a href="http://eclipsesource.com/blogs/wp-content/uploads/2013/02/jasminegraph.png"><img class="aligncenter size-full wp-image-14429" alt="jasminegraph Writing JavaScript Tests with Jasmine for RAP" src="http://eclipsesource.com/blogs/wp-content/uploads/2013/02/jasminegraph.png" width="761" height="496" title="Writing JavaScript Tests with Jasmine for RAP" /></a></p>
<h3>What to test?</h3>
<p>There may be several parts to your JavaScript component. The RAP <a href="#typehandler">type handler</a> has little to no logic of it&#8217;s own, and would require a &#8220;real&#8221; RAP client to be tested. Therefore we omit it, and only test the widget <a href="http://en.wikipedia.org/wiki/Prototype-based_programming">&#8220;class&#8221;</a> itself.</p>
<p>If your custom widget is basically a wrapper for an existing JavaScript app (like CKEditor), then you might want to test <i>only</i> the wrapper. If so, you can also replace the app with your own mock, though you have to know the app&#8217;s API really well for that to work. In my case, I first did a untested prototype to figure out how to get the CKEditor to cooperate with RAP. Then I started again from scratch, writing tests first using a <a href="https://github.com/eclipsesource/rap-ckeditor/blob/master/com.eclipsesource.widgets.ckeditor.test/js/CKEditorMock.js">CKEditor mock</a> I created myself.</p>
<p>If you are writing the entire widget yourself, you should of course test all of it, not just the part that connects to RAP.</p>
<h3>Setting Up Jasmine with a RAP enviroment</h3>
<p>Download the Jasmine <a href="http://pivotal.github.com/jasmine/#section-Downloads">Standalone Release</a> and unzip it to a folder in your test project. You don&#8217;t need the included examples, so delete the <code>src</code> and <code>specs</code> folder. Open the <code>SpecRunner.html</code> in an editor. We are interested in the <code>&lt;script&gt;</code> tags only. Remove those that point to the deleted files. Then get the &#8220;<a href="https://github.com/eclipsesource/rap-ckeditor/blob/master/com.eclipsesource.widgets.ckeditor.test/js/rap-mock.js">rap-mock.js</a> from our GitHub repository and include it with a new script tag. This is key, as the file contains a mock implementation of the RAP JavaScript API, so that your custom component can be tested outside an actual RAP application.</p>
<p><i>Below</i> the rap-mock.js, add the JavaScript file(s) from your own RAP JavaScript component. If they are in another bundle, it may have to look like this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="html" style="font-family:monospace;">&lt;script 
  type=&quot;text/javascript&quot; 
  src=&quot;../../com.eclipsesource.widgets.ckeditor/src/resources/handler.js&quot;&gt;
&lt;/script&gt;</pre></td></tr></table></div>

<p><span/><br />
Finally, create a new JavaScript file like &#8220;<a href="https://github.com/eclipsesource/rap-ckeditor/blob/master/com.eclipsesource.widgets.ckeditor.test/js/specs/CKEditorSpec.js">CKEditorSpec.js</a>&#8221; and also include it in the HTML file. This is where we will put the tests.</p>
<p>The rap mock is initialized automatically by including the file itself, but to be sure that everything is reset with each test, your outmost &#8220;beforeEach&#8221; should look like this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"> beforeEach<span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  rap <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">new</span> RapMock<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><span/></p>
<p>In addition to the <a href="http://download.eclipse.org/rt/rap/doc/2.0/guide/reference/jsdoc/symbols/rap.html">official API of the &#8220;rap&#8221; object</a>, this one has two fields &#8220;fakeRemoteObject&#8221; and &#8220;fakeComposite&#8221;. Like &#8220;rap&#8221; itself, they are only empty implementations of the <code>RemoteObject</code> and <code>Composite</code> types, which are returned if <code>rap.getRemoteObject()</code> or <code>rap.getObject()</code> (respectively) are called. That makes it a lot easier to test interactions with these objects later on. (Note that it always returns the <i>same</i> instances, but since they dont have any state it shouldn&#8217;t matter.)</p>
<h3>My First Spec</h3>
<p>Since variables have function scope in JavaScript, and all Suites and Specs are functions, you can freely define variables within any suite and share them with the contained Specs. I would suggest to do so for your outmost Suite for the instance of your custom widget. For me, it looks like this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">describe<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;eclipsesource.CKEditor&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">var</span> editor<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">var</span> createEditor <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    editor <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">new</span> eclipsesource.<span style="color: #660066;">CKEditor</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">&quot;parent&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;w2&quot;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  beforeEach<span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    rap <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">new</span> RapMock<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    editor <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  afterEach<span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    editor <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  ...
&nbsp;
<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><span/></p>
<p>I&#8217;m not creating an instance in the outer Suite because we will sometimes need to do some setup <i>before</i> calling the constructor. This is where <a href="https://github.com/pivotal/jasmine/wiki/Spies">spies</a> come into play. Remember, our rap mock (and in this case CKEditor mock) does absolutely nothing itself (except preventing crashes). To write meaningful tests, we need to spy on it.</p>
<p>Spies replace methods with stubs, which can later be checked for invocations Mockito-style. They can also return any value, capture arguments, or execute arbitrary code. Read more about them <a href="https://github.com/pivotal/jasmine/wiki/Spies">here</a>. Spies are automatically removed after each <code>it</code>.</p>
<p>Now we dive right into it, and test that the widget adds itself (specifically it&#8217;s element) to the parent:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">  describe<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;The Constructor&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    it<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;should get a Composite with the parent id&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      spyOn<span style="color: #009900;">&#40;</span> rap<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;getObject&quot;</span> <span style="color: #009900;">&#41;</span>.<span style="color: #660066;">andCallThrough</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      createEditor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      expect<span style="color: #009900;">&#40;</span> rap.<span style="color: #660066;">getObject</span> <span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toHaveBeenCalledWith</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;w2&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    it<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;should add an element to the composite&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      spyOn<span style="color: #009900;">&#40;</span> rap.<span style="color: #660066;">fakeComposite</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;append&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      createEditor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      expect<span style="color: #009900;">&#40;</span> rap.<span style="color: #660066;">fakeComposite</span>.<span style="color: #660066;">append</span> <span style="color: #009900;">&#41;</span>
       .<span style="color: #660066;">toHaveBeenCalledWith</span><span style="color: #009900;">&#40;</span> editor.<span style="color: #660066;">element</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><span/></p>
<p>It is a common pattern to prefix &#8220;private&#8221; fields of JavaScript objects with a &#8220;_&#8221;. For the CKEditor wrapper I completely abstained from creating private fields and made everything &#8220;public&#8221;, including the HTML element. If I hadn&#8217;t, I would either have to access a private field, or examine the contents of the element that was given to the fake composite. Since i&#8217;m not interested in testing the CKEditor itself, I chose this simpler solution.</p>
<p>Most other aspects of the constructor and the editor/wrapper are tested in similar ways, as you can read in the <a href="https://github.com/eclipsesource/rap-ckeditor/blob/master/com.eclipsesource.widgets.ckeditor.test/js/specs/CKEditorSpec.js">full Spec file</a>. However, there are a few more special cases I like to discuss in detail.</p>
<h3>Testing events</h3>
<p>The CKEditor wrapper registers events listener on the CKEditor itself and on the &#8220;rap&#8221; object, e.g. to check for changes before a request is send to the server. There are various ways to test them. The &#8220;cleanest&#8221; one would likely be to obtain the listener with a spy and execute it:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">describe<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;The send listener&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">var</span> onSendListener<span style="color: #339933;">;</span>
&nbsp;
  beforeEach<span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    spyOn<span style="color: #009900;">&#40;</span> rap<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;on&quot;</span> <span style="color: #009900;">&#41;</span>.<span style="color: #660066;">andCallFake</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> event<span style="color: #339933;">,</span> listener <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> event <span style="color: #339933;">===</span> <span style="color: #3366CC;">&quot;send&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        onSendListener <span style="color: #339933;">=</span> listener<span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    createEditor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  describe<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;of an editor that has not changed&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    it<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;sends nothing&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      spyOn<span style="color: #009900;">&#40;</span> rap.<span style="color: #660066;">fakeRemoteObject</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;set&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      onSendListener<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      expect<span style="color: #009900;">&#40;</span> rap.<span style="color: #660066;">fakeRemoteObject</span>.<span style="color: #000066; font-weight: bold;">set</span> <span style="color: #009900;">&#41;</span>.<span style="color: #660066;">not</span>.<span style="color: #660066;">toHaveBeenCalled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><span/></p>
<p>With the &#8220;beforeEach&#8221; function this does not bloat your code all that much, but it&#8217;s still a couple of lines. So instead I simply made the listener &#8220;public&#8221; (like with the HTML element) and called it <i>after checking it was registered</i>. This is part of the &#8220;contructor&#8221; Suite show above:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">it<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;should add a send listener&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  spyOn<span style="color: #009900;">&#40;</span> rap<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;on&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  createEditor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  expect<span style="color: #009900;">&#40;</span> rap.<span style="color: #660066;">on</span> <span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toHaveBeenCalledWith</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;send&quot;</span><span style="color: #339933;">,</span> editor.<span style="color: #660066;">onSend</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><span/></p>
<p>Now I can simply invoke <code>editor.onSend</code> whenever I want, since I now it has been registered with the RAP client, which I trust to work correctly. <b>But</b>, there is one important bit: You should <b>not</b> simply write <code>editor.onSend()</code>, because this would mean that <code>editor</code> will be the context (<code>this</code>) of the invokation. This is not automatically given when working with JavaScript callbacks, and I know it is not the case with <code>rap.on</code>. (To see how I solved that issue for the CKEditor, look at the <code>bindAll</code> function in the <a href="https://github.com/eclipsesource/rap-ckeditor/blob/master/com.eclipsesource.widgets.ckeditor/src/resources/handler.js">source code</a>.) Instead, you can write <code>editor.onSend.call();</code>, which executes it without context.</p>
<h3>The Clock makes &#8220;tick&#8221;</h3>
<p>A common issue with JavaScript testing are asynchronously executed function. This custom widget has one of those for setting the editors font, which happens with a small delay using the JavaScript <code>setTimeout</code> function. This means I can not simply call <code>editor.setFont</code> and check the results right away. Jasmine includes two different solutions for this issue. If you want or need your test to emulate the actual runtime scenario, you need to <a href="http://pivotal.github.com/jasmine/#section-Asynchronous_Support">wrap the code</a> of your Spec in <code>runs</code> and <code>waitsFor</code> functions. </p>
<p>Since I use only a mock CKEditor I had no such requirement, and used the alternative: Simply mocking the JavaScript timer.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">describe<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;The setFont function&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
   <span style="color: #000066; font-weight: bold;">var</span> body<span style="color: #339933;">;</span>
&nbsp;
   beforeEach<span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    jasmine.<span style="color: #660066;">Clock</span>.<span style="color: #660066;">useMock</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    createEditor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    body <span style="color: #339933;">=</span> editor.<span style="color: #660066;">editor</span>.<span style="color: #660066;">document</span>.<span style="color: #660066;">getBody</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    spyOn<span style="color: #009900;">&#40;</span> body<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;setStyle&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    editor.<span style="color: #660066;">setFont</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;13px Arial&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  it<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;calls body.setStyle on a ready event&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    editor.<span style="color: #660066;">onReady</span>.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    jasmine.<span style="color: #660066;">Clock</span>.<span style="color: #660066;">tick</span><span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    expect<span style="color: #009900;">&#40;</span> body.<span style="color: #660066;">setStyle</span> <span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toHaveBeenCalledWith</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;font&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;13px Arial&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>Feedback&#8230;</h3>
<p>&#8230;would be welcome, especially if you have trouble writing tests for RAP custom widgets. I did not touch on some topics like sending events to the server (which the CKEditor doesn&#8217;t do), or how to test DOM changes, but that would have completely burst the scope of this article. (<a href="http://eclipsesource.com/blogs/2012/08/14/debugging-javascript-on-android-and-ios/">I sometimes have issus keeping things short&#8230;</a>) Also, on testing the server side: RAP includes a Fixture (not official API) which allows testing the Remote API, but we might change it soon, so I didn&#8217;t want to write about it now. If you are curious, look at <a href="https://github.com/eclipsesource/rap-ckeditor/blob/master/com.eclipsesource.widgets.ckeditor.test/src/com/eclipsesource/widgets/ckeditor/CKEditor_Test.java"><code>CKEditor_Test.java</code></a>.</p>
<h3>Final Words</h3>
<p>Jasmine is awesome. Go use it for something.</p>
<p><br/><div style="display: inline-block"><a href="https://twitter.com/intent/tweet?source=webclient&amp;text=Writing+JavaScript+Tests+with+Jasmine+for+RAP&amp;via=eclipsesource&amp;url=http://eclipsesource.com/blogs/2013/04/02/rap-and-jasmine/" target="_blank" title="Share on Twitter" style="margin-right: 5px;"><img title="Twitter" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/twitter.png" alt="Twitter"/></a><a href="https://plus.google.com/share?url=http://eclipsesource.com/blogs/2013/04/02/rap-and-jasmine/" target="_blank" title="+1" style="margin-right: 5px;"><img title="Google+" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/google_plus.png" alt="Google+"/></a><a href="http://www.linkedin.com/cws/share?url=http://eclipsesource.com/blogs/2013/04/02/rap-and-jasmine/" target="_blank" title="Share on LinkedIn" style="margin-right: 5px;"><img title="LinkedIn" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/linkedin.png" alt="LinkedIn"/></a><a href="https://www.facebook.com/sharer/sharer.php?u=http://eclipsesource.com/blogs/2013/04/02/rap-and-jasmine/&amp;t=Writing+JavaScript+Tests+with+Jasmine+for+RAP" target="_blank" title="Facebook" style="margin-right: 5px;"><img title="Facebook" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/facebook.png" alt="Facebook"/></a></div><br/><a href="http://eclipsesource.com/blogs/2013/04/02/rap-and-jasmine/#comments">Leave a Comment</a>. Tagged with <a href='http://eclipsesource.com/blogs/tag/jasmine/' title='jasmine Tag'>jasmine</a>, <a href='http://eclipsesource.com/blogs/tag/javascript/' title='javascript Tag'>javascript</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a>, <a href='http://eclipsesource.com/blogs/tag/testing/' title='testing Tag'>testing</a>, <a href='http://eclipsesource.com/blogs/tag/tutorial/' title='tutorial Tag'>tutorial</a>, <a href='http://eclipsesource.com/blogs/tag/jasmine/' title='jasmine Tag'>jasmine</a>, <a href='http://eclipsesource.com/blogs/tag/javascript/' title='javascript Tag'>javascript</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a>, <a href='http://eclipsesource.com/blogs/tag/testing/' title='testing Tag'>testing</a>, <a href='http://eclipsesource.com/blogs/tag/tutorial/' title='tutorial Tag'>tutorial</a></p>]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2013/04/02/rap-and-jasmine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Keyboard Controls in RAP: Next Step Mnemonics</title>
		<link>http://eclipsesource.com/blogs/2013/03/15/rap-mnemonics/</link>
		<comments>http://eclipsesource.com/blogs/2013/03/15/rap-mnemonics/#comments</comments>
		<pubDate>Fri, 15 Mar 2013 11:20:13 +0000</pubDate>
		<dc:creator>Tim Buschtöns</dc:creator>
				<category><![CDATA[EclipseSource News]]></category>
		<category><![CDATA[Editors choice]]></category>
		<category><![CDATA[Planet Eclipse]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[kepler]]></category>
		<category><![CDATA[rap]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=14913</guid>
		<description><![CDATA[Applications built with RAP are often designed for high productivity: The faster you can control the app, the more work you can get done. In many cases, keyboard controls are significantly faster than mouse controls. Consequentially, RAP has continually improved keyboard controls since it&#8217;s inception. What are Mnemonics? Should you not know, Mnemonics are the <a href="http://eclipsesource.com/blogs/2013/03/15/rap-mnemonics/" style="text-decoration: none;">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Applications built with RAP are often designed for high productivity: The faster you can control the app, the more work you can get done. In many cases, keyboard controls are significantly faster than mouse controls. Consequentially, RAP has <a href="http://eclipse.org/rap/noteworthy/1.2/#Workbench">continually</a> <a href="http://eclipsesource.com/blogs/2011/04/27/key-bindings-in-rap/">improved</a> <a href="http://eclipsesource.com/blogs/2012/03/08/using-key-events-effectively-in-rap/">keyboard</a> <a href="http://eclipsesource.com/blogs/2012/03/23/client-side-input-validation-with-rap-clientscripting/">controls</a> since it&#8217;s inception.</p>
<h3>What are Mnemonics?</h3>
<p>Should you not know, Mnemonics are the characters that get underlined in some widgets (especially the menu bar) if you hold down the ALT key. Mac users may scratch their heads right now, because <a href="https://developer.apple.com/library/mac/documentation/Java/Conceptual/Java14Development/07-NativePlatformIntegration/NativePlatformIntegration.html#//apple_ref/doc/uid/TP40001909-212166-TPXREF146">those aren&#8217;t supported in OS X</a>. Their exact behavior differs a bit between the other platforms, but as long as you hold ALT and press of the underlined character on your keyboard, the widget gets selected. What I like about that is that, unlike normal shortcuts, you do not need to remember Mnemonics, and they can change all the time depending on what&#8217;s on screen. </p>
<h3>Mnemonics in RAP 2.1M1</h3>
<p><a href="http://eclipsesource.com/blogs/wp-content/uploads/2013/03/mnemonics.png"><img src="http://eclipsesource.com/blogs/wp-content/uploads/2013/03/mnemonics.png" alt="mnemonics Keyboard Controls in RAP: Next Step Mnemonics " width="429" height="147" class="aligncenter size-full wp-image-14926" title="Keyboard Controls in RAP: Next Step Mnemonics " /></a><br />
As of M2 (or the current <a href="http://eclipse.org/rap/downloads/">nightly build</a>), RAP will support Mnemonics on Menus, Buttons, ToolItems, TabItems, Labels and Groups. (Also CTabItem and CLabel.) To enable them, you first need to set the modifier that makes the Mnemonics visible. While you could use ALT, it&#8217;s strongly discouraged, because that would activate the <em>actual</em> Mnemonics of your browser with unpredictable results. I recommend using CTRL+ALT, and reserve CTRL and CTRL+SHIFT for global shortcuts/Key Bindings. The combo can be set with just one line:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">display.<span style="color: #006633;">setData</span><span style="color: #009900;">&#40;</span> RWT.<span style="color: #006633;">MNEMONIC_ACTIVATOR</span>, <span style="color: #0000ff;">&quot;CTRL+ALT&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Now all you need to do is to put a &#8220;&#038;&#8221; before a character in a widgets text, and you already have a working Mnemonic. Example:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">tabItem.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;Tab Item &amp;1&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Since this is a relatively complex new feature, I would love for developers to grab RAP 2.1M1 when it&#8217;s available next week and try it in their application so that we can get some feedback.</p>
<p>Coming soon: <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=403206">Full Accelerator support</a>.</p>
<p><br/><div style="display: inline-block"><a href="https://twitter.com/intent/tweet?source=webclient&amp;text=Keyboard+Controls+in+RAP%3A+Next+Step+Mnemonics&amp;via=eclipsesource&amp;url=http://eclipsesource.com/blogs/2013/03/15/rap-mnemonics/" target="_blank" title="Share on Twitter" style="margin-right: 5px;"><img title="Twitter" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/twitter.png" alt="Twitter"/></a><a href="https://plus.google.com/share?url=http://eclipsesource.com/blogs/2013/03/15/rap-mnemonics/" target="_blank" title="+1" style="margin-right: 5px;"><img title="Google+" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/google_plus.png" alt="Google+"/></a><a href="http://www.linkedin.com/cws/share?url=http://eclipsesource.com/blogs/2013/03/15/rap-mnemonics/" target="_blank" title="Share on LinkedIn" style="margin-right: 5px;"><img title="LinkedIn" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/linkedin.png" alt="LinkedIn"/></a><a href="https://www.facebook.com/sharer/sharer.php?u=http://eclipsesource.com/blogs/2013/03/15/rap-mnemonics/&amp;t=Keyboard+Controls+in+RAP%3A+Next+Step+Mnemonics" target="_blank" title="Facebook" style="margin-right: 5px;"><img title="Facebook" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/facebook.png" alt="Facebook"/></a></div><br/><a href="http://eclipsesource.com/blogs/2013/03/15/rap-mnemonics/#comments">Leave a Comment</a>. Tagged with <a href='http://eclipsesource.com/blogs/tag/api/' title='api Tag'>api</a>, <a href='http://eclipsesource.com/blogs/tag/eclipse/' title='eclipse Tag'>eclipse</a>, <a href='http://eclipsesource.com/blogs/tag/kepler/' title='kepler Tag'>kepler</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a>, <a href='http://eclipsesource.com/blogs/tag/tips/' title='tips Tag'>tips</a>, <a href='http://eclipsesource.com/blogs/tag/api/' title='api Tag'>api</a>, <a href='http://eclipsesource.com/blogs/tag/eclipse/' title='eclipse Tag'>eclipse</a>, <a href='http://eclipsesource.com/blogs/tag/kepler/' title='kepler Tag'>kepler</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a>, <a href='http://eclipsesource.com/blogs/tag/tips/' title='tips Tag'>tips</a></p>]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2013/03/15/rap-mnemonics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RAP 2.0 RC1 published</title>
		<link>http://eclipsesource.com/blogs/2013/01/18/rap-2-0-rc1-published/</link>
		<comments>http://eclipsesource.com/blogs/2013/01/18/rap-2-0-rc1-published/#comments</comments>
		<pubDate>Fri, 18 Jan 2013 12:30:48 +0000</pubDate>
		<dc:creator>Tim Buschtöns</dc:creator>
				<category><![CDATA[EclipseSource News]]></category>
		<category><![CDATA[Planet Eclipse]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[New]]></category>
		<category><![CDATA[new and noteworthy]]></category>
		<category><![CDATA[rap]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=13620</guid>
		<description><![CDATA[The RAP team wishes everyone a Happy New Year and proudly presents the first release candidate for RAP 2.0. When you look at our New and Noteworthy log for RAP 2.0 RC1, you&#8217;ll notice that we are going to live up our new name: The brand new RAP &#8220;Remote&#8221; API on Server and Client makes <a href="http://eclipsesource.com/blogs/2013/01/18/rap-2-0-rc1-published/" style="text-decoration: none;">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>The RAP team wishes everyone a Happy New Year and proudly presents the <a href="http://eclipse.org/rap/downloads/">first release candidate for RAP 2.0</a>.</p>
<p>When you look at our <a href="http://eclipse.org/rap/noteworthy/2.0/?build=RC1">New and Noteworthy</a> log for RAP 2.0 RC1, you&#8217;ll notice that we are going to <a href="http://eclipsesource.com/blogs/2012/11/26/rap-becomes-the-remote-application-platform/">live up our new name</a>: The brand new RAP &#8220;Remote&#8221; API on Server and Client makes custom widget development much simpler than it ever was. This is also the first time we publish official JavaScript API, making JavaScript components much more future-poof.</p>
<p>This build also introduces simplified EntryPoints, which can safe you a nice bit of typing when starting new RWT applications or snippets:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HelloEntryPoint <span style="color: #000000; font-weight: bold;">extends</span> AbstractEntryPoint <span style="color: #009900;">&#123;</span>
&nbsp;
  @Override
  <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> createContents<span style="color: #009900;">&#40;</span> <span style="color: #003399;">Composite</span> parent <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">Button</span> button <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Button</span><span style="color: #009900;">&#40;</span> parent, SWT.<span style="color: #006633;">PUSH</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    button.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;Hello World!&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>We encourage everyone to <a href="http://eclipse.org/rap/downloads/">download and install RC1</a>, and report any issues you may find to the RAP Newsgroup or Bugzilla. RAP 2.0 will be released on February 11. </p>
<p><br/><div style="display: inline-block"><a href="https://twitter.com/intent/tweet?source=webclient&amp;text=RAP+2.0+RC1+published&amp;via=eclipsesource&amp;url=http://eclipsesource.com/blogs/2013/01/18/rap-2-0-rc1-published/" target="_blank" title="Share on Twitter" style="margin-right: 5px;"><img title="Twitter" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/twitter.png" alt="Twitter"/></a><a href="https://plus.google.com/share?url=http://eclipsesource.com/blogs/2013/01/18/rap-2-0-rc1-published/" target="_blank" title="+1" style="margin-right: 5px;"><img title="Google+" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/google_plus.png" alt="Google+"/></a><a href="http://www.linkedin.com/cws/share?url=http://eclipsesource.com/blogs/2013/01/18/rap-2-0-rc1-published/" target="_blank" title="Share on LinkedIn" style="margin-right: 5px;"><img title="LinkedIn" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/linkedin.png" alt="LinkedIn"/></a><a href="https://www.facebook.com/sharer/sharer.php?u=http://eclipsesource.com/blogs/2013/01/18/rap-2-0-rc1-published/&amp;t=RAP+2.0+RC1+published" target="_blank" title="Facebook" style="margin-right: 5px;"><img title="Facebook" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/facebook.png" alt="Facebook"/></a></div><br/>Comments are off for this post.. Tagged with <a href='http://eclipsesource.com/blogs/tag/eclipse/' title='eclipse Tag'>eclipse</a>, <a href='http://eclipsesource.com/blogs/tag/new/' title='New Tag'>New</a>, <a href='http://eclipsesource.com/blogs/tag/new-and-noteworthy/' title='new and noteworthy Tag'>new and noteworthy</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a>, <a href='http://eclipsesource.com/blogs/tag/eclipse/' title='eclipse Tag'>eclipse</a>, <a href='http://eclipsesource.com/blogs/tag/new/' title='New Tag'>New</a>, <a href='http://eclipsesource.com/blogs/tag/new-and-noteworthy/' title='new and noteworthy Tag'>new and noteworthy</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a></p>]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2013/01/18/rap-2-0-rc1-published/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RAP ClientServices explained</title>
		<link>http://eclipsesource.com/blogs/2012/12/17/rap-clientservices-explained/</link>
		<comments>http://eclipsesource.com/blogs/2012/12/17/rap-clientservices-explained/#comments</comments>
		<pubDate>Mon, 17 Dec 2012 14:28:38 +0000</pubDate>
		<dc:creator>Tim Buschtöns</dc:creator>
				<category><![CDATA[EclipseSource News]]></category>
		<category><![CDATA[Planet Eclipse]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[rap]]></category>
		<category><![CDATA[Tabris]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=12966</guid>
		<description><![CDATA[One of the bigger changes in the RAP 2.0 API is the introduction of client services. These are features that interact with the client, but aren&#8217;t directly related to the widget toolkit. Since there are now multiple types of clients that can be connected (mainly our default WebClient, Tabris for iOS and Tabris for Android), <a href="http://eclipsesource.com/blogs/2012/12/17/rap-clientservices-explained/" style="text-decoration: none;">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>One of the bigger changes in the <a href="eclipse.org/rap/noteworthy/2.0/">RAP 2.0 API</a> is the introduction of client services. These are features that interact with the client, but aren&#8217;t directly related to the widget toolkit. Since there are now multiple types of clients that can be connected (mainly our default WebClient, <a href="http://developer.eclipsesource.com/tabris/">Tabris for iOS and Tabris for Android</a>), as well as different environments (browser, OS version, hardware), not all of these features may be available at all times.</p>
<p><a href="http://eclipsesource.com/blogs/?attachment_id=" rel="attachment wp-att-13007"><img class="aligncenter size-full wp-image-13007" style="margin-left: auto; margin-right: auto;" alt="clientervices RAP ClientServices explained" src="http://eclipsesource.com/blogs/wp-content/uploads/2012/12/clientervices.png" width="405" height="360" title="RAP ClientServices explained" /></a></p>
<p>The client service API accounts for that. In RAP 2.0, the client is represented by a class implementing the <code>Client</code> interface (<code>WebClient</code> by default). An instance of this class can be obtained from <code>RWT.getClient()</code>, which selects an implementation that matches the currently connected client. This implementation then provides the client services via the <code>getService</code> method. For example:<br />



<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">MyService service <span style="color: #339933;">=</span> RWT.<span style="color: #006633;">getClient</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getService</span><span style="color: #009900;">&#40;</span> MyService.<span style="color: #000000; font-weight: bold;">class</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


</p>
<p>If the client connected to the current session supports the service, an instance is returned, otherwise null. (Also, within one session it will always return the same instance for the same service.) If you can be certain that the service is supported by all clients you are targeting, you can use it immediately, otherwise you should check for null first.</p>
<p>Right now, all services that are part of RAP are supported by the WebClient at all times. Some of them provide features that already existed in RAP 1.x in some form, some of them are completely new. There will certainly be even more in the future, especially ones that are based on HTML5-only features. As such, their availability at runtime may depend on the currently connected browser.</p>
<p>For now there is:</p>
<ul>
<li><b>ClientInfo</b>: Provides you with the clients timezone offset and locale setting.</li>
<li><b>BrowserNavigation</b>: Allows you to support the browser&#8217;s back/forward button and deep linking.</li>
<li><b>ExitConfirmation</b>: Lets you set a message that is displayed if the users tries to close the window or navigate to another website.</li>
<li><b>UrlLauncher</b>: Open any given URL without leaving the application or influencing the client. May be used to open other websites, view files, start mailing or calling a specific person. May also support opening save dialogs in the future.</li>
<li><b>JavaScriptLoader</b>: This new feature allows the server to add JavaScript to an already running client. The service also keeps track of which files have already been loaded. This makes it easy to develop custom widgets/components that are loaded as they are needed, keeping the initial loading time for the user as short as possible. (Fittingly, we also introduce a new custom component API in 2.0).</li>
<li><b>JavaScriptExecuter</b>: This service allows you access the client directly. If there is a simple, client-related task that RAP does not provide any Java API for (yet), this may be a way around that. Of course one should be <em>very</em> careful with this feature. Using it incorrectly may disrupt or even crash the entire client. Just make sure your script can not throw any exceptions and does not mess with any clients internals.</li>
</ul>
<p><b>Update:</b> You can try all services in the <a href="http://rap.eclipsesource.com/controlsdemo/controls#ClientServices">updated Controls Demo</a>.</p>
<p><br/><div style="display: inline-block"><a href="https://twitter.com/intent/tweet?source=webclient&amp;text=RAP+ClientServices+explained&amp;via=eclipsesource&amp;url=http://eclipsesource.com/blogs/2012/12/17/rap-clientservices-explained/" target="_blank" title="Share on Twitter" style="margin-right: 5px;"><img title="Twitter" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/twitter.png" alt="Twitter"/></a><a href="https://plus.google.com/share?url=http://eclipsesource.com/blogs/2012/12/17/rap-clientservices-explained/" target="_blank" title="+1" style="margin-right: 5px;"><img title="Google+" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/google_plus.png" alt="Google+"/></a><a href="http://www.linkedin.com/cws/share?url=http://eclipsesource.com/blogs/2012/12/17/rap-clientservices-explained/" target="_blank" title="Share on LinkedIn" style="margin-right: 5px;"><img title="LinkedIn" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/linkedin.png" alt="LinkedIn"/></a><a href="https://www.facebook.com/sharer/sharer.php?u=http://eclipsesource.com/blogs/2012/12/17/rap-clientservices-explained/&amp;t=RAP+ClientServices+explained" target="_blank" title="Facebook" style="margin-right: 5px;"><img title="Facebook" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/facebook.png" alt="Facebook"/></a></div><br/>Comments are off for this post.. Tagged with <a href='http://eclipsesource.com/blogs/tag/html5/' title='html5 Tag'>html5</a>, <a href='http://eclipsesource.com/blogs/tag/javascript/' title='javascript Tag'>javascript</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a>, <a href='http://eclipsesource.com/blogs/tag/tabris/' title='Tabris Tag'>Tabris</a>, <a href='http://eclipsesource.com/blogs/tag/html5/' title='html5 Tag'>html5</a>, <a href='http://eclipsesource.com/blogs/tag/javascript/' title='javascript Tag'>javascript</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a>, <a href='http://eclipsesource.com/blogs/tag/tabris/' title='Tabris Tag'>Tabris</a></p>]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2012/12/17/rap-clientservices-explained/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eclipse RAP on Windows 8: First Impressions</title>
		<link>http://eclipsesource.com/blogs/2012/11/12/eclipse-rap-on-windows-8-first-impressions/</link>
		<comments>http://eclipsesource.com/blogs/2012/11/12/eclipse-rap-on-windows-8-first-impressions/#comments</comments>
		<pubDate>Mon, 12 Nov 2012 12:57:22 +0000</pubDate>
		<dc:creator>Tim Buschtöns</dc:creator>
				<category><![CDATA[EclipseSource News]]></category>
		<category><![CDATA[Planet Eclipse]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[kepler]]></category>
		<category><![CDATA[rap]]></category>
		<category><![CDATA[windows 8]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=12501</guid>
		<description><![CDATA[Along with the release of Windows 8 also came the new Internet Explorer 10. (It has not yet been released for Windows 7.) While IE9 was an impressive (but overdue) technical improvement over IE8, IE10 is &#8211; naturally &#8211; a much smaller step forward. Significant for RAP are especially the improvements in CSS3 support, and <a href="http://eclipsesource.com/blogs/2012/11/12/eclipse-rap-on-windows-8-first-impressions/" style="text-decoration: none;">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Along with the release of Windows 8 also came the new Internet Explorer 10. (It has not yet been released for Windows 7.) While IE9 was an impressive (but overdue) technical improvement over IE8, IE10 is &#8211; naturally &#8211; a much smaller step forward. Significant for <a href="http://developer.eclipsesource.com/technology/crossplatform/#rap">RAP</a> are especially the improvements in CSS3 support, and the new touchscreen controls when running IE in its &#8220;modern app&#8221; (Metro) mode. Google Chrome also <a href="http://support.google.com/chrome/bin/answer.py?hl=en&amp;answer=2762879">already supports</a> the new windows 8 UI, so we will take a look at that too. Firefox only runs in desktop mode, but I also tried it shortly.</p>
<p>I did all my testing with the upcoming <a href="http://eclipse.org/rap/downloads/">RAP 2.0M3</a> on a 64Bit Intel version of Windows 8. I currently have no WinRT tablet available for testing.</p>
<h3>IE 10, Desktop mode</h3>
<p>RAP basically runs like it would on IE9. That means that it takes advantage of modern features like HTML5, but not to the same degree as on Firefox and Chrome/Safari. One shortcoming of IE9 was its limited support of CSS3, which is why RAP used some SVG in the UI to compensate for that. Since IE10 is currently running as IE9, this is still the case.</p>
<p><a href="http://eclipsesource.com/blogs/wp-content/uploads/2012/11/ie10_svg.png"><img class="alignnone size-large wp-image-12504" title="ie10_svg" src="http://eclipsesource.com/blogs/wp-content/uploads/2012/11/ie10_svg-1024x739.png" alt="ie10 svg 1024x739 Eclipse RAP on Windows 8: First Impressions" width="1024" height="739" /></a></p>
<p>After 5 minutes of hacking I got RAP to only use CSS3 in IE10. While it generally works, there seems to be an issue with gradients having an incorrect orientation. If it turns out to be an easy fix, we might be able to render the UI with CSS3 only in RAP 2.x/IE10.</p>
<h3>IE 10, App mode</h3>
<p>For IE to run in app mode, it has to be set as the default browser. It took me a while to figure that out. It&#8217;s like IE is offended that I dared to install another browser.</p>
<p>The UI seems to work like in desktop mode, but we are here to look at the controls. Using the mouse already causes some issue: Usually a right-click is used to bring up the URL-bar, which is hidden by default. However, that does not work while running a RAP application. It should not be hard to fix, assuming there is a way to detect IEs app-mode with JavaScript. Using fingers (swipe from bottom) or keyboard (CTRL+L) works fine though.</p>
<p><a href="http://eclipsesource.com/blogs/wp-content/uploads/2012/11/ie10_metro_css3.png"><img class="alignnone  wp-image-12506" title="ie10_metro_css3" src="http://eclipsesource.com/blogs/wp-content/uploads/2012/11/ie10_metro_css3-1024x575.png" alt="ie10 metro css3 1024x575 Eclipse RAP on Windows 8: First Impressions" width="1024" height="575" /></a></p>
<p style="text-align: center;"><small><em>Running fullscreen, the RAP theming fits quite well with the metro design.</em></small></p>
<p>Using fingers to press buttons and menus, or select items also works flawlessly, as does editing text. Double-tapping zooms into the application, a feature which we usually suppress on iOS and Android to allow quick selections and double-clicks. Touch-scrolling does not work at all except on multi-line textfields. Dragging any other items (like scrollbar thumbs) is also not possible.</p>
<p>RAP already supports all of this on iOS and Android (within limitations), but that code was written specifically for webkit browser and does not seem to work on IE10. We will likely have to put some effort into getting IE10 to the same level. Amusingly, the IE10-gesture of swiping left/right to navigate back/forward works very well with the more advanced BrowserHistory feature of RAP, as can be tested with the <a href="http://rap.eclipsesource.com/rapdemo/examples#input">Examples Demo</a>.</p>
<h3>Google Chrome 23</h3>
<p>Even though RAP does not detect Chrome on Windows as a touch-enabled browser, touch-controls work pretty good. Even scrolling trees and tables works, which was a huge issue on Android and iOS. Double-tapping does not zoom, but correctly fires a double-click event.<br />
Fixing the touch-detecting in RAP improves the touch-scrolling a bit, but changes nothing else.</p>
<h3>Firefox 17 beta</h3>
<p>Firefox is also not detected as a touch-device. Emulating simple clicks works fine, but that&#8217;s about it. Clicking in textfields does not bring up the keyboard. Touch-scrolling works, but is very much broken. However, since this version of Firefox is not yet a &#8220;real&#8221; Windows 8 app, let&#8217;s hope for an improved version soon.</p>
<h3>Conclusion</h3>
<p>Overall RAP is usable with touchscreens on Windows 8, though not quite yet at the same level as in iOS. However, support is noticeably better than it initially was with the first iOS/Android devices, so it should be not quite as hard for RAP to get there.</p>
<p><br/><div style="display: inline-block"><a href="https://twitter.com/intent/tweet?source=webclient&amp;text=Eclipse+RAP+on+Windows+8%3A+First+Impressions&amp;via=eclipsesource&amp;url=http://eclipsesource.com/blogs/2012/11/12/eclipse-rap-on-windows-8-first-impressions/" target="_blank" title="Share on Twitter" style="margin-right: 5px;"><img title="Twitter" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/twitter.png" alt="Twitter"/></a><a href="https://plus.google.com/share?url=http://eclipsesource.com/blogs/2012/11/12/eclipse-rap-on-windows-8-first-impressions/" target="_blank" title="+1" style="margin-right: 5px;"><img title="Google+" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/google_plus.png" alt="Google+"/></a><a href="http://www.linkedin.com/cws/share?url=http://eclipsesource.com/blogs/2012/11/12/eclipse-rap-on-windows-8-first-impressions/" target="_blank" title="Share on LinkedIn" style="margin-right: 5px;"><img title="LinkedIn" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/linkedin.png" alt="LinkedIn"/></a><a href="https://www.facebook.com/sharer/sharer.php?u=http://eclipsesource.com/blogs/2012/11/12/eclipse-rap-on-windows-8-first-impressions/&amp;t=Eclipse+RAP+on+Windows+8%3A+First+Impressions" target="_blank" title="Facebook" style="margin-right: 5px;"><img title="Facebook" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/facebook.png" alt="Facebook"/></a></div><br/>Comments are off for this post.. Tagged with <a href='http://eclipsesource.com/blogs/tag/ajax/' title='ajax Tag'>ajax</a>, <a href='http://eclipsesource.com/blogs/tag/javascript/' title='javascript Tag'>javascript</a>, <a href='http://eclipsesource.com/blogs/tag/kepler/' title='kepler Tag'>kepler</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a>, <a href='http://eclipsesource.com/blogs/tag/windows-8/' title='windows 8 Tag'>windows 8</a>, <a href='http://eclipsesource.com/blogs/tag/ajax/' title='ajax Tag'>ajax</a>, <a href='http://eclipsesource.com/blogs/tag/javascript/' title='javascript Tag'>javascript</a>, <a href='http://eclipsesource.com/blogs/tag/kepler/' title='kepler Tag'>kepler</a>, <a href='http://eclipsesource.com/blogs/tag/rap/' title='rap Tag'>rap</a>, <a href='http://eclipsesource.com/blogs/tag/windows-8/' title='windows 8 Tag'>windows 8</a></p>]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2012/11/12/eclipse-rap-on-windows-8-first-impressions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to deal with whitespaces in the Eclipse IDE</title>
		<link>http://eclipsesource.com/blogs/2012/10/08/how-to-deal-with-whitespaces-in-the-eclipse-ide/</link>
		<comments>http://eclipsesource.com/blogs/2012/10/08/how-to-deal-with-whitespaces-in-the-eclipse-ide/#comments</comments>
		<pubDate>Mon, 08 Oct 2012 09:27:13 +0000</pubDate>
		<dc:creator>Tim Buschtöns</dc:creator>
				<category><![CDATA[EclipseSource News]]></category>
		<category><![CDATA[Planet Eclipse]]></category>
		<category><![CDATA[clean code]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=11286</guid>
		<description><![CDATA[Whatever your project&#8217;s specific policy on whitespaces is (tabs vs. spaces, etc), the most important rule should always be consistency. Not just to make your code look nice, but also to avoid issues with patches and your version control system. Changes to whitespaces may be more or less invisible to the naked eye, but Git <a href="http://eclipsesource.com/blogs/2012/10/08/how-to-deal-with-whitespaces-in-the-eclipse-ide/" style="text-decoration: none;">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Whatever your project&#8217;s specific policy on whitespaces is (tabs vs. spaces, etc), the most important rule should always be consistency. Not just to make your code look nice, but also to avoid issues with patches and your version control system. Changes to whitespaces may be more or less invisible to the naked eye, but Git and co. register them anyway.</p>
<p>Here are some simple ways to automate how you deal with whitespaces in Eclipse.</p>
<p>First, if you don&#8217;t want to have trailing spaces in your java code (why would you), you can remove them automatically:<br />
<a href="http://eclipsesource.com/blogs/wp-content/uploads/2012/10/spaces1e.png"><img class="alignnone size-full wp-image-11288" style="margin-top: 10px; margin-bottom: 10px;" title="spaces1e" src="http://eclipsesource.com/blogs/wp-content/uploads/2012/10/spaces1e.png" alt="spaces1e How to deal with whitespaces in the Eclipse IDE" width="697" height="599" /></a><br />
If you use JSDT, there also is an option available to turn this feature on for javascript.</p>
<p>Second, if you want to be sure not to miss any unwanted whitespaces, you can configure Eclipse to show them as characters. Since doing this for all whitespaces can make the code harder to read, you can choose to show only those you don&#8217;t want to have in your code:<br />
<a href="http://eclipsesource.com/blogs/wp-content/uploads/2012/10/spaces2e1.png"><img class="alignnone size-full wp-image-11293" style="margin-top: 10px; margin-bottom: 10px;" title="spaces2e" src="http://eclipsesource.com/blogs/wp-content/uploads/2012/10/spaces2e1.png" alt="spaces2e1 How to deal with whitespaces in the Eclipse IDE" width="713" height="733" /></a><br />
This setting affects all text files, including java, javascript and HTML. Sadly, there is no option yet that shows only two or more enclosed spaces.</p>
<p><br/><div style="display: inline-block"><a href="https://twitter.com/intent/tweet?source=webclient&amp;text=How+to+deal+with+whitespaces+in+the+Eclipse+IDE&amp;via=eclipsesource&amp;url=http://eclipsesource.com/blogs/2012/10/08/how-to-deal-with-whitespaces-in-the-eclipse-ide/" target="_blank" title="Share on Twitter" style="margin-right: 5px;"><img title="Twitter" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/twitter.png" alt="Twitter"/></a><a href="https://plus.google.com/share?url=http://eclipsesource.com/blogs/2012/10/08/how-to-deal-with-whitespaces-in-the-eclipse-ide/" target="_blank" title="+1" style="margin-right: 5px;"><img title="Google+" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/google_plus.png" alt="Google+"/></a><a href="http://www.linkedin.com/cws/share?url=http://eclipsesource.com/blogs/2012/10/08/how-to-deal-with-whitespaces-in-the-eclipse-ide/" target="_blank" title="Share on LinkedIn" style="margin-right: 5px;"><img title="LinkedIn" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/linkedin.png" alt="LinkedIn"/></a><a href="https://www.facebook.com/sharer/sharer.php?u=http://eclipsesource.com/blogs/2012/10/08/how-to-deal-with-whitespaces-in-the-eclipse-ide/&amp;t=How+to+deal+with+whitespaces+in+the+Eclipse+IDE" target="_blank" title="Facebook" style="margin-right: 5px;"><img title="Facebook" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/facebook.png" alt="Facebook"/></a></div><br/>Comments are off for this post.. Tagged with <a href='http://eclipsesource.com/blogs/tag/clean-code/' title='clean code Tag'>clean code</a>, <a href='http://eclipsesource.com/blogs/tag/eclipse/' title='eclipse Tag'>eclipse</a>, <a href='http://eclipsesource.com/blogs/tag/git/' title='git Tag'>git</a>, <a href='http://eclipsesource.com/blogs/tag/java/' title='Java Tag'>Java</a>, <a href='http://eclipsesource.com/blogs/tag/javascript/' title='javascript Tag'>javascript</a>, <a href='http://eclipsesource.com/blogs/tag/tips/' title='tips Tag'>tips</a>, <a href='http://eclipsesource.com/blogs/tag/clean-code/' title='clean code Tag'>clean code</a>, <a href='http://eclipsesource.com/blogs/tag/eclipse/' title='eclipse Tag'>eclipse</a>, <a href='http://eclipsesource.com/blogs/tag/git/' title='git Tag'>git</a>, <a href='http://eclipsesource.com/blogs/tag/java/' title='Java Tag'>Java</a>, <a href='http://eclipsesource.com/blogs/tag/javascript/' title='javascript Tag'>javascript</a>, <a href='http://eclipsesource.com/blogs/tag/tips/' title='tips Tag'>tips</a></p>]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2012/10/08/how-to-deal-with-whitespaces-in-the-eclipse-ide/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Why should we always program in English?</title>
		<link>http://eclipsesource.com/blogs/2012/09/03/js-i18n/</link>
		<comments>http://eclipsesource.com/blogs/2012/09/03/js-i18n/#comments</comments>
		<pubDate>Mon, 03 Sep 2012 08:19:19 +0000</pubDate>
		<dc:creator>Tim Buschtöns</dc:creator>
				<category><![CDATA[EclipseSource News]]></category>
		<category><![CDATA[clean code]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=10472</guid>
		<description><![CDATA[Want to be a developer, but your English is really, really bad? Are you learning some other language and want to practice while doing your job? Or do you just want drive your colleagues insane with code that only you can read &#8211; because you happen to know Hindi? If you are a Javascript developer, <a href="http://eclipsesource.com/blogs/2012/09/03/js-i18n/" style="text-decoration: none;">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Want to be a developer, but your English is really, really bad? Are you learning some other language and want to practice while doing your job? Or do you just want drive your colleagues insane with code that only you can read &#8211; because you happen to know Hindi?</p>
<p>If you are a Javascript developer, <a href="http://fhtr.org/js-i18n/">this internationalization tool</a> fixes all these problems.</p>
<p>Instead of writing&#8230;</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">function</span> foo<span style="color: #009900;">&#40;</span> arr <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> arr.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> arr<span style="color: #009900;">&#91;</span> i <span style="color: #009900;">&#93;</span> <span style="color: #339933;">===</span> <span style="color: #003366; font-weight: bold;">undefined</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      arr<span style="color: #009900;">&#91;</span> i <span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000066; font-weight: bold;">return</span> arr<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>&#8230;you could write&#8230;</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">funktion foo<span style="color: #009900;">&#40;</span> arr <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  für<span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> arr.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    wenn<span style="color: #009900;">&#40;</span> arr<span style="color: #009900;">&#91;</span> i <span style="color: #009900;">&#93;</span> <span style="color: #339933;">===</span> undefiniert <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      arr<span style="color: #009900;">&#91;</span> i <span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
  rücksprung arr<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>&#8230; or &#8230;</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">функция foo<span style="color: #009900;">&#40;</span> arr <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  для<span style="color: #009900;">&#40;</span> пер i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> arr.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    если<span style="color: #009900;">&#40;</span> arr<span style="color: #009900;">&#91;</span> i <span style="color: #009900;">&#93;</span> <span style="color: #339933;">===</span> неопредел <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      arr<span style="color: #009900;">&#91;</span> i <span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> нуль<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
  возврат arr<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>&#8230; and the code will still work.</p>
<p>Seriously though, I&#8217;m not 100% sure if this is supposed to be a joke or not. I&#8217;ve seen developers naming variables in their code in their native language. I even did it myself &#8211; when I was 12.</p>
<p>I&#8217;m not sure if it&#8217;s because of a lack of language skills or some sense of linguistic purity/anglophobia, but it&#8217;s really cringe-worthy. Not only will almost no one outside your country be able to understand it, but the constant switching between English keywords and another language is just confusing and hard to read. (Though I guess this tool would solve that particular problem&#8230;)</p>
<p><br/><div style="display: inline-block"><a href="https://twitter.com/intent/tweet?source=webclient&amp;text=Why+should+we+always+program+in+English%3F&amp;via=eclipsesource&amp;url=http://eclipsesource.com/blogs/2012/09/03/js-i18n/" target="_blank" title="Share on Twitter" style="margin-right: 5px;"><img title="Twitter" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/twitter.png" alt="Twitter"/></a><a href="https://plus.google.com/share?url=http://eclipsesource.com/blogs/2012/09/03/js-i18n/" target="_blank" title="+1" style="margin-right: 5px;"><img title="Google+" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/google_plus.png" alt="Google+"/></a><a href="http://www.linkedin.com/cws/share?url=http://eclipsesource.com/blogs/2012/09/03/js-i18n/" target="_blank" title="Share on LinkedIn" style="margin-right: 5px;"><img title="LinkedIn" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/linkedin.png" alt="LinkedIn"/></a><a href="https://www.facebook.com/sharer/sharer.php?u=http://eclipsesource.com/blogs/2012/09/03/js-i18n/&amp;t=Why+should+we+always+program+in+English%3F" target="_blank" title="Facebook" style="margin-right: 5px;"><img title="Facebook" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/facebook.png" alt="Facebook"/></a></div><br/>Comments are off for this post.. Tagged with <a href='http://eclipsesource.com/blogs/tag/clean-code/' title='clean code Tag'>clean code</a>, <a href='http://eclipsesource.com/blogs/tag/javascript/' title='javascript Tag'>javascript</a>, <a href='http://eclipsesource.com/blogs/tag/clean-code/' title='clean code Tag'>clean code</a>, <a href='http://eclipsesource.com/blogs/tag/javascript/' title='javascript Tag'>javascript</a></p>]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2012/09/03/js-i18n/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Debugging JavaScript on Android and iOS</title>
		<link>http://eclipsesource.com/blogs/2012/08/14/debugging-javascript-on-android-and-ios/</link>
		<comments>http://eclipsesource.com/blogs/2012/08/14/debugging-javascript-on-android-and-ios/#comments</comments>
		<pubDate>Tue, 14 Aug 2012 08:44:18 +0000</pubDate>
		<dc:creator>Tim Buschtöns</dc:creator>
				<category><![CDATA[EclipseSource News]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">http://eclipsesource.com/blogs/?p=9357</guid>
		<description><![CDATA[Overall, mobile browsers are an appealing alternative to native applications: They support most modern web standards like HTML5 and CSS3, and you don't have to set up and learn using multiple SDKs. The technical limitations that do exist  will hopefully get fewer as time goes on (or get patched otherwise), while performance and stability will <a href="http://eclipsesource.com/blogs/2012/08/14/debugging-javascript-on-android-and-ios/" style="text-decoration: none;">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Overall, mobile browsers are an appealing alternative to native applications: They support most modern web standards like HTML5 and CSS3, and you don't have to set up and learn using multiple SDKs. The technical limitations that <em>do</em> exist  will hopefully get fewer as time goes on (<a href="http://phonegap.com/">or get patched otherwise</a>), while performance and stability will improve. Sure, native apps will always have some advantages, but proper debugging tools should not be one of them. Why those were not available for iOS and Android right from the start is baffling to me, it basically threw us back into the stone age of alert-debugging.</p>
<p>In this article I will describe four basic approaches to debugging JavaScript on Android (stock browser and Google Chrome) and iOS (Safari), and consider the pros and cons respectively. While you can read about some of these tools here and there, I've got the impression that some authors only tried them shortly to see if it works at all. I really used most of these at some point to <a title="Eclipse RAP" href="http://eclipse.org/rap">get actual work done</a>.</p>
<p>I will occasionally use an example script that contains the following function:<br />



<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">function</span> foo<span style="color: #009900;">&#40;</span> myObject<span style="color: #339933;">,</span> myNumber <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">var</span> bar <span style="color: #339933;">=</span> <span style="color: #CC0000;">10</span> <span style="color: #339933;">/</span> myNumber<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">var</span> result <span style="color: #339933;">=</span> myObject.<span style="color: #660066;">calcSomething</span><span style="color: #009900;">&#40;</span> bar <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;result&quot;</span> <span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;The result is &quot;</span> <span style="color: #339933;">+</span> result<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


It is expected to be called with the second parameter (<code>myNumber</code>) being 7. It is then supposed to write "The result is 286" on the screen. The function itself has no bugs in it, but it might not be working for a number of other reasons.</p>
<p>Contents:</p>
<ol>
<li><a href="#ch1">Native Tools</a></li>
<li><a href="#ch2">JavaScript and Bookmarklets</a></li>
<li><a href="#ch3">HTTP Remote-Debugging</a></li>
<li><a href="#ch4">USB Remote-Debugging</a></li>
<li><a href="#concl">Conclusion</a></li>
</ol>
<h2 id="ch1"></h2>
<h2>1. Native Tools</h2>
<p>This is what you can do with only your phone or tablet. (Without injecting additional JavaScript into your application.) It isn't much.</p>
<p><strong>iOS</strong></p>
<p>For iOS you can enable the debug console. Go to Settings -&gt; Safari -&gt; Advanced, set "Debug Console" to "on". This makes a bar appear at the top of the browser. Tapping that bar shows the console. Here all uncaught exceptions are logged, much like they would on MacOS/Windows Safari for example. The buttons at the bottom allow you to filter the messages, but you can not type anything, or interact in any other way.</p>
<p style="text-align: center;"><a href="http://eclipsesource.com/blogs/wp-content/uploads/2012/08/IMG_00161.png"><img class="size-full wp-image-9918 aligncenter" style="border: 1px solid #aaaaaa; padding: 5px;" title="Mobile Safari Console" src="http://eclipsesource.com/blogs/wp-content/uploads/2012/08/IMG_00161.png" alt="IMG 00161 Debugging JavaScript on Android and iOS" width="255" height="144" /></a></p>
<p style="text-align: center;"><em>This would not really explain why our script does not print anything.</em></p>
<p style="text-align: left;">You can also use <code>console.log()</code> in your script to print out messages:</p>
<p style="text-align: center;"><a href="http://eclipsesource.com/blogs/wp-content/uploads/2012/08/log.png"><img class="alignnone size-full wp-image-9928 aligncenter" style="border: 1px solid #aaaaaa; padding: 5px;" title="log" src="http://eclipsesource.com/blogs/wp-content/uploads/2012/08/log.png" alt="log Debugging JavaScript on Android and iOS" width="469" height="361" /></a></p>
<p style="text-align: center;"><em>Now we can tell that it's myObject that is null, but only since we already suspected it and put the log there.<br />
It also does not tell us why. For that a stacktrace, or better yet, a step-by-step debugger would be helpful.<br />
</em></p>
<p>The functions <code>debug()</code>, <code>info()</code>, <code>warn()</code> and <code>error()</code> do the same, just with different icons. There are also a bunch of other functions on the console object, but they all don't seem to do anything. Even <code>console.trace()</code>, which can be really useful sometimes, doesn't work at all.</p>
<p>I also found an <a href="http://itunes.apple.com/gb/app/jsconsole/id386805071?mt=8">JS console app</a>, but it's more suitable for experimenting with JavaScript, not for debugging.</p>
<p><strong>Android</strong></p>
<p>The Android Browser doesn't have a console, or any other tools working out of the box. However, I found some apps in Googles Play store that could help.</p>
<p><a href="https://play.google.com/store/apps/details?id=com.zoeetrope.jslog&amp;feature=search_result">JS Log</a> is basically a replacement for the js iOS console. It logs messages and uncaught exceptions in the Android notification area. Too bad that it worked very unreliably.  On my Android 3 tablet it sometimes didn't log even when explicitly calling <code>console.log()</code>. On my Android 4 phone it didn't work at all. (So no Google Chrome support either.) Not recommended.</p>
<p>The <a href="https://play.google.com/store/apps/details?id=com.starbug1.android.htmldomviewer&amp;feature=nav_result">HTML DOM Viewer</a> is a minimalstic browser (presumably using the default Android browser internally) that also features a console (for logging only), and allows you to inspect the current HTML/DOM state. Unlike JS Log it's pretty reliable, but it's not very convenient to use. I wasn't able to scroll or clear the console, which is already a deal-breaker. The HTML view has no syntax highlighting at all, and longer tags do not wrap, nor can you scroll horizontally. Oh, and it has ads:</p>
<p style="text-align: center;"><a href="http://eclipsesource.com/blogs/wp-content/uploads/2012/08/Screenshot_2012-08-02-11-02-371.png"><img class="alignnone  wp-image-9926 aligncenter" style="border: 1px solid #aaaaaa; padding: 5px;" title="Screenshot_2012-08-02-11-02-37" src="http://eclipsesource.com/blogs/wp-content/uploads/2012/08/Screenshot_2012-08-02-11-02-371.png" alt="Screenshot 2012 08 02 11 02 371 Debugging JavaScript on Android and iOS" height="400" /></a></p>
<p style="text-align: center;"><em>Sadly, no real recommandation for this tool either.</em></p>
<div style="border: 1px dashed #aaaaaa; width: auto; padding-left: 10px;">
<p><strong>Summary Native Tools:</strong></p>
<p><em>Pro:</em></p>
<ul>
<li>Quick Setup</li>
<li>Still better than using "alert"</li>
</ul>
<p><em>Con:</em></p>
<ul>
<li>Helps only in simple cases.</li>
<li>Requires additional Apps for Android, which don't work very well.</li>
<li><a href="https://www.google.com/search?btnG=1&amp;pws=0&amp;q=IOS6+safari+console">Safari console will be dropped from iOS?</a></li>
</ul>
</div>
<h2 id="ch2"></h2>
<h2>2. JavaScript and Bookmarklets</h2>
<p>Debug-tools can also be implemented with JavaScript itself, and they can be surprisingly powerful. Of coure, running in the same enviorement as the application that they are supposed to be debugging bears a slight risk of interference.</p>
<p><strong>D.I.Y.-Console for Android</strong></p>
<p>The minimal requirement for me is to have a (reliable) way to log errors and messages. So I wrote this little script for Android browsers:<br />



<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span> <span style="color: #009966; font-style: italic;">/android/gi</span> <span style="color: #009900;">&#41;</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span> navigator.<span style="color: #660066;">appVersion</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  console <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #3366CC;">&quot;_log&quot;</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;log&quot;</span> <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">var</span> arr <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> arguments.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        arr.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span> arguments<span style="color: #009900;">&#91;</span> i <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000066; font-weight: bold;">this</span>._log.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span> arr.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;, &quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;trace&quot;</span> <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">var</span> stack<span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">throw</span> <span style="color: #000066; font-weight: bold;">new</span> Error<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span> ex <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        stack <span style="color: #339933;">=</span> ex.<span style="color: #660066;">stack</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;console.trace()<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #339933;">+</span> stack.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slice</span><span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">2</span> <span style="color: #009900;">&#41;</span>.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;  <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;dir&quot;</span> <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> obj <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;Content of &quot;</span> <span style="color: #339933;">+</span> obj <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">var</span> key <span style="color: #000066; font-weight: bold;">in</span> obj <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">var</span> value <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">typeof</span> obj<span style="color: #009900;">&#91;</span> key <span style="color: #009900;">&#93;</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">&quot;function&quot;</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">&quot;function&quot;</span> <span style="color: #339933;">:</span> obj<span style="color: #009900;">&#91;</span> key <span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot; -<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933;">+</span> key <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> -&gt; <span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933;">+</span> value <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;show&quot;</span> <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      alert<span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span>._log.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">this</span>._log <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  window.<span style="color: #660066;">onerror</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> msg<span style="color: #339933;">,</span> url<span style="color: #339933;">,</span> line <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ERROR: <span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933;">+</span> msg <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> at <span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>, line &quot;</span> <span style="color: #339933;">+</span> line<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  window.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;touchstart&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> e <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> e.<span style="color: #660066;">touches</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">===</span> <span style="color: #CC0000;">3</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      console.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


</p>
<p>Copy this code into your application or put it in an external .js file and load it from your application. It replaces the dummy "console" object of the Android or Chrome browser with one that actually works. You can see the console either by calling console.show() form your code, or by touching the document with three fingers at once. (So be sure to remove the code before your application goes live.) It obviously won't work on devices that don't have multi-touch.</p>
<p style="text-align: center;"><a href="http://eclipsesource.com/blogs/wp-content/uploads/2012/08/device-2012-08-02-170408.png"><img class="size-full wp-image-9929 aligncenter" style="border: 1px solid #aaaaaa;" title="device-2012-08-02-170408" src="http://eclipsesource.com/blogs/wp-content/uploads/2012/08/device-2012-08-02-170408.png" alt="device 2012 08 02 170408 Debugging JavaScript on Android and iOS" width="750" height="435" /></a></p>
<p style="text-align: center;"><em>In contrast to the other console implementations up to this point it also supports "trace" and "dir" commands.</em></p>
<p>As you can see, it uses the alert function to display the log. This keeps the code small, robust and minimally invasive. It works well enough since Android's alert-window supports scrolling. However, if you wanted to, you could easily replace it with a &lt;div&gt; popup and pretty-print the output, or add other features like javascript execution. Personally, I like this lightweight, simplistic approach. I did not have any problems with it yet, except that the lines tend to wrap a lot due to the small size of the popup - especially on phones. It does not (and isn't supposed to) work on iOS.</p>
<p><strong>Firebug Lite</strong></p>
<p>Firebug was one of the first debugging add-ons for browsers, and it's name is almost synonymous for  such tools. <a href="https://getfirebug.com/firebuglite/">Firebug Lite</a> implements a subset of the Firebug features using JavaScript. For the most part it works well on iPad and Android tablets, though it's clearly not made for touchscreens. To use it with your application, add the following line in your header:</p>
<textarea rows="2" style="margin: 0px; height: 48px; width: 100%; ">&lt;script type="text/javascript" src="https://getfirebug.com/firebug-lite-debug.js"&gt;&lt;/script&gt;</textarea>
<p>This is the so-called debug version, because for some reason the minified version didn't work for me anywhere but the iPad. Of course this only works if you have an internet connection. Otherwise you have to download Firebug Lite and host it yourself.</p>
<p>Firebug will appear automatically:</p>
<p><a href="http://eclipsesource.com/blogs/wp-content/uploads/2012/08/IMG_0034.png"><img class="alignnone  wp-image-9935 aligncenter" style="border: 1px solid #aaaaaa;" title="IMG_0034" src="http://eclipsesource.com/blogs/wp-content/uploads/2012/08/IMG_0034.png" alt="IMG 0034 Debugging JavaScript on Android and iOS" width="690" height="518" /></a></p>
<p style="text-align: center;"><em>Firebug Lite on the iPad. Finally a stack-trace in Safari!</em></p>
<p>You can view scripts, but not set a breakpoint. However, it is possible to use the console to execute JavaScript commands:</p>
<p><a href="http://eclipsesource.com/blogs/wp-content/uploads/2012/08/IMG_0037.png"><img class="alignnone  wp-image-9946 aligncenter" style="border: 1px solid #aaaaaa;" title="IMG_0037" src="http://eclipsesource.com/blogs/wp-content/uploads/2012/08/IMG_0037.png" alt="IMG 0037 Debugging JavaScript on Android and iOS" width="690" /></a></p>
<p style="text-align: center;"><em> You should disable the keyboards auto-uppercase feature, it will save a lot of time while typing.</em></p>
<p>Viewing HTML is possible, but a bit fiddly because the UI is not designed for touchscreens. Hitting the "+" icon can be an ordeal.</p>
<p><a href="http://eclipsesource.com/blogs/wp-content/uploads/2012/08/domfb.png"><img class="alignnone  wp-image-9940 aligncenter" style="border: 1px solid #aaaaaa;" title="domfb" src="http://eclipsesource.com/blogs/wp-content/uploads/2012/08/domfb.png" alt="domfb Debugging JavaScript on Android and iOS" width="690" /></a></p>
<p style="text-align: center;"><em>This would explain why the text isn't visible...<br />
</em><em></em></p>
<p style="text-align: left;">The DOM tab doesn't work for some reason. One possible improvement with this approach is to attach a keyboard and/or mouse to your tablet.</p>
<p style="text-align: center;"><a href="http://eclipsesource.com/blogs/wp-content/uploads/2012/09/asus.jpg"><img class="alignnone  wp-image-9965 aligncenter" style="border: 1px solid #aaaaaa;" title="asus" src="http://eclipsesource.com/blogs/wp-content/uploads/2012/09/asus.jpg" alt="asus Debugging JavaScript on Android and iOS" width="500" height="520" /></a></p>
<p style="text-align: center;"><em>If your Android device has an USB port you can also attach a normal mouse.</em></p>
<p>Of course you can also just pinch-zoom in (when your application allows it), but it's less convinient and may produce minor glitches. Apparently no one has tried to make a touchscreen-friendly version of firebug or something similar. (Well, excluding my selfmade console above.)  I'm sure there are <a href="http://jsconsole.com/">other tools</a> like this out there, but I didn't find any really worthwhile yet.</p>
<p>On <strong>iPhone</strong> it didn't work at all for some reason, but Firebug is pretty much impossible to operate on phones anyway, due to the small screen.</p>
<p><strong>Bookmarklets</strong></p>
<p>Adding JavaScript tools to your application by editing your HTML/JS files isn't very convenient, and you risk forgetting to remove them afterwards. An alternative to this are bookmarklets. These are bookmarks that contain JavaScript that is executed in the loaded website. They can be created from any javascript with tools like <a href="http://ted.mielczarek.org/code/mozilla/bookmarklet.html">this one</a>. On desktop browser they are  usually added using drag and drop, but that doesn't work on mobile devices. One method is to add them to your desktop browser and sync them to your phone/tablet. (I haven't tried that yet.) Alternatively, you have to do this:</p>
<p>First you need to somehow get the code (starting with "javascript:") into the iOS/Android clipboard. Bookmarklets on websites are usually given as a link, so that won't work. Copy the code on your PC/Mac and put it into a textfile, or email, or whatever you like, and get that to your device. For our examples you can just use the code below. Select (long-press) and copy it.</p>
<p>Firebug Lite (debug):<br />
<textarea wrap="off" rows="1" style="margin: 0px; height: 60px; width: 100%; ">javascript:(function(F,i,r,e,b,u,g,L,I,T,E){if(F.getElementById(b))return;E=F[i+'NS']&&F.documentElement.namespaceURI;E=E?F[i+'NS'](E,'script'):F[i]('script');E[r]('id',b);E[r]('src',I+g+T);E[r](b,u);(F[e]('head')[0]||F[e]('body')[0]).appendChild(E);E=new%20Image;E[r]('src',I+L);})(document,'createElement','setAttribute','getElementsByTagName','FirebugLite','4','firebug-lite-debug.js','releases/lite/debug/skin/xp/sprite.png','https://getfirebug.com/','#startOpened');
</textarea></p>
<p>Firebug Lite (minified):<br />
<textarea  wrap="off" rows="1" style="margin: 0px; height: 60px; width: 100%; ">javascript:(function(F,i,r,e,b,u,g,L,I,T,E){if(F.getElementById(b))return;E=F[i+'NS']&&F.documentElement.namespaceURI;E=E?F[i+'NS'](E,'script'):F[i]('script');E[r]('id',b);E[r]('src',I+g+T);E[r](b,u);(F[e]('head')[0]||F[e]('body')[0]).appendChild(E);E=new%20Image;E[r]('src',I+L);})(document,'createElement','setAttribute','getElementsByTagName','FirebugLite','4','firebug-lite.js','releases/lite/latest/skin/xp/sprite.png','https://getfirebug.com/','#startOpened');
</textarea></p>
<p>Android Console:<br />
<textarea  wrap="off" rows="1" style="margin: 0px; height: 60px; width: 100%; ">javascript:(function(){if((/android/gi).test(navigator.appVersion)){console={"_log":[],"log":function(){var%20arr=[];for(var%20i=0;i<arguments.length;i++){arr.push(arguments[i]);}this._log.push(arr.join(",%20"));},"trace":function(){var%20stack;try{throw%20new%20Error();}catch(ex){stack=ex.stack;}console.log("console.trace()\n"+stack.split("\n").slice(2).join("%20%20\n"));},"dir":function(obj){console.log("Content%20of%20"+obj);for(var%20key%20in%20obj){var%20value=typeof%20obj[key]==="function"?"function":obj[key];console.log("%20-\""+key+"\"%20->%20\""+value+"\"");}},"show":function(){alert(this._log.join("\n"));this._log=[];}};window.onerror=function(msg,url,line){console.log("ERROR:%20\""+msg+"\"%20at%20\""+"\",%20line%20"+line);}window.addEventListener("touchstart",function(e){if(e.touches.length===3){console.show();}});}})();
</textarea></p>
<p>On the <strong>iPad</strong>, you first  have to create a bookmark in the share menu, then edit it using the "Edit" button in the bookmarks menu. Paste the code where the URL would be. For the <strong>Android</strong> browser it's a bit simpler, since you can edit the URL while creating a new bookmark. Depending on the Android version/browser, bookmarks are added by pressing some star or "+" icon, or by selecting "Save to bookmarks" from a menu.</p>
<p style="text-align: center;"><a href="http://eclipsesource.com/blogs/wp-content/uploads/2012/08/bookmarklet.png"><img class=" wp-image-9947 aligncenter" style="border: 1px solid #aaaaaa;" title="bookmarklet" src="http://eclipsesource.com/blogs/wp-content/uploads/2012/08/bookmarklet.png" alt="bookmarklet Debugging JavaScript on Android and iOS" width="690" /></a></p>
<p style="text-align: center;"><em>iOS on the left, Android on the right. Obviously.</em></p>
<p>Now you just have to open the bookmark while your application is running. This works very well to open Firebug Lite on the iPad, or the DIY console on Android 3. Sadly, that's it. I had <strong>no success with Android 2 and 4</strong> at all, and<strong> Android 3 wouldn't load Firebug</strong> half of the time, or only very slowly. Another problem is that if you need the tool while the document is loading (e.g. for logging), this solution won't work.</p>
<div style="border: 1px dashed #aaaaaa; width: auto; padding-left: 10px;">
<p><strong>Summary JavaScript and Bookmarklets:</strong></p>
<p><em>Pro:</em></p>
<ul>
<li>Stack trace on all browser.</li>
<li>Somewhat satisfying HTML view and JS execution on tablets.</li>
<li>You can easily write your own tools (within limits) if you want.</li>
<li>Reasonably fast setup...</li>
</ul>
<p><em>Con:</em></p>
<ul>
<li>...except for bookmarklets, which don't even work everywhere.</li>
<li>No step-by-step debugging, profiling or request log. DOM exploration not working in FB.</li>
<li>Limited usability and performance, especially for tools not designed for mobile devices.</li>
<li>Potentially invasive, risk of interfering with target application.</li>
</ul>
</div>
<h2 id="ch3"></h2>
<h2>3. HTTP Remote-Debugging</h2>
<p>To get around the limitations of a touchscreen-only device, remote debugging is (besides an emulator) the only way to go. In this chapter we look at tools that achieve this by injecting JavaScript into your application (debug target) that communicates with an HTTP-server (debug server), and can then be controlled by another browser (on your desktop, debug client). I will only explore the scenario of a one-to-one connection.</p>
<p><strong>weinre</strong></p>
<p>Probably the best known of such tools is <a href="http://people.apache.org/~pmuellr/weinre/docs/latest/Home.html">weinre</a>. Similar to Firebug Lite, it implements a subset of the features of the WebKit Developer Tools. It has now become part of the <a href="http://incubator.apache.org/cordova/">Apache Cordova</a> project, but there are no official releases of that yet (August 2012).  However, you can get weinre "unofficially" <a href="http://people.apache.org/~pmuellr/weinre/builds/">here</a>. I'm using "weinre-jar-1.6.1.zip" on a windows machine in my example.</p>
<p>Unzip the jar file, then type on your console (or create a script or shortcut):</p>
<textarea rows="1" style="margin: 0px; height: 28px; width: 100%; ">java -jar weinre.jar --boundHost -all- --httpPort 9090</textarea>
<p>It should print "weinre:HTTP server started at [...]". Then Add the following line to your HTML <code>&lt;head&gt;</code>, with [...] standing in for your IP:</p>
<textarea rows="2" style="margin: 0px; height: 28px; width: 100%; "><script src="http://[...]:9090/target/target-script-min.js#anonymous"></script>
</textarea>
<p>You can also use a bookmarklet (you can get the code at "http://localhost:9090/"), but if you have a dynamic IP it's pretty pointless.</p>
<p>Then open Safari or Google Chrome on your desktop machine and go to "http://localhost:9090/client/#anonymous". There your mobile device should appear under "Targets" as soon as you load your application.</p>
<p style="text-align: center;"><a href="http://eclipsesource.com/blogs/wp-content/uploads/2012/08/weinre1.png"><img class="size-full wp-image-9955 aligncenter" style="border: 1px solid #aaaaaa; padding: 5px;" title="weinre1" src="http://eclipsesource.com/blogs/wp-content/uploads/2012/08/weinre1.png" alt="weinre1 Debugging JavaScript on Android and iOS" width="628" height="313" /></a></p>
<p style="text-align: center;"><em>This is what it should look like. When you reload your target application,<br />
multiple targets may be displayed temporarily.</em></p>
<p style="text-align: left;">Weinre has a similar functional range as Firebug Lite. It doesn't support as much console commands (no trace for example), but it features a network and a timeline tab. (The last one is very limited though, and doesn't seem to catch touch events.) No step-by-step debugging or profiling either, those would likely by impossible to implement in JavaScript.</p>
<p style="text-align: center;"><a href="http://eclipsesource.com/blogs/wp-content/uploads/2012/08/weinre4.png"><img class="alignnone  wp-image-9956" style="border: 1px solid #aaaaaa;" title="weinre4" src="http://eclipsesource.com/blogs/wp-content/uploads/2012/08/weinre4.png" alt="weinre4 Debugging JavaScript on Android and iOS" width="690" /></a></p>
<p style="text-align: center;"><em>The Network tab is useful if you work with XMLHttpRequests, like this <a href="http://eclipse.org/rap/">Eclipse RAP</a> application.</em></p>
<p style="text-align: left;">I had the occasional problem to get a working connection, and performance can be bad if your application is very complex. Also, hardcoding an IP address in your script is obviously not a good idea, especially if your IP may change often. Which is where we get to...</p>
<p><strong>Adobe Shadow</strong></p>
<p>While the name might make you think <a href="http://labs.adobe.com/technologies/shadow/">Adobe Shadow</a> is completely different tool developed entirely by Adobe Systems, this is not the case. It has some nice little features of its own (like taking a screenshots of a website on multiple devices at once), but for our purposes it's just a convenient wrapper around weinre.</p>
<p>The difference is that you don't have to add any javascript to your application yourself. Instead, you download an app (<a href="http://itunes.apple.com/de/app/adobe-shadow/id498621426?mt=8">here</a> for iOS and <a href="https://play.google.com/store/apps/details?id=com.adobe.shadow.android">here</a> for Android), which will do that for you. You will also need the <a href="http://labs.adobe.com/downloads/shadow.html">server component</a> (no Linux version though) and a <a href="https://chrome.google.com/webstore/detail/ijoeapleklopieoejahbpdnhkjjgddem">Google Chrome extension</a>.</p>
<p>After you have all that, start the Adobe Shadow application and Google Chrome on your desktop, and the app on your device. Supposedly the app should find the server by itself, but I always had to enter the IP manually. Then you have to enter a short pin from your device on the Chrome extension, and you're connected. Your connected devices will all go to the same URL as your desktop Chrome browser, which is cool in theory, but can get really weired/annoying if you just change tabs to quickly look something up.</p>
<p><a href="http://eclipsesource.com/blogs/wp-content/uploads/2012/08/as.png"><img class="alignnone  wp-image-9957 aligncenter" style="border: 1px solid #aaa;" title="as" src="http://eclipsesource.com/blogs/wp-content/uploads/2012/08/as.png" alt="as Debugging JavaScript on Android and iOS" width="690" /></a></p>
<p style="text-align: center;"><em>Now you just have to click the "&lt;&gt;" icon besides any of your listed devices, and a popup with weinre opens.</em></p>
<p>I have to say that Adobe Shadow isn't much of an improvement over weinre. In fact, with Shadow I had a <em>lot </em>more issues with not getting or even loosing a connection than with just weinre. Also, both Adobe Shadow apps (iOS+Android) have that feature where they reload the page without using cache (useful!) - triggered by a "pull-down" gesture. This can interfere with your application if you work with touch events or vertically scrolling elements. It really annoys me because it's so unnecessary. Dear Adobe, what's wrong with using a button? It's a tool, not a videogame!</p>
<p>I say go with weinre, unless your IP changs really often. And even then, consider that you still have to re-connect the devices (with a pin!) to your desktop machine every time. Also, Shadow does not work on linux.</p>
<p><strong>Other</strong></p>
<p><a href="http://socketbug.com/">Socketbug</a> and <a href="https://github.com/firebug-crossfire/crossfire/wiki">Firebug Crossfire</a> and <a href="http://jsconsole.com/remote-debugging.html">remote jsconsole</a> take the same basic approach as weinre.  I didn't get around to try them, but they seem to offer  less functionality and no  significant improvement over weinre. Perhaps one of these tool will come out on top eventually, but for now I recommend weinre.</p>
<div style="border: 1px dashed #aaaaaa; width: auto; padding-left: 10px;">
<p><strong>Summary HTTP Remote-Debugging:</strong></p>
<p><em>Pro:</em></p>
<ul>
<li>Works on all browser i tested.</li>
<li>weinre/A.S can log network activity.</li>
<li>Better usability than previous methods...</li>
</ul>
<p><em>Con:</em></p>
<ul>
<li>...once the connection is established, which can be a hassle every time.</li>
<li>Still no step-by-step debugger or profiler. Timeline very limited.</li>
<li>Only minimal console support. (e.g. no stack trace)</li>
<li>Noticeable delays possible.</li>
<li>No linux support for Adobe Shadow.</li>
<li>Still invasive. (Runs partially in same environment as target.)</li>
</ul>
</div>
<h2 id="ch4"></h2>
<h2>4. USB Remote-Debugging</h2>
<p>This is very similar to HTTP Remote Debugging, but communicating with the browser application itself, not some JavaScript running inside.</p>
<p><strong>Android</strong></p>
<p>This is only possible with Google Chrome, not the default browser. (Chrome is available for Android 4+).</p>
<p>First it is required to enable USB debugging on the phone/tablet: Go to the device settings, select "Developer options" and enable "USB debugging". Then open Chrome (still on the mobile device), open the menu, go to Settings -&gt; Developer tools -&gt; "Enable USB Web debugging".</p>
<p>For the PC(/Mac) a bit of setup is requried. Download and install the <a href="http://developer.android.com/sdk/index.html">Android SDK</a>, specifically the "platform tools" and "Google USB Driver". It's available for Windows, Mac and Linux. Now connect your device to your PC via USB.  In the SDK-directory "platform-tools" you can find the executable "adb". To check that the device is properly connected, type "<code>adb devices</code>". It should appear in the printed list.</p>
<p>Now type "<code>adb forward tcp:9222 localabstract:chrome_devtools_remote</code>" and open "<code>localhost:9222</code>" on your PC's Google Chrome. You'll see a gallery representing the tabs opened on the mobile Google Chrome. Select one and you get the usual WebKit Developer Tools. Like with weinre you can use the console and DOM exploring, but now we can finally do step-by-step debugging:</p>
<p><a href="http://eclipsesource.com/blogs/wp-content/uploads/2012/08/usband.png"><img class="alignnone  wp-image-9967 aligncenter" style="border: 1px solid #aaa;" title="usband" src="http://eclipsesource.com/blogs/wp-content/uploads/2012/08/usband.png" alt="usband Debugging JavaScript on Android and iOS" width="690" /></a></p>
<p style="text-align: center;"><em>No more trial and error logging, the debugger reveals everything.</em></p>
<p>Reloading the page on the device does not require a re-connect, and even breakpoints are sustained. There's no noticeable delay.</p>
<p><a href="http://eclipsesource.com/blogs/wp-content/uploads/2012/08/usband2.png"><img class="wp-image-9968 aligncenter" style="border: 1px solid #aaaaaa;" title="usband2" src="http://eclipsesource.com/blogs/wp-content/uploads/2012/08/usband2.png" alt="usband2 Debugging JavaScript on Android and iOS" width="690" /></a></p>
<p style="text-align: center;"><em>The Timeline tab works much better now, and there is even more stuff like Profiling.</em></p>
<p>Because I'm lazy I wrote a little script so I can always get the developer tools opened in a few seconds.</p>
<p><span style="font-size: smaller;">Windows batchfile:</span><br />
<textarea rows="6" style="margin: 0px; width: 100%; ">@echo off
adb devices
adb forward tcp:9222 localabstract:chrome_devtools_remote
%localappdata%\Google\Chrome\Application\chrome.exe "http://localhost:9222/"
pause</textarea></p>
<p>If your device gets listed here, but the desktop Chrome shows something like "This webpage is not available", then USB Debugging is probably not enabled on the mobile Chrome.</p>
<p><strong>iOS</strong></p>
<p>For iOS there is a tool called <a href="http://www.iwebinspector.com/">iWebInspector</a>, which seems to be very similar. However, it's only working with the iOS simulator, not with real devices. More importantly, it's only running properly on Mac OS 10.6 or 10.7, <a href="http://www.iwebinspector.com/help.html#ml"><em>but no later</em></a>. (Windows and Linux are out anyway.) As such, I couldn't test it and consider it useless by now.</p>
<p>However, it's very likely Apple does not want to stay behind Google for long, so an <a href="http://www.mobilexweb.com/blog/ios-6-beta-1-html5-native">alternative</a> is arriving soon. Time will tell if it's going to be a match for Google Chromes remote debugging. Support for Windows or Linux machines doesn't seem very likely though. Bad Apple!</p>
<div style="border: 1px dashed #aaaaaa; width: auto; padding-left: 10px;">
<p><strong>Summary USB Remote-Debugging:</strong></p>
<p><em>Pro:</em></p>
<ul>
<li>All features you could ask for!</li>
<li>Mostly stable and fast connection.</li>
<li>Non-invasive.</li>
</ul>
<p><em>Con:</em></p>
<ul>
<li>Initial setup may be a bit time-consuming.</li>
<li>No support for Android stock browser.</li>
<li>Currently no good solution for iOS. Future solution will likely exclude win/linux users.</li>
</ul>
</div>
<h2 style="margin-top:30px;" id="concl">5.Conclusion</h2>
<p>The main issue here is that there is not one solution that fits for all cases and all browsers. The only option I can really recommend wholeheartedly is the remote USB debugging of Chrome, but that's no solution if you have a problem with another browser. If you require only logging you are probably going to be covered, but anything beyond that requires sub-optimal tools like weinre or Firebug Lite. Of those two I can't generally recommend one over the other. See which one best fits your needs.</p>
<p>You can also use a user agent switcher (like <a href="https://chrome.google.com/webstore/detail/djflhoibgkdhkhhcedjiklpkjnoahfmg?hl=en-US">this</a> one) to test your application in a normal browser. This works fine as long as you don't have a browser-specific problem, or need any devices-specific features for your testing (like touch events, rotation, etc.).</p>
<p>I can also generally recommend  to write <a href="http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#JavaScript">unit tests</a> and run them on your mobile devices. That already gives you a lot more security while writing more code. It  may be worth another blog post entirely.</p>
<p>If someone has anything to add, please let me know in the comments. I'm more than happy to update the article. I'll also try to keep it up to date regarding new releases like iOS 6 or Apache Cordova.</p>
<p><br/><div style="display: inline-block"><a href="https://twitter.com/intent/tweet?source=webclient&amp;text=Debugging+JavaScript+on+Android+and+iOS&amp;via=eclipsesource&amp;url=http://eclipsesource.com/blogs/2012/08/14/debugging-javascript-on-android-and-ios/" target="_blank" title="Share on Twitter" style="margin-right: 5px;"><img title="Twitter" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/twitter.png" alt="Twitter"/></a><a href="https://plus.google.com/share?url=http://eclipsesource.com/blogs/2012/08/14/debugging-javascript-on-android-and-ios/" target="_blank" title="+1" style="margin-right: 5px;"><img title="Google+" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/google_plus.png" alt="Google+"/></a><a href="http://www.linkedin.com/cws/share?url=http://eclipsesource.com/blogs/2012/08/14/debugging-javascript-on-android-and-ios/" target="_blank" title="Share on LinkedIn" style="margin-right: 5px;"><img title="LinkedIn" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/linkedin.png" alt="LinkedIn"/></a><a href="https://www.facebook.com/sharer/sharer.php?u=http://eclipsesource.com/blogs/2012/08/14/debugging-javascript-on-android-and-ios/&amp;t=Debugging+JavaScript+on+Android+and+iOS" target="_blank" title="Facebook" style="margin-right: 5px;"><img title="Facebook" src="http://eclipsesource.com/blogs/wp-content/plugins/custom-about-author/images/social_media/facebook.png" alt="Facebook"/></a></div><br/>Comments are off for this post.. Tagged with <a href='http://eclipsesource.com/blogs/tag/android/' title='android Tag'>android</a>, <a href='http://eclipsesource.com/blogs/tag/html5/' title='html5 Tag'>html5</a>, <a href='http://eclipsesource.com/blogs/tag/ios/' title='iOS Tag'>iOS</a>, <a href='http://eclipsesource.com/blogs/tag/javascript/' title='javascript Tag'>javascript</a>, <a href='http://eclipsesource.com/blogs/tag/mobile/' title='mobile Tag'>mobile</a>, <a href='http://eclipsesource.com/blogs/tag/android/' title='android Tag'>android</a>, <a href='http://eclipsesource.com/blogs/tag/html5/' title='html5 Tag'>html5</a>, <a href='http://eclipsesource.com/blogs/tag/ios/' title='iOS Tag'>iOS</a>, <a href='http://eclipsesource.com/blogs/tag/javascript/' title='javascript Tag'>javascript</a>, <a href='http://eclipsesource.com/blogs/tag/mobile/' title='mobile Tag'>mobile</a></p>]]></content:encoded>
			<wfw:commentRss>http://eclipsesource.com/blogs/2012/08/14/debugging-javascript-on-android-and-ios/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
