1eef8a14105f66eef37959de6cf394bc4356c3b5
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Tools / GardeningServer / ui / ct-results-detail.html
1 <!--
2 Copyright 2014 The Chromium Authors. All rights reserved.
3 Use of this source code is governed by a BSD-style license that can be
4 found in the LICENSE file.
5 -->
6
7 <link rel="import" href="ct-results-comparison.html">
8
9 <polymer-element name="ct-results-detail" attributes="failure builder">
10   <template>
11     <style>
12       :host {
13         display: block;
14       }
15     </style>
16     <template if="{{!_urlGroups.length}}">
17       No results to display.
18     </template>
19     <template repeat="{{urlGroup in _urlGroups}}">
20       <template if="{{urlGroup.urls[_kUnknownKind]}}">
21         <ct-test-output type="{{urlGroup.type}}" url="{{urlGroup.urls[_kUnknownKind]}}"></ct-test-output>
22       </template>
23       <template if="{{!urlGroup.urls[_kUnknownKind]}}">
24         <ct-results-comparison type="{{urlGroup.type}}" expectedUrl="{{urlGroup.urls[_kExpectedKind]}}"
25             actualUrl="{{urlGroup.urls[_kActualKind]}}" diffUrl="{{urlGroup.urls[_kDiffKind]}}"></ct-results-comparison>
26       </template>
27     </template>
28   </template>
29   <script>
30     Polymer({
31       failure: null,
32       // FIXME: Initializing builder gives a JS error. Presumably because
33       // ct-results-by-builder sets builder="{{builders[selected]}}". But,
34       // it seems wrong that the way the parent uses this element constrains
35       // what the element can do. Polymer bug?
36       // builder: '',
37
38       _urlGroups: [],
39       _kExpectedKind: results.kExpectedKind,
40       _kActualKind: results.kActualKind,
41       _kDiffKind: results.kDiffKind,
42       _kUnknownKind: results.kUnknownKind,
43
44       observe: {
45         failure: '_update',
46         builder: '_update',
47       },
48
49       _update: function() {
50         if (!this.failure || !this.builder)
51           return;
52
53         // FIXME: If the types of groups doesn't change, then it'd be better to do this
54         // update in place so that the user doesn't see a flicker.
55         this._urlGroups = [];
56
57         var result = this.failure.resultNodesByBuilder[this.builder];
58         // FIXME: There's probably a less hacky way to check this.
59         if (result.actual == 'FAIL' || result.actual == 'UNKNOWN')
60           this._updateUrls();
61         else
62           this._updateWebkitTestUrls();
63       },
64
65       _updateWebkitTestUrls: function() {
66         var result = this.failure.resultNodesByBuilder[this.builder];
67         var failureInfo = results.failureInfo(this.failure.testName, this.builder, result.actual);
68
69         // FIXME: Move this logic to a proper model class so that the network requests this makes
70         // can be easily mocked out in tests.
71         results.fetchResultsURLs(failureInfo).then(function(resultsUrls) {
72           var resultsUrlsByTypeAndKind = {};
73           resultsUrls.forEach(function(url) {
74               var resultType = results.resultType(url);
75               if (!resultsUrlsByTypeAndKind[resultType])
76                   resultsUrlsByTypeAndKind[resultType] = {};
77               resultsUrlsByTypeAndKind[resultType][results.resultKind(url)] = url;
78           });
79
80           Object.keys(resultsUrlsByTypeAndKind, function(resultType, resultsUrlsByKind) {
81             this._urlGroups.push({
82               type: resultType,
83               urls: resultsUrlsByKind,
84             });
85           }.bind(this));
86         }.bind(this));
87       },
88
89       _updateUrls: function() {
90         // FIXME: Along with _updateWebkitTestUrls, move this logic to a proper model class
91         // so that the network requests this makes can be easily mocked out in tests.
92
93         var result = this.failure.resultNodesByBuilder[this.builder];
94
95         // FIXME: We only store build logs by the test name, not the testsuite.testname,
96         // which means that two failing tests from different test suites conflict!
97         var testPart = result.actual == 'UNKNOWN' ? 'stdio' : this.failure.testName.split('.')[1];
98         var url = result.masterUrl +
99             '/builders/' + encodeURIComponent(this.builder) +
100             '/builds/' + result.lastFailingBuild +
101             '/steps/' + this.failure.step +
102             '/logs/' + testPart;
103
104         var resultsUrlsByKind = {};
105         resultsUrlsByKind[this._kUnknownKind] = url;
106
107         this._urlGroups.push({
108           type: results.kTextType,
109           urls: resultsUrlsByKind,
110         });
111       },
112     });
113   </script>
114 </polymer-element>