Bug 976654: Rename 'options.id' to 'options.name' and generate unique 'id'. r=ZER0, a=lsblakk
authorIrakli Gozalishvili <rfobic@gmail.com>
Fri, 14 Mar 2014 15:30:19 -0700
changeset 183369 0071e789edce1f9c4ad5a04fce7758407e57e8bb
parent 183368 2efeedd5443bb03e2b8014fc09920853886a14e7
child 183370 052b1189180097d20f505fe70bcc54d2f8c99577
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersZER0, lsblakk
bugs976654
milestone29.0a2
Bug 976654: Rename 'options.id' to 'options.name' and generate unique 'id'. r=ZER0, a=lsblakk
addon-sdk/source/lib/sdk/ui/frame/model.js
addon-sdk/source/test/test-ui-frame.js
--- a/addon-sdk/source/lib/sdk/ui/frame/model.js
+++ b/addon-sdk/source/lib/sdk/ui/frame/model.js
@@ -27,27 +27,27 @@ const { id: addonID, data: { url: resolv
 const { Frames } = require("../../input/frame");
 
 
 const output = new OutputPort({ id: "frame-change" });
 const mailbox = new OutputPort({ id: "frame-mailbox" });
 const input = Frames;
 
 
-const urlToId = url =>
+const makeID = url =>
   ("frame-" + addonID + "-" + url).
     split("/").join("-").
     split(".").join("-").
     replace(/[^A-Za-z0-9_\-]/g, "");
 
 const validate = contract({
-  id: {
+  name: {
     is: ["string", "undefined"],
     ok: x => /^[a-z][a-z0-9-_]+$/i.test(x),
-    msg: "The `option.id` must be a valid alphanumeric string (hyphens and " +
+    msg: "The `option.name` must be a valid alphanumeric string (hyphens and " +
          "underscores are allowed) starting with letter."
   },
   url: {
     map: x => x.toString(),
     is: ["string"],
     ok: x => isLocalURL(x),
     msg: "The `options.url` must be a valid local URI."
   }
@@ -83,17 +83,17 @@ const Message = function({type, data, so
 const frames = new Map();
 const sources = new Map();
 
 const Frame = Class({
   extends: EventTarget,
   implements: [Disposable, Source],
   initialize: function(params={}) {
     const options = validate(params);
-    const id = options.id || urlToId(options.url);
+    const id = makeID(options.name || options.url);
 
     if (frames.has(id))
       throw Error("Frame with this id already exists: " + id);
 
     const initial = { id: id, url: resolve(options.url) };
     this.id = id;
 
     setListeners(this, params);
--- a/addon-sdk/source/test/test-ui-frame.js
+++ b/addon-sdk/source/test/test-ui-frame.js
@@ -41,36 +41,36 @@ exports["test frame API"] = function*(as
   assert.throws(() => new Frame(),
                 /The `options.url`/,
                 "must provide url");
 
   assert.throws(() => new Frame({ url: "http://mozilla.org/" }),
                 /The `options.url`/,
                 "options.url must be local url");
 
-  assert.throws(() => new Frame({url: url, id: "4you" }),
-                /The `option.id` must be a valid/,
-                "can only take valid ID's");
+  assert.throws(() => new Frame({url: url, name: "4you" }),
+                /The `option.name` must be a valid/,
+                "can only take valid names");
 
   const f1 = new Frame({ url: url });
 
   assert.ok(f1.id, "frame has an id");
   assert.equal(f1.url, void(0), "frame has no url until it's loaded");
   assert.equal(typeof(f1.postMessage), "function",
                "frames can postMessages");
 
   const p1 = wait(f1, "register");
 
   assert.throws(() => new Frame({ url: url }),
                 /Frame with this id already exists/,
                 "can't have two identical frames");
 
 
-  const f2 = new Frame({ id: "frame-2", url: url });
-  assert.pass("can create frame with same url but diff id");
+  const f2 = new Frame({ name: "frame-2", url: url });
+  assert.pass("can create frame with same url but diff name");
   const p2 = wait(f2, "register");
 
   yield p1;
   assert.pass("frame#1 was registered");
   assert.equal(f1.url, url, "once registered it get's url");
 
   yield p2;
   assert.pass("frame#2 was registered");
@@ -140,17 +140,17 @@ exports["test frame in toolbar"] = funct
 
 exports["test host to content messaging"] = function*(assert) {
   const url = "data:text/html,<script>new " + function() {
     window.addEventListener("message", (event) => {
       if (event.data === "ping!")
         event.source.postMessage("pong!", event.origin);
     });
   } + "</script>";
-  const f1 = new Frame({ id: "mailbox", url: url });
+  const f1 = new Frame({ name: "mailbox", url: url });
   const t1 = new Toolbar({ title: "mailbox", items: [f1] });
 
   const e1 = yield wait(f1, "ready");
   e1.source.postMessage("ping!", e1.origin);
 
   const pong = yield wait(f1, "message");
   assert.equal(pong.data, "pong!", "received ping back");
   t1.destroy();
@@ -164,17 +164,17 @@ exports["test content to host messaging"
     window.addEventListener("message", (event) => {
       if (event.data === "pong!")
         event.source.postMessage("end", event.origin);
     });
 
     window.parent.postMessage("ping!", "*");
   } + "</script>";
 
-  const f1 = new Frame({ id: "inbox", url: url });
+  const f1 = new Frame({ name: "inbox", url: url });
   const t1 = new Toolbar({ title: "inbox", items: [f1] });
 
   const e1 = yield wait(f1, "message");
   assert.equal(e1.data, "ping!", "received ping from content");
 
   e1.source.postMessage("pong!", e1.origin);
 
   const e2 = yield wait(f1, "message");
@@ -192,17 +192,17 @@ exports["test direct messaging"] = funct
       if (event.data === "inc")
         n = n + 1;
       if (event.data === "print")
         event.source.postMessage({ n: n }, event.origin);
     });
   } + "</script>";
 
   const w1 = getMostRecentBrowserWindow();
-  const f1 = new Frame({ url: url, id: "mail-cluster" });
+  const f1 = new Frame({ url: url, name: "mail-cluster" });
   const t1 = new Toolbar({ title: "claster", items: [f1] });
 
   yield wait(f1, "ready");
   assert.pass("document loaded in window#1");
 
   const w2 = open();
 
   yield wait(f1, "ready");