forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbindings_test.js
76 lines (69 loc) · 2.43 KB
/
bindings_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2017 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.
goog.module('chromium.BindingsTest');
// Needed to let C++ invoke the test.
goog.module.declareLegacyNamespace();
const Connection = goog.require('chromium.DevTools.Connection');
const DOM = goog.require('chromium.DevTools.DOM');
const Page = goog.require('chromium.DevTools.Page');
const Runtime = goog.require('chromium.DevTools.Runtime');
/**
* A trivial test which is invoked from C++ by HeadlessJsBindingsTest.
*/
class BindingsTest {
constructor() {}
/**
* Evaluates 1+1 and returns the result over the chromium.DevTools.Connection.
*/
evalOneAddOne() {
let connection = new Connection(window.TabSocket);
let runtime = new Runtime(connection);
runtime.evaluate({'expression': '1+1'}).then(function(message) {
connection.sendDevToolsMessage(
'__Result',
{'result': JSON.stringify(message.result.value)});
});
}
/**
* Evaluates 1+1 and returns the result over the chromium.DevTools.Connection.
*/
listenForChildNodeCountUpdated() {
let connection = new Connection(window.TabSocket);
let dom = new DOM(connection);
dom.onChildNodeCountUpdated(function(params) {
connection.sendDevToolsMessage('__Result',
{'result': JSON.stringify(params)});
});
dom.enable().then(function() {
return dom.getDocument({});
}).then(function() {
// Create a new div which should trigger the event.
let div = document.createElement('div');
document.body.appendChild(div);
});
}
/**
* Uses experimental commands to create an isolated world.
*/
getIsolatedWorldName() {
let connection = new Connection(window.TabSocket);
let page = new Page(connection);
let runtime = new Runtime(connection);
runtime.enable().then(function() {
runtime.onExecutionContextCreated(function(params) {
if (params.context.auxData['isDefault'] === false) {
connection.sendDevToolsMessage(
'__Result', {'result': 'Created ' + params.context.name});
}
});
page.experimental.getResourceTree().then(function(result) {
page.experimental.createIsolatedWorld({
'frameId': result.frameTree.frame.id,
'worldName': 'Test Isolated World'
});
});
});
}
}
exports = BindingsTest;