text:
// -*- c++ -*-
// Generated by gmmproc 2.46.2 -- DO NOT MODIFY!
#ifndef _GIOMM_POLLABLEOUTPUTSTREAM_H
#define _GIOMM_POLLABLEOUTPUTSTREAM_H

#include <glibmm/ustring.h>
#include <sigc++/sigc++.h>

// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-

#include <glibmm/interface.h>

#ifndef DOXYGEN_SHOULD_SKIP_THIS
typedef struct _GPollableOutputStreamInterface GPollableOutputStreamInterface;
#endif /* DOXYGEN_SHOULD_SKIP_THIS */

#ifndef DOXYGEN_SHOULD_SKIP_THIS
typedef struct _GPollableOutputStream GPollableOutputStream;
typedef struct _GPollableOutputStreamClass GPollableOutputStreamClass;
#endif /* DOXYGEN_SHOULD_SKIP_THIS */

#ifndef DOXYGEN_SHOULD_SKIP_THIS
namespace Gio
{ class PollableOutputStream_Class; } // namespace Gio
#endif // DOXYGEN_SHOULD_SKIP_THIS

namespace Gio
{

class Cancellable;

//TODO: Instead derive from OutputStream, when we can break ABI,
//because the GPollableOutputStream interface requires the GOutputStream interface.
//LoadableIcon does a similar thing correctly, for instance.

/** PollableOutputStream - Interface for pollable output streams.
 * PollableOutputStream is implemented by OutputStreams that can be polled for
 * readiness to write. This can be used when interfacing with a non-GIO API
 * that expects UNIX-file-descriptor-style asynchronous I/O rather than
 * GIO-style.
 * @newin{2,34}
 */

class PollableOutputStream : public Glib::Interface
{

#ifndef DOXYGEN_SHOULD_SKIP_THIS

public:
  typedef PollableOutputStream CppObjectType;
  typedef PollableOutputStream_Class CppClassType;
  typedef GPollableOutputStream BaseObjectType;
  typedef GPollableOutputStreamInterface BaseClassType;

  // noncopyable
  PollableOutputStream(const PollableOutputStream&) = delete;
  PollableOutputStream& operator=(const PollableOutputStream&) = delete;

private:
  friend class PollableOutputStream_Class;
  static CppClassType pollableoutputstream_class_;

#endif /* DOXYGEN_SHOULD_SKIP_THIS */
protected:
  /**
   * You should derive from this class to use it.
   */
  PollableOutputStream();

#ifndef DOXYGEN_SHOULD_SKIP_THIS
  /** Called by constructors of derived classes. Provide the result of
   * the Class init() function to ensure that it is properly
   * initialized.
   *
   * @param interface_class The Class object for the derived type.
   */
  explicit PollableOutputStream(const Glib::Interface_Class& interface_class);

public:
  // This is public so that C++ wrapper instances can be
  // created for C instances of unwrapped types.
  // For instance, if an unexpected C type implements the C interface.
  explicit PollableOutputStream(GPollableOutputStream* castitem);

protected:
#endif /* DOXYGEN_SHOULD_SKIP_THIS */

public:

  PollableOutputStream(PollableOutputStream&& src) noexcept;
  PollableOutputStream& operator=(PollableOutputStream&& src) noexcept;

  virtual ~PollableOutputStream() noexcept;

  static void add_interface(GType gtype_implementer);

  /** Get the GType for this class, for use with the underlying GObject type system.
   */
  static GType get_type()      G_GNUC_CONST;

#ifndef DOXYGEN_SHOULD_SKIP_THIS
  static GType get_base_type() G_GNUC_CONST;
#endif

  ///Provides access to the underlying C GObject.
  GPollableOutputStream*       gobj()       { return reinterpret_cast<GPollableOutputStream*>(gobject_); }

  ///Provides access to the underlying C GObject.
  const GPollableOutputStream* gobj() const { return reinterpret_cast<GPollableOutputStream*>(gobject_); }

private:

public:

  /** Checks if @a stream is actually pollable. Some classes may implement
   * PollableOutputStream but have only certain instances of that
   * class be pollable. If this method returns <tt>false</tt>, then the behavior
   * of other PollableOutputStream methods is undefined.
   *
   * For any given stream, the value returned by this method is constant;
   * a stream cannot switch from pollable to non-pollable or vice versa.
   *
   * @newin{2,28}
   *
   * @return <tt>true</tt> if @a stream is pollable, <tt>false</tt> if not.
   */
  bool can_poll() const;

  /** Checks if @a stream can be written.
   *
   * Note that some stream types may not be able to implement this 100%
   * reliably, and it is possible that a call to g_output_stream_write()
   * after this returns <tt>true</tt> would still block. To guarantee
   * non-blocking behavior, you should always use
   * g_pollable_output_stream_write_nonblocking(), which will return a
   * IO_ERROR_WOULD_BLOCK error rather than blocking.
   *
   * @newin{2,28}
   *
   * @return <tt>true</tt> if @a stream is writable, <tt>false</tt> if not. If an error
   * has occurred on @a stream, this will result in
   * g_pollable_output_stream_is_writable() returning <tt>true</tt>, and the
   * next attempt to write will return the error.
   */
  bool is_writable() const;

  //TODO: _WRAP_METHOD(Glib::RefPtr<Source> create_source(const Glib::RefPtr<Cancellable>& cancellable), g_pollable_output_stream_create_source)

  /** Attempts to write up to @a count bytes from @a buffer to @a stream, as
   * with g_output_stream_write(). If @a stream is not currently writable,
   * this will immediately return IO_ERROR_WOULD_BLOCK, and you can
   * use g_pollable_output_stream_create_source() to create a Source
   * that will be triggered when @a stream is writable.
   *
   * Note that since this method never blocks, you cannot actually
   * use @a cancellable to cancel it. However, it will return an error
   * if @a cancellable has already been cancelled when you call, which
   * may happen if you call this method after a source triggers due
   * to having been cancelled.
   *
   * Virtual: write_nonblocking
   *
   * @param buffer A buffer to write
   * data from.
   * @param count The number of bytes you want to write.
   * @param cancellable A Cancellable, or <tt>0</tt>.
   * @return The number of bytes written, or -1 on error (including
   * IO_ERROR_WOULD_BLOCK).
   */
  gssize write_nonblocking(const void* buffer, gsize count, const Glib::RefPtr<Cancellable>& cancellable);

  /// A write_nonblocking() convenience overload.
  gssize write_nonblocking(const void* buffer, gsize count);

    virtual bool can_poll_vfunc() const;

    virtual bool is_writable_vfunc() const;

  //TODO:_WRAP_VFUNC(Glib::RefPtr<Source> create_source(const Glib::RefPtr<Cancellable>& cancellable), "create_source")

  /// @throws Glib::Error.
  virtual gssize write_nonblocking_vfunc(const void* buffer, gsize count);

public:

public:
  //C++ methods used to invoke GTK+ virtual functions:

protected:
  //GTK+ Virtual Functions (override these to change behaviour):

  //Default Signal Handlers::

};

} // namespace Gio

namespace Glib
{
  /** A Glib::wrap() method for this object.
   *
   * @param object The C instance.
   * @param take_copy False if the result should take ownership of the C instance. True if it should take a new copy or ref.
   * @result A C++ instance that wraps this C instance.
   *
   * @relates Gio::PollableOutputStream
   */
  Glib::RefPtr<Gio::PollableOutputStream> wrap(GPollableOutputStream* object, bool take_copy = false);

} // namespace Glib

#endif /* _GIOMM_POLLABLEOUTPUTSTREAM_H */


text:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum GameState
{
    PLAY,
    TRANSITION_TO_PLAY,
    PAUSE,
    PAUSE_ON_TEXT,
    TRANSITION_TO_PAUSE,
    END,
    MENU
}

public class GameController : MonoBehaviour
{
    // UI

    // General Values
    public GameState currentState;
    private bool tickSkipped;
    private float scale;

    // Player

    // Camera
    public Camera cam;

    void Start()
    {
        Restart();
    }

    void Update()
    {
        scale = transform.lossyScale.y;
        //Debug.Log(scale);

        switch (currentState)
        {
            case GameState.PLAY:
                {
                    /*if (nexusHealth > 0f)
                        HandleLoop();*/
                    break;
                }
            case GameState.TRANSITION_TO_PLAY:
                {
                    if (tickSkipped)
                        currentState = GameState.PLAY;
                    else
                        tickSkipped = !tickSkipped;

                    break;
                }
            case GameState.PAUSE:
                {
                    /*if (trackingImages[card0])
                    {
                        warning.SetActive(false);
                    }*/

                    break;
                }
            case GameState.PAUSE_ON_TEXT:
                {
                    DisableMovement();

                    break;
                }
            case GameState.TRANSITION_TO_PAUSE:
                {
                    if (tickSkipped)
                        currentState = GameState.PAUSE;
                    else
                        tickSkipped = !tickSkipped;

                    break;
                }
            default: return;
        }
    }

