Introduce a validation framework for tab strip service [chromium/src : main]

0 views
Skip to first unread message

Fred Shih (Gerrit)

unread,
Dec 22, 2025, 9:39:56 PM (4 days ago) Dec 22
to David Yeung, Keren Zhu, Tom Lukaszewicz, Chromium LUCI CQ, chromium...@chromium.org
Attention needed from David Yeung, Keren Zhu and Tom Lukaszewicz

Fred Shih added 1 comment

Patchset-level comments
File-level comment, Patchset 2 (Latest):
Fred Shih . resolved

What do you folks think?

Open in Gerrit

Related details

Attention is currently required from:
  • David Yeung
  • Keren Zhu
  • Tom Lukaszewicz
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: Ieae36732460e33fadeaf6c64b9911817e3ca7941
Gerrit-Change-Number: 7306191
Gerrit-PatchSet: 2
Gerrit-Owner: Fred Shih <ff...@chromium.org>
Gerrit-Reviewer: David Yeung <day...@chromium.org>
Gerrit-Reviewer: Fred Shih <ff...@chromium.org>
Gerrit-Reviewer: Keren Zhu <kere...@chromium.org>
Gerrit-Reviewer: Tom Lukaszewicz <tl...@chromium.org>
Gerrit-Attention: David Yeung <day...@chromium.org>
Gerrit-Attention: Keren Zhu <kere...@chromium.org>
Gerrit-Attention: Tom Lukaszewicz <tl...@chromium.org>
Gerrit-Comment-Date: Tue, 23 Dec 2025 02:39:46 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Keren Zhu (Gerrit)

unread,
Dec 22, 2025, 11:55:46 PM (4 days ago) Dec 22
to Fred Shih, David Yeung, Tom Lukaszewicz, Chromium LUCI CQ, chromium...@chromium.org
Attention needed from David Yeung, Fred Shih and Tom Lukaszewicz

Keren Zhu added 2 comments

File chrome/browser/ui/tabs/tab_strip_api/tab_strip_service_impl.cc
Line 13, Patchset 2 (Latest):#include "base/types/expected_macros.h"
Keren Zhu . resolved

TIL `RETURN_IF_ERROR` and `ASSIGN_OR_RETURN`. Looks useful.

Line 240, Patchset 2 (Latest): ASSIGN_OR_RETURN(auto tab_id, validations::GetNativeId(id));
Keren Zhu . unresolved

It is a bit weird that `GetNativeId()` is under `validation` namespace. I think the `NodeId` -> `NativeId` conversion deserves a helper function (I almost made one myself), but I won't search under the `./validation` folder for such a helper.

WDYT of simply adding the 2 helper functions under the `./utilities` folder?

Open in Gerrit

Related details

