-
Notifications
You must be signed in to change notification settings - Fork 0
Create test WE for Bug 1292234 #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
4f8fb95
7737265
966aeec
5cd6eab
d8f075d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web-ext-artifacts |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Test WE for Bug 1292234 | ||
|
||
|
||
## About | ||
|
||
This extension is a test extension for providing a patch for [Bug 1292234](https://bugzilla.mozilla.org/show_bug.cgi?id=1292234). | ||
|
||
It simply sets some storage values in `browser.storage.local`. | ||
|
||
Because I am using this extension to develop the patch for Bug 1292234 landing in Firefox, I have a `web-ext-config.js` file that points to my local build of Firefox. | ||
|
||
See the README for the related [Hidden with Options Page extension](https://github.com/biancadanforth/webextensions-examples/tree/master/hidden-with-options-page) for some more context. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
(async function main() { | ||
|
||
// Open an extension page in a new tab to make use of the Browser Content Toolbox | ||
// to be able to debug the storage actor script: | ||
// (mozilla-central/devtools/server/actors/storage.js) | ||
browser.tabs.create({url: browser.extension.getURL('extension-page.html')}); | ||
|
||
|
||
// This is what our customer data looks like. | ||
const customerData = [ | ||
{ ssn: "444-44-4444", name: "Bill", age: 35, email: "bill@company.com" }, | ||
{ ssn: "555-55-5555", name: "Donna", age: 32, email: "donna@home.org" } | ||
]; | ||
|
||
// Populate extension local storage as similarly as possible to how the | ||
// same data populates IndexedDB storage | ||
for (const entry of customerData) { | ||
browser.storage.local.set({[entry.ssn]: entry}); | ||
} | ||
|
||
// Populate window.indexedDB storage | ||
// (Put something (e.g. object literal) in window.indexedDB to compare | ||
// how IndexedDB storage actors access/handle the information, since | ||
// extension storage is similar (but more restrictive) in terms of | ||
// acceptable store items.) | ||
function storeObjectLiteralInIndexedDB() { | ||
|
||
if (!window.indexedDB) { | ||
window.alert("Your browser doesn't support a stable version of IndexedDB."); | ||
} | ||
|
||
// Open a database | ||
const dbName = "Bug1292234IndexedDB"; | ||
|
||
var db; | ||
var request = indexedDB.open(dbName, 4); | ||
request.onerror = function(event) { | ||
throw new Error(`${request.errorCode}`); | ||
}; | ||
request.onsuccess = function(event) { | ||
db = event.target.result; | ||
}; | ||
// Also fires when a new db is being created. | ||
request.onupgradeneeded = function(event) { | ||
var db = event.target.result; | ||
|
||
// 2. Create an object store in the database | ||
// Create an objectStore to hold information about our customers. We're | ||
// going to use "ssn" as our key path because it's guaranteed to be | ||
// unique - or at least that's what I was told during the kickoff meeting. | ||
var objectStore = db.createObjectStore("customers", { keyPath: "ssn" }); | ||
|
||
// Create an index to search customers by name. We may have duplicates | ||
// so we can't use a unique index. | ||
objectStore.createIndex("name", "name", { unique: false }); | ||
|
||
// Create an index to search customers by email. We want to ensure that | ||
// no two customers have the same email, so use a unique index. | ||
objectStore.createIndex("email", "email", { unique: true }); | ||
|
||
// Wait for the operation to complete by listening to the right kind of | ||
// DOM event. | ||
// Use transaction oncomplete to make sure the objectStore creation is | ||
// finished before adding data into it. | ||
objectStore.transaction.oncomplete = function(event) { | ||
// Store values in the newly created objectStore. | ||
var customerObjectStore = db.transaction("customers", "readwrite").objectStore("customers"); | ||
customerData.forEach((customer) => { | ||
customerObjectStore.add(customer); | ||
}); | ||
}; | ||
}; | ||
} | ||
|
||
storeObjectLiteralInIndexedDB(); | ||
|
||
function handleChange(changes, areaName) { | ||
if (areaName !== 'local') return; | ||
console.log("WebExtensionLog::ExtensionLocalStorageChange", changes); | ||
} | ||
|
||
// Add listeners | ||
browser.storage.onChanged.addListener(handleChange); | ||
}()); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" dir="ltr"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Bug 1292234 Test Extension Page</title> | ||
</head> | ||
<body> | ||
<div id="extension-page"> | ||
If you have this tab focused, you can debug the storage actor scripts running in the actor's target extension process using the Browser Content Toolbox. | ||
Note: The storage actor is created upon opening the addon devtool's storage inspector. | ||
</div> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"hidden": true, | ||
"background": { | ||
"scripts": ["background.js"] | ||
}, | ||
"browser_action": { | ||
"default_title": "Bug 1292234", | ||
"default_popup": "popup.html" | ||
}, | ||
"description": "Test WE for Bug 1292234; simply sets some keys/values in browser.storage.local", | ||
"homepage_url": "https://github.com/biancadanforth/webextensions-examples/tree/master/bug-1292234-test-we", | ||
"manifest_version": 2, | ||
"name": "Test WE for Bug 1292234", | ||
"permissions": [ | ||
"storage", | ||
"tabs" | ||
], | ||
"version": "1.1", | ||
"applications": { | ||
"gecko": { | ||
"id": "test-we-for-bug-1292234@mozilla.org", | ||
"strict_min_version": "57.0a1" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" dir="ltr"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Bug 1292234 Test WE</title> | ||
</head> | ||
<body> | ||
<div id="browser-action-app"> | ||
Check extension local storage | ||
</div> | ||
<script src="popup.js"></script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Open an extension page in a new tab to make use of the Browser Content Toolbox | ||
// to be able to debug the storage actor script: | ||
// (mozilla-central/devtools/server/actors/storage.js) | ||
// Useful for debugging storage actor when we have no background page (or remove | ||
// it temporarily) | ||
browser.tabs.create({url: browser.extension.getURL('extension-page.html')}); | ||
|
||
const customerData = [ | ||
{ ssn: "666-66-6666", name: "Linda", age: 39, email: "linda@company.com" }, | ||
{ ssn: "777-77-7777", name: "Greg", age: 31, email: "greg@home.org" } | ||
]; | ||
|
||
for (const entry of customerData) { | ||
browser.storage.local.set({[entry.ssn]: entry}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
run: { | ||
// Points to my local artifact development build of Firefox | ||
firefox: '/Users/bdanforth/src/mozilla-unified/objdir-frontend-debug-artifact/dist/Nightly.app/Contents/MacOS/firefox', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seem pretty specific for your setup :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is that bad? How might I abstract that away? One way or the other, I need to point to my local build. |
||
startUrl: [ | ||
'about:debugging', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't know |
||
], | ||
}, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this comment adds clarity, since it's just describing what is happening on the next line.
If you want to document why adding a handler is a good idea here, that would be worth commenting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point thanks