blob: e5172d3e40fb1a884902f3a7c1ce9792c637d8d7 [file] [log] [blame]
Andrey Kosyakov0e2b5c9d2025-02-25 06:28:181// Copyright 2025 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "content/renderer/client_navigation_throttler.h"
6
7#include "base/test/bind.h"
8#include "testing/gmock/include/gmock/gmock.h"
9#include "testing/gtest/include/gtest/gtest.h"
10
11namespace content {
12namespace {
13
14TEST(ClientNavigationThrottlerTest, Empty) {
15 ClientNavigationThrottler unused;
16}
17
18TEST(ClientNavigationThrottlerTest, Basic) {
19 ClientNavigationThrottler throttler;
20 int foo = 1;
21 throttler.DispatchOrScheduleNavigation(
22 base::BindLambdaForTesting([&foo]() { foo++; }));
23 EXPECT_THAT(foo, testing::Eq(2));
24}
25
26TEST(ClientNavigationThrottlerTest, Throttles) {
27 ClientNavigationThrottler throttler;
28 int foo = 1;
29 auto throttle1 = throttler.DeferNavigations();
30 auto throttle2 = throttler.DeferNavigations();
31 throttler.DispatchOrScheduleNavigation(
32 base::BindLambdaForTesting([&foo]() { foo++; }));
33 EXPECT_THAT(foo, testing::Eq(1));
34 throttle1 = {};
35 EXPECT_THAT(foo, testing::Eq(1));
36 throttle2 = {};
37 EXPECT_THAT(foo, testing::Eq(2));
38}
39
40TEST(ClientNavigationThrottlerTest, Order) {
41 ClientNavigationThrottler throttler;
42 int foo = 1;
43 {
44 auto handle = throttler.DeferNavigations();
45 throttler.DispatchOrScheduleNavigation(
46 base::BindLambdaForTesting([&foo]() { foo += 1; }));
47 throttler.DispatchOrScheduleNavigation(
48 base::BindLambdaForTesting([&foo]() { foo <<= 1; }));
49 EXPECT_THAT(foo, testing::Eq(1));
50 }
51 EXPECT_THAT(foo, testing::Eq(4));
52}
53
54} // namespace
55
56} // namespace content