test_instance_deprecated.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright (c) 2012 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.
  4. #ifndef PPAPI_TESTS_TEST_INSTANCE_DEPRECATED_H_
  5. #define PPAPI_TESTS_TEST_INSTANCE_DEPRECATED_H_
  6. #include <string>
  7. #include <vector>
  8. #include "ppapi/cpp/dev/scriptable_object_deprecated.h"
  9. #include "ppapi/tests/test_case.h"
  10. class TestInstance;
  11. // ScriptableObject used by TestInstance.
  12. class InstanceSO : public pp::deprecated::ScriptableObject {
  13. public:
  14. explicit InstanceSO(TestInstance* i);
  15. virtual ~InstanceSO();
  16. // pp::deprecated::ScriptableObject overrides.
  17. bool HasMethod(const pp::Var& name, pp::Var* exception);
  18. pp::Var Call(const pp::Var& name,
  19. const std::vector<pp::Var>& args,
  20. pp::Var* exception);
  21. // For out-of-process, the InstanceSO might be deleted after the instance was
  22. // already destroyed, so we can't rely on test_instance_ being valid.
  23. void clear_test_instance() { test_instance_ = NULL; }
  24. private:
  25. TestInstance* test_instance_;
  26. const PPB_Testing_Private* testing_interface_;
  27. };
  28. class TestInstance : public TestCase {
  29. public:
  30. TestInstance(TestingInstance* instance);
  31. virtual ~TestInstance();
  32. // TestCase implementation.
  33. virtual bool Init();
  34. virtual void RunTests(const std::string& filter);
  35. void set_string(const std::string& s) { string_ = s; }
  36. // Leak a reference to the given var, but ignore the leak in the leak checking
  37. // that happens at shutdown. This allows us to test the "ForceFree" that
  38. // happens on instance shutdown.
  39. void LeakReferenceAndIgnore(const pp::Var& leaked);
  40. // This resets the scriptable object if it gets destroyed before the instance
  41. // which should be the case for in-process tests.
  42. void clear_instance_so() { instance_so_ = NULL; }
  43. protected:
  44. // Test case protected overrides.
  45. virtual pp::deprecated::ScriptableObject* CreateTestObject();
  46. private:
  47. std::string TestExecuteScript();
  48. std::string TestRecursiveObjects();
  49. std::string TestLeakedObjectDestructors();
  50. std::string TestSetupExecuteScriptAtInstanceShutdown();
  51. std::string TestExecuteScriptAtInstanceShutdown();
  52. // Value written by set_string which is called by the ScriptableObject. This
  53. // allows us to keep track of what was called.
  54. std::string string_;
  55. // The scriptable object for this test.
  56. InstanceSO* instance_so_;
  57. };
  58. #endif // PPAPI_TESTS_TEST_INSTANCE_DEPRECATED_H_