    bool DisableMovement()
    {

        return true;
    }

    void OnTriggerEnter(Collider other)
    {
        /*if (other.tag == "Bullet")
        {
            SpawnExplosion(other.transform);
            Destroy(other.gameObject);
        }*/
    }

    private void Restart()
    {
        // Reset UI to menu
        currentState = GameState.MENU;
        /*startButton.SetActive(true);
        startPanel.SetActive(true);
        resumeButton.SetActive(false);
        pauseButton.SetActive(false);
        restartButton.SetActive(false);
        deathPanel.SetActive(false);*/
    }

    private void HandleLoop()
    {
        if (Input.touchCount > 0)
        {
            /*Vector3 aim = cam.transform.forward;
            aim.x = Input.GetTouch(0).position.x;
            aim.y = Input.GetTouch(0).position.y;

            ProjectileController proj = projectileSpawner.SpawnProjectile(cam.transform, aim, scale);
            proj.SetAttributes(this, projectileSpeed, null, damage);*/
        }
        else if (Input.GetMouseButtonDown(0))
        {
            /*ProjectileController proj = projectileSpawner.SpawnProjectile(cam.transform, Input.mousePosition, scale);
            proj.SetAttributes(this, projectileSpeed, null, damage);*/
        }

        /*spawnTimer += Time.deltaTime;
        if (spawnTimer >= spawnFrequency)
        {
            spawnTimer = 0f;
            SpawnEnemy();
        }*/
    }

    // Utility ===================================================

    public GameState GetState()
    {
        return currentState;
    }

    public float GetScale()
    {
        return scale;
    }

    // UI ===================================================

    public void StartGame()
    {
        /*startButton.SetActive(false);
        nexusLife.transform.parent.gameObject.SetActive(true);
        currentState = GameState.TRANSITION_TO_PLAY;
        tickSkipped = false;

        killCount = 0;
        killCountLabel.text = killCount.ToString();*/
    }

    public void Pause()
    {
        /*pauseButton.SetActive(false);
        resumeButton.SetActive(true);
        restartButton.SetActive(true);
        pausePanel.SetActive(true);
        currentState = GameState.TRANSITION_TO_PAUSE;
        tickSkipped = false;*/
    }

    public void Resume()
    {
        /*restartButton.SetActive(false);
        resumeButton.SetActive(false);
        pauseButton.SetActive(true);
        currentState = GameState.TRANSITION_TO_PLAY;
        tickSkipped = false;*/
    }

    public void Reset()
    {
        /*restartButton.SetActive(false);
        resumeButton.SetActive(false);
        pauseButton.SetActive(false);
        startButton.SetActive(true);
        tickSkipped = false;
        Restart();*/
    }

    public void Exit()
    {
        Application.Quit();
    }
}

redpajama_set_name: RedPajamaGithub


text:
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");

const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;

function LOG(str) {
  dump("*** " + str + "\n");
}

const WCCR_CONTRACTID = "@mozilla.org/embeddor.implemented/web-content-handler-registrar;1";
const WCCR_CLASSID = Components.ID("{792a7e82-06a0-437c-af63-b2d12e808acc}");

const WCC_CLASSID = Components.ID("{db7ebf28-cc40-415f-8a51-1b111851df1e}");
const WCC_CLASSNAME = "Web Service Handler";

const TYPE_MAYBE_FEED = "application/vnd.mozilla.maybe.feed";
const TYPE_ANY = "*/*";

const PREF_CONTENTHANDLERS_AUTO = "browser.contentHandlers.auto.";
const PREF_CONTENTHANDLERS_BRANCH = "browser.contentHandlers.types.";
const PREF_SELECTED_WEB = "browser.feeds.handlers.webservice";
const PREF_SELECTED_ACTION = "browser.feeds.handler";
const PREF_SELECTED_READER = "browser.feeds.handler.default";
const PREF_HANDLER_EXTERNAL_PREFIX = "network.protocol-handler.external";
const PREF_ALLOW_DIFFERENT_HOST = "gecko.handlerService.allowRegisterFromDifferentHost";

const STRING_BUNDLE_URI = "chrome://browser/locale/feeds/subscribe.properties";

const NS_ERROR_MODULE_DOM = 2152923136;
const NS_ERROR_DOM_SYNTAX_ERR = NS_ERROR_MODULE_DOM + 12;

function WebContentConverter() {
}
WebContentConverter.prototype = {
  convert: function WCC_convert() { },
  asyncConvertData: function WCC_asyncConvertData() { },
  onDataAvailable: function WCC_onDataAvailable() { },
  onStopRequest: function WCC_onStopRequest() { },

  onStartRequest: function WCC_onStartRequest(request, context) {
    var wccr =
        Cc[WCCR_CONTRACTID].
        getService(Ci.nsIWebContentConverterService);
    wccr.loadPreferredHandler(request);
  },

  QueryInterface: function WCC_QueryInterface(iid) {
    if (iid.equals(Ci.nsIStreamConverter) ||
        iid.equals(Ci.nsIStreamListener) ||
        iid.equals(Ci.nsISupports))
      return this;
    throw Cr.NS_ERROR_NO_INTERFACE;
  }
};

var WebContentConverterFactory = {
  createInstance: function WCCF_createInstance(outer, iid) {
    if (outer != null)
      throw Cr.NS_ERROR_NO_AGGREGATION;
    return new WebContentConverter().QueryInterface(iid);
  },

  QueryInterface: function WCC_QueryInterface(iid) {
    if (iid.equals(Ci.nsIFactory) ||
        iid.equals(Ci.nsISupports))
      return this;
    throw Cr.NS_ERROR_NO_INTERFACE;
  }
};

function ServiceInfo(contentType, uri, name) {
  this._contentType = contentType;
  this._uri = uri;
  this._name = name;
}
ServiceInfo.prototype = {
  /**
   * See nsIHandlerApp
   */
  get name() {
    return this._name;
  },

  /**
   * See nsIHandlerApp
   */
  equals: function SI_equals(aHandlerApp) {
    if (!aHandlerApp)
      throw Cr.NS_ERROR_NULL_POINTER;

    if (aHandlerApp instanceof Ci.nsIWebContentHandlerInfo &&
        aHandlerApp.contentType == this.contentType &&
        aHandlerApp.uri == this.uri)
      return true;

    return false;
  },

  /**
   * See nsIWebContentHandlerInfo
   */
  get contentType() {
    return this._contentType;
  },

  /**
   * See nsIWebContentHandlerInfo
   */
  get uri() {
    return this._uri;
  },

  /**
   * See nsIWebContentHandlerInfo
   */
  getHandlerURI: function SI_getHandlerURI(uri) {
    return this._uri.replace(/%s/gi, encodeURIComponent(uri));
  },

  QueryInterface: function SI_QueryInterface(iid) {
    if (iid.equals(Ci.nsIWebContentHandlerInfo) ||
        iid.equals(Ci.nsISupports))
      return this;
    throw Cr.NS_ERROR_NO_INTERFACE;
  }
};

function WebContentConverterRegistrar() {
  this._contentTypes = { };
  this._autoHandleContentTypes = { };
}

