[Pkg-mozext-commits] [firebug] 19/82: FBTest for issue 5873 (Integrate FireClosure)

David Prévot taffit at moszumanska.debian.org
Mon Mar 31 22:45:37 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to tag fbtest-1.11.2
in repository firebug.

commit 680ea76013e126c60e10a735531ecc805b243c82
Author: Simon Lindholm <simon.lindholm10 at gmail.com>
Date:   Tue Dec 18 01:14:44 2012 +0100

    FBTest for issue 5873 (Integrate FireClosure)
    
    http://code.google.com/p/fbug/issues/detail?id=5873
---
 tests/FBTest/content/FBTestFirebug.js         |   2 +-
 tests/content/commandLine/5873/frame.html     |   9 +
 tests/content/commandLine/5873/issue5873.html | 150 +++++++++++++
 tests/content/commandLine/5873/issue5873.js   | 289 ++++++++++++++++++++++++++
 tests/content/firebug.html                    |   1 +
 5 files changed, 450 insertions(+), 1 deletion(-)

diff --git a/tests/FBTest/content/FBTestFirebug.js b/tests/FBTest/content/FBTestFirebug.js
index 014cb94..2e1ebd9 100644
--- a/tests/FBTest/content/FBTestFirebug.js
+++ b/tests/FBTest/content/FBTestFirebug.js
@@ -969,7 +969,7 @@ this.disableConsolePanel = function(callback)
 };
 
 /**
- * Enables the Script panel and reloads if a callback is specified.
+ * Enables the Console panel and reloads if a callback is specified.
  * @param {Function} callback A handler that is called as soon as the page is reloaded.
  */
 this.enableConsolePanel = function(callback)
