[go: nahoru, domu]

blob: 5fc5dac4d2c031e2ed31ecf1b56cf83ca94924eb [file] [log] [blame]
Sadrul Habib Chowdhury6b9697f2017-12-08 04:13:431// Copyright 2017 The Chromium Authors. All rights reserved.
2// 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"
8#include "base/test/scoped_task_environment.h"
9#include "base/threading/thread_task_runner_handle.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;
19 auto task_runner = base::ThreadTaskRunnerHandle::Get();
20 // 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;
28 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
29 runloop.QuitClosure());
30 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