<commit_before>// Copyright (c) Microsoft Open Technologies, Inc.  All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
/// <reference path="ms-appx://$(TargetFramework)/js/base.js" />
/// <reference path="ms-appx://$(TargetFramework)/js/en-us/base.strings.js" />
/// <reference path="ms-appx://$(TargetFramework)/js/ui.js" />
/// <reference path="ms-appx://$(TargetFramework)/js/en-us/ui.strings.js" />
/// <reference path="ms-appx://$(TargetFramework)/css/ui-dark.css" />
/// <reference path="../TestLib/ListView/Helpers.js" />
/// <reference path="../TestLib/util.js" />
/// <reference path="../TestLib/ItemsManager/TestDataSource.js" />
/// <deploy src="../TestData/" />

var WinJSTests = WinJSTests || {};

WinJSTests.ListViewDragDropTest = function () {
    "use strict";
    var Key = WinJS.Utilities.Key;
    var ITEMS_COUNT = 10;
    var ddEventsList = ["itemdragstart",
                    "itemdragenter",
                    "itemdragend",
                    "itemdragbetween",
                    "itemdragleave",
                    "itemdragchanged",
                    "itemdragdrop"];

    this.setUp = function (complete) {
        LiveUnit.LoggingCore.logComment("In setup");
        var newNode = document.createElement("div");
        newNode.id = "DragDropTest";
        newNode.style.width = "200px";
        newNode.style.height = "300px";
        document.body.appendChild(newNode);
        appendCSSFileToHead("$(TESTDATA)/ListView.css").then(complete);
    };

    this.tearDown = function () {
        LiveUnit.LoggingCore.logComment("In tearDown");

        var element = document.getElementById("DragDropTest");
        if (element) {
            WinJS.Utilities.disposeSubTree(element);
            document.body.removeChild(element);
        }
        removeCSSFileFromHead("$(TESTDATA)/ListView.css");
    }

    function getRawData(count) {
        var rawData = [];
        for (var i = 0; i < (count ? count : ITEMS_COUNT) ; i++) {
            rawData.push({ itemInfo: "Tile" + i });
        }
        return rawData;
    }

    function getDataSource(count) {
        var rawData = getRawData(count);
        return new WinJS.Binding.List(rawData).dataSource;
    }

    function getAdjustedKeys(rtl) {
        return {
            left: rtl ? WinJS.Utilities.Key.rightArrow : WinJS.Utilities.Key.leftArrow,
            up: WinJS.Utilities.Key.upArrow,
            right: rtl ? WinJS.Utilities.Key.leftArrow : WinJS.Utilities.Key.rightArrow,
            down: WinJS.Utilities.Key.downArrow
        };
    }
    function basicRenderer(itemPromise) {
        var element = document.createElement("div");
        element.style.width = "50px";
        element.style.height = "50px";
        return {
            element: element,
            renderComplete: itemPromise.then(function (item) {
                element.textContent = item.data.itemInfo;
                if (item.data.markUndraggable) {
                    element.className += " win-nondraggable";
                }
            })
        };
    }

    function generateEventInElement(listView, name, element, rtl, offset) {
        var elementRect = element.getBoundingClientRect();
        if (!offset) {
            offset = {
                x: element.offsetWidth / 2,
                y: element.offsetHeight / 2,
            };
        }
        var fakeEventObject = {
            clientX: elementRect[rtl ? "right" : "left"] + (rtl ? -offset.x : offset.x),
            clientY: elementRect.top + offset.y,
            preventDefault: function () { },
            dataTransfer: { setData: function () { }},
            target: element
        };

        listView._currentMode()[name](fakeEventObject);
    }

    function generateKeyEventInListView(listView, keyPressed, ctrlDown, altDown, shiftDown) {
        var fakeEventObject = {
            ctrlKey: !!ctrlDown,
            altKey: !!altDown,
            shiftKey: !!shiftDown,
            keyCode: keyPressed,
            preventDefault: function () { },
            stopPropagation: function () { },
            target: listView.element
        };

        listView._currentMode()["onKeyDown"](fakeEventObject);
    }

    function changeListViewFocus(listView, focusedIndex) {
        listView._selection._setFocused({ type: "item", index: focusedIndex }, false);
    }


    // Creates a VDS out of the provided array (data) or
    // creates a new data array of specified size
    function createDragDropVDSDataSource(size, data, isSynchronous) {
        // Populate a data array
        if (!data) {
            data = getRawData(size);
        }
        // isSynchronous defaults to true
        if (isSynchronous === undefined) {
            isSynchronous = true;
        }

        // Create the datasource
        var controller = {
            directivesForMethod: function (method) {
                return {
                    callMethodSynchronously: isSynchronous,
                    delay: isSynchronous ? undefined : 0,
                    sendChangeNotifications: true,
                    countBeforeDelta: 0,
                    countAfterDelta: 0,
                    countBeforeOverride: -1,
                    countAfterOverride: -1
                };
            }
        };

        // Data adapter abilities - requirements for ListView Reordering.  
        var abilities = {
            itemsFromIndex: true, // If these change, update the public docs!!
            itemsFromKey: true,
            remove: true,
            getCount: true,
            setNotificationHandler: true,
            moveBefore: true,
            moveAfter: true,
            moveToStart: true,
        };

        return TestComponents.createTestDataSource(data, controller, abilities);
    };

    function nabItem(listView, index) {
        if (listView.itemDataSource._list) {
            return listView.itemDataSource._list.getItem(index);
        } else {
            return listView.itemDataSource.testDataAdapter.getItems()[index];
        }
    }

    this.generate = function (name, testFunction, itemsCount) {
        function generateTest(that, layout, dataSource, rtl) {
            var fullName = name + layout + dataSource + (rtl ? "_rtl" : "_ltr");

            // Issue #135
            if (fullName === "DisabledDragBetweenListLayoutBindingList_ltr" || 
                fullName === "DisabledDragBetweenGridLayoutVDS_ltr") {
                return;
            }

            that[fullName] = function (complete) {
                LiveUnit.LoggingCore.logComment("in " + fullName);<commit_msg>disabled DraggableAttributeGridLayoutVDS_rtl test<commit_after>// Copyright (c) Microsoft Open Technologies, Inc.  All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
/// <reference path="ms-appx://$(TargetFramework)/js/base.js" />
/// <reference path="ms-appx://$(TargetFramework)/js/en-us/base.strings.js" />
/// <reference path="ms-appx://$(TargetFramework)/js/ui.js" />
/// <reference path="ms-appx://$(TargetFramework)/js/en-us/ui.strings.js" />
/// <reference path="ms-appx://$(TargetFramework)/css/ui-dark.css" />
/// <reference path="../TestLib/ListView/Helpers.js" />
/// <reference path="../TestLib/util.js" />
/// <reference path="../TestLib/ItemsManager/TestDataSource.js" />
/// <deploy src="../TestData/" />

var WinJSTests = WinJSTests || {};

WinJSTests.ListViewDragDropTest = function () {
    "use strict";
    var Key = WinJS.Utilities.Key;
    var ITEMS_COUNT = 10;
    var ddEventsList = ["itemdragstart",
                    "itemdragenter",
                    "itemdragend",
                    "itemdragbetween",
                    "itemdragleave",
                    "itemdragchanged",
                    "itemdragdrop"];

    this.setUp = function (complete) {
        LiveUnit.LoggingCore.logComment("In setup");
        var newNode = document.createElement("div");
        newNode.id = "DragDropTest";
        newNode.style.width = "200px";
        newNode.style.height = "300px";
        document.body.appendChild(newNode);
        appendCSSFileToHead("$(TESTDATA)/ListView.css").then(complete);
    };

    this.tearDown = function () {
        LiveUnit.LoggingCore.logComment("In tearDown");

        var element = document.getElementById("DragDropTest");
        if (element) {
            WinJS.Utilities.disposeSubTree(element);
            document.body.removeChild(element);
        }
        removeCSSFileFromHead("$(TESTDATA)/ListView.css");
    }

    function getRawData(count) {
        var rawData = [];
        for (var i = 0; i < (count ? count : ITEMS_COUNT) ; i++) {
            rawData.push({ itemInfo: "Tile" + i });
        }
        return rawData;
    }

    function getDataSource(count) {
        var rawData = getRawData(count);
        return new WinJS.Binding.List(rawData).dataSource;
    }

    function getAdjustedKeys(rtl) {
        return {
            left: rtl ? WinJS.Utilities.Key.rightArrow : WinJS.Utilities.Key.leftArrow,
            up: WinJS.Utilities.Key.upArrow,
            right: rtl ? WinJS.Utilities.Key.leftArrow : WinJS.Utilities.Key.rightArrow,
            down: WinJS.Utilities.Key.downArrow
        };
    }
    function basicRenderer(itemPromise) {
        var element = document.createElement("div");
        element.style.width = "50px";
        element.style.height = "50px";
        return {
            element: element,
            renderComplete: itemPromise.then(function (item) {
                element.textContent = item.data.itemInfo;
                if (item.data.markUndraggable) {
                    element.className += " win-nondraggable";
                }
            })
        };
    }

    function generateEventInElement(listView, name, element, rtl, offset) {
        var elementRect = element.getBoundingClientRect();
        if (!offset) {
            offset = {
                x: element.offsetWidth / 2,
                y: element.offsetHeight / 2,
            };
        }
        var fakeEventObject = {
            clientX: elementRect[rtl ? "right" : "left"] + (rtl ? -offset.x : offset.x),
            clientY: elementRect.top + offset.y,
            preventDefault: function () { },
            dataTransfer: { setData: function () { }},
            target: element
        };

        listView._currentMode()[name](fakeEventObject);
    }

    function generateKeyEventInListView(listView, keyPressed, ctrlDown, altDown, shiftDown) {
        var fakeEventObject = {
            ctrlKey: !!ctrlDown,
            altKey: !!altDown,
            shiftKey: !!shiftDown,
            keyCode: keyPressed,
            preventDefault: function () { },
            stopPropagation: function () { },
            target: listView.element
        };

        listView._currentMode()["onKeyDown"](fakeEventObject);
    }

    function changeListViewFocus(listView, focusedIndex) {
        listView._selection._setFocused({ type: "item", index: focusedIndex }, false);
    }


    // Creates a VDS out of the provided array (data) or
    // creates a new data array of specified size
    function createDragDropVDSDataSource(size, data, isSynchronous) {
        // Populate a data array
        if (!data) {
            data = getRawData(size);
        }
        // isSynchronous defaults to true
        if (isSynchronous === undefined) {
            isSynchronous = true;
        }

        // Create the datasource
        var controller = {
            directivesForMethod: function (method) {
                return {
                    callMethodSynchronously: isSynchronous,
                    delay: isSynchronous ? undefined : 0,
                    sendChangeNotifications: true,
                    countBeforeDelta: 0,
                    countAfterDelta: 0,
                    countBeforeOverride: -1,
                    countAfterOverride: -1
                };
            }
        };

        // Data adapter abilities - requirements for ListView Reordering.  
        var abilities = {
            itemsFromIndex: true, // If these change, update the public docs!!
            itemsFromKey: true,
            remove: true,
            getCount: true,
            setNotificationHandler: true,
            moveBefore: true,
            moveAfter: true,
            moveToStart: true,
        };

        return TestComponents.createTestDataSource(data, controller, abilities);
    };

    function nabItem(listView, index) {
        if (listView.itemDataSource._list) {
            return listView.itemDataSource._list.getItem(index);
        } else {
            return listView.itemDataSource.testDataAdapter.getItems()[index];
        }
    }

    this.generate = function (name, testFunction, itemsCount) {
        function generateTest(that, layout, dataSource, rtl) {
            var fullName = name + layout + dataSource + (rtl ? "_rtl" : "_ltr");

            // Issue #135
            if (fullName === "DisabledDragBetweenListLayoutBindingList_ltr" || 
                fullName === "DisabledDragBetweenGridLayoutVDS_ltr" ||
                fullName === "DraggableAttributeGridLayoutVDS_rtl" ) {
                return;
            }

            that[fullName] = function (complete) {
                LiveUnit.LoggingCore.logComment("in " + fullName);
{'fraction_non_alphanumeric': 0.11849258955835257, 'fraction_numerical': 0.003723840023832576, 'mean_word_length': 1.948616600790514, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 21, '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': '3094390', 'n_tokens_mistral': 3716, 'n_tokens_neox': 3584, 'n_words': 739}