1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "gtest/gtest.h"
7 
8 #include "gfxFeature.h"
9 #include "mozilla/gfx/gfxConfigManager.h"
10 #include "nsIGfxInfo.h"
11 
12 using namespace mozilla;
13 using namespace mozilla::gfx;
14 
15 namespace mozilla {
16 namespace gfx {
17 
18 class MockGfxInfo final : public nsIGfxInfo {
19  public:
20   NS_DECL_THREADSAFE_ISUPPORTS
21 
22   int32_t mStatusWr;
23   int32_t mStatusWrCompositor;
24   int32_t mMaxRefreshRate;
25   Maybe<bool> mHasBattery;
26   const char* mVendorId;
27 
28   // Default allows WebRender + compositor, and is desktop NVIDIA.
MockGfxInfo()29   MockGfxInfo()
30       : mStatusWr(nsIGfxInfo::FEATURE_ALLOW_ALWAYS),
31         mStatusWrCompositor(nsIGfxInfo::FEATURE_STATUS_OK),
32         mMaxRefreshRate(-1),
33         mHasBattery(Some(false)),
34         mVendorId("0x10de") {}
35 
GetFeatureStatus(int32_t aFeature,nsACString & aFailureId,int32_t * _retval)36   NS_IMETHOD GetFeatureStatus(int32_t aFeature, nsACString& aFailureId,
37                               int32_t* _retval) override {
38     switch (aFeature) {
39       case nsIGfxInfo::FEATURE_WEBRENDER:
40         *_retval = mStatusWr;
41         break;
42       case nsIGfxInfo::FEATURE_WEBRENDER_COMPOSITOR:
43         *_retval = mStatusWrCompositor;
44         break;
45       default:
46         return NS_ERROR_NOT_IMPLEMENTED;
47     }
48     return NS_OK;
49   }
50 
GetHasBattery(bool * aHasBattery)51   NS_IMETHOD GetHasBattery(bool* aHasBattery) override {
52     if (mHasBattery.isNothing()) {
53       return NS_ERROR_NOT_IMPLEMENTED;
54     }
55     *aHasBattery = *mHasBattery;
56     return NS_OK;
57   }
58 
GetAdapterVendorID(nsAString & aAdapterVendorID)59   NS_IMETHOD GetAdapterVendorID(nsAString& aAdapterVendorID) override {
60     if (!mVendorId) {
61       return NS_ERROR_NOT_IMPLEMENTED;
62     }
63     aAdapterVendorID.AssignASCII(mVendorId);
64     return NS_OK;
65   }
66 
GetMaxRefreshRate()67   NS_IMETHOD_(int32_t) GetMaxRefreshRate() override { return mMaxRefreshRate; }
68 
69   // The following methods we don't need for testing gfxConfigManager.
GetFeatureSuggestedDriverVersion(int32_t aFeature,nsAString & _retval)70   NS_IMETHOD GetFeatureSuggestedDriverVersion(int32_t aFeature,
71                                               nsAString& _retval) override {
72     return NS_ERROR_NOT_IMPLEMENTED;
73   }
74 
GetMonitors(JSContext * cx,JS::MutableHandleValue _retval)75   NS_IMETHOD GetMonitors(JSContext* cx,
76                          JS::MutableHandleValue _retval) override {
77     return NS_ERROR_NOT_IMPLEMENTED;
78   }
GetFailures(nsTArray<int32_t> & indices,nsTArray<nsCString> & failures)79   NS_IMETHOD GetFailures(nsTArray<int32_t>& indices,
80                          nsTArray<nsCString>& failures) override {
81     return NS_ERROR_NOT_IMPLEMENTED;
82   }
LogFailure(const nsACString & failure)83   NS_IMETHOD_(void) LogFailure(const nsACString& failure) override {}
GetInfo(JSContext *,JS::MutableHandle<JS::Value>)84   NS_IMETHOD GetInfo(JSContext*, JS::MutableHandle<JS::Value>) override {
85     return NS_ERROR_NOT_IMPLEMENTED;
86   }
GetFeatures(JSContext *,JS::MutableHandle<JS::Value>)87   NS_IMETHOD GetFeatures(JSContext*, JS::MutableHandle<JS::Value>) override {
88     return NS_ERROR_NOT_IMPLEMENTED;
89   }
GetFeatureLog(JSContext *,JS::MutableHandle<JS::Value>)90   NS_IMETHOD GetFeatureLog(JSContext*, JS::MutableHandle<JS::Value>) override {
91     return NS_ERROR_NOT_IMPLEMENTED;
92   }
GetActiveCrashGuards(JSContext *,JS::MutableHandle<JS::Value>)93   NS_IMETHOD GetActiveCrashGuards(JSContext*,
94                                   JS::MutableHandle<JS::Value>) override {
95     return NS_ERROR_NOT_IMPLEMENTED;
96   }
GetContentBackend(nsAString & aContentBackend)97   NS_IMETHOD GetContentBackend(nsAString& aContentBackend) override {
98     return NS_ERROR_NOT_IMPLEMENTED;
99   }
GetUsingGPUProcess(bool * aOutValue)100   NS_IMETHOD GetUsingGPUProcess(bool* aOutValue) override {
101     return NS_ERROR_NOT_IMPLEMENTED;
102   }
GetWebRenderEnabled(bool * aWebRenderEnabled)103   NS_IMETHOD GetWebRenderEnabled(bool* aWebRenderEnabled) override {
104     return NS_ERROR_NOT_IMPLEMENTED;
105   }
GetIsHeadless(bool * aIsHeadless)106   NS_IMETHOD GetIsHeadless(bool* aIsHeadless) override {
107     return NS_ERROR_NOT_IMPLEMENTED;
108   }
GetUsesTiling(bool * aUsesTiling)109   NS_IMETHOD GetUsesTiling(bool* aUsesTiling) override {
110     return NS_ERROR_NOT_IMPLEMENTED;
111   }
GetContentUsesTiling(bool * aUsesTiling)112   NS_IMETHOD GetContentUsesTiling(bool* aUsesTiling) override {
113     return NS_ERROR_NOT_IMPLEMENTED;
114   }
GetOffMainThreadPaintEnabled(bool * aOffMainThreadPaintEnabled)115   NS_IMETHOD GetOffMainThreadPaintEnabled(
116       bool* aOffMainThreadPaintEnabled) override {
117     return NS_ERROR_NOT_IMPLEMENTED;
118   }
GetOffMainThreadPaintWorkerCount(int32_t * aOffMainThreadPaintWorkerCount)119   NS_IMETHOD GetOffMainThreadPaintWorkerCount(
120       int32_t* aOffMainThreadPaintWorkerCount) override {
121     return NS_ERROR_NOT_IMPLEMENTED;
122   }
GetTargetFrameRate(uint32_t * aTargetFrameRate)123   NS_IMETHOD GetTargetFrameRate(uint32_t* aTargetFrameRate) override {
124     return NS_ERROR_NOT_IMPLEMENTED;
125   }
GetD2DEnabled(bool * aD2DEnabled)126   NS_IMETHOD GetD2DEnabled(bool* aD2DEnabled) override {
127     return NS_ERROR_NOT_IMPLEMENTED;
128   }
GetDWriteEnabled(bool * aDWriteEnabled)129   NS_IMETHOD GetDWriteEnabled(bool* aDWriteEnabled) override {
130     return NS_ERROR_NOT_IMPLEMENTED;
131   }
GetDWriteVersion(nsAString & aDwriteVersion)132   NS_IMETHOD GetDWriteVersion(nsAString& aDwriteVersion) override {
133     return NS_ERROR_NOT_IMPLEMENTED;
134   }
GetCleartypeParameters(nsAString & aCleartypeParams)135   NS_IMETHOD GetCleartypeParameters(nsAString& aCleartypeParams) override {
136     return NS_ERROR_NOT_IMPLEMENTED;
137   }
GetWindowProtocol(nsAString & aWindowProtocol)138   NS_IMETHOD GetWindowProtocol(nsAString& aWindowProtocol) override {
139     return NS_ERROR_NOT_IMPLEMENTED;
140   }
GetDesktopEnvironment(nsAString & aDesktopEnvironment)141   NS_IMETHOD GetDesktopEnvironment(nsAString& aDesktopEnvironment) override {
142     return NS_ERROR_NOT_IMPLEMENTED;
143   }
GetAdapterDescription(nsAString & aAdapterDescription)144   NS_IMETHOD GetAdapterDescription(nsAString& aAdapterDescription) override {
145     return NS_ERROR_NOT_IMPLEMENTED;
146   }
GetAdapterDriver(nsAString & aAdapterDriver)147   NS_IMETHOD GetAdapterDriver(nsAString& aAdapterDriver) override {
148     return NS_ERROR_NOT_IMPLEMENTED;
149   }
GetAdapterDeviceID(nsAString & aAdapterDeviceID)150   NS_IMETHOD GetAdapterDeviceID(nsAString& aAdapterDeviceID) override {
151     return NS_ERROR_NOT_IMPLEMENTED;
152   }
GetAdapterSubsysID(nsAString & aAdapterSubsysID)153   NS_IMETHOD GetAdapterSubsysID(nsAString& aAdapterSubsysID) override {
154     return NS_ERROR_NOT_IMPLEMENTED;
155   }
GetAdapterRAM(uint32_t * aAdapterRAM)156   NS_IMETHOD GetAdapterRAM(uint32_t* aAdapterRAM) override {
157     return NS_ERROR_NOT_IMPLEMENTED;
158   }
GetAdapterDriverVendor(nsAString & aAdapterDriverVendor)159   NS_IMETHOD GetAdapterDriverVendor(nsAString& aAdapterDriverVendor) override {
160     return NS_ERROR_NOT_IMPLEMENTED;
161   }
GetAdapterDriverVersion(nsAString & aAdapterDriverVersion)162   NS_IMETHOD GetAdapterDriverVersion(
163       nsAString& aAdapterDriverVersion) override {
164     return NS_ERROR_NOT_IMPLEMENTED;
165   }
GetAdapterDriverDate(nsAString & aAdapterDriverDate)166   NS_IMETHOD GetAdapterDriverDate(nsAString& aAdapterDriverDate) override {
167     return NS_ERROR_NOT_IMPLEMENTED;
168   }
GetAdapterDescription2(nsAString & aAdapterDescription)169   NS_IMETHOD GetAdapterDescription2(nsAString& aAdapterDescription) override {
170     return NS_ERROR_NOT_IMPLEMENTED;
171   }
GetAdapterDriver2(nsAString & aAdapterDriver)172   NS_IMETHOD GetAdapterDriver2(nsAString& aAdapterDriver) override {
173     return NS_ERROR_NOT_IMPLEMENTED;
174   }
GetAdapterVendorID2(nsAString & aAdapterVendorID)175   NS_IMETHOD GetAdapterVendorID2(nsAString& aAdapterVendorID) override {
176     return NS_ERROR_NOT_IMPLEMENTED;
177   }
GetAdapterDeviceID2(nsAString & aAdapterDeviceID)178   NS_IMETHOD GetAdapterDeviceID2(nsAString& aAdapterDeviceID) override {
179     return NS_ERROR_NOT_IMPLEMENTED;
180   }
GetAdapterSubsysID2(nsAString & aAdapterSubsysID)181   NS_IMETHOD GetAdapterSubsysID2(nsAString& aAdapterSubsysID) override {
182     return NS_ERROR_NOT_IMPLEMENTED;
183   }
GetAdapterRAM2(uint32_t * aAdapterRAM)184   NS_IMETHOD GetAdapterRAM2(uint32_t* aAdapterRAM) override {
185     return NS_ERROR_NOT_IMPLEMENTED;
186   }
GetAdapterDriverVendor2(nsAString & aAdapterDriverVendor)187   NS_IMETHOD GetAdapterDriverVendor2(nsAString& aAdapterDriverVendor) override {
188     return NS_ERROR_NOT_IMPLEMENTED;
189   }
GetAdapterDriverVersion2(nsAString & aAdapterDriverVersion)190   NS_IMETHOD GetAdapterDriverVersion2(
191       nsAString& aAdapterDriverVersion) override {
192     return NS_ERROR_NOT_IMPLEMENTED;
193   }
GetAdapterDriverDate2(nsAString & aAdapterDriverDate)194   NS_IMETHOD GetAdapterDriverDate2(nsAString& aAdapterDriverDate) override {
195     return NS_ERROR_NOT_IMPLEMENTED;
196   }
GetIsGPU2Active(bool * aIsGPU2Active)197   NS_IMETHOD GetIsGPU2Active(bool* aIsGPU2Active) override {
198     return NS_ERROR_NOT_IMPLEMENTED;
199   }
GetDisplayInfo(nsTArray<nsString> & aDisplayInfo)200   NS_IMETHOD GetDisplayInfo(nsTArray<nsString>& aDisplayInfo) override {
201     return NS_ERROR_NOT_IMPLEMENTED;
202   }
GetDisplayWidth(nsTArray<uint32_t> & aDisplayWidth)203   NS_IMETHOD GetDisplayWidth(nsTArray<uint32_t>& aDisplayWidth) override {
204     return NS_ERROR_NOT_IMPLEMENTED;
205   }
GetDisplayHeight(nsTArray<uint32_t> & aDisplayHeight)206   NS_IMETHOD GetDisplayHeight(nsTArray<uint32_t>& aDisplayHeight) override {
207     return NS_ERROR_NOT_IMPLEMENTED;
208   }
ControlGPUProcessForXPCShell(bool aEnable,bool * _retval)209   NS_IMETHOD ControlGPUProcessForXPCShell(bool aEnable,
210                                           bool* _retval) override {
211     return NS_ERROR_NOT_IMPLEMENTED;
212   }
GetData()213   NS_IMETHOD_(void) GetData() override {}
214 
215  private:
216   virtual ~MockGfxInfo() = default;
217 };
218 
219 NS_IMPL_ISUPPORTS(MockGfxInfo, nsIGfxInfo)
220 
221 class GfxConfigManager : public ::testing::Test, public gfxConfigManager {
222  public:
GfxConfigManager()223   GfxConfigManager() {
224     mFeatureWr = &mFeatures.mWr;
225     mFeatureWrQualified = &mFeatures.mWrQualified;
226     mFeatureWrCompositor = &mFeatures.mWrCompositor;
227     mFeatureWrAngle = &mFeatures.mWrAngle;
228     mFeatureWrDComp = &mFeatures.mWrDComp;
229     mFeatureWrPartial = &mFeatures.mWrPartial;
230     mFeatureHwCompositing = &mFeatures.mHwCompositing;
231     mFeatureD3D11HwAngle = &mFeatures.mD3D11HwAngle;
232     mFeatureGPUProcess = &mFeatures.mGPUProcess;
233   }
234 
SetUp()235   void SetUp() override {
236     mMockGfxInfo = new MockGfxInfo();
237     mGfxInfo = mMockGfxInfo;
238 
239     // By default, turn everything on. This effectively assumes we are on
240     // qualified nightly Windows 10 with DirectComposition support.
241     mFeatureHwCompositing->EnableByDefault();
242     mFeatureD3D11HwAngle->EnableByDefault();
243     mFeatureGPUProcess->EnableByDefault();
244 
245     mWrCompositorEnabled.emplace(true);
246     mWrQualified = true;
247     mWrPictureCaching = true;
248     mWrPartialPresent = true;
249     mWrForceAngle = true;
250     mWrDCompWinEnabled = true;
251     mWrCompositorDCompRequired = true;
252     mHwStretchingSupport = true;
253     mDwmCompositionEnabled = true;
254     mIsWin10OrLater = true;
255     mIsWindows = true;
256     mIsNightly = true;
257   }
258 
TearDown()259   void TearDown() override {
260     mFeatures.mWr.Reset();
261     mFeatures.mWrQualified.Reset();
262     mFeatures.mWrCompositor.Reset();
263     mFeatures.mWrAngle.Reset();
264     mFeatures.mWrDComp.Reset();
265     mFeatures.mWrPartial.Reset();
266     mFeatures.mHwCompositing.Reset();
267     mFeatures.mD3D11HwAngle.Reset();
268     mFeatures.mGPUProcess.Reset();
269   }
270 
271   struct {
272     FeatureState mWr;
273     FeatureState mWrQualified;
274     FeatureState mWrCompositor;
275     FeatureState mWrAngle;
276     FeatureState mWrDComp;
277     FeatureState mWrPartial;
278     FeatureState mHwCompositing;
279     FeatureState mD3D11HwAngle;
280     FeatureState mGPUProcess;
281   } mFeatures;
282 
283   RefPtr<MockGfxInfo> mMockGfxInfo;
284 };
285 
286 }  // namespace gfx
287 }  // namespace mozilla
288 
TEST_F(GfxConfigManager,WebRenderDefault)289 TEST_F(GfxConfigManager, WebRenderDefault) {
290   ConfigureWebRender();
291 
292   EXPECT_TRUE(mFeatures.mWrQualified.IsEnabled());
293   EXPECT_TRUE(mFeatures.mWr.IsEnabled());
294   EXPECT_TRUE(mFeatures.mWrCompositor.IsEnabled());
295   EXPECT_TRUE(mFeatures.mWrAngle.IsEnabled());
296   EXPECT_TRUE(mFeatures.mWrDComp.IsEnabled());
297   EXPECT_TRUE(mFeatures.mWrPartial.IsEnabled());
298   EXPECT_TRUE(mFeatures.mHwCompositing.IsEnabled());
299   EXPECT_TRUE(mFeatures.mGPUProcess.IsEnabled());
300   EXPECT_TRUE(mFeatures.mD3D11HwAngle.IsEnabled());
301 }
302 
TEST_F(GfxConfigManager,WebRenderNoPartialPresent)303 TEST_F(GfxConfigManager, WebRenderNoPartialPresent) {
304   mWrPartialPresent = false;
305   ConfigureWebRender();
306 
307   EXPECT_TRUE(mFeatures.mWrQualified.IsEnabled());
308   EXPECT_TRUE(mFeatures.mWr.IsEnabled());
309   EXPECT_TRUE(mFeatures.mWrCompositor.IsEnabled());
310   EXPECT_TRUE(mFeatures.mWrAngle.IsEnabled());
311   EXPECT_TRUE(mFeatures.mWrDComp.IsEnabled());
312   EXPECT_FALSE(mFeatures.mWrPartial.IsEnabled());
313   EXPECT_TRUE(mFeatures.mHwCompositing.IsEnabled());
314   EXPECT_TRUE(mFeatures.mGPUProcess.IsEnabled());
315   EXPECT_TRUE(mFeatures.mD3D11HwAngle.IsEnabled());
316 }
317 
TEST_F(GfxConfigManager,WebRenderNoPictureCaching)318 TEST_F(GfxConfigManager, WebRenderNoPictureCaching) {
319   mWrPictureCaching = false;
320   ConfigureWebRender();
321 
322   EXPECT_TRUE(mFeatures.mWrQualified.IsEnabled());
323   EXPECT_TRUE(mFeatures.mWr.IsEnabled());
324   EXPECT_FALSE(mFeatures.mWrCompositor.IsEnabled());
325   EXPECT_TRUE(mFeatures.mWrAngle.IsEnabled());
326   EXPECT_TRUE(mFeatures.mWrDComp.IsEnabled());
327   EXPECT_FALSE(mFeatures.mWrPartial.IsEnabled());
328   EXPECT_TRUE(mFeatures.mHwCompositing.IsEnabled());
329   EXPECT_TRUE(mFeatures.mGPUProcess.IsEnabled());
330   EXPECT_TRUE(mFeatures.mD3D11HwAngle.IsEnabled());
331 }
332 
TEST_F(GfxConfigManager,WebRenderScaledResolutionWithHwStretching)333 TEST_F(GfxConfigManager, WebRenderScaledResolutionWithHwStretching) {
334   mScaledResolution = true;
335   ConfigureWebRender();
336 
337   EXPECT_TRUE(mFeatures.mWrQualified.IsEnabled());
338   EXPECT_TRUE(mFeatures.mWr.IsEnabled());
339   EXPECT_TRUE(mFeatures.mWrCompositor.IsEnabled());
340   EXPECT_TRUE(mFeatures.mWrAngle.IsEnabled());
341   EXPECT_TRUE(mFeatures.mWrDComp.IsEnabled());
342   EXPECT_TRUE(mFeatures.mWrPartial.IsEnabled());
343   EXPECT_TRUE(mFeatures.mHwCompositing.IsEnabled());
344   EXPECT_TRUE(mFeatures.mGPUProcess.IsEnabled());
345   EXPECT_TRUE(mFeatures.mD3D11HwAngle.IsEnabled());
346 }
347 
TEST_F(GfxConfigManager,WebRenderScaledResolutionNoHwStretching)348 TEST_F(GfxConfigManager, WebRenderScaledResolutionNoHwStretching) {
349   mHwStretchingSupport = false;
350   mScaledResolution = true;
351   ConfigureWebRender();
352 
353   EXPECT_TRUE(mFeatures.mWrQualified.IsEnabled());
354   EXPECT_TRUE(mFeatures.mWr.IsEnabled());
355   EXPECT_FALSE(mFeatures.mWrCompositor.IsEnabled());
356   EXPECT_TRUE(mFeatures.mWrAngle.IsEnabled());
357   EXPECT_TRUE(mFeatures.mWrDComp.IsEnabled());
358   EXPECT_TRUE(mFeatures.mWrPartial.IsEnabled());
359   EXPECT_TRUE(mFeatures.mHwCompositing.IsEnabled());
360   EXPECT_TRUE(mFeatures.mGPUProcess.IsEnabled());
361   EXPECT_TRUE(mFeatures.mD3D11HwAngle.IsEnabled());
362 }
363 
TEST_F(GfxConfigManager,WebRenderEnabledWithDisableHwCompositingNoWr)364 TEST_F(GfxConfigManager, WebRenderEnabledWithDisableHwCompositingNoWr) {
365   mDisableHwCompositingNoWr = true;
366   ConfigureWebRender();
367 
368   EXPECT_TRUE(mFeatures.mWrQualified.IsEnabled());
369   EXPECT_TRUE(mFeatures.mWr.IsEnabled());
370   EXPECT_TRUE(mFeatures.mWrCompositor.IsEnabled());
371   EXPECT_TRUE(mFeatures.mWrAngle.IsEnabled());
372   EXPECT_TRUE(mFeatures.mWrDComp.IsEnabled());
373   EXPECT_TRUE(mFeatures.mWrPartial.IsEnabled());
374   EXPECT_TRUE(mFeatures.mHwCompositing.IsEnabled());
375   EXPECT_TRUE(mFeatures.mGPUProcess.IsEnabled());
376   EXPECT_TRUE(mFeatures.mD3D11HwAngle.IsEnabled());
377 }
378 
TEST_F(GfxConfigManager,WebRenderDisabledWithDisableHwCompositingNoWr)379 TEST_F(GfxConfigManager, WebRenderDisabledWithDisableHwCompositingNoWr) {
380   mDisableHwCompositingNoWr = true;
381   mWrQualified = false;
382   ConfigureWebRender();
383 
384   EXPECT_TRUE(mFeatures.mWrQualified.IsEnabled());
385   EXPECT_FALSE(mFeatures.mWr.IsEnabled());
386   EXPECT_FALSE(mFeatures.mWrCompositor.IsEnabled());
387   EXPECT_FALSE(mFeatures.mWrAngle.IsEnabled());
388   EXPECT_FALSE(mFeatures.mWrDComp.IsEnabled());
389   EXPECT_FALSE(mFeatures.mWrPartial.IsEnabled());
390   EXPECT_FALSE(mFeatures.mHwCompositing.IsEnabled());
391   EXPECT_FALSE(mFeatures.mGPUProcess.IsEnabled());
392   EXPECT_TRUE(mFeatures.mD3D11HwAngle.IsEnabled());
393 }
394 
TEST_F(GfxConfigManager,WebRenderDisabledWithAllowSoftwareGPUProcess)395 TEST_F(GfxConfigManager, WebRenderDisabledWithAllowSoftwareGPUProcess) {
396   mDisableHwCompositingNoWr = true;
397   mWrQualified = false;
398   mGPUProcessAllowSoftware = true;
399   ConfigureWebRender();
400 
401   EXPECT_TRUE(mFeatures.mWrQualified.IsEnabled());
402   EXPECT_FALSE(mFeatures.mWr.IsEnabled());
403   EXPECT_FALSE(mFeatures.mWrCompositor.IsEnabled());
404   EXPECT_FALSE(mFeatures.mWrAngle.IsEnabled());
405   EXPECT_FALSE(mFeatures.mWrDComp.IsEnabled());
406   EXPECT_FALSE(mFeatures.mWrPartial.IsEnabled());
407   EXPECT_FALSE(mFeatures.mHwCompositing.IsEnabled());
408   EXPECT_TRUE(mFeatures.mGPUProcess.IsEnabled());
409   EXPECT_TRUE(mFeatures.mD3D11HwAngle.IsEnabled());
410 }
411 
TEST_F(GfxConfigManager,WebRenderQualifiedOverrideDisabled)412 TEST_F(GfxConfigManager, WebRenderQualifiedOverrideDisabled) {
413   mWrQualifiedOverride.emplace(false);
414   ConfigureWebRender();
415 
416   EXPECT_FALSE(mFeatures.mWrQualified.IsEnabled());
417   EXPECT_FALSE(mFeatures.mWr.IsEnabled());
418   EXPECT_FALSE(mFeatures.mWrCompositor.IsEnabled());
419   EXPECT_FALSE(mFeatures.mWrAngle.IsEnabled());
420   EXPECT_FALSE(mFeatures.mWrDComp.IsEnabled());
421   EXPECT_FALSE(mFeatures.mWrPartial.IsEnabled());
422   EXPECT_TRUE(mFeatures.mHwCompositing.IsEnabled());
423   EXPECT_TRUE(mFeatures.mGPUProcess.IsEnabled());
424   EXPECT_TRUE(mFeatures.mD3D11HwAngle.IsEnabled());
425 }
426 
TEST_F(GfxConfigManager,WebRenderSafeMode)427 TEST_F(GfxConfigManager, WebRenderSafeMode) {
428   mSafeMode = true;
429   ConfigureWebRender();
430 
431   EXPECT_TRUE(mFeatures.mWrQualified.IsEnabled());
432   EXPECT_FALSE(mFeatures.mWr.IsEnabled());
433   EXPECT_FALSE(mFeatures.mWrCompositor.IsEnabled());
434   EXPECT_FALSE(mFeatures.mWrAngle.IsEnabled());
435   EXPECT_FALSE(mFeatures.mWrDComp.IsEnabled());
436   EXPECT_FALSE(mFeatures.mWrPartial.IsEnabled());
437   EXPECT_TRUE(mFeatures.mHwCompositing.IsEnabled());
438   EXPECT_TRUE(mFeatures.mGPUProcess.IsEnabled());
439   EXPECT_TRUE(mFeatures.mD3D11HwAngle.IsEnabled());
440 }
441 
TEST_F(GfxConfigManager,WebRenderEarlierThanWindows10)442 TEST_F(GfxConfigManager, WebRenderEarlierThanWindows10) {
443   mIsWin10OrLater = false;
444   ConfigureWebRender();
445 
446   EXPECT_TRUE(mFeatures.mWrQualified.IsEnabled());
447   EXPECT_TRUE(mFeatures.mWr.IsEnabled());
448   EXPECT_FALSE(mFeatures.mWrCompositor.IsEnabled());
449   EXPECT_TRUE(mFeatures.mWrAngle.IsEnabled());
450   EXPECT_FALSE(mFeatures.mWrDComp.IsEnabled());
451   EXPECT_TRUE(mFeatures.mWrPartial.IsEnabled());
452   EXPECT_TRUE(mFeatures.mHwCompositing.IsEnabled());
453   EXPECT_TRUE(mFeatures.mGPUProcess.IsEnabled());
454   EXPECT_TRUE(mFeatures.mD3D11HwAngle.IsEnabled());
455 }
456 
TEST_F(GfxConfigManager,WebRenderDCompDisabled)457 TEST_F(GfxConfigManager, WebRenderDCompDisabled) {
458   mWrDCompWinEnabled = false;
459   ConfigureWebRender();
460 
461   EXPECT_TRUE(mFeatures.mWrQualified.IsEnabled());
462   EXPECT_TRUE(mFeatures.mWr.IsEnabled());
463   EXPECT_FALSE(mFeatures.mWrCompositor.IsEnabled());
464   EXPECT_TRUE(mFeatures.mWrAngle.IsEnabled());
465   EXPECT_FALSE(mFeatures.mWrDComp.IsEnabled());
466   EXPECT_TRUE(mFeatures.mWrPartial.IsEnabled());
467   EXPECT_TRUE(mFeatures.mHwCompositing.IsEnabled());
468   EXPECT_TRUE(mFeatures.mGPUProcess.IsEnabled());
469   EXPECT_TRUE(mFeatures.mD3D11HwAngle.IsEnabled());
470 }
471 
TEST_F(GfxConfigManager,WebRenderDCompNotRequired)472 TEST_F(GfxConfigManager, WebRenderDCompNotRequired) {
473   mWrDCompWinEnabled = false;
474   mWrCompositorDCompRequired = false;
475   ConfigureWebRender();
476 
477   EXPECT_TRUE(mFeatures.mWrQualified.IsEnabled());
478   EXPECT_TRUE(mFeatures.mWr.IsEnabled());
479   EXPECT_TRUE(mFeatures.mWrCompositor.IsEnabled());
480   EXPECT_TRUE(mFeatures.mWrAngle.IsEnabled());
481   EXPECT_FALSE(mFeatures.mWrDComp.IsEnabled());
482   EXPECT_TRUE(mFeatures.mWrPartial.IsEnabled());
483   EXPECT_TRUE(mFeatures.mHwCompositing.IsEnabled());
484   EXPECT_TRUE(mFeatures.mGPUProcess.IsEnabled());
485   EXPECT_TRUE(mFeatures.mD3D11HwAngle.IsEnabled());
486 }
487 
TEST_F(GfxConfigManager,WebRenderForceAngleDisabled)488 TEST_F(GfxConfigManager, WebRenderForceAngleDisabled) {
489   mWrForceAngle = false;
490   ConfigureWebRender();
491 
492   EXPECT_TRUE(mFeatures.mWrQualified.IsEnabled());
493   EXPECT_TRUE(mFeatures.mWr.IsEnabled());
494   EXPECT_FALSE(mFeatures.mWrCompositor.IsEnabled());
495   EXPECT_FALSE(mFeatures.mWrAngle.IsEnabled());
496   EXPECT_FALSE(mFeatures.mWrDComp.IsEnabled());
497   EXPECT_TRUE(mFeatures.mWrPartial.IsEnabled());
498   EXPECT_TRUE(mFeatures.mHwCompositing.IsEnabled());
499   EXPECT_TRUE(mFeatures.mGPUProcess.IsEnabled());
500   EXPECT_TRUE(mFeatures.mD3D11HwAngle.IsEnabled());
501 }
502 
TEST_F(GfxConfigManager,WebRenderD3D11HwAngleDisabled)503 TEST_F(GfxConfigManager, WebRenderD3D11HwAngleDisabled) {
504   mFeatures.mD3D11HwAngle.UserDisable("", EmptyCString());
505   ConfigureWebRender();
506 
507   EXPECT_TRUE(mFeatures.mWrQualified.IsEnabled());
508   EXPECT_FALSE(mFeatures.mWr.IsEnabled());
509   EXPECT_FALSE(mFeatures.mWrCompositor.IsEnabled());
510   EXPECT_FALSE(mFeatures.mWrAngle.IsEnabled());
511   EXPECT_FALSE(mFeatures.mWrDComp.IsEnabled());
512   EXPECT_FALSE(mFeatures.mWrPartial.IsEnabled());
513   EXPECT_TRUE(mFeatures.mHwCompositing.IsEnabled());
514   EXPECT_TRUE(mFeatures.mGPUProcess.IsEnabled());
515   EXPECT_FALSE(mFeatures.mD3D11HwAngle.IsEnabled());
516 }
517 
TEST_F(GfxConfigManager,WebRenderD3D11HwAngleAndForceAngleDisabled)518 TEST_F(GfxConfigManager, WebRenderD3D11HwAngleAndForceAngleDisabled) {
519   mWrForceAngle = false;
520   mFeatures.mD3D11HwAngle.UserDisable("", EmptyCString());
521   ConfigureWebRender();
522 
523   EXPECT_TRUE(mFeatures.mWrQualified.IsEnabled());
524   EXPECT_TRUE(mFeatures.mWr.IsEnabled());
525   EXPECT_FALSE(mFeatures.mWrCompositor.IsEnabled());
526   EXPECT_FALSE(mFeatures.mWrAngle.IsEnabled());
527   EXPECT_FALSE(mFeatures.mWrDComp.IsEnabled());
528   EXPECT_TRUE(mFeatures.mWrPartial.IsEnabled());
529   EXPECT_TRUE(mFeatures.mHwCompositing.IsEnabled());
530   EXPECT_TRUE(mFeatures.mGPUProcess.IsEnabled());
531   EXPECT_FALSE(mFeatures.mD3D11HwAngle.IsEnabled());
532 }
533 
TEST_F(GfxConfigManager,WebRenderGPUProcessDisabled)534 TEST_F(GfxConfigManager, WebRenderGPUProcessDisabled) {
535   mFeatures.mGPUProcess.UserDisable("", EmptyCString());
536   ConfigureWebRender();
537 
538   EXPECT_TRUE(mFeatures.mWrQualified.IsEnabled());
539   EXPECT_FALSE(mFeatures.mWr.IsEnabled());
540   EXPECT_FALSE(mFeatures.mWrCompositor.IsEnabled());
541   EXPECT_FALSE(mFeatures.mWrAngle.IsEnabled());
542   EXPECT_FALSE(mFeatures.mWrDComp.IsEnabled());
543   EXPECT_FALSE(mFeatures.mWrPartial.IsEnabled());
544   EXPECT_TRUE(mFeatures.mHwCompositing.IsEnabled());
545   EXPECT_FALSE(mFeatures.mGPUProcess.IsEnabled());
546   EXPECT_TRUE(mFeatures.mD3D11HwAngle.IsEnabled());
547 }
548 
TEST_F(GfxConfigManager,WebRenderQualifiedAndBlocklistAllowQualified)549 TEST_F(GfxConfigManager, WebRenderQualifiedAndBlocklistAllowQualified) {
550   mMockGfxInfo->mStatusWr = nsIGfxInfo::FEATURE_ALLOW_QUALIFIED;
551   ConfigureWebRender();
552 
553   EXPECT_TRUE(mFeatures.mWrQualified.IsEnabled());
554   EXPECT_TRUE(mFeatures.mWr.IsEnabled());
555   EXPECT_TRUE(mFeatures.mWrCompositor.IsEnabled());
556   EXPECT_TRUE(mFeatures.mWrAngle.IsEnabled());
557   EXPECT_TRUE(mFeatures.mWrDComp.IsEnabled());
558   EXPECT_TRUE(mFeatures.mWrPartial.IsEnabled());
559   EXPECT_TRUE(mFeatures.mHwCompositing.IsEnabled());
560   EXPECT_TRUE(mFeatures.mGPUProcess.IsEnabled());
561   EXPECT_TRUE(mFeatures.mD3D11HwAngle.IsEnabled());
562 }
563 
TEST_F(GfxConfigManager,WebRenderQualifiedAndBlocklistAllowAlways)564 TEST_F(GfxConfigManager, WebRenderQualifiedAndBlocklistAllowAlways) {
565   mIsNightly = false;
566   mMockGfxInfo->mStatusWr = nsIGfxInfo::FEATURE_ALLOW_ALWAYS;
567   ConfigureWebRender();
568 
569   EXPECT_TRUE(mFeatures.mWrQualified.IsEnabled());
570   EXPECT_TRUE(mFeatures.mWr.IsEnabled());
571   EXPECT_TRUE(mFeatures.mWrCompositor.IsEnabled());
572   EXPECT_TRUE(mFeatures.mWrAngle.IsEnabled());
573   EXPECT_TRUE(mFeatures.mWrDComp.IsEnabled());
574   EXPECT_TRUE(mFeatures.mWrPartial.IsEnabled());
575   EXPECT_TRUE(mFeatures.mHwCompositing.IsEnabled());
576   EXPECT_TRUE(mFeatures.mGPUProcess.IsEnabled());
577   EXPECT_TRUE(mFeatures.mD3D11HwAngle.IsEnabled());
578 }
579 
TEST_F(GfxConfigManager,WebRenderNotQualifiedAndBlocklistAllowQualified)580 TEST_F(GfxConfigManager, WebRenderNotQualifiedAndBlocklistAllowQualified) {
581   mWrQualified = false;
582   mMockGfxInfo->mStatusWr = nsIGfxInfo::FEATURE_ALLOW_QUALIFIED;
583   ConfigureWebRender();
584 
585   EXPECT_TRUE(mFeatures.mWrQualified.IsEnabled());
586   EXPECT_FALSE(mFeatures.mWr.IsEnabled());
587   EXPECT_FALSE(mFeatures.mWrCompositor.IsEnabled());
588   EXPECT_FALSE(mFeatures.mWrAngle.IsEnabled());
589   EXPECT_FALSE(mFeatures.mWrDComp.IsEnabled());
590   EXPECT_FALSE(mFeatures.mWrPartial.IsEnabled());
591   EXPECT_TRUE(mFeatures.mHwCompositing.IsEnabled());
592   EXPECT_TRUE(mFeatures.mGPUProcess.IsEnabled());
593   EXPECT_TRUE(mFeatures.mD3D11HwAngle.IsEnabled());
594 }
595 
TEST_F(GfxConfigManager,WebRenderNotQualifiedAndBlocklistAllowAlways)596 TEST_F(GfxConfigManager, WebRenderNotQualifiedAndBlocklistAllowAlways) {
597   mWrQualified = false;
598   mIsNightly = false;
599   mMockGfxInfo->mStatusWr = nsIGfxInfo::FEATURE_ALLOW_ALWAYS;
600   ConfigureWebRender();
601 
602   EXPECT_TRUE(mFeatures.mWrQualified.IsEnabled());
603   EXPECT_TRUE(mFeatures.mWr.IsEnabled());
604   EXPECT_TRUE(mFeatures.mWrCompositor.IsEnabled());
605   EXPECT_TRUE(mFeatures.mWrAngle.IsEnabled());
606   EXPECT_TRUE(mFeatures.mWrDComp.IsEnabled());
607   EXPECT_TRUE(mFeatures.mWrPartial.IsEnabled());
608   EXPECT_TRUE(mFeatures.mHwCompositing.IsEnabled());
609   EXPECT_TRUE(mFeatures.mGPUProcess.IsEnabled());
610   EXPECT_TRUE(mFeatures.mD3D11HwAngle.IsEnabled());
611 }
612 
TEST_F(GfxConfigManager,WebRenderIntelBatteryNoPictureCaching)613 TEST_F(GfxConfigManager, WebRenderIntelBatteryNoPictureCaching) {
614   mWrPictureCaching = false;
615   mMockGfxInfo->mHasBattery.ref() = true;
616   mMockGfxInfo->mVendorId = "0x8086";
617   ConfigureWebRender();
618 
619   EXPECT_TRUE(mFeatures.mWrQualified.IsEnabled());
620   EXPECT_TRUE(mFeatures.mWr.IsEnabled());
621   EXPECT_FALSE(mFeatures.mWrCompositor.IsEnabled());
622   EXPECT_TRUE(mFeatures.mWrAngle.IsEnabled());
623   EXPECT_TRUE(mFeatures.mWrDComp.IsEnabled());
624   EXPECT_FALSE(mFeatures.mWrPartial.IsEnabled());
625   EXPECT_TRUE(mFeatures.mHwCompositing.IsEnabled());
626   EXPECT_TRUE(mFeatures.mGPUProcess.IsEnabled());
627   EXPECT_TRUE(mFeatures.mD3D11HwAngle.IsEnabled());
628 }
629 
TEST_F(GfxConfigManager,WebRenderIntelBatteryNoHwStretchingNotNightly)630 TEST_F(GfxConfigManager, WebRenderIntelBatteryNoHwStretchingNotNightly) {
631   mIsNightly = false;
632   mHwStretchingSupport = false;
633   mScaledResolution = true;
634   mMockGfxInfo->mHasBattery.ref() = true;
635   mMockGfxInfo->mVendorId = "0x8086";
636   ConfigureWebRender();
637 
638   EXPECT_FALSE(mFeatures.mWrQualified.IsEnabled());
639   EXPECT_FALSE(mFeatures.mWr.IsEnabled());
640   EXPECT_FALSE(mFeatures.mWrCompositor.IsEnabled());
641   EXPECT_FALSE(mFeatures.mWrAngle.IsEnabled());
642   EXPECT_FALSE(mFeatures.mWrDComp.IsEnabled());
643   EXPECT_FALSE(mFeatures.mWrPartial.IsEnabled());
644   EXPECT_TRUE(mFeatures.mHwCompositing.IsEnabled());
645   EXPECT_TRUE(mFeatures.mGPUProcess.IsEnabled());
646   EXPECT_TRUE(mFeatures.mD3D11HwAngle.IsEnabled());
647 }
648 
TEST_F(GfxConfigManager,WebRenderNoDWMSupportWin10)649 TEST_F(GfxConfigManager, WebRenderNoDWMSupportWin10) {
650   mDwmCompositionEnabled = false;
651   ConfigureWebRender();
652 
653   EXPECT_TRUE(mFeatures.mWrQualified.IsEnabled());
654   EXPECT_TRUE(mFeatures.mWr.IsEnabled());
655   EXPECT_TRUE(mFeatures.mWrCompositor.IsEnabled());
656   EXPECT_TRUE(mFeatures.mWrAngle.IsEnabled());
657   EXPECT_TRUE(mFeatures.mWrDComp.IsEnabled());
658   EXPECT_TRUE(mFeatures.mWrPartial.IsEnabled());
659   EXPECT_TRUE(mFeatures.mHwCompositing.IsEnabled());
660   EXPECT_TRUE(mFeatures.mGPUProcess.IsEnabled());
661   EXPECT_TRUE(mFeatures.mD3D11HwAngle.IsEnabled());
662 }
663 
TEST_F(GfxConfigManager,WebRenderNoDWMSupportWin7)664 TEST_F(GfxConfigManager, WebRenderNoDWMSupportWin7) {
665   mDwmCompositionEnabled = false;
666   mIsWin10OrLater = false;
667   ConfigureWebRender();
668 
669   EXPECT_TRUE(mFeatures.mWrQualified.IsEnabled());
670   EXPECT_FALSE(mFeatures.mWr.IsEnabled());
671   EXPECT_FALSE(mFeatures.mWrCompositor.IsEnabled());
672   EXPECT_FALSE(mFeatures.mWrAngle.IsEnabled());
673   EXPECT_FALSE(mFeatures.mWrDComp.IsEnabled());
674   EXPECT_FALSE(mFeatures.mWrPartial.IsEnabled());
675   EXPECT_TRUE(mFeatures.mHwCompositing.IsEnabled());
676   EXPECT_TRUE(mFeatures.mGPUProcess.IsEnabled());
677   EXPECT_TRUE(mFeatures.mD3D11HwAngle.IsEnabled());
678 }
679 
TEST_F(GfxConfigManager,WebRenderNoDWMSupportNotWindows)680 TEST_F(GfxConfigManager, WebRenderNoDWMSupportNotWindows) {
681   mDwmCompositionEnabled = false;
682   mIsWindows = false;
683   mIsWin10OrLater = false;
684   ConfigureWebRender();
685 
686   EXPECT_TRUE(mFeatures.mWrQualified.IsEnabled());
687   EXPECT_TRUE(mFeatures.mWr.IsEnabled());
688   EXPECT_FALSE(mFeatures.mWrCompositor.IsEnabled());
689   EXPECT_TRUE(mFeatures.mWrAngle.IsEnabled());
690   EXPECT_FALSE(mFeatures.mWrDComp.IsEnabled());
691   EXPECT_TRUE(mFeatures.mWrPartial.IsEnabled());
692   EXPECT_TRUE(mFeatures.mHwCompositing.IsEnabled());
693   EXPECT_TRUE(mFeatures.mGPUProcess.IsEnabled());
694   EXPECT_TRUE(mFeatures.mD3D11HwAngle.IsEnabled());
695 }
696 
TEST_F(GfxConfigManager,WebRenderHighRefreshRateNightly)697 TEST_F(GfxConfigManager, WebRenderHighRefreshRateNightly) {
698   mIsNightly = true;
699   mMockGfxInfo->mMaxRefreshRate = 120;
700   ConfigureWebRender();
701 
702   EXPECT_TRUE(mFeatures.mWrQualified.IsEnabled());
703   EXPECT_TRUE(mFeatures.mWr.IsEnabled());
704   EXPECT_TRUE(mFeatures.mWrCompositor.IsEnabled());
705   EXPECT_TRUE(mFeatures.mWrAngle.IsEnabled());
706   EXPECT_TRUE(mFeatures.mWrDComp.IsEnabled());
707   EXPECT_TRUE(mFeatures.mWrPartial.IsEnabled());
708   EXPECT_TRUE(mFeatures.mHwCompositing.IsEnabled());
709   EXPECT_TRUE(mFeatures.mGPUProcess.IsEnabled());
710   EXPECT_TRUE(mFeatures.mD3D11HwAngle.IsEnabled());
711 }
712 
TEST_F(GfxConfigManager,WebRenderHighRefreshRateNotNightly)713 TEST_F(GfxConfigManager, WebRenderHighRefreshRateNotNightly) {
714   mIsNightly = false;
715   mMockGfxInfo->mMaxRefreshRate = 120;
716   ConfigureWebRender();
717 
718   EXPECT_FALSE(mFeatures.mWrQualified.IsEnabled());
719   EXPECT_FALSE(mFeatures.mWr.IsEnabled());
720   EXPECT_FALSE(mFeatures.mWrCompositor.IsEnabled());
721   EXPECT_FALSE(mFeatures.mWrAngle.IsEnabled());
722   EXPECT_FALSE(mFeatures.mWrDComp.IsEnabled());
723   EXPECT_FALSE(mFeatures.mWrPartial.IsEnabled());
724   EXPECT_TRUE(mFeatures.mHwCompositing.IsEnabled());
725   EXPECT_TRUE(mFeatures.mGPUProcess.IsEnabled());
726   EXPECT_TRUE(mFeatures.mD3D11HwAngle.IsEnabled());
727 }
728 
TEST_F(GfxConfigManager,WebRenderAtRefreshRateThreshold)729 TEST_F(GfxConfigManager, WebRenderAtRefreshRateThreshold) {
730   mIsNightly = false;
731   mMockGfxInfo->mMaxRefreshRate = 60;
732   ConfigureWebRender();
733 
734   EXPECT_TRUE(mFeatures.mWrQualified.IsEnabled());
735   EXPECT_TRUE(mFeatures.mWr.IsEnabled());
736   EXPECT_TRUE(mFeatures.mWrCompositor.IsEnabled());
737   EXPECT_TRUE(mFeatures.mWrAngle.IsEnabled());
738   EXPECT_TRUE(mFeatures.mWrDComp.IsEnabled());
739   EXPECT_TRUE(mFeatures.mWrPartial.IsEnabled());
740   EXPECT_TRUE(mFeatures.mHwCompositing.IsEnabled());
741   EXPECT_TRUE(mFeatures.mGPUProcess.IsEnabled());
742   EXPECT_TRUE(mFeatures.mD3D11HwAngle.IsEnabled());
743 }
744