OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 CHROME_TEST_V8_UNIT_TEST_H_ | 5 #ifndef CHROME_TEST_V8_UNIT_TEST_H_ |
6 #define CHROME_TEST_V8_UNIT_TEST_H_ | 6 #define CHROME_TEST_V8_UNIT_TEST_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/string_piece.h" | 10 #include "base/string_piece.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "v8/include/v8.h" | 12 #include "v8/include/v8.h" |
13 | 13 |
14 // A superclass for unit tests that involve running JavaeScript. This class | 14 // A superclass for unit tests that involve running JavaScript. This class |
15 // sets up V8 context and has methods that make it easy to execute scripts in | 15 // sets up V8 context and has methods that make it easy to execute scripts in |
16 // this context as well as call functions in the context. | 16 // this context as well as call functions in the context. |
17 class V8UnitTest : public testing::Test { | 17 class V8UnitTest : public testing::Test { |
18 public: | 18 public: |
19 V8UnitTest() {} | 19 V8UnitTest() {} |
20 virtual void SetUp(); | 20 virtual void SetUp(); |
21 | 21 |
22 protected: | 22 protected: |
23 // Executes the given script source in the context. The specified script | 23 // Executes the given script source in the context. The specified script |
24 // name is used when reporting errors. | 24 // name is used when reporting errors. |
(...skipping 16 matching lines...) Expand all Loading... |
41 | 41 |
42 // Handle scope that is used throughout the life of this class. | 42 // Handle scope that is used throughout the life of this class. |
43 v8::HandleScope handle_scope_; | 43 v8::HandleScope handle_scope_; |
44 | 44 |
45 // Context for the JavaScript in the test. | 45 // Context for the JavaScript in the test. |
46 v8::Handle<v8::Context> context_; | 46 v8::Handle<v8::Context> context_; |
47 }; | 47 }; |
48 | 48 |
49 #endif // CHROME_TEST_V8_UNIT_TEST_H_ | 49 #endif // CHROME_TEST_V8_UNIT_TEST_H_ |
50 | 50 |
51 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
52 // Use of this source code is governed by a BSD-style license that can be | |
53 // found in the LICENSE file. | |
54 | 51 |
55 #ifndef CHROME_TEST_V8_UNIT_TEST_H_ | |
56 #define CHROME_TEST_V8_UNIT_TEST_H_ | |
57 | |
58 #include <string> | |
59 | |
60 #include "base/string_piece.h" | |
61 #include "testing/gtest/include/gtest/gtest.h" | |
62 #include "v8/include/v8.h" | |
63 | |
64 // A superclass for unit tests that involve running JavaeScript. This class | |
65 // sets up V8 context and has methods that make it easy to execute scripts in | |
66 // this context as well as call functions in the context. | |
67 class V8UnitTest : public testing::Test { | |
68 public: | |
69 V8UnitTest() {} | |
70 virtual void SetUp(); | |
71 | |
72 protected: | |
73 // Executes the given script source in the context. The specified script | |
74 // name is used when reporting errors. | |
75 virtual void ExecuteScriptInContext(const StringPiece& script_source, | |
76 const StringPiece& script_name); | |
77 | |
78 // Converts a v8::TryCatch into a human readable string. | |
79 virtual std::string ExceptionToString(v8::TryCatch* try_catch); | |
80 | |
81 // Calls the specified function that resides in the global scope of the | |
82 // context. If the function throws an exception, FAIL() is called to | |
83 // indicate a unit test failure. This is useful for executing unit test | |
84 // functions implemented in JavaScript. | |
85 virtual void TestFunction(const std::string& function_name); | |
86 | |
87 // This method is bound to a global function "log" in the context. | |
88 // Scripts running in the context can call this to print out logging | |
89 // information to the console. | |
90 static v8::Handle<v8::Value> Log(const v8::Arguments& args); | |
91 | |
92 // Handle scope that is used throughout the life of this class. | |
93 v8::HandleScope handle_scope_; | |
94 | |
95 // Context for the JavaScript in the test. | |
96 v8::Handle<v8::Context> context_; | |
97 }; | |
98 | |
99 #endif // CHROME_TEST_V8_UNIT_TEST_H_ | |
100 | |
OLD | NEW |