File: shared_context_state_unittest.cc

package info (click to toggle)
qt6-webengine 6.8.2%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 3,834,164 kB
  • sloc: cpp: 20,319,195; ansic: 8,076,006; javascript: 3,260,843; asm: 839,896; python: 814,858; xml: 506,536; java: 215,396; sh: 104,539; objc: 99,126; perl: 71,598; cs: 50,882; fortran: 24,137; makefile: 24,065; sql: 19,787; pascal: 13,725; tcl: 9,530; yacc: 8,012; php: 6,830; lisp: 3,457; lex: 1,323; ruby: 901; awk: 339; csh: 120; sed: 37
file content (100 lines) | stat: -rw-r--r-- 3,611 bytes parent folder | download | duplicates (2)
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
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "gpu/command_buffer/service/shared_context_state.h"

#include <limits>
#include <memory>
#include <string>
#include <utility>

#include "base/command_line.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/ptr_util.h"
#include "gpu/command_buffer/common/gles2_cmd_utils.h"
#include "gpu/command_buffer/service/context_state_test_helpers.h"
#include "gpu/command_buffer/service/feature_info.h"
#include "gpu/command_buffer/service/test_helper.h"
#include "gpu/config/gpu_driver_bug_workarounds.h"
#include "gpu/config/gpu_feature_info.h"
#include "gpu/config/gpu_preferences.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gl/gl_context_stub.h"
#include "ui/gl/gl_mock.h"
#include "ui/gl/gl_surface_stub.h"
#include "ui/gl/init/gl_factory.h"
#include "ui/gl/test/gl_surface_test_support.h"

using ::testing::_;
using ::testing::InSequence;
using ::testing::Return;
using ::testing::SetArgPointee;
using ::testing::StrictMock;

namespace gpu {

class SharedContextStateTest : public ::testing::Test {
 public:
  SharedContextStateTest() = default;
};

TEST_F(SharedContextStateTest, InitFailsIfLostContext) {
  const ContextType context_type = CONTEXT_TYPE_OPENGLES2;

  // For easier substring/extension matching
  gl::SetGLGetProcAddressProc(gl::MockGLInterface::GetGLProcAddress);
  auto* display = gl::GLSurfaceTestSupport::InitializeOneOffWithMockBindings();
  ASSERT_TRUE(display);
  {
    StrictMock<gl::MockGLInterface> gl_interface;
    gl::MockGLInterface::SetGLInterface(&gl_interface);

    InSequence sequence;

    auto surface = base::MakeRefCounted<gl::GLSurfaceStub>();
    auto context = base::MakeRefCounted<gl::GLContextStub>();
    const char gl_version[] = "2.1";
    context->SetGLVersionString(gl_version);
    const char gl_extensions[] = "GL_KHR_robustness";
    context->SetExtensionsString(gl_extensions);

    context->MakeCurrent(surface.get());

    GpuFeatureInfo gpu_feature_info;
    GpuDriverBugWorkarounds workarounds;
    auto feature_info =
        base::MakeRefCounted<gles2::FeatureInfo>(workarounds, gpu_feature_info);
    gles2::TestHelper::SetupFeatureInfoInitExpectationsWithGLVersion(
        &gl_interface, gl_extensions, "", gl_version, context_type);
    feature_info->Initialize(gpu::CONTEXT_TYPE_OPENGLES2,
                             false /* passthrough */,
                             gles2::DisallowedFeatures());

    // Setup expectations for SharedContextState::InitializeGL().
    EXPECT_CALL(gl_interface, GetIntegerv(GL_MAX_VERTEX_ATTRIBS, _))
        .WillOnce(SetArgPointee<1>(8u))
        .RetiresOnSaturation();
    EXPECT_CALL(gl_interface,
                GetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, _))
        .WillOnce(SetArgPointee<1>(8u))
        .RetiresOnSaturation();
    ContextStateTestHelpers::SetupInitState(&gl_interface, feature_info.get(),
                                            gfx::Size(1, 1));

    EXPECT_CALL(gl_interface, GetGraphicsResetStatusARB())
        .WillOnce(Return(GL_GUILTY_CONTEXT_RESET_ARB));

    auto shared_context_state = base::MakeRefCounted<SharedContextState>(
        new gl::GLShareGroup(), surface, context,
        false /* use_virtualized_gl_contexts */, base::DoNothing(),
        GrContextType::kGL);

    bool result =
        shared_context_state->InitializeGL(GpuPreferences(), feature_info);
    EXPECT_FALSE(result);
  }
  gl::GLSurfaceTestSupport::ShutdownGL(display);
}

}  // namespace gpu