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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
// Copyright (c) 2012 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 "base/message_loop.h"
#include "base/run_loop.h"
#include "content/browser/gpu/gpu_data_manager_impl.h"
#include "content/public/browser/gpu_data_manager_observer.h"
#include "content/public/common/gpu_info.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
class TestObserver : public content::GpuDataManagerObserver {
public:
TestObserver()
: gpu_info_updated_(false),
video_memory_usage_stats_updated_(false) {
}
virtual ~TestObserver() { }
bool gpu_info_updated() const { return gpu_info_updated_; }
bool video_memory_usage_stats_updated() const {
return video_memory_usage_stats_updated_;
}
virtual void OnGpuInfoUpdate() OVERRIDE {
gpu_info_updated_ = true;
}
virtual void OnVideoMemoryUsageStatsUpdate(
const content::GPUVideoMemoryUsageStats& stats) OVERRIDE {
video_memory_usage_stats_updated_ = true;
}
private:
bool gpu_info_updated_;
bool video_memory_usage_stats_updated_;
};
} // namespace anonymous
class GpuDataManagerImplTest : public testing::Test {
public:
GpuDataManagerImplTest() { }
virtual ~GpuDataManagerImplTest() { }
protected:
void SetUp() {
}
void TearDown() {
}
MessageLoop message_loop_;
};
// We use new method instead of GetInstance() method because we want
// each test to be independent of each other.
TEST_F(GpuDataManagerImplTest, GpuSideBlacklisting) {
// If a feature is allowed in preliminary step (browser side), but
// disabled when GPU process launches and collects full GPU info,
// it's too late to let renderer know, so we basically block all GPU
// access, to be on the safe side.
GpuDataManagerImpl* manager = new GpuDataManagerImpl();
ASSERT_TRUE(manager);
EXPECT_EQ(0, manager->GetBlacklistedFeatures());
EXPECT_TRUE(manager->GpuAccessAllowed());
manager->SetPreliminaryBlacklistedFeatures(
content::GPU_FEATURE_TYPE_WEBGL);
EXPECT_TRUE(manager->GpuAccessAllowed());
EXPECT_EQ(content::GPU_FEATURE_TYPE_WEBGL,
manager->GetBlacklistedFeatures());
manager->UpdateBlacklistedFeatures(
content::GPU_FEATURE_TYPE_WEBGL);
EXPECT_TRUE(manager->GpuAccessAllowed());
EXPECT_EQ(content::GPU_FEATURE_TYPE_WEBGL,
manager->GetBlacklistedFeatures());
manager->UpdateBlacklistedFeatures(
content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS);
EXPECT_EQ(content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS,
manager->GetBlacklistedFeatures());
EXPECT_FALSE(manager->GpuAccessAllowed());
delete manager;
}
TEST_F(GpuDataManagerImplTest, BlacklistCard) {
GpuDataManagerImpl* manager = new GpuDataManagerImpl();
ASSERT_TRUE(manager);
EXPECT_EQ(0, manager->GetBlacklistedFeatures());
EXPECT_TRUE(manager->GpuAccessAllowed());
manager->BlacklistCard();
EXPECT_FALSE(manager->GpuAccessAllowed());
// If software rendering is enabled, even if we blacklist GPU,
// GPU process is still allowed.
manager->software_rendering_ = true;
EXPECT_TRUE(manager->GpuAccessAllowed());
delete manager;
}
TEST_F(GpuDataManagerImplTest, GpuInfoUpdate) {
GpuDataManagerImpl* manager = new GpuDataManagerImpl();
ASSERT_TRUE(manager);
TestObserver observer;
manager->AddObserver(&observer);
EXPECT_FALSE(observer.gpu_info_updated());
content::GPUInfo gpu_info;
manager->UpdateGpuInfo(gpu_info);
base::RunLoop run_loop;
run_loop.RunUntilIdle();
EXPECT_TRUE(observer.gpu_info_updated());
delete manager;
}
TEST_F(GpuDataManagerImplTest, GPUVideoMemoryUsageStatsUpdate) {
GpuDataManagerImpl* manager = new GpuDataManagerImpl();
ASSERT_TRUE(manager);
TestObserver observer;
manager->AddObserver(&observer);
EXPECT_FALSE(observer.video_memory_usage_stats_updated());
content::GPUVideoMemoryUsageStats vram_stats;
manager->UpdateVideoMemoryUsageStats(vram_stats);
base::RunLoop run_loop;
run_loop.RunUntilIdle();
EXPECT_TRUE(observer.video_memory_usage_stats_updated());
delete manager;
}
|