From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../newtab/test/unit/lib/TippyTopProvider.test.js | 121 +++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 browser/components/newtab/test/unit/lib/TippyTopProvider.test.js (limited to 'browser/components/newtab/test/unit/lib/TippyTopProvider.test.js') diff --git a/browser/components/newtab/test/unit/lib/TippyTopProvider.test.js b/browser/components/newtab/test/unit/lib/TippyTopProvider.test.js new file mode 100644 index 0000000000..661a6b7b83 --- /dev/null +++ b/browser/components/newtab/test/unit/lib/TippyTopProvider.test.js @@ -0,0 +1,121 @@ +import { GlobalOverrider } from "test/unit/utils"; +import { TippyTopProvider } from "lib/TippyTopProvider.sys.mjs"; + +describe("TippyTopProvider", () => { + let instance; + let globals; + beforeEach(async () => { + globals = new GlobalOverrider(); + let fetchStub = globals.sandbox.stub(); + globals.set("fetch", fetchStub); + fetchStub.resolves({ + ok: true, + status: 200, + json: () => + Promise.resolve([ + { + domains: ["facebook.com"], + image_url: "images/facebook-com.png", + favicon_url: "images/facebook-com.png", + background_color: "#3b5998", + }, + { + domains: ["gmail.com", "mail.google.com"], + image_url: "images/gmail-com.png", + favicon_url: "images/gmail-com.png", + background_color: "#000000", + }, + ]), + }); + instance = new TippyTopProvider(); + await instance.init(); + }); + it("should provide an icon for facebook.com", () => { + const site = instance.processSite({ url: "https://facebook.com" }); + assert.equal( + site.tippyTopIcon, + "chrome://activity-stream/content/data/content/tippytop/images/facebook-com.png" + ); + assert.equal( + site.smallFavicon, + "chrome://activity-stream/content/data/content/tippytop/images/facebook-com.png" + ); + assert.equal(site.backgroundColor, "#3b5998"); + }); + it("should provide an icon for www.facebook.com", () => { + const site = instance.processSite({ url: "https://www.facebook.com" }); + assert.equal( + site.tippyTopIcon, + "chrome://activity-stream/content/data/content/tippytop/images/facebook-com.png" + ); + assert.equal( + site.smallFavicon, + "chrome://activity-stream/content/data/content/tippytop/images/facebook-com.png" + ); + assert.equal(site.backgroundColor, "#3b5998"); + }); + it("should not provide an icon for other.facebook.com", () => { + const site = instance.processSite({ url: "https://other.facebook.com" }); + assert.isUndefined(site.tippyTopIcon); + }); + it("should provide an icon for other.facebook.com with stripping", () => { + const site = instance.processSite( + { url: "https://other.facebook.com" }, + "*" + ); + assert.equal( + site.tippyTopIcon, + "chrome://activity-stream/content/data/content/tippytop/images/facebook-com.png" + ); + }); + it("should provide an icon for facebook.com/foobar", () => { + const site = instance.processSite({ url: "https://facebook.com/foobar" }); + assert.equal( + site.tippyTopIcon, + "chrome://activity-stream/content/data/content/tippytop/images/facebook-com.png" + ); + assert.equal( + site.smallFavicon, + "chrome://activity-stream/content/data/content/tippytop/images/facebook-com.png" + ); + assert.equal(site.backgroundColor, "#3b5998"); + }); + it("should provide an icon for gmail.com", () => { + const site = instance.processSite({ url: "https://gmail.com" }); + assert.equal( + site.tippyTopIcon, + "chrome://activity-stream/content/data/content/tippytop/images/gmail-com.png" + ); + assert.equal( + site.smallFavicon, + "chrome://activity-stream/content/data/content/tippytop/images/gmail-com.png" + ); + assert.equal(site.backgroundColor, "#000000"); + }); + it("should provide an icon for mail.google.com", () => { + const site = instance.processSite({ url: "https://mail.google.com" }); + assert.equal( + site.tippyTopIcon, + "chrome://activity-stream/content/data/content/tippytop/images/gmail-com.png" + ); + assert.equal( + site.smallFavicon, + "chrome://activity-stream/content/data/content/tippytop/images/gmail-com.png" + ); + assert.equal(site.backgroundColor, "#000000"); + }); + it("should handle garbage URLs gracefully", () => { + const site = instance.processSite({ url: "garbagejlfkdsa" }); + assert.isUndefined(site.tippyTopIcon); + assert.isUndefined(site.backgroundColor); + }); + it("should handle error when fetching and parsing manifest", async () => { + globals = new GlobalOverrider(); + let fetchStub = globals.sandbox.stub(); + globals.set("fetch", fetchStub); + fetchStub.rejects("whaaaa"); + instance = new TippyTopProvider(); + await instance.init(); + instance.processSite({ url: "https://facebook.com" }); + }); +}); -- cgit v1.2.3