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