diff --git a/tests/content/commandLine/5873/frame.html b/tests/content/commandLine/5873/frame.html
new file mode 100644
index 0000000..0c8d4a9
--- /dev/null
+++ b/tests/content/commandLine/5873/frame.html
@@ -0,0 +1,9 @@
+<script>
+(function() {
+    var framePriv = 2;
+    window.frameA = function() {
+        return framePriv * Math.random();
+    };
+})();
+location.fra = frameA;
+</script>
diff --git a/tests/content/commandLine/5873/issue5873.html b/tests/content/commandLine/5873/issue5873.html
new file mode 100644
index 0000000..0c7614e
--- /dev/null
+++ b/tests/content/commandLine/5873/issue5873.html
@@ -0,0 +1,150 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta charset="UTF-8"/>
+        <title>Issue 5873: Integrate FireClosure</title>
+        <link href="../../_common/testcase.css" type="text/css" rel="stylesheet"/>
+        <script>
+function doBreak() {
+    debugger;
+    var count = (function() {
+        var counter = 0;
+        return function() {
+            ++counter;
+        };
+    })();
+
+    for (var i = 0; i < 10; ++i) {
+        count();
+    }
+}
+function breakSoon()
+{
+    setTimeout(doBreak, 0);
+}
+
+// run in the command line:
+/*
+// with(_FirebugCommandLine) {
+window.global = 1;
+with({withVar: 2})
+{
+    window.A = function(param)
+    {
+        function helper(x)
+        {
+            return x + 4;
+        }
+        var local = 5;
+        try
+        {
+            throw 6;
+        }
+        catch (catched)
+        {
+            this.someFunction = function(someFuncParam)
+            {
+                return helper(global + withVar + param + local + catched + someFuncParam);
+            };
+        }
+    };
+}
+window.a = new A(3);
+// }
+*/
+
+window.emptyObject = {};
+
+(function()
+{
+    var priv = 2;
+    window.funcWithProto = function()
+    {
+        return priv;
+    };
+    (function()
+    {
+        var priv = 10;
+        window.funcWithProto.prototype.func = function()
+        {
+            return priv;
+        };
+    })();
+})();
+
+(function()
+{
+    var unrelated = 3;
+    window.otherFunc = function()
+    {
+        return unrelated;
+    };
+    window.otherFunc.regularProp = 4;
+})();
+
+(function()
+{
+    var priv = 1;
+    window.func = function()
+    {
+        return priv % oth;
+    };
+    var oth = window.otherFunc;
+})();
+
+window.scopelessFunc = function() {};
+window.scopelessFunc.prop = window.func;
+        </script>
+        <style>
+            #content::after {
+                content: ".";
+                display: block;
+                visibility: hidden;
+                clear: both;
+                line-height: 0;
+                height: 0;
+            }
+            .ifr-cont {
+                float: left;
+                padding: 10px;
+            }
+            .ifr-cont iframe {
+                height: 50px;
+                width: 70px;
+            }
+        </style>
+    </head>
+    <body>
+        <header>
+        <h1><a href="http://code.google.com/p/fbug/issues/detail?id=5873">Issue 5873</a>: Integrate FireClosure</h1>
+        </header>
+        <div>
+            <section id="content">
+                <div class="ifr-cont"> Same-origin:<br><iframe src="frame.html"></iframe> </div>
+                <div class="ifr-cont"> Sandboxed:<br><iframe src="frame.html" sandbox="allow-scripts"></iframe> </div>
+            </section>
+            <section id="description">
+                <h3>Steps to reproduce</h3>
+                <ul>
+                    <li>See issue5873.js.</li>
+                </ul>
+                <h3>Expected Results</h3>
+                <ul>
+                    <li><code>someFunction.%someClosureVar</code> should access a variable bound to
+                    someFunction through a closure.</li>
+                    <li>Operator precedence of <code>.%</code> should be like that of <code>.</code>.</li>
+                    <li><code>someObject.%someClosureVar</code> should to a first approximation do
+                    the same thing; making some intelligent guesses about relevant functions to
+                    steal closures off.</li>
+                    <li>Auto-completion should work for <code>.%</code>.</li>
+                    <li>It should only be possible to access closures of same-origin functions.</li>
+                    <li>The operator should work even when stopped in the debugger, and in
+                    breakpoint conditions.</li>
+                </ul>
+            </section>
+            <footer>
+                Simon Lindholm, simon.lindholm10 at gmail.com
+            </footer>
+        </div>
+    </body>
+</html>
diff --git a/tests/content/commandLine/5873/issue5873.js b/tests/content/commandLine/5873/issue5873.js
new file mode 100644
index 0000000..efcf8a0
--- /dev/null
+++ b/tests/content/commandLine/5873/issue5873.js
@@ -0,0 +1,289 @@
+function runTest()
+{
+    FBTest.sysout("issue5873.START");
+    FBTest.setPref("commandLineShowCompleterPopup", true);
+    FBTest.openNewTab(basePath + "commandLine/5873/issue5873.html", function(win)
+    {
+        FBTest.openFirebug();
+        FBTest.enableConsolePanel();
+        FBTest.enableScriptPanel(function(win)
+        {
+            var panel = FW.Firebug.chrome.selectPanel("console");
+
+            var doc = FW.Firebug.chrome.window.document;
+            var cmdLine = doc.getElementById("fbCommandLine");
+            var completionBox = doc.getElementById("fbCommandLineCompletion");
+            var popup = doc.getElementById("fbCommandLineCompletionList");
+            cmdLine.value = "";
+
+            function waitForOpen(callback)
+            {
+                if (popup.state === "opening")
+                {
+                    setTimeout(waitForOpen, 10, callback);
+                    return;
+                }
+
+                if (popup.state === "closed")
+                    FBTest.compare("open", "closed", "Completion popup should open.");
+
+                callback();
+            }
+
+            function createA(callback)
+            {
+                // Run the code of createA in the Firebug command line.
+                function createA()
+                {
+                    window.global = 1;
+                    with({withVar: 2})
+                    {
+                        window.A = function(param)
+                        {
+                            function helper(x)
+                            {
+                                return x + 4;
+                            }
+                            var local = 5, unused = 15;
+                            try
+                            {
+                                throw 6;
+                            }
+                            catch (catched)
+                            {
+                                this.someFunction = function(someFuncParam)
+                                {
+                                    return helper(global + withVar + param + local + catched + someFuncParam);
+                                };
+                            }
+                        };
+                    }
+                    window.a = new A(3);
+                }
+                var src = (createA + "").replace(/\n/g,' ').replace(/ +/g, ' ');
+                src += " createA();";
+                FW.Firebug.CommandLine.evaluate(src, FW.Firebug.currentContext, undefined,
+                    undefined, function() {}, function() {});
+                callback();
+            }
+
+            function verifyNothingInjected(callback)
+            {
+                FBTest.compare("undefined", typeof win.wrappedJSObject.__fb_scopedVars,
+                    "The scope getter function must not yet be available to page content.");
+                callback();
+            }
+
+            function verifyCompletionPopupForA(callback)
+            {
+                FBTest.typeCommand("a.%");
+                waitForOpen(function()
+                {
+                    var completions = popup.getElementsByClassName("completionText");
+                    var joined = [].slice.call(completions).map(function(el)
+                    {
+                        return el.textContent;
+                    }).join(",");
+                    var wanted = "catched,helper,local,param,unused,withVar";
+                    FBTest.compare(wanted, joined, "The completion popup should show the right list of closure variables.");
+                    if (wanted !== joined)
+                        FBTest.progress("Actual: " + joined);
+                    cmdLine.value = "";
+                    FBTest.setPref("commandLineShowCompleterPopup", false);
+                    callback();
+                });
+            }
+
+            function testCompletion(callback, expr, shouldComplete)
+            {
+                // To save on time, only send the last character as a key press.
+                cmdLine.focus();
+                cmdLine.value = expr.slice(0, -1);
+                FBTest.synthesizeKey(expr.slice(-1), null, win);
+
+                var hasCompletion = (completionBox.value.length > expr.length);
+                FBTest.compare(shouldComplete, hasCompletion,
+                    "Completions should " + (shouldComplete ? "" : "not ") +
+                    "appear for: " + expr);
+
+                callback();
+            }
+
+            function verifyParsing(callback)
+            {
+                // Some unit tests for verifying parsing.
+                function tr(expr)
+                {
+                    return FW.Firebug.JSAutoCompleter.transformScopeOperator(expr, "f");
+                }
+
+                var tests = [
+                    ["a.%b", "f(a).b"],
+                    ["a\na.%b", "a\nf(a).b"],
+                    ["anew\na.%b", "anew\nf(a).b"],
+                    ["new\na.%b()", "new\n(f(a)).b()"],
+                    ["a new\na.%b()", "a new\n(f(a)).b()"],
+                    ["a.%b.%c", "f(f(a).b).c"],
+                    ["z.a.%b.c.%d", "f(f(z.a).b.c).d"],
+                    ["0.%a", "0.%a"],
+                    ["'a.%a'", "'a.%a'"]
+                ];
+                for (var i = 0; i < tests.length; ++i)
+                {
+                    var from = tests[i][0], to = tests[i][1];
+                    FBTest.compare(to, tr(from), "Should transform |" + from + "| -> |" + to);
+                }
+
+                callback();
+            }
+
+            function testInDebugger(callback)
+            {
+                function step0()
+                {
+                    // Break into the debugger.
+                    FBTest.waitForBreakInDebugger(null, 9, false, step1);
+                    win.wrappedJSObject.breakSoon();
+                }
+                function step1()
+                {
+                    // Test that completions work.
+                    FBTest.clickConsolePreviewButton();
+                    testCompletion(step2, "func.%pr", true);
+                }
+                function step2()
+                {
+                    // Test that evaluations work.
+                    FBTest.executeCommandAndVerify(step3, "a.%global",
+                        "1", "pre", "objectBox-number");
+                }
+                function step3()
+                {
+                    // Set a conditional breakpoint with .% syntax.
+                    FBTest.setBreakpoint(null, null, 18, {
+                        condition: "count.%counter === 4"
+                    }, step4);
+                }
+                function step4()
+                {
+                    // Hit it.
+                    FBTest.waitForBreakInDebugger(null, 18, true, step5);
+                    FBTest.clickToolbarButton(null, "fbContinueButton");
+                }
+                function step5()
+                {
+                    // Check that it hit at the right point.
+                    FBTest.executeCommandAndVerify(step6, "i", "4", "pre", "objectBox-number");
+                }
+                function step6()
+                {
+                    // Remove the breakpoint.
+                    FBTest.removeBreakpoint(null, null, 18, step7);
+                }
+                function step7()
+                {
+                    // Resume.
+                    FBTest.waitForDebuggerResume(step8);
+                    FBTest.clickToolbarButton(null, "fbContinueButton");
+                }
+                function step8()
+                {
+                    // Whew, done. Switch back to the console panel.
+                    panel = FW.Firebug.chrome.selectPanel("console");
+                    callback();
+                }
+                step0();
+            }
+
+            var taskList = new FBTest.TaskList();
+
+            taskList.push(createA);
+            taskList.push(verifyNothingInjected);
+            taskList.push(verifyCompletionPopupForA);
+
+            // Verify cross-compartment permissions
+            taskList.push(FBTest.executeCommandAndVerify, "_FirebugCommandLine.%cmd",
+                "Error: permission denied to access cross origin scope", "span", "errorMessage");
+            if ("sandbox" in document.createElement("iframe"))
+            {
+                taskList.push(FBTest.executeCommandAndVerify, "frames[1].%framePriv",
+                    "Error: permission denied to access cross origin scope", "span", "errorMessage");
+                taskList.push(FBTest.executeCommandAndVerify, "frames[1].location.%framePriv",
+                    "Error: permission denied to access cross origin scope", "span", "errorMessage");
+            }
+            taskList.push(FBTest.executeCommandAndVerify, "frames[0].location.%framePriv",
+                "2", "pre", "objectBox-number");
+            taskList.push(FBTest.executeCommandAndVerify, "frames[0].%framePriv",
+                "2", "pre", "objectBox-number");
+            taskList.push(FBTest.executeCommandAndVerify, "frames[0].frameA.%framePriv",
+                "2", "pre", "objectBox-number");
+
+            // Test getting
+            taskList.push(FBTest.executeCommandAndVerify, "a.%global",
+                "1", "pre", "objectBox-number");
+            taskList.push(FBTest.executeCommandAndVerify, "typeof a.%values",
+                "\"function\"", "pre", "objectBox-string");
+            taskList.push(FBTest.executeCommandAndVerify, "a.%nonExistent",
+                "undefined", "pre", "objectBox-undefined");
+
+            taskList.push(FBTest.executeCommandAndVerify, "emptyObject.%blah",
+                "Error: missing closure", "span", "errorMessage");
+            taskList.push(FBTest.executeCommandAndVerify, "a.%local.%blah",
+                "TypeError: can't get scope of non-object", "span", "errorMessage");
+
+            // Test setting
+            taskList.push(FBTest.executeCommandAndVerify, "a.%nonExistent = 1",
+                "Error: can't create new closure variables", "span", "errorMessage");
+            taskList.push(FBTest.executeCommandAndVerify, "a.%unused = 1",
+                "1", "pre", "objectBox-number");
+            taskList.push(FBTest.executeCommandAndVerify, "++a.%local",
+                "6", "pre", "objectBox-number");
+
+            taskList.push(FBTest.executeCommandAndVerify, "emptyObject.%blah = 1",
+                "Error: missing closure", "span", "errorMessage");
+
+            // Verify the setting
+            taskList.push(FBTest.executeCommandAndVerify, "a.%unused",
+                "(optimized away)", "pre", "objectBox-optimizedAway");
+            taskList.push(FBTest.executeCommandAndVerify, "a.%local",
+                "6", "pre", "objectBox-number");
+
+            // Test object->function heuristics:
+            // * already a function
+            taskList.push(FBTest.executeCommandAndVerify, "func.%priv",
+                "1", "pre", "objectBox-number");
+            // * already a function, but would need scope anyway
+            taskList.push(FBTest.executeCommandAndVerify, "scopelessFunc.%priv",
+                "Error: missing closure", "span", "errorMessage");
+            // * use of own functions
+            taskList.push(FBTest.executeCommandAndVerify, "funcWithProto.prototype.%priv",
+                "10", "pre", "objectBox-number");
+            // * use of own "constructor"
+            taskList.push(FBTest.executeCommandAndVerify, "func.prototype.%priv",
+                "1", "pre", "objectBox-number");
+            // * use of inherited functions
+            taskList.push(FBTest.executeCommandAndVerify, "new funcWithProto().%priv",
+                "10", "pre", "objectBox-number");
+            // * use of "constructor"
+            taskList.push(FBTest.executeCommandAndVerify, "new func().%priv",
+                "1", "pre", "objectBox-number");
+
+            // Test completion
+            taskList.push(testCompletion, "new func().%pr", true);
+            taskList.push(testCompletion, "func.prototype.%", true);
+            taskList.push(testCompletion, "func.%priv.toP", true);
+            taskList.push(testCompletion, "func.%oth.%u", true);
+            taskList.push(testCompletion, "func.%oth.reg", true);
+            taskList.push(testCompletion, "new func.%oth().%u", true);
+
+            taskList.push(verifyParsing);
+
+            taskList.push(testInDebugger);
+
+            // Run!
+            taskList.run(function() {
+                FBTest.testDone("issue5873.DONE");
+            }, 0)
+        });
+    });
+}
diff --git a/tests/content/firebug.html b/tests/content/firebug.html
index a276ab6..f19242f 100644
--- a/tests/content/firebug.html
+++ b/tests/content/firebug.html
@@ -182,6 +182,7 @@ var testList = [
     {group: "commandLine",        uri: "commandLine/5042/issue5042.js",           desc: "Issue 5042: Command Line should not prevent tabbing out when empty", testPage: "commandLine/5042/issue5042.html"},
     {group: "commandLine",        uri: "commandLine/5130/issue5130.js",           desc: "Array indices are sorted alphabetically instead of numerically", testPage: "commandLine/5130/issue5130.html"},
     {group: "commandLine",        uri: "commandLine/5779/issue5779.js",           desc: "Allow to set the root element in $ and $$", testPage: "commandLine/5779/issue5779.html"},
+    {group: "commandLine",        uri: "commandLine/5873/issue5873.js",           desc: "Issue 5873: Integrate FireClosure", testPage: "commandLine/5873/issue5873.html"},
     {group: "commandLine",        uri: "commandLine/5878/issue5878.js",           desc: "Issue 5878: proposal for a command line method: include(url)", testPage: "commandLine/5878/issue5878.html"},
     {group: "commandLine",        uri: "commandLine/5951/issue5951.js",           desc: "Title of array-like objects should be clickable", testPage: "commandLine/5951/issue5951.html"},
     {group: "html",               uri: "html/breakpoints/breakOnElement.js",      desc: "Mutation breakpoints test", testPage: "html/breakpoints/breakOnElement.html"},

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/firebug.git



More information about the Pkg-mozext-commits mailing list