| 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 "gpu/np_utils/np_class.h" | |
| 6 #include "gpu/np_utils/np_object_mock.h" | |
| 7 #include "testing/gmock/include/gmock/gmock.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 | |
| 10 using testing::StrictMock; | |
| 11 | |
| 12 namespace np_utils { | |
| 13 | |
| 14 class NPClassTest : public testing::Test { | |
| 15 protected: | |
| 16 virtual void SetUp() { | |
| 17 np_class = NPGetClass<StrictMock<MockNPObject> >(); | |
| 18 | |
| 19 // Dummy identifier is never used with real NPAPI so it can point to | |
| 20 // anything. | |
| 21 identifier = this; | |
| 22 } | |
| 23 | |
| 24 virtual void TearDown() { | |
| 25 } | |
| 26 | |
| 27 NPP_t npp_; | |
| 28 const NPClass* np_class; | |
| 29 NPIdentifier identifier; | |
| 30 NPVariant args[3]; | |
| 31 NPVariant result; | |
| 32 }; | |
| 33 | |
| 34 TEST_F(NPClassTest, AllocateAndDeallocateObject) { | |
| 35 MockNPObject* object = static_cast<MockNPObject*>( | |
| 36 np_class->allocate(&npp_, const_cast<NPClass*>(np_class))); | |
| 37 EXPECT_TRUE(NULL != object); | |
| 38 | |
| 39 np_class->deallocate(object); | |
| 40 } | |
| 41 | |
| 42 TEST_F(NPClassTest, InvalidateForwards) { | |
| 43 MockNPObject* object = static_cast<MockNPObject*>( | |
| 44 np_class->allocate(&npp_, const_cast<NPClass*>(np_class))); | |
| 45 | |
| 46 EXPECT_CALL(*object, Invalidate()); | |
| 47 np_class->invalidate(object); | |
| 48 | |
| 49 np_class->deallocate(object); | |
| 50 } | |
| 51 | |
| 52 TEST_F(NPClassTest, HasMethodForwards) { | |
| 53 MockNPObject* object = static_cast<MockNPObject*>( | |
| 54 np_class->allocate(&npp_, const_cast<NPClass*>(np_class))); | |
| 55 | |
| 56 EXPECT_CALL(*object, HasMethod(identifier)); | |
| 57 np_class->hasMethod(object, identifier); | |
| 58 | |
| 59 np_class->deallocate(object); | |
| 60 } | |
| 61 | |
| 62 TEST_F(NPClassTest, InvokeForwards) { | |
| 63 MockNPObject* object = static_cast<MockNPObject*>( | |
| 64 np_class->allocate(&npp_, const_cast<NPClass*>(np_class))); | |
| 65 | |
| 66 EXPECT_CALL(*object, Invoke(identifier, args, 3, &result)); | |
| 67 np_class->invoke(object, identifier, args, 3, &result); | |
| 68 | |
| 69 np_class->deallocate(object); | |
| 70 } | |
| 71 | |
| 72 TEST_F(NPClassTest, InvokeDefaultForwards) { | |
| 73 MockNPObject* object = static_cast<MockNPObject*>( | |
| 74 np_class->allocate(&npp_, const_cast<NPClass*>(np_class))); | |
| 75 | |
| 76 EXPECT_CALL(*object, InvokeDefault(args, 3, &result)); | |
| 77 np_class->invokeDefault(object, args, 3, &result); | |
| 78 | |
| 79 np_class->deallocate(object); | |
| 80 } | |
| 81 | |
| 82 TEST_F(NPClassTest, HasPropertyForwards) { | |
| 83 MockNPObject* object = static_cast<MockNPObject*>( | |
| 84 np_class->allocate(&npp_, const_cast<NPClass*>(np_class))); | |
| 85 | |
| 86 EXPECT_CALL(*object, HasProperty(identifier)); | |
| 87 np_class->hasProperty(object, identifier); | |
| 88 | |
| 89 np_class->deallocate(object); | |
| 90 } | |
| 91 | |
| 92 TEST_F(NPClassTest, GetPropertyForwards) { | |
| 93 MockNPObject* object = static_cast<MockNPObject*>( | |
| 94 np_class->allocate(&npp_, const_cast<NPClass*>(np_class))); | |
| 95 | |
| 96 EXPECT_CALL(*object, GetProperty(identifier, &result)); | |
| 97 np_class->getProperty(object, identifier, &result); | |
| 98 | |
| 99 np_class->deallocate(object); | |
| 100 } | |
| 101 | |
| 102 TEST_F(NPClassTest, SetPropertyForwards) { | |
| 103 MockNPObject* object = static_cast<MockNPObject*>( | |
| 104 np_class->allocate(&npp_, const_cast<NPClass*>(np_class))); | |
| 105 | |
| 106 EXPECT_CALL(*object, SetProperty(identifier, &result)); | |
| 107 np_class->setProperty(object, identifier, &result); | |
| 108 | |
| 109 np_class->deallocate(object); | |
| 110 } | |
| 111 | |
| 112 TEST_F(NPClassTest, RemovePropertyForwards) { | |
| 113 MockNPObject* object = static_cast<MockNPObject*>( | |
| 114 np_class->allocate(&npp_, const_cast<NPClass*>(np_class))); | |
| 115 | |
| 116 EXPECT_CALL(*object, RemoveProperty(identifier)); | |
| 117 np_class->removeProperty(object, identifier); | |
| 118 | |
| 119 np_class->deallocate(object); | |
| 120 } | |
| 121 | |
| 122 TEST_F(NPClassTest, EnumerateForwards) { | |
| 123 MockNPObject* object = static_cast<MockNPObject*>( | |
| 124 np_class->allocate(&npp_, const_cast<NPClass*>(np_class))); | |
| 125 | |
| 126 NPIdentifier* identifier = NULL; | |
| 127 uint32_t count; | |
| 128 EXPECT_CALL(*object, Enumerate(&identifier, &count)); | |
| 129 np_class->enumerate(object, &identifier, &count); | |
| 130 | |
| 131 np_class->deallocate(object); | |
| 132 } | |
| 133 | |
| 134 TEST_F(NPClassTest, ConstructForwards) { | |
| 135 MockNPObject* object = static_cast<MockNPObject*>( | |
| 136 np_class->allocate(&npp_, const_cast<NPClass*>(np_class))); | |
| 137 | |
| 138 EXPECT_CALL(*object, Construct(args, 3, &result)); | |
| 139 np_class->construct(object, args, 3, &result); | |
| 140 | |
| 141 np_class->deallocate(object); | |
| 142 } | |
| 143 } // namespace np_utils | |
| OLD | NEW |