WebContentConverterRegistrar.prototype = {
  get stringBundle() {
    var sb = Cc["@mozilla.org/intl/stringbundle;1"].
              getService(Ci.nsIStringBundleService).
              createBundle(STRING_BUNDLE_URI);
    delete WebContentConverterRegistrar.prototype.stringBundle;
    return WebContentConverterRegistrar.prototype.stringBundle = sb;
  },

  _getFormattedString: function WCCR__getFormattedString(key, params) {
    return this.stringBundle.formatStringFromName(key, params, params.length);
  },

  _getString: function WCCR_getString(key) {
    return this.stringBundle.GetStringFromName(key);
  },

  /**
   * See nsIWebContentConverterService
   */
  getAutoHandler:
  function WCCR_getAutoHandler(contentType) {
    contentType = this._resolveContentType(contentType);
    if (contentType in this._autoHandleContentTypes)
      return this._autoHandleContentTypes[contentType];
    return null;
  },

  /**
   * See nsIWebContentConverterService
   */
  setAutoHandler:
  function WCCR_setAutoHandler(contentType, handler) {
    if (handler && !this._typeIsRegistered(contentType, handler.uri))
      throw Cr.NS_ERROR_NOT_AVAILABLE;

    contentType = this._resolveContentType(contentType);
    this._setAutoHandler(contentType, handler);

    var ps =
        Cc["@mozilla.org/preferences-service;1"].
        getService(Ci.nsIPrefService);
    var autoBranch = ps.getBranch(PREF_CONTENTHANDLERS_AUTO);
    if (handler)
      autoBranch.setCharPref(contentType, handler.uri);
    else if (autoBranch.prefHasUserValue(contentType))
      autoBranch.clearUserPref(contentType);

    ps.savePrefFile(null);
  },

  /**
   * Update the internal data structure (not persistent)
   */
  _setAutoHandler:
  function WCCR__setAutoHandler(contentType, handler) {
    if (handler)
      this._autoHandleContentTypes[contentType] = handler;
    else if (contentType in this._autoHandleContentTypes)
      delete this._autoHandleContentTypes[contentType];
  },

  /**
   * See nsIWebContentConverterService
   */
  getWebContentHandlerByURI:
  function WCCR_getWebContentHandlerByURI(contentType, uri) {
    var handlers = this.getContentHandlers(contentType, { });
    for (var i = 0; i < handlers.length; ++i) {
      if (handlers[i].uri == uri)
        return handlers[i];
    }
    return null;
  },

  /**
   * See nsIWebContentConverterService
   */
  loadPreferredHandler:
  function WCCR_loadPreferredHandler(request) {
    var channel = request.QueryInterface(Ci.nsIChannel);
    var contentType = this._resolveContentType(channel.contentType);
    var handler = this.getAutoHandler(contentType);
    if (handler) {
      request.cancel(Cr.NS_ERROR_FAILURE);

      var webNavigation =
          channel.notificationCallbacks.getInterface(Ci.nsIWebNavigation);
      webNavigation.loadURI(handler.getHandlerURI(channel.URI.spec),
                            Ci.nsIWebNavigation.LOAD_FLAGS_NONE,
                            null, null, null);
    }
  },

  /**
   * See nsIWebContentConverterService
   */
  removeProtocolHandler:
  function WCCR_removeProtocolHandler(aProtocol, aURITemplate) {
    var eps = Cc["@mozilla.org/uriloader/external-protocol-service;1"].
              getService(Ci.nsIExternalProtocolService);
    var handlerInfo = eps.getProtocolHandlerInfo(aProtocol);
    var handlers =  handlerInfo.possibleApplicationHandlers;
    for (let i = 0; i < handlers.length; i++) {
      try { // We only want to test web handlers
        let handler = handlers.queryElementAt(i, Ci.nsIWebHandlerApp);
        if (handler.uriTemplate == aURITemplate) {
          handlers.removeElementAt(i);
          var hs = Cc["@mozilla.org/uriloader/handler-service;1"].
                   getService(Ci.nsIHandlerService);
          hs.store(handlerInfo);
          return;
        }
      } catch (e) { /* it wasn't a web handler */ }
    }
  },

  /**
   * See nsIWebContentConverterService
   */
  removeContentHandler:
  function WCCR_removeContentHandler(contentType, uri) {
    function notURI(serviceInfo) {
      return serviceInfo.uri != uri;
    }

    if (contentType in this._contentTypes) {
      this._contentTypes[contentType] =
        this._contentTypes[contentType].filter(notURI);
    }
  },

  /**
   *
   */
  _mappings: {
    "application/rss+xml": TYPE_MAYBE_FEED,
    "application/atom+xml": TYPE_MAYBE_FEED,
  },

  /**
   * These are types for which there is a separate content converter aside
   * from our built in generic one. We should not automatically register
   * a factory for creating a converter for these types.
   */
  _blockedTypes: {
    "application/vnd.mozilla.maybe.feed": true,
  },

  /**
   * Determines the "internal" content type based on the _mappings.
   * @param   contentType
   * @returns The resolved contentType value.
   */
  _resolveContentType:
  function WCCR__resolveContentType(contentType) {
    if (contentType in this._mappings)
      return this._mappings[contentType];
    return contentType;
  },

  _makeURI: function(aURL, aOriginCharset, aBaseURI) {
    var ioService = Components.classes["@mozilla.org/network/io-service;1"]
                              .getService(Components.interfaces.nsIIOService);
    return ioService.newURI(aURL, aOriginCharset, aBaseURI);
  },

  _checkAndGetURI:
  function WCCR_checkAndGetURI(aURIString, aContentWindow)
  {
    try {
      var uri = this._makeURI(aURIString);
    } catch (ex) {
      // not supposed to throw according to spec
      return;
    }

    // For security reasons we reject non-http(s) urls (see bug 354316),
    // we may need to revise this once we support more content types
    // XXX this should be a "security exception" according to spec, but that
    // isn't defined yet.
    if (uri.scheme != "http" && uri.scheme != "https")
      throw("Permission denied to add " + uri.spec + " as a content or protocol handler");

    // We also reject handlers registered from a different host (see bug 402287)
    // The pref allows us to test the feature
    var pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
    if ((!pb.prefHasUserValue(PREF_ALLOW_DIFFERENT_HOST) ||
         !pb.getBoolPref(PREF_ALLOW_DIFFERENT_HOST)) &&
        aContentWindow.location.hostname != uri.host)
      throw("Permission denied to add " + uri.spec + " as a content or protocol handler");

    // If the uri doesn't contain '%s', it won't be a good handler
    if (uri.spec.indexOf("%s") < 0)
      throw NS_ERROR_DOM_SYNTAX_ERR;

    return uri;
  },

  /**
   * Determines if a web handler is already registered.
   *
   * @param aProtocol
   *        The scheme of the web handler we are checking for.
   * @param aURITemplate
   *        The URI template that the handler uses to handle the protocol.
   * @return true if it is already registered, false otherwise.
   */
  _protocolHandlerRegistered:
  function WCCR_protocolHandlerRegistered(aProtocol, aURITemplate) {
    var eps = Cc["@mozilla.org/uriloader/external-protocol-service;1"].
              getService(Ci.nsIExternalProtocolService);
    var handlerInfo = eps.getProtocolHandlerInfo(aProtocol);
    var handlers =  handlerInfo.possibleApplicationHandlers;
    for (let i = 0; i < handlers.length; i++) {
      try { // We only want to test web handlers
        let handler = handlers.queryElementAt(i, Ci.nsIWebHandlerApp);
        if (handler.uriTemplate == aURITemplate)
          return true;
      } catch (e) { /* it wasn't a web handler */ }
    }
    return false;
  },

  /**
   * See nsIWebContentHandlerRegistrar
   */
  registerProtocolHandler:
  function WCCR_registerProtocolHandler(aProtocol, aURIString, aTitle, aContentWindow) {
    LOG("registerProtocolHandler(" + aProtocol + "," + aURIString + "," + aTitle + ")");

    var browserWindow = this._getBrowserWindowForContentWindow(aContentWindow);
    if (browserWindow.gPrivateBrowsingUI.privateWindow) {
      // Inside the private browsing mode, we don't want to alert the user to save
      // a protocol handler.  We log it to the error console so that web developers
      // would have some way to tell what's going wrong.
      Cc["@mozilla.org/consoleservice;1"].
      getService(Ci.nsIConsoleService).
      logStringMessage("Web page denied access to register a protocol handler inside private browsing mode");
      return;
    }

    // First, check to make sure this isn't already handled internally (we don't
    // want to let them take over, say "chrome").
    var ios = Cc["@mozilla.org/network/io-service;1"].
              getService(Ci.nsIIOService);
    var handler = ios.getProtocolHandler(aProtocol);
    if (!(handler instanceof Ci.nsIExternalProtocolHandler)) {
      // This is handled internally, so we don't want them to register
      // XXX this should be a "security exception" according to spec, but that
      // isn't defined yet.
      throw("Permission denied to add " + aURIString + "as a protocol handler");
    }

    // check if it is in the black list
    var pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
    var allowed;
    try {
      allowed = pb.getBoolPref(PREF_HANDLER_EXTERNAL_PREFIX + "." + aProtocol);
    }
    catch (e) {
      allowed = pb.getBoolPref(PREF_HANDLER_EXTERNAL_PREFIX + "-default");
    }
    if (!allowed) {
      // XXX this should be a "security exception" according to spec
      throw("Not allowed to register a protocol handler for " + aProtocol);
    }

    var uri = this._checkAndGetURI(aURIString, aContentWindow);

    var buttons, message;
    if (this._protocolHandlerRegistered(aProtocol, uri.spec))
      message = this._getFormattedString("protocolHandlerRegistered",
                                         [aTitle, aProtocol]);
    else {
      // Now Ask the user and provide the proper callback
      message = this._getFormattedString("addProtocolHandler",
                                         [aTitle, uri.host, aProtocol]);

      var notificationIcon = uri.prePath + "/favicon.ico";
      var notificationValue = "Protocol Registration: " + aProtocol;
      var addButton = {
        label: this._getString("addProtocolHandlerAddButton"),
        accessKey: this._getString("addHandlerAddButtonAccesskey"),
        protocolInfo: { protocol: aProtocol, uri: uri.spec, name: aTitle },

        callback:
        function WCCR_addProtocolHandlerButtonCallback(aNotification, aButtonInfo) {
          var protocol = aButtonInfo.protocolInfo.protocol;
          var uri      = aButtonInfo.protocolInfo.uri;
          var name     = aButtonInfo.protocolInfo.name;

          var handler = Cc["@mozilla.org/uriloader/web-handler-app;1"].
                        createInstance(Ci.nsIWebHandlerApp);
          handler.name = name;
          handler.uriTemplate = uri;

          var eps = Cc["@mozilla.org/uriloader/external-protocol-service;1"].
                    getService(Ci.nsIExternalProtocolService);
          var handlerInfo = eps.getProtocolHandlerInfo(protocol);
          handlerInfo.possibleApplicationHandlers.appendElement(handler, false);

          // Since the user has agreed to add a new handler, chances are good
          // that the next time they see a handler of this type, they're going
          // to want to use it.  Reset the handlerInfo to ask before the next
          // use.
          handlerInfo.alwaysAskBeforeHandling = true;

          var hs = Cc["@mozilla.org/uriloader/handler-service;1"].
                   getService(Ci.nsIHandlerService);
          hs.store(handlerInfo);
        }
      };
      buttons = [addButton];
    }

    var browserElement = this._getBrowserForContentWindow(browserWindow, aContentWindow);
    var notificationBox = browserWindow.getBrowser().getNotificationBox(browserElement);
    notificationBox.appendNotification(message,
                                       notificationValue,
                                       notificationIcon,
                                       notificationBox.PRIORITY_INFO_LOW,
                                       buttons);
  },

  /**
   * See nsIWebContentHandlerRegistrar
   * If a DOM window is provided, then the request came from content, so we
   * prompt the user to confirm the registration.
   */
  registerContentHandler:
  function WCCR_registerContentHandler(aContentType, aURIString, aTitle, aContentWindow) {
    LOG("registerContentHandler(" + aContentType + "," + aURIString + "," + aTitle + ")");

    // We only support feed types at present.
    // XXX this should be a "security exception" according to spec, but that
    // isn't defined yet.
    var contentType = this._resolveContentType(aContentType);
    if (contentType != TYPE_MAYBE_FEED)
      return;

    if (aContentWindow) {
      var uri = this._checkAndGetURI(aURIString, aContentWindow);

      var browserWindow = this._getBrowserWindowForContentWindow(aContentWindow);
      var browserElement = this._getBrowserForContentWindow(browserWindow, aContentWindow);
      var notificationBox = browserWindow.getBrowser().getNotificationBox(browserElement);
      this._appendFeedReaderNotification(uri, aTitle, notificationBox);
    }
    else
      this._registerContentHandler(contentType, aURIString, aTitle);
  },

  /**
   * Returns the browser chrome window in which the content window is in
   */
  _getBrowserWindowForContentWindow:
  function WCCR__getBrowserWindowForContentWindow(aContentWindow) {
    return aContentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
                         .getInterface(Ci.nsIWebNavigation)
                         .QueryInterface(Ci.nsIDocShellTreeItem)
                         .rootTreeItem
                         .QueryInterface(Ci.nsIInterfaceRequestor)
                         .getInterface(Ci.nsIDOMWindow)
                         .wrappedJSObject;
  },

  /**
   * Returns the <xul:browser> element associated with the given content
   * window.
   *
   * @param aBrowserWindow
   *        The browser window in which the content window is in.
   * @param aContentWindow
   *        The content window. It's possible to pass a child content window
   *        (i.e. the content window of a frame/iframe).
   */
  _getBrowserForContentWindow:
  function WCCR__getBrowserForContentWindow(aBrowserWindow, aContentWindow) {
    // This depends on pseudo APIs of browser.js and tabbrowser.xml
    aContentWindow = aContentWindow.top;
    var browsers = aBrowserWindow.getBrowser().browsers;
    for (var i = 0; i < browsers.length; ++i) {
      if (browsers[i].contentWindow == aContentWindow)
        return browsers[i];
    }
  },

  /**
   * Appends a notifcation for the given feed reader details.
   *
   * The notification could be either a pseudo-dialog which lets
   * the user to add the feed reader:
   * [ [icon] Add %feed-reader-name% (%feed-reader-host%) as a Feed Reader?  (Add) [x] ]
   *
   * or a simple message for the case where the feed reader is already registered:
   * [ [icon] %feed-reader-name% is already registered as a Feed Reader             [x] ]
   *
   * A new notification isn't appended if the given notificationbox has a
   * notification for the same feed reader.
   *
   * @param aURI
   *        The url of the feed reader as a nsIURI object
   * @param aName
   *        The feed reader name as it was passed to registerContentHandler
   * @param aNotificationBox
   *        The notification box to which a notification might be appended
   * @return true if a notification has been appended, false otherwise.
   */
  _appendFeedReaderNotification:
  function WCCR__appendFeedReaderNotification(aURI, aName, aNotificationBox) {
    var uriSpec = aURI.spec;
    var notificationValue = "feed reader notification: " + uriSpec;
    var notificationIcon = aURI.prePath + "/favicon.ico";

    // Don't append a new notification if the notificationbox
    // has a notification for the given feed reader already
    if (aNotificationBox.getNotificationWithValue(notificationValue))
      return false;

    var buttons, message;
    if (this.getWebContentHandlerByURI(TYPE_MAYBE_FEED, uriSpec))
      message = this._getFormattedString("handlerRegistered", [aName]);
    else {
      message = this._getFormattedString("addHandler", [aName, aURI.host]);
      var self = this;
      var addButton = {
        _outer: self,
        label: self._getString("addHandlerAddButton"),
        accessKey: self._getString("addHandlerAddButtonAccesskey"),
        feedReaderInfo: { uri: uriSpec, name: aName },

        /* static */
        callback:
        function WCCR__addFeedReaderButtonCallback(aNotification, aButtonInfo) {
          var uri = aButtonInfo.feedReaderInfo.uri;
          var name = aButtonInfo.feedReaderInfo.name;
          var outer = aButtonInfo._outer;

          // The reader could have been added from another window mean while
          if (!outer.getWebContentHandlerByURI(TYPE_MAYBE_FEED, uri))
            outer._registerContentHandler(TYPE_MAYBE_FEED, uri, name);

          // avoid reference cycles
          aButtonInfo._outer = null;

          return false;
        }
      };
      buttons = [addButton];
    }

    aNotificationBox.appendNotification(message,
                                        notificationValue,
                                        notificationIcon,
                                        aNotificationBox.PRIORITY_INFO_LOW,
                                        buttons);
    return true;
  },

  /**
   * Save Web Content Handler metadata to persistent preferences.
   * @param   contentType
   *          The content Type being handled
   * @param   uri
   *          The uri of the web service
   * @param   title
   *          The human readable name of the web service
   *
   * This data is stored under:
   *
   *    browser.contentHandlers.type0 = content/type
   *    browser.contentHandlers.uri0 = http://www.foo.com/q=%s
   *    browser.contentHandlers.title0 = Foo 2.0alphr
   */
  _saveContentHandlerToPrefs:
  function WCCR__saveContentHandlerToPrefs(contentType, uri, title) {
    var ps =
        Cc["@mozilla.org/preferences-service;1"].
        getService(Ci.nsIPrefService);
    var i = 0;
    var typeBranch = null;
    while (true) {
      typeBranch =
        ps.getBranch(PREF_CONTENTHANDLERS_BRANCH + i + ".");
      try {
        typeBranch.getCharPref("type");
        ++i;
      }
      catch (e) {
        // No more handlers
        break;
      }
    }
    if (typeBranch) {
      typeBranch.setCharPref("type", contentType);
      var pls =
          Cc["@mozilla.org/pref-localizedstring;1"].
          createInstance(Ci.nsIPrefLocalizedString);
      pls.data = uri;
      typeBranch.setComplexValue("uri", Ci.nsIPrefLocalizedString, pls);
      pls.data = title;
      typeBranch.setComplexValue("title", Ci.nsIPrefLocalizedString, pls);

      ps.savePrefFile(null);
    }
  },

  /**
   * Determines if there is a type with a particular uri registered for the
   * specified content type already.
   * @param   contentType
   *          The content type that the uri handles
   * @param   uri
   *          The uri of the
   */
  _typeIsRegistered: function WCCR__typeIsRegistered(contentType, uri) {
    if (!(contentType in this._contentTypes))
      return false;

    var services = this._contentTypes[contentType];
    for (var i = 0; i < services.length; ++i) {
      // This uri has already been registered
      if (services[i].uri == uri)
        return true;
    }
    return false;
  },

  /**
   * Gets a stream converter contract id for the specified content type.
   * @param   contentType
   *          The source content type for the conversion.
   * @returns A contract id to construct a converter to convert between the
   *          contentType and *\/*.
   */
  _getConverterContractID: function WCCR__getConverterContractID(contentType) {
    const template = "@mozilla.org/streamconv;1?from=%s&to=*/*";
    return template.replace(/%s/, contentType);
  },

  /**
   * Register a web service handler for a content type.
   *
   * @param   contentType
   *          the content type being handled
   * @param   uri
   *          the URI of the web service
   * @param   title
   *          the human readable name of the web service
   */
  _registerContentHandler:
  function WCCR__registerContentHandler(contentType, uri, title) {
    this._updateContentTypeHandlerMap(contentType, uri, title);
    this._saveContentHandlerToPrefs(contentType, uri, title);

    if (contentType == TYPE_MAYBE_FEED) {
      // Make the new handler the last-selected reader in the preview page
      // and make sure the preview page is shown the next time a feed is visited
      var pb = Cc["@mozilla.org/preferences-service;1"].
               getService(Ci.nsIPrefService).getBranch(null);
      pb.setCharPref(PREF_SELECTED_READER, "web");

      var supportsString =
        Cc["@mozilla.org/supports-string;1"].
        createInstance(Ci.nsISupportsString);
        supportsString.data = uri;
      pb.setComplexValue(PREF_SELECTED_WEB, Ci.nsISupportsString,
                         supportsString);
      pb.setCharPref(PREF_SELECTED_ACTION, "ask");
      this._setAutoHandler(TYPE_MAYBE_FEED, null);
    }
  },

  /**
   * Update the content type -> handler map. This mapping is not persisted, use
   * registerContentHandler or _saveContentHandlerToPrefs for that purpose.
   * @param   contentType
   *          The content Type being handled
   * @param   uri
   *          The uri of the web service
   * @param   title
   *          The human readable name of the web service
   */
  _updateContentTypeHandlerMap:
  function WCCR__updateContentTypeHandlerMap(contentType, uri, title) {
    if (!(contentType in this._contentTypes))
      this._contentTypes[contentType] = [];

    // Avoid adding duplicates
    if (this._typeIsRegistered(contentType, uri))
      return;

    this._contentTypes[contentType].push(new ServiceInfo(contentType, uri, title));

    if (!(contentType in this._blockedTypes)) {
      var converterContractID = this._getConverterContractID(contentType);
      var cr = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
      cr.registerFactory(WCC_CLASSID, WCC_CLASSNAME, converterContractID,
                         WebContentConverterFactory);
    }
  },

  /**
   * See nsIWebContentConverterService
   */
  getContentHandlers:
  function WCCR_getContentHandlers(contentType, countRef) {
    countRef.value = 0;
    if (!(contentType in this._contentTypes))
      return [];

    var handlers = this._contentTypes[contentType];
    countRef.value = handlers.length;
    return handlers;
  },

  /**
   * See nsIWebContentConverterService
   */
  resetHandlersForType:
  function WCCR_resetHandlersForType(contentType) {
    // currently unused within the tree, so only useful for extensions; previous
    // impl. was buggy (and even infinite-looped!), so I argue that this is a
    // definite improvement
    throw Cr.NS_ERROR_NOT_IMPLEMENTED;
  },

  /**
   * Registers a handler from the settings on a preferences branch.
   *
   * @param branch
   *        an nsIPrefBranch containing "type", "uri", and "title" preferences
   *        corresponding to the content handler to be registered
   */
  _registerContentHandlerWithBranch: function(branch) {
    /**
     * Since we support up to six predefined readers, we need to handle gaps
     * better, since the first branch with user-added values will be .6
     *
     * How we deal with that is to check to see if there's no prefs in the
     * branch and stop cycling once that's true.  This doesn't fix the case
     * where a user manually removes a reader, but that's not supported yet!
     */
    var vals = branch.getChildList("");
    if (vals.length == 0)
      return;

    try {
      var type = branch.getCharPref("type");
      var uri = branch.getComplexValue("uri", Ci.nsIPrefLocalizedString).data;
      var title = branch.getComplexValue("title",
                                         Ci.nsIPrefLocalizedString).data;
      this._updateContentTypeHandlerMap(type, uri, title);
    }
    catch(ex) {
      // do nothing, the next branch might have values
    }
  },

  /**
   * Load the auto handler, content handler and protocol tables from
   * preferences.
   */
  _init: function WCCR__init() {
    var ps =
        Cc["@mozilla.org/preferences-service;1"].
        getService(Ci.nsIPrefService);

    var kids = ps.getBranch(PREF_CONTENTHANDLERS_BRANCH)
                 .getChildList("");

    // first get the numbers of the providers by getting all ###.uri prefs
    var nums = [];
    for (var i = 0; i < kids.length; i++) {
      var match = /^(\d+)\.uri$/.exec(kids[i]);
      if (!match)
        continue;
      else
        nums.push(match[1]);
    }

    // sort them, to get them back in order
    nums.sort(function(a, b) {return a - b;});

    // now register them
    for (var i = 0; i < nums.length; i++) {
      var branch = ps.getBranch(PREF_CONTENTHANDLERS_BRANCH + nums[i] + ".");
      this._registerContentHandlerWithBranch(branch);
    }

    // We need to do this _after_ registering all of the available handlers,
    // so that getWebContentHandlerByURI can return successfully.
    try {
      var autoBranch = ps.getBranch(PREF_CONTENTHANDLERS_AUTO);
      var childPrefs = autoBranch.getChildList("");
      for (var i = 0; i < childPrefs.length; ++i) {
        var type = childPrefs[i];
        var uri = autoBranch.getCharPref(type);
        if (uri) {
          var handler = this.getWebContentHandlerByURI(type, uri);
          this._setAutoHandler(type, handler);
        }
      }
    }
    catch (e) {
      // No auto branch yet, that's fine
      //LOG("WCCR.init: There is no auto branch, benign");
    }
  },

  /**
   * See nsIObserver
   */
  observe: function WCCR_observe(subject, topic, data) {
    var os =
        Cc["@mozilla.org/observer-service;1"].
        getService(Ci.nsIObserverService);
    switch (topic) {
    case "app-startup":
      os.addObserver(this, "browser-ui-startup-complete", false);
      break;
    case "browser-ui-startup-complete":
      os.removeObserver(this, "browser-ui-startup-complete");
      this._init();
      break;
    }
  },

  /**
   * See nsIFactory
   */
  createInstance: function WCCR_createInstance(outer, iid) {
    if (outer != null)
      throw Cr.NS_ERROR_NO_AGGREGATION;
    return this.QueryInterface(iid);
  },

  classID: WCCR_CLASSID,
  classInfo: XPCOMUtils.generateCI({classID: WCCR_CLASSID,
                                    contractID: WCCR_CONTRACTID,
                                    interfaces: [Ci.nsIWebContentConverterService,
                                                 Ci.nsIWebContentHandlerRegistrar,
                                                 Ci.nsIObserver, Ci.nsIFactory],
                                    flags: Ci.nsIClassInfo.DOM_OBJECT}),

  /**
   * See nsISupports
   */
  QueryInterface: XPCOMUtils.generateQI(
     [Ci.nsIWebContentConverterService,
      Ci.nsIWebContentHandlerRegistrar,
      Ci.nsIObserver,
      Ci.nsIFactory]),

  _xpcom_categories: [{
    category: "app-startup",
    service: true
  }]
};

this.NSGetFactory = XPCOMUtils.generateNSGetFactory([WebContentConverterRegistrar]);


text:
package com.flipper.example.insidelist.activity;

import android.os.Bundle;
import android.view.Menu;
import com.flipper.example.insidelist.R;
import com.flipper.example.insidelist.adapter.DebugAdapter;
import com.flipper.example.insidelist.component.DebugListView;
import com.flipper.example.insidelist.model.DataModel;
import com.flipper.example.insidelist.rendermodel.RenderDebug;

import java.util.ArrayList;

public class NoRecycleActivity extends InsideBaseListActivity {

    private static final int INIT_VALUES = 100;
    ArrayList<DataModel> listValues = new ArrayList<DataModel>();
    DebugAdapter adapter;
    private DebugListView lv_list;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_inside_list);
        mapGUI();
    }

    @Override
    protected void refreshList() {
        super.refreshList();
        lv_list.invalidateViews();
    }

    private void mapGUI() {
        lv_list = (DebugListView) findViewById(R.id.ll_list);
        initAdapter();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    private void initAdapter() {

        //init avatars(this works because resids are consecutive,
        //not good practices)
        //init values to insert
        for (int i = 0; i < INIT_VALUES; i++) {
            DataModel data = new DataModel();
            data.setAvatar(R.drawable.avatar_1 + i);
            data.setTitle("pos " + i);

            listValues.add(data);
        }

        adapter = new DebugAdapter(getApplicationContext(), listValues);
        adapter.registerRender(DataModel.class, RenderDebug.class);
        adapter.deactivateRecycle();

        adapter.setGeneralInfoListener(this);
        lv_list.setAdapter(adapter);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        return true;
    }

}


