diff options
author | 2013-06-07 11:59:57 -0700 | |
---|---|---|
committer | 2013-06-07 11:59:57 -0700 | |
commit | 8690d56ff0bbd1031e8cc6788dd2159aac6b7adb (patch) | |
tree | d573336305dc756f357f20dd986f77cb3ceafb9b /src/js/firefox | |
parent | f42930c2226d07482725b03ad522c106c0bdec8b (diff) |
Reorganize the build system
* Move all javascript source to src/js
* Update the test runner, etc.
* Do less javascript compilation
Diffstat (limited to 'src/js/firefox')
-rw-r--r-- | src/js/firefox/build.mk | 102 | ||||
-rw-r--r-- | src/js/firefox/icons/fiveui-icon.html | 82 | ||||
-rw-r--r-- | src/js/firefox/icons/fiveui-icon.js | 42 | ||||
-rw-r--r-- | src/js/firefox/icons/options-icon.html | 31 | ||||
-rw-r--r-- | src/js/firefox/icons/options-icon.js | 27 | ||||
-rw-r--r-- | src/js/firefox/injected/platform-compute.js | 55 | ||||
-rw-r--r-- | src/js/firefox/injected/platform-ui.js | 30 | ||||
-rw-r--r-- | src/js/firefox/js/platform-ajax.js | 8 | ||||
-rw-r--r-- | src/js/firefox/js/platform-options.js | 33 | ||||
-rw-r--r-- | src/js/firefox/lib/ajax.js | 36 | ||||
-rw-r--r-- | src/js/firefox/lib/main.js | 216 | ||||
-rw-r--r-- | src/js/firefox/lib/storage-wrapper.js | 68 | ||||
-rw-r--r-- | src/js/firefox/lib/tabIds.js | 38 | ||||
-rw-r--r-- | src/js/firefox/package.json | 16 | ||||
-rw-r--r-- | src/js/firefox/test/test-main.js | 55 |
15 files changed, 839 insertions, 0 deletions
diff --git a/src/js/firefox/build.mk b/src/js/firefox/build.mk new file mode 100644 index 0000000..4696930 --- /dev/null +++ b/src/js/firefox/build.mk @@ -0,0 +1,102 @@ + +# Firefox Extension ############################################################ + +all: $(build-dir)/firefox.xpi + +firefox-dir := $(path) + +firefox-build := $(build-dir)/firefox + +$(firefox-build): | $(build-dir) + $(call cmd,mkdir) + + +# Generic Extension ############################################################ + +$(eval $(call stage-fiveui,$(firefox-build),stage-firefox)) + + +# Firefox File Staging ######################################################### + +# copy in firefox scripts +$(firefox-build)/data/js/%: $(firefox-dir)/js/% | $(firefox-build)/data/js + $(call cmd,cp) + +# copy in firefox scripts +$(firefox-build)/data/injected/%: $(firefox-dir)/injected/% \ + | $(firefox-build)/data/injected + $(call cmd,cp) + +$(firefox-build)/data/icons/%: $(firefox-dir)/icons/% \ + | $(firefox-build)/data/icons + $(call cmd,cp) + +$(firefox-build)/data/icons: | $(firefox-build)/data + $(call cmd,mkdir) + +$(firefox-build)/data/%: $(firefox-dir)/lib/% | $(firefox-build)/data + $(call cmd,cp) + + +$(firefox-build)/%: $(firefox-dir)/% | $(firefox-build) + $(call cmd,cp) + + +# Wrapper Compilation ########################################################## + +# In order to turn a number of different javascript modules into a single one, +# we just concatenate them all together. This should be fine, as all of the +# modules we define just provide functions, or register callbacks. +quiet_cmd_compilejs = JSC $(call drop-prefix,$@) + cmd_compilejs = cat $^ > $@ + +# we have to build one big source for the firefox main.js, as we can't really +# share reuse the CommonJS module system in the chrome version. +$(firefox-build)/data/main.js: \ + $(firefox-dir)/lib/main.js \ + $(fiveui-dir)/js/set.js \ + $(fiveui-dir)/js/url-pat.js \ + $(fiveui-dir)/js/url-pat.js \ + $(fiveui-dir)/js/settings.js \ + $(fiveui-dir)/js/messenger.js \ + $(fiveui-dir)/js/state.js \ + $(fiveui-dir)/js/utils.js \ + $(fiveui-dir)/js/rules.js \ + $(fiveui-dir)/js/background.js \ + | $(firefox-build)/data + $(call cmd,compilejs) + + +# Packaging #################################################################### + +addon-sdk := $(topdir)/tools/addon-sdk + +# wrapper for setting up the environment for the running the cfx command +cfx = ( cd $(addon-sdk) $(redir) && \ + . bin/activate $(redir) && \ + cd $1 $(redir) && \ + cfx $2 $(redir) ) + +.PHONY: stage-firefox +stage-firefox: \ + $(firefox-build)/package.json \ + $(firefox-build)/data/main.js \ + $(firefox-build)/data/ajax.js \ + $(firefox-build)/data/storage-wrapper.js \ + $(firefox-build)/data/tabIds.js \ + $(firefox-build)/data/icons/fiveui-icon.html \ + $(firefox-build)/data/icons/fiveui-icon.js \ + $(firefox-build)/data/icons/options-icon.html \ + $(firefox-build)/data/icons/options-icon.js \ + | $(firefox-build) + +$(build-dir)/firefox.xpi: stage-firefox + $(call label,XPI $(call drop-prefix,$@))\ + $(call cfx,$(build-dir),xpi -p $(topdir)/profiles/firefox \ + --pkgdir=$(firefox-build) ) + + +# Testing ###################################################################### + +run-firefox: stage-firefox + $(call label,RUNFF)$(call cfx,$(firefox-build),run) diff --git a/src/js/firefox/icons/fiveui-icon.html b/src/js/firefox/icons/fiveui-icon.html new file mode 100644 index 0000000..d943367 --- /dev/null +++ b/src/js/firefox/icons/fiveui-icon.html @@ -0,0 +1,82 @@ +<!-- + * Module : firefox/icon-content.html + * Copyright : (c) 2011-2012, Galois, Inc. + * + * Maintainer : + * Stability : Provisional + * Portability: Not Portable (Firefox Only) + * + * Licensed 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. + --> +<!DOCTYPE html> +<head> + <style type="text/css"> + body>div { + width: 24px; + } + div { + cursor: default; + } + + #icon-div { + position: absolute; + } + + #badge-text { + position: absolute; + right: 0px; + bottom: 4px; + border: 1px solid black; + border-radius: 3px; + color: white; + font-size: 7pt; + font-weigth: bold; + padding-left: 2px; + padding-right: 1px; + + /* IE10 */ + background-image: -ms-linear-gradient(top, #E61010 0%, #750202 100%); + + /* Mozilla Firefox */ + background-image: -moz-linear-gradient(top, #E61010 0%, #750202 100%); + + /* Opera */ + background-image: -o-linear-gradient(top, #E61010 0%, #750202 100%); + + /* Webkit (Safari/Chrome 10) */ + background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #E61010), color-stop(1, #750202)); + + /* Webkit (Chrome 11+) */ + background-image: -webkit-linear-gradient(top, #E61010 0%, #750202 100%); + + /* Proposed W3C Markup */ + background-image: linear-gradient(top, #E61010 0%, #750202 100%); + } + </style> +</head> +<html> + <body> + <div id="icon-div" height="16px"> + <img id="disabled-img" + src="../images/fiveui-icon-disabled.png" + height="16px" width="16px"> + </img> + <img id="enabled-img" + src="../images/fiveui-icon-enabled.png" + height="16px" width="16px" + style="display:none"> + </img> + <div id="badge-text"></div> + </div> + </body> +</html> diff --git a/src/js/firefox/icons/fiveui-icon.js b/src/js/firefox/icons/fiveui-icon.js new file mode 100644 index 0000000..61545da --- /dev/null +++ b/src/js/firefox/icons/fiveui-icon.js @@ -0,0 +1,42 @@ +/* + * Module : firefox/icon-script.js + * Copyright : (c) 2011-2012, Galois, Inc. + * + * Maintainer : + * Stability : Provisional + * Portability: Not Portable (Firefox only) + * + * Licensed 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. + */ + +(function() { + var updateBadgeText = function(text) { + $('#badge-text').text(text); + $('#badge-text').show(); + }; + + self.port.on('setEnabled', function(text) { + $('#disabled-img').hide(); + $('#enabled-img').show(); + if (text.length != 0) { + updateBadgeText(text); + } else { + $('#badge-text').hide(); + } + }); + self.port.on('setDisabled', function() { + $('#disabled-img').show(); + $('#enabled-img').hide(); + $('#badge-text').hide(); + }); + })(); diff --git a/src/js/firefox/icons/options-icon.html b/src/js/firefox/icons/options-icon.html new file mode 100644 index 0000000..850b530 --- /dev/null +++ b/src/js/firefox/icons/options-icon.html @@ -0,0 +1,31 @@ +<!-- + * Module : firefox/options-icon.html + * Copyright : (c) 2011-2012, Galois, Inc. + * + * Maintainer : + * Stability : Provisional + * Portability: Not Portable (Firefox only) + * + * Licensed 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. + --> + +<html> + <body> + <div id="options-div"> + <img id="options-img" + src="../images/Gear_3.svg" + height="16" width="16"> + </img> + </div> + </body> +</html> diff --git a/src/js/firefox/icons/options-icon.js b/src/js/firefox/icons/options-icon.js new file mode 100644 index 0000000..2008883 --- /dev/null +++ b/src/js/firefox/icons/options-icon.js @@ -0,0 +1,27 @@ +/* + * Module : firefox/options-script.js + * Copyright : (c) 2011-2012, Galois, Inc. + * + * Maintainer : + * Stability : Provisional + * Portability: Not Portable (Firefox only) + * + * Licensed 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. + */ + +(function() { + $('#options-div').click(function() { + //console.log('options-div handler'); + self.port.emit('showOptions'); + }); + })(); diff --git a/src/js/firefox/injected/platform-compute.js b/src/js/firefox/injected/platform-compute.js new file mode 100644 index 0000000..1f1dc48 --- /dev/null +++ b/src/js/firefox/injected/platform-compute.js @@ -0,0 +1,55 @@ +/* + * Module : firefox/firefox-injected-compute.js + * Copyright : (c) 2011-2012, Galois, Inc. + * + * Maintainer : + * Stability : Provisional + * Portability: Not Portable (Firefox only) + * + * Licensed 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. + */ + +/** + * @param {!string} css The css to inject. + */ +var addGlobalStyle = function(css) { + var head = document.getElementsByTagName('head')[0]; // find head element, which should exist + if (!head) { + head = document.createElement('head'); + + // XXX this is perhaps not reliable? + document.body.appendChild(head); + } + + var style = document.createElement('style'); // create <style> element + style.type = 'text/css'; + + if (style.styleSheet) { // for some cross-browser problem + style.styleSheet.cssText = css; // attach CSS text to style elt + } else { + style.appendChild(document.createTextNode(css)); // attach CSS text to style elt + } + head.appendChild(style); // attach style element to head +}; + +/** + * @return {{on: function(!string, function(*)), emit: function(!string, *)}} + */ +var obtainComputePort = function() { + var port = self.port; + + port.on('injectCSS', addGlobalStyle); + return self.port; +}; + + diff --git a/src/js/firefox/injected/platform-ui.js b/src/js/firefox/injected/platform-ui.js new file mode 100644 index 0000000..79636c1 --- /dev/null +++ b/src/js/firefox/injected/platform-ui.js @@ -0,0 +1,30 @@ +/* + * Module : firefox/firefox-injected-ui.js + * Copyright : (c) 2011-2012, Galois, Inc. + * + * Maintainer : + * Stability : Provisional + * Portability: Not Portable (Firefox only) + * + * Licensed 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. + */ + +/** + * @return {{on: function(!string, function(*)), emit: function(!string, *)}} + */ +var obtainPort = function() { + var port = self.port; + return self.port; +}; + + diff --git a/src/js/firefox/js/platform-ajax.js b/src/js/firefox/js/platform-ajax.js new file mode 100644 index 0000000..e32225a --- /dev/null +++ b/src/js/firefox/js/platform-ajax.js @@ -0,0 +1,8 @@ + +/** + * Placeholder function, as all ajax should be done in the backend + */ +var fiveui = fiveui || {}; +fiveui.ajax = fiveui.ajax || {}; + +fiveui.ajax.get = function () {}; diff --git a/src/js/firefox/js/platform-options.js b/src/js/firefox/js/platform-options.js new file mode 100644 index 0000000..0ae65f9 --- /dev/null +++ b/src/js/firefox/js/platform-options.js @@ -0,0 +1,33 @@ +/* + * Module : firefox/firefox-options.js + * Copyright : (c) 2011-2012, Galois, Inc. + * + * Maintainer : + * Stability : Provisional + * Portability: Not Portable (Firefox only) + * + * Licensed 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. + */ + +var fiveui = fiveui || {}; + +(function() { + +fiveui.firefox = fiveui.firefox || {}; +fiveui.firefox.options = fiveui.firefox.options || {}; + +fiveui.firefox.options.init = function() { + fiveui.options.init(self.port); +}; + +})(); diff --git a/src/js/firefox/lib/ajax.js b/src/js/firefox/lib/ajax.js new file mode 100644 index 0000000..404deee --- /dev/null +++ b/src/js/firefox/lib/ajax.js @@ -0,0 +1,36 @@ + +var fiveui = fiveui || {}; +var Request = require('request').Request; +var _ = require('underscore'); + +(function() { + +/** + * Use the request api to make an XHR request from the extension context. + * Behaves somewhat like the jQuery.ajax method, but only ever returns the text + * content of the response. + */ +exports.get = function(url, opts) { + + _.defaults(opts, { + success: function() {}, + error: function() {}, + }); + + Request({ + + url: url, + + onComplete:function(resp) { + if(resp.status == 200) { + opts.success(resp.text); + } else { + opts.error(); + } + }, + + }).get(); + +}; + +})(); diff --git a/src/js/firefox/lib/main.js b/src/js/firefox/lib/main.js new file mode 100644 index 0000000..84619ea --- /dev/null +++ b/src/js/firefox/lib/main.js @@ -0,0 +1,216 @@ +/* + * Module : firefox/main.js + * Copyright : (c) 2011-2012, Galois, Inc. + * + * Maintainer : + * Stability : Provisional + * Portability: Not Portable (Firefox only) + * + * Licensed 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. + */ + +_ = require('underscore'); +Backbone = require('backbone'); +StorageWrapper = require('storage-wrapper').StorageWrapper; +TabIds = require('tabIds').TabIds; + +var fiveui = fiveui || {}; + +fiveui.ajax = require('ajax'); + +(function() { + +fiveui.firefox = fiveui.firefox || {}; + +const widgets = require("widget"); +const tabs = require("tabs"); +const data = require("self").data; +const pageMod = require("page-mod"); + +fiveui.firefox.main = function() { + var settings = new fiveui.Settings(new StorageWrapper()); + var activeId = 0; + + // initialze the background functionality + + // the FiveUI button: + var icon = widgets.Widget({ + id: "FiveUI-Icon", + label: "FiveUI", + contentURL: data.url('icons/fiveui-icon.html'), + contentScriptFile: [ + data.url('jquery/jquery-1.8.3.js'), + data.url('icons/fiveui-icon.js') + ], + onClick: function() { + background.showUI(activeId); + } + }); + + var optionsButton = widgets.Widget( + { id: "FiveUI-Options", + label: "FiveUI", + contentURL: data.url('icons/options-icon.html'), + contentScriptFile: [ + data.url('jquery/jquery-1.8.3.js'), + data.url('icons/options-icon.js') + ] + } + ); + + /** + * @param {?fiveui.TabState} tabState + */ + var updateWidget = function(tabState) { + if(null == tabState) { + icon.port.emit('setDisabled'); + icon.width = 16; + } else { + var problems = getProblemCount(tabState); + icon.port.emit('setEnabled', problems); + if (problems == 0){ + icon.width = 16; + } else { + icon.width = 24; + } + } + }; + + // store the contents of the injected css, so that we can inject it later + var injectedCSS = [ + data.load('injected/injected.css'), + data.load('jquery/bundled.css') + ].join('\n'); + + /** + * Inject code and resources into the specified tab's web page. + * + * @param {!number} tabid The id of the tab to load scripts into. + * @param {!Array.<string>} inScripts The list of scripts to load in + * order. + * @param {!boolean} inFrames Whether or not to inject into iFrames. + * @return {void} + */ + var loadScripts = function(tabId, inScripts, inFrames, tab) { + + if(inFrames) { + var firefoxScripts = [dataLoader('injected/platform-compute.js')]; + } else { + var firefoxScripts = [dataLoader('injected/platform-ui.js')]; + } + + // just scripts, css gets filtered out. + var scripts = _.filter(_.flatten([firefoxScripts, inScripts]), + function(script) { + return script.search(/\.css$/i) == -1; + }); + + if (tab) { + var worker = tab.attach({ + contentScriptFile: scripts + }); + + background.connect(tabId, worker.port, tab.url, !inFrames); + worker.port.emit('injectCSS', injectedCSS); + } + }; + + var dataLoader = function(path) { + return data.url(path); + }; + + var background = new fiveui.Background(settings, updateWidget, + loadScripts, dataLoader); + + var tabIds = new TabIds(); + + var handleNewTab = function(tab) { + var tabId = tabIds.allocate(); + + tab.on('activate', function() { + background.activate(tabId); + activeId = tabId; + }); + + tab.on('ready', function() { + background.pageLoad(tabId, tab.url, tab); + }); + + tab.on('close', function() { + tabIds.free(tabId); + background.removeTab(tabId); + }); + }; + + // handle existing tabs + _.each(tabs, handleNewTab); + + // manage new tab creation + tabs.on('open', handleNewTab); + + /** + * @param {!fiveui.TabState} tabstate + * @return {void} + */ + var getProblemCount = function(tabState){ + var tabId = tabState.tabId; + var probs = tabState.problems.length; + var text = ''; + if (probs > 0) { + if (probs > 99) { + text = '99+'; + } else { + text = probs.toString(); + } + } + return text; + }; + + var showOptions = function() { + // TODO does not make use of existing options tabs, if any are open: + tabs.open(data.url('options.html')); + }; + + // set up a page-mod to be active on the options page, so that + // page can communicate with the add-on: + pageMod.PageMod( + { include: data.url('options.html') + , contentScriptWhen: 'end' + , contentScriptFile: + [ data.url('jquery/jquery-1.8.3.js') + , data.url('underscore.js') + , data.url('backbone.js') + , data.url('js/settings.js') + , data.url('js/chan.js') + , data.url('js/messenger.js') + , data.url('js/options.js') + , data.url('js/update-manager.js') + , data.url('js/utils.js') + , data.url('js/entry.js') + , data.url('js/rules.js') + , data.url('js/url-pat.js') + , data.url('js/platform-ajax.js') + , data.url('js/platform-options.js') + ] + , contentScript: 'fiveui.firefox.options.init();' + , onAttach: function (worker) { + fiveui.Settings.manager(worker.port, settings); + } + }); + + optionsButton.port.on('showOptions', showOptions); +}; + +exports.main = fiveui.firefox.main; + +})(); diff --git a/src/js/firefox/lib/storage-wrapper.js b/src/js/firefox/lib/storage-wrapper.js new file mode 100644 index 0000000..03bfeec --- /dev/null +++ b/src/js/firefox/lib/storage-wrapper.js @@ -0,0 +1,68 @@ +/* + * Module : firefox/storage.js + * Copyright : (c) 2011-2012, Galois, Inc. + * + * Maintainer : + * Stability : Provisional + * Portability: Not Portable (Firefox only) + * + * Licensed 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. + */ + + +const ss = require('simple-storage'); + +var fiveui = { firefox : {} }; + +/** + * A wraper around the Firefox Simple-Storage API to match the w3c Storage interface: + * http://dev.w3.org/html5/webstorage/#storage-0 + */ +fiveui.firefox.StorageWrapper = function() { + this.__defineGetter__('length', + function(){ + return Object.keys(ss.storage).length; + }); +}; + +fiveui.firefox.StorageWrapper.prototype.key = function(idx) { + return Object.keys(ss.storage)[idx]; +}; + +fiveui.firefox.StorageWrapper.prototype.getItem = function(key) { + return ss.storage[key]; +}; + +fiveui.firefox.StorageWrapper.prototype.setItem = function(key, value) { + ss.storage[key] = value; +}; + +fiveui.firefox.StorageWrapper.prototype.removeItem = function(key) { + var keys = Object.keys(ss.storage); + for(var i=0; i<keys.length; ++i) { + if(keys[i] == key) { + keys.splice(i,1); + delete ss.storage[key]; + return; + } + } +}; + +fiveui.firefox.StorageWrapper.prototype.clear = function() { + var keys = Object.keys(ss.storage); + for(var i=0; i<keys.length; ++i) { + delete ss.storage[keys[i]]; + } +}; + +exports.StorageWrapper = fiveui.firefox.StorageWrapper; diff --git a/src/js/firefox/lib/tabIds.js b/src/js/firefox/lib/tabIds.js new file mode 100644 index 0000000..f5dad78 --- /dev/null +++ b/src/js/firefox/lib/tabIds.js @@ -0,0 +1,38 @@ +/* + * Module : firefox/tabIds.js + * Copyright : (c) 2011-2012, Galois, Inc. + * + * Maintainer : + * Stability : Provisional + * Portability: Not Portable (Firefox only) + * + * Licensed 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. + */ + +var _ = require('underscore'); + +exports.TabIds = function() { + this.next = 0; +}; + +_.extend(exports.TabIds.prototype, { + + allocate:function() { + var tabId = this.next; + this.next = this.next + 1; + return tabId; + }, + + free:function(tabId) {} + +}); diff --git a/src/js/firefox/package.json b/src/js/firefox/package.json new file mode 100644 index 0000000..b3b2df2 --- /dev/null +++ b/src/js/firefox/package.json @@ -0,0 +1,16 @@ +{ + "name": "fiveui", + "fullName": "Five UI", + "license": "BSD 3", + "author": "Galois (http://galois.com)", + "contributors": [ "Rogan Creswick <creswick@galois.com>", + "Trevor Elliot <trevor@galois.com>", + "Benjamin Jones <bjones@galois.com>" + ], + "version": "0.2", + "id": "jid1-oquzbbbog1fmxq", + "description": "UI Constraint Checker", + "lib": "data/", + "main": "main.js", + "tests": "test" +} diff --git a/src/js/firefox/test/test-main.js b/src/js/firefox/test/test-main.js new file mode 100644 index 0000000..c25fec5 --- /dev/null +++ b/src/js/firefox/test/test-main.js @@ -0,0 +1,55 @@ +/* + * Module : firefox/test/test-main.js + * Copyright : (c) 2011-2012, Galois, Inc. + * + * Maintainer : + * Stability : Provisional + * Portability: Not Portable (Firefox only) + * + * Licensed 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. + */ + +const stWrapper = require("fiveui/firefox/storage"); + +var setup = function(fn){ + return function(test) { + var storage = new stWrapper.StorageWrapper(); + storage.clear(); + fn(test); + }; +}; + +exports.test_newStorageWrapper = setup(function(test) { + var storage = new stWrapper.StorageWrapper(); + var key = 'key'; + var val = 'val'; + storage.setItem(key, val); + test.assertEqual(val, storage.getItem(key), 'wrong value'); +}); + +exports.test_keys = setup(function(test) { + var storage = new stWrapper.StorageWrapper(); + var key = 'key'; + var val = 'val'; + storage.setItem(key, val); + test.assertEqual(key, storage.key(0), 'wrong key returned'); +}); + +exports.test_length = setup(function(test) { + var storage = new stWrapper.StorageWrapper(); + var x = 10; + for (var i=0; i < x; ++i) { + storage.setItem(i, i*i); + } + test.assertEqual(x, storage.length, 'unexpected length'); +});
\ No newline at end of file |