<commit_before>var sinon = require("sinon");
var should = require("should");
var assert = require("assert");
var helpers = require("./helpers");

describe("Mock API SDK Tests", function() {
    var client = helpers.setupClient();

    describe("#Serialization", function() {
        var scenarios = [
            {
                "name": "Serialization - Attachment",
                "method": client.sheets.addAttachment,
                "shouldError": false,
                "options": {
                    "sheetId": 1,
                    "body": {
                        "name": "Search Engine",
                        "description": "A popular search engine",
                        "attachmentType": "LINK",
                        "url": "http://www.google.com"
                    }
                }
            },
            {
                "name": "Serialization - Home",
                "method": client.home.listContents,
                "shouldError": false,
                "options": {}
            },
            {
                "name": "Serialization - Groups",
                "method": client.groups.createGroup,
                "shouldError": false,
                "options": {
                    "body": {
                        "name": "mock api test group",
                        "description": "it's a group",
                        "members": [
                            {
                                "email": "john.doe@smartsheet.com"
                            },
                            {
                                "email": "jane.doe@smartsheet.com"
                            }
                        ]
                    }
                }
            },
            {
                "name": "Serialization - Discussion",
                "method": client.sheets.createRowDiscussion,
                "shouldError": false,
                "options": {
                    "sheetId": 1,
                    "rowId": 2,
                    "body": {
                        "comment": {
                            "text": "This is a comment!"
                        }
                    }
                }
            },
            {
                "name": "Serialization - Contact",
                "method": client.contacts.getContact,
                "shouldError": false,
                "options": {
                    "id": "ABC"
                }
            },
            {
                "name": "Serialization - Folder",
                "method": client.home.createFolder,
                "shouldError": false,
                "options": {
                    "body": {
                        "name": "folder"
                    }
                }
            },
            // {
            //     "name": "Serialization - Column",
            //     "method": client.sheets.addColumn,
            //     "shouldError": false,
            //     "options": {
            //         "sheetId": 1,
            //         "body": {
            //             "title": "A Brave New Column",
            //             "type": "PICKLIST",
            //             "options": [
            //                 "option1",
            //                 "option2",
            //                 "option3"
            //             ],
            //             "index": 2,
            //             "validation": false,
            //             "width": 42,
            //             "locked": false
            //         }
            //     }
            // },
            {
                "name": "Serialization - UserProfile",
                "method": client.users.getCurrentUser,
                "shouldError": false,
                "options": {}
            },
            {
                "name": "Serialization - Workspace",
                "method": client.workspaces.createWorkspace,
                "shouldError": false,
                "options": {
                    "body": {
                        "name": "A Whole New Workspace"
                    }
                }
            },
            {
                "name": "Serialization - User",
                "method": client.users.addUser,
                "shouldError": false,
                "options": {
                    "body": {
                        "email": "john.doe@smartsheet.com",
                        "admin": false,
                        "licensedSheetCreator": true,
                        "firstName": "John",
                        "lastName": "Doe",
                        "groupAdmin": false,
                        "resourceViewer": true
                    }
                }
            },
            {
                "name": "Serialization - Sheet",
                "method": client.sheets.createSheet,
                "shouldError": false,
                "options": {
                    "body": {
                        "name": "The First Sheet",
                        "columns": [
                            {
                                "title": "The First Column",
                                "primary": true,
                                "type": "TEXT_NUMBER"
                            },
                            {
                                "title": "The Second Column",
                                "primary": false,
                                "type": "TEXT_NUMBER",
                                "systemColumnType": "AUTO_NUMBER",
                                "autoNumberFormat": {
                                    "prefix": "{YYYY}-{MM}-{DD}-",
                                    "suffix": "-SUFFIX",
                                    "fill": "000000"
                                }
                            }
                        ]
                    }
                }
            },
            {
                "name": "Serialization - AlternateEmail",
                "method": client.users.addAlternateEmail,
                "shouldError": false,
                "options": {
                    "userId": 1,
                    "body": [
                        {
                            "email": "not.not.john.doe@smartsheet.com"
                        }
                    ]
                }
            },
            // {
            //     "name": "Serialization - Predecessor",
            //     "method": client.sheets.addRows,
            //     "shouldError": false,
            //     "options": {
            //         "sheetId": 1,
            //         "body": {
            //             "cells": [
            //                 {
            //                     "columnId": 2,
            //                     "objectValue": {
            //                         "objectType": "PREDECESSOR_LIST",
            //                         "predecessors": [
            //                             {
            //                                 "rowId": 3,
            //                                 "type": "FS",
            //                                 "lag": {
            //                                     "objectType": "DURATION",
            //                                     "negative": false,
            //                                     "elapsed": false,
            //                                     "weeks": 1.5,
            //                                     "days": 2.5,
            //                                     "hours": 3.5,
            //                                     "minutes": 4.5,
            //                                     "seconds": 5.5,
            //                                     "milliseconds": 6
            //                                 }
            //                             }
            //                         ]
            //                     }
            //                 }
            //             ]
            //         },
            //         "queryParameters": {
            //             "include": "objectValue"
            //         }
            //     }
            // },
            {
                "name": "Serialization - IndexResult",
                "method": client.users.listAllUsers,
                "shouldError": false,
                "options": {}
            },
            {
                "name": "Serialization - Image",
                "method": client.sheets.getRow,
                "shouldError": false,
                "options": {
                    "sheetId": 1,
                    "rowId": 2
                }
            },
            {
                "name": "Serialization - Image Urls",
                "method": client.images.listImageUrls,
                "shouldError": false,
                "options": {
                    "body": [
                        {
                            "imageId": "abc",
                            "height": 100,
                            "width": 200
                        }
                    ]
                }
            },
            {
                "name": "Serialization - BulkFailure",
                "method": client.sheets.addRows,
                "shouldError": false,
                "options": {
                    "sheetId": 1,
                    "body": [
                        {
                            "toBottom": true,
                            "cells": [
                                {
                                    "columnId": 2,
                                    "value": "Some Value"
                                }
                            ]
                        },
                        {
                            "toBottom": true,
                            "cells": [
                                {
                                    "columnId": 3,
                                    "value": "Some Value"
                                }
                            ]
                        }
                    ],
                    "queryParameters": {
                        "allowPartialSuccess": "true"
                    }
                }
            },
            // {
            //     "name": "Serialization - Rows",
            //     "method": client.sheets.addRows,
            //     "shouldError": false,
            //     "options": {
            //         "sheetId": 1,
            //         "body": {
            //             "expanded": true,
            //             "format": ",,,,,,,,4,,,,,,,",
            //             "cells": [
            //                 {
            //                     "columnId": 2,
            //                     "value": "url link",
            //                     "strict": false,
            //                     "hyperlink": {
            //                         "url": "https://google.com"
            //                     }
            //                 },
            //                 {
            //                     "columnId": 3,
            //                     "value": "sheet id link",
            //                     "strict": false,
            //                     "hyperlink": {
            //                         "sheetId": 4
            //                     }
            //                 },
            //                 {
            //                     "columnId": 5,
            //                     "value": "report id link",
            //                     "strict": false,
            //                     "hyperlink": {
            //                         "reportId": 6
            //                     }
            //                 }
            //             ],
            //             "locked": false
            //         }
            //     }
            // },
            // {
            //     "name": "Serialization - Cell Link",
            //     "method": client.sheets.updateRow,
            //     "shouldError": false,
            //     "options": {
            //         "sheetId": 1,
            //         "body": {
            //             "id": 2,
            //             "cells": [
            //                 {
            //                     "columnId": 3,
            //                     "value": null,
            //                     "linkInFromCell": {
            //                         "sheetId": 4,
            //                         "rowId": 5,
            //                         "columnId": 6
            //                     }
            //                 }
            //             ]
            //         }
            //     }
            // },
            // {
            //     "name": "Serialization - Favorite",
            //     "method": client.favorites.addSheetToFavorites,
            //     "shouldError": false,
            //     "options": {
            //         "objectId": 1
            //     }
            // },
            {
                "name": "Serialization - Report",
                "method": client.reports.getReport,
                "shouldError": false,
                "options": {
                    "id": 1
                }
            },
            // {
            //     "name": "Serialization - Share",
            //     "method": client.sheets.share,
            //     "shouldError": false,
            //     "options": {
            //         "sheetId": 1,
            //         "body": {
            //             "email": "john.doe@smartsheet.com",
            //             "accessLevel": "VIEWER",
            //             "subject": "Check out this sheet",
            //             "message": "Let me know what you think. Thanks!",
            //             "ccMe": true
            //         },
            //         "queryParameters": {
            //             "sendEmail": "true"
            //         }
            //     }
            // },
            {
                "name": "Serialization - Send via Email",
                "method": client.sheets.sendSheetViaEmail,
                "shouldError": false,
                "options": {
                    "sheetId": 1,
                    "body": {
                        "sendTo": [
                            {
                                "email": "john.doe@smartsheet.com"
                            },
                            {
                                "groupId": 2
                            }
                        ],
                        "subject": "Some subject",
                        "message": "Some message",
                        "ccMe": true,
                        "format": "PDF",
                        "formatDetails": {
                            "paperSize": "LETTER"
                        }
                    }
                }
            },
            {
                "name": "Serialization - Row Email",
                "method": client.sheets.sendRows,
                "shouldError": false,
                "options": {
                    "sheetId": 1,
                    "body": {
                        "sendTo": [
                            {
                                "groupId": 2
                            }
                        ],
                        "subject": "Some subject",
                        "message": "Some message",
                        "columnIds": [
                            3
                        ],
                        "includeAttachments": false,
                        "includeDiscussions": true,
                        "layout": "VERTICAL",
                        "rowIds": [
                            4
                        ]
                    }
                }
            },
            {
                "name": "Serialization - Template",
                "method": client.templates.listPublicTemplates,
                "shouldError": false,
                "options": {}
            },
            {
                "name": "Serialization - Update Request",
                "method": client.sheets.createUpdateRequest,
                "shouldError": false,
                "options": {
                    "sheetId": 1,
                    "body": {
                        "sendTo": [
                            {
                                "email": "john.doe@smartsheet.com"
                            }
                        ],
                        "rowIds": [
                            2
                        ],
                        "columnIds": [
                            3
                        ],
                        "includeAttachments": true,
                        "includeDiscussions": false,
                        "subject": "Some subject",
                        "message": "Some message",
                        "ccMe": true,
                        "schedule": {
                            "type": "MONTHLY",
                            "startAt": "2018-03-01T19:00:00Z",
                            "endAt": "2018-06-01T00:00:00Z",
                            "dayOrdinal": "FIRST",
                            "dayDescriptors": [
                                "FRIDAY"
                            ],
                            "repeatEvery": 1
                        }
                    }
                }
            },
            {
                "name": "Serialization - Sent Update Requests",
                "method": client.sheets.getSentUpdateRequest,
                "shouldError": false,
                "options": {
                    "sheetId": 1,
                    "sentUpdateRequestId": 2
                }
            },
            {
                "name": "Serialization - Sheet Settings",
                "method": client.sheets.updateSheet,
                "shouldError": false,
                "options": {
                    "id": 1,
                    "body": {
                        "userSettings": {
                            "criticalPathEnabled": true,
                            "displaySummaryTasks": true
                        },
                        "projectSettings": {
                            "workingDays": [
                                "MONDAY",
                                "TUESDAY"
                            ],
                            "nonWorkingDays": [
                                "2018-04-04",
                                "2018-05-05",
                                "2018-06-06"
                            ],
                            "lengthOfDay": 23.5
                        }
                    }
                }
            },
            // {
            //     "name": "Serialization - Container Destination",
            //     "method": client.folders.copyFolder,
            //     "shouldError": false,
            //     "options": {
            //         "folderId": 1,
            //         "body": {
            //             "destinationType": "home",
            //             "destinationId": null,
            //             "newName": "Copy of Some Folder"
            //         }
            //     }
            // },
            {
                "name": "Serialization - Cross Sheet Reference",
                "method": client.sheets.createCrossSheetReference,
                "shouldError": false,
                "options": {
                    "sheetId": 1,
                    "body": {
                        "name": "Some Cross Sheet Reference",
                        "sourceSheetId": 2,
                        "startRowId": 3,
                        "endRowId": 4,
                        "startColumnId": 5,
                        "endColumnId": 6
                    }
                }
            }
        ];

        helpers.defineMockApiTests(scenarios);
    });
});
<commit_msg>Uncomment skipped tests to make merge conflicts easier<commit_after>var sinon = require("sinon");
var should = require("should");
var assert = require("assert");
var helpers = require("./helpers");

