Bug 1638557 - Remove the `MOZ_NEW_WEBEXT_STORAGE` build flag. r=markh

Now that we've landed all the pieces for Rust `storage.sync`, and
intend to ship it for everyone in 78, we don't need to hide it behind a
build flag. Setting the `webextensions.storage.sync.kinto` pref to
false toggles the new Rust backend at runtime.

Differential Revision: https://phabricator.services.mozilla.com/D75872
This commit is contained in:
Lina Cambridge 2020-05-19 00:48:03 +00:00
Родитель e3920e9728
Коммит 466b3ca6f9
10 изменённых файлов: 208 добавлений и 261 удалений

Просмотреть файл

@ -4,21 +4,19 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
Classes = []
if defined('MOZ_NEW_WEBEXT_STORAGE'):
Classes += [
{
'cid': '{f1e424f2-67fe-4f69-a8f8-3993a71f44fa}',
'contract_ids': ['@mozilla.org/extensions/storage/internal/sync-area;1'],
'type': 'mozIConfigurableExtensionStorageArea',
'headers': ['mozilla/extensions/storage/ExtensionStorageComponents.h'],
'constructor': 'mozilla::extensions::storage::NewSyncArea',
},
{
'cid': '{5b7047b4-fe17-4661-8e13-871402bc2023}',
'contract_ids': ['@mozilla.org/extensions/storage/sync;1'],
'jsm': 'resource://gre/modules/ExtensionStorageComponents.jsm',
'constructor': 'StorageSyncService',
'singleton': True,
},
]
Classes = [
{
'cid': '{f1e424f2-67fe-4f69-a8f8-3993a71f44fa}',
'contract_ids': ['@mozilla.org/extensions/storage/internal/sync-area;1'],
'type': 'mozIConfigurableExtensionStorageArea',
'headers': ['mozilla/extensions/storage/ExtensionStorageComponents.h'],
'constructor': 'mozilla::extensions::storage::NewSyncArea',
},
{
'cid': '{5b7047b4-fe17-4661-8e13-871402bc2023}',
'contract_ids': ['@mozilla.org/extensions/storage/sync;1'],
'jsm': 'resource://gre/modules/ExtensionStorageComponents.jsm',
'constructor': 'StorageSyncService',
'singleton': True,
},
]

Просмотреть файл

@ -17,7 +17,7 @@ XPIDL_SOURCES += [
# a delegate for consumers to use instead. Android Components can then provide
# an implementation of the delegate that's backed by the Rust component. For
# details, please see bug 1626506, comment 4.
if CONFIG['MOZ_WIDGET_TOOLKIT'] != "android" and CONFIG['MOZ_NEW_WEBEXT_STORAGE']:
if CONFIG['MOZ_WIDGET_TOOLKIT'] != "android":
EXPORTS.mozilla.extensions.storage += [
'ExtensionStorageComponents.h',
]

Просмотреть файл

@ -43,244 +43,219 @@ add_task(async function setup_storage_sync() {
do_get_profile();
});
add_task(
add_task(async function test_storage_sync_service() {
const service = StorageSyncService.getInterface(Ci.mozIExtensionStorageArea);
{
skip_if: () => !AppConstants.MOZ_NEW_WEBEXT_STORAGE,
},
async function test_storage_sync_service() {
const service = StorageSyncService.getInterface(
Ci.mozIExtensionStorageArea
let { changes, value } = await promisify(
service.set,
"ext-1",
JSON.stringify({
hi: "hello! 💖",
bye: "adiós",
})
);
{
let { changes, value } = await promisify(
service.set,
"ext-1",
JSON.stringify({
hi: "hello! 💖",
bye: "adiós",
})
);
deepEqual(
changes,
[
{
hi: {
newValue: "hello! 💖",
},
bye: {
newValue: "adiós",
},
deepEqual(
changes,
[
{
hi: {
newValue: "hello! 💖",
},
bye: {
newValue: "adiós",
},
],
"`set` should notify listeners about changes"
);
ok(!value, "`set` should not return a value");
}
{
let { changes, value } = await promisify(
service.get,
"ext-1",
JSON.stringify(["hi"])
);
deepEqual(changes, [], "`get` should not notify listeners");
deepEqual(
value,
{
hi: "hello! 💖",
},
"`get` with key should return value"
);
let { value: allValues } = await promisify(service.get, "ext-1", "null");
deepEqual(
allValues,
{
hi: "hello! 💖",
bye: "adiós",
},
"`get` without a key should return all values"
);
}
{
await promisify(
service.set,
"ext-2",
JSON.stringify({
hi: "hola! 👋",
})
);
await promisify(service.clear, "ext-1");
let { value: allValues } = await promisify(service.get, "ext-1", "null");
deepEqual(allValues, {}, "clear removed ext-1");
let { value: allValues2 } = await promisify(service.get, "ext-2", "null");
deepEqual(allValues2, { hi: "hola! 👋" }, "clear didn't remove ext-2");
// We need to clear data for ext-2 too, so later tests don't fail due to
// this data.
await promisify(service.clear, "ext-2");
}
],
"`set` should notify listeners about changes"
);
ok(!value, "`set` should not return a value");
}
);
add_task(
{
skip_if: () => !AppConstants.MOZ_NEW_WEBEXT_STORAGE,
},
async function test_storage_sync_bridged_engine() {
const area = StorageSyncService.getInterface(Ci.mozIExtensionStorageArea);
const engine = StorageSyncService.getInterface(Ci.mozIBridgedSyncEngine);
info("Add some local items");
await promisify(area.set, "ext-1", JSON.stringify({ a: "abc" }));
await promisify(area.set, "ext-2", JSON.stringify({ b: "xyz" }));
info("Start a sync");
await promisify(engine.syncStarted);
info("Store some incoming synced items");
let incomingEnvelopesAsJSON = [
let { changes, value } = await promisify(
service.get,
"ext-1",
JSON.stringify(["hi"])
);
deepEqual(changes, [], "`get` should not notify listeners");
deepEqual(
value,
{
hi: "hello! 💖",
},
"`get` with key should return value"
);
let { value: allValues } = await promisify(service.get, "ext-1", "null");
deepEqual(
allValues,
{
hi: "hello! 💖",
bye: "adiós",
},
"`get` without a key should return all values"
);
}
{
await promisify(
service.set,
"ext-2",
JSON.stringify({
hi: "hola! 👋",
})
);
await promisify(service.clear, "ext-1");
let { value: allValues } = await promisify(service.get, "ext-1", "null");
deepEqual(allValues, {}, "clear removed ext-1");
let { value: allValues2 } = await promisify(service.get, "ext-2", "null");
deepEqual(allValues2, { hi: "hola! 👋" }, "clear didn't remove ext-2");
// We need to clear data for ext-2 too, so later tests don't fail due to
// this data.
await promisify(service.clear, "ext-2");
}
});
add_task(async function test_storage_sync_bridged_engine() {
const area = StorageSyncService.getInterface(Ci.mozIExtensionStorageArea);
const engine = StorageSyncService.getInterface(Ci.mozIBridgedSyncEngine);
info("Add some local items");
await promisify(area.set, "ext-1", JSON.stringify({ a: "abc" }));
await promisify(area.set, "ext-2", JSON.stringify({ b: "xyz" }));
info("Start a sync");
await promisify(engine.syncStarted);
info("Store some incoming synced items");
let incomingEnvelopesAsJSON = [
{
id: "guidAAA",
modified: 0.1,
cleartext: JSON.stringify({
id: "guidAAA",
modified: 0.1,
cleartext: JSON.stringify({
id: "guidAAA",
extId: "ext-2",
data: JSON.stringify({
c: 1234,
}),
extId: "ext-2",
data: JSON.stringify({
c: 1234,
}),
},
{
}),
},
{
id: "guidBBB",
modified: 0.1,
cleartext: JSON.stringify({
id: "guidBBB",
modified: 0.1,
cleartext: JSON.stringify({
id: "guidBBB",
extId: "ext-3",
data: JSON.stringify({
d: "new! ✨",
}),
extId: "ext-3",
data: JSON.stringify({
d: "new! ✨",
}),
},
].map(e => JSON.stringify(e));
await promisify(area.storeIncoming, incomingEnvelopesAsJSON);
}),
},
].map(e => JSON.stringify(e));
await promisify(area.storeIncoming, incomingEnvelopesAsJSON);
info("Merge");
// Three levels of JSON wrapping: each outgoing envelope, the cleartext in
// each envelope, and the extension storage data in each cleartext.
// TODO: Should we reduce to 2? Extension storage data could be a map...
let { value: outgoingEnvelopesAsJSON } = await promisify(area.apply);
let outgoingEnvelopes = outgoingEnvelopesAsJSON.map(json =>
JSON.parse(json)
);
let parsedCleartexts = outgoingEnvelopes.map(e => JSON.parse(e.cleartext));
let parsedData = parsedCleartexts.map(c => JSON.parse(c.data));
info("Merge");
// Three levels of JSON wrapping: each outgoing envelope, the cleartext in
// each envelope, and the extension storage data in each cleartext.
// TODO: Should we reduce to 2? Extension storage data could be a map...
let { value: outgoingEnvelopesAsJSON } = await promisify(area.apply);
let outgoingEnvelopes = outgoingEnvelopesAsJSON.map(json => JSON.parse(json));
let parsedCleartexts = outgoingEnvelopes.map(e => JSON.parse(e.cleartext));
let parsedData = parsedCleartexts.map(c => JSON.parse(c.data));
// ext-1 doesn't exist remotely yet, so the Rust sync layer will generate
// a GUID for it. We don't know what it is, so we find it by the extension
// ID.
let ext1Index = parsedCleartexts.findIndex(c => c.extId == "ext-1");
greater(ext1Index, -1, "Should find envelope for ext-1");
let ext1Guid = outgoingEnvelopes[ext1Index].id;
// ext-1 doesn't exist remotely yet, so the Rust sync layer will generate
// a GUID for it. We don't know what it is, so we find it by the extension
// ID.
let ext1Index = parsedCleartexts.findIndex(c => c.extId == "ext-1");
greater(ext1Index, -1, "Should find envelope for ext-1");
let ext1Guid = outgoingEnvelopes[ext1Index].id;
// ext-2 has a remote GUID that we set in the test above.
let ext2Index = outgoingEnvelopes.findIndex(c => c.id == "guidAAA");
greater(ext2Index, -1, "Should find envelope for ext-2");
// ext-2 has a remote GUID that we set in the test above.
let ext2Index = outgoingEnvelopes.findIndex(c => c.id == "guidAAA");
greater(ext2Index, -1, "Should find envelope for ext-2");
equal(outgoingEnvelopes.length, 2, "Should upload ext-1 and ext-2");
equal(
ext1Guid,
parsedCleartexts[ext1Index].id,
"ext-1 ID in envelope should match cleartext"
);
deepEqual(
parsedData[ext1Index],
{
a: "abc",
},
"Should upload new data for ext-1"
);
equal(
outgoingEnvelopes[ext2Index].id,
parsedCleartexts[ext2Index].id,
"ext-2 ID in envelope should match cleartext"
);
deepEqual(
parsedData[ext2Index],
{
b: "xyz",
c: 1234,
},
"Should merge local and remote data for ext-2"
);
equal(outgoingEnvelopes.length, 2, "Should upload ext-1 and ext-2");
equal(
ext1Guid,
parsedCleartexts[ext1Index].id,
"ext-1 ID in envelope should match cleartext"
);
deepEqual(
parsedData[ext1Index],
{
a: "abc",
},
"Should upload new data for ext-1"
);
equal(
outgoingEnvelopes[ext2Index].id,
parsedCleartexts[ext2Index].id,
"ext-2 ID in envelope should match cleartext"
);
deepEqual(
parsedData[ext2Index],
{
b: "xyz",
c: 1234,
},
"Should merge local and remote data for ext-2"
);
info("Mark all extensions as uploaded");
await promisify(engine.setUploaded, 0, [ext1Guid, "guidAAA"]);
info("Mark all extensions as uploaded");
await promisify(engine.setUploaded, 0, [ext1Guid, "guidAAA"]);
info("Finish sync");
await promisify(engine.syncFinished);
info("Finish sync");
await promisify(engine.syncFinished);
// Try fetching values for the remote-only extension we just synced.
let { value: ext3Value } = await promisify(area.get, "ext-3", "null");
deepEqual(
ext3Value,
{
d: "new! ✨",
},
"Should return new keys for ext-3"
);
// Try fetching values for the remote-only extension we just synced.
let { value: ext3Value } = await promisify(area.get, "ext-3", "null");
deepEqual(
ext3Value,
{
d: "new! ✨",
},
"Should return new keys for ext-3"
);
info("Try applying a second time");
let secondApply = await promisify(area.apply);
deepEqual(
secondApply.value,
{},
"Shouldn't merge anything on second apply"
);
info("Try applying a second time");
let secondApply = await promisify(area.apply);
deepEqual(secondApply.value, {}, "Shouldn't merge anything on second apply");
info("Wipe all items");
await promisify(engine.wipe);
info("Wipe all items");
await promisify(engine.wipe);
for (let extId of ["ext-1", "ext-2", "ext-3"]) {
// `get` always returns an object, even if there are no keys for the
// extension ID.
let { value } = await promisify(area.get, extId, "null");
deepEqual(value, {}, `Wipe should remove all values for ${extId}`);
}
for (let extId of ["ext-1", "ext-2", "ext-3"]) {
// `get` always returns an object, even if there are no keys for the
// extension ID.
let { value } = await promisify(area.get, extId, "null");
deepEqual(value, {}, `Wipe should remove all values for ${extId}`);
}
);
});
add_task(
{
skip_if: () => !AppConstants.MOZ_NEW_WEBEXT_STORAGE,
},
async function test_storage_sync_quota() {
const service = StorageSyncService.getInterface(
Ci.mozIExtensionStorageArea
);
const engine = StorageSyncService.getInterface(Ci.mozIBridgedSyncEngine);
await promisify(engine.wipe);
await promisify(service.set, "ext-1", JSON.stringify({ x: "hi" }));
await promisify(service.set, "ext-1", JSON.stringify({ longer: "value" }));
add_task(async function test_storage_sync_quota() {
const service = StorageSyncService.getInterface(Ci.mozIExtensionStorageArea);
const engine = StorageSyncService.getInterface(Ci.mozIBridgedSyncEngine);
await promisify(engine.wipe);
await promisify(service.set, "ext-1", JSON.stringify({ x: "hi" }));
await promisify(service.set, "ext-1", JSON.stringify({ longer: "value" }));
let { value: v1 } = await promisify(service.getBytesInUse, "ext-1", '"x"');
Assert.equal(v1, 5); // key len without quotes, value len with quotes.
let { value: v2 } = await promisify(service.getBytesInUse, "ext-1", "null");
// 5 from 'x', plus 'longer' (6 for key, 7 for value = 13) = 18.
Assert.equal(v2, 18);
let { value: v1 } = await promisify(service.getBytesInUse, "ext-1", '"x"');
Assert.equal(v1, 5); // key len without quotes, value len with quotes.
let { value: v2 } = await promisify(service.getBytesInUse, "ext-1", "null");
// 5 from 'x', plus 'longer' (6 for key, 7 for value = 13) = 18.
Assert.equal(v2, 18);
// Now set something greater than our quota.
await Assert.rejects(
promisify(
service.set,
"ext-1",
JSON.stringify({
big: "x".repeat(Ci.mozIExtensionStorageArea.SYNC_QUOTA_BYTES),
})
),
ex => ex.result == NS_ERROR_DOM_QUOTA_EXCEEDED_ERR,
"should reject with NS_ERROR_DOM_QUOTA_EXCEEDED_ERR"
);
}
);
// Now set something greater than our quota.
await Assert.rejects(
promisify(
service.set,
"ext-1",
JSON.stringify({
big: "x".repeat(Ci.mozIExtensionStorageArea.SYNC_QUOTA_BYTES),
})
),
ex => ex.result == NS_ERROR_DOM_QUOTA_EXCEEDED_ERR,
"should reject with NS_ERROR_DOM_QUOTA_EXCEEDED_ERR"
);
});

Просмотреть файл

@ -32,7 +32,6 @@ wasm_library_sandboxing = ["gkrust-shared/wasm_library_sandboxing"]
webgpu = ["gkrust-shared/webgpu"]
remote_agent = ["gkrust-shared/remote"]
glean = ["gkrust-shared/glean"]
new_webext_storage = ["gkrust-shared/new_webext_storage"]
[dependencies]
bench-collections-gtest = { path = "../../../../xpcom/rust/gtest/bench-collections" }

Просмотреть файл

@ -33,7 +33,6 @@ wasm_library_sandboxing = ["gkrust-shared/wasm_library_sandboxing"]
webgpu = ["gkrust-shared/webgpu"]
remote_agent = ["gkrust-shared/remote"]
glean = ["gkrust-shared/glean"]
new_webext_storage = ["gkrust-shared/new_webext_storage"]
[dependencies]
gkrust-shared = { path = "shared" }

Просмотреть файл

@ -79,6 +79,3 @@ if CONFIG['MOZ_GLEAN']:
if CONFIG['MOZ_USING_WASM_SANDBOXING']:
gkrust_features += ['wasm_library_sandboxing']
if CONFIG['MOZ_NEW_WEBEXT_STORAGE']:
gkrust_features += ['new_webext_storage']

Просмотреть файл

@ -50,7 +50,7 @@ wgpu_bindings = { path = "../../../../gfx/wgpu_bindings", optional = true }
mapped_hyph = { git = "https://github.com/jfkthame/mapped_hyph.git", tag = "v0.3.0" }
remote = { path = "../../../../remote", optional = true }
fog = { path = "../../../components/glean", optional = true }
webext_storage_bridge = { path = "../../../components/extensions/storage/webext_storage_bridge", optional = true }
webext_storage_bridge = { path = "../../../components/extensions/storage/webext_storage_bridge" }
unic-langid = { version = "0.8", features = ["likelysubtags"] }
unic-langid-ffi = { path = "../../../../intl/locale/rust/unic-langid-ffi" }
@ -102,7 +102,6 @@ wasm_library_sandboxing = ["rlbox_lucet_sandbox"]
webgpu = ["wgpu_bindings"]
remote_agent = ["remote"]
glean = ["fog"]
new_webext_storage = ["webext_storage_bridge"]
[lib]
path = "lib.rs"

Просмотреть файл

@ -55,7 +55,6 @@ extern crate xulstore;
extern crate audio_thread_priority;
#[cfg(feature = "new_webext_storage")]
extern crate webext_storage_bridge;
#[cfg(feature = "webrtc")]

Просмотреть файл

@ -411,11 +411,4 @@ this.AppConstants = Object.freeze({
#else
false,
#endif
MOZ_NEW_WEBEXT_STORAGE:
#ifdef MOZ_NEW_WEBEXT_STORAGE
true,
#else
false,
#endif
});

Просмотреть файл

@ -1983,18 +1983,6 @@ set_config('MOZ_GLEAN', True, when=glean)
set_define('MOZ_GLEAN', True, when=glean)
# New WebExtension `storage.sync` implementation in Rust
# ==============================================================
@depends(milestone)
def new_webext_storage(milestone):
if milestone.is_nightly:
return True
set_config('MOZ_NEW_WEBEXT_STORAGE', True, when=new_webext_storage)
set_define('MOZ_NEW_WEBEXT_STORAGE', True, when=new_webext_storage)
# dump_syms
# ==============================================================