<commit_before><!DOCTYPE html>
<!--
Copyright (c) 2014 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/side_panel/side_panel_registry.html">
<link rel="import" href="/tracing/side_panel/side_panel_container.html">
<link rel="import" href="/tracing/trace_model.html">

<script>
'use strict';

tv.unittest.testSuite(function() {
  /**
   * @constructor
   */
  var Panel1 = tv.ui.define('panel-1');
  Panel1.textLabel = 'Panel 1';
  Panel1.supportsModel = function(m) {
    return {
      supported: false,
      reason: 'Explanation'
    };
  };

  Panel1.prototype = {
    __proto__: HTMLUnknownElement.prototype,

    decorate: function() {
      this.textContent = 'I am panel 1';
    }
  };

  /**
   * @constructor
   */
  var Panel2 = tv.ui.define('panel-2');
  Panel2.textLabel = 'Panel 2';
  Panel2.supportsModel = function(m) {
    return {
      supported: true
    };
  };

  Panel2.prototype = {
    __proto__: HTMLUnknownElement.prototype,

    decorate: function() {
      this.textContent = 'I am panel 1';
      this.style.height = '300px';
    }
  };

  function testBasic(name, fn) {
    test(name, function() {
      var registeredPanelConstructors =
          tracing.SidePanelRegistry.getPanelConstructors();
      var oldConstructors = registeredPanelConstructors.splice(
          0, registeredPanelConstructors.length);
      tracing.SidePanelRegistry.registerPanelSubtype(Panel1);
      tracing.SidePanelRegistry.registerPanelSubtype(Panel2);
      try {
        fn.call(this);
      } finally {
        tracing.SidePanelRegistry.unregisterPanelSubtype(Panel1);
        tracing.SidePanelRegistry.unregisterPanelSubtype(Panel2);
        registeredPanelConstructors.push.apply(registeredPanelConstructors,
            oldConstructors);
      }
    });
  }

  function createModel() {
    var m = new tracing.TraceModel();
    m.importTraces([], false, false, function() {
      var browserProcess = m.getOrCreateProcess(1);
      var browserMain = browserProcess.getOrCreateThread(2);
      browserMain.sliceGroup.beginSlice('cat', 'Task', 0);
      browserMain.sliceGroup.endSlice(10);
      browserMain.sliceGroup.beginSlice('cat', 'Task', 20);
      browserMain.sliceGroup.endSlice(30);
    });
    return m;
  }

  testBasic('instantiateCollapsed', function() {
    var container = new tracing.SidePanelContainer();
    container.model = createModel();
    this.addHTMLOutput(container);
  });

  testBasic('instantiateExpanded', function() {
    var container = new tracing.SidePanelContainer();
    container.model = createModel();
    container.activePanelConstructor = Panel2;
    container.activePanelConstructor = undefined;
    container.activePanelConstructor = Panel2;
    this.addHTMLOutput(container);
  });
});
</script>
<commit_msg>Fix side_panel_container_test after registry refactoring<commit_after><!DOCTYPE html>
<!--
Copyright (c) 2014 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/side_panel/side_panel_registry.html">
<link rel="import" href="/tracing/side_panel/side_panel_container.html">
<link rel="import" href="/tracing/trace_model.html">

<script>
'use strict';

tv.unittest.testSuite(function() {
  /**
   * @constructor
   */
  var Panel1 = tv.ui.define('panel-1');
  Panel1.textLabel = 'Panel 1';
  Panel1.supportsModel = function(m) {
    return {
      supported: false,
      reason: 'Explanation'
    };
  };

  Panel1.prototype = {
    __proto__: HTMLUnknownElement.prototype,

    decorate: function() {
      this.textContent = 'I am panel 1';
    }
  };

  /**
   * @constructor
   */
  var Panel2 = tv.ui.define('panel-2');
  Panel2.textLabel = 'Panel 2';
  Panel2.supportsModel = function(m) {
    return {
      supported: true
    };
  };

  Panel2.prototype = {
    __proto__: HTMLUnknownElement.prototype,

    decorate: function() {
      this.textContent = 'I am panel 1';
      this.style.height = '300px';
    }
  };

  function testBasic(name, fn) {
    test(name, function() {
      var registeredPanelConstructors =
          tracing.SidePanelRegistry.getPanelConstructors();
      var oldConstructors = registeredPanelConstructors.splice(
          0, registeredPanelConstructors.length);
      tracing.SidePanelRegistry.registerPanel(Panel1);
      tracing.SidePanelRegistry.registerPanel(Panel2);
      try {
        fn.call(this);
      } finally {
        tracing.SidePanelRegistry.unregisterPanel(Panel1);
        tracing.SidePanelRegistry.unregisterPanel(Panel2);
        registeredPanelConstructors.push.apply(registeredPanelConstructors,
            oldConstructors);
      }
    });
  }

  function createModel() {
    var m = new tracing.TraceModel();
    m.importTraces([], false, false, function() {
      var browserProcess = m.getOrCreateProcess(1);
      var browserMain = browserProcess.getOrCreateThread(2);
      browserMain.sliceGroup.beginSlice('cat', 'Task', 0);
      browserMain.sliceGroup.endSlice(10);
      browserMain.sliceGroup.beginSlice('cat', 'Task', 20);
      browserMain.sliceGroup.endSlice(30);
    });
    return m;
  }

  testBasic('instantiateCollapsed', function() {
    var container = new tracing.SidePanelContainer();
    container.model = createModel();
    this.addHTMLOutput(container);
  });

  testBasic('instantiateExpanded', function() {
    var container = new tracing.SidePanelContainer();
    container.model = createModel();
    container.activePanelConstructor = Panel2;
    container.activePanelConstructor = undefined;
    container.activePanelConstructor = Panel2;
    this.addHTMLOutput(container);
  });
});
</script>

{'fraction_non_alphanumeric': 0.12472083834392717, 'fraction_numerical': 0.01271259233808624, 'mean_word_length': 3.4273764258555133, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3108210', 'n_tokens_mistral': 1771, 'n_tokens_neox': 1710, 'n_words': 332}