describe("Mock API SDK Tests", function() {
    var client = helpers.setupClient();

    describe("#Serialization", function() {
        var scenarios = [
            {
                "name": "Serialization - Attachment",
                "method": client.sheets.addAttachment,
                "shouldError": false,
                "options": {
                    "sheetId": 1,
                    "body": {
                        "name": "Search Engine",
                        "description": "A popular search engine",
                        "attachmentType": "LINK",
                        "url": "http://www.google.com"
                    }
                }
            },
            {
                "name": "Serialization - Home",
                "method": client.home.listContents,
                "shouldError": false,
                "options": {}
            },
            {
                "name": "Serialization - Groups",
                "method": client.groups.createGroup,
                "shouldError": false,
                "options": {
                    "body": {
                        "name": "mock api test group",
                        "description": "it's a group",
                        "members": [
                            {
                                "email": "john.doe@smartsheet.com"
                            },
                            {
                                "email": "jane.doe@smartsheet.com"
                            }
                        ]
                    }
                }
            },
            {
                "name": "Serialization - Discussion",
                "method": client.sheets.createRowDiscussion,
                "shouldError": false,
                "options": {
                    "sheetId": 1,
                    "rowId": 2,
                    "body": {
                        "comment": {
                            "text": "This is a comment!"
                        }
                    }
                }
            },
            {
                "name": "Serialization - Contact",
                "method": client.contacts.getContact,
                "shouldError": false,
                "options": {
                    "id": "ABC"
                }
            },
            {
                "name": "Serialization - Folder",
                "method": client.home.createFolder,
                "shouldError": false,
                "options": {
                    "body": {
                        "name": "folder"
                    }
                }
            },
            {
                "name": "Serialization - Column",
                "method": client.sheets.addColumn,
                "shouldError": false,
                "options": {
                    "sheetId": 1,
                    "body": {
                        "title": "A Brave New Column",
                        "type": "PICKLIST",
                        "options": [
                            "option1",
                            "option2",
                            "option3"
                        ],
                        "index": 2,
                        "validation": false,
                        "width": 42,
                        "locked": false
                    }
                }
            },
            {
                "name": "Serialization - UserProfile",
                "method": client.users.getCurrentUser,
                "shouldError": false,
                "options": {}
            },
            {
                "name": "Serialization - Workspace",
                "method": client.workspaces.createWorkspace,
                "shouldError": false,
                "options": {
                    "body": {
                        "name": "A Whole New Workspace"
                    }
                }
            },
            {
                "name": "Serialization - User",
                "method": client.users.addUser,
                "shouldError": false,
                "options": {
                    "body": {
                        "email": "john.doe@smartsheet.com",
                        "admin": false,
                        "licensedSheetCreator": true,
                        "firstName": "John",
                        "lastName": "Doe",
                        "groupAdmin": false,
                        "resourceViewer": true
                    }
                }
            },
            {
                "name": "Serialization - Sheet",
                "method": client.sheets.createSheet,
                "shouldError": false,
                "options": {
                    "body": {
                        "name": "The First Sheet",
                        "columns": [
                            {
                                "title": "The First Column",
                                "primary": true,
                                "type": "TEXT_NUMBER"
                            },
                            {
                                "title": "The Second Column",
                                "primary": false,
                                "type": "TEXT_NUMBER",
                                "systemColumnType": "AUTO_NUMBER",
                                "autoNumberFormat": {
                                    "prefix": "{YYYY}-{MM}-{DD}-",
                                    "suffix": "-SUFFIX",
                                    "fill": "000000"
                                }
                            }
                        ]
                    }
                }
            },
            {
                "name": "Serialization - AlternateEmail",
                "method": client.users.addAlternateEmail,
                "shouldError": false,
                "options": {
                    "userId": 1,
                    "body": [
                        {
                            "email": "not.not.john.doe@smartsheet.com"
                        }
                    ]
                }
            },
            {
                "name": "Serialization - Predecessor",
                "method": client.sheets.addRows,
                "shouldError": false,
                "options": {
                    "sheetId": 1,
                    "body": {
                        "cells": [
                            {
                                "columnId": 2,
                                "objectValue": {
                                    "objectType": "PREDECESSOR_LIST",
                                    "predecessors": [
                                        {
                                            "rowId": 3,
                                            "type": "FS",
                                            "lag": {
                                                "objectType": "DURATION",
                                                "negative": false,
                                                "elapsed": false,
                                                "weeks": 1.5,
                                                "days": 2.5,
                                                "hours": 3.5,
                                                "minutes": 4.5,
                                                "seconds": 5.5,
                                                "milliseconds": 6
                                            }
                                        }
                                    ]
                                }
                            }
                        ]
                    },
                    "queryParameters": {
                        "include": "objectValue"
                    }
                }
            },
            {
                "name": "Serialization - IndexResult",
                "method": client.users.listAllUsers,
                "shouldError": false,
                "options": {}
            },
            {
                "name": "Serialization - Image",
                "method": client.sheets.getRow,
                "shouldError": false,
                "options": {
                    "sheetId": 1,
                    "rowId": 2
                }
            },
            {
                "name": "Serialization - Image Urls",
                "method": client.images.listImageUrls,
                "shouldError": false,
                "options": {
                    "body": [
                        {
                            "imageId": "abc",
                            "height": 100,
                            "width": 200
                        }
                    ]
                }
            },
            {
                "name": "Serialization - BulkFailure",
                "method": client.sheets.addRows,
                "shouldError": false,
                "options": {
                    "sheetId": 1,
                    "body": [
                        {
                            "toBottom": true,
                            "cells": [
                                {
                                    "columnId": 2,
                                    "value": "Some Value"
                                }
                            ]
                        },
                        {
                            "toBottom": true,
                            "cells": [
                                {
                                    "columnId": 3,
                                    "value": "Some Value"
                                }
                            ]
                        }
                    ],
                    "queryParameters": {
                        "allowPartialSuccess": "true"
                    }
                }
            },
            {
                "name": "Serialization - Rows",
                "method": client.sheets.addRows,
                "shouldError": false,
                "options": {
                    "sheetId": 1,
                    "body": {
                        "expanded": true,
                        "format": ",,,,,,,,4,,,,,,,",
                        "cells": [
                            {
                                "columnId": 2,
                                "value": "url link",
                                "strict": false,
                                "hyperlink": {
                                    "url": "https://google.com"
                                }
                            },
                            {
                                "columnId": 3,
                                "value": "sheet id link",
                                "strict": false,
                                "hyperlink": {
                                    "sheetId": 4
                                }
                            },
                            {
                                "columnId": 5,
                                "value": "report id link",
                                "strict": false,
                                "hyperlink": {
                                    "reportId": 6
                                }
                            }
                        ],
                        "locked": false
                    }
                }
            },
            {
                "name": "Serialization - Cell Link",
                "method": client.sheets.updateRow,
                "shouldError": false,
                "options": {
                    "sheetId": 1,
                    "body": {
                        "id": 2,
                        "cells": [
                            {
                                "columnId": 3,
                                "value": null,
                                "linkInFromCell": {
                                    "sheetId": 4,
                                    "rowId": 5,
                                    "columnId": 6
                                }
                            }
                        ]
                    }
                }
            },
            {
                "name": "Serialization - Favorite",
                "method": client.favorites.addSheetToFavorites,
                "shouldError": false,
                "options": {
                    "objectId": 1
                }
            },
            {
                "name": "Serialization - Report",
                "method": client.reports.getReport,
                "shouldError": false,
                "options": {
                    "id": 1
                }
            },
            {
                "name": "Serialization - Share",
                "method": client.sheets.share,
                "shouldError": false,
                "options": {
                    "sheetId": 1,
                    "body": {
                        "email": "john.doe@smartsheet.com",
                        "accessLevel": "VIEWER",
                        "subject": "Check out this sheet",
                        "message": "Let me know what you think. Thanks!",
                        "ccMe": true
                    },
                    "queryParameters": {
                        "sendEmail": "true"
                    }
                }
            },
            {
                "name": "Serialization - Send via Email",
                "method": client.sheets.sendSheetViaEmail,
                "shouldError": false,
                "options": {
                    "sheetId": 1,
                    "body": {
                        "sendTo": [
                            {
                                "email": "john.doe@smartsheet.com"
                            },
                            {
                                "groupId": 2
                            }
                        ],
                        "subject": "Some subject",
                        "message": "Some message",
                        "ccMe": true,
                        "format": "PDF",
                        "formatDetails": {
                            "paperSize": "LETTER"
                        }
                    }
                }
            },
            {
                "name": "Serialization - Row Email",
                "method": client.sheets.sendRows,
                "shouldError": false,
                "options": {
                    "sheetId": 1,
                    "body": {
                        "sendTo": [
                            {
                                "groupId": 2
                            }
                        ],
                        "subject": "Some subject",
                        "message": "Some message",
                        "columnIds": [
                            3
                        ],
                        "includeAttachments": false,
                        "includeDiscussions": true,
                        "layout": "VERTICAL",
                        "rowIds": [
                            4
                        ]
                    }
                }
            },
            {
                "name": "Serialization - Template",
                "method": client.templates.listPublicTemplates,
                "shouldError": false,
                "options": {}
            },
            {
                "name": "Serialization - Update Request",
                "method": client.sheets.createUpdateRequest,
                "shouldError": false,
                "options": {
                    "sheetId": 1,
                    "body": {
                        "sendTo": [
                            {
                                "email": "john.doe@smartsheet.com"
                            }
                        ],
                        "rowIds": [
                            2
                        ],
                        "columnIds": [
                            3
                        ],
                        "includeAttachments": true,
                        "includeDiscussions": false,
                        "subject": "Some subject",
                        "message": "Some message",
                        "ccMe": true,
                        "schedule": {
                            "type": "MONTHLY",
                            "startAt": "2018-03-01T19:00:00Z",
                            "endAt": "2018-06-01T00:00:00Z",
                            "dayOrdinal": "FIRST",
                            "dayDescriptors": [
                                "FRIDAY"
                            ],
                            "repeatEvery": 1
                        }
                    }
                }
            },
            {
                "name": "Serialization - Sent Update Requests",
                "method": client.sheets.getSentUpdateRequest,
                "shouldError": false,
                "options": {
                    "sheetId": 1,
                    "sentUpdateRequestId": 2
                }
            },
            {
                "name": "Serialization - Sheet Settings",
                "method": client.sheets.updateSheet,
                "shouldError": false,
                "options": {
                    "id": 1,
                    "body": {
                        "userSettings": {
                            "criticalPathEnabled": true,
                            "displaySummaryTasks": true
                        },
                        "projectSettings": {
                            "workingDays": [
                                "MONDAY",
                                "TUESDAY"
                            ],
                            "nonWorkingDays": [
                                "2018-04-04",
                                "2018-05-05",
                                "2018-06-06"
                            ],
                            "lengthOfDay": 23.5
                        }
                    }
                }
            },
            {
                "name": "Serialization - Container Destination",
                "method": client.folders.copyFolder,
                "shouldError": false,
                "options": {
                    "folderId": 1,
                    "body": {
                        "destinationType": "home",
                        "destinationId": null,
                        "newName": "Copy of Some Folder"
                    }
                }
            },
            {
                "name": "Serialization - Cross Sheet Reference",
                "method": client.sheets.createCrossSheetReference,
                "shouldError": false,
                "options": {
                    "sheetId": 1,
                    "body": {
                        "name": "Some Cross Sheet Reference",
                        "sourceSheetId": 2,
                        "startRowId": 3,
                        "endRowId": 4,
                        "startColumnId": 5,
                        "endColumnId": 6
                    }
                }
            }
        ];

        helpers.defineMockApiTests(scenarios);
    });
});
<|endoftext|>


