[go: nahoru, domu]

blob: 6c4eda8ab1ae7a60ff52331ef004e19ba5ebcf14 [file] [log] [blame]
Avi Drissman3f7a9d82022-09-08 20:55:421// Copyright 2017 The Chromium Authors
Sadrul Habib Chowdhury6b9697f2017-12-08 04:13:432// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "cc/raster/staging_buffer_pool.h"
6
Sadrul Habib Chowdhury6b9697f2017-12-08 04:13:437#include "base/run_loop.h"
Sean Maher5b9af51f2022-11-21 15:32:478#include "base/task/single_thread_task_runner.h"
Gabriel Charettec7108742019-08-23 03:31:409#include "base/test/task_environment.h"
kylechardfe762f2018-02-26 17:00:0110#include "components/viz/test/test_context_provider.h"
Sadrul Habib Chowdhury6b9697f2017-12-08 04:13:4311#include "testing/gtest/include/gtest/gtest.h"
12
13namespace cc {
14
15TEST(StagingBufferPoolTest, ShutdownImmediatelyAfterCreation) {
kylechardfe762f2018-02-26 17:00:0116 auto context_provider = viz::TestContextProvider::CreateWorker();
Sadrul Habib Chowdhury6b9697f2017-12-08 04:13:4317 bool use_partial_raster = false;
18 int max_staging_buffer_usage_in_bytes = 1024;
Sean Maher5b9af51f2022-11-21 15:32:4719 auto task_runner = base::SingleThreadTaskRunner::GetCurrentDefault();
Sadrul Habib Chowdhury6b9697f2017-12-08 04:13:4320 // Create a StagingBufferPool and immediately shut it down.
21 auto pool = std::make_unique<StagingBufferPool>(
danakj2b8f93fa2018-04-27 19:31:2922 task_runner.get(), context_provider.get(), use_partial_raster,
23 max_staging_buffer_usage_in_bytes);
Sadrul Habib Chowdhury6b9697f2017-12-08 04:13:4324 pool->Shutdown();
25 // Flush the message loop.
26 auto flush_message_loop = [] {
27 base::RunLoop runloop;
Sean Maher5b9af51f2022-11-21 15:32:4728 base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
29 FROM_HERE, runloop.QuitClosure());
Sadrul Habib Chowdhury6b9697f2017-12-08 04:13:4330 runloop.Run();
31 };
32
33 // Constructing the pool does a post-task to add itself as an observer. So
34 // allow for that registration to complete first.
35 flush_message_loop();
36
37 // Now, destroy the pool, and trigger a notification from the
Takashi Sakamoto370e46f2018-10-05 02:51:1038 // MemoryPressureListener.
Sadrul Habib Chowdhury6b9697f2017-12-08 04:13:4339 pool = nullptr;
Takashi Sakamoto370e46f2018-10-05 02:51:1040 base::MemoryPressureListener::SimulatePressureNotification(
41 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL);
Sadrul Habib Chowdhury6b9697f2017-12-08 04:13:4342 // Allow the callbacks in the observers to run.
43 flush_message_loop();
44 // No crash.
45}
46
47} // namespace cc