зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1797612 - Newtab prevent sponsored topsites from being dragged r=nanj
Differential Revision: https://phabricator.services.mozilla.com/D161000
This commit is contained in:
Родитель
fb091ef338
Коммит
624091d13e
|
@ -37,7 +37,8 @@ export class TopSiteLink extends React.PureComponent {
|
|||
*/
|
||||
_allowDrop(e) {
|
||||
return (
|
||||
(this.dragged || !this.props.link.sponsored_position) &&
|
||||
(this.dragged ||
|
||||
(!this.props.link.sponsored_position && !this.props.link.shim)) &&
|
||||
e.dataTransfer.types.includes("text/topsite-index")
|
||||
);
|
||||
}
|
||||
|
@ -52,7 +53,7 @@ export class TopSiteLink extends React.PureComponent {
|
|||
break;
|
||||
case "dragstart":
|
||||
event.target.blur();
|
||||
if (this.props.link.sponsored_position) {
|
||||
if (this.props.link.sponsored_position || this.props.link.shim) {
|
||||
event.preventDefault();
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -11632,7 +11632,7 @@ class TopSiteLink extends (external_React_default()).PureComponent {
|
|||
|
||||
|
||||
_allowDrop(e) {
|
||||
return (this.dragged || !this.props.link.sponsored_position) && e.dataTransfer.types.includes("text/topsite-index");
|
||||
return (this.dragged || !this.props.link.sponsored_position && !this.props.link.shim) && e.dataTransfer.types.includes("text/topsite-index");
|
||||
}
|
||||
|
||||
onDragEvent(event) {
|
||||
|
@ -11648,7 +11648,7 @@ class TopSiteLink extends (external_React_default()).PureComponent {
|
|||
case "dragstart":
|
||||
event.target.blur();
|
||||
|
||||
if (this.props.link.sponsored_position) {
|
||||
if (this.props.link.sponsored_position || this.props.link.shim) {
|
||||
event.preventDefault();
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -469,6 +469,34 @@ describe("<TopSiteLink>", () => {
|
|||
const wrapper = shallow(<TopSiteLink className="foo bar" />);
|
||||
assert.ok(wrapper.find("li").hasClass("top-site-outer foo bar"));
|
||||
});
|
||||
describe("#_allowDrop", () => {
|
||||
let wrapper;
|
||||
let event;
|
||||
beforeEach(() => {
|
||||
event = {
|
||||
dataTransfer: {
|
||||
types: ["text/topsite-index"],
|
||||
},
|
||||
};
|
||||
wrapper = shallow(
|
||||
<TopSiteLink isDraggable={true} onDragEvent={() => {}} />
|
||||
);
|
||||
});
|
||||
it("should be droppable for basic case", () => {
|
||||
const result = wrapper.instance()._allowDrop(event);
|
||||
assert.isTrue(result);
|
||||
});
|
||||
it("should not be droppable for sponsored_position", () => {
|
||||
wrapper.setProps({ link: { sponsored_position: 1 } });
|
||||
const result = wrapper.instance()._allowDrop(event);
|
||||
assert.isFalse(result);
|
||||
});
|
||||
it("should not be droppable for link.shim", () => {
|
||||
wrapper.setProps({ link: { shim: "foo" } });
|
||||
const result = wrapper.instance()._allowDrop(event);
|
||||
assert.isFalse(result);
|
||||
});
|
||||
});
|
||||
describe("#onDragEvent", () => {
|
||||
let simulate;
|
||||
let wrapper;
|
||||
|
@ -525,6 +553,32 @@ describe("<TopSiteLink>", () => {
|
|||
|
||||
assert.notOk(event.prevented);
|
||||
});
|
||||
it("should prevent dragging with sponsored_position from dragstart", () => {
|
||||
const preventDefault = sinon.stub();
|
||||
const blur = sinon.stub();
|
||||
wrapper.setProps({ link: { sponsored_position: 1 } });
|
||||
wrapper.instance().onDragEvent({
|
||||
type: "dragstart",
|
||||
preventDefault,
|
||||
target: { blur },
|
||||
});
|
||||
assert.calledOnce(preventDefault);
|
||||
assert.calledOnce(blur);
|
||||
assert.isUndefined(wrapper.instance().dragged);
|
||||
});
|
||||
it("should prevent dragging with link.shim from dragstart", () => {
|
||||
const preventDefault = sinon.stub();
|
||||
const blur = sinon.stub();
|
||||
wrapper.setProps({ link: { shim: "foo" } });
|
||||
wrapper.instance().onDragEvent({
|
||||
type: "dragstart",
|
||||
preventDefault,
|
||||
target: { blur },
|
||||
});
|
||||
assert.calledOnce(preventDefault);
|
||||
assert.calledOnce(blur);
|
||||
assert.isUndefined(wrapper.instance().dragged);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#generateColor", () => {
|
||||
|
|
Загрузка…
Ссылка в новой задаче