<commit_before>// Eloquent JavaScript

// Run this file in your terminal using `node my_solution.js`. Make sure it works before moving on!

// Program Structure
// Write your own variable and do something to it.
/*
var bill = 112;
bill++;
console.log(bill);
*/
// Favorite Food program

//var favoriteFood = prompt("What's your favorite food?");
//alert("Hey! That's my favorite too!");

// Complete one of the exercises: Looping a Triangle, FizzBuzz, or Chess Board

//Triangle
/*
for (var output = "#"; output.length <= 7; output += "#")
  console.log(output);
*/
//FizzBuzz
/*
for (var counter = 0; counter <=100; counter++) {
  if (counter % 3 == 0) {
    if (counter % 5 == 0) console.log("FizzBuzz");
    else console.log("Fizz");
  }
  else if (counter % 5 == 0) console.log("Buzz");
  else console.log(counter);
}
*/
//Chess Board

var size = 8;
for (var height = 0; height <= (size - 1); height++) {
  var printLine = ""
  for (var width = 0; width <= (size - 1); width++) {
    if (height % 2 == 0) {
      if (width % 2 ==0) printLine += " ";
      else printLine += "#";
    }
    else {
      if (width % 2 ==0) printLine += "#";
      else printLine += " ";
    }
  }
  console.log(printLine);
}

