forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlow_memory_mode_controller_unittest.cc
86 lines (61 loc) · 2.42 KB
/
low_memory_mode_controller_unittest.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/renderer/low_memory_mode_controller.h"
#include "base/test/metrics/histogram_tester.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace content {
namespace {
class LowMemoryModeControllerTest : public testing::Test {
public:
LowMemoryModeController* controller() { return &controller_; }
void ExpectTransitionCount(int enabled_count, int disabled_count) {
static constexpr char kHistogram[] =
"SiteIsolation.LowMemoryMode.Transition";
histogram_tester_.ExpectBucketCount(kHistogram, true, enabled_count);
histogram_tester_.ExpectBucketCount(kHistogram, false, disabled_count);
histogram_tester_.ExpectTotalCount(kHistogram,
enabled_count + disabled_count);
}
private:
base::HistogramTester histogram_tester_;
LowMemoryModeController controller_;
};
TEST_F(LowMemoryModeControllerTest, CreateMainFrames) {
EXPECT_FALSE(controller()->is_enabled());
controller()->OnFrameCreated(true);
EXPECT_FALSE(controller()->is_enabled());
controller()->OnFrameCreated(true);
EXPECT_FALSE(controller()->is_enabled());
controller()->OnFrameDestroyed(true);
EXPECT_FALSE(controller()->is_enabled());
controller()->OnFrameDestroyed(true);
EXPECT_TRUE(controller()->is_enabled());
ExpectTransitionCount(1, 0);
}
TEST_F(LowMemoryModeControllerTest, MainFrameAddSubframe) {
EXPECT_FALSE(controller()->is_enabled());
controller()->OnFrameCreated(true);
EXPECT_FALSE(controller()->is_enabled());
controller()->OnFrameCreated(false);
EXPECT_FALSE(controller()->is_enabled());
controller()->OnFrameDestroyed(true);
EXPECT_TRUE(controller()->is_enabled());
controller()->OnFrameDestroyed(false);
EXPECT_TRUE(controller()->is_enabled());
ExpectTransitionCount(1, 0);
}
TEST_F(LowMemoryModeControllerTest, SubFrameAddMainFrame) {
EXPECT_FALSE(controller()->is_enabled());
controller()->OnFrameCreated(false);
EXPECT_TRUE(controller()->is_enabled());
controller()->OnFrameCreated(true);
EXPECT_FALSE(controller()->is_enabled());
controller()->OnFrameDestroyed(true);
EXPECT_TRUE(controller()->is_enabled());
controller()->OnFrameDestroyed(false);
EXPECT_TRUE(controller()->is_enabled());
ExpectTransitionCount(2, 1);
}
} // namespace
} // namespace content