| <!DOCTYPE html> |
| <!-- |
| Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| Use of this source code is governed by a BSD-style license that can be |
| found in the LICENSE file. |
| --> |
| |
| <link rel="import" href="/extras/chrome/cc/display_item_list.html"> |
| <link rel="import" href="/extras/chrome/cc/display_item_debugger.html"> |
| |
| <script> |
| 'use strict'; |
| |
| tr.b.unittest.testSuite(function() { |
| test('instantiate', function() { |
| var displayItemList = new tr.e.cc.DisplayItemListSnapshot( |
| {id: '31415'}, |
| 10, |
| { |
| 'params': { |
| 'layer_rect': [-15, -15, 46, 833], |
| 'items': [ |
| 'BeginClipDisplayItem', |
| 'EndClipDisplayItem' |
| ] |
| }, |
| 'skp64': '[another skia picture in base64]'}); |
| displayItemList.preInitialize(); |
| displayItemList.initialize(); |
| |
| var dbg = new tr.e.cc.DisplayItemDebugger(); |
| this.addHTMLOutput(dbg); |
| assert.isUndefined(dbg.displayItemList_); |
| assert.isUndefined(dbg.picture_); |
| dbg.displayItemList = displayItemList; |
| assert.isDefined(dbg.displayItemList_); |
| assert.isDefined(dbg.picture_); |
| assert.equal(dbg.displayItemList_.items.length, 2); |
| dbg.style.border = '1px solid black'; |
| }); |
| |
| test('selections', function() { |
| var displayItemList = new tr.e.cc.DisplayItemListSnapshot( |
| {id: '31415'}, |
| 10, |
| { |
| 'params': { |
| 'layer_rect': [-15, -15, 46, 833], |
| 'items': [ |
| 'BeginClipDisplayItem', |
| 'TransformDisplayItem', |
| {'name': 'DrawingDisplayItem', 'skp64': '[skia picture in base64]'}, |
| 'EndTransformDisplayItem', |
| 'EndClipDisplayItem' |
| ] |
| }, |
| 'skp64': '[another skia picture in base64]'}); |
| displayItemList.preInitialize(); |
| displayItemList.initialize(); |
| |
| var dbg = new tr.e.cc.DisplayItemDebugger(); |
| this.addHTMLOutput(dbg); |
| dbg.displayItemList = displayItemList; |
| assert.isDefined(dbg.displayItemList_); |
| assert.isDefined(dbg.picture_); |
| assert.equal(dbg.displayItemList_.items.length, 5); |
| |
| var initialPicture = dbg.picture_; |
| assert.isAbove(initialPicture.guid, 0); |
| |
| // Select the drawing display item and make sure the picture updates. |
| var listView = dbg.displayItemListView_; |
| listView.selectedElement = listView.getElementByIndex(3); |
| var updatedPicture = dbg.picture_; |
| assert.isAbove(updatedPicture.guid, 0); |
| assert.notEqual(initialPicture.guid, updatedPicture.guid); |
| |
| // Select the TransformDisplayItem and make sure the picture is blank. |
| listView.selectedElement = listView.getElementByIndex(2); |
| assert.isUndefined(dbg.picture_); |
| |
| // Deselect a list item and make sure the picture is reset to the original. |
| listView.selectedElement = undefined; |
| updatedPicture = dbg.picture_; |
| assert.isAbove(updatedPicture.guid, 0); |
| assert.equal(initialPicture.guid, updatedPicture.guid); |
| |
| dbg.style.border = '1px solid black'; |
| }); |
| |
| test('export', function() { |
| var displayItemList = new tr.e.cc.DisplayItemListSnapshot( |
| {id: '31415'}, |
| 10, |
| { |
| 'params': { |
| 'layer_rect': [-15, -15, 46, 833], |
| 'items': [ |
| 'BeginClipDisplayItem', |
| 'EndClipDisplayItem' |
| ] |
| }, |
| 'skp64': 'c2twaWN0dXJl'}); |
| displayItemList.preInitialize(); |
| displayItemList.initialize(); |
| |
| var dbg = new tr.e.cc.DisplayItemDebugger(); |
| this.addHTMLOutput(dbg); |
| dbg.displayItemList = displayItemList; |
| |
| var onSaveDisplayListCalled = false; |
| dbg.saveFile_ = function(filename, rawData) { |
| onSaveDisplayListCalled = true; |
| assert.equal(filename, 'displayitemlist.json'); |
| assert.equal(rawData, '["BeginClipDisplayItem","EndClipDisplayItem"]'); |
| }; |
| dbg.onExportDisplayListClicked_(); |
| assert(onSaveDisplayListCalled); |
| |
| var onSaveSkPictureCalled = false; |
| dbg.saveFile_ = function(filename, rawData) { |
| onSaveSkPictureCalled = true; |
| assert.equal(filename, 'skpicture.skp'); |
| assert.equal(rawData, 'skpicture'); |
| }; |
| dbg.onExportSkPictureClicked_(); |
| assert(onSaveSkPictureCalled); |
| }); |
| }); |
| </script> |