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