You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by dd...@apache.org on 2012/09/10 20:02:37 UTC

svn commit: r1383008 - in /shindig/trunk/features: ./ src/main/javascript/features/ src/main/javascript/features/container.mixin/ src/main/javascript/features/container.util/ src/main/javascript/features/container/ src/main/javascript/features/oauthpop...

Author: ddumont
Date: Mon Sep 10 18:02:37 2012
New Revision: 1383008

URL: http://svn.apache.org/viewvc?rev=1383008&view=rev
Log:
SHINDIG-1864 - Refactor oauthpopup feature to use rpc to the container.  Followup fix to create a container.mixin feature

Added:
    shindig/trunk/features/src/main/javascript/features/container.mixin/
    shindig/trunk/features/src/main/javascript/features/container.mixin/feature.xml   (with props)
    shindig/trunk/features/src/main/javascript/features/container.mixin/mixin.js   (with props)
    shindig/trunk/features/src/test/javascript/features/container/mixin_test.js   (with props)
Modified:
    shindig/trunk/features/pom.xml
    shindig/trunk/features/src/main/javascript/features/container.util/constant.js
    shindig/trunk/features/src/main/javascript/features/container/container.js
    shindig/trunk/features/src/main/javascript/features/container/feature.xml
    shindig/trunk/features/src/main/javascript/features/features.txt
    shindig/trunk/features/src/main/javascript/features/oauthpopup/container_oauthpopup.js
    shindig/trunk/features/src/main/javascript/features/oauthpopup/feature.xml
    shindig/trunk/features/src/test/javascript/features/container/container_test.js
    shindig/trunk/features/src/test/javascript/features/views/views-init-test.js

Modified: shindig/trunk/features/pom.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/features/pom.xml?rev=1383008&r1=1383007&r2=1383008&view=diff
==============================================================================
--- shindig/trunk/features/pom.xml (original)
+++ shindig/trunk/features/pom.xml Mon Sep 10 18:02:37 2012
@@ -140,6 +140,7 @@
                 <source>core.prefs/prefs.js</source>
                 <source>core.log/log.js</source>
                 <source>core.io/io.js</source>
+                <source>container.mixin/mixin.js</source>
                 <source>container.util/constant.js</source>
                 <source>container.util/util.js</source>
                 <source>container.site/site.js</source>

Added: shindig/trunk/features/src/main/javascript/features/container.mixin/feature.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/container.mixin/feature.xml?rev=1383008&view=auto
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/container.mixin/feature.xml (added)
+++ shindig/trunk/features/src/main/javascript/features/container.mixin/feature.xml Mon Sep 10 18:02:37 2012
@@ -0,0 +1,29 @@
+<?xml version="1.0"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations under the License.
+-->
+<feature>
+  <name>container.mixin</name>
+  <dependency>globals</dependency>
+  <container>
+    <script src="mixin.js"/>
+    <api>
+      <exports type="js">osapi.container.addMixin</exports>
+      <exports type="js">osapi.container.mixin</exports>
+    </api>
+  </container>
+</feature>
\ No newline at end of file

Propchange: shindig/trunk/features/src/main/javascript/features/container.mixin/feature.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: shindig/trunk/features/src/main/javascript/features/container.mixin/feature.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: shindig/trunk/features/src/main/javascript/features/container.mixin/mixin.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/container.mixin/mixin.js?rev=1383008&view=auto
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/container.mixin/mixin.js (added)
+++ shindig/trunk/features/src/main/javascript/features/container.mixin/mixin.js Mon Sep 10 18:02:37 2012
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+
+/**
+ * @fileoverview Provide mixin capabilities to the CommonContainer
+ */
+
+osapi.container = osapi.container || {};
+
+(function() {
+  /**
+   * Adds the ability for features to extend the container with
+   * their own functionality that may be specific to that feature.
+   * @type {Object<string,function>}
+   * @private
+   */
+  var mixins = {};
+
+  /**
+   * Order of addMixin calls.
+   * @type {Array<string>}
+   * @private
+   */
+  var order = [];
+
+  /**
+   * Adds a new namespace to be mixed into a constructed container object.
+   * The namespace will contain the result of calling the function passed in.
+   *
+   * @param {string} namespace The namespace to add.
+   * @param {function} func Constructor for the namespace. (will be newed)
+   */
+  osapi.container.addMixin = function(namespace, func) {
+    if (mixins[namespace]) {
+      var orig = mixins[namespace];
+      mixins[namespace] = function(container) {
+        var base = orig.call(this, container);
+        return func.call(this, container, base); // pass overriding mixins the original.
+      };
+    } else {
+      order.push(namespace);
+      mixins[namespace] = func;
+    }
+  };
+
+  /**
+   * Mixes all added mixins into the provided container.
+   *
+   * @param {osapi.container.Container} container The container to mix in to.
+   */
+  osapi.container.mixin = function(container) {
+    for (var i = 0; i < order.length; i++) {
+      var namespace = order[i];
+      container[namespace] = new mixins[namespace](container);
+    }
+  };
+})();
\ No newline at end of file

Propchange: shindig/trunk/features/src/main/javascript/features/container.mixin/mixin.js
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: shindig/trunk/features/src/main/javascript/features/container.mixin/mixin.js
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: shindig/trunk/features/src/main/javascript/features/container.util/constant.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/container.util/constant.js?rev=1383008&r1=1383007&r2=1383008&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/container.util/constant.js (original)
+++ shindig/trunk/features/src/main/javascript/features/container.util/constant.js Mon Sep 10 18:02:37 2012
@@ -26,7 +26,7 @@
  * Set up namespace.
  * @type {Object}
  */
-osapi.container = {};
+osapi.container = osapi.container || {};
 
 
 /**

Modified: shindig/trunk/features/src/main/javascript/features/container/container.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/container/container.js?rev=1383008&r1=1383007&r2=1383008&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/container/container.js (original)
+++ shindig/trunk/features/src/main/javascript/features/container/container.js Mon Sep 10 18:02:37 2012
@@ -393,19 +393,9 @@ osapi.container.Container.prototype.onCo
  * @param {string} namespace the namespace to add.
  * @param {function} func to call when creating the namespace.
  */
+// TODO: Deprecate me in 3.0 in favor of new location.
 osapi.container.Container.addMixin = function(namespace, func) {
-  var mixins = osapi.container.Container.prototype.mixins_;
-
-  if (mixins[namespace]) {
-    var orig = mixins[namespace];
-    mixins[namespace] = function(container) {
-      var base = orig.call(this, container);
-      return func.call(this, container, base); // pass overriding mixins the original.
-    };
-  } else {
-    osapi.container.Container.prototype.mixinsOrder_.push(namespace);
-    mixins[namespace] = func;
-  }
+  osapi.container.addMixin(namespace, func);
 };
 
 
@@ -413,34 +403,13 @@ osapi.container.Container.addMixin = fun
 // Private variables and methods.
 // -----------------------------------------------------------------------------
 
-
-/**
- * Adds the ability for features to extend the container with
- * their own functionality that may be specific to that feature.
- * @type {Object<string,function>}
- * @private
- */
-osapi.container.Container.prototype.mixins_ = {};
-
-/**
- * Order of addMixin calls.
- * @type {Array<string>}
- * @private
- */
-osapi.container.Container.prototype.mixinsOrder_ = [];
-
-
 /**
  * Called from the constructor to add any namespace extensions.
  * @private
  */
+//TODO: Deprecate me in 3.0 in favor of new location.
 osapi.container.Container.prototype.initializeMixins_ = function() {
-  var mixins = osapi.container.Container.prototype.mixins_,
-      order = osapi.container.Container.prototype.mixinsOrder_;
-  for (var i = 0; i < order.length; i++) {
-    var namespace = order[i];
-    this[namespace] = new mixins[namespace](this);
-  }
+  osapi.container.mixin(this);
 };
 
 

Modified: shindig/trunk/features/src/main/javascript/features/container/feature.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/container/feature.xml?rev=1383008&r1=1383007&r2=1383008&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/container/feature.xml (original)
+++ shindig/trunk/features/src/main/javascript/features/container/feature.xml Mon Sep 10 18:02:37 2012
@@ -28,6 +28,7 @@ under the License.
   <dependency>container.util</dependency>
   <dependency>container.site.gadget</dependency>
   <dependency>container.site.url</dependency>
+  <dependency>container.mixin</dependency>
   <dependency>oauthpopup</dependency>
   <container>
     <script src="service.js"/>

