OLD | NEW |
| (Empty) |
1 // Copyright (c) 2006-2008 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 <string> | |
6 | |
7 #include "gpu/np_utils/dynamic_np_object.h" | |
8 #include "gpu/np_utils/np_browser_stub.h" | |
9 #include "gpu/np_utils/np_utils.h" | |
10 #include "testing/gmock/include/gmock/gmock.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 using testing::Return; | |
14 using testing::StrictMock; | |
15 | |
16 namespace np_utils { | |
17 | |
18 class NPDynamicNPObjectTest : public testing::Test { | |
19 protected: | |
20 virtual void SetUp() { | |
21 object_ = NPCreateObject<DynamicNPObject>(NULL); | |
22 } | |
23 | |
24 StubNPBrowser stub_browser_; | |
25 NPObjectPointer<DynamicNPObject> object_; | |
26 }; | |
27 | |
28 TEST_F(NPDynamicNPObjectTest, HasPropertyReturnsFalseForMissingProperty) { | |
29 EXPECT_FALSE(NPHasProperty(NULL, object_, "missing")); | |
30 } | |
31 | |
32 TEST_F(NPDynamicNPObjectTest, GetPropertyReturnsFalseForMissingProperty) { | |
33 int32 r; | |
34 EXPECT_FALSE(NPGetProperty(NULL, object_, "missing", &r)); | |
35 } | |
36 | |
37 TEST_F(NPDynamicNPObjectTest, CanSetProperty) { | |
38 EXPECT_TRUE(NPSetProperty(NULL, object_, "foo", 7)); | |
39 int32 r; | |
40 EXPECT_TRUE(NPHasProperty(NULL, object_, "foo")); | |
41 EXPECT_TRUE(NPGetProperty(NULL, object_, "foo", &r)); | |
42 EXPECT_EQ(7, r); | |
43 } | |
44 | |
45 TEST_F(NPDynamicNPObjectTest, CanRemoveProperty) { | |
46 EXPECT_TRUE(NPSetProperty(NULL, object_, "foo", 7)); | |
47 EXPECT_TRUE(NPHasProperty(NULL, object_, "foo")); | |
48 EXPECT_FALSE(NPRemoveProperty(NULL, object_, "foo")); | |
49 EXPECT_FALSE(NPHasProperty(NULL, object_, "foo")); | |
50 int32 r; | |
51 EXPECT_FALSE(NPGetProperty(NULL, object_, "foo", &r)); | |
52 } | |
53 | |
54 TEST_F(NPDynamicNPObjectTest, CanEnumerateProperties) { | |
55 EXPECT_TRUE(NPSetProperty(NULL, object_, "foo", 7)); | |
56 | |
57 NPIdentifier* names; | |
58 uint32 num_names; | |
59 EXPECT_TRUE(object_->_class->enumerate(object_.Get(), &names, &num_names)); | |
60 | |
61 EXPECT_EQ(1, num_names); | |
62 EXPECT_EQ(NPBrowser::get()->GetStringIdentifier("foo"), names[0]); | |
63 | |
64 NPBrowser::get()->MemFree(names); | |
65 } | |
66 | |
67 // Properties should not be | |
68 TEST_F(NPDynamicNPObjectTest, InvalidateNullsObjectProperties) { | |
69 EXPECT_EQ(1, object_->referenceCount); | |
70 { | |
71 EXPECT_TRUE(NPSetProperty(NULL, object_, "foo", object_)); | |
72 EXPECT_TRUE(NPHasProperty(NULL, object_, "foo")); | |
73 object_->_class->invalidate(object_.Get()); | |
74 EXPECT_TRUE(NPHasProperty(NULL, object_, "foo")); | |
75 NPObjectPointer<DynamicNPObject> r; | |
76 EXPECT_TRUE(NPGetProperty(NULL, object_, "foo", &r)); | |
77 EXPECT_TRUE(NULL == r.Get()); | |
78 } | |
79 // Invalidate did not release object | |
80 EXPECT_EQ(2, object_->referenceCount); | |
81 NPBrowser::get()->ReleaseObject(object_.Get()); | |
82 } | |
83 } // namespace np_utils | |
OLD | NEW |