summaryrefslogtreecommitdiffstats
path: root/webkit/plugins/ppapi/resource_tracker_unittest.cc
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-16 18:15:52 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-16 18:15:52 +0000
commit0bd753681a82634f322d4867b19148474c25566b (patch)
tree2f96cb4494c075ddee5a3e42e6b41c096a5357a9 /webkit/plugins/ppapi/resource_tracker_unittest.cc
parentd1d0afe664ff43825a4585f88ee8ce412eab0194 (diff)
downloadchromium_src-0bd753681a82634f322d4867b19148474c25566b.zip
chromium_src-0bd753681a82634f322d4867b19148474c25566b.tar.gz
chromium_src-0bd753681a82634f322d4867b19148474c25566b.tar.bz2
Move the Pepper implementation from webkit/glue/plugins/pepper_* to
webkit/plugins/ppapi/*. This renamed the files and interface implementation classes from foo.cc/Foo to ppb_foo_impl/PPB_Foo_Impl to match the proxy ppb_foo_proxy/PPB_Foo_Proxy. This moves plugin_switches.* from webkit/glue/plugins to webkit/plugins. Review URL: http://codereview.chromium.org/5828003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69424 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/plugins/ppapi/resource_tracker_unittest.cc')
-rw-r--r--webkit/plugins/ppapi/resource_tracker_unittest.cc119
1 files changed, 119 insertions, 0 deletions
diff --git a/webkit/plugins/ppapi/resource_tracker_unittest.cc b/webkit/plugins/ppapi/resource_tracker_unittest.cc
new file mode 100644
index 0000000..60910df
--- /dev/null
+++ b/webkit/plugins/ppapi/resource_tracker_unittest.cc
@@ -0,0 +1,119 @@
+// Copyright (c) 2010 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 "webkit/plugins/ppapi/ppapi_unittest.h"
+
+#include "webkit/plugins/ppapi/resource_tracker.h"
+#include "webkit/plugins/ppapi/mock_resource.h"
+
+namespace webkit {
+namespace ppapi {
+
+namespace {
+
+class TrackedMockResource : public MockResource {
+ public:
+ static int tracked_objects_alive;
+
+ TrackedMockResource(PluginModule* module) : MockResource(module) {
+ tracked_objects_alive++;
+ }
+ ~TrackedMockResource() {
+ tracked_objects_alive--;
+ }
+};
+
+int TrackedMockResource::tracked_objects_alive = 0;
+
+} // namespace
+
+class ResourceTrackerTest : public PpapiUnittest {
+ public:
+ ResourceTrackerTest() {
+ }
+
+ virtual void SetUp() {
+ PpapiUnittest::SetUp();
+ ResourceTracker::SetSingletonOverride(&tracker_);
+ }
+ virtual void TearDown() {
+ ResourceTracker::ClearSingletonOverride();
+ PpapiUnittest::TearDown();
+ }
+
+ ResourceTracker& tracker() { return tracker_; }
+
+ private:
+ ResourceTracker tracker_;
+};
+
+TEST_F(ResourceTrackerTest, Ref) {
+ ASSERT_EQ(0, TrackedMockResource::tracked_objects_alive);
+ EXPECT_EQ(0u, tracker().GetLiveObjectsForModule(module()));
+ {
+ scoped_refptr<TrackedMockResource> new_resource(
+ new TrackedMockResource(module()));
+ ASSERT_EQ(1, TrackedMockResource::tracked_objects_alive);
+
+ // Since we haven't gotten a PP_Resource, it's not associated with the
+ // module.
+ EXPECT_EQ(0u, tracker().GetLiveObjectsForModule(module()));
+ }
+ ASSERT_EQ(0, TrackedMockResource::tracked_objects_alive);
+
+ // Make a new resource and get it as a PP_Resource.
+ PP_Resource resource_id = 0;
+ {
+ scoped_refptr<TrackedMockResource> new_resource(
+ new TrackedMockResource(module()));
+ ASSERT_EQ(1, TrackedMockResource::tracked_objects_alive);
+ resource_id = new_resource->GetReference();
+ EXPECT_EQ(1u, tracker().GetLiveObjectsForModule(module()));
+
+ // Resource IDs should be consistent.
+ PP_Resource resource_id_2 = new_resource->GetReference();
+ ASSERT_EQ(resource_id, resource_id_2);
+ }
+
+ // This time it should not have been deleted since the PP_Resource carries
+ // a ref.
+ ASSERT_EQ(1, TrackedMockResource::tracked_objects_alive);
+
+ // Now we have two refs, derefing twice should delete the object.
+ tracker().UnrefResource(resource_id);
+ ASSERT_EQ(1, TrackedMockResource::tracked_objects_alive);
+ tracker().UnrefResource(resource_id);
+ ASSERT_EQ(0, TrackedMockResource::tracked_objects_alive);
+}
+
+TEST_F(ResourceTrackerTest, ForceDelete) {
+ // Make two resources.
+ scoped_refptr<TrackedMockResource> resource1(
+ new TrackedMockResource(module()));
+ PP_Resource pp_resource1 = resource1->GetReference();
+ scoped_refptr<TrackedMockResource> resource2(
+ new TrackedMockResource(module()));
+ PP_Resource pp_resource2 = resource2->GetReference();
+
+ // Keep an "internal" ref to only the first (the PP_Resource also holds a
+ // ref to each resource on behalf of the plugin).
+ resource2 = NULL;
+
+ ASSERT_EQ(2, TrackedMockResource::tracked_objects_alive);
+ EXPECT_EQ(2u, tracker().GetLiveObjectsForModule(module()));
+
+ // Force delete both refs.
+ tracker().ForceDeletePluginResourceRefs(pp_resource1);
+ tracker().ForceDeletePluginResourceRefs(pp_resource2);
+ EXPECT_EQ(0u, tracker().GetLiveObjectsForModule(module()));
+
+ // The resource we have a scoped_refptr to should still be alive.
+ ASSERT_EQ(1, TrackedMockResource::tracked_objects_alive);
+ resource1 = NULL;
+ ASSERT_EQ(0, TrackedMockResource::tracked_objects_alive);
+}
+
+} // namespace ppapi
+} // namespace webkit
+