summaryrefslogtreecommitdiffstats
path: root/chrome/test/v8_unit_test.cc
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-29 22:56:14 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-29 22:56:14 +0000
commitaecb6caa6177e69648acc0ebe682283acb469cea (patch)
tree1a7c51d8ae8ad9672a31b3a61778f5438b400081 /chrome/test/v8_unit_test.cc
parentbbbdc91b5f82da1726ed10c9da8b975a21ee9ffe (diff)
downloadchromium_src-aecb6caa6177e69648acc0ebe682283acb469cea.zip
chromium_src-aecb6caa6177e69648acc0ebe682283acb469cea.tar.gz
chromium_src-aecb6caa6177e69648acc0ebe682283acb469cea.tar.bz2
Move more files from chrome/test to chrome/test/base, part #3
BUG=90905 Review URL: http://codereview.chromium.org/7541001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94780 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/v8_unit_test.cc')
-rw-r--r--chrome/test/v8_unit_test.cc103
1 files changed, 0 insertions, 103 deletions
diff --git a/chrome/test/v8_unit_test.cc b/chrome/test/v8_unit_test.cc
deleted file mode 100644
index 281bacc..0000000
--- a/chrome/test/v8_unit_test.cc
+++ /dev/null
@@ -1,103 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/stringprintf.h"
-#include "base/string_piece.h"
-#include "chrome/test/v8_unit_test.h"
-
-V8UnitTest::V8UnitTest() {}
-
-V8UnitTest::~V8UnitTest() {}
-
-void V8UnitTest::SetUp() {
- v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
- global->Set(v8::String::New("log"),
- v8::FunctionTemplate::New(&V8UnitTest::Log));
- context_ = v8::Context::New(NULL, global);
-}
-
-void V8UnitTest::SetGlobalStringVar(const std::string& var_name,
- const std::string& value) {
- v8::Context::Scope context_scope(context_);
- context_->Global()->Set(v8::String::New(var_name.c_str(), var_name.length()),
- v8::String::New(value.c_str(), value.length()));
-}
-
-void V8UnitTest::ExecuteScriptInContext(const base::StringPiece& script_source,
- const base::StringPiece& script_name) {
- v8::Context::Scope context_scope(context_);
- v8::HandleScope handle_scope;
- v8::Handle<v8::String> source = v8::String::New(script_source.data(),
- script_source.size());
- v8::Handle<v8::String> name = v8::String::New(script_name.data(),
- script_source.size());
-
- v8::TryCatch try_catch;
- v8::Handle<v8::Script> script = v8::Script::Compile(source, name);
- // Ensure the script compiled without errors.
- if (script.IsEmpty()) {
- FAIL() << ExceptionToString(&try_catch);
- }
- v8::Handle<v8::Value> result = script->Run();
- // Ensure the script ran without errors.
- if (result.IsEmpty()) {
- FAIL() << ExceptionToString(&try_catch);
- }
-}
-
-std::string V8UnitTest::ExceptionToString(v8::TryCatch* try_catch) {
- std::string str;
- v8::HandleScope handle_scope;
- v8::String::Utf8Value exception(try_catch->Exception());
- v8::Handle<v8::Message> message = try_catch->Message();
- if (message.IsEmpty()) {
- str.append(base::StringPrintf("%s\n", *exception));
- } else {
- v8::String::Utf8Value filename(message->GetScriptResourceName());
- int linenum = message->GetLineNumber();
- int colnum = message->GetStartColumn();
- str.append(base::StringPrintf(
- "%s:%i:%i %s\n", *filename, linenum, colnum, *exception));
- v8::String::Utf8Value sourceline(message->GetSourceLine());
- str.append(base::StringPrintf("%s\n", *sourceline));
- }
- return str;
-}
-
-void V8UnitTest::TestFunction(const std::string& function_name) {
- v8::Context::Scope context_scope(context_);
- v8::HandleScope handle_scope;
-
- v8::Handle<v8::Value> functionProperty =
- context_->Global()->Get(v8::String::New(function_name.c_str()));
- ASSERT_FALSE(functionProperty.IsEmpty());
- ASSERT_TRUE(functionProperty->IsFunction());
- v8::Handle<v8::Function> function =
- v8::Handle<v8::Function>::Cast(functionProperty);
-
- v8::TryCatch try_catch;
- v8::Handle<v8::Value> result = function->Call(context_->Global(), 0, NULL);
- // The test fails if an exception was thrown.
- if (result.IsEmpty()) {
- FAIL() << ExceptionToString(&try_catch);
- }
-}
-
-// static
-v8::Handle<v8::Value> V8UnitTest::Log(const v8::Arguments& args) {
- std::string message;
- bool first = true;
- for (int i = 0; i < args.Length(); i++) {
- v8::HandleScope handle_scope;
- if (first) {
- first = false;
- } else {
- message += " ";
- }
- v8::String::Utf8Value str(args[i]);
- message += *str;
- }
- std::cout << message << "\n";
- return v8::Undefined();
-}