You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ripple.apache.org by gt...@apache.org on 2013/10/21 04:42:35 UTC

[06/15] git commit: some more inappbrowser support and tests

some more inappbrowser support and tests


Project: http://git-wip-us.apache.org/repos/asf/incubator-ripple/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ripple/commit/837a8232
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ripple/tree/837a8232
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ripple/diff/837a8232

Branch: refs/heads/next
Commit: 837a82326339dea217afbea2e1c10f65cf1252f0
Parents: 80b1964
Author: Gord Tanner <gt...@gmail.com>
Authored: Thu Sep 26 23:34:31 2013 -0400
Committer: Gord Tanner <gt...@gmail.com>
Committed: Thu Sep 26 23:34:31 2013 -0400

----------------------------------------------------------------------
 .../cordova/3.0.0/bridge/inappbrowser.js        |  16 +--
 lib/client/ui/plugins/browser.js                |  22 +++-
 lib/client/ui/plugins/browser/overlay.html      |   4 +
 test/unit/client/cordova/inappbrowser.js        | 116 +++++++++++++++++++
 4 files changed, 148 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ripple/blob/837a8232/lib/client/platform/cordova/3.0.0/bridge/inappbrowser.js
----------------------------------------------------------------------
diff --git a/lib/client/platform/cordova/3.0.0/bridge/inappbrowser.js b/lib/client/platform/cordova/3.0.0/bridge/inappbrowser.js
index abb5131..e8833bb 100644
--- a/lib/client/platform/cordova/3.0.0/bridge/inappbrowser.js
+++ b/lib/client/platform/cordova/3.0.0/bridge/inappbrowser.js
@@ -21,6 +21,7 @@
 
 var emulatorBridge = ripple('emulatorBridge'),
     event = ripple('event'),
