<commit_before>require "spec_helper"

module GlimmerSpec
  describe "Glimmer Video" do
    include Glimmer

    before do
      @original_temp = ENV['temp']
      @target = shell {
        alpha 0 # keep invisible while running specs
      }
      @timeout = Thread.new {
        timeout_duration = 6
        sleep(timeout_duration)
        async_exec {
          @target&.dispose
          fail("Time out after #{timeout_duration} seconds!")
        }
      }
    end

    after do
      if @target && !@target.swt_widget.isDisposed
        @target.open
      end
      @timeout.kill
      ENV['temp'] = @original_temp
    end

    let(:video_file) { File.join(FIXTURES_PATH, 'videos/Pepa-creativeCommonsMp4956_512kb.mp4') }
    let(:video_url) { "http://www.youtube.com/fdajiew" }
    let(:video_url_truncated) { "www.youtube.com/fdajiew" }

    it "initializes video source by file option argument" do
      @target.content {
        @video = video(file: video_file) {
          on_completed {
            expect(@video.swt_widget.evaluate("return document.getElementById('video').src")).to eq("file://#{video_file}")
            @target.dispose
          }
        }
      }
      expect(@video.source).to eq("file://#{video_file}")
    end

    it "initializes video source by url option argument" do
      @target.content {
        @video = video(url: video_url) {
          on_completed {
            expect(@video.swt_widget.evaluate("return document.getElementById('video').src")).to eq(video_url)
            @target.dispose
          }
        }
      }
      expect(@video.source).to eq(video_url)
    end

    it 'initializes video source by uri:classloader file (JAR file path)' do
      expected_source = "file:///tmp/glimmer/lib/glimmer/ui/video/#{File.basename(video_file)}"
      @target.content {
        @video = video(file: "uri:classloader://#{video_file}") {
          on_completed {
            expect(@video.swt_widget.evaluate("return document.getElementById('video').src")).to eq(expected_source)
            expect(Dir['/tmp/glimmer/lib/glimmer/ui/video/*'].to_a.size).to be > 0
            @target.dispose
          }
        }
      }
      expect(@video.source).to eq(expected_source)
    end

    it 'initializes video source by uri:classloader file (JAR file path) with ENV["temp"] set for windows' do
      ENV['temp'] = '/tmp/tmp'
      expected_source = "file:///tmp/tmp/glimmer/lib/glimmer/ui/video/#{File.basename(video_file)}"<commit_msg>Updated a failing video spec<commit_after>require "spec_helper"

module GlimmerSpec
  describe "Glimmer Video" do
    include Glimmer

    before do
      @original_temp = ENV['temp']
      @target = shell {
        alpha 0 # keep invisible while running specs
      }
      @timeout = Thread.new {
        timeout_duration = 6
        sleep(timeout_duration)
        async_exec {
          @target&.dispose
          fail("Time out after #{timeout_duration} seconds!")
        }
      }
    end

    after do
      if @target && !@target.swt_widget.isDisposed
        @target.open
      end
      @timeout.kill
      ENV['temp'] = @original_temp
    end

    let(:video_file) { File.join(FIXTURES_PATH, 'videos/Pepa-creativeCommonsMp4956_512kb.mp4') }
    let(:video_url) { "http://www.youtube.com/fdajiew" }
    let(:video_url_truncated) { "www.youtube.com/fdajiew" }

    it "initializes video source by file option argument" do
      @target.content {
        @video = video(file: video_file) {
          on_completed {
            expect(@video.swt_widget.evaluate("return document.getElementById('video').src")).to eq("file://#{video_file}")
            @target.dispose
          }
        }
      }
      expect(@video.source).to eq("file://#{video_file}")
    end

    it "initializes video source by url option argument" do
      @target.content {
        @video = video(url: video_url) {
          on_loaded {
            expect(@video.swt_widget.evaluate("return document.getElementById('video').src")).to eq(video_url)
            @target.dispose
          }
        }
      }
      expect(@video.source).to eq(video_url)
    end

    it 'initializes video source by uri:classloader file (JAR file path)' do
      expected_source = "file:///tmp/glimmer/lib/glimmer/ui/video/#{File.basename(video_file)}"
      @target.content {
        @video = video(file: "uri:classloader://#{video_file}") {
          on_completed {
            expect(@video.swt_widget.evaluate("return document.getElementById('video').src")).to eq(expected_source)
            expect(Dir['/tmp/glimmer/lib/glimmer/ui/video/*'].to_a.size).to be > 0
            @target.dispose
          }
        }
      }
      expect(@video.source).to eq(expected_source)
    end

    it 'initializes video source by uri:classloader file (JAR file path) with ENV["temp"] set for windows' do
      ENV['temp'] = '/tmp/tmp'
      expected_source = "file:///tmp/tmp/glimmer/lib/glimmer/ui/video/#{File.basename(video_file)}"
{'fraction_non_alphanumeric': 0.1296818364881192, 'fraction_numerical': 0.004430124848973017, 'mean_word_length': 2.4043865661411927, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '4325611', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1544, 'n_words': 291}