blob: 2e0a724bda90d2c762fdf46e63be7113707b75c0 [file] [log] [blame]
[email protected]1f7d92af2014-05-29 20:10:361// Copyright 2014 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 "base/supports_user_data.h"
6
7#include <vector>
8
sdefresneae5e2d22017-02-13 11:49:269#include "base/memory/ptr_util.h"
[email protected]1f7d92af2014-05-29 20:10:3610#include "testing/gtest/include/gtest/gtest.h"
11
12namespace base {
13namespace {
14
15struct TestSupportsUserData : public SupportsUserData {};
16
17struct UsesItself : public SupportsUserData::Data {
18 UsesItself(SupportsUserData* supports_user_data, const void* key)
19 : supports_user_data_(supports_user_data),
20 key_(key) {
21 }
22
dcheng56488182014-10-21 10:54:5123 ~UsesItself() override {
Ivan Kotenkova16212a52017-11-08 12:37:3324 EXPECT_EQ(nullptr, supports_user_data_->GetUserData(key_));
[email protected]1f7d92af2014-05-29 20:10:3625 }
26
27 SupportsUserData* supports_user_data_;
28 const void* key_;
29};
30
31TEST(SupportsUserDataTest, ClearWorksRecursively) {
32 TestSupportsUserData supports_user_data;
33 char key = 0;
sdefresneae5e2d22017-02-13 11:49:2634 supports_user_data.SetUserData(
Jeremy Roman9532f252017-08-16 23:27:2435 &key, std::make_unique<UsesItself>(&supports_user_data, &key));
[email protected]1f7d92af2014-05-29 20:10:3636 // Destruction of supports_user_data runs the actual test.
37}
38
39} // namespace
40} // namespace base