<commit_before>﻿// Copyright (c) 2007-2017 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE

using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.Testing;
using OpenTK;
using OpenTK.Graphics;

namespace osu.Framework.VisualTests.Tests
{
    internal class TestCaseOnlineTextures : TestCase
    {
        private FillFlowContainerNoInput flow;
        private ScrollContainer scroll;

        private const int panel_count = 2048;

        public override void Reset()
        {
            base.Reset();

            Children = new Drawable[]
            {
                scroll = new ScrollContainer
                {
                    RelativeSizeAxes = Axes.Both,
                    Children = new Drawable[]
                    {
                        flow = new FillFlowContainerNoInput
                        {
                            RelativeSizeAxes = Axes.X,
                            AutoSizeAxes = Axes.Y,
                        }
                    }
                }
            };

            for (int i = 1; i < panel_count; i++)
                flow.Add(new Container
                {
                    Size = new Vector2(128),
                    Children = new Drawable[]
                    {
                        new DelayedLoadContainer
                        {
                            RelativeSizeAxes = Axes.Both,
                            FinishedLoading = d => {
                                if ((d.Children.FirstOrDefault() as Sprite)?.Texture == null)
                                {
                                    d.Add(new SpriteText {
                                        Colour = Color4.Gray,
                                        Text = @"nope",
                                        Anchor = Anchor.Centre,
                                        Origin = Anchor.Centre,
                                    });
                                }
                            },
                            Children = new Drawable[]
                            {
                                new Avatar(i) { RelativeSizeAxes = Axes.Both }
                            }
                        },
                        new SpriteText { Text = i.ToString() },
                    }
                });

            var childrenWithAvatarsLoaded = flow.Children.Where(c => c.Children.OfType<DelayedLoadContainer>().First().Children.FirstOrDefault()?.IsLoaded ?? false);

            AddWaitStep(10);
            AddStep("scroll down", () => scroll.ScrollToEnd());
            AddWaitStep(10);
            AddAssert("any panels loaded", () => childrenWithAvatarsLoaded.Count() > 5);
            AddAssert("too many panels loaded", () => childrenWithAvatarsLoaded.Count() < panel_count / 4);
            AddAssert("any panels loaded", () => childrenWithAvatarsLoaded.Count() > 5);
        }

        private class FillFlowContainerNoInput : FillFlowContainer<Container>
        {
            public override bool HandleInput => false;
        }
    }

    public class Avatar : Sprite
    {
        private readonly int userId;

        public Avatar(int userId)
        {
            this.userId = userId;
        }

        [BackgroundDependencyLoader]
        private void load(TextureStore textures)
        {
            Texture = textures.Get($@"https://a.ppy.sh/{userId}");
        }
    }
}
<commit_msg>TestCaseOnlineTextures fixes.<commit_after>﻿// Copyright (c) 2007-2017 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE

using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.Testing;
using OpenTK;
using OpenTK.Graphics;

namespace osu.Framework.VisualTests.Tests
{
    internal class TestCaseOnlineTextures : TestCase
    {
        private FillFlowContainerNoInput flow;
        private ScrollContainer scroll;

        private const int panel_count = 512;

        public override void Reset()
        {
            base.Reset();

            Children = new Drawable[]
            {
                scroll = new ScrollContainer
                {
                    RelativeSizeAxes = Axes.Both,
                    Children = new Drawable[]
                    {
                        flow = new FillFlowContainerNoInput
                        {
                            RelativeSizeAxes = Axes.X,
                            AutoSizeAxes = Axes.Y,
                        }
                    }
                }
            };

            for (int i = 1; i < panel_count; i++)
                flow.Add(new Container
                {
                    Size = new Vector2(128),
                    Children = new Drawable[]
                    {
                        new DelayedLoadContainer
                        {
                            RelativeSizeAxes = Axes.Both,
                            FinishedLoading = d => {
                                if ((d.Children.FirstOrDefault() as Sprite)?.Texture == null)
                                {
                                    d.Add(new SpriteText {
                                        Colour = Color4.Gray,
                                        Text = @"nope",
                                        Anchor = Anchor.Centre,
                                        Origin = Anchor.Centre,
                                    });
                                }
                            },
                            Children = new Drawable[]
                            {
                                new Avatar(i) { RelativeSizeAxes = Axes.Both }
                            }
                        },
                        new SpriteText { Text = i.ToString() },
                    }
                });

            var childrenWithAvatarsLoaded = flow.Children.Where(c => c.Children.OfType<DelayedLoadContainer>().First().Children.FirstOrDefault()?.IsLoaded ?? false);

            AddWaitStep(10);
            AddStep("scroll down", () => scroll.ScrollToEnd());
            AddWaitStep(10);
            AddAssert("some loaded", () => childrenWithAvatarsLoaded.Count() > 5);
            AddAssert("not too many loaded", () => childrenWithAvatarsLoaded.Count() < panel_count / 4);
        }

        private class FillFlowContainerNoInput : FillFlowContainer<Container>
        {
            public override bool HandleInput => false;
        }
    }

    public class Avatar : Sprite
    {
        private readonly int userId;

        public Avatar(int userId)
        {
            this.userId = userId;
        }

        [BackgroundDependencyLoader]
        private void load(TextureStore textures)
        {
            Texture = textures.Get($@"https://a.ppy.sh/{userId}");
        }
    }
}

{'fraction_non_alphanumeric': 0.08355904658721561, 'fraction_numerical': 0.0065005417118093175, 'mean_word_length': 1.0686274509803921, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 27, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5524251', 'n_tokens_mistral': 1827, 'n_tokens_neox': 1648, 'n_words': 345}