<commit_before>/*
 * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jitsi.meet.test;

import org.openqa.selenium.*;
import org.openqa.selenium.chrome.*;

/**
 * The static fixture which holds the drivers to access the conference
 * participant pages.
 *
 * @author <NAME>
 */
public class ConferenceFixture
{
    public static final String JITSI_MEET_URL_PROP = "jitsi-meet.instance.url";

    public static String currentRoomName;

    /**
     * The focus in the tests.
     */
    private static WebDriver focus;

    /**
     * The second participant.
     */
    private static WebDriver secondParticipant;

    /**
     * Returns the currently allocated focus.
     * @return the currently allocated focus.
     */
    public static WebDriver getFocus()
    {
        return focus;
    }

    /**
     * Returns the currently allocated second participant.
     * @return the currently allocated second participant.
     */
    public static WebDriver getSecondParticipant()
    {
        if(secondParticipant == null)
        {
            // this will only happen if some test that quits the
            // second participant fails, and couldn't open it
            startParticipant();
        }

        return secondParticipant;
    }

    /**
     * Starts the focus, the first participant that generates the random
     * room name.
     */
    public static void startFocus()
    {
        focus = startChromeInstance();

        currentRoomName = "torture"
            + String.valueOf((int)(Math.random()*1000000));

        openRoom(focus);
    }

    /**
     * Opens the room for the given participant.
     * @param participant to open the current test room.
     */
    public static void openRoom(WebDriver participant)
    {
        participant.get(System.getProperty(JITSI_MEET_URL_PROP) + "/"
            + currentRoomName);

        // disables animations
        ((JavascriptExecutor) participant)
            .executeScript("try { jQuery.fx.off = true; } catch(e) {}");
    }

    /**
     * Starts chrome instance using some default settings.
     * @return the webdriver instance.
     */
    private static WebDriver startChromeInstance()
    {
        ChromeOptions ops = new ChromeOptions();
        ops.addArguments("use-fake-ui-for-media-stream");
        ops.addArguments("use-fake-device-for-media-stream");
        ops.addArguments("vmodule=\"*media/*=3,*turn*=3\"");
        return new ChromeDriver(ops);
    }

    /**
     * Start another participant reusing the already generated room name.
     */
    public static void startParticipant()
    {
        secondParticipant = startChromeInstance();

        openRoom(secondParticipant);
    }

    /**
     * Checks whether participant has joined the room
     * @param participant where we check
     * @param timeout the time to wait for the event.
     */
    public static void checkParticipantToJoinRoom(
        WebDriver participant, long timeout)
    {
        TestUtils.waitsForBoolean(
            participant,
            "return connection.emuc.joined;",
            timeout);
    }

    /**
     * Waits the focus to get event for iceConnectionState that changes
     * to connected.
     */
    public static void waitsFocusToJoinConference()
    {
        TestUtils.waitsForBoolean(
            focus,
            "return focus !== null"
            ,10);
        TestUtils.waitsForBoolean(
            focus,<commit_msg>Changes the titles of the browsers after page is loaded.<commit_after>/*
 * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jitsi.meet.test;

import org.openqa.selenium.*;
import org.openqa.selenium.chrome.*;

/**
 * The static fixture which holds the drivers to access the conference
 * participant pages.
 *
 * @author <NAME>
 */
public class ConferenceFixture
{
    public static final String JITSI_MEET_URL_PROP = "jitsi-meet.instance.url";

    public static String currentRoomName;

    /**
     * The focus in the tests.
     */
    private static WebDriver focus;

    /**
     * The second participant.
     */
    private static WebDriver secondParticipant;

    /**
     * Returns the currently allocated focus.
     * @return the currently allocated focus.
     */
    public static WebDriver getFocus()
    {
        return focus;
    }

    /**
     * Returns the currently allocated second participant.
     * @return the currently allocated second participant.
     */
    public static WebDriver getSecondParticipant()
    {
        if(secondParticipant == null)
        {
            // this will only happen if some test that quits the
            // second participant fails, and couldn't open it
            startParticipant();
        }

        return secondParticipant;
    }

    /**
     * Starts the focus, the first participant that generates the random
     * room name.
     */
    public static void startFocus()
    {
        focus = startChromeInstance();

        currentRoomName = "torture"
            + String.valueOf((int)(Math.random()*1000000));

        openRoom(focus);

        ((JavascriptExecutor) focus)
            .executeScript("document.title='Focus'");
    }

    /**
     * Opens the room for the given participant.
     * @param participant to open the current test room.
     */
    public static void openRoom(WebDriver participant)
    {
        participant.get(System.getProperty(JITSI_MEET_URL_PROP) + "/"
            + currentRoomName);

        // disables animations
        ((JavascriptExecutor) participant)
            .executeScript("try { jQuery.fx.off = true; } catch(e) {}");
    }

    /**
     * Starts chrome instance using some default settings.
     * @return the webdriver instance.
     */
    private static WebDriver startChromeInstance()
    {
        ChromeOptions ops = new ChromeOptions();
        ops.addArguments("use-fake-ui-for-media-stream");
        ops.addArguments("use-fake-device-for-media-stream");
        ops.addArguments("vmodule=\"*media/*=3,*turn*=3\"");
        return new ChromeDriver(ops);
    }

    /**
     * Start another participant reusing the already generated room name.
     */
    public static void startParticipant()
    {
        secondParticipant = startChromeInstance();

        openRoom(secondParticipant);

        ((JavascriptExecutor) secondParticipant)
            .executeScript("document.title='SecondParticipant'");
    }

    /**
     * Checks whether participant has joined the room
     * @param participant where we check
     * @param timeout the time to wait for the event.
     */
    public static void checkParticipantToJoinRoom(
        WebDriver participant, long timeout)
    {
        TestUtils.waitsForBoolean(
            participant,
            "return connection.emuc.joined;",
            timeout);
    }

    /**
     * Waits the focus to get event for iceConnectionState that changes
     * to connected.
     */
    public static void waitsFocusToJoinConference()
    {
        TestUtils.waitsForBoolean(
            focus,
            "return focus !== null"
            ,10);
        TestUtils.waitsForBoolean(
            focus,
{'fraction_non_alphanumeric': 0.09419002050580998, 'fraction_numerical': 0.0030075187969924814, 'mean_word_length': 2.2386011509517485, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3009700', 'n_tokens_mistral': 1985, 'n_tokens_neox': 1901, 'n_words': 564}