aboutsummaryrefslogtreecommitdiff
path: root/deps/v8/test/inspector/runtime/console-context.js
blob: 74996ae595d4b17b48e6c9db22a5fe659e9ee660 (plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright 2017 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.

let {session, contextGroup, Protocol} = InspectorTest.start('Tests console.context');

InspectorTest.runAsyncTestSuite([
  async function testConsoleContextMethod() {
    InspectorTest.log('console.context description:');
    var {result:{result}} = await Protocol.Runtime.evaluate({
      expression: 'console.context'});
    InspectorTest.logMessage(result);

    InspectorTest.log('console.context() methods:');
    var {result:{result:{value}}} = await Protocol.Runtime.evaluate({
      expression: 'Object.keys(console.context())', returnByValue: true});
    InspectorTest.logMessage(value);
  },

  async function testDefaultConsoleContext() {
    await Protocol.Runtime.enable();
    Protocol.Runtime.evaluate({expression: 'console.log(239)'});
    var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
    InspectorTest.log(context);
    Protocol.Runtime.evaluate({expression: 'console.info(239)'});
    var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
    InspectorTest.log(context);
    Protocol.Runtime.evaluate({expression: 'console.debug(239)'});
    var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
    InspectorTest.log(context);
    await Protocol.Runtime.evaluate({expression: 'console.clear()'});
    await Protocol.Runtime.disable();
  },

  async function testAnonymousConsoleContext() {
    await Protocol.Runtime.enable();
    Protocol.Runtime.evaluate({expression: 'console.context().log(239)'});
    var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
    InspectorTest.log(context);
    Protocol.Runtime.evaluate({expression: 'console.context().info(239)'});
    var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
    InspectorTest.log(context);
    Protocol.Runtime.evaluate({expression: 'console.context().debug(239)'});
    var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
    InspectorTest.log(context);
    await Protocol.Runtime.evaluate({expression: 'console.context().clear()'});
    await Protocol.Runtime.disable();
  },

  async function testNamedConsoleContext() {
    await Protocol.Runtime.enable();
    Protocol.Runtime.evaluate({expression: `
      var context = console.context('named-context');
      context.log(239);
      context.info(239);
      context.debug(239);
    `});
    var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
    InspectorTest.log(context);
    var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
    InspectorTest.log(context);
    var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
    InspectorTest.log(context);
    await Protocol.Runtime.evaluate({expression: 'console.clear()'});
    await Protocol.Runtime.disable();
  },

  async function testTwoConsoleContextsWithTheSameName() {
    await Protocol.Runtime.enable();
    Protocol.Runtime.evaluate({expression: 'console.context(\'named-context\').log(239)'});
    var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
    InspectorTest.log(context);
    Protocol.Runtime.evaluate({expression: 'console.context(\'named-context\').log(239)'});
    var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
    InspectorTest.log(context);
    await Protocol.Runtime.evaluate({expression: 'console.clear()'});
    await Protocol.Runtime.disable();
  },

  async function testConsoleCountInDifferentConsoleContexts() {
    await Protocol.Runtime.enable();
    Protocol.Runtime.evaluate({expression: 'console.context(\'named-context\').count(239)'});
    var {params:{args}} = await Protocol.Runtime.onceConsoleAPICalled();
    InspectorTest.logMessage(args);
    Protocol.Runtime.evaluate({expression: 'console.context(\'named-context\').count(239)'});
    var {params:{args}} = await Protocol.Runtime.onceConsoleAPICalled();
    InspectorTest.logMessage(args);
    await Protocol.Runtime.evaluate({expression: 'console.clear()'});
    await Protocol.Runtime.disable();
  },

  async function testConsoleCountForNamedConsoleContext() {
    await Protocol.Runtime.enable();
    Protocol.Runtime.evaluate({expression: `
      var context = console.context('named-context');
      context.count(239);
      context.count(239);
    `});
    var {params:{args}} = await Protocol.Runtime.onceConsoleAPICalled();
    InspectorTest.logMessage(args);
    var {params:{args}} = await Protocol.Runtime.onceConsoleAPICalled();
    InspectorTest.logMessage(args);
    await Protocol.Runtime.evaluate({expression: 'console.clear()'});
    await Protocol.Runtime.disable();
  }
]);