• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // 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 
9 #include "base/memory/ptr_util.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 
12 namespace base {
13 namespace {
14 
15 struct TestSupportsUserData : public SupportsUserData {};
16 
17 struct UsesItself : public SupportsUserData::Data {
UsesItselfbase::__anonb5d009600111::UsesItself18   UsesItself(SupportsUserData* supports_user_data, const void* key)
19       : supports_user_data_(supports_user_data),
20         key_(key) {
21   }
22 
~UsesItselfbase::__anonb5d009600111::UsesItself23   ~UsesItself() override {
24     EXPECT_EQ(nullptr, supports_user_data_->GetUserData(key_));
25   }
26 
27   SupportsUserData* supports_user_data_;
28   const void* key_;
29 };
30 
TEST(SupportsUserDataTest,ClearWorksRecursively)31 TEST(SupportsUserDataTest, ClearWorksRecursively) {
32   TestSupportsUserData supports_user_data;
33   char key = 0;
34   supports_user_data.SetUserData(
35       &key, std::make_unique<UsesItself>(&supports_user_data, &key));
36   // Destruction of supports_user_data runs the actual test.
37 }
38 
39 }  // namespace
40 }  // namespace base
41