| 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="ct-tree-status.html"> |
| 8 | 8 |
| 9 <script> | 9 <script> |
| 10 (function () { | 10 (function () { |
| 11 | 11 |
| 12 module("ct-tree-status"); | 12 module("ct-tree-status"); |
| 13 | 13 |
| 14 openTreeJson = { | 14 asyncTest('basic', 5, function() { |
| 15 "username": "username@test.org", | 15 var openTree = document.createElement("ct-tree-status"); |
| 16 "message": "Tree is open", | 16 var openTreeStatus = new TreeStatus('open-tree-project'); |
| 17 "can_commit_freely": true | 17 openTreeStatus.status = 'open'; |
| 18 } | 18 openTree.status = openTreeStatus; |
| 19 | 19 |
| 20 throttledTreeJson = { | 20 var throttledTree = document.createElement("ct-tree-status"); |
| 21 "username": "username@test.org", | 21 var throttledTreeStatus = new TreeStatus('throttled-tree-project'); |
| 22 "message": "Tree is throttled just for fun", | 22 throttledTreeStatus.status = 'throttled'; |
| 23 "can_commit_freely": false | 23 throttledTreeStatus.message = 'Tree is throttled just for fun'; |
| 24 } | 24 throttledTree.status = throttledTreeStatus; |
| 25 | 25 |
| 26 closedTreeJson = { | 26 var closedTree = document.createElement("ct-tree-status"); |
| 27 "username": "username@test.org", | 27 var closedTreeStatus = new TreeStatus('closed-tree-project'); |
| 28 "message": "Tree is closed for maintenance", | 28 closedTreeStatus.status = 'closed'; |
| 29 "can_commit_freely": false | 29 closedTreeStatus.message = 'Tree is closed'; |
| 30 } | 30 closedTree.status = closedTreeStatus; |
| 31 | 31 |
| 32 asyncTest("basic", 10, function() { | |
| 33 var simulator = new NetworkSimulator(); | 32 var simulator = new NetworkSimulator(); |
| 34 simulator.json = function(url) { | |
| 35 if (url.indexOf('closed') != -1) | |
| 36 return Promise.resolve(closedTreeJson); | |
| 37 else if (url.indexOf('throttled') != -1) | |
| 38 return Promise.resolve(throttledTreeJson); | |
| 39 else | |
| 40 return Promise.resolve(openTreeJson); | |
| 41 }; | |
| 42 | |
| 43 var opentree = document.createElement("ct-tree-status"); | |
| 44 opentree.project = "open-tree-project"; | |
| 45 var throttledtree = document.createElement("ct-tree-status"); | |
| 46 throttledtree.project = "throttled-tree-project"; | |
| 47 var closedtree = document.createElement("ct-tree-status"); | |
| 48 closedtree.project = "closed-tree-project"; | |
| 49 | |
| 50 simulator.runTest(function() { | 33 simulator.runTest(function() { |
| 51 var urlByName = treestatus.urlByName; | 34 requestAnimationFrame(function() { |
| 52 treestatus.urlByName = function(name) { | 35 ok(!openTree.shadowRoot.textContent.has("open-tree-project")); |
| 53 return "http://" + name + "-status.appspot.com/"; | 36 ok(throttledTree.shadowRoot.textContent.has("throttled-tree-project")); |
| 54 } | 37 ok(closedTree.shadowRoot.textContent.has("closed-tree-project")); |
| 55 Promise.all([ | 38 equal(closedTree.shadowRoot.querySelector('a').href, closedTreeStatus.url)
; |
| 56 opentree.update().then(function() { | 39 start(); |
| 57 equal(opentree.status, "open"); | |
| 58 }), | |
| 59 throttledtree.update().then(function() { | |
| 60 equal(throttledtree.message, | |
| 61 "Tree is throttled just for fun by username@test.org"); | |
| 62 equal(throttledtree.status, "throttled"); | |
| 63 }), | |
| 64 closedtree.update().then(function() { | |
| 65 equal(closedtree.message, | |
| 66 "Tree is closed for maintenance by username@test.org"); | |
| 67 equal(closedtree.status, "closed"); | |
| 68 equal(closedtree.shadowRoot.querySelector('a').href, treestatus.urlByNam
e('closed-tree-project')); | |
| 69 }) | |
| 70 ]).then(function() { | |
| 71 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(); | |
| 76 treestatus.urlByName = urlByName; | |
| 77 }); | |
| 78 }); | 40 }); |
| 79 }); | 41 }); |
| 80 }); | 42 }); |
| 81 | 43 |
| 82 })(); | 44 })(); |
| 83 </script> | 45 </script> |
| OLD | NEW |