Index: chrome/test/base/v8_unit_test.h |
diff --git a/chrome/test/base/v8_unit_test.h b/chrome/test/base/v8_unit_test.h |
index 243b332e5efe0fe7c400e3db0690bdfa28087b8c..9391dae8a9a5d5a259d9560ce1228316671ba7a4 100644 |
--- a/chrome/test/base/v8_unit_test.h |
+++ b/chrome/test/base/v8_unit_test.h |
@@ -7,7 +7,9 @@ |
#pragma once |
#include <string> |
+#include <vector> |
+#include "base/file_path.h" |
#include "testing/gtest/include/gtest/gtest.h" |
#include "v8/include/v8.h" |
@@ -23,37 +25,67 @@ class V8UnitTest : public testing::Test { |
V8UnitTest(); |
virtual ~V8UnitTest(); |
- virtual void SetUp(); |
+ // Methods from testing::Test. |
+ virtual void SetUp() OVERRIDE; |
protected: |
- // Executes the given script source in the context. The specified script |
- // name is used when reporting errors. |
+ // Add a custom helper JS library for your test. If |library_path| is |
+ // relative, it'll be read as relative to the test data dir. |
+ void AddLibrary(const FilePath& library_path); |
+ |
+ // Runs |test_fixture|.|test_name| using the framework in test_api.js. |
+ bool RunJavascriptTestF(const std::string& test_fixture, |
+ const std::string& test_name); |
+ |
+ // Executes the given |script_source| in the context. The specified |
+ // |script_name| is used when reporting errors. |
virtual void ExecuteScriptInContext(const base::StringPiece& script_source, |
const base::StringPiece& script_name); |
- // Set a variable to a string value in the global scope. |
+ // Set the variable |var_name| to a string |value| in the global scope. |
virtual void SetGlobalStringVar(const std::string& var_name, |
const std::string& value); |
- // Converts a v8::TryCatch into a human readable string. |
+ // Converts the v8::TryCatch |try_catch| into a human readable string. |
virtual std::string ExceptionToString(const v8::TryCatch& try_catch); |
- // Calls the specified function that resides in the global scope of the |
- // context. If the function throws an exception, FAIL() is called to |
- // indicate a unit test failure. This is useful for executing unit test |
- // functions implemented in JavaScript. |
+ // Calls the specified |function_name| that resides in the global scope of the |
+ // context. If the function throws an exception, FAIL() is called to indicate |
+ // a unit test failure. This is useful for executing unit test functions |
+ // implemented in JavaScript. |
virtual void TestFunction(const std::string& function_name); |
- // This method is bound to a global function "log" in the context. |
- // Scripts running in the context can call this to print out logging |
- // information to the console. |
+ // This method is bound to a global function "log" in the context, as well as |
+ // to log, warn, and info of the console object. Scripts running in the |
+ // context can call this with |args| to print out logging information to the |
+ // console. |
static v8::Handle<v8::Value> Log(const v8::Arguments& args); |
+ // This method is bound to console.error in the context. Any calls to this |
+ // will log |args| to the console and also signal an error condition causing |
+ // |RunJavascriptF| to fail. |
+ static v8::Handle<v8::Value> Error(const v8::Arguments& args); |
+ |
+ // This method is bound to a method "chrome.send" in the context. When |
+ // test_api calls testDone with |args| to report its results, this will |
+ // capture and hold the results for analysis by |RunJavascriptF|. |
+ static v8::Handle<v8::Value> ChromeSend(const v8::Arguments& args); |
+ |
+ private: |
+ // Executes all added javascript libraries. Returns true if no errors. |
+ bool ExecuteJavascriptLibraries(); |
+ |
+ // Initializes paths and libraries. |
+ void InitPathsAndLibraries(); |
+ |
// Handle scope that is used throughout the life of this class. |
v8::HandleScope handle_scope_; |
// Context for the JavaScript in the test. |
v8::Handle<v8::Context> context_; |
+ |
+ // User added libraries. |
+ std::vector<FilePath> user_libraries_; |
}; |
#endif // CHROME_TEST_BASE_V8_UNIT_TEST_H_ |