Attention is currently required from:
  • David Yeung
  • Fred Shih
  • Tom Lukaszewicz
Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: Ieae36732460e33fadeaf6c64b9911817e3ca7941
    Gerrit-Change-Number: 7306191
    Gerrit-PatchSet: 2
    Gerrit-Owner: Fred Shih <ff...@chromium.org>
    Gerrit-Reviewer: David Yeung <day...@chromium.org>
    Gerrit-Reviewer: Fred Shih <ff...@chromium.org>
    Gerrit-Reviewer: Keren Zhu <kere...@chromium.org>
    Gerrit-Reviewer: Tom Lukaszewicz <tl...@chromium.org>
    Gerrit-Attention: David Yeung <day...@chromium.org>
    Gerrit-Attention: Tom Lukaszewicz <tl...@chromium.org>
    Gerrit-Attention: Fred Shih <ff...@chromium.org>
    Gerrit-Comment-Date: Tue, 23 Dec 2025 04:55:40 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    David Yeung (Gerrit)

    unread,
    Dec 23, 2025, 12:15:08 AM (4 days ago) Dec 23
    to Fred Shih, Keren Zhu, Tom Lukaszewicz, Chromium LUCI CQ, chromium...@chromium.org
    Attention needed from Fred Shih and Tom Lukaszewicz

    David Yeung added 3 comments

    File chrome/browser/ui/tabs/tab_strip_api/tab_strip_service_impl.cc
    Line 123, Patchset 2 (Latest): RETURN_IF_ERROR(validations::IsContentType(tab_mojom_id));
    David Yeung . unresolved

    nit. I think this makes it harder to read. Curious what your thoughts are about readability

    Line 375, Patchset 2 (Latest): if (tab_id.Type() != tabs_api::NodeId::Type::kContent) {
    return base::unexpected(
    mojo_base::mojom::Error::New(mojo_base::mojom::Code::kInvalidArgument,
    "only a content tab id can be provided"));
    }
    David Yeung . unresolved

    There are several places where we'd want to change to `RETURN_IF_ERROR(validations::IsContentType(tab_mojom_id));`. Is that a follow up CL?

    Line 381, Patchset 2 (Latest): ASSIGN_OR_RETURN(auto handle_id, validations::GetNativeId(tab_id));
    David Yeung . unresolved

    Can we introduce a validation framework one level above the service implementation? Maybe a centralized place whenever a NodeId is forwarded over rather than having to check every time the api is used.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Fred Shih
    • Tom Lukaszewicz
    Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: Ieae36732460e33fadeaf6c64b9911817e3ca7941
    Gerrit-Change-Number: 7306191
    Gerrit-PatchSet: 2
    Gerrit-Owner: Fred Shih <ff...@chromium.org>
    Gerrit-Reviewer: David Yeung <day...@chromium.org>
    Gerrit-Reviewer: Fred Shih <ff...@chromium.org>
    Gerrit-Reviewer: Keren Zhu <kere...@chromium.org>
    Gerrit-Reviewer: Tom Lukaszewicz <tl...@chromium.org>
    Gerrit-Attention: Tom Lukaszewicz <tl...@chromium.org>
    Gerrit-Attention: Fred Shih <ff...@chromium.org>
    Gerrit-Comment-Date: Tue, 23 Dec 2025 05:14:56 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Fred Shih (Gerrit)

    unread,
    Dec 23, 2025, 4:06:31 PM (3 days ago) Dec 23
    to David Yeung, Keren Zhu, Tom Lukaszewicz, Chromium LUCI CQ, chromium...@chromium.org
    Attention needed from David Yeung, Keren Zhu and Tom Lukaszewicz

    Fred Shih added 4 comments

    File chrome/browser/ui/tabs/tab_strip_api/tab_strip_service_impl.cc
    Line 123, Patchset 2: RETURN_IF_ERROR(validations::IsContentType(tab_mojom_id));
    David Yeung . unresolved

    nit. I think this makes it harder to read. Curious what your thoughts are about readability

    Fred Shih

    I didn't like it at first when I used this pattern in Google3, but I have sorta come around to it. It's more of a side-effect of us not being able to throw exceptions IMO.

    This CL (and the macro lib) are based on Google3's macros:

    https://g3doc.corp.google.com/devtools/library_club/g3doc/totw/labs/fantastic-macros.md?cl=head
    https://g3doc.corp.google.com/devtools/library_club/g3doc/totw/121.md?cl=head

    I do admit that it looks kinda bleh at first though... Is there any other pattern you'd prefer?

    I also changed the function to `CheckIsContentType` to make it more clear that this is performing some sort of validation. I can see how it's confusing that a `IsContentType` would end up returning an error..

    Line 240, Patchset 2: ASSIGN_OR_RETURN(auto tab_id, validations::GetNativeId(id));
    Keren Zhu . resolved

    It is a bit weird that `GetNativeId()` is under `validation` namespace. I think the `NodeId` -> `NativeId` conversion deserves a helper function (I almost made one myself), but I won't search under the `./validation` folder for such a helper.

    WDYT of simply adding the 2 helper functions under the `./utilities` folder?

    Fred Shih

    I am not super opinionated on this. I had originally placed it under validations because it returns a InvalidArgument error, but I could also see the merit of putting it under utilities. If this makes more sense to you, then I will move it over there. Done!

    Line 375, Patchset 2: if (tab_id.Type() != tabs_api::NodeId::Type::kContent) {

    return base::unexpected(
    mojo_base::mojom::Error::New(mojo_base::mojom::Code::kInvalidArgument,
    "only a content tab id can be provided"));
    }
    David Yeung . resolved

    There are several places where we'd want to change to `RETURN_IF_ERROR(validations::IsContentType(tab_mojom_id));`. Is that a follow up CL?

    Fred Shih

    yep, followup later. This is more of a demonstration on the new way of checking-for and propagating errors.

    Line 381, Patchset 2: ASSIGN_OR_RETURN(auto handle_id, validations::GetNativeId(tab_id));
    David Yeung . unresolved

    Can we introduce a validation framework one level above the service implementation? Maybe a centralized place whenever a NodeId is forwarded over rather than having to check every time the api is used.

    Fred Shih

    I'm not sure how we would do this in a generic way. The node id can be embedded as part of a request, for example, as part of a Tab object. In that scenario, the interceptor (?) would have to have contextual knowledge about the underlying resource to perform meaningful validation.

    The only other way I can think of is to have manual validation written for each request type (and probably for each method). For example, when passing in NodeId, some services require that a specific type of node id is passed in, how would we declare that at higher level?

    Open in Gerrit

    Related details

    Attention is currently required from:
    • David Yeung
    • Keren Zhu
    • Tom Lukaszewicz
    Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: Ieae36732460e33fadeaf6c64b9911817e3ca7941
    Gerrit-Change-Number: 7306191
    Gerrit-PatchSet: 2
    Gerrit-Owner: Fred Shih <ff...@chromium.org>
    Gerrit-Reviewer: David Yeung <day...@chromium.org>
    Gerrit-Reviewer: Fred Shih <ff...@chromium.org>
    Gerrit-Reviewer: Keren Zhu <kere...@chromium.org>
    Gerrit-Reviewer: Tom Lukaszewicz <tl...@chromium.org>
    Gerrit-Attention: David Yeung <day...@chromium.org>
    Gerrit-Attention: Keren Zhu <kere...@chromium.org>
    Gerrit-Attention: Tom Lukaszewicz <tl...@chromium.org>
    Gerrit-Comment-Date: Tue, 23 Dec 2025 21:06:12 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: David Yeung <day...@chromium.org>
    Comment-In-Reply-To: Keren Zhu <kere...@chromium.org>
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Keren Zhu (Gerrit)

    unread,
    Dec 23, 2025, 9:23:37 PM (3 days ago) Dec 23
    to Fred Shih, David Yeung, Tom Lukaszewicz, Chromium LUCI CQ, chromium...@chromium.org
    Attention needed from David Yeung, Fred Shih and Tom Lukaszewicz

    Keren Zhu voted and added 1 comment

    Votes added by Keren Zhu

    Code-Review+1

    1 comment

    Patchset-level comments
    File-level comment, Patchset 3 (Latest):
    Keren Zhu . resolved

    looks great, thank you!

    Open in Gerrit

    Related details

    Attention is currently required from:
    • David Yeung
    • Fred Shih
    • Tom Lukaszewicz
    Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement satisfiedCode-Owners
      • requirement satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: Ieae36732460e33fadeaf6c64b9911817e3ca7941
      Gerrit-Change-Number: 7306191
      Gerrit-PatchSet: 3
      Gerrit-Owner: Fred Shih <ff...@chromium.org>
      Gerrit-Reviewer: David Yeung <day...@chromium.org>
      Gerrit-Reviewer: Fred Shih <ff...@chromium.org>
      Gerrit-Reviewer: Keren Zhu <kere...@chromium.org>
      Gerrit-Reviewer: Tom Lukaszewicz <tl...@chromium.org>
      Gerrit-Attention: David Yeung <day...@chromium.org>
      Gerrit-Attention: Tom Lukaszewicz <tl...@chromium.org>
      Gerrit-Attention: Fred Shih <ff...@chromium.org>
      Gerrit-Comment-Date: Wed, 24 Dec 2025 02:23:29 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      David Yeung (Gerrit)

      unread,
      1:39 PM (10 hours ago) 1:39 PM
      to Fred Shih, Keren Zhu, Tom Lukaszewicz, Chromium LUCI CQ, chromium...@chromium.org
      Attention needed from Fred Shih and Tom Lukaszewicz

      David Yeung voted and added 3 comments

      Votes added by David Yeung

      Code-Review+1

      3 comments

      File chrome/browser/ui/tabs/tab_strip_api/tab_strip_service_impl.cc
      Line 123, Patchset 2: RETURN_IF_ERROR(validations::IsContentType(tab_mojom_id));
      David Yeung . unresolved

      nit. I think this makes it harder to read. Curious what your thoughts are about readability

      Fred Shih

      I didn't like it at first when I used this pattern in Google3, but I have sorta come around to it. It's more of a side-effect of us not being able to throw exceptions IMO.

      This CL (and the macro lib) are based on Google3's macros:

      https://g3doc.corp.google.com/devtools/library_club/g3doc/totw/labs/fantastic-macros.md?cl=head
      https://g3doc.corp.google.com/devtools/library_club/g3doc/totw/121.md?cl=head

      I do admit that it looks kinda bleh at first though... Is there any other pattern you'd prefer?

      I also changed the function to `CheckIsContentType` to make it more clear that this is performing some sort of validation. I can see how it's confusing that a `IsContentType` would end up returning an error..

      David Yeung

      I just assumed any macro that hides errors end up as an anti-pattern because its harder to read and debug. By centralizing these validation checks, I'm worried we may also end up having one-off validation checks and just explode the validation file.

      Happy to try this out though and be proven wrong.

      Line 381, Patchset 2: ASSIGN_OR_RETURN(auto handle_id, validations::GetNativeId(tab_id));
      David Yeung . resolved

      Can we introduce a validation framework one level above the service implementation? Maybe a centralized place whenever a NodeId is forwarded over rather than having to check every time the api is used.

      Fred Shih

      I'm not sure how we would do this in a generic way. The node id can be embedded as part of a request, for example, as part of a Tab object. In that scenario, the interceptor (?) would have to have contextual knowledge about the underlying resource to perform meaningful validation.

      The only other way I can think of is to have manual validation written for each request type (and probably for each method). For example, when passing in NodeId, some services require that a specific type of node id is passed in, how would we declare that at higher level?

      David Yeung

      I don't have any suggestions. The main downside I had was that each API would need to remember to add a validation check.

      File chrome/browser/ui/tabs/tab_strip_api/utilities/tab_id_utils.cc
      Line 21, Patchset 3 (Latest):base::expected<int32_t, mojo_base::mojom::ErrorPtr> GetNativeId(
      David Yeung . unresolved

      Should this be explicit for tab ids? GetNativeTabId?

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Fred Shih
      • Tom Lukaszewicz
      Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: Ieae36732460e33fadeaf6c64b9911817e3ca7941
      Gerrit-Change-Number: 7306191
      Gerrit-PatchSet: 3
      Gerrit-Owner: Fred Shih <ff...@chromium.org>
      Gerrit-Reviewer: David Yeung <day...@chromium.org>
      Gerrit-Reviewer: Fred Shih <ff...@chromium.org>
      Gerrit-Reviewer: Keren Zhu <kere...@chromium.org>
      Gerrit-Reviewer: Tom Lukaszewicz <tl...@chromium.org>
      Gerrit-Attention: Tom Lukaszewicz <tl...@chromium.org>
      Gerrit-Attention: Fred Shih <ff...@chromium.org>
      Gerrit-Comment-Date: Fri, 26 Dec 2025 18:38:54 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      Comment-In-Reply-To: David Yeung <day...@chromium.org>
      Comment-In-Reply-To: Fred Shih <ff...@chromium.org>
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Fred Shih (Gerrit)

      unread,
      7:33 PM (4 hours ago) 7:33 PM
      to David Yeung, Keren Zhu, Tom Lukaszewicz, Chromium LUCI CQ, chromium...@chromium.org
      Attention needed from Tom Lukaszewicz

      Fred Shih added 2 comments

      File chrome/browser/ui/tabs/tab_strip_api/tab_strip_service_impl.cc
      Line 123, Patchset 2: RETURN_IF_ERROR(validations::IsContentType(tab_mojom_id));
      David Yeung . resolved

      nit. I think this makes it harder to read. Curious what your thoughts are about readability

      Fred Shih

      I didn't like it at first when I used this pattern in Google3, but I have sorta come around to it. It's more of a side-effect of us not being able to throw exceptions IMO.

      This CL (and the macro lib) are based on Google3's macros:

      https://g3doc.corp.google.com/devtools/library_club/g3doc/totw/labs/fantastic-macros.md?cl=head
      https://g3doc.corp.google.com/devtools/library_club/g3doc/totw/121.md?cl=head

      I do admit that it looks kinda bleh at first though... Is there any other pattern you'd prefer?

      I also changed the function to `CheckIsContentType` to make it more clear that this is performing some sort of validation. I can see how it's confusing that a `IsContentType` would end up returning an error..

      David Yeung

      I just assumed any macro that hides errors end up as an anti-pattern because its harder to read and debug. By centralizing these validation checks, I'm worried we may also end up having one-off validation checks and just explode the validation file.

      Happy to try this out though and be proven wrong.

      Fred Shih

      we can always create more files :)

      File chrome/browser/ui/tabs/tab_strip_api/utilities/tab_id_utils.cc
      Line 21, Patchset 3 (Latest):base::expected<int32_t, mojo_base::mojom::ErrorPtr> GetNativeId(
      David Yeung . resolved

      Should this be explicit for tab ids? GetNativeTabId?

      Fred Shih

      not too opionated, sure.

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Tom Lukaszewicz
      Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement satisfiedCode-Owners
      • requirement satisfiedCode-Review
      • requirement satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: Ieae36732460e33fadeaf6c64b9911817e3ca7941
      Gerrit-Change-Number: 7306191
      Gerrit-PatchSet: 3
      Gerrit-Owner: Fred Shih <ff...@chromium.org>
      Gerrit-Reviewer: David Yeung <day...@chromium.org>
      Gerrit-Reviewer: Fred Shih <ff...@chromium.org>
      Gerrit-Reviewer: Keren Zhu <kere...@chromium.org>
      Gerrit-Reviewer: Tom Lukaszewicz <tl...@chromium.org>
      Gerrit-Attention: Tom Lukaszewicz <tl...@chromium.org>
      Gerrit-Comment-Date: Sat, 27 Dec 2025 00:33:38 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      satisfied_requirement
      open
      diffy

      Chromium LUCI CQ (Gerrit)

      unread,
      8:28 PM (3 hours ago) 8:28 PM
      to Fred Shih, David Yeung, Keren Zhu, Tom Lukaszewicz, chromium...@chromium.org

      Chromium LUCI CQ submitted the change with unreviewed changes

      Unreviewed changes

      3 is the latest approved patch-set.
      The change was submitted with unreviewed changes in the following files:

      ```
      The name of the file: chrome/browser/ui/tabs/tab_strip_api/utilities/tab_id_utils.cc
      Insertions: 1, Deletions: 1.

      @@ -18,7 +18,7 @@
      return base::ok();
      }

      -base::expected<int32_t, mojo_base::mojom::ErrorPtr> GetNativeId(
      +base::expected<int32_t, mojo_base::mojom::ErrorPtr> GetNativeTabId(
      const NodeId& node_id) {
      int32_t tab_id;
      if (!base::StringToInt(node_id.Id(), &tab_id)) {
      ```
      ```
      The name of the file: chrome/browser/ui/tabs/tab_strip_api/utilities/tab_id_utils_unittest.cc
      Insertions: 4, Deletions: 4.

      @@ -20,14 +20,14 @@
      ASSERT_EQ(mojo_base::mojom::Code::kInvalidArgument, result.error()->code);
      }

      -TEST(TabStripApiUtilsTest, GetNativeId) {
      - auto result = GetNativeId(NodeId(NodeId::Type::kContent, "123"));
      +TEST(TabStripApiUtilsTest, GetNativeTabId) {
      + auto result = GetNativeTabId(NodeId(NodeId::Type::kContent, "123"));
      ASSERT_TRUE(result.has_value());
      ASSERT_EQ(123, result.value());
      }

      -TEST(TabStripApiUtilsTest, GetNativeId_BadType) {
      - auto result = GetNativeId(NodeId(NodeId::Type::kContent, "abc"));
      +TEST(TabStripApiUtilsTest, GetNativeTabId_BadType) {
      + auto result = GetNativeTabId(NodeId(NodeId::Type::kContent, "abc"));
      ASSERT_FALSE(result.has_value());
      ASSERT_EQ(mojo_base::mojom::Code::kInvalidArgument, result.error()->code);
      }
      ```
      ```
      The name of the file: chrome/browser/ui/tabs/tab_strip_api/utilities/tab_id_utils.h
      Insertions: 1, Deletions: 1.

      @@ -13,7 +13,7 @@

      base::expected<void, mojo_base::mojom::ErrorPtr> CheckIsContentType(
      const NodeId& node_id);
      -base::expected<int32_t, mojo_base::mojom::ErrorPtr> GetNativeId(
      +base::expected<int32_t, mojo_base::mojom::ErrorPtr> GetNativeTabId(
      const NodeId& node_id);

      } // namespace tabs_api::utils
      ```
      ```
      The name of the file: chrome/browser/ui/tabs/tab_strip_api/tab_strip_service_impl.cc
      Insertions: 3, Deletions: 3.

      @@ -121,7 +121,7 @@
      auto session = session_controller_->CreateSession();

      RETURN_IF_ERROR(utils::CheckIsContentType(tab_mojom_id));
      - ASSIGN_OR_RETURN(auto tab_id, utils::GetNativeId(tab_mojom_id));
      + ASSIGN_OR_RETURN(auto tab_id, utils::GetNativeTabId(tab_mojom_id));

      tabs_api::mojom::TabPtr tab_result;
      // TODO (crbug.com/412709270) TabStripModel or TabCollections should have an
      @@ -237,7 +237,7 @@

      "only a content tab id can be provided"));
      }

      -  ASSIGN_OR_RETURN(auto tab_id, utils::GetNativeId(id));
      + ASSIGN_OR_RETURN(auto tab_id, utils::GetNativeTabId(id));

      auto maybe_idx =
      tab_strip_model_adapter_->GetIndexForHandle(tabs::TabHandle(tab_id));
      @@ -378,7 +378,7 @@

      "only a content tab id can be provided"));
      }

      -  ASSIGN_OR_RETURN(auto handle_id, utils::GetNativeId(tab_id));
      + ASSIGN_OR_RETURN(auto handle_id, utils::GetNativeTabId(tab_id));

      auto maybe_idx =
      tab_strip_model_adapter_->GetIndexForHandle(tabs::TabHandle(handle_id));
      ```

      Change information

      Commit message:
      Introduce a validation framework for tab strip service

      There are a lot of validations for tab strip service, which can make it
      difficult to test the validation logic. To make matters worse, most of
      the methods copy-and-paste the validation logic throughout the service.

      Instead, group the validation in a central place and make each validator
      logically simple. Use the expected macros to take advantage our usage of
      base::expected. This allows us to easily short-circuit return or
      assign-or-return on validation.

      Unit testing for these validations are very simple because they are
      stateless function calls.

      There is no need to test the service methods themselves because they
      validations are performed inline and falls straight through. The assign
      or return ensures that we do not use unvalidated variables in our code.

      This will not cover all cases. There might be some methods which require
      very specific validations. Those methods will need to explicitly test
      those validations in their unit_test.
      Change-Id: Ieae36732460e33fadeaf6c64b9911817e3ca7941
      Reviewed-by: Keren Zhu <kere...@chromium.org>
      Reviewed-by: David Yeung <day...@chromium.org>
      Commit-Queue: Fred Shih <ff...@chromium.org>
      Cr-Commit-Position: refs/heads/main@{#1562821}
      Files:
      • M chrome/browser/ui/tabs/tab_strip_api/tab_strip_service_impl.cc
      • M chrome/browser/ui/tabs/tab_strip_api/utilities/BUILD.gn
      • A chrome/browser/ui/tabs/tab_strip_api/utilities/tab_id_utils.cc
      • A chrome/browser/ui/tabs/tab_strip_api/utilities/tab_id_utils.h
      • A chrome/browser/ui/tabs/tab_strip_api/utilities/tab_id_utils_unittest.cc
      Change size: M
      Delta: 5 files changed, 102 insertions(+), 23 deletions(-)
      Branch: refs/heads/main
      Submit Requirements:
      • requirement satisfiedCode-Review: +1 by Keren Zhu, +1 by David Yeung
      Open in Gerrit
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: merged
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: Ieae36732460e33fadeaf6c64b9911817e3ca7941
      Gerrit-Change-Number: 7306191
      Gerrit-PatchSet: 5
      Gerrit-Owner: Fred Shih <ff...@chromium.org>
      Gerrit-Reviewer: Chromium LUCI CQ <chromiu...@luci-project-accounts.iam.gserviceaccount.com>
      Gerrit-Reviewer: David Yeung <day...@chromium.org>
      Gerrit-Reviewer: Fred Shih <ff...@chromium.org>
      Gerrit-Reviewer: Keren Zhu <kere...@chromium.org>
      Gerrit-Reviewer: Tom Lukaszewicz <tl...@chromium.org>
      open
      diffy
      satisfied_requirement
      Reply all
      Reply to author
      Forward
      0 new messages