Modified: shindig/trunk/features/src/main/javascript/features/features.txt
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/features.txt?rev=1383008&r1=1383007&r2=1383008&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/features.txt (original)
+++ shindig/trunk/features/src/main/javascript/features/features.txt Mon Sep 10 18:02:37 2012
@@ -28,6 +28,7 @@ features/caja/es53-guest-frame.opt.xml
 features/caja/es53-taming-frame.xml
 features/caja/es53-taming-frame.opt.xml
 features/container/feature.xml
+features/container.mixin/feature.xml
 features/container.site/feature.xml
 features/container.site.gadget/feature.xml
 features/container.site.url/feature.xml

Modified: shindig/trunk/features/src/main/javascript/features/oauthpopup/container_oauthpopup.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/oauthpopup/container_oauthpopup.js?rev=1383008&r1=1383007&r2=1383008&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/oauthpopup/container_oauthpopup.js (original)
+++ shindig/trunk/features/src/main/javascript/features/oauthpopup/container_oauthpopup.js Mon Sep 10 18:02:37 2012
@@ -109,22 +109,20 @@
     }
   };
 
+
+  if (gadgets.rpc) { // Tests dont have gadgets.rpc defined right away.
+    gadgets.rpc.register('oauth.open', function(location, options) {
+      oauth.open(location, options, this.f, this.callback);
+    });
+  }
+
   // Support mixing into the container which makes js rpc tests super easy.
-  // To override this mixin, you'll need to setTimeout, because we need to do the same here.
-  // This feature doesn't depend on `container` so it probably won't get defined before us.
-  setTimeout(function() {
-    if (osapi && osapi.container && osapi.container.Container && osapi.container.Container.addMixin) {
-      osapi.container.Container.addMixin('oauth', function(container) {
-        gadgets.rpc.register('oauth.open', function(location, options) {
-          container.oauth.open(location, options, this.f, this.callback);
-        });
-  
-        return oauth;
-      });
-    } else {
-      gadgets.rpc.register('oauth.open', function(location, options) {
-        oauth.open(location, options, this.f, this.callback);
-      });
-    }
-  }, 0);
+  // This overrides the rpc register above if you instantiate a commoncontainer.
+  osapi.container.addMixin('oauth', function(container) {
+    gadgets.rpc.register('oauth.open', function(location, options) {
+      container.oauth.open(location, options, this.f, this.callback);
+    });
+
+    return oauth;
+  });
 })();
\ No newline at end of file

Modified: shindig/trunk/features/src/main/javascript/features/oauthpopup/feature.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/oauthpopup/feature.xml?rev=1383008&r1=1383007&r2=1383008&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/oauthpopup/feature.xml (original)
+++ shindig/trunk/features/src/main/javascript/features/oauthpopup/feature.xml Mon Sep 10 18:02:37 2012
@@ -18,6 +18,8 @@ specific language governing permissions 
 -->
 <feature>
   <name>oauthpopup</name>
+  <dependency>globals</dependency>
+  <dependency>container.mixin</dependency>
   <dependency>rpc</dependency>
   <container>
     <script src="container_oauthpopup.js"/>