+    ui = ripple('ui'),
     browser = ripple("ui/plugins/browser");
 
 module.exports = {
@@ -30,13 +31,14 @@ module.exports = {
             options = args[2],
             trigger = function (event) {
                 return function () {
-                    win({type: event, url: url});
+                    return win && win({type: event, url: url});
                 };
             };
 
-        browser.show(url);
+        browser.show(url, target, options);
 
         jWorkflow.order()
+                 //force this async
                  .chill(1)
                  .andThen(trigger("loadstart"))
                  .chill(10)
@@ -47,7 +49,7 @@ module.exports = {
     },
 
     show: function (win, fail, args) {
-        console.log(args);
+        ui.showOverlay("inappbrowser");
     },
 
     close: function (win, fail, args) {
@@ -55,18 +57,18 @@ module.exports = {
     },
 
     injectScriptCode: function (win, fail, args) {
-        console.log(args);
+        browser.injectScript(args[0]);
     },
 
     injectScriptFile: function (win, fail, args) {
-        console.log(args);
+        browser.injectScript(args[0]);
     },
 
     injectStyleCode: function (win, fail, args) {
-        console.log(args);
+        browser.injectCSS(args[0]);
     },
 
     injectStyleFile: function (win, fail, args) {
-        console.log(args);
+        browser.injectCSS(args[0]);
     }
 };

http://git-wip-us.apache.org/repos/asf/incubator-ripple/blob/837a8232/lib/client/ui/plugins/browser.js
----------------------------------------------------------------------
diff --git a/lib/client/ui/plugins/browser.js b/lib/client/ui/plugins/browser.js
index 503481d..8dbadb6 100644
--- a/lib/client/ui/plugins/browser.js
+++ b/lib/client/ui/plugins/browser.js
@@ -23,11 +23,17 @@ var ui = ripple('ui'),
     event = ripple('event'),
     _url = document.getElementById('browser-url'),
     _target = document.getElementById('browser-target'),
-    _options = document.getElementById('browser-options');
-    close = document.getElementById('browser-close'),
+    _options = document.getElementById('browser-options'),
+    _injectJS = document.getElementById('browser-inject-js'),
+    _injectJSHeader = document.getElementById('browser-inject-js-header'),
+    _injectCSS = document.getElementById('browser-inject-css'),
+    _injectCSSHeader = document.getElementById('browser-inject-css-header'),
+    _close = document.getElementById('browser-close'),
     _self = {
         initialize: function () {
-            close.addEventListener('click', _self.hide);
+            _close.addEventListener('click', _self.hide);
+            _injectJSHeader.style.display = "none";
+            _injectCSSHeader.style.display = "none";
         },
         show: function (url, target, options) {
             _url.innerHTML = url;
@@ -38,6 +44,16 @@ var ui = ripple('ui'),
         hide: function () {
             ui.hideOverlay("inappbrowser");
             event.trigger("browser-close");
+        },
+
+        injectScript: function (script) {
+            _injectJSHeader.style.display = "block";
+            _injectJS.innerHTML = script;
+        },
+
+        injectCSS: function (css) {
+            _injectCSSHeader.style.display = "block";
+            _injectCSS.innerHTML = css;
         }
     };
 

http://git-wip-us.apache.org/repos/asf/incubator-ripple/blob/837a8232/lib/client/ui/plugins/browser/overlay.html
----------------------------------------------------------------------
diff --git a/lib/client/ui/plugins/browser/overlay.html b/lib/client/ui/plugins/browser/overlay.html
index 766a6e2..d0800ed 100644
--- a/lib/client/ui/plugins/browser/overlay.html
+++ b/lib/client/ui/plugins/browser/overlay.html
@@ -27,6 +27,10 @@
     <blockquote id="browser-target">_blank</blockquote>
     <h3>OPTIONS:</h3>
     <blockquote id="browser-options">{}</blockquote>
+    <h3 id="browser-inject-js-header">INJECTED JAVASCRIPT:</h3>
+    <pre id="browser-inject-js"></pre>
+    <h3 id="browser-inject-css-header">INJECTED CSS:</h3>
+    <pre id="browser-inject-css"></pre>
     <button id="browser-close" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only small-button">
         <span class="ui-button-text">Close</span>
     </button>

http://git-wip-us.apache.org/repos/asf/incubator-ripple/blob/837a8232/test/unit/client/cordova/inappbrowser.js
----------------------------------------------------------------------
diff --git a/test/unit/client/cordova/inappbrowser.js b/test/unit/client/cordova/inappbrowser.js
new file mode 100644
index 0000000..e1444cd
--- /dev/null
+++ b/test/unit/client/cordova/inappbrowser.js
@@ -0,0 +1,116 @@
+/*
+ *
+ * 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.
+ *
+ */
+describe("cordova inappbrowser bridge", function () {
+    var iab = ripple('platform/cordova/3.0.0/bridge/inappbrowser'),
+        event = ripple('event'),
+        browser = ripple('ui/plugins/browser');
+
+    describe("open", function () {
+        var jwfMock;
+
+        beforeEach(function () {
+            jwfMock = {
+                chill: jasmine.createSpy("chill"),
+                andThen: jasmine.createSpy("andThen"),
+                start: jasmine.createSpy("start")
+            };
+
+            jwfMock.chill.andReturn(jwfMock);
+            jwfMock.andThen.andReturn(jwfMock);
+            jwfMock.start.andReturn(jwfMock);
+
+            spyOn(jWorkflow, "order").andReturn(jwfMock);
+            spyOn(browser, "show");
+            spyOn(event, "once");
+        });
+
+        it("shows the browser", function () {
+            iab.open(null, null, ["a", "b", "c"]);
+            expect(browser.show).toHaveBeenCalledWith("a", "b", "c");
+        });
+
+        it("creates a workflow for loading events", function () {
+            iab.open(null, null, ["a", "b", "c"]);
+            expect(jWorkflow.order).toHaveBeenCalled();
+            expect(jwfMock.chill).toHaveBeenCalledWith(1);
+            expect(jwfMock.chill).toHaveBeenCalledWith(10);
+            expect(jwfMock.andThen).toHaveBeenCalledWith(jasmine.any(Function));
+            expect(jwfMock.start).toHaveBeenCalled();
+        });
+
+        it("calls the win callback with loadstart from the workflow", function () {
+            var win = jasmine.createSpy();
+            iab.open(win, null, ["a", "b", "c"]);
+            jwfMock.andThen.argsForCall[0][0]();
+            expect(win).toHaveBeenCalledWith({type: "loadstart", url: "a"});
+        });
+
+        it("calls the win callback with loadstart from the workflow", function () {
+            var win = jasmine.createSpy();
+            iab.open(win, null, ["a", "b", "c"]);
+            jwfMock.andThen.argsForCall[1][0]();
+            expect(win).toHaveBeenCalledWith({type: "loadstop", url: "a"});
+        });
+
+        it("syncs once on the browser-close event", function () {
+            iab.open(null, null, ["a", "b", "c"]);
+            expect(event.once).toHaveBeenCalledWith("browser-close", jasmine.any(Function));
+        });
+
+        it("calls the win callback with exit on the browser-close event", function () {
+            var win = jasmine.createSpy();
+            iab.open(win, null, ["a", "b", "c"]);
+            console.log(event.once.mostRecentCall);
+            event.once.mostRecentCall.args[1]();
+            expect(win).toHaveBeenCalledWith({type: "exit", url: "a"});
+        });
+    });
+
+    describe("show", function () {
+        var ui = ripple('ui');
+
+        it("shows the inappbrowser overlay", function () {
+            spyOn(ui, "showOverlay");
+            iab.show();
+            expect(ui.showOverlay).toHaveBeenCalledWith('inappbrowser');
+        });
+    });
+
+    describe("close", function () {
+        it("hides the browser", function () {
+            spyOn(browser, "hide");
+            iab.close();
+            expect(browser.hide).toHaveBeenCalled();
+        });
+    });
+
+    it("calls injectScript for injectScriptFile", function () {
+        spyOn(browser, "injectScript");
+        iab.injectScriptFile(null, null, ["bob"]);
+        expect(browser.injectScript).toHaveBeenCalledWith("bob");
+    });
+
+    it("calls injectScript for injectScriptCode", function () {
+        spyOn(browser, "injectScript");
+        iab.injectScriptCode(null, null, ["bob"]);
+        expect(browser.injectScript).toHaveBeenCalledWith("bob");
+    });
+});