Upstream version 9.37.197.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / third_party / tvcm / src / tvcm / ui / list_and_associated_view_test.js
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 'use strict';
6
7 tvcm.require('tvcm.ui.list_and_associated_view');
8
9 tvcm.unittest.testSuite('tvcm.ui.list_and_associated_view_test', function() {
10   var ListAndAssociatedView = tvcm.ui.ListAndAssociatedView;
11
12   var SimpleView = tvcm.ui.define('div');
13   SimpleView.prototype = {
14     __proto__: HTMLDivElement.prototype,
15
16     decorate: function() {
17       this.item_ = undefined;
18     },
19
20     set item(item) {
21       this.item_ = item;
22     },
23     get item() {
24       return this.item_;
25     }
26   };
27
28   test('listViewNamingWithField', function() {
29     var lav = new ListAndAssociatedView();
30     var list = [
31       {x: '1'},
32       {x: '2'},
33       {x: '3'}
34     ];
35     var view = new SimpleView();
36
37     lav.list = list;
38     lav.listProperty = 'x';
39     lav.view = view;
40     lav.viewProperty = 'item';
41
42     var lavListView = lav.listView;
43     assertEquals(3, lavListView.children.length);
44     assertEquals('1', lavListView.children[0].textContent);
45   });
46
47   test('listViewNamingWithProperty', function() {
48     var lav = new ListAndAssociatedView();
49
50     function X(x) {
51       this.x = x;
52     }
53     X.prototype = {
54       get title() {
55         return this.x;
56       }
57     };
58
59     var list = [
60       new X('1'),
61       new X('2'),
62       new X('3')
63     ];
64     var view = new SimpleView();
65
66     lav.list = list;
67     lav.listProperty = 'title';
68     lav.view = view;
69     lav.viewProperty = 'item';
70
71     var lavListView = lav.listView;
72     assertEquals(3, lavListView.children.length);
73     assertEquals('1', lavListView.children[0].textContent);
74   });
75
76   test('selectionChangesView', function() {
77     var lav = new ListAndAssociatedView();
78     var list = [
79       {x: '1'},
80       {x: '2'},
81       {x: '3'}
82     ];
83     var view = new SimpleView();
84
85     lav.list = list;
86     lav.listProperty = 'x';
87     lav.view = view;
88     lav.viewProperty = 'item';
89     var lavListView = lav.listView;
90
91     assertEquals(list[0], view.item);
92     lavListView.children[1].selected = true;
93     assertEquals(list[1], view.item);
94   });
95 });