Modified: shindig/trunk/features/src/test/javascript/features/container/container_test.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/test/javascript/features/container/container_test.js?rev=1383008&r1=1383007&r2=1383008&view=diff
==============================================================================
--- shindig/trunk/features/src/test/javascript/features/container/container_test.js (original)
+++ shindig/trunk/features/src/test/javascript/features/container/container_test.js Mon Sep 10 18:02:37 2012
@@ -73,7 +73,7 @@ ContainerTest.prototype.testUnloadGadget
 
 ContainerTest.prototype.testPreloadConfigGadgets = function() {
   this.setupGadgetsRpcRegister();
-  var container = new osapi.container.Container( 
+  var container = new osapi.container.Container(
     { 'preloadMetadatas' : { 'preloaded1.xml' : {}}});
   var test = null;
   this.assertTrue('1', 'preloaded1.xml' in container.preloadedGadgetUrls_);
@@ -133,23 +133,6 @@ ContainerTest.prototype.testNewGadgetSit
   this.assertTrue(container.sites_[2] != null);
 };
 
-ContainerTest.prototype.testMixinViaPrototype = function() {
-  this.setupGadgetsRpcRegister();
-  osapi.container.Container.prototype.mixins_['test'] = function(context) {
-    return {
-      'getSitesLength' : function() {
-        return context.sites_.length;
-      }
-    };
-  };
-  osapi.container.Container.prototype.mixinsOrder_.push('test');
-  var container = new osapi.container.Container();
-  this.setupGadgetSite(1, {}, null);
-  container.newGadgetSite(null);
-  this.assertTrue(container.sites_[1] != null);
-  this.assertEquals(container.sites_.length, container.test.getSitesLength());
-};
-
 ContainerTest.prototype.testMixinViaAdd = function() {
   this.setupGadgetsRpcRegister();
   osapi.container.Container.addMixin('test2', function(context) {

Added: shindig/trunk/features/src/test/javascript/features/container/mixin_test.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/test/javascript/features/container/mixin_test.js?rev=1383008&view=auto
==============================================================================
--- shindig/trunk/features/src/test/javascript/features/container/mixin_test.js (added)
+++ shindig/trunk/features/src/test/javascript/features/container/mixin_test.js Mon Sep 10 18:02:37 2012
@@ -0,0 +1,49 @@
+function MixinTest(name) {
+  TestCase.call(this, name); // super
+}
+MixinTest.inherits(TestCase);
+
+MixinTest.prototype.setUp = function() {
+  this.apiUri = window.__API_URI;
+  window.__API_URI = shindig.uri('http://shindig.com');
+  this.containerUri = window.__CONTAINER_URI;
+  window.__CONTAINER_URI = shindig.uri('http://container.com');
+  this.gadgetsRpc = gadgets.rpc;
+  gadgets.rpc = {
+    register: function() {}
+  };
+};
+
+MixinTest.prototype.tearDown = function() {
+  window.__API_URI = this.apiUri;
+  window.__CONTAINER_URI = this.containerUri;
+  gadgets.rpc = this.gadgetsRpc;
+};
+
+MixinTest.prototype.testMixin = function() {
+  var testobj = new osapi.container.Container();
+  this.assertUndefined(testobj.test);
+
+  osapi.container.addMixin('test', function(context) {
+    return {
+      'test1' : function() {
+        return true;
+      }
+    };
+  });
+  osapi.container.addMixin('test', function(context, base) {
+    base.test2 = function() {
+      return false;
+    };
+
+    return base;
+  });
+
+  testobj = new osapi.container.Container();
+
+  this.assertNotUndefined(testobj.test);
+  this.assertNotUndefined(testobj.test.test1);
+  this.assertNotUndefined(testobj.test.test2);
+  this.assertTrue(testobj.test.test1());
+  this.assertFalse(testobj.test.test2());
+};
\ No newline at end of file

Propchange: shindig/trunk/features/src/test/javascript/features/container/mixin_test.js
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: shindig/trunk/features/src/test/javascript/features/container/mixin_test.js
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: shindig/trunk/features/src/test/javascript/features/views/views-init-test.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/test/javascript/features/views/views-init-test.js?rev=1383008&r1=1383007&r2=1383008&view=diff
==============================================================================
--- shindig/trunk/features/src/test/javascript/features/views/views-init-test.js (original)
+++ shindig/trunk/features/src/test/javascript/features/views/views-init-test.js Mon Sep 10 18:02:37 2012
@@ -65,10 +65,15 @@ ViewsInitTest.prototype.testRewriteLinks
       name = arguments[0];
       func = arguments[1];
       bubble = arguments[2];
-    }
+    },
+    location: {
+      href: "http://localhost",
+      host: "localhost",
+      hostname: "localhost"
+    },
+    scripts: []
   };
 
-  document.scripts = [];
   gadgets.config.init({views:{rewriteLinks: true}});
 
   this.assertEquals("click", name);
@@ -83,12 +88,15 @@ ViewsInitTest.prototype.testRewriteLinks
     attachEvent: function() {
       name = arguments[0];
       func = arguments[1];
-    
     },
-    addEventListener: undefined
+    location: {
+      href: "http://localhost",
+      host: "localhost",
+      hostname: "localhost"
+    },
+    scripts: []
   };
 
-  document.scripts = [];
   gadgets.config.init({views:{rewriteLinks: true}});
 
   this.assertEquals("onclick", name);