Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(411)

Unified Diff: ppapi/proxy/ppp_instance_private_proxy_unittest.cc

Issue 9034035: Make it possible to have 1 PpapiGlobals per thread. Update unit tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove perftest stuff from this CL Created 8 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/proxy/ppapi_proxy_test.cc ('k') | ppapi/proxy/ppp_messaging_proxy_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/proxy/ppp_instance_private_proxy_unittest.cc
diff --git a/ppapi/proxy/ppp_instance_private_proxy_unittest.cc b/ppapi/proxy/ppp_instance_private_proxy_unittest.cc
index ea57ec114bf022568241472ac98e61a2d65e34f0..5181ac9ecedaaaae81aef4dc89fd804725301568 100644
--- a/ppapi/proxy/ppp_instance_private_proxy_unittest.cc
+++ b/ppapi/proxy/ppp_instance_private_proxy_unittest.cc
@@ -10,20 +10,27 @@
#include "ppapi/c/private/ppp_instance_private.h"
#include "ppapi/proxy/host_dispatcher.h"
#include "ppapi/proxy/ppapi_proxy_test.h"
+#include "ppapi/shared_impl/ppb_var_shared.h"
+#include "ppapi/shared_impl/var.h"
namespace ppapi {
+
+// A fake version of NPObjectVar for testing.
+class NPObjectVar : public Var {
+ public:
+ NPObjectVar() {}
+ virtual ~NPObjectVar() {}
+
+ // Var overrides.
+ virtual NPObjectVar* AsNPObjectVar() OVERRIDE { return this; }
+ virtual PP_VarType GetType() const OVERRIDE { return PP_VARTYPE_OBJECT; }
+};
+
namespace proxy {
namespace {
const PP_Instance kInstance = 0xdeadbeef;
-PP_Var MakeObjectVar(int64_t object_id) {
- PP_Var ret;
- ret.type = PP_VARTYPE_OBJECT;
- ret.value.as_id = object_id;
- return ret;
-}
-
PluginDispatcher* plugin_dispatcher = NULL;
// Return the plugin-side proxy for PPB_Var_Deprecated.
const PPB_Var_Deprecated* plugin_var_deprecated_if() {
@@ -40,7 +47,8 @@ PP_Var instance_obj;
PP_Var GetInstanceObject(PP_Instance /*instance*/) {
// The 1 ref we got from CreateObject will be passed to the host. We want to
// have a ref of our own.
- plugin_var_deprecated_if()->AddRef(instance_obj);
+ printf("GetInstanceObject called\n");
+ PpapiGlobals::Get()->GetVarTracker()->AddRefVar(instance_obj);
return instance_obj;
}
@@ -67,41 +75,19 @@ void DidDestroy(PP_Instance /*instance*/) {
PPP_Instance_1_0 ppp_instance_mock = { &DidCreate, &DidDestroy };
-} // namespace
-
// Mock PPB_Var_Deprecated, so that we can emulate creating an Object Var.
-std::map<int64_t, int> id_refcount_map;
-void AddRefVar(PP_Var var) {
- CHECK(var.type >= PP_VARTYPE_STRING); // Must be a ref-counted type.
- CHECK(id_refcount_map.find(var.value.as_id) != id_refcount_map.end());
- ++id_refcount_map[var.value.as_id];
-}
-
-void ReleaseVar(PP_Var var) {
- CHECK(var.type >= PP_VARTYPE_STRING); // Must be a ref-counted type.
- std::map<int64_t, int>::iterator iter = id_refcount_map.find(var.value.as_id);
- CHECK(iter != id_refcount_map.end());
- CHECK(iter->second > 0);
- if (--(iter->second) == 0)
- id_refcount_map.erase(iter);
-}
-
-PP_Var CreateObject(PP_Instance instance,
+PP_Var CreateObject(PP_Instance /*instance*/,
const PPP_Class_Deprecated* /*ppp_class*/,
void* /*ppp_class_data*/) {
- static int64_t last_id = 0;
- ++last_id;
- // Set the refcount to 0. It should really be 1, but that ref gets passed to
- // the plugin immediately (and we don't emulate all of that behavior here).
- id_refcount_map[last_id] = 0;
- return MakeObjectVar(last_id);
+ NPObjectVar* obj_var = new NPObjectVar;
+ return obj_var->GetPPVar();
}
const PPB_Var_Deprecated ppb_var_deprecated_mock = {
- &AddRefVar,
- &ReleaseVar,
- NULL, // VarFromUtf8
- NULL, // VarToUtf8
+ PPB_Var_Shared::GetVarInterface1_0()->AddRef,
+ PPB_Var_Shared::GetVarInterface1_0()->Release,
+ PPB_Var_Shared::GetVarInterface1_0()->VarFromUtf8,
+ PPB_Var_Shared::GetVarInterface1_0()->VarToUtf8,
NULL, // HasProperty
NULL, // HasMethod
NULL, // GetProperty
@@ -114,7 +100,7 @@ const PPB_Var_Deprecated ppb_var_deprecated_mock = {
&CreateObject
};
-const PPB_Var ppb_var_mock = { &AddRefVar, &ReleaseVar };
+} // namespace
class PPP_Instance_Private_ProxyTest : public TwoWayTest {
public:
@@ -126,8 +112,6 @@ class PPP_Instance_Private_ProxyTest : public TwoWayTest {
&ppp_instance_mock);
host().RegisterTestInterface(PPB_VAR_DEPRECATED_INTERFACE,
&ppb_var_deprecated_mock);
- host().RegisterTestInterface(PPB_VAR_INTERFACE,
- &ppb_var_mock);
}
};
@@ -154,36 +138,32 @@ TEST_F(PPP_Instance_Private_ProxyTest, PPPInstancePrivate) {
// properly.
EXPECT_EQ(PP_TRUE, ppp_instance->DidCreate(kInstance, 0, NULL, NULL));
- // Now instance_obj is valid and should have a ref-count of 1.
- PluginVarTracker& plugin_var_tracker =
- *PluginGlobals::Get()->plugin_var_tracker();
// Check the plugin-side reference count.
- EXPECT_EQ(1, plugin_var_tracker.GetRefCountForObject(instance_obj));
- // Check the host-side var and reference count.
- ASSERT_EQ(1u, id_refcount_map.size());
- EXPECT_EQ(plugin_var_tracker.GetHostObject(instance_obj).value.as_id,
- id_refcount_map.begin()->first);
- EXPECT_EQ(0, id_refcount_map.begin()->second);
+ EXPECT_EQ(1, plugin().var_tracker().GetRefCountForObject(instance_obj));
+ // Check the host-side var exists with the expected id and has 0 refcount.
+ int32 expected_host_id =
+ plugin().var_tracker().GetHostObject(instance_obj).value.as_id;
+ Var* host_var = host().var_tracker().GetVar(expected_host_id);
+ ASSERT_TRUE(host_var);
+ EXPECT_EQ(1, host().var_tracker().GetRefCountForObject(host_var->GetPPVar()));
dmichael (off chromium) 2012/01/03 23:27:44 I'm getting a 2 here and some other surprises belo
// Call from the browser side to get the instance object.
- PP_Var host_obj = ppp_instance_private->GetInstanceObject(kInstance);
- EXPECT_EQ(instance_obj.type, host_obj.type);
- EXPECT_EQ(host_obj.value.as_id,
- plugin_var_tracker.GetHostObject(instance_obj).value.as_id);
- EXPECT_EQ(1, plugin_var_tracker.GetRefCountForObject(instance_obj));
- ASSERT_EQ(1u, id_refcount_map.size());
+ PP_Var host_pp_var = ppp_instance_private->GetInstanceObject(kInstance);
+ EXPECT_EQ(instance_obj.type, host_pp_var.type);
+ EXPECT_EQ(host_pp_var.value.as_id,
+ host_var->GetPPVar().value.as_id);
+ EXPECT_EQ(1, plugin().var_tracker().GetRefCountForObject(instance_obj));
// The browser should be passed a reference.
- EXPECT_EQ(1, id_refcount_map.begin()->second);
+ EXPECT_EQ(2, host().var_tracker().GetRefCountForObject(host_pp_var));
dmichael (off chromium) 2012/01/03 23:27:44 Here I get 4
// The plugin is going away; generally, so will all references to its instance
// object.
- ReleaseVar(host_obj);
+ host().var_tracker().ReleaseVar(host_pp_var);
// Destroy the instance. DidDestroy above decrements the reference count for
// instance_obj, so it should also be destroyed.
ppp_instance->DidDestroy(kInstance);
- EXPECT_EQ(-1, plugin_var_tracker.GetRefCountForObject(instance_obj));
- // Check the host-side reference count.
- EXPECT_EQ(0u, id_refcount_map.size());
+ EXPECT_EQ(-1, plugin().var_tracker().GetRefCountForObject(instance_obj));
+ EXPECT_EQ(-1, host().var_tracker().GetRefCountForObject(host_pp_var));
dmichael (off chromium) 2012/01/03 23:27:44 Here I get 3. Might be a real bug... but this is
}
} // namespace proxy
« no previous file with comments | « ppapi/proxy/ppapi_proxy_test.cc ('k') | ppapi/proxy/ppp_messaging_proxy_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698