summaryrefslogtreecommitdiffstats
path: root/browser/components/asrouter/tests/unit/content-src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
commitd8bbc7858622b6d9c278469aab701ca0b609cddf (patch)
treeeff41dc61d9f714852212739e6b3738b82a2af87 /browser/components/asrouter/tests/unit/content-src
parentReleasing progress-linux version 125.0.3-1~progress7.99u1. (diff)
downloadfirefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.tar.xz
firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.zip
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/asrouter/tests/unit/content-src')
-rw-r--r--browser/components/asrouter/tests/unit/content-src/components/ASRouterAdmin.test.jsx44
1 files changed, 43 insertions, 1 deletions
diff --git a/browser/components/asrouter/tests/unit/content-src/components/ASRouterAdmin.test.jsx b/browser/components/asrouter/tests/unit/content-src/components/ASRouterAdmin.test.jsx
index 46d5704107..c5b0d09b39 100644
--- a/browser/components/asrouter/tests/unit/content-src/components/ASRouterAdmin.test.jsx
+++ b/browser/components/asrouter/tests/unit/content-src/components/ASRouterAdmin.test.jsx
@@ -1,4 +1,7 @@
-import { ASRouterAdminInner } from "content-src/components/ASRouterAdmin/ASRouterAdmin";
+import {
+ ASRouterAdminInner,
+ toBinary,
+} from "content-src/components/ASRouterAdmin/ASRouterAdmin";
import { ASRouterUtils } from "content-src/asrouter-utils";
import { GlobalOverrider } from "test/unit/utils";
import React from "react";
@@ -259,4 +262,43 @@ describe("ASRouterAdmin", () => {
});
});
});
+ describe("toBinary", () => {
+ // Bringing the 'fromBinary' function over from
+ // messagepreview to prove it works
+ function fromBinary(encoded) {
+ const binary = atob(decodeURIComponent(encoded));
+ const bytes = new Uint8Array(binary.length);
+ for (let i = 0; i < bytes.length; i++) {
+ bytes[i] = binary.charCodeAt(i);
+ }
+ return String.fromCharCode(...new Uint16Array(bytes.buffer));
+ }
+
+ it("correctly encodes a latin string", () => {
+ const testString = "Hi I am a test string";
+ const expectedResult =
+ "SABpACAASQAgAGEAbQAgAGEAIAB0AGUAcwB0ACAAcwB0AHIAaQBuAGcA";
+
+ const encodedResult = toBinary(testString);
+
+ assert.equal(encodedResult, expectedResult);
+
+ const decodedResult = fromBinary(encodedResult);
+
+ assert.equal(decodedResult, testString);
+ });
+
+ it("correctly encodes a non-latin string", () => {
+ const nonLatinString = "тестовое сообщение";
+ const expectedResult = "QgQ1BEEEQgQ+BDIEPgQ1BCAAQQQ+BD4EMQRJBDUEPQQ4BDUE";
+
+ const encodedResult = toBinary("тестовое сообщение");
+
+ assert.equal(encodedResult, expectedResult);
+
+ const decodedResult = fromBinary(encodedResult);
+
+ assert.equal(decodedResult, nonLatinString);
+ });
+ });
});