summaryrefslogtreecommitdiffstats
path: root/gpu/np_utils/dynamic_np_object_unittest.cc
blob: d58e9637f5d602181523bd8eb6becec9e9eefdba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <string>

#include "gpu/np_utils/dynamic_np_object.h"
#include "gpu/np_utils/np_browser_stub.h"
#include "gpu/np_utils/np_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

using testing::Return;
using testing::StrictMock;

namespace np_utils {

class NPDynamicNPObjectTest : public testing::Test {
 protected:
  virtual void SetUp() {
    object_ = NPCreateObject<DynamicNPObject>(NULL);
  }

  StubNPBrowser stub_browser_;
  NPObjectPointer<DynamicNPObject> object_;
};

TEST_F(NPDynamicNPObjectTest, HasPropertyReturnsFalseForMissingProperty) {
  EXPECT_FALSE(NPHasProperty(NULL, object_, "missing"));
}

TEST_F(NPDynamicNPObjectTest, GetPropertyReturnsFalseForMissingProperty) {
  int32 r;
  EXPECT_FALSE(NPGetProperty(NULL, object_, "missing", &r));
}

TEST_F(NPDynamicNPObjectTest, CanSetProperty) {
  EXPECT_TRUE(NPSetProperty(NULL, object_, "foo", 7));
  int32 r;
  EXPECT_TRUE(NPHasProperty(NULL, object_, "foo"));
  EXPECT_TRUE(NPGetProperty(NULL, object_, "foo", &r));
  EXPECT_EQ(7, r);
}

TEST_F(NPDynamicNPObjectTest, CanRemoveProperty) {
  EXPECT_TRUE(NPSetProperty(NULL, object_, "foo", 7));
  EXPECT_TRUE(NPHasProperty(NULL, object_, "foo"));
  EXPECT_FALSE(NPRemoveProperty(NULL, object_, "foo"));
  EXPECT_FALSE(NPHasProperty(NULL, object_, "foo"));
  int32 r;
  EXPECT_FALSE(NPGetProperty(NULL, object_, "foo", &r));
}

TEST_F(NPDynamicNPObjectTest, CanEnumerateProperties) {
  EXPECT_TRUE(NPSetProperty(NULL, object_, "foo", 7));

  NPIdentifier* names;
  uint32 num_names;
  EXPECT_TRUE(object_->_class->enumerate(object_.Get(), &names, &num_names));

  EXPECT_EQ(1, num_names);
  EXPECT_EQ(NPBrowser::get()->GetStringIdentifier("foo"), names[0]);

  NPBrowser::get()->MemFree(names);
}

// Properties should not be
TEST_F(NPDynamicNPObjectTest, InvalidateNullsObjectProperties) {
  EXPECT_EQ(1, object_->referenceCount);
  {
    EXPECT_TRUE(NPSetProperty(NULL, object_, "foo", object_));
    EXPECT_TRUE(NPHasProperty(NULL, object_, "foo"));
    object_->_class->invalidate(object_.Get());
    EXPECT_TRUE(NPHasProperty(NULL, object_, "foo"));
    NPObjectPointer<DynamicNPObject> r;
    EXPECT_TRUE(NPGetProperty(NULL, object_, "foo", &r));
    EXPECT_TRUE(NULL == r.Get());
  }
  // Invalidate did not release object
  EXPECT_EQ(2, object_->referenceCount);
  NPBrowser::get()->ReleaseObject(object_.Get());
}
}  // namespace np_utils