Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / base / view_prop_unittest.cc
blobd369c94fe92202d228c3b8875293ef9efb3f210b
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
3 // found in the LICENSE file.
5 #include "testing/gtest/include/gtest/gtest.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "ui/base/view_prop.h"
10 namespace {
11 const char kKey1[] = "key_1";
12 const char kKey2[] = "key_2";
13 } // namespace
15 namespace ui {
17 // Test a handful of viewprop assertions.
18 TEST(ViewPropTest, Basic) {
19 gfx::AcceleratedWidget nv1 = reinterpret_cast<gfx::AcceleratedWidget>(1);
20 gfx::AcceleratedWidget nv2 = reinterpret_cast<gfx::AcceleratedWidget>(2);
22 void* data1 = reinterpret_cast<void*>(11);
23 void* data2 = reinterpret_cast<void*>(12);
25 // Initial value for a new view/key pair should be NULL.
26 EXPECT_EQ(NULL, ViewProp::GetValue(nv1, kKey1));
29 // Register a value for a view/key pair.
30 ViewProp prop(nv1, kKey1, data1);
31 EXPECT_EQ(data1, ViewProp::GetValue(nv1, kKey1));
34 // The property fell out of scope, so the value should now be NULL.
35 EXPECT_EQ(NULL, ViewProp::GetValue(nv1, kKey1));
38 // Register a value for a view/key pair.
39 scoped_ptr<ViewProp> v1(new ViewProp(nv1, kKey1, data1));
40 EXPECT_EQ(data1, ViewProp::GetValue(nv1, kKey1));
42 // Register a value for the same view/key pair.
43 scoped_ptr<ViewProp> v2(new ViewProp(nv1, kKey1, data2));
44 // The new value should take over.
45 EXPECT_EQ(data2, ViewProp::GetValue(nv1, kKey1));
47 // Null out the first ViewProp, which should NULL out the value.
48 v1.reset(NULL);
49 EXPECT_EQ(NULL, ViewProp::GetValue(nv1, kKey1));
52 // The property fell out of scope, so the value should now be NULL.
53 EXPECT_EQ(NULL, ViewProp::GetValue(nv1, kKey1));
56 // Register a value for a view/key pair.
57 scoped_ptr<ViewProp> v1(new ViewProp(nv1, kKey1, data1));
58 scoped_ptr<ViewProp> v2(new ViewProp(nv2, kKey2, data2));
59 EXPECT_EQ(data1, ViewProp::GetValue(nv1, kKey1));
60 EXPECT_EQ(data2, ViewProp::GetValue(nv2, kKey2));
62 v1.reset(NULL);
63 EXPECT_EQ(NULL, ViewProp::GetValue(nv1, kKey1));
64 EXPECT_EQ(data2, ViewProp::GetValue(nv2, kKey2));
66 v2.reset(NULL);
67 EXPECT_EQ(NULL, ViewProp::GetValue(nv1, kKey1));
68 EXPECT_EQ(NULL, ViewProp::GetValue(nv2, kKey2));
72 } // namespace ui