OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_TESTING_INSTANCE_H_ | 5 #ifndef PPAPI_TESTS_TESTING_INSTANCE_H_ |
6 #define PPAPI_TESTS_TESTING_INSTANCE_H_ | 6 #define PPAPI_TESTS_TESTING_INSTANCE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "ppapi/cpp/completion_callback.h" | 10 #include "ppapi/cpp/completion_callback.h" |
11 | |
12 #if defined(__native_client__) | |
13 #include "ppapi/cpp/instance.h" | 11 #include "ppapi/cpp/instance.h" |
14 #else | |
15 #include "ppapi/cpp/private/instance_private.h" | |
16 #endif | |
17 | 12 |
18 class TestCase; | 13 class TestCase; |
19 | 14 |
20 // In trusted builds, we use InstancePrivate and allow tests that use | 15 class TestingInstance : public pp::Instance { |
21 // synchronous scripting. NaCl does not support synchronous scripting. | |
22 class TestingInstance : public | |
23 #if defined(__native_client__) | |
24 pp::Instance { | |
25 #else | |
26 pp::InstancePrivate { | |
27 #endif | |
28 public: | 16 public: |
29 explicit TestingInstance(PP_Instance instance); | 17 explicit TestingInstance(PP_Instance instance); |
30 virtual ~TestingInstance(); | 18 virtual ~TestingInstance(); |
31 | 19 |
32 // pp::Instance override. | 20 // pp::Instance override. |
33 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]); | 21 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]); |
34 virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip); | 22 virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip); |
35 | |
36 #if !(defined __native_client__) | |
37 virtual pp::Var GetInstanceObject(); | 23 virtual pp::Var GetInstanceObject(); |
38 #endif | |
39 | 24 |
40 // Outputs the information from one test run, using the format | 25 // Outputs the information from one test run, using the format |
41 // <test_name> [PASS|FAIL <error_message>] | 26 // <test_name> [PASS|FAIL <error_message>] |
42 // If error_message is empty, we say the test passed and emit PASS. If | 27 // If error_message is empty, we say the test passed and emit PASS. If |
43 // error_message is nonempty, the test failed with that message as the error | 28 // error_message is nonempty, the test failed with that message as the error |
44 // string. | 29 // string. |
45 // | 30 // |
46 // Intended usage: | 31 // Intended usage: |
47 // LogTest("Foo", FooTest()); | 32 // LogTest("Foo", FooTest()); |
48 // | 33 // |
49 // Where FooTest is defined as: | 34 // Where FooTest is defined as: |
50 // std::string FooTest() { | 35 // std::string FooTest() { |
51 // if (something_horrible_happened) | 36 // if (something_horrible_happened) |
52 // return "Something horrible happened"; | 37 // return "Something horrible happened"; |
53 // return ""; | 38 // return ""; |
54 // } | 39 // } |
55 void LogTest(const std::string& test_name, const std::string& error_message); | 40 void LogTest(const std::string& test_name, const std::string& error_message); |
56 | 41 |
57 // Appends an error message to the log. | 42 // Appends an error message to the log. |
58 void AppendError(const std::string& message); | 43 void AppendError(const std::string& message); |
59 | 44 |
60 // Passes the message_data through to the HandleMessage method on the | 45 // Passes the message_data through to the HandleMessage method on the |
61 // TestClass object that's associated with this instance. | 46 // TestClass object that's associated with this instance. |
62 virtual void HandleMessage(const pp::Var& message_data); | 47 virtual void HandleMessage(const pp::Var& message_data); |
63 | 48 |
64 const std::string& protocol() { | |
65 return protocol_; | |
66 } | |
67 | |
68 private: | 49 private: |
69 void ExecuteTests(int32_t unused); | 50 void ExecuteTests(int32_t unused); |
70 | 51 |
71 // Creates a new TestCase for the give test name, or NULL if there is no such | 52 // Creates a new TestCase for the give test name, or NULL if there is no such |
72 // test. Ownership is passed to the caller. | 53 // test. Ownership is passed to the caller. |
73 TestCase* CaseForTestName(const char* name); | 54 TestCase* CaseForTestName(const char* name); |
74 | 55 |
75 // Appends a list of available tests to the console in the document. | 56 // Appends a list of available tests to the console in the document. |
76 void LogAvailableTests(); | 57 void LogAvailableTests(); |
77 | 58 |
(...skipping 12 matching lines...) Expand all Loading... |
90 TestCase* current_case_; | 71 TestCase* current_case_; |
91 | 72 |
92 // Set once the tests are run so we know not to re-run when the view is sized. | 73 // Set once the tests are run so we know not to re-run when the view is sized. |
93 bool executed_tests_; | 74 bool executed_tests_; |
94 | 75 |
95 // Collects all errors to send the the browser. Empty indicates no error yet. | 76 // Collects all errors to send the the browser. Empty indicates no error yet. |
96 std::string errors_; | 77 std::string errors_; |
97 | 78 |
98 // True if running in Native Client. | 79 // True if running in Native Client. |
99 bool nacl_mode_; | 80 bool nacl_mode_; |
100 | |
101 // String representing the protocol. Used for detecting whether we're running | |
102 // with http. | |
103 std::string protocol_; | |
104 }; | 81 }; |
105 | 82 |
106 #endif // PPAPI_TESTS_TESTING_INSTANCE_H_ | 83 #endif // PPAPI_TESTS_TESTING_INSTANCE_H_ |
107 | 84 |
OLD | NEW |