зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1723145 - Replace OS.File with IOUtils in marionette, r=Gijs,webdriver-reviewers,whimboo
Differential Revision: https://phabricator.services.mozilla.com/D121407
This commit is contained in:
Родитель
37016a9847
Коммит
764259e4af
|
@ -11,7 +11,6 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
OS: "resource://gre/modules/osfile.jsm",
|
||||
Services: "resource://gre/modules/Services.jsm",
|
||||
|
||||
Addon: "chrome://remote/content/marionette/addon.js",
|
||||
|
@ -2906,12 +2905,10 @@ GeckoDriver.prototype.print = async function(cmd) {
|
|||
|
||||
// return all data as a base64 encoded string
|
||||
let bytes;
|
||||
const file = await OS.File.open(filePath);
|
||||
try {
|
||||
bytes = await file.read();
|
||||
bytes = await IOUtils.read(filePath);
|
||||
} finally {
|
||||
file.close();
|
||||
await OS.File.remove(filePath);
|
||||
await IOUtils.remove(filePath);
|
||||
}
|
||||
|
||||
// Each UCS2 character has an upper byte of 0 and a lower byte matching
|
||||
|
|
|
@ -12,7 +12,6 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
clearInterval: "resource://gre/modules/Timer.jsm",
|
||||
OS: "resource://gre/modules/osfile.jsm",
|
||||
setInterval: "resource://gre/modules/Timer.jsm",
|
||||
|
||||
Log: "chrome://remote/content/shared/Log.jsm",
|
||||
|
@ -100,9 +99,9 @@ function getPrintSettings(settings, filePath) {
|
|||
|
||||
print.printToFile = async function(browser, settings) {
|
||||
// Create a unique filename for the temporary PDF file
|
||||
const basePath = OS.Path.join(OS.Constants.Path.tmpDir, "marionette.pdf");
|
||||
const { file, path: filePath } = await OS.File.openUnique(basePath);
|
||||
await file.close();
|
||||
const tempDir = await PathUtils.getTempDir();
|
||||
const basePath = PathUtils.join(tempDir, "marionette.pdf");
|
||||
const filePath = await PathUtils.createUniquePath(basePath);
|
||||
|
||||
let printSettings = getPrintSettings(settings, filePath);
|
||||
|
||||
|
@ -115,7 +114,7 @@ print.printToFile = async function(browser, settings) {
|
|||
|
||||
let lastSize = 0;
|
||||
const timerId = setInterval(async () => {
|
||||
const fileInfo = await OS.File.stat(filePath);
|
||||
const fileInfo = await IOUtils.stat(filePath);
|
||||
if (lastSize > 0 && fileInfo.size == lastSize) {
|
||||
clearInterval(timerId);
|
||||
resolve();
|
||||
|
|
|
@ -13,7 +13,6 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
E10SUtils: "resource://gre/modules/E10SUtils.jsm",
|
||||
OS: "resource://gre/modules/osfile.jsm",
|
||||
|
||||
AppInfo: "chrome://remote/content/marionette/appinfo.js",
|
||||
assert: "chrome://remote/content/shared/webdriver/Assert.jsm",
|
||||
|
@ -785,14 +784,12 @@ browserRect.height: ${browserRect.height}`);
|
|||
|
||||
const filePath = await print.printToFile(win.gBrowser, settings);
|
||||
|
||||
const fp = await OS.File.open(filePath, { read: true });
|
||||
try {
|
||||
const pdf = await this.loadPdf(url, fp);
|
||||
const pdf = await this.loadPdf(url, filePath);
|
||||
let pages = this.getPages(pageRanges, url, pdf.numPages);
|
||||
return [this.renderPages(pdf, pages), pages.size];
|
||||
} finally {
|
||||
fp.close();
|
||||
await OS.File.remove(filePath);
|
||||
await IOUtils.remove(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -810,8 +807,8 @@ browserRect.height: ${browserRect.height}`);
|
|||
"resource://pdf.js/build/pdf.worker.js";
|
||||
}
|
||||
|
||||
async loadPdf(url, fp) {
|
||||
const data = await fp.read();
|
||||
async loadPdf(url, filePath) {
|
||||
const data = await IOUtils.read(filePath);
|
||||
return this.parentWindow.pdfjsLib.getDocument({ data }).promise;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче