Flutter Engine
The Flutter Engine
resource_cache_limit_calculator_unittests.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
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 "flutter/shell/common/resource_cache_limit_calculator.h"
6
7#include "gtest/gtest.h"
8
9namespace flutter {
10namespace testing {
11
13 public:
14 explicit TestResourceCacheLimitItem(size_t resource_cache_limit)
15 : resource_cache_limit_(resource_cache_limit), weak_factory_(this) {}
16
17 size_t GetResourceCacheLimit() override { return resource_cache_limit_; }
18
20 return weak_factory_.GetWeakPtr();
21 }
22
23 private:
24 size_t resource_cache_limit_;
26};
27
28TEST(ResourceCacheLimitCalculatorTest, GetResourceCacheMaxBytes) {
29 ResourceCacheLimitCalculator calculator(800U);
30 auto item1 = std::make_unique<TestResourceCacheLimitItem>(100.0);
31 calculator.AddResourceCacheLimitItem(item1->GetWeakPtr());
32 EXPECT_EQ(calculator.GetResourceCacheMaxBytes(), static_cast<size_t>(100U));
33
34 auto item2 = std::make_unique<TestResourceCacheLimitItem>(200.0);
35 calculator.AddResourceCacheLimitItem(item2->GetWeakPtr());
36 EXPECT_EQ(calculator.GetResourceCacheMaxBytes(), static_cast<size_t>(300U));
37
38 auto item3 = std::make_unique<TestResourceCacheLimitItem>(300.0);
39 calculator.AddResourceCacheLimitItem(item3->GetWeakPtr());
40 EXPECT_EQ(calculator.GetResourceCacheMaxBytes(), static_cast<size_t>(600U));
41
42 auto item4 = std::make_unique<TestResourceCacheLimitItem>(400.0);
43 calculator.AddResourceCacheLimitItem(item4->GetWeakPtr());
44 EXPECT_EQ(calculator.GetResourceCacheMaxBytes(), static_cast<size_t>(800U));
45
46 item3.reset();
47 EXPECT_EQ(calculator.GetResourceCacheMaxBytes(), static_cast<size_t>(700U));
48
49 item2.reset();
50 EXPECT_EQ(calculator.GetResourceCacheMaxBytes(), static_cast<size_t>(500U));
51}
52
53} // namespace testing
54} // namespace flutter
void AddResourceCacheLimitItem(const fml::WeakPtr< ResourceCacheLimitItem > &item)
TEST(DisplayListComplexity, EmptyDisplayList)