Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Unified Diff: test/inspector-protocol/channel-impl.cc

Issue 2358943002: [inspector] added inspector protocol test runner (Closed)
Patch Set: a Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/inspector-protocol/channel-impl.cc
diff --git a/test/inspector-protocol/channel-impl.cc b/test/inspector-protocol/channel-impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f5f7a25c5af3a809c9789f6256624699f650b4a8
--- /dev/null
+++ b/test/inspector-protocol/channel-impl.cc
@@ -0,0 +1,51 @@
+// Copyright 2016 the V8 project 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 "test/inspector-protocol/channel-impl.h"
+
+#include "src/inspector/string-util.h"
+#include "test/inspector-protocol/task-queue.h"
+#include "test/inspector-protocol/task.h"
+
+namespace v8_inspector {
+
+namespace {
+
+class DispatchMessageOnFrontendTask : public Task {
+ public:
+ DispatchMessageOnFrontendTask(const StringView& message)
+ : message_(toString16(message)) {}
+
+ bool is_protocol_task() final { return true; }
+
+ void Run(v8::Isolate* isolate,
+ const v8::Global<v8::Context>& global_context) override {
+ v8_inspector::TaskScope task_scope(isolate, global_context);
+ v8::Local<v8::Context> context = task_scope.context();
+ v8::Local<v8::Object> global = context->Global();
+ v8::Local<v8::Value> dispatcher;
+ if (!global
+ ->Get(context, toV8StringInternalized(isolate, "dispatchMessage"))
+ .ToLocal(&dispatcher) ||
+ !dispatcher->IsFunction()) {
+ fprintf(stderr,
dgozman 2016/09/22 17:44:49 Is this the correct way to return error from a tes
+ "Warning: no dispatchMessage function in test context.\n");
+ return;
+ }
+ v8::Local<v8::Value> message = toV8String(isolate, message_);
+ v8::MaybeLocal<v8::Value> result;
+ result = dispatcher.As<v8::Function>()->Call(context, global, 1, &message);
+ }
+
+ private:
+ String16 message_;
+};
+
+} // namespace
+
+void ChannelImpl::SendMessageToFrontend(const StringView& message) {
+ frontend_queue_->Append(new DispatchMessageOnFrontendTask(message));
+}
+
+} // namespace v8

Powered by Google App Engine
This is Rietveld 408576698