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_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/utility/completion_callback_factory.h" | 10 #include "ppapi/utility/completion_callback_factory.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]); | 55 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]); |
56 virtual void DidChangeView(const pp::View& view); | 56 virtual void DidChangeView(const pp::View& view); |
57 virtual bool HandleInputEvent(const pp::InputEvent& event); | 57 virtual bool HandleInputEvent(const pp::InputEvent& event); |
58 | 58 |
59 #if !(defined __native_client__) | 59 #if !(defined __native_client__) |
60 virtual pp::Var GetInstanceObject(); | 60 virtual pp::Var GetInstanceObject(); |
61 #endif | 61 #endif |
62 | 62 |
63 // Outputs the information from one test run, using the format | 63 // Outputs the information from one test run, using the format |
64 // <test_name> [PASS|FAIL <error_message>] | 64 // <test_name> [PASS|FAIL <error_message>] |
| 65 // |
| 66 // You should generally use one of the RUN_TEST* macros in test_case.h |
| 67 // instead. |
| 68 // |
65 // If error_message is empty, we say the test passed and emit PASS. If | 69 // If error_message is empty, we say the test passed and emit PASS. If |
66 // error_message is nonempty, the test failed with that message as the error | 70 // error_message is nonempty, the test failed with that message as the error |
67 // string. | 71 // string. |
68 // | 72 // |
69 // Intended usage: | 73 // Intended usage: |
70 // LogTest("Foo", FooTest()); | 74 // PP_TimeTicks start_time(core.GetTimeTicks()); |
| 75 // LogTest("Foo", FooTest(), start_time); |
71 // | 76 // |
72 // Where FooTest is defined as: | 77 // Where FooTest is defined as: |
73 // std::string FooTest() { | 78 // std::string FooTest() { |
74 // if (something_horrible_happened) | 79 // if (something_horrible_happened) |
75 // return "Something horrible happened"; | 80 // return "Something horrible happened"; |
76 // return ""; | 81 // return ""; |
77 // } | 82 // } |
78 void LogTest(const std::string& test_name, const std::string& error_message); | 83 // |
| 84 // NOTE: It's important to get the start time in the previous line, rather |
| 85 // than calling GetTimeTicks in the LogTestLine. There's no guarantee |
| 86 // that GetTimeTicks will be evaluated before FooTest(). |
| 87 void LogTest(const std::string& test_name, |
| 88 const std::string& error_message, |
| 89 PP_TimeTicks start_time); |
79 | 90 |
80 // Appends an error message to the log. | 91 // Appends an error message to the log. |
81 void AppendError(const std::string& message); | 92 void AppendError(const std::string& message); |
82 | 93 |
83 // Passes the message_data through to the HandleMessage method on the | 94 // Passes the message_data through to the HandleMessage method on the |
84 // TestClass object that's associated with this instance. | 95 // TestClass object that's associated with this instance. |
85 virtual void HandleMessage(const pp::Var& message_data); | 96 virtual void HandleMessage(const pp::Var& message_data); |
86 | 97 |
87 const std::string& protocol() { | 98 const std::string& protocol() { |
88 return protocol_; | 99 return protocol_; |
(...skipping 20 matching lines...) Expand all Loading... |
109 // See doc for |remove_plugin_|. | 120 // See doc for |remove_plugin_|. |
110 void set_remove_plugin(bool remove) { remove_plugin_ = remove; } | 121 void set_remove_plugin(bool remove) { remove_plugin_ = remove; } |
111 | 122 |
112 private: | 123 private: |
113 void ExecuteTests(int32_t unused); | 124 void ExecuteTests(int32_t unused); |
114 | 125 |
115 // Creates a new TestCase for the give test name, or NULL if there is no such | 126 // Creates a new TestCase for the give test name, or NULL if there is no such |
116 // test. Ownership is passed to the caller. The given string is split by '_'. | 127 // test. Ownership is passed to the caller. The given string is split by '_'. |
117 // The test case name is the first part. | 128 // The test case name is the first part. |
118 TestCase* CaseForTestName(const std::string& name); | 129 TestCase* CaseForTestName(const std::string& name); |
119 // Returns the filter (second part) of the given string. If there is no '_', | |
120 // returns the empty string, which means 'run all tests for this test case'. | |
121 // E.g.: | |
122 // http://testserver/test_case.html?testcase=PostMessage | |
123 // Otherwise, the part of the testcase after '_' is returned, and the test | |
124 // whose name matches that string (if any) will be run: | |
125 // http://testserver/test_case.html?testcase=PostMessage_SendingData | |
126 // Runs 'PostMessage_SendingData. | |
127 std::string FilterForTestName(const std::string& name); | |
128 | 130 |
129 // Sends a test command to the page using PostMessage. | 131 // Sends a test command to the page using PostMessage. |
130 void SendTestCommand(const std::string& command); | 132 void SendTestCommand(const std::string& command); |
131 void SendTestCommand(const std::string& command, const std::string& params); | 133 void SendTestCommand(const std::string& command, const std::string& params); |
132 | 134 |
133 // Appends a list of available tests to the console in the document. | 135 // Appends a list of available tests to the console in the document. |
134 void LogAvailableTests(); | 136 void LogAvailableTests(); |
135 | 137 |
136 // Appends the given error test to the console in the document. | 138 // Appends the given error test to the console in the document. |
137 void LogError(const std::string& text); | 139 void LogError(const std::string& text); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 // WebSocket port. | 175 // WebSocket port. |
174 int websocket_port_; | 176 int websocket_port_; |
175 | 177 |
176 // At the end of each set of tests, the plugin is removed from the web-page. | 178 // At the end of each set of tests, the plugin is removed from the web-page. |
177 // However, for some tests, it is desirable to not remove the plguin from the | 179 // However, for some tests, it is desirable to not remove the plguin from the |
178 // page. | 180 // page. |
179 bool remove_plugin_; | 181 bool remove_plugin_; |
180 }; | 182 }; |
181 | 183 |
182 #endif // PPAPI_TESTS_TESTING_INSTANCE_H_ | 184 #endif // PPAPI_TESTS_TESTING_INSTANCE_H_ |
OLD | NEW |