text:
package org.openkilda.wfm.topology.flowmonitoring.service;

import org.openkilda.server42.messaging.FlowDirection;
import org.openkilda.wfm.topology.flowmonitoring.model.Link;

import java.time.Duration;
import java.util.List;

public interface FlowCacheBoltCarrier {

    void emitCalculateFlowLatencyRequest(String flowId, FlowDirection direction, List<Link> flowPath);

    void emitGetLinkLatencyRequest(String flowId, String requestId, Link link);

    void emitCheckFlowLatencyRequest(String flowId, FlowDirection direction, Duration latency);

    public void emitLatencyStats(String flowId, FlowDirection direction, Duration latency);
}


text:
import Collapse from '../../src/collapse'
import EventHandler from '../../src/dom/event-handler'
import { makeArray } from '../../src/util/index'

/** Test helpers */
import { getFixture, clearFixture, jQueryMock } from '../helpers/fixture'

describe('Collapse', () => {
  let fixtureEl

  beforeAll(() => {
    fixtureEl = getFixture()
  })

  afterEach(() => {
    clearFixture()
  })

  describe('VERSION', () => {
    it('should return plugin version', () => {
      expect(Collapse.VERSION).toEqual(jasmine.any(String))
    })
  })

  describe('Default', () => {
    it('should return plugin default config', () => {
      expect(Collapse.Default).toEqual(jasmine.any(Object))
    })
  })

  describe('constructor', () => {
    it('should allow jquery object in parent config', () => {
      fixtureEl.innerHTML = [
        '
',
        '
',
        '    Toggle item',
        '
Lorem ipsum
',
        '
',
        '
'
      ].join('')

      const collapseEl = fixtureEl.querySelector('div.collapse')
      const myCollapseEl = fixtureEl.querySelector('.my-collapse')
      const fakejQueryObject = {
        0: myCollapseEl
      }
      const collapse = new Collapse(collapseEl, {
        parent: fakejQueryObject
      })

      expect(collapse._config.parent).toEqual(fakejQueryObject)
      expect(collapse._getParent()).toEqual(myCollapseEl)
    })

    it('should allow non jquery object in parent config', () => {
      fixtureEl.innerHTML = [
        '
',
        '
',
        '    Toggle item',
        '
Lorem ipsum
',
        '
',
        '
'
      ].join('')

      const collapseEl = fixtureEl.querySelector('div.collapse')
      const myCollapseEl = fixtureEl.querySelector('.my-collapse')
      const collapse = new Collapse(collapseEl, {
        parent: myCollapseEl
      })

      expect(collapse._config.parent).toEqual(myCollapseEl)
    })

    it('should allow string selector in parent config', () => {
      fixtureEl.innerHTML = [
        '
',
        '
',
        '    Toggle item',
        '
Lorem ipsum
',
        '
',
        '
'
      ].join('')

      const collapseEl = fixtureEl.querySelector('div.collapse')
      const myCollapseEl = fixtureEl.querySelector('.my-collapse')
      const collapse = new Collapse(collapseEl, {
        parent: 'div.my-collapse'
      })

      expect(collapse._config.parent).toEqual('div.my-collapse')
      expect(collapse._getParent()).toEqual(myCollapseEl)
    })
  })

  describe('toggle', () => {
    it('should call show method if show class is not present', () => {
      fixtureEl.innerHTML = '

'

      const collapseEl = fixtureEl.querySelector('div')
      const collapse = new Collapse(collapseEl)

      spyOn(collapse, 'show')

      collapse.toggle()

      expect(collapse.show).toHaveBeenCalled()
    })

    it('should call hide method if show class is present', () => {
      fixtureEl.innerHTML = '

'

      const collapseEl = fixtureEl.querySelector('.show')
      const collapse = new Collapse(collapseEl, {
        toggle: false
      })

      spyOn(collapse, 'hide')

      collapse.toggle()

      expect(collapse.hide).toHaveBeenCalled()
    })

    it('should find collapse children if they have collapse class too not only data-parent', done => {
      fixtureEl.innerHTML = [
        '
',
        '
',
        '    Toggle item 1',
        '
Lorem ipsum 1
',
        '
',
        '
',
        '    Toggle item 2',
        '
Lorem ipsum 2
',
        '
',
        '
'
      ].join('')

      const parent = fixtureEl.querySelector('.my-collapse')
      const collapseEl1 = fixtureEl.querySelector('#collapse1')
      const collapseEl2 = fixtureEl.querySelector('#collapse2')

      const collapseList = makeArray(fixtureEl.querySelectorAll('.collapse'))
        .map(el => new Collapse(el, {
          parent,
          toggle: false
        }))

      collapseEl2.addEventListener('shown.bs.collapse', () => {
        expect(collapseEl2.classList.contains('show')).toEqual(true)
        expect(collapseEl1.classList.contains('show')).toEqual(false)
        done()
      })

      collapseList[1].toggle()
    })
  })

  describe('show', () => {
    it('should do nothing if is transitioning', () => {
      fixtureEl.innerHTML = '

'

      spyOn(EventHandler, 'trigger')

      const collapseEl = fixtureEl.querySelector('div')
      const collapse = new Collapse(collapseEl, {
        toggle: false
      })

      collapse._isTransitioning = true
      collapse.show()

      expect(EventHandler.trigger).not.toHaveBeenCalled()
    })

    it('should do nothing if already shown', () => {
      fixtureEl.innerHTML = '

'

      spyOn(EventHandler, 'trigger')

      const collapseEl = fixtureEl.querySelector('div')
      const collapse = new Collapse(collapseEl, {
        toggle: false
      })

      collapse.show()

      expect(EventHandler.trigger).not.toHaveBeenCalled()
    })

    it('should show a collapsed element', done => {
      fixtureEl.innerHTML = '

'

      const collapseEl = fixtureEl.querySelector('div')
      const collapse = new Collapse(collapseEl, {
        toggle: false
      })

      collapseEl.addEventListener('show.bs.collapse', () => {
        expect(collapseEl.style.height).toEqual('0px')
      })
      collapseEl.addEventListener('shown.bs.collapse', () => {
        expect(collapseEl.classList.contains('show')).toEqual(true)
        expect(collapseEl.style.height).toEqual('')
        done()
      })

      collapse.show()
    })

    it('should show a collapsed element on width', done => {
      fixtureEl.innerHTML = '

'

      const collapseEl = fixtureEl.querySelector('div')
      const collapse = new Collapse(collapseEl, {
        toggle: false
      })

      collapseEl.addEventListener('show.bs.collapse', () => {
        expect(collapseEl.style.width).toEqual('0px')
      })
      collapseEl.addEventListener('shown.bs.collapse', () => {
        expect(collapseEl.classList.contains('show')).toEqual(true)
        expect(collapseEl.style.width).toEqual('')
        done()
      })

      collapse.show()
    })

    it('should collapse only the first collapse', done => {
      fixtureEl.innerHTML = [
        '
',
        '
',
        '
',
        '
',
        '
',
        '
'
      ].join('')

      const el1 = fixtureEl.querySelector('#collapse1')
      const el2 = fixtureEl.querySelector('#collapse2')
      const collapse = new Collapse(el1, {
        toggle: false
      })

      el1.addEventListener('shown.bs.collapse', () => {
        expect(el1.classList.contains('show')).toEqual(true)
        expect(el2.classList.contains('show')).toEqual(true)
        done()
      })

      collapse.show()
    })

    it('should not fire shown when show is prevented', done => {
      fixtureEl.innerHTML = '

'

      const collapseEl = fixtureEl.querySelector('div')
      const collapse = new Collapse(collapseEl, {
        toggle: false
      })

      const expectEnd = () => {
        setTimeout(() => {
          expect().nothing()
          done()
        }, 10)
      }

      collapseEl.addEventListener('show.bs.collapse', e => {
        e.preventDefault()
        expectEnd()
      })

      collapseEl.addEventListener('shown.bs.collapse', () => {
        throw new Error('should not fire shown event')
      })

      collapse.show()
    })
  })

  describe('hide', () => {
    it('should do nothing if is transitioning', () => {
      fixtureEl.innerHTML = '

'

      spyOn(EventHandler, 'trigger')

      const collapseEl = fixtureEl.querySelector('div')
      const collapse = new Collapse(collapseEl, {
        toggle: false
      })

      collapse._isTransitioning = true
      collapse.hide()

      expect(EventHandler.trigger).not.toHaveBeenCalled()
    })

    it('should do nothing if already shown', () => {
      fixtureEl.innerHTML = '

'

      spyOn(EventHandler, 'trigger')

      const collapseEl = fixtureEl.querySelector('div')
      const collapse = new Collapse(collapseEl, {
        toggle: false
      })

      collapse.hide()

      expect(EventHandler.trigger).not.toHaveBeenCalled()
    })

    it('should hide a collapsed element', done => {
      fixtureEl.innerHTML = '

'

      const collapseEl = fixtureEl.querySelector('div')
      const collapse = new Collapse(collapseEl, {
        toggle: false
      })

      collapseEl.addEventListener('hidden.bs.collapse', () => {
        expect(collapseEl.classList.contains('show')).toEqual(false)
        expect(collapseEl.style.height).toEqual('')
        done()
      })

      collapse.hide()
    })

    it('should not fire hidden when hide is prevented', done => {
      fixtureEl.innerHTML = '

'

      const collapseEl = fixtureEl.querySelector('div')
      const collapse = new Collapse(collapseEl, {
        toggle: false
      })

      const expectEnd = () => {
        setTimeout(() => {
          expect().nothing()
          done()
        }, 10)
      }

      collapseEl.addEventListener('hide.bs.collapse', e => {
        e.preventDefault()
        expectEnd()
      })

      collapseEl.addEventListener('hidden.bs.collapse', () => {
        throw new Error('should not fire hidden event')
      })

      collapse.hide()
    })
  })

  describe('dispose', () => {
    it('should destroy a collapse', () => {
      fixtureEl.innerHTML = '

'

      const collapseEl = fixtureEl.querySelector('div')
      const collapse = new Collapse(collapseEl, {
        toggle: false
      })

      expect(Collapse.getInstance(collapseEl)).toEqual(collapse)

      collapse.dispose()

      expect(Collapse.getInstance(collapseEl)).toEqual(null)
    })
  })

  describe('data-api', () => {
    it('should show multiple collapsed elements', done => {
      fixtureEl.innerHTML = [
        '',
        '
',
        '
'
      ].join('')

      const trigger = fixtureEl.querySelector('a')
      const collapse1 = fixtureEl.querySelector('#collapse1')
      const collapse2 = fixtureEl.querySelector('#collapse2')

      collapse2.addEventListener('shown.bs.collapse', () => {
        expect(trigger.getAttribute('aria-expanded')).toEqual('true')
        expect(trigger.classList.contains('collapsed')).toEqual(false)
        expect(collapse1.classList.contains('show')).toEqual(true)
        expect(collapse1.classList.contains('show')).toEqual(true)
        done()
      })

      trigger.click()
    })

    it('should hide multiple collapsed elements', done => {
      fixtureEl.innerHTML = [
        '',
        '
',
        '
'
      ].join('')

      const trigger = fixtureEl.querySelector('a')
      const collapse1 = fixtureEl.querySelector('#collapse1')
      const collapse2 = fixtureEl.querySelector('#collapse2')

      collapse2.addEventListener('hidden.bs.collapse', () => {
        expect(trigger.getAttribute('aria-expanded')).toEqual('false')
        expect(trigger.classList.contains('collapsed')).toEqual(true)
        expect(collapse1.classList.contains('show')).toEqual(false)
        expect(collapse1.classList.contains('show')).toEqual(false)
        done()
      })

      trigger.click()
    })

    it('should remove "collapsed" class from target when collapse is shown', done => {
      fixtureEl.innerHTML = [
        '',
        '',
        '

'
      ].join('')

      const link1 = fixtureEl.querySelector('#link1')
      const link2 = fixtureEl.querySelector('#link2')
      const collapseTest1 = fixtureEl.querySelector('#test1')

      collapseTest1.addEventListener('shown.bs.collapse', () => {
        expect(link1.getAttribute('aria-expanded')).toEqual('true')
        expect(link2.getAttribute('aria-expanded')).toEqual('true')
        expect(link1.classList.contains('collapsed')).toEqual(false)
        expect(link2.classList.contains('collapsed')).toEqual(false)
        done()
      })

      link1.click()
    })

    it('should add "collapsed" class to target when collapse is hidden', done => {
      fixtureEl.innerHTML = [
        '',
        '',
        '

'
      ].join('')

      const link1 = fixtureEl.querySelector('#link1')
      const link2 = fixtureEl.querySelector('#link2')
      const collapseTest1 = fixtureEl.querySelector('#test1')

      collapseTest1.addEventListener('hidden.bs.collapse', () => {
        expect(link1.getAttribute('aria-expanded')).toEqual('false')
        expect(link2.getAttribute('aria-expanded')).toEqual('false')
        expect(link1.classList.contains('collapsed')).toEqual(true)
        expect(link2.classList.contains('collapsed')).toEqual(true)
        done()
      })

      link1.click()
    })

    it('should allow accordion to use children other than card', done => {
      fixtureEl.innerHTML = [
        '
',
        '
',
        '    ',
        '

',
        '
',
        '
',
        '    ',
        '

',
        '
',
        '
'
      ].join('')

      const trigger = fixtureEl.querySelector('#linkTrigger')
      const triggerTwo = fixtureEl.querySelector('#linkTriggerTwo')
      const collapseOne = fixtureEl.querySelector('#collapseOne')
      const collapseTwo = fixtureEl.querySelector('#collapseTwo')

      collapseOne.addEventListener('shown.bs.collapse', () => {
        expect(collapseOne.classList.contains('show')).toEqual(true)
        expect(collapseTwo.classList.contains('show')).toEqual(false)

        collapseTwo.addEventListener('shown.bs.collapse', () => {
          expect(collapseOne.classList.contains('show')).toEqual(false)
          expect(collapseTwo.classList.contains('show')).toEqual(true)
          done()
        })

        triggerTwo.click()
      })

      trigger.click()
    })

    it('should not prevent event for input', done => {
      fixtureEl.innerHTML = [
        '<input type="checkbox" data-toggle="collapse" data-target="#collapsediv1" />',
        '

'
      ].join('')

      const target = fixtureEl.querySelector('input')
      const collapseEl = fixtureEl.querySelector('#collapsediv1')

      collapseEl.addEventListener('shown.bs.collapse', () => {
        expect(collapseEl.classList.contains('show')).toEqual(true)
        expect(target.checked).toEqual(true)
        done()
      })

      target.click()
    })

    it('should allow accordion to contain nested elements', done => {
      fixtureEl.innerHTML = [
        '
',
        '
',
        '
',
        '
',
        '        ',
        '

',
        '
',
        '
',
        '
',
        '
',
        '        ',
        '

',
        '
',
        '
',
        '
',
        '
'
      ].join('')

      const triggerEl = fixtureEl.querySelector('#linkTrigger')
      const triggerTwoEl = fixtureEl.querySelector('#linkTriggerTwo')
      const collapseOneEl = fixtureEl.querySelector('#collapseOne')
      const collapseTwoEl = fixtureEl.querySelector('#collapseTwo')

      collapseOneEl.addEventListener('shown.bs.collapse', () => {
        expect(collapseOneEl.classList.contains('show')).toEqual(true)
        expect(triggerEl.classList.contains('collapsed')).toEqual(false)
        expect(triggerEl.getAttribute('aria-expanded')).toEqual('true')

        expect(collapseTwoEl.classList.contains('show')).toEqual(false)
        expect(triggerTwoEl.classList.contains('collapsed')).toEqual(true)
        expect(triggerTwoEl.getAttribute('aria-expanded')).toEqual('false')

        collapseTwoEl.addEventListener('shown.bs.collapse', () => {
          expect(collapseOneEl.classList.contains('show')).toEqual(false)
          expect(triggerEl.classList.contains('collapsed')).toEqual(true)
          expect(triggerEl.getAttribute('aria-expanded')).toEqual('false')

          expect(collapseTwoEl.classList.contains('show')).toEqual(true)
          expect(triggerTwoEl.classList.contains('collapsed')).toEqual(false)
          expect(triggerTwoEl.getAttribute('aria-expanded')).toEqual('true')
          done()
        })

        triggerTwoEl.click()
      })

      triggerEl.click()
    })

    it('should allow accordion to target multiple elements', done => {
      fixtureEl.innerHTML = [
        '
',
        '  ',
        '  ',
        '

',
        '

',
        '

',
        '

',
        '
'
      ].join('')

      const trigger = fixtureEl.querySelector('#linkTriggerOne')
      const triggerTwo = fixtureEl.querySelector('#linkTriggerTwo')
      const collapseOneOne = fixtureEl.querySelector('#collapseOneOne')
      const collapseOneTwo = fixtureEl.querySelector('#collapseOneTwo')
      const collapseTwoOne = fixtureEl.querySelector('#collapseTwoOne')
      const collapseTwoTwo = fixtureEl.querySelector('#collapseTwoTwo')
      const collapsedElements = {
        one: false,
        two: false
      }

      function firstTest() {
        expect(collapseOneOne.classList.contains('show')).toEqual(true)
        expect(collapseOneTwo.classList.contains('show')).toEqual(true)

        expect(collapseTwoOne.classList.contains('show')).toEqual(false)
        expect(collapseTwoTwo.classList.contains('show')).toEqual(false)

        triggerTwo.click()
      }

      function secondTest() {
        expect(collapseOneOne.classList.contains('show')).toEqual(false)
        expect(collapseOneTwo.classList.contains('show')).toEqual(false)

        expect(collapseTwoOne.classList.contains('show')).toEqual(true)
        expect(collapseTwoTwo.classList.contains('show')).toEqual(true)
        done()
      }

      collapseOneOne.addEventListener('shown.bs.collapse', () => {
        if (collapsedElements.one) {
          firstTest()
        } else {
          collapsedElements.one = true
        }
      })

      collapseOneTwo.addEventListener('shown.bs.collapse', () => {
        if (collapsedElements.one) {
          firstTest()
        } else {
          collapsedElements.one = true
        }
      })

      collapseTwoOne.addEventListener('shown.bs.collapse', () => {
        if (collapsedElements.two) {
          secondTest()
        } else {
          collapsedElements.two = true
        }
      })

      collapseTwoTwo.addEventListener('shown.bs.collapse', () => {
        if (collapsedElements.two) {
          secondTest()
        } else {
          collapsedElements.two = true
        }
      })

      trigger.click()
    })

    it('should collapse accordion children but not nested accordion children', done => {
      fixtureEl.innerHTML = [
        '
',
        '
',
        '    ',
        '
',
        '
',
        '
',
        '          ',
        '

',
        '
',
        '
',
        '
',
        '
',
        '
',
        '    ',
        '

',
        '
',
        '
'
      ].join('')

      const trigger = fixtureEl.querySelector('#linkTrigger')
      const triggerTwo = fixtureEl.querySelector('#linkTriggerTwo')
      const nestedTrigger = fixtureEl.querySelector('#nestedLinkTrigger')
      const collapseOne = fixtureEl.querySelector('#collapseOne')
      const collapseTwo = fixtureEl.querySelector('#collapseTwo')
      const nestedCollapseOne = fixtureEl.querySelector('#nestedCollapseOne')

      function handlerCollapseOne() {
        expect(collapseOne.classList.contains('show')).toEqual(true)
        expect(collapseTwo.classList.contains('show')).toEqual(false)
        expect(nestedCollapseOne.classList.contains('show')).toEqual(false)

        nestedCollapseOne.addEventListener('shown.bs.collapse', handlerNestedCollapseOne)
        nestedTrigger.click()
        collapseOne.removeEventListener('shown.bs.collapse', handlerCollapseOne)
      }

      function handlerNestedCollapseOne() {
        expect(collapseOne.classList.contains('show')).toEqual(true)
        expect(collapseTwo.classList.contains('show')).toEqual(false)
        expect(nestedCollapseOne.classList.contains('show')).toEqual(true)

        collapseTwo.addEventListener('shown.bs.collapse', () => {
          expect(collapseOne.classList.contains('show')).toEqual(false)
          expect(collapseTwo.classList.contains('show')).toEqual(true)
          expect(nestedCollapseOne.classList.contains('show')).toEqual(true)
          done()
        })

        triggerTwo.click()
        nestedCollapseOne.removeEventListener('shown.bs.collapse', handlerNestedCollapseOne)
      }

      collapseOne.addEventListener('shown.bs.collapse', handlerCollapseOne)
      trigger.click()
    })

    it('should add "collapsed" class and set aria-expanded to triggers only when all the targeted collapse are hidden', done => {
      fixtureEl.innerHTML = [
        '',
        '',
        '',
        '
',
        '
'
      ].join('')

      const trigger1 = fixtureEl.querySelector('#trigger1')
      const trigger2 = fixtureEl.querySelector('#trigger2')
      const trigger3 = fixtureEl.querySelector('#trigger3')
      const target1 = fixtureEl.querySelector('#test1')
      const target2 = fixtureEl.querySelector('#test2')

      const target2Shown = () => {
        expect(trigger1.classList.contains('collapsed')).toEqual(false)
        expect(trigger1.getAttribute('aria-expanded')).toEqual('true')

        expect(trigger2.classList.contains('collapsed')).toEqual(false)
        expect(trigger2.getAttribute('aria-expanded')).toEqual('true')

        expect(trigger3.classList.contains('collapsed')).toEqual(false)
        expect(trigger3.getAttribute('aria-expanded')).toEqual('true')

        target2.addEventListener('hidden.bs.collapse', () => {
          expect(trigger1.classList.contains('collapsed')).toEqual(false)
          expect(trigger1.getAttribute('aria-expanded')).toEqual('true')

          expect(trigger2.classList.contains('collapsed')).toEqual(true)
          expect(trigger2.getAttribute('aria-expanded')).toEqual('false')

          expect(trigger3.classList.contains('collapsed')).toEqual(false)
          expect(trigger3.getAttribute('aria-expanded')).toEqual('true')

          target1.addEventListener('hidden.bs.collapse', () => {
            expect(trigger1.classList.contains('collapsed')).toEqual(true)
            expect(trigger1.getAttribute('aria-expanded')).toEqual('false')

            expect(trigger2.classList.contains('collapsed')).toEqual(true)
            expect(trigger2.getAttribute('aria-expanded')).toEqual('false')

            expect(trigger3.classList.contains('collapsed')).toEqual(true)
            expect(trigger3.getAttribute('aria-expanded')).toEqual('false')
            done()
          })

          trigger1.click()
        })

        trigger2.click()
      }

      target2.addEventListener('shown.bs.collapse', target2Shown)
      trigger3.click()
    })
  })

  describe('jQueryInterface', () => {
    it('should create a collapse', () => {
      fixtureEl.innerHTML = '

'

      const div = fixtureEl.querySelector('div')

      jQueryMock.fn.collapse = Collapse.jQueryInterface
      jQueryMock.elements = [div]

      jQueryMock.fn.collapse.call(jQueryMock)

      expect(Collapse.getInstance(div)).toBeDefined()
    })

    it('should not re create a collapse', () => {
      fixtureEl.innerHTML = '

'

      const div = fixtureEl.querySelector('div')
      const collapse = new Collapse(div)

      jQueryMock.fn.collapse = Collapse.jQueryInterface
      jQueryMock.elements = [div]

      jQueryMock.fn.collapse.call(jQueryMock)

      expect(Collapse.getInstance(div)).toEqual(collapse)
    })

    it('should throw error on undefined method', () => {
      fixtureEl.innerHTML = '

'

      const div = fixtureEl.querySelector('div')
      const action = 'undefinedMethod'

      jQueryMock.fn.collapse = Collapse.jQueryInterface
      jQueryMock.elements = [div]

      try {
        jQueryMock.fn.collapse.call(jQueryMock, action)
      } catch (error) {
        expect(error.message).toEqual(`No method named "${action}"`)
      }
    })
  })

  describe('getInstance', () => {
    it('should return collapse instance', () => {
      fixtureEl.innerHTML = '

'

      const div = fixtureEl.querySelector('div')
      const collapse = new Collapse(div)

      expect(Collapse.getInstance(div)).toEqual(collapse)
    })

    it('should return null when there is no collapse instance', () => {
      fixtureEl.innerHTML = '

'

      const div = fixtureEl.querySelector('div')

      expect(Collapse.getInstance(div)).toEqual(null)
    })
  })
})