< Summary

Class:Clipboard
Assembly:Clipboard
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Clipboard/Clipboard.cs
Covered lines:19
Uncovered lines:1
Coverable lines:20
Total lines:72
Line coverage:95% (19 of 20)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Clipboard(...)0%110100%
Create()0%110100%
WriteText(...)0%6200%
ReadText()0%220100%
OnReadText(...)0%330100%
Dispose()0%110100%
Initialize()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Clipboard/Clipboard.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using DCL;
 4using DCL.Helpers;
 5
 6public class Clipboard : IClipboard
 7{
 6308    private readonly Queue<Promise<string>> promises = new Queue<Promise<string>>();
 9    private readonly IClipboardHandler handler = null;
 10
 11    /// <summary>
 12    /// Create a platform specific instance of Clipboard
 13    /// </summary>
 14    /// <returns>Clipboard instance</returns>
 15    public static Clipboard Create()
 16    {
 17#if UNITY_WEBGL && !UNITY_EDITOR
 18        return new Clipboard(ClipboardWebGL.i);
 19#else
 62920        return new Clipboard(new ClipboardStandalone());
 21#endif
 22    }
 23
 24    /// <summary>
 25    /// Push a string value to the clipboard
 26    /// </summary>
 27    /// <param name="text">string to store</param>
 028    public void WriteText(string text) { handler?.RequestWriteText(text); }
 29
 30    /// <summary>
 31    /// Request the string stored at the clipboard
 32    /// </summary>
 33    /// <returns>Promise of the string value stored at clipboard</returns>
 34    [Obsolete("Firefox not supported")]
 35    public Promise<string> ReadText()
 36    {
 237        Promise<string> promise = new Promise<string>();
 238        promises.Enqueue(promise);
 239        handler?.RequestGetText();
 240        return promise;
 41    }
 42
 63043    public Clipboard(IClipboardHandler handler)
 44    {
 63045        this.handler = handler;
 63046        handler.Initialize(OnReadText);
 63047    }
 48
 49    private void OnReadText(string text, bool error)
 50    {
 451        while (promises.Count > 0)
 52        {
 253            var promise = promises.Dequeue();
 254            if (error)
 55            {
 156                promise.Reject(text);
 157            }
 58            else
 59            {
 160                promise.Resolve(text);
 61            }
 62        }
 263    }
 64
 65    public void Dispose()
 66    {
 62967    }
 68
 69    public void Initialize()
 70    {
 62971    }
 72}