// Functions

// Complete the `minimum` exercise.

// Data Structures: Objects and Arrays
// Create an object called "me" that stores your name, age, 3 favorite foods, and a quirk below.<commit_msg>Complete challenge 7.2<commit_after>// Eloquent JavaScript

// Run this file in your terminal using `node my_solution.js`. Make sure it works before moving on!

// Program Structure
// Write your own variable and do something to it.

var bill = 112;
bill++;
console.log(bill);

// Favorite Food program

var favoriteFood = prompt("What's your favorite food?");
alert("Hey! That's my favorite too!");

// Complete one of the exercises: Looping a Triangle, FizzBuzz, or Chess Board

//Triangle

for (var output = "#"; output.length <= 7; output += "#")
  console.log(output);

//FizzBuzz

for (var counter = 0; counter <=100; counter++) {
  if (counter % 3 == 0) {
    if (counter % 5 == 0) console.log("FizzBuzz");
    else console.log("Fizz");
  }
  else if (counter % 5 == 0) console.log("Buzz");
  else console.log(counter);
}

//Chess Board

var size = 8;
for (var height = 0; height <= (size - 1); height++) {
  var printLine = ""
  for (var width = 0; width <= (size - 1); width++) {
    if (height % 2 == 0) {
      if (width % 2 ==0) printLine += " ";
      else printLine += "#";
    }
    else {
      if (width % 2 ==0) printLine += "#";
      else printLine += " ";
    }
  }
  console.log(printLine);
}

// Functions

// Complete the `minimum` exercise.

function min(a, b) {
 return (a <= b ? a : b);
}

// Data Structures: Objects and Arrays
// Create an object called "me" that stores your name, age, 3 favorite foods, and a quirk below.

var me = {
  name: "Michael",
  age: 35,
  favoriteFoods: ["sushi", "croissants", "pate"],
  quirk: "Owns over 3 dozen puppets"
};<|endoftext|>


<commit_before>/**
 * @module Lights, Camera
 * @submodule Lights
 * @for p5
 * @requires core
 */

'use strict';

var p5 = require('../core/core');

/**
 * Creates an ambient light with a color
 *
 * @method ambientLight
 * @param  {Number}        v1      red or hue value relative to
 *                                 the current color range
 * @param  {Number}        v2      green or saturation value
 *                                 relative to the current color range
 * @param  {Number}        v3      blue or brightness value
 *                                 relative to the current color range
 * @param  {Number}        [alpha]
 * @chainable
 */

/**
 * @method ambientLight
 * @param  {String}        value   a color string
 * @param  {Number}        [alpha]
 * @chainable
 */

/**
 * @method ambientLight
 * @param  {Number[]}      values  an array containing the red,green,blue &
 *                                 and alpha components of the color
 * @chainable
 */

/**
 * @method ambientLight
 * @param  {p5.Color}      color   the ambient light color
 * @param  {Number}        [alpha]
 * @chainable
 *
 * @example
 *

 *
 * function setup(){
 *   createCanvas(100, 100, WEBGL);
 * }
 * function draw(){
 *   background(0);
 *   ambientLight(150);
 *   ambientMaterial(250);
 *   sphere(50);
 * }
 *
 *

 *
 * @alt
 * nothing displayed
 *
 */
p5.prototype.ambientLight = function(v1, v2, v3, a){
  if (! this._renderer.curFillShader.isLightShader()) {
    this._renderer.setFillShader(this._renderer._getLightShader());
  }

  var color = this._renderer._pInst.color.apply(
    this._renderer._pInst, arguments);

  //@todo this is a bit icky. array uniforms have
  //to be multiples of the type 3(rgb) in this case.
  //a preallocated Float32Array(24) that we copy into
  //would be better
  var colors = new Float32Array(color._array.slice(0,3));
  this._renderer.curFillShader.setUniform('uAmbientColor', colors);
  this._renderer.curFillShader.setUniform('uUseLighting', true);
  this._renderer.ambientLightCount++;
  //in case there's no material color for the geometry
  this._renderer.curFillShader.setUniform('uMaterialColor',
    this._renderer.curFillColor);
  this._renderer.curFillShader.setUniform('uAmbientLightCount',
    this._renderer.ambientLightCount);
  return this;
};

/**
 * Creates a directional light with a color and a direction
 * @method  directionalLight
 * @param  {Number|Array|String|p5.Color} v1   gray value,
 * red or hue value (depending on the current color mode),
 * or color Array, or CSS color string
 * @param  {Number}          [v2] green or saturation value
 * @param  {Number}          [v3] blue or brightness value
 * @param  {Number}          [a]  opacity
 * @param  {Number|p5.Vector} x   x axis direction or a p5.Vector
 * @param  {Number}          [y]  y axis direction
 * @param  {Number}          [z]  z axis direction
 * @chainable
 * @example
 *

 *
 * function setup(){
 *   createCanvas(100, 100, WEBGL);
 * }
 * function draw(){
 *   background(0);
 *   //move your mouse to change light direction
 *   var dirX = (mouseX / width - 0.5) *2;
 *   var dirY = (mouseY / height - 0.5) *(-2);
 *   directionalLight(250, 250, 250, dirX, dirY, 0.25);
 *   ambientMaterial(250);
 *   sphere(50);
 * }
 *
 *

 *
 * @alt
 * light source on canvas changeable with mouse position
 *
 */
p5.prototype.directionalLight = function(v1, v2, v3, x, y, z) {
  if (! this._renderer.curFillShader.isLightShader()) {
    this._renderer.setFillShader(this._renderer._getLightShader());
  }

  //@TODO: check parameters number
  var color = this._renderer._pInst.color.apply(
    this._renderer._pInst, [v1, v2, v3]);

  var colors = new Float32Array(color._array.slice(0,3));
  this._renderer.curFillShader.setUniform('uDirectionalColor', colors);

  var _x, _y, _z;

  var args = new Array(arguments.length);
  for (var i = 0; i < args.length; ++i) {
    args[i] = arguments[i];
  }
  if(typeof args[args.length-1] === 'number'){
    _x = args[args.length-3];
    _y = args[args.length-2];
    _z = args[args.length-1];

  }else{
    try{
      _x = args[args.length-1].x;
      _y = args[args.length-1].y;
      _z = args[args.length-1].z;
    }
    catch(error){
      throw error;
    }
  }
  this._renderer.curFillShader.setUniform('uUseLighting', true);
  //in case there's no material color for the geometry
  this._renderer.curFillShader.setUniform('uMaterialColor',
    this._renderer.curFillColor);
  this._renderer.curFillShader.setUniform('uLightingDirection', [_x, _y, _z]);
  this._renderer.directionalLightCount ++;
  this._renderer.curFillShader.setUniform('uDirectionalLightCount',
    this._renderer.directionalLightCount);
  return this;
};

/**
 * Creates a point light with a color and a light position
 * @method  pointLight
 * @param  {Number|Array|String|p5.Color} v1   gray value,
 * red or hue value (depending on the current color mode),
 * or color Array, or CSS color string
 * @param  {Number}          [v2] green or saturation value
 * @param  {Number}          [v3] blue or brightness value
 * @param  {Number}          [a]  opacity
 * @param  {Number|p5.Vector} x   x axis position or a p5.Vector
 * @param  {Number}          [y]  y axis position
 * @param  {Number}          [z]  z axis position
 * @chainable
 * @example
 *

 *
 * function setup(){
 *   createCanvas(100, 100, WEBGL);
 * }
 * function draw(){
 *   background(0);
 *   //move your mouse to change light position
 *   var locY = (mouseY / height - 0.5) *(-2);
 *   var locX = (mouseX / width - 0.5) *2;
 *   //to set the light position,
 *   //think of the world's coordinate as:
 *   // -1,1 -------- 1,1
 *   //   |            |
 *   //   |            |
 *   //   |            |
 *   // -1,-1---------1,-1
 *   pointLight(250, 250, 250, locX, locY, 0);
 *   ambientMaterial(250);
 *   sphere(50);
 * }
 *
 *

 *
 * @alt
 * spot light on canvas changes position with mouse
 *
 */
p5.prototype.pointLight = function(v1, v2, v3, a, x, y, z) {
  if (! this._renderer.curFillShader.isLightShader()) {
    this._renderer.setFillShader(this._renderer._getLightShader());
  }
  //@TODO: check parameters number
  var color = this._renderer._pInst.color.apply(
    this._renderer._pInst, [v1, v2, v3]);

  var colors = new Float32Array(color._array.slice(0,3));
  this._renderer.curFillShader.setUniform('uPointLightColor', colors);

  var _x, _y, _z;

  var args = new Array(arguments.length);
  for (var i = 0; i < args.length; ++i) {
    args[i] = arguments[i];
  }
  if(typeof args[args.length-1] === 'number'){
    _x = args[args.length-3];
    _y = args[args.length-2];
    _z = args[args.length-1];

  }else{
    try{
      _x = args[args.length-1].x;
      _y = args[args.length-1].y;
      _z = args[args.length-1].z;
    }
    catch(error){
      throw error;
    }
  }
  this._renderer.curFillShader.setUniform('uUseLighting', true);
  //in case there's no material color for the geometry
  this._renderer.curFillShader.setUniform('uMaterialColor',
    this._renderer.curFillColor);
  this._renderer.curFillShader.setUniform('uPointLightLocation', [_x, _y, _z]);
  this._renderer.pointLightCount++;
  this._renderer.curFillShader.setUniform('uPointLightCount',
    this._renderer.pointLightCount);
  return this;
};

module.exports = p5;
<commit_msg>fix directionalLight & pointLIght<commit_after>/**
 * @module Lights, Camera
 * @submodule Lights
 * @for p5
 * @requires core
 */

'use strict';

var p5 = require('../core/core');

/**
 * Creates an ambient light with a color
 *
 * @method ambientLight
 * @param  {Number}        v1      red or hue value relative to
 *                                 the current color range
 * @param  {Number}        v2      green or saturation value
 *                                 relative to the current color range
 * @param  {Number}        v3      blue or brightness value
 *                                 relative to the current color range
 * @param  {Number}        [alpha]
 * @chainable
 */

/**
 * @method ambientLight
 * @param  {String}        value   a color string
 * @param  {Number}        [alpha]
 * @chainable
 */

/**
 * @method ambientLight
 * @param  {Number[]}      values  an array containing the red,green,blue &
 *                                 and alpha components of the color
 * @chainable
 */

/**
 * @method ambientLight
 * @param  {p5.Color}      color   the ambient light color
 * @param  {Number}        [alpha]
 * @chainable
 *
 * @example
 *

 *
 * function setup(){
 *   createCanvas(100, 100, WEBGL);
 * }
 * function draw(){
 *   background(0);
 *   ambientLight(150);
 *   ambientMaterial(250);
 *   sphere(50);
 * }
 *
 *

 *
 * @alt
 * nothing displayed
 *
 */
p5.prototype.ambientLight = function(v1, v2, v3, a){
  if (! this._renderer.curFillShader.isLightShader()) {
    this._renderer.setFillShader(this._renderer._getLightShader());
  }

  var color = this._renderer._pInst.color.apply(
    this._renderer._pInst, arguments);

  //@todo this is a bit icky. array uniforms have
  //to be multiples of the type 3(rgb) in this case.
  //a preallocated Float32Array(24) that we copy into
  //would be better
  var colors = new Float32Array(color._array.slice(0,3));
  this._renderer.curFillShader.setUniform('uAmbientColor', colors);
  this._renderer.curFillShader.setUniform('uUseLighting', true);
  this._renderer.ambientLightCount++;
  //in case there's no material color for the geometry
  this._renderer.curFillShader.setUniform('uMaterialColor',
    this._renderer.curFillColor);
  this._renderer.curFillShader.setUniform('uAmbientLightCount',
    this._renderer.ambientLightCount);
  return this;
};

/**
 * Creates a directional light with a color and a direction
 * @method directionalLight
 * @param  {Number}    r        red or hue value (depending on the current
 * color mode),
 * @param  {Number}    g        green or saturation value
 * @param  {Number}    b        blue or brightness value
 * @param  {p5.Vector} position the direction of the light
 * @chainable
 */

/**
 * @method directionalLight
 * @param  {Number[]|String|p5.Color} color   color Array, CSS color string,
 *                                             or p5.Color value
 * @param  {Number}                   x       x axis direction
 * @param  {Number}                   y       y axis direction
 * @param  {Number}                   z       z axis direction
 * @chainable
 */

/**
 * @method directionalLight
 * @param  {Number[]|String|p5.Color} color
 * @param  {p5.Vector}                position
 * @chainable
 */

/**
 * @method directionalLight
 * @param  {Number}    r
 * @param  {Number}    g
 * @param  {Number}    b
 * @param  {Number}    x
 * @param  {Number}    y
 * @param  {Number}    z
 * @chainable
 *
 * @example
 *

 *
 * function setup(){
 *   createCanvas(100, 100, WEBGL);
 * }
 * function draw(){
 *   background(0);
 *   //move your mouse to change light direction
 *   var dirX = (mouseX / width - 0.5) *2;
 *   var dirY = (mouseY / height - 0.5) *(-2);
 *   directionalLight(250, 250, 250, dirX, dirY, 0.25);
 *   ambientMaterial(250);
 *   sphere(50);
 * }
 *
 *

 *
 * @alt
 * light source on canvas changeable with mouse position
 *
 */
p5.prototype.directionalLight = function(v1, v2, v3, x, y, z) {
  if (! this._renderer.curFillShader.isLightShader()) {
    this._renderer.setFillShader(this._renderer._getLightShader());
  }

  //@TODO: check parameters number
  var color = this._renderer._pInst.color.apply(
    this._renderer._pInst, [v1, v2, v3]);

  var colors = new Float32Array(color._array.slice(0,3));
  this._renderer.curFillShader.setUniform('uDirectionalColor', colors);

  var _x, _y, _z;

  var args = new Array(arguments.length);
  for (var i = 0; i < args.length; ++i) {
    args[i] = arguments[i];
  }
  if(typeof args[args.length-1] === 'number'){
    _x = args[args.length-3];
    _y = args[args.length-2];
    _z = args[args.length-1];

  }else{
    try{
      _x = args[args.length-1].x;
      _y = args[args.length-1].y;
      _z = args[args.length-1].z;
    }
    catch(error){
      throw error;
    }
  }
  this._renderer.curFillShader.setUniform('uUseLighting', true);
  //in case there's no material color for the geometry
  this._renderer.curFillShader.setUniform('uMaterialColor',
    this._renderer.curFillColor);
  this._renderer.curFillShader.setUniform('uLightingDirection', [_x, _y, _z]);
  this._renderer.directionalLightCount ++;
  this._renderer.curFillShader.setUniform('uDirectionalLightCount',
    this._renderer.directionalLightCount);
  return this;
};

/**
 * Creates a point light with a color and a light position
 * @method pointLight
 * @param  {Number}    r        red or hue value (depending on the current
 * color mode),
 * @param  {Number}    g        green or saturation value
 * @param  {Number}    b        blue or brightness value
 * @param  {Number}    x        x axis position
 * @param  {Number}    y        y axis position
 * @param  {Number}    z        z axis position
 * @chainable
 * @example
 *

 *
 * function setup(){
 *   createCanvas(100, 100, WEBGL);
 * }
 * function draw(){
 *   background(0);
 *   //move your mouse to change light position
 *   var locY = (mouseY / height - 0.5) *(-2);
 *   var locX = (mouseX / width - 0.5) *2;
 *   //to set the light position,
 *   //think of the world's coordinate as:
 *   // -1,1 -------- 1,1
 *   //   |            |
 *   //   |            |
 *   //   |            |
 *   // -1,-1---------1,-1
 *   pointLight(250, 250, 250, locX, locY, 0);
 *   ambientMaterial(250);
 *   sphere(50);
 * }
 *
 *

 *
 * @alt
 * spot light on canvas changes position with mouse
 *
 */

/**
 * @method pointLight
 * @param  {Number}    r
 * @param  {Number}    g
 * @param  {Number}    b
 * @param  {p5.Vector} position the position of the light
 * @chainable
 */

/**
 * @method pointLight
 * @param  {Number[]|String|p5.Color} color   color Array, CSS color string,
 * or p5.Color value
 * @param  {Number}                   x
 * @param  {Number}                   y
 * @param  {Number}                   z
 * @chainable
 */

/**
 * @method pointLight
 * @param  {Number[]|String|p5.Color} color
 * @param  {p5.Vector}                position
 * @chainable
 */
p5.prototype.pointLight = function(r, g, b, x, y, z) {
  if (! this._renderer.curFillShader.isLightShader()) {
    this._renderer.setFillShader(this._renderer._getLightShader());
  }
  //@TODO: check parameters number
  var color = this._renderer._pInst.color.apply(
    this._renderer._pInst, [r, g, b]);

  var colors = new Float32Array(color._array.slice(0,3));
  this._renderer.curFillShader.setUniform('uPointLightColor', colors);

  var _x, _y, _z;

  var args = new Array(arguments.length);
  for (var i = 0; i < args.length; ++i) {
    args[i] = arguments[i];
  }
  if(typeof args[args.length-1] === 'number'){
    _x = args[args.length-3];
    _y = args[args.length-2];
    _z = args[args.length-1];

  }else{
    try{
      _x = args[args.length-1].x;
      _y = args[args.length-1].y;
      _z = args[args.length-1].z;
    }
    catch(error){
      throw error;
    }
  }
  this._renderer.curFillShader.setUniform('uUseLighting', true);
  //in case there's no material color for the geometry
  this._renderer.curFillShader.setUniform('uMaterialColor',
    this._renderer.curFillColor);
  this._renderer.curFillShader.setUniform('uPointLightLocation', [_x, _y, _z]);
  this._renderer.pointLightCount++;
  this._renderer.curFillShader.setUniform('uPointLightCount',
    this._renderer.pointLightCount);
  return this;
};

module.exports = p5;
<|endoftext|>


<commit_before>// List of people who've contributed to the project. Thank you!
export default [
  'Annie LaCourt',
  'Isaac Chansky',
  'Michelle Bernstein',
  'Alec Danaher',
  'Sasha Maryl',
  'Drew Love',
  'Liani Lye',
  'Andrew Cunningham',
  'Liam Morley',
  'Nick Francisci',
  'Stephen Chin',
  'Shameek Poddar',
  'Will McIntosh',
  'Andrew Seeder',
  'Ben Lewis',
  'Yingtong Zhao',
  'Don Blair',
  'Ethan Strominger',
  'Nick Lee',
  'Jonathan Marcus',
  'Emily Wasserman',
  'Ethan Blackwood',
  'Valerie Kenyon',
  'Robert Christie',
];
<commit_msg>add name to contributors<commit_after>// List of people who've contributed to the project. Thank you!
export default [
  'Annie LaCourt',
  'Isaac Chansky',
  'Michelle Bernstein',
  'Alec Danaher',
  'Sasha Maryl',
  'Drew Love',
  'Liani Lye',
  'Andrew Cunningham',
  'Liam Morley',
  'Nick Francisci',
  'Stephen Chin',
  'Shameek Poddar',
  'Will McIntosh',
  'Andrew Seeder',
  'Ben Lewis',
  'Yingtong Zhao',
  'Don Blair',
  'Ethan Strominger',
  'Nick Lee',
  'Jonathan Marcus',
  'Emily Wasserman',
  'Ethan Blackwood',
  'Valerie Kenyon',
  'Robert Christie',
  'Jeff Langevin',
];
<|endoftext|>


<commit_before>/** @license
 * Copyright 2016 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */

describe('Offline', () => {
  /** @type {!shaka.Player} */
  let player;
  /** @type {!shaka.offline.Storage} */
  let storage;
  /** @type {!HTMLVideoElement} */
  let video;
  /** @type {!shaka.util.EventManager} */
  let eventManager;

  beforeAll(() => {
    video = shaka.test.UiUtils.createVideoElement();
    document.body.appendChild(video);
  });

  afterAll(() => {
    document.body.removeChild(video);
  });

  beforeEach(async () => {
    player = new shaka.Player(video);
    player.addEventListener('error', fail);

    eventManager = new shaka.util.EventManager();

    if (supportsStorage()) {
      // Make sure we are starting with a blank slate.
      await shaka.offline.Storage.deleteAll();
      storage = new shaka.offline.Storage(player);
    }
  });

  afterEach(async () => {
    eventManager.release();

    if (storage) {
      await storage.destroy();
    }

    // Make sure we don't leave anything in storage after the test.
    if (supportsStorage()) {
      await shaka.offline.Storage.deleteAll();
    }

    if (player) {
      await player.destroy();
    }
  });

  it('stores, plays, and deletes clear content', async () => {
    if (!supportsStorage()) {
      pending('Storage is not supported.');
      return;
    }

    const content = await storage.store('test:sintel');
    expect(content).toBeTruthy();

    const contentUri = content.offlineUri;
    goog.asserts.assert(
        contentUri, 'Stored content should have an offline uri.');

    await player.load(content.offlineUri);

    video.play();
    await playTo(/* end= */ 3, /* timeout= */ 10);
    await player.unload();
    await storage.remove(contentUri);
  });

  // TODO: Add a PlayReady version once Edge supports offline.
  drmIt(
      'stores, plays, and deletes protected content with a persistent license',
      async () => {
        if (!supportsStorage()) {
          pending('Storage is not supported on this platform.');
          return;
        }

        const support = await shaka.Player.probeSupport();
        const widevineSupport = support.drm['com.widevine.alpha'];

        if (!widevineSupport || !widevineSupport.persistentState) {
          pending('Widevine persistent licenses are not supported');
          return;
        }

        shaka.test.TestScheme.setupPlayer(player, 'sintel-enc');

        storage.configure({usePersistentLicense: true});
        const content = await storage.store('test:sintel-enc');

        // Work around http://crbug.com/887535 in which load cannot happen right
        // after close.  Experimentally, we seem to need a ~1s delay, so we're
        // using a 3s delay to ensure it doesn't flake.  Without this, we get
        // error 6005 (FAILED_TO_CREATE_SESSION) with system code 70.
        // TODO: Remove when Chrome is fixed
        await shaka.test.Util.delay(3);

        const contentUri = content.offlineUri;
        goog.asserts.assert(
            contentUri, 'Stored content should have an offline uri.');

        await player.load(contentUri);

        video.play();
        await playTo(/* end= */ 3, /* timeout= */ 10);
        await player.unload();
        await storage.remove(contentUri);
      });

  drmIt(
      'stores, plays, and deletes protected content with a temporary license',
      async () => {
        if (!supportsStorage()) {
          pending('Storage is not supported.');
          return;
        }

        const support = await shaka.Player.probeSupport();
        const widevineSupport = support.drm['com.widevine.alpha'];
        const playreadySupport = support.drm['com.microsoft.playready'];

        if (!(widevineSupport || playreadySupport)) {
          pending('Widevine and PlayReady are not supported');
          return;
        }

        // Because we do not need a persistent license, we also do not need init
        // data in the manifest.  Using this covers issue #1159, where we used
        // to throw an error inappropriately.
        shaka.test.TestScheme.setupPlayer(player, 'multidrm_no_init_data');

        storage.configure({usePersistentLicense: false});
        const content = await storage.store('test:multidrm_no_init_data');

        const contentUri = content.offlineUri;
        goog.asserts.assert(
            contentUri, 'Stored content should have an offline uri.');

        await player.load(contentUri);

        video.play();
        await playTo(/* end= */ 3, /* timeout= */ 10);
        await player.unload();
        await storage.remove(contentUri);
      });

  /**
   * @param {number} endSeconds
   * @param {number} timeoutSeconds
   * @return {!Promise}
   */
  async function playTo(endSeconds, timeoutSeconds) {
    await shaka.test.Util.waitUntilPlayheadReaches(
        eventManager, video, endSeconds, timeoutSeconds);
  }

  /** @return {boolean} */
  function supportsStorage() {
    return shaka.offline.Storage.support();
  }
});
<commit_msg>Fix DRM test failures introduced by removal of deprecated features<commit_after>/** @license
 * Copyright 2016 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */

describe('Offline', () => {
  /** @type {!shaka.Player} */
  let player;
  /** @type {!shaka.offline.Storage} */
  let storage;
  /** @type {!HTMLVideoElement} */
  let video;
  /** @type {!shaka.util.EventManager} */
  let eventManager;

  beforeAll(() => {
    video = shaka.test.UiUtils.createVideoElement();
    document.body.appendChild(video);
  });

  afterAll(() => {
    document.body.removeChild(video);
  });

  beforeEach(async () => {
    player = new shaka.Player(video);
    player.addEventListener('error', fail);

    eventManager = new shaka.util.EventManager();

    if (supportsStorage()) {
      // Make sure we are starting with a blank slate.
      await shaka.offline.Storage.deleteAll();
      storage = new shaka.offline.Storage(player);
    }
  });

  afterEach(async () => {
    eventManager.release();

    if (storage) {
      await storage.destroy();
    }

    // Make sure we don't leave anything in storage after the test.
    if (supportsStorage()) {
      await shaka.offline.Storage.deleteAll();
    }

    if (player) {
      await player.destroy();
    }
  });

  it('stores, plays, and deletes clear content', async () => {
    if (!supportsStorage()) {
      pending('Storage is not supported.');
      return;
    }

    const content = await storage.store('test:sintel');
    expect(content).toBeTruthy();

    const contentUri = content.offlineUri;
    goog.asserts.assert(
        contentUri, 'Stored content should have an offline uri.');

    await player.load(content.offlineUri);

    video.play();
    await playTo(/* end= */ 3, /* timeout= */ 10);
    await player.unload();
    await storage.remove(contentUri);
  });

  // TODO: Add a PlayReady version once Edge supports offline.
  drmIt(
      'stores, plays, and deletes protected content with a persistent license',
      async () => {
        if (!supportsStorage()) {
          pending('Storage is not supported on this platform.');
          return;
        }

        const support = await shaka.Player.probeSupport();
        const widevineSupport = support.drm['com.widevine.alpha'];

        if (!widevineSupport || !widevineSupport.persistentState) {
          pending('Widevine persistent licenses are not supported');
          return;
        }

        shaka.test.TestScheme.setupPlayer(player, 'sintel-enc');

        storage.configure('offline.usePersistentLicense', true);
        const content = await storage.store('test:sintel-enc');

        // Work around http://crbug.com/887535 in which load cannot happen right
        // after close.  Experimentally, we seem to need a ~1s delay, so we're
        // using a 3s delay to ensure it doesn't flake.  Without this, we get
        // error 6005 (FAILED_TO_CREATE_SESSION) with system code 70.
        // TODO: Remove when Chrome is fixed
        await shaka.test.Util.delay(3);

        const contentUri = content.offlineUri;
        goog.asserts.assert(
            contentUri, 'Stored content should have an offline uri.');

        await player.load(contentUri);

        video.play();
        await playTo(/* end= */ 3, /* timeout= */ 10);
        await player.unload();
        await storage.remove(contentUri);
      });

  drmIt(
      'stores, plays, and deletes protected content with a temporary license',
      async () => {
        if (!supportsStorage()) {
          pending('Storage is not supported.');
          return;
        }

        const support = await shaka.Player.probeSupport();
        const widevineSupport = support.drm['com.widevine.alpha'];
        const playreadySupport = support.drm['com.microsoft.playready'];

        if (!(widevineSupport || playreadySupport)) {
          pending('Widevine and PlayReady are not supported');
          return;
        }

        // Because we do not need a persistent license, we also do not need init
        // data in the manifest.  Using this covers issue #1159, where we used
        // to throw an error inappropriately.
        shaka.test.TestScheme.setupPlayer(player, 'multidrm_no_init_data');

        storage.configure('offline.usePersistentLicense', false);
        const content = await storage.store('test:multidrm_no_init_data');

        const contentUri = content.offlineUri;
        goog.asserts.assert(
            contentUri, 'Stored content should have an offline uri.');

        await player.load(contentUri);

        video.play();
        await playTo(/* end= */ 3, /* timeout= */ 10);
        await player.unload();
        await storage.remove(contentUri);
      });

  /**
   * @param {number} endSeconds
   * @param {number} timeoutSeconds
   * @return {!Promise}
   */
  async function playTo(endSeconds, timeoutSeconds) {
    await shaka.test.Util.waitUntilPlayheadReaches(
        eventManager, video, endSeconds, timeoutSeconds);
  }

  /** @return {boolean} */
  function supportsStorage() {
    return shaka.offline.Storage.support();
  }
});
<|endoftext|>