## Copyright (c) 2022, NVIDIA CORPORATION.  All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto.  Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
import os
import tempfile
import omni.kit.app
import omni.usd
from omni.kit.test.async_unittest import AsyncTestCase
from omni.kit import ui_test
from omni.kit.test_suite.helpers import open_stage, get_test_data_path, get_prims, wait_stage_loading, arrange_windows
from omni.kit.window.content_browser import get_content_window


class TestExternalDragDrop(AsyncTestCase):
    # Before running each test
    async def setUp(self):
        await arrange_windows("Stage", 512)

    # After running each test
    async def tearDown(self):
        await wait_stage_loading()

    async def test_external_drag_drop(self):
        # position mouse
        await ui_test.find("Content").click()
        await ui_test.human_delay()

        with tempfile.TemporaryDirectory() as tmpdir:
            test_file = f"{tmpdir}/bound_shapes.usda"

            # browse to tempdir
            content_browser = get_content_window()
            content_browser.navigate_to(str(tmpdir))
            await ui_test.human_delay(50)

            # if target file exists remove
            if os.path.exists(test_file):
                os.remove(test_file)

            # simulate drag/drop 
            item_path = get_test_data_path(__name__, "bound_shapes.usda")
            omni.appwindow.get_default_app_window().get_window_drop_event_stream().push(0, 0, {'paths': [item_path]})
            await ui_test.human_delay(50)

            # verify exists
            self.assertTrue(os.path.exists(test_file))
