Commit e089450a authored by OPNA2608's avatar OPNA2608
Browse files

lomiri.morph-browser: Modernise, help with test timeout, add doc output

parent 3d9f7807
Loading
Loading
Loading
Loading
+196 −0
Original line number Diff line number Diff line
From 9c4cd4fa938244cc2e319555d372e4e32029964a Mon Sep 17 00:00:00 2001
From: OPNA2608 <opna2608@protonmail.com>
Date: Tue, 14 Jan 2025 23:06:20 +0100
Subject: [PATCH] tests/unittests/qml/tst_AddressBar.qml: Replace wait +
 compare with tryCompare

---
 tests/unittests/qml/tst_AddressBar.qml | 75 +++++++++++---------------
 1 file changed, 30 insertions(+), 45 deletions(-)

diff --git a/tests/unittests/qml/tst_AddressBar.qml b/tests/unittests/qml/tst_AddressBar.qml
index 5c27acff..dc0ec4c6 100644
--- a/tests/unittests/qml/tst_AddressBar.qml
+++ b/tests/unittests/qml/tst_AddressBar.qml
@@ -73,6 +73,15 @@ Item {
         name: "AddressBar"
         when: windowShown
 
+        function verifyAddressBarText(text) {
+            tryCompare(addressBar, "text", text)
+        }
+
+        function typeStringAndVerify(text) {
+            typeString(text)
+            verifyAddressBarText(text)
+        }
+
         function init() {
             addressBar.actualUrl = ""
             validatedSpy.clear()
@@ -101,9 +110,7 @@ Item {
         }
 
         function test_validUrlShouldNotBeRewritten(data) {
-            typeString(data.url)
-            wait(500)
-            compare(addressBar.text, data.url)
+            typeStringAndVerify(data.url)
             keyClick(Qt.Key_Return)
             validatedSpy.wait()
             compare(addressBar.requestedUrl, data.url)
@@ -120,9 +127,7 @@ Item {
         }
 
         function test_urlWithoutSchemeShouldBeRewritten(data) {
-            typeString(data.text)
-            wait(500)
-            compare(addressBar.text, data.text)
+            typeStringAndVerify(data.text)
             keyClick(Qt.Key_Return)
             validatedSpy.wait()
             compare(addressBar.requestedUrl, data.requestedUrl)
@@ -137,9 +142,7 @@ Item {
         }
 
         function test_leadingAndTrailingWhitespacesShouldBeTrimmed(data) {
-            typeString(data.text)
-            wait(500)
-            compare(addressBar.text, data.text)
+            typeStringAndVerify(data.text)
             keyClick(Qt.Key_Return)
             validatedSpy.wait()
             compare(addressBar.requestedUrl, data.requestedUrl)
@@ -153,9 +156,7 @@ Item {
         }
 
         function test_searchQueryShouldBeRewritten(data) {
-            typeString(data.text)
-            wait(500)
-            compare(addressBar.text, data.text)
+            typeStringAndVerify(data.text)
             keyClick(Qt.Key_Return)
             validatedSpy.wait()
             compare(addressBar.requestedUrl.toString().indexOf(data.start), 0)
@@ -174,9 +175,7 @@ Item {
         }
 
         function test_htmlEntitiesShouldBeEscapedInSearchQueries(data) {
-            typeString(data.text)
-            wait(500)
-            compare(addressBar.text, data.text)
+            typeStringAndVerify(data.text)
             keyClick(Qt.Key_Return)
             validatedSpy.wait()
             verify(addressBar.requestedUrl.toString().indexOf("q=" + data.escaped) > 0)
@@ -191,9 +190,7 @@ Item {
         }
 
         function test_uppercaseDomainsShouldBeRewritten(data) {
-            typeString(data.text)
-            wait(500)
-            compare(addressBar.text, data.text)
+            typeStringAndVerify(data.text)
             keyClick(Qt.Key_Return)
             validatedSpy.wait()
             compare(addressBar.requestedUrl, data.requestedUrl)
@@ -213,9 +210,7 @@ Item {
         }
 
         function test_uppercaseSchemeShouldBeRewritten(data) {
-            typeString(data.text)
-            wait(500)
-            compare(addressBar.text, data.text)
+            typeStringAndVerify(data.text)
             keyClick(Qt.Key_Return)
             validatedSpy.wait()
             compare(addressBar.requestedUrl, data.requestedUrl)
@@ -266,9 +261,7 @@ Item {
         }
 
         function test_urlShouldBeSimplifiedWhenUnfocused(data) {
-            typeString(data.input)
-            wait(500)
-            compare(addressBar.text, data.input)
+            typeStringAndVerify(data.input)
             keyClick(Qt.Key_Return)
             validatedSpy.wait()
             addressBar.actualUrl = addressBar.requestedUrl
@@ -289,9 +282,7 @@ Item {
 
         function test_clickingWhenUnfocusedShouldSelectAll() {
             var url = "http://example.org/"
-            typeString(url)
-            wait(500)
-            compare(addressBar.text, url)
+            typeStringAndVerify(url)
             addressBar.actualUrl = url
             clickItem(textInput)
             verify(!addressBar.activeFocus)
@@ -301,9 +292,7 @@ Item {
 
         function test_clickingWhenFocusedShouldDeselectText() {
             var url = "http://example.org/"
-            typeString(url)
-            wait(500)
-            compare(addressBar.text, url)
+            typeStringAndVerify(url)
             addressBar.actualUrl = url
             clickItem(textInput)
             verify(!addressBar.activeFocus)
@@ -316,9 +305,7 @@ Item {
 
         function test_clickingActionButtonWhenUnfocusedShouldNotSelectAll() {
             var url = "http://example.org/"
-            typeString(url)
-            wait(500)
-            compare(addressBar.text, url)
+            typeStringAndVerify(url)
             clickItem(textInput)
             verify(!addressBar.activeFocus)
             clickItem(addressBar.__actionButton)
@@ -355,31 +342,29 @@ Item {
         }
 
         function test_unfocusingWhileEditingShouldResetUrl() {
-            var url = "http://example.org/"
-            typeString(url)
-            wait(500)
-            compare(addressBar.text, url)
+            var host = "example.org"
+            var url = "http://" + host + "/"
+            typeStringAndVerify(url)
             addressBar.actualUrl = url
             var clearButton = findChild(addressBar, "clear_button")
             verify(clearButton != null)
             clickItem(clearButton)
-            compare(addressBar.text, "")
+            verifyAddressBarText("")
             clickItem(textInput)
-            compare(addressBar.text, "example.org")
+            verifyAddressBarText(host)
             clickItem(addressBar)
-            compare(addressBar.text, url)
+            verifyAddressBarText(url)
         }
 
         function test_exitingFindInPageRestoresUrl() {
-            addressBar.actualUrl = "http://example.org/"
+            var host = "example.org"
+            addressBar.actualUrl = "http://" + host + "/"
             addressBar.findInPageMode = true
             verify(addressBar.activeFocus)
             compare(addressBar.text, "")
-            typeString("hello")
-            wait(500)
+            typeStringAndVerify("hello")
             addressBar.findInPageMode = false
-            wait(500)
-            compare(addressBar.text, "example.org")
+            verifyAddressBarText(host)
         }
     }
 }
-- 
2.47.0
+21 −9
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
  qtdeclarative,
  qtquickcontrols2,
  qtsystems,
  qttools,
  qtwebengine,
  wrapQtAppsHook,
  xvfb-run,
@@ -38,27 +39,38 @@ stdenv.mkDerivation (finalAttrs: {
    hash = "sha256-VxSADFTlaxQUDc81TzGkx54mjAUgY2L+suQC9zYGKo0=";
  };

  outputs = [
    "out"
    "doc"
  ];

  patches = [
    # Remove when https://gitlab.com/ubports/development/core/morph-browser/-/merge_requests/576 merged & in release
    # Remove when version > 1.1.1
    (fetchpatch {
      name = "0002-morph-browser-Call-i18n-bindtextdomain-with-buildtime-determined-locale-path.patch";
      url = "https://gitlab.com/ubports/development/core/morph-browser/-/commit/0527a1e01fb27c62f5e0011274f73bad400e9691.patch";
      url = "https://gitlab.com/ubports/development/core/morph-browser/-/commit/3d9777fdc7d5b302a9f17679e4ea125e94468772.patch";
      hash = "sha256-zx/pP72uNqAi8TZR4bKeONuqcJyK/vGtPglTA+5R5no=";
    })

    # Remove when https://gitlab.com/ubports/development/core/morph-browser/-/merge_requests/589 merged & in release
    ./1001-morph-browser-tst_AddressBar-Replace-wait-and-compare-with-tryCompare.patch
  ];

  postPatch =
    ''
      substituteInPlace src/{Morph,Ubuntu}/CMakeLists.txt \
        --replace '/usr/lib/''${CMAKE_LIBRARY_ARCHITECTURE}/qt5/qml' "\''${CMAKE_INSTALL_PREFIX}/${qtbase.qtQmlPrefix}"
        --replace-fail '/usr/lib/''${CMAKE_LIBRARY_ARCHITECTURE}/qt5/qml' "\''${CMAKE_INSTALL_PREFIX}/${qtbase.qtQmlPrefix}"

      substituteInPlace src/app/webbrowser/morph-browser.desktop.in.in \
        --replace 'Icon=@CMAKE_INSTALL_FULL_DATADIR@/morph-browser/morph-browser.svg' 'Icon=morph-browser' \
        --replace 'X-Lomiri-Splash-Image=@CMAKE_INSTALL_FULL_DATADIR@/morph-browser/morph-browser-splash.svg' 'X-Lomiri-Splash-Image=lomiri-app-launch/splash/morph-browser.svg'
        --replace-fail 'Icon=@CMAKE_INSTALL_FULL_DATADIR@/morph-browser/morph-browser.svg' 'Icon=morph-browser' \
        --replace-fail 'X-Lomiri-Splash-Image=@CMAKE_INSTALL_FULL_DATADIR@/morph-browser/morph-browser-splash.svg' 'X-Lomiri-Splash-Image=lomiri-app-launch/splash/morph-browser.svg'

      substituteInPlace doc/CMakeLists.txt \
        --replace-fail 'COMMAND ''${QDOC_EXECUTABLE} -qt5' 'COMMAND ''${QDOC_EXECUTABLE}'
    ''
    + lib.optionalString (!finalAttrs.finalPackage.doCheck) ''
      substituteInPlace CMakeLists.txt \
        --replace 'add_subdirectory(tests)' ""
        --replace-fail 'add_subdirectory(tests)' ""
    '';

  strictDeps = true;
@@ -67,6 +79,7 @@ stdenv.mkDerivation (finalAttrs: {
    cmake
    gettext
    pkg-config
    qttools # qdoc
    wrapQtAppsHook
  ];

@@ -138,9 +151,8 @@ stdenv.mkDerivation (finalAttrs: {
      # Test of morph-browser itself
      standalone = nixosTests.morph-browser;

      # Lomiri-specific issues with the desktop file may break the entire session, make sure it still works
      lomiri-basics = nixosTests.lomiri.desktop-basics;
      lomiri-appinteractions = nixosTests.lomiri.desktop-appinteractions;
      # Interactions between the Lomiri ecosystem and this browser
      inherit (nixosTests.lomiri) desktop-basics desktop-appinteractions;
    };
  };