Skip to content

fix(test): adapt night mode tests to async NightFilter refactor - #379

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:fix/night-mode-test-adapt
Sep 11, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:fix/night-mode-test-adapt

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Night mode was refactored to an async implementation (EyeProtectionManager + NightFilter + background thread), removing BrowserPage::applyNightMode. The existing tests still called the removed API, causing compile failure and preventing the entire test suite from running.

Changes

tests/browser/ut_browserpage.cppUT_BrowserPage_applyNightMode_001:

  • Rewrote to test NightFilter::apply() pure filter logic directly (null input → null output; white image → dark inverted output; dark image → boosted white) instead of the removed synchronous applyNightMode method.

tests/browser/ut_pagerenderthread.cpponDocPageNormalImageTaskFinished_002 / onDocPageBigImageTaskFinished_002:

  • Added setImageObjectRects stub. The refactoring inserted task.page->setImageObjectRects() before handleRenderFinished() in these slots; without the stub, the null task.page caused a segfault that killed the test process, preventing .gcda coverage generation.

Test Results

[==========] 1120 tests from 77 test suites ran. (50330 ms total)
[  PASSED  ] 1120 tests.
  • Line coverage: 83.80%
  • Function coverage: 98.50%

No production code changes.

Summary by Sourcery

Update unit tests for the asynchronous night-mode refactor and stabilize page-render completion test fixtures.

Bug Fixes:

  • Update browser page night-mode coverage to validate the refactored asynchronous filter behavior without relying on the removed synchronous API.
  • Prevent page-render-thread tests from crashing when exercising image completion handlers after the night-mode refactor.

Tests:

  • Adapt night-mode and page-render-thread unit tests to the current asynchronous implementation and ensure the full test suite can run successfully.

BrowserPage::applyNightMode was removed in the night mode refactoring
(async EyeProtectionManager + NightFilter + background thread). Update
tests to match the new API:

1. ut_browserpage.cpp: UT_BrowserPage_applyNightMode_001 — rewrite to
   test NightFilter::apply() pure filter logic directly (null input,
   white→dark inversion, dark→white boost) instead of the removed
   synchronous applyNightMode method.

2. ut_pagerenderthread.cpp: onDocPageNormalImageTaskFinished_002 and
   onDocPageBigImageTaskFinished_002 — add setImageObjectRects stub.
   The refactoring added task.page->setImageObjectRects() before
   handleRenderFinished() in these slots; without the stub, nullptr
   task.page caused a segfault that prevented the full suite from
   completing and coverage from being generated.

No production code changes. All 1120 tests pass (0 failures).
@sourcery-ai

sourcery-ai Bot commented Sep 11, 2026

Copy link
Copy Markdown

Reviewer's Guide

The test suite was adapted to the async NightFilter-based night-mode implementation by replacing calls to the removed BrowserPage API with pure filter assertions and stubbing the new page callback in render-thread tests. No production code changed; all 1,120 tests pass with reported line coverage of 83.80% and function coverage of 98.50%.

File-Level Changes

Change Details Files
Migrated the BrowserPage night-mode test from the removed synchronous API to direct validation of the asynchronous refactor’s pure filter behavior.
  • Included NightFilter and tested null, white, and dark image transformations.
  • Asserted output pixel properties for darkening and white boosting.
tests/browser/ut_browserpage.cpp
Updated render-thread tests to stub the newly introduced page image-rectangle update before render completion handling.
  • Added a no-op setImageObjectRects stub.
  • Registered the stub in normal- and large-image completion tests to avoid null-page dereferences.
tests/browser/ut_pagerenderthread.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tests/browser/ut_browserpage.cpp" line_range="854-856" />
<code_context>
+    QImage nightImg = NightFilter::apply(whiteImg);
+    EXPECT_FALSE(nightImg.isNull());
+    QRgb pixel = nightImg.pixel(0, 0);
+    EXPECT_LT(qRed(pixel), 128);
+    EXPECT_LT(qGreen(pixel), 128);
+    EXPECT_LT(qBlue(pixel), 128);
+
+    // 深色像素(boostSourceBelow 以下)反色后应提纯白
</code_context>
<issue_to_address>
**nitpick (testing):** The white-image assertions only require each RGB channel to be below 128, so an incorrect implementation that turns white pixels completely black still passes even though the documented filter clamps the inverted lightness to a non-black minimum.

**Triggers:** When the filter regresses to producing black output for white input.

**Suggested fix:** Assert the expected dark-gray range or exact/reference pixel values, including the alpha channel, rather than only checking that the channels are below 128.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment on lines +854 to +856
EXPECT_LT(qRed(pixel), 128);
EXPECT_LT(qGreen(pixel), 128);
EXPECT_LT(qBlue(pixel), 128);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick (testing): The white-image assertions only require each RGB channel to be below 128, so an incorrect implementation that turns white pixels completely black still passes even though the documented filter clamps the inverted lightness to a non-black minimum.

Triggers: When the filter regresses to producing black output for white input.

Suggested fix: Assert the expected dark-gray range or exact/reference pixel values, including the alpha channel, rather than only checking that the channels are below 128.

@pengfeixx

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot
deepin-bot Bot merged commit 9295c52 into linuxdeepin:master Sep 11, 2026
8 checks passed
@pengfeixx
pengfeixx deleted the fix/night-mode-test-adapt branch September 11, 2026 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants