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.
8 function CTFailureGroup(key, failures, annotation) {
10 this.failures = failures;
11 this.annotation = annotation || {};
12 this._computeProperties();
15 CTFailureGroup.prototype.snoozeUntil = function(time) {
16 return this._annotate({
21 CTFailureGroup.prototype.unsnooze = function() {
22 return this._annotate({
23 snoozeTime: undefined,
27 CTFailureGroup.prototype._computeProperties = function() {
28 this.isSnoozed = Date.now() < this.annotation.snoozeTime;
30 this.category = 'snoozed';
32 // FIXME: crbug.com/400397 Split into: Whole step failure, Tree closer, Test failure, Flaky tests
33 this.category = 'default';
37 CTFailureGroup.prototype._annotate = function(newAnnotation) {
38 // FIXME: Post the new annotation to frontend rather than storing locally.
39 return CTFailureGroup.fetchAnnotations().then(function(annotations) {
40 var annotation = annotations[this.key] || {};
42 Object.keys(newAnnotation, function(key, value) {
43 if (value === 'undefined') {
44 delete annotation[key];
46 annotation[key] = value;
50 if (Object.size(annotation) == 0) {
51 delete annotations[this.key];
53 annotations[this.key] = annotation;
56 localStorage.CTFailureGroupAnnotations = JSON.stringify(annotations);
58 this.annotation = annotation;
59 this._computeProperties();
63 CTFailureGroup.fetchAnnotations = function() {
64 // FIXME: Fetch annotations from frontend.
65 var stored = localStorage.CTFailureGroupAnnotations;
66 var annotations = stored ? JSON.parse(stored) : {};
67 return Promise.resolve(annotations);