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