| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/base/view_prop.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 5 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 6 | 10 |
| 7 #include "base/memory/scoped_ptr.h" | |
| 8 #include "ui/base/view_prop.h" | |
| 9 | |
| 10 namespace { | 11 namespace { |
| 11 const char kKey1[] = "key_1"; | 12 const char kKey1[] = "key_1"; |
| 12 const char kKey2[] = "key_2"; | 13 const char kKey2[] = "key_2"; |
| 13 } // namespace | 14 } // namespace |
| 14 | 15 |
| 15 namespace ui { | 16 namespace ui { |
| 16 | 17 |
| 17 // Test a handful of viewprop assertions. | 18 // Test a handful of viewprop assertions. |
| 18 TEST(ViewPropTest, Basic) { | 19 TEST(ViewPropTest, Basic) { |
| 19 gfx::AcceleratedWidget nv1 = reinterpret_cast<gfx::AcceleratedWidget>(1); | 20 gfx::AcceleratedWidget nv1 = reinterpret_cast<gfx::AcceleratedWidget>(1); |
| 20 gfx::AcceleratedWidget nv2 = reinterpret_cast<gfx::AcceleratedWidget>(2); | 21 gfx::AcceleratedWidget nv2 = reinterpret_cast<gfx::AcceleratedWidget>(2); |
| 21 | 22 |
| 22 void* data1 = reinterpret_cast<void*>(11); | 23 void* data1 = reinterpret_cast<void*>(11); |
| 23 void* data2 = reinterpret_cast<void*>(12); | 24 void* data2 = reinterpret_cast<void*>(12); |
| 24 | 25 |
| 25 // Initial value for a new view/key pair should be NULL. | 26 // Initial value for a new view/key pair should be NULL. |
| 26 EXPECT_EQ(NULL, ViewProp::GetValue(nv1, kKey1)); | 27 EXPECT_EQ(NULL, ViewProp::GetValue(nv1, kKey1)); |
| 27 | 28 |
| 28 { | 29 { |
| 29 // Register a value for a view/key pair. | 30 // Register a value for a view/key pair. |
| 30 ViewProp prop(nv1, kKey1, data1); | 31 ViewProp prop(nv1, kKey1, data1); |
| 31 EXPECT_EQ(data1, ViewProp::GetValue(nv1, kKey1)); | 32 EXPECT_EQ(data1, ViewProp::GetValue(nv1, kKey1)); |
| 32 } | 33 } |
| 33 | 34 |
| 34 // The property fell out of scope, so the value should now be NULL. | 35 // The property fell out of scope, so the value should now be NULL. |
| 35 EXPECT_EQ(NULL, ViewProp::GetValue(nv1, kKey1)); | 36 EXPECT_EQ(NULL, ViewProp::GetValue(nv1, kKey1)); |
| 36 | 37 |
| 37 { | 38 { |
| 38 // Register a value for a view/key pair. | 39 // Register a value for a view/key pair. |
| 39 scoped_ptr<ViewProp> v1(new ViewProp(nv1, kKey1, data1)); | 40 std::unique_ptr<ViewProp> v1(new ViewProp(nv1, kKey1, data1)); |
| 40 EXPECT_EQ(data1, ViewProp::GetValue(nv1, kKey1)); | 41 EXPECT_EQ(data1, ViewProp::GetValue(nv1, kKey1)); |
| 41 | 42 |
| 42 // Register a value for the same view/key pair. | 43 // Register a value for the same view/key pair. |
| 43 scoped_ptr<ViewProp> v2(new ViewProp(nv1, kKey1, data2)); | 44 std::unique_ptr<ViewProp> v2(new ViewProp(nv1, kKey1, data2)); |
| 44 // The new value should take over. | 45 // The new value should take over. |
| 45 EXPECT_EQ(data2, ViewProp::GetValue(nv1, kKey1)); | 46 EXPECT_EQ(data2, ViewProp::GetValue(nv1, kKey1)); |
| 46 | 47 |
| 47 // Null out the first ViewProp, which should NULL out the value. | 48 // Null out the first ViewProp, which should NULL out the value. |
| 48 v1.reset(NULL); | 49 v1.reset(NULL); |
| 49 EXPECT_EQ(NULL, ViewProp::GetValue(nv1, kKey1)); | 50 EXPECT_EQ(NULL, ViewProp::GetValue(nv1, kKey1)); |
| 50 } | 51 } |
| 51 | 52 |
| 52 // The property fell out of scope, so the value should now be NULL. | 53 // The property fell out of scope, so the value should now be NULL. |
| 53 EXPECT_EQ(NULL, ViewProp::GetValue(nv1, kKey1)); | 54 EXPECT_EQ(NULL, ViewProp::GetValue(nv1, kKey1)); |
| 54 | 55 |
| 55 { | 56 { |
| 56 // Register a value for a view/key pair. | 57 // Register a value for a view/key pair. |
| 57 scoped_ptr<ViewProp> v1(new ViewProp(nv1, kKey1, data1)); | 58 std::unique_ptr<ViewProp> v1(new ViewProp(nv1, kKey1, data1)); |
| 58 scoped_ptr<ViewProp> v2(new ViewProp(nv2, kKey2, data2)); | 59 std::unique_ptr<ViewProp> v2(new ViewProp(nv2, kKey2, data2)); |
| 59 EXPECT_EQ(data1, ViewProp::GetValue(nv1, kKey1)); | 60 EXPECT_EQ(data1, ViewProp::GetValue(nv1, kKey1)); |
| 60 EXPECT_EQ(data2, ViewProp::GetValue(nv2, kKey2)); | 61 EXPECT_EQ(data2, ViewProp::GetValue(nv2, kKey2)); |
| 61 | 62 |
| 62 v1.reset(NULL); | 63 v1.reset(NULL); |
| 63 EXPECT_EQ(NULL, ViewProp::GetValue(nv1, kKey1)); | 64 EXPECT_EQ(NULL, ViewProp::GetValue(nv1, kKey1)); |
| 64 EXPECT_EQ(data2, ViewProp::GetValue(nv2, kKey2)); | 65 EXPECT_EQ(data2, ViewProp::GetValue(nv2, kKey2)); |
| 65 | 66 |
| 66 v2.reset(NULL); | 67 v2.reset(NULL); |
| 67 EXPECT_EQ(NULL, ViewProp::GetValue(nv1, kKey1)); | 68 EXPECT_EQ(NULL, ViewProp::GetValue(nv1, kKey1)); |
| 68 EXPECT_EQ(NULL, ViewProp::GetValue(nv2, kKey2)); | 69 EXPECT_EQ(NULL, ViewProp::GetValue(nv2, kKey2)); |
| 69 } | 70 } |
| 70 } | 71 } |
| 71 | 72 |
| 72 } // namespace ui | 73 } // namespace ui |
| OLD | NEW |