Bug 1391934 - stop using sdk/clipboard in devtools tests;r=gl

MozReview-Commit-ID: 9UB3nIeaI5g

--HG--
extra : rebase_source : 93ee894bff5540cdcd7981594face449271d8bb4
This commit is contained in:
Julian Descottes 2017-08-19 11:25:29 +02:00
Родитель 1ca83fd296
Коммит 368c87be52
4 изменённых файлов: 63 добавлений и 30 удалений

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

@ -12,7 +12,7 @@ Services.scriptloader.loadSubScript(
this);
var {getInplaceEditorForSpan: inplaceEditor} = require("devtools/client/shared/inplace-editor");
var clipboard = require("sdk/clipboard");
var clipboard = require("devtools/shared/platform/clipboard");
var {ActorRegistryFront} = require("devtools/shared/fronts/actor-registry");
// If a test times out we want to see the complete log and not just the last few
@ -297,7 +297,7 @@ function searchUsingSelectorSearch(selector, inspector) {
var isEditingMenuDisabled = Task.async(
function* (nodeFront, inspector, assert = true) {
// To ensure clipboard contains something to paste.
clipboard.set("<p>test</p>", "html");
clipboard.copyString("<p>test</p>");
yield selectNode(nodeFront, inspector);
let allMenuItems = openContextMenuAndGetAllItems(inspector);
@ -329,7 +329,7 @@ function* (nodeFront, inspector, assert = true) {
var isEditingMenuEnabled = Task.async(
function* (nodeFront, inspector, assert = true) {
// To ensure clipboard contains something to paste.
clipboard.set("<p>test</p>", "html");
clipboard.copyString("<p>test</p>");
yield selectNode(nodeFront, inspector);
let allMenuItems = openContextMenuAndGetAllItems(inspector);

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

@ -62,14 +62,14 @@ const TEST_CASES = [
{
desc: "doctype node with html on clipboard",
clipboardData: "<p>some text</p>",
clipboardDataType: "html",
clipboardDataType: "text",
selector: null,
disabled: INACTIVE_ON_DOCTYPE_ITEMS,
},
{
desc: "element node HTML on the clipboard",
clipboardData: "<p>some text</p>",
clipboardDataType: "html",
clipboardDataType: "text",
disabled: [
"node-menu-copyimagedatauri",
"node-menu-copy-attribute",
@ -81,7 +81,7 @@ const TEST_CASES = [
{
desc: "<html> element",
clipboardData: "<p>some text</p>",
clipboardDataType: "html",
clipboardDataType: "text",
selector: "html",
disabled: [
"node-menu-copyimagedatauri",
@ -97,7 +97,7 @@ const TEST_CASES = [
{
desc: "<body> with HTML on clipboard",
clipboardData: "<p>some text</p>",
clipboardDataType: "html",
clipboardDataType: "text",
selector: "body",
disabled: [
"node-menu-copyimagedatauri",
@ -111,7 +111,7 @@ const TEST_CASES = [
{
desc: "<img> with HTML on clipboard",
clipboardData: "<p>some text</p>",
clipboardDataType: "html",
clipboardDataType: "text",
selector: "img",
disabled: [
"node-menu-copy-attribute",
@ -122,7 +122,7 @@ const TEST_CASES = [
{
desc: "<head> with HTML on clipboard",
clipboardData: "<p>some text</p>",
clipboardDataType: "html",
clipboardDataType: "text",
selector: "head",
disabled: [
"node-menu-copyimagedatauri",
@ -148,7 +148,7 @@ const TEST_CASES = [
{
desc: "<element> with text on clipboard",
clipboardData: "some text",
clipboardDataType: undefined,
clipboardDataType: "text",
selector: "#paste-area",
disabled: [
"node-menu-copyimagedatauri",
@ -160,9 +160,9 @@ const TEST_CASES = [
{
desc: "<element> with base64 encoded image data uri on clipboard",
clipboardData:
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABC" +
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABC" +
"AAAAAA6fptVAAAACklEQVQYV2P4DwABAQEAWk1v8QAAAABJRU5ErkJggg==",
clipboardDataType: undefined,
clipboardDataType: "image",
selector: "#paste-area",
disabled: PASTE_MENU_ITEMS.concat([
"node-menu-copyimagedatauri",
@ -174,7 +174,7 @@ const TEST_CASES = [
{
desc: "<element> with empty string on clipboard",
clipboardData: "",
clipboardDataType: undefined,
clipboardDataType: "text",
selector: "#paste-area",
disabled: PASTE_MENU_ITEMS.concat([
"node-menu-copyimagedatauri",
@ -186,7 +186,7 @@ const TEST_CASES = [
{
desc: "<element> with whitespace only on clipboard",
clipboardData: " \n\n\t\n\n \n",
clipboardDataType: undefined,
clipboardDataType: "text",
selector: "#paste-area",
disabled: PASTE_MENU_ITEMS.concat([
"node-menu-copyimagedatauri",
@ -225,8 +225,9 @@ const TEST_CASES = [
}
];
var clipboard = require("sdk/clipboard");
var clipboard = require("devtools/shared/platform/clipboard");
registerCleanupFunction(() => {
clipboard.copyString("");
clipboard = null;
});
@ -258,7 +259,7 @@ add_task(function* () {
let menuItem = allMenuItems.find(item => item.id === id);
let shouldBeDisabled = disabled.indexOf(id) !== -1;
is(menuItem.disabled, shouldBeDisabled,
`#${id} should be ${shouldBeDisabled ? "disabled" : "enabled"} `);
`#${id} should be ${shouldBeDisabled ? "disabled" : "enabled"}`);
}
}
});
@ -283,11 +284,43 @@ function* getNodeFrontForSelector(selector, inspector) {
* clipboard if data is falsy.
*/
function setupClipboard(data, type) {
if (data) {
info("Populating clipboard with " + type + " data.");
clipboard.set(data, type);
} else {
info("Clearing clipboard.");
clipboard.set("", "text");
if (!data) {
info("Clearing the clipboard.");
clipboard.copyString("");
} else if (type === "text") {
info("Populating clipboard with text.");
clipboard.copyString(data);
} else if (type === "image") {
info("Populating clipboard with image content");
copyImageToClipboard(data);
}
}
/**
* The code below is a simplified version of the sdk/clipboard helper set() method.
*/
function copyImageToClipboard(data) {
let clipboardService = Cc["@mozilla.org/widget/clipboard;1"]
.getService(Ci.nsIClipboard);
let imageTools = Cc["@mozilla.org/image/tools;1"]
.getService(Ci.imgITools);
// Image data is stored as base64 in the test.
let image = atob(data);
let input = Cc["@mozilla.org/io/string-input-stream;1"]
.createInstance(Ci.nsIStringInputStream);
input.setData(image, image.length);
let imgPtr = Cc["@mozilla.org/supports-interface-pointer;1"]
.createInstance(Ci.nsISupportsInterfacePointer);
imgPtr.data = imageTools.decodeImage(input, "image/png");
let xferable = Cc["@mozilla.org/widget/transferable;1"]
.createInstance(Ci.nsITransferable);
xferable.init(null);
xferable.addDataFlavor("image/png");
xferable.setTransferData("image/png", imgPtr, -1);
clipboardService.setData(xferable, null, clipboardService.kGlobalClipboard);
}

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

@ -10,7 +10,7 @@ const PASTE_AS_FIRST_CHILD = '<circle xmlns="http://www.w3.org/2000/svg" cx="42"
const PASTE_AS_LAST_CHILD = '<circle xmlns="http://www.w3.org/2000/svg" cx="42" cy="42" r="15"/>';
add_task(function* () {
let clipboard = require("sdk/clipboard");
let clipboard = require("devtools/shared/platform/clipboard");
let { inspector, testActor } = yield openInspectorForURL(TEST_URL);
@ -32,7 +32,7 @@ add_task(function* () {
target: markupTagLine,
});
info(`Testing ${menuId} for ${clipboardData}`);
clipboard.set(clipboardData);
clipboard.copyString(clipboardData);
let onMutation = inspector.once("markupmutation");
allMenuItems.find(item => item.id === menuId).click();

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

@ -29,7 +29,7 @@ const PASTE_ADJACENT_HTML_DATA = [
},
];
var clipboard = require("sdk/clipboard");
var clipboard = require("devtools/shared/platform/clipboard");
registerCleanupFunction(() => {
clipboard = null;
});
@ -43,7 +43,7 @@ add_task(function* () {
function* testPasteOuterHTMLMenu() {
info("Testing that 'Paste Outer HTML' menu item works.");
clipboard.set("this was pasted (outerHTML)");
clipboard.copyString("this was pasted (outerHTML)");
let outerHTMLSelector = "#paste-area h1";
let nodeFront = yield getNodeFront(outerHTMLSelector, inspector);
@ -60,7 +60,7 @@ add_task(function* () {
yield onNodeReselected;
let outerHTML = yield testActor.getProperty("body", "outerHTML");
ok(outerHTML.includes(clipboard.get()),
ok(outerHTML.includes(clipboard.getText()),
"Clipboard content was pasted into the node's outer HTML.");
ok(!(yield testActor.hasNode(outerHTMLSelector)),
"The original node was removed.");
@ -68,7 +68,7 @@ add_task(function* () {
function* testPasteInnerHTMLMenu() {
info("Testing that 'Paste Inner HTML' menu item works.");
clipboard.set("this was pasted (innerHTML)");
clipboard.copyString("this was pasted (innerHTML)");
let innerHTMLSelector = "#paste-area .inner";
let getInnerHTML = () => testActor.getProperty(innerHTMLSelector,
"innerHTML");
@ -86,7 +86,7 @@ add_task(function* () {
info("Waiting for mutation to occur");
yield onMutation;
ok((yield getInnerHTML()) === clipboard.get(),
ok((yield getInnerHTML()) === clipboard.getText(),
"Clipboard content was pasted into the node's inner HTML.");
ok((yield testActor.hasNode(innerHTMLSelector)),
"The original node has been preserved.");
@ -107,7 +107,7 @@ add_task(function* () {
target: markupTagLine,
});
info(`Testing ${menuId} for ${clipboardData}`);
clipboard.set(clipboardData);
clipboard.copyString(clipboardData);
let onMutation = inspector.once("markupmutation");
allMenuItems.find(item => item.id === menuId).click();