OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** @fileoverview Suite of tests for extension-sidebar. */ | 5 /** @fileoverview Suite of tests for extension-sidebar. */ |
6 cr.define('extension_manager_tests', function() { | 6 cr.define('extension_manager_tests', function() { |
7 /** @enum {string} */ | 7 /** @enum {string} */ |
8 var TestNames = { | 8 var TestNames = { |
9 SplitSections: 'split sections', | 9 SplitSections: 'split sections', |
| 10 ItemOrder: 'item order', |
10 }; | 11 }; |
11 | 12 |
12 function registerTests() { | 13 function registerTests() { |
13 suite('ExtensionManagerTest', function() { | 14 suite('ExtensionManagerTest', function() { |
14 /** @type {extensions.Manager} */ | 15 /** @type {extensions.Manager} */ |
15 var manager; | 16 var manager; |
16 | 17 |
17 setup(function() { | 18 setup(function() { |
18 manager = document.querySelector('extensions-manager'); | 19 manager = document.querySelector('extensions-manager'); |
19 }); | 20 }); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 var hosted_app = findItemWithName('hosted_app'); | 58 var hosted_app = findItemWithName('hosted_app'); |
58 selector = '#' + hosted_app.data.id; | 59 selector = '#' + hosted_app.data.id; |
59 testVisible(selector, true) | 60 testVisible(selector, true) |
60 expectTrue(!!manager.$$('#websites-list').querySelector(selector)); | 61 expectTrue(!!manager.$$('#websites-list').querySelector(selector)); |
61 | 62 |
62 var packaged_app = findItemWithName('Packaged App Test'); | 63 var packaged_app = findItemWithName('Packaged App Test'); |
63 selector = '#' + packaged_app.data.id; | 64 selector = '#' + packaged_app.data.id; |
64 testVisible(selector, true) | 65 testVisible(selector, true) |
65 expectTrue(!!manager.$$('#websites-list').querySelector(selector)); | 66 expectTrue(!!manager.$$('#websites-list').querySelector(selector)); |
66 }); | 67 }); |
| 68 |
| 69 test(assert(TestNames.ItemOrder), function() { |
| 70 var extensionsSection = manager.$['extensions-list']; |
| 71 var service = extensions.Service.getInstance(); |
| 72 expectEquals(0, extensionsSection.children.length); |
| 73 |
| 74 var alphaFromStore = extension_test_util.createExtensionInfo( |
| 75 {location: 'FROM_STORE', name: 'Alpha', id: 'a'.repeat(32)}); |
| 76 manager.addItem(alphaFromStore, service); |
| 77 |
| 78 expectEquals(1, extensionsSection.children.length); |
| 79 expectEquals(alphaFromStore.id, extensionsSection.children[0].id); |
| 80 |
| 81 // Unpacked extensions come first. |
| 82 var betaUnpacked = extension_test_util.createExtensionInfo( |
| 83 {location: 'UNPACKED', name: 'Beta', id: 'b'.repeat(32)}); |
| 84 manager.addItem(betaUnpacked, service); |
| 85 |
| 86 expectEquals(2, extensionsSection.children.length); |
| 87 expectEquals(betaUnpacked.id, extensionsSection.children[0].id); |
| 88 expectEquals(alphaFromStore.id, extensionsSection.children[1].id); |
| 89 |
| 90 // Extensions from the same location are sorted by name. |
| 91 var gammaUnpacked = extension_test_util.createExtensionInfo( |
| 92 {location: 'UNPACKED', name: 'Gamma', id: 'c'.repeat(32)}); |
| 93 manager.addItem(gammaUnpacked, service); |
| 94 |
| 95 expectEquals(3, extensionsSection.children.length); |
| 96 expectEquals(betaUnpacked.id, extensionsSection.children[0].id); |
| 97 expectEquals(gammaUnpacked.id, extensionsSection.children[1].id); |
| 98 expectEquals(alphaFromStore.id, extensionsSection.children[2].id); |
| 99 |
| 100 // The name-sort should be case-insensitive, and should fall back on |
| 101 // id. |
| 102 var aaFromStore = extension_test_util.createExtensionInfo( |
| 103 {location: 'FROM_STORE', name: 'AA', id: 'd'.repeat(32)}); |
| 104 var AaFromStore = extension_test_util.createExtensionInfo( |
| 105 {location: 'FROM_STORE', name: 'Aa', id: 'e'.repeat(32)}); |
| 106 var aAFromStore = extension_test_util.createExtensionInfo( |
| 107 {location: 'FROM_STORE', name: 'aA', id: 'f'.repeat(32)}); |
| 108 manager.addItem(aaFromStore, service); |
| 109 manager.addItem(AaFromStore, service); |
| 110 manager.addItem(aAFromStore, service); |
| 111 |
| 112 expectEquals(6, extensionsSection.children.length); |
| 113 expectEquals(betaUnpacked.id, extensionsSection.children[0].id); |
| 114 expectEquals(gammaUnpacked.id, extensionsSection.children[1].id); |
| 115 expectEquals(aaFromStore.id, extensionsSection.children[2].id); |
| 116 expectEquals(AaFromStore.id, extensionsSection.children[3].id); |
| 117 expectEquals(aAFromStore.id, extensionsSection.children[4].id); |
| 118 expectEquals(alphaFromStore.id, extensionsSection.children[5].id); |
| 119 }); |
67 }); | 120 }); |
68 } | 121 } |
69 | 122 |
70 return { | 123 return { |
71 registerTests: registerTests, | 124 registerTests: registerTests, |
72 TestNames: TestNames, | 125 TestNames: TestNames, |
73 }; | 126 }; |
74 }); | 127 }); |
OLD | NEW |