Bug 1124536 - Fix Debugger UI loadSourceError on PageMod content scripts associated to 'javascript:SOURCECODE' urls. r=jlongster
☠☠ backed out by 1821e8426f63 ☠ ☠
authorLuca Greco <luca.greco@alcacoop.it>
Sat, 07 Feb 2015 11:13:00 -0500
changeset 242518 acc254692008fcf3ad1603c9bbeadc5e504e2535
parent 242517 d7ce14fb3ee9bb52983d23604d49ba54df25f625
child 242519 96ac8d46bf2a7450e1bf4404299acadc9baf44ca
push id660
push usermichael.l.comella@gmail.com
push dateThu, 12 Feb 2015 18:55:31 +0000
reviewersjlongster
bugs1124536
milestone38.0a1
Bug 1124536 - Fix Debugger UI loadSourceError on PageMod content scripts associated to 'javascript:SOURCECODE' urls. r=jlongster
browser/devtools/debugger/test/browser.ini
browser/devtools/debugger/test/browser_dbg_sources-pagemod.js
browser/devtools/debugger/test/doc_script-pagemod.html
toolkit/devtools/server/actors/script.js
--- a/browser/devtools/debugger/test/browser.ini
+++ b/browser/devtools/debugger/test/browser.ini
@@ -81,16 +81,17 @@ support-files =
   doc_random-javascript.html
   doc_recursion-stack.html
   doc_same-line-functions.html
   doc_scope-variable.html
   doc_scope-variable-2.html
   doc_scope-variable-3.html
   doc_scope-variable-4.html
   doc_script-eval.html
+  doc_script-pagemod.html
   doc_script-switching-01.html
   doc_script-switching-02.html
   doc_split-console-paused-reload.html
   doc_step-out.html
   doc_terminate-on-tab-close.html
   doc_tracing-01.html
   doc_watch-expressions.html
   doc_watch-expression-button.html
@@ -408,16 +409,18 @@ skip-if = e10s && debug
 [browser_dbg_sources-eval-01.js]
 skip-if = e10s && debug
 [browser_dbg_sources-eval-02.js]
 skip-if = e10s && debug
 [browser_dbg_sources-labels.js]
 skip-if = e10s && debug
 [browser_dbg_sources-sorting.js]
 skip-if = e10s && debug
+[browser_dbg_sources-pagemod.js]
+skip-if = e10s && debug
 [browser_dbg_split-console-paused-reload.js]
 skip-if = e10s && debug
 [browser_dbg_stack-01.js]
 skip-if = e10s && debug
 [browser_dbg_stack-02.js]
 skip-if = e10s && debug
 [browser_dbg_stack-03.js]
 skip-if = e10s # TODO
new file mode 100644
--- /dev/null
+++ b/browser/devtools/debugger/test/browser_dbg_sources-pagemod.js
@@ -0,0 +1,60 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Make sure eval scripts appear in the source list
+ */
+
+const TAB_URL = EXAMPLE_URL + "doc_script-pagemod.html";
+
+const pagemod = require("sdk/page-mod");
+const CONTENT_SCRIPT_CODE = "console.log('page-mod executed');";
+
+
+let testPageMod = pagemod.PageMod({
+  include: TAB_URL,
+  contentScript: CONTENT_SCRIPT_CODE
+});
+
+let destroyTestPageMod = testPageMod.destroy.bind(testPageMod);
+
+function test() {
+  let gTab, gPanel, gDebugger;
+  let gSources, gBreakpoints;
+
+  initDebugger(TAB_URL).then(([aTab,, aPanel]) => {
+    gTab = aTab;
+    gPanel = aPanel;
+    gDebugger = gPanel.panelWin;
+    gSources = gDebugger.DebuggerView.Sources;
+    gBreakpoints = gDebugger.DebuggerController.Breakpoints;
+
+    return Task.spawn(function*() {
+      let waitForSource =  waitForDebuggerEvents(gPanel, gPanel.panelWin.EVENTS.SOURCES_ADDED, 1);
+
+      // NOTE: devtools debugger panel needs to be already open,
+      // or the pagemod script will not be shown in the sources panel
+      callInTab(gTab, "reloadTab");
+
+      yield waitForSource;
+      is(gSources.values.length, 3, "Should have 3 source");
+
+      let item = gSources.getItemForAttachment(e => {
+        return e.label.indexOf("javascript:") === 0;
+      });
+      ok(item, "Source label is incorrect.");
+
+      yield selectSourceAndGetBlackBoxButton(gPanel, "javascript:" + CONTENT_SCRIPT_CODE);
+
+      let res = yield promiseInvoke(gDebugger.DebuggerController.client,
+                                gDebugger.DebuggerController.client.request,
+                                { to: item.value, type: "source"});
+
+      ok(res && res.source == CONTENT_SCRIPT_CODE, "SourceActor reply received");
+      is(res.source, CONTENT_SCRIPT_CODE, "source is correct");
+      is(res.contentType, "text/javascript", "contentType is correct");
+
+      yield closeDebuggerAndFinish(gPanel);
+    }).then(destroyTestPageMod, destroyTestPageMod);
+  });
+}
new file mode 100644
--- /dev/null
+++ b/browser/devtools/debugger/test/doc_script-pagemod.html
@@ -0,0 +1,14 @@
+<!-- Any copyright is dedicated to the Public Domain.
+     http://creativecommons.org/publicdomain/zero/1.0/ -->
+<!doctype html>
+
+<html>
+  <head>
+    <meta charset="utf-8"/>
+    <title>Debugger test page</title>
+  </head>
+
+  <body>
+    <script>function reloadTab() { window.location.reload(); }</script>
+  </body>
+</html>
--- a/toolkit/devtools/server/actors/script.js
+++ b/toolkit/devtools/server/actors/script.js
@@ -5309,16 +5309,24 @@ ThreadSources.prototype = {
         if (urlInfo.fileExtension === "html") {
           spec.isInlineSource = true;
         }
         else if (urlInfo.fileExtension === "js") {
           spec.contentType = "text/javascript";
         }
       } catch(ex) {
         // Not a valid URI.
+
+        // bug 1124536: fix getSourceText on scripts associated "javascript:SOURCE" urls
+        // (e.g. 'evaluate(sandbox, sourcecode, "javascript:"+sourcecode)' )
+        if (url.indexOf("javascript:") === 0) {
+          spec.contentType = "text/javascript";
+        } else {
+          console.warn("unable to parse url during SourceActor type detection", url, ex);
+        }
       }
     }
     else {
       // Assume the content is javascript if there's no URL
       spec.contentType = "text/javascript";
     }
 
     return this.source(spec);