blob: 1969f4e0d9c0889c83a197e4e6ddc40d1e691c68 [file] [log] [blame]
// Copyright (c) 2011 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 "ppapi/proxy/plugin_resource_tracker.h"
#include "base/process/process.h"
#include "ppapi/proxy/mock_resource.h"
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/ppapi_proxy_test.h"
#include "ppapi/shared_impl/proxy_lock.h"
namespace ppapi {
namespace proxy {
namespace {
// Object so we know when a resource has been released.
class TrackedMockResource : public MockResource {
TrackedMockResource(const HostResource& serialized)
: MockResource(serialized) {
~TrackedMockResource() {
static int tracked_alive_count;
int TrackedMockResource::tracked_alive_count = 0;
} // namespace
class PluginResourceTrackerTest : public PluginProxyTest {
PluginResourceTrackerTest() {}
~PluginResourceTrackerTest() {}
TEST_F(PluginResourceTrackerTest, PluginResourceForHostResource) {
ProxyAutoLock lock;
PP_Resource host_resource = 0x5678;
HostResource serialized;
serialized.SetHostResource(pp_instance(), host_resource);
// When we haven't added an object, the return value should be 0.
EXPECT_EQ(0, resource_tracker().PluginResourceForHostResource(serialized));
EXPECT_EQ(0, TrackedMockResource::tracked_alive_count);
TrackedMockResource* object = new TrackedMockResource(serialized);
EXPECT_EQ(1, TrackedMockResource::tracked_alive_count);
PP_Resource plugin_resource = object->GetReference();
// Now that the object has been added, the return value should be the plugin
// resource ID we already got.
// Releasing the resource should have freed it.
EXPECT_EQ(0, TrackedMockResource::tracked_alive_count);
EXPECT_EQ(0, resource_tracker().PluginResourceForHostResource(serialized));
} // namespace proxy
} // namespace ppapi