summaryrefslogtreecommitdiffstats
path: root/gin/test
diff options
context:
space:
mode:
authorabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-18 17:09:36 +0000
committerabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-18 17:09:36 +0000
commit855ab43da4bd0342e2b8c9592b52ef80ac0b773f (patch)
tree0ea5aa300191aa3e0145fe083015b880edcaed53 /gin/test
parenta29e465aecb6cfc30b757d31242b06eb39846f2a (diff)
downloadchromium_src-855ab43da4bd0342e2b8c9592b52ef80ac0b773f.zip
chromium_src-855ab43da4bd0342e2b8c9592b52ef80ac0b773f.tar.gz
chromium_src-855ab43da4bd0342e2b8c9592b52ef80ac0b773f.tar.bz2
Introduce gin_shell
This CL adds a simple shell program for Gin to make edit/test/debug cycle faster. The shell excutes a list of scripts from the command line and loads any requested AMD modules relative to the current working directory. This CL will also let us remove the ugly code in https://codereview.chromium.org/69843003/diff/240001/mojo/public/bindings/js/test/run_js_tests.cc because we now know how to file modules via the file system. Eventually for Mojo, we'll want to use a net_module_provider (instead of the file_module_provider included in this CL) to load additional AMD modules off the network. BUG=317398 R=jochen@chromium.org Review URL: https://codereview.chromium.org/74753002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@235750 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gin/test')
-rw-r--r--gin/test/file_runner.cc37
-rw-r--r--gin/test/file_runner.h10
2 files changed, 28 insertions, 19 deletions
diff --git a/gin/test/file_runner.cc b/gin/test/file_runner.cc
index a8d0cc2..a343d64 100644
--- a/gin/test/file_runner.cc
+++ b/gin/test/file_runner.cc
@@ -5,37 +5,36 @@
#include "gin/test/file_runner.h"
#include "base/file_util.h"
+#include "base/message_loop/message_loop.h"
+#include "base/path_service.h"
#include "gin/converter.h"
#include "gin/modules/module_registry.h"
#include "gin/test/gtest.h"
+#include "gin/try_catch.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace gin {
namespace {
-std::string GetExceptionInfo(const v8::TryCatch& try_catch) {
- std::string info;
- ConvertFromV8(try_catch.Message()->Get(), &info);
- return info;
+base::FilePath GetModuleBase() {
+ base::FilePath path;
+ PathService::Get(base::DIR_SOURCE_ROOT, &path);
+ return path;
}
} // namespace
-FileRunnerDelegate::FileRunnerDelegate() {
+FileRunnerDelegate::FileRunnerDelegate()
+ : ModuleRunnerDelegate(GetModuleBase()) {
}
FileRunnerDelegate::~FileRunnerDelegate() {
}
-v8::Handle<v8::ObjectTemplate> FileRunnerDelegate::GetGlobalTemplate(
- Runner* runner) {
- v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
- ModuleRegistry::RegisterGlobals(runner->isolate(), templ);
- return templ;
-}
-
void FileRunnerDelegate::DidCreateContext(Runner* runner) {
+ ModuleRunnerDelegate::DidCreateContext(runner);
+
v8::Handle<v8::Context> context = runner->context();
ModuleRegistry* registry = ModuleRegistry::From(context);
@@ -43,16 +42,24 @@ void FileRunnerDelegate::DidCreateContext(Runner* runner) {
GetGTestTemplate(runner->isolate()));
}
+void FileRunnerDelegate::UnhandledException(Runner* runner,
+ TryCatch& try_catch) {
+ ModuleRunnerDelegate::UnhandledException(runner, try_catch);
+ EXPECT_FALSE(try_catch.HasCaught()) << try_catch.GetPrettyMessage();
+}
+
void RunTestFromFile(const base::FilePath& path, RunnerDelegate* delegate) {
ASSERT_TRUE(base::PathExists(path)) << path.LossyDisplayName();
std::string source;
ASSERT_TRUE(ReadFileToString(path, &source));
+
+ base::MessageLoop message_loop;
+
gin::Runner runner(delegate, v8::Isolate::GetCurrent());
gin::Runner::Scope scope(&runner);
-
- v8::TryCatch try_catch;
runner.Run(source);
- EXPECT_FALSE(try_catch.HasCaught()) << GetExceptionInfo(try_catch);
+
+ message_loop.RunUntilIdle();
v8::Handle<v8::Value> result = runner.context()->Global()->Get(
StringToSymbol(runner.isolate(), "result"));
diff --git a/gin/test/file_runner.h b/gin/test/file_runner.h
index b4ca00e..b00e089 100644
--- a/gin/test/file_runner.h
+++ b/gin/test/file_runner.h
@@ -7,19 +7,21 @@
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
+#include "gin/modules/module_runner_delegate.h"
#include "gin/runner.h"
namespace gin {
-class FileRunnerDelegate : public RunnerDelegate {
+class FileRunnerDelegate : public ModuleRunnerDelegate {
public:
FileRunnerDelegate();
virtual ~FileRunnerDelegate();
- virtual v8::Handle<v8::ObjectTemplate> GetGlobalTemplate(
- Runner* runner) OVERRIDE;
- virtual void DidCreateContext(Runner* runner) OVERRIDE;
private:
+ // From ModuleRunnerDelegate:
+ virtual void DidCreateContext(Runner* runner) OVERRIDE;
+ virtual void UnhandledException(Runner* runner, TryCatch& try_catch) OVERRIDE;
+
DISALLOW_COPY_AND_ASSIGN(FileRunnerDelegate);
};