| OLD | NEW |
| 1 <!-- | 1 <!-- |
| 2 Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 3 Use of this source code is governed by a BSD-style license that can be |
| 4 found in the LICENSE file. | 4 found in the LICENSE file. |
| 5 --> | 5 --> |
| 6 | 6 |
| 7 <link rel="import" href="ct-tree-status.html"> | 7 <link rel="import" href="tree-status.html"> |
| 8 | 8 |
| 9 <script> | 9 <script> |
| 10 |
| 10 (function () { | 11 (function () { |
| 11 | 12 |
| 12 module("ct-tree-status"); | 13 module("tree-status"); |
| 13 | 14 |
| 14 openTreeJson = { | 15 var openTreeJson = { |
| 16 "username": "erg@chromium.org", |
| 17 "date": "2013-10-14 20:22:00.887390", |
| 18 "message": "Tree is open", |
| 19 "can_commit_freely": true, |
| 20 "general_state": "open" |
| 21 }; |
| 22 |
| 23 var throttledTreeJson = { |
| 15 "username": "username@test.org", | 24 "username": "username@test.org", |
| 16 "message": "Tree is open", | 25 "date": "2013-10-14 20:22:00.887390", |
| 17 "can_commit_freely": true | |
| 18 } | |
| 19 | |
| 20 throttledTreeJson = { | |
| 21 "username": "username@test.org", | |
| 22 "message": "Tree is throttled just for fun", | 26 "message": "Tree is throttled just for fun", |
| 23 "can_commit_freely": false | 27 "can_commit_freely": false |
| 24 } | 28 }; |
| 25 | 29 |
| 26 closedTreeJson = { | 30 var closedTreeJson = { |
| 27 "username": "username@test.org", | 31 "username": "ojan@chromium.org", |
| 28 "message": "Tree is closed for maintenance", | 32 "date": "2013-10-14 20:32:09.642350", |
| 29 "can_commit_freely": false | 33 "message": "Tree is closed", |
| 30 } | 34 "can_commit_freely": false, |
| 35 "general_state": "closed" |
| 36 }; |
| 31 | 37 |
| 32 asyncTest("basic", 10, function() { | 38 test('url', 3, function() { |
| 39 var treeStatus = new TreeStatus('blink'); |
| 40 equal(new TreeStatus('blink').url(), 'http://blink-status.appspot.com/'); |
| 41 equal(new TreeStatus('chromium').url(), 'http://chromium-status.appspot.com/')
; |
| 42 equal(new TreeStatus('foo').url(), null); |
| 43 }); |
| 44 |
| 45 asyncTest("basic", 6, function() { |
| 33 var simulator = new NetworkSimulator(); | 46 var simulator = new NetworkSimulator(); |
| 34 simulator.json = function(url) { | 47 simulator.json = function(url) { |
| 35 if (url.indexOf('closed') != -1) | 48 if (url.indexOf('closed') != -1) |
| 36 return Promise.resolve(closedTreeJson); | 49 return Promise.resolve(closedTreeJson); |
| 37 else if (url.indexOf('throttled') != -1) | 50 else if (url.indexOf('throttled') != -1) |
| 38 return Promise.resolve(throttledTreeJson); | 51 return Promise.resolve(throttledTreeJson); |
| 39 else | 52 else |
| 40 return Promise.resolve(openTreeJson); | 53 return Promise.resolve(openTreeJson); |
| 41 }; | 54 }; |
| 42 | 55 |
| 43 var opentree = document.createElement("ct-tree-status"); | 56 var opentree = new TreeStatus("open-tree-project"); |
| 44 opentree.project = "open-tree-project"; | 57 var throttledtree = new TreeStatus("throttled-tree-project"); |
| 45 var throttledtree = document.createElement("ct-tree-status"); | 58 var closedtree = new TreeStatus("closed-tree-project"); |
| 46 throttledtree.project = "throttled-tree-project"; | |
| 47 var closedtree = document.createElement("ct-tree-status"); | |
| 48 closedtree.project = "closed-tree-project"; | |
| 49 | 59 |
| 50 simulator.runTest(function() { | 60 simulator.runTest(function() { |
| 51 var urlByName = treestatus.urlByName; | 61 var url = TreeStatus.prototype.url; |
| 52 treestatus.urlByName = function(name) { | 62 TreeStatus.prototype.url = function() { |
| 53 return "http://" + name + "-status.appspot.com/"; | 63 return "http://" + this.project + "-status.appspot.com/"; |
| 54 } | 64 } |
| 55 Promise.all([ | 65 Promise.all([ |
| 56 opentree.update().then(function() { | 66 opentree.update().then(function() { |
| 57 equal(opentree.status, "open"); | 67 equal(opentree.status, "open"); |
| 58 }), | 68 }), |
| 59 throttledtree.update().then(function() { | 69 throttledtree.update().then(function() { |
| 60 equal(throttledtree.message, | 70 equal(throttledtree.message, |
| 61 "Tree is throttled just for fun by username@test.org"); | 71 "Tree is throttled just for fun by username@test.org"); |
| 62 equal(throttledtree.status, "throttled"); | 72 equal(throttledtree.status, "throttled"); |
| 63 }), | 73 }), |
| 64 closedtree.update().then(function() { | 74 closedtree.update().then(function() { |
| 65 equal(closedtree.message, | 75 equal(closedtree.message, |
| 66 "Tree is closed for maintenance by username@test.org"); | 76 "Tree is closed by ojan@chromium.org"); |
| 67 equal(closedtree.status, "closed"); | 77 equal(closedtree.status, "closed"); |
| 68 equal(closedtree.shadowRoot.querySelector('a').href, treestatus.urlByNam
e('closed-tree-project')); | |
| 69 }) | 78 }) |
| 70 ]).then(function() { | 79 ]).then(function() { |
| 71 requestAnimationFrame(function() { | 80 requestAnimationFrame(function() { |
| 72 ok(!opentree.shadowRoot.textContent.has("open-tree-project")); | |
| 73 ok(throttledtree.shadowRoot.textContent.has("throttled-tree-project")); | |
| 74 ok(closedtree.shadowRoot.textContent.has("closed-tree-project")); | |
| 75 start(); | 81 start(); |
| 76 treestatus.urlByName = urlByName; | 82 TreeStatus.prototype.url = url; |
| 77 }); | 83 }); |
| 78 }); | 84 }); |
| 79 }); | 85 }); |
| 80 }); | 86 }); |
| 81 | 87 |
| 82 })(); | 88 })(); |
| 83 </script> | 89 </script> |
| OLD | NEW |