shindig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject svn commit: r1152004 - in /shindig/trunk/java/gadgets/src: main/java/org/apache/shindig/gadgets/js/AddJslInfoVariableProcessor.java test/java/org/apache/shindig/gadgets/js/AddJslInfoVariableProcessorTest.java
Date Thu, 28 Jul 2011 21:13:51 GMT
Author: johnh
Date: Thu Jul 28 21:13:50 2011
New Revision: 1152004

URL: http://svn.apache.org/viewvc?rev=1152004&view=rev
Log:
Decline to inject ___jsl.u="" or "null" when an empty value is present.


Modified:
    shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/AddJslInfoVariableProcessor.java
    shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/js/AddJslInfoVariableProcessorTest.java

Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/AddJslInfoVariableProcessor.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/AddJslInfoVariableProcessor.java?rev=1152004&r1=1152003&r2=1152004&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/AddJslInfoVariableProcessor.java
(original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/AddJslInfoVariableProcessor.java
Thu Jul 28 21:13:50 2011
@@ -40,10 +40,13 @@ public class AddJslInfoVariableProcessor
   private static final String CODE_ID = "[jsload-code-info]";
 
   @VisibleForTesting
-  static final String HINT_TEMPLATE = 
-      "window['___jsl'] = window['___jsl'] || {};" +
-      "window['___jsl']['u'] = '%s';" +
-      "window['___jsl']['f'] = [%s];";
+  static final String BASE_HINT_TEMPLATE = "window['___jsl'] = window['___jsl'] || {};";
+
+  @VisibleForTesting
+  static final String FEATURES_HINT_TEMPLATE = "window['___jsl']['f'] = [%s];";
+
+  @VisibleForTesting
+  static final String URL_HINT_TEMPLATE = "window['___jsl']['u'] = '%s';";
 
   private final JsUriManager jsUriManager;
 
@@ -57,7 +60,11 @@ public class AddJslInfoVariableProcessor
     if (!jsUri.isNohint()) {
       String uri = StringEscapeUtils.escapeJavaScript(getUri(jsUri));
       String features = getFeatures(jsUri);
-      builder.prependJs(String.format(HINT_TEMPLATE, uri, features), CODE_ID);
+      builder.prependJs(String.format(FEATURES_HINT_TEMPLATE, features), CODE_ID);
+      if (uri != null && !"".equals(uri)) {
+        builder.prependJs(String.format(URL_HINT_TEMPLATE, uri), CODE_ID);
+      }
+      builder.prependJs(BASE_HINT_TEMPLATE, CODE_ID);
     }
     return true;
   }

Modified: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/js/AddJslInfoVariableProcessorTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/js/AddJslInfoVariableProcessorTest.java?rev=1152004&r1=1152003&r2=1152004&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/js/AddJslInfoVariableProcessorTest.java
(original)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/js/AddJslInfoVariableProcessorTest.java
Thu Jul 28 21:13:50 2011
@@ -77,7 +77,10 @@ public class AddJslInfoVariableProcessor
     setJsUri(URI);
     control.replay();
     processor.process(request, response);
-    String expected = String.format(AddJslInfoVariableProcessor.HINT_TEMPLATE, URI_JS, LIBS_JS);
+    String expected = String.format(AddJslInfoVariableProcessor.BASE_HINT_TEMPLATE +
+        AddJslInfoVariableProcessor.URL_HINT_TEMPLATE +
+        AddJslInfoVariableProcessor.FEATURES_HINT_TEMPLATE,
+        URI_JS, LIBS_JS);
     assertEquals(expected, response.build().toJsString());
     control.verify();    
   }
@@ -89,13 +92,28 @@ public class AddJslInfoVariableProcessor
     EasyMock.expect(jsUriManager.makeExternJsUri(EasyMock.capture(captureJsUri))).andReturn(Uri.parse(GENERATED_URI));
     control.replay();
     processor.process(request, response);
-    String expected = String.format(AddJslInfoVariableProcessor.HINT_TEMPLATE, GENERATED_URI_JS,
LIBS_JS);
+    String expected = String.format(AddJslInfoVariableProcessor.BASE_HINT_TEMPLATE +
+        AddJslInfoVariableProcessor.URL_HINT_TEMPLATE +
+        AddJslInfoVariableProcessor.FEATURES_HINT_TEMPLATE,
+        GENERATED_URI_JS, LIBS_JS);
     assertEquals(expected, response.build().toJsString());
     assertFalse(captureJsUri.getValue().isJsload());
     assertTrue(captureJsUri.getValue().isNohint());
     control.verify();    
   }
   
+  @Test
+  public void testAddsHintWithoutUriIfBlank() throws Exception {
+    setJsUri("");
+    control.replay();
+    processor.process(request, response);
+    String expected = String.format(AddJslInfoVariableProcessor.BASE_HINT_TEMPLATE +
+        AddJslInfoVariableProcessor.FEATURES_HINT_TEMPLATE,
+        LIBS_JS);
+    assertEquals(expected, response.build().toJsString());
+    control.verify();    
+  }
+  
 
   private void setJsUri(String uri) {
     jsUri = new JsUri(UriStatus.VALID_UNVERSIONED, Uri.parse(uri), LIBS, null);



Mime
View raw message