Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / ppapi / proxy / plugin_resource_tracker_unittest.cc
blob8623f649de3b0e6daaccc10187f36b3f31b51a7c
1 // Copyright (c) 2011 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.
5 #include "base/memory/scoped_ptr.h"
6 #include "base/process/process.h"
7 #include "ppapi/proxy/mock_resource.h"
8 #include "ppapi/proxy/plugin_dispatcher.h"
9 #include "ppapi/proxy/plugin_resource_tracker.h"
10 #include "ppapi/proxy/ppapi_messages.h"
11 #include "ppapi/proxy/ppapi_proxy_test.h"
12 #include "ppapi/shared_impl/proxy_lock.h"
14 namespace ppapi {
15 namespace proxy {
17 namespace {
19 // Object so we know when a resource has been released.
20 class TrackedMockResource : public MockResource {
21 public:
22 TrackedMockResource(const HostResource& serialized)
23 : MockResource(serialized) {
24 tracked_alive_count++;
26 ~TrackedMockResource() {
27 tracked_alive_count--;
30 static int tracked_alive_count;
33 int TrackedMockResource::tracked_alive_count = 0;
35 } // namespace
37 class PluginResourceTrackerTest : public PluginProxyTest {
38 public:
39 PluginResourceTrackerTest() {}
40 ~PluginResourceTrackerTest() {}
43 TEST_F(PluginResourceTrackerTest, PluginResourceForHostResource) {
44 ProxyAutoLock lock;
46 PP_Resource host_resource = 0x5678;
48 HostResource serialized;
49 serialized.SetHostResource(pp_instance(), host_resource);
51 // When we haven't added an object, the return value should be 0.
52 EXPECT_EQ(0, resource_tracker().PluginResourceForHostResource(serialized));
54 EXPECT_EQ(0, TrackedMockResource::tracked_alive_count);
55 TrackedMockResource* object = new TrackedMockResource(serialized);
56 EXPECT_EQ(1, TrackedMockResource::tracked_alive_count);
57 PP_Resource plugin_resource = object->GetReference();
59 // Now that the object has been added, the return value should be the plugin
60 // resource ID we already got.
61 EXPECT_EQ(plugin_resource,
62 resource_tracker().PluginResourceForHostResource(serialized));
64 // Releasing the resource should have freed it.
65 resource_tracker().ReleaseResource(plugin_resource);
66 EXPECT_EQ(0, TrackedMockResource::tracked_alive_count);
67 EXPECT_EQ(0, resource_tracker().PluginResourceForHostResource(serialized));
70 } // namespace proxy
71 } // namespace ppapi