Allow to release WebSocket resource in completion callbacks invoked by Close().

 - Protect |this| around invoking plugin callbacks
 - Add unit tests to check the case

BUG=
TEST=browser_tests


Review URL: https://chromiumcodereview.appspot.com/10661026

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@144872 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/ppapi/tests/test_utils.h b/ppapi/tests/test_utils.h
index 1e2ec36..4168cec 100644
--- a/ppapi/tests/test_utils.h
+++ b/ppapi/tests/test_utils.h
@@ -62,12 +62,22 @@
 enum CallbackType { PP_REQUIRED, PP_OPTIONAL, PP_BLOCKING };
 class TestCompletionCallback {
  public:
+  class Delegate {
+   public:
+    virtual ~Delegate() {}
+    virtual void OnCallback(void* user_data, int32_t result) = 0;
+  };
   explicit TestCompletionCallback(PP_Instance instance);
   // TODO(dmichael): Remove this constructor.
   TestCompletionCallback(PP_Instance instance, bool force_async);
 
   TestCompletionCallback(PP_Instance instance, CallbackType callback_type);
 
+  // Sets a Delegate instance. OnCallback() of this instance will be invoked
+  // when the completion callback is invoked.
+  // The delegate will be reset when Reset() or GetCallback() is called.
+  void SetDelegate(Delegate* delegate) { delegate_ = delegate; }
+
   // Waits for the callback to be called and returns the
   // result. Returns immediately if the callback was previously called
   // and the result wasn't returned (i.e. each result value received
@@ -153,6 +163,7 @@
   std::string errors_;
   unsigned run_count_;
   PP_Instance instance_;
+  Delegate* delegate_;
 };
 
 // Verifies that the callback didn't record any errors. If the callback is run