Bug 1610298 - Snippets preview messages don't belong to a provider r=k88hudson

Differential Revision: https://phabricator.services.mozilla.com/D60414

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrei Oprea 2020-02-03 13:43:52 +00:00
Родитель 3006334585
Коммит 2736c686b6
5 изменённых файлов: 88 добавлений и 0 удалений

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

@ -709,6 +709,10 @@ class _ASRouter {
* @returns bool
*/
isExcludedByProvider(message) {
// preview snippets are never excluded
if (message.provider === "preview") {
return false;
}
const provider = this.state.providers.find(p => p.id === message.provider);
if (!provider) {
return true;

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

@ -3,6 +3,7 @@ support-files =
blue_page.html
red_page.html
head.js
snippet.json
prefs =
browser.newtabpage.activity-stream.debug=false
browser.newtabpage.activity-stream.discoverystream.enabled=true

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

@ -64,3 +64,39 @@ test_newtab({
);
},
});
add_task(async () => {
ASRouter._validPreviewEndpoint = () => true;
await BrowserTestUtils.withNewTab(
{
gBrowser,
url:
"about:newtab?endpoint=https://example.com/browser/browser/components/newtab/test/browser/snippet.json",
},
async browser => {
let text = await SpecialPowers.spawn(browser, [], async () => {
await ContentTaskUtils.waitForCondition(
() => content.document.querySelector(".activity-stream"),
`Should render Activity Stream`
);
await ContentTaskUtils.waitForCondition(
() =>
content.document.querySelector(
"#footer-asrouter-container .SimpleSnippet"
),
"Should find the snippet inside the footer container"
);
return content.document.querySelector(
"#footer-asrouter-container .SimpleSnippet"
).innerText;
});
Assert.equal(
text,
"On January 30th Nightly will introduce dedicated profiles, making it simpler to run different installations of Firefox side by side. Learn what this means for you.",
"Snippet content match"
);
}
);
});

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

@ -0,0 +1,25 @@
{
"messages": [
{
"weight": 50,
"id": "10533",
"template": "simple_snippet",
"template_version": "1.0.0",
"content": {
"icon": "",
"text": "On January 30th Nightly will introduce dedicated profiles, making it simpler to run different installations of Firefox side by side. <link0> Learn what this means for you</link0>.",
"tall": false,
"do_not_autoblock": false,
"links": {
"link0": {
"url": "https://support.mozilla.org/kb/dedicated-profiles-firefox-installation/?utm_source=desktop-snippet&utm_medium=snippet&utm_campaign=nightly_profile_management&utm_term=10533&utm_content=nightly"
}
}
},
"campaign": "nightly-profile-management",
"targeting": "true",
"provider_url": "https://snippets.cdn.mozilla.net/6/Firefox/66.0a1/20190122215349/Darwin_x86_64-gcc3/en-US/default/Darwin%2018.0.0/default/default/",
"provider": "snippets"
}
]
}

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

@ -50,6 +50,7 @@ function fakeExecuteUserAction(action) {
return fakeAsyncMessage({ data: action, type: "USER_ACTION" });
}
// eslint-disable-next-line max-statements
describe("ASRouter", () => {
let Router;
let globals;
@ -4038,4 +4039,25 @@ describe("ASRouter", () => {
});
});
});
describe("#loadMessagesForProvider", () => {
it("should fetch json from url", async () => {
let result = await MessageLoaderUtils.loadMessagesForProvider({
location: "http://fake.com/endpoint",
type: "json",
});
assert.property(result, "messages");
assert.lengthOf(result.messages, FAKE_REMOTE_MESSAGES.length);
});
it("should catch errors", async () => {
fetchStub.throws();
let result = await MessageLoaderUtils.loadMessagesForProvider({
location: "http://fake.com/endpoint",
type: "json",
});
assert.property(result, "messages");
assert.lengthOf(result.messages, 0);
});
});
});