summaryrefslogtreecommitdiff
path: root/chromium/third_party/catapult/tracing/tracing/ui/analysis/memory_dump_header_pane_test.html
blob: f3e220605e8d10e9371dfa5af53eb63bf9ad3d76 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<!DOCTYPE html>
<!--
Copyright 2015 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.
-->

<link rel="import" href="/tracing/ui/analysis/memory_dump_header_pane.html">
<link rel="import"
    href="/tracing/ui/analysis/memory_dump_sub_view_test_utils.html">
<link rel="import" href="/tracing/ui/analysis/memory_dump_sub_view_util.html">
<link rel="import" href="/tracing/ui/base/deep_utils.html">

<script>
'use strict';

tr.b.unittest.testSuite(function() {
  var AggregationMode = tr.ui.analysis.MemoryColumn.AggregationMode;
  var isElementDisplayed = tr.ui.analysis.isElementDisplayed;

  function createAndCheckMemoryDumpHeaderPane(test, containerMemoryDumps,
      expectedLabelText, expectedChildPaneRequested, expectedSelectorVisible) {
    var viewEl =
        tr.ui.analysis.createTestPane('tr-ui-a-memory-dump-header-pane');
    viewEl.containerMemoryDumps = containerMemoryDumps;
    viewEl.rebuild();
    test.addHTMLOutput(viewEl);
    checkMemoryDumpHeaderPane(viewEl, containerMemoryDumps, expectedLabelText,
        expectedChildPaneRequested, expectedSelectorVisible);
  }

  function checkMemoryDumpHeaderPane(viewEl, containerMemoryDumps,
      expectedLabelText, expectedChildPaneRequested, expectedSelectorVisible) {
    // The default aggregation mode is DIFF.
    assert.equal(viewEl.aggregationMode, AggregationMode.DIFF);

    // Check the text in the label.
    assert.equal(viewEl.$.label.textContent, expectedLabelText);

    // Check the visibility of aggregation mode selector.
    var aggregationModeContainerVisible =
        isElementDisplayed(viewEl.$.aggregation_mode_container);
    var childPanes = viewEl.requestedChildPanes;

    // Check the requested child panes.
    if (containerMemoryDumps === undefined ||
        containerMemoryDumps.length === 0) {
      assert.isTrue(!expectedSelectorVisible);  // Test sanity check.
      assert.isFalse(aggregationModeContainerVisible);
      assert.lengthOf(childPanes, 1);
      assert.isUndefined(childPanes[0]);
      return;
    }

    var expectedProcessMemoryDumps = containerMemoryDumps.map(
        function(containerMemoryDump) {
          return containerMemoryDump.processMemoryDumps;
        });
    function checkLastChildPane(expectedChildPaneCount) {
      assert.lengthOf(childPanes, expectedChildPaneCount);
      var lastChildPane = childPanes[expectedChildPaneCount - 1];
      assert.equal(lastChildPane.tagName, 'TR-UI-A-MEMORY-DUMP-OVERVIEW-PANE');
      assert.deepEqual(lastChildPane.processMemoryDumps,
          expectedProcessMemoryDumps);
      assert.equal(lastChildPane.aggregationMode, viewEl.aggregationMode);
    }

    checkLastChildPane(1);

    // Check the behavior of aggregation mode selector (if visible).
    if (!expectedSelectorVisible) {
      assert.isFalse(aggregationModeContainerVisible);
      return;
    }

    assert.isTrue(aggregationModeContainerVisible);
    var selector = tr.b.findDeepElementMatching(viewEl, 'select');

    selector.selectedValue = AggregationMode.MAX;
    viewEl.rebuild();
    assert.equal(viewEl.aggregationMode, AggregationMode.MAX);
    checkLastChildPane(2);

    selector.selectedValue = AggregationMode.DIFF;
    viewEl.rebuild();
    assert.equal(viewEl.aggregationMode, AggregationMode.DIFF);
    checkLastChildPane(3);
  }

  test('instantiate_empty', function() {
    tr.ui.analysis.createAndCheckEmptyPanes(this,
        'tr-ui-a-memory-dump-header-pane', 'containerMemoryDumps',
        function(viewEl) {
          checkMemoryDumpHeaderPane(viewEl, [], 'No memory dumps selected',
              false /* no child pane requested */,
              false /* aggregation mode selector hidden */);
        });
  });

  test('instantiate_singleGlobalMemoryDump', function() {
    createAndCheckMemoryDumpHeaderPane(this,
        [tr.ui.analysis.createSingleTestGlobalMemoryDump()],
        'Selected 1 memory dump in global space at 68.000 ms',
        true /* child pane requested */,
        false /* aggregation mode selector hidden */);
  });

  test('instantiate_multipleGlobalMemoryDumps', function() {
    createAndCheckMemoryDumpHeaderPane(this,
        tr.ui.analysis.createMultipleTestGlobalMemoryDumps(),
        'Selected 3 memory dumps in global space at 42.000 ms\u2026100.000 ms',
        true /* child pane requested */,
        true /* aggregation selector visible */);
  });

  test('instantiate_singleProcessMemoryDump', function() {
    createAndCheckMemoryDumpHeaderPane(this,
        [tr.ui.analysis.createSingleTestProcessMemoryDump()],
        'Selected 1 memory dump in Process 2 at 69.000 ms',
        true /* child pane requested */,
        false /* aggregation mode selector hidden */);
  });

  test('instantiate_multipleProcessMemoryDumps', function() {
    createAndCheckMemoryDumpHeaderPane(this,
        tr.ui.analysis.createMultipleTestProcessMemoryDumps(),
        'Selected 3 memory dumps in Process 2 at 42.000 ms\u2026102.000 ms',
        true /* child pane requested */,
        true /* aggregation selector visible */);
  });
});
</script>