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