fx-compat: Add HiddenBrowser.jsm
Remove Zotero.Browser and add HiddenBrowser.jsm. Post-Fission, web/file content loads in a separate process, so it's not possible (as best as I can tell) to directly access the contents of a hidden browser -- it just appears as about:blank in the parent process. We now use Mozilla's JSWindowActor mechanism [1] to get page data, including character set and body text for full-text indexing. We'll have to evaluate other uses of hidden browsers to see how to handle them. This also adds include.jsm for loading the Zotero object into a JSM. [1] https://firefox-source-docs.mozilla.org/dom/ipc/jsactors.html
This commit is contained in:
parent
7f748b2620
commit
6a2949be8a
7 changed files with 275 additions and 54 deletions
39
test/tests/HiddenBrowserTest.js
Normal file
39
test/tests/HiddenBrowserTest.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
describe("HiddenBrowser", function() {
|
||||
const { HiddenBrowser } = ChromeUtils.import(
|
||||
"chrome://zotero/content/HiddenBrowser.jsm"
|
||||
);
|
||||
|
||||
describe("#getPageData()", function () {
|
||||
it("should handle local UTF-8 HTML file", async function () {
|
||||
var path = OS.Path.join(getTestDataDirectory().path, 'test-hidden.html');
|
||||
var browser = await HiddenBrowser.create(path);
|
||||
var { characterSet, bodyText } = await HiddenBrowser.getPageData(
|
||||
browser, ['characterSet', 'bodyText']
|
||||
);
|
||||
assert.equal(characterSet, 'UTF-8');
|
||||
// Should ignore hidden text
|
||||
assert.equal(bodyText, 'This is a test.');
|
||||
});
|
||||
|
||||
it("should handle local GBK HTML file", async function () {
|
||||
var path = OS.Path.join(getTestDataDirectory().path, 'charsets', 'gbk.html');
|
||||
var browser = await HiddenBrowser.create(path);
|
||||
var { characterSet, bodyText } = await HiddenBrowser.getPageData(
|
||||
browser, ['characterSet', 'bodyText']
|
||||
);
|
||||
assert.equal(characterSet, 'GBK');
|
||||
assert.equal(bodyText, '主体');
|
||||
});
|
||||
|
||||
it("should handle local GBK text file", async function () {
|
||||
var path = OS.Path.join(getTestDataDirectory().path, 'charsets', 'gbk.txt');
|
||||
var browser = await HiddenBrowser.create(path);
|
||||
var { characterSet, bodyText } = await HiddenBrowser.getPageData(
|
||||
browser, ['characterSet', 'bodyText']
|
||||
);
|
||||
HiddenBrowser.destroy(browser);
|
||||
assert.equal(characterSet, 'GBK');
|
||||
assert.equal(bodyText, '这是一个测试文件。');
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue