Commit 7f289a57 authored by Erik Nordin's avatar Erik Nordin Committed by enordin@mozilla.com
Browse files

Bug 1820252 - Rework assertPageIsTranslated r=translations-reviewers,gregtatum

This patch reworks the way that we assert that the page
is translated in Full-Page Translations tests. In addition
to ensuring that the translated content matches the expectations,
each test now ensures that the TranslationsDocument has fulfilled
every translation request that we expect it to, as well as ensures
that the intersection-observed nodes within the TranslationsDocument
match what we expect, since nodes are no longer observed once they
are fully translated (until they are mutated).

These changes give us extremely strong correctness guarantees in
terms of assurance that the TranslationsDocument algorithms are
working as intended, and maintaining their invariants in all cases.

Differential Revision: https://phabricator.services.mozilla.com/D249987
parent 913de3ae
Loading
Loading
Loading
Loading
+4 −2
Changes for browser/components/translations/tests/browser/browser_translations_e2e_full_page_translate_with_lexical_shortlist.js: 4 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -31,12 +31,14 @@ add_task(
    });

    await FullPageTranslationsTestUtils.clickTranslateButton();
    await FullPageTranslationsTestUtils.assertPageIsTranslated({
    await FullPageTranslationsTestUtils.assertOnlyIntersectingContentIsTranslated(
      {
        endToEndTest: true,
        fromLanguage: "es",
        toLanguage: "en",
        runInPage,
    });
      }
    );

    await cleanup();
  }
+4 −2
Changes for browser/components/translations/tests/browser/browser_translations_e2e_full_page_translate_without_lexical_shortlist.js: 4 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -31,12 +31,14 @@ add_task(
    });

    await FullPageTranslationsTestUtils.clickTranslateButton();
    await FullPageTranslationsTestUtils.assertPageIsTranslated({
    await FullPageTranslationsTestUtils.assertOnlyIntersectingContentIsTranslated(
      {
        endToEndTest: true,
        fromLanguage: "es",
        toLanguage: "en",
        runInPage,
    });
      }
    );

    await cleanup();
  }
+2 −1
Changes for browser/components/translations/tests/browser/browser_translations_full_page_language_id_behavior.js: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -188,6 +188,7 @@ add_task(async function test_language_identification_behavior() {
      page,
      languagePairs: LANGUAGE_PAIRS,
      autoDownloadFromRemoteSettings: true,
      contentEagerMode: true,
      prefs: [
        [
          "browser.translations.alwaysTranslateLanguages",
@@ -232,7 +233,7 @@ add_task(async function test_language_identification_behavior() {
    }

    if (translatePage) {
      await FullPageTranslationsTestUtils.assertPageIsTranslated({
      await FullPageTranslationsTestUtils.assertAllPageContentIsTranslated({
        fromLanguage: translatePage,
        toLanguage: "en",
        runInPage,
+5 −3
Changes for browser/components/translations/tests/browser/browser_translations_full_page_moz_extension.js: 5 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -14,10 +14,12 @@ add_task(async function test_translations_moz_extension() {
    files: {
      "test_page.html": `<!DOCTYPE html>
        <html lang="es">
          <head>
            <meta charset="UTF-8">
          </head>
          <body>
            <div>
            <h1>Don Quijote de La Mancha</h1>
            </div>
            <p>— Pues, aunque mováis más brazos que los del gigante Briareo, me lo habéis de pagar.</p>
          </body>
        </html>`,
    },
@@ -50,7 +52,7 @@ add_task(async function test_translations_moz_extension() {
    downloadHandler: resolveDownloads,
  });

  await FullPageTranslationsTestUtils.assertPageIsTranslated({
  await FullPageTranslationsTestUtils.assertAllPageContentIsTranslated({
    fromLanguage: "es",
    toLanguage: "en",
    runInPage,
+8 −4
Changes for browser/components/translations/tests/browser/browser_translations_full_page_multiple_windows.js: 8 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -34,13 +34,15 @@ add_task(async function test_browser_translations_full_page_multiple_windows() {
  await FullPageTranslationsTestUtils.clickTranslateButton({
    downloadHandler: testPage1.resolveDownloads,
  });
  await FullPageTranslationsTestUtils.assertPageIsTranslated({
  await FullPageTranslationsTestUtils.assertOnlyIntersectingContentIsTranslated(
    {
      fromLanguage: "es",
      toLanguage: "en",
      runInPage: testPage1.runInPage,
      message: "Window 1 gets translated",
      win: window1,
  });
    }
  );

  await focusWindow(window2);

@@ -51,13 +53,15 @@ add_task(async function test_browser_translations_full_page_multiple_windows() {
    expectedToLanguage: "en",
  });
  await FullPageTranslationsTestUtils.clickTranslateButton({ win: window2 });
  await FullPageTranslationsTestUtils.assertPageIsTranslated({
  await FullPageTranslationsTestUtils.assertOnlyIntersectingContentIsTranslated(
    {
      fromLanguage: "es",
      toLanguage: "en",
      runInPage: testPage2.runInPage,
      message: "Window 2 gets translated",
      win: window2,
  });
    }
  );

  await testPage2.cleanup();
  await BrowserTestUtils.closeWindow(window2);
Loading