|
| 1 | +library test_browser_action; |
| 2 | + |
| 3 | +import 'dart:async'; |
| 4 | + |
| 5 | +import 'package:unittest/unittest.dart'; |
| 6 | +import 'package:chrome_gen/chrome_ext.dart' as chrome; |
| 7 | + |
| 8 | +void main() { |
| 9 | + group('chrome.browser_action', () { |
| 10 | + test('title -- global', () { |
| 11 | + String title = 'test title'; |
| 12 | + chrome.BrowserActionSetTitleParams details = |
| 13 | + new chrome.BrowserActionSetTitleParams(title: title); |
| 14 | + chrome.browserAction.setTitle(details); |
| 15 | + chrome.browserAction.getTitle(new chrome.BrowserActionGetTitleParams()) |
| 16 | + .then(expectAsync1((String actual) { |
| 17 | + expect(actual, equals(title)); |
| 18 | + })); |
| 19 | + |
| 20 | + String originalTitle = "chrome_ext.dart - test"; |
| 21 | + chrome.BrowserActionSetTitleParams originalTitleDetails = |
| 22 | + new chrome.BrowserActionSetTitleParams(title: originalTitle); |
| 23 | + chrome.browserAction.setTitle(originalTitleDetails); |
| 24 | + chrome.browserAction.getTitle(new chrome.BrowserActionGetTitleParams()) |
| 25 | + .then(expectAsync1((String actual) { |
| 26 | + expect(actual, equals(originalTitle)); |
| 27 | + })); |
| 28 | + }); |
| 29 | + |
| 30 | + test('title -- tab', () { |
| 31 | + String title = 'test title'; |
| 32 | + chrome.tabs.getCurrent().then(expectAsync1((chrome.Tab tab) { |
| 33 | + chrome.BrowserActionSetTitleParams details = |
| 34 | + new chrome.BrowserActionSetTitleParams(title: title, tabId: tab.id); |
| 35 | + |
| 36 | + chrome.browserAction.setTitle(details); |
| 37 | + chrome.BrowserActionGetTitleParams getTitleDetails = |
| 38 | + new chrome.BrowserActionGetTitleParams(tabId: tab.id); |
| 39 | + chrome.browserAction.getTitle(getTitleDetails).then(expectAsync1((actual) { |
| 40 | + expect(actual, equals(title)); |
| 41 | + })); |
| 42 | + String originalTitle = "chrome_ext.dart - test"; |
| 43 | + chrome.BrowserActionSetTitleParams originalTitleDetails = |
| 44 | + new chrome.BrowserActionSetTitleParams(title: originalTitle, tabId: tab.id); |
| 45 | + chrome.browserAction.setTitle(originalTitleDetails); |
| 46 | + |
| 47 | + chrome.BrowserActionGetTitleParams getOriginalTitleDetails = |
| 48 | + new chrome.BrowserActionGetTitleParams(tabId: tab.id); |
| 49 | + chrome.browserAction.getTitle(getOriginalTitleDetails) |
| 50 | + .then(expectAsync1((String actual) { |
| 51 | + expect(actual, equals(originalTitle)); |
| 52 | + })); |
| 53 | + })); |
| 54 | + }); |
| 55 | + |
| 56 | + test('badge text -- global', () { |
| 57 | + String badgeText = '9999'; |
| 58 | + chrome.BrowserActionSetBadgeTextParams details = |
| 59 | + new chrome.BrowserActionSetBadgeTextParams(text: badgeText); |
| 60 | + chrome.browserAction.setBadgeText(details); |
| 61 | + |
| 62 | + chrome.BrowserActionGetBadgeTextParams getBadgedetails = |
| 63 | + new chrome.BrowserActionGetBadgeTextParams(); |
| 64 | + chrome.browserAction.getBadgeText(getBadgedetails) |
| 65 | + .then(expectAsync1((String actual) { |
| 66 | + expect(actual, equals(badgeText)); |
| 67 | + })); |
| 68 | + |
| 69 | + chrome.BrowserActionSetBadgeTextParams clearBadgedetails = |
| 70 | + new chrome.BrowserActionSetBadgeTextParams(text: ''); |
| 71 | + chrome.browserAction.setBadgeText(clearBadgedetails); |
| 72 | + chrome.browserAction.getBadgeText(getBadgedetails) |
| 73 | + .then(expectAsync1((String actual) { |
| 74 | + expect(actual, equals('')); |
| 75 | + })); |
| 76 | + }); |
| 77 | + |
| 78 | + test('badge text -- tab', () { |
| 79 | + String badgeText = '9999'; |
| 80 | + chrome.tabs.getCurrent().then(expectAsync1((chrome.Tab tab) { |
| 81 | + chrome.BrowserActionSetBadgeTextParams details = |
| 82 | + new chrome.BrowserActionSetBadgeTextParams(text: badgeText, tabId: tab.id); |
| 83 | + chrome.browserAction.setBadgeText(details); |
| 84 | + |
| 85 | + chrome.BrowserActionGetBadgeTextParams getBadgeDetails = |
| 86 | + new chrome.BrowserActionGetBadgeTextParams(tabId: tab.id); |
| 87 | + chrome.browserAction.getBadgeText(getBadgeDetails) |
| 88 | + .then(expectAsync1((String actual) { |
| 89 | + expect(actual, equals(badgeText)); |
| 90 | + })); |
| 91 | + |
| 92 | + chrome.BrowserActionSetBadgeTextParams clearBadgedetails = |
| 93 | + new chrome.BrowserActionSetBadgeTextParams(text: '', tabId: tab.id); |
| 94 | + chrome.browserAction.setBadgeText(clearBadgedetails); |
| 95 | + chrome.browserAction.getBadgeText(getBadgeDetails) |
| 96 | + .then(expectAsync1((String actual) { |
| 97 | + expect(actual, equals('')); |
| 98 | + })); |
| 99 | + })); |
| 100 | + }); |
| 101 | + |
| 102 | + test('badge background color -- global', () { |
| 103 | + chrome.BrowserActionSetBadgeBackgroundColorParams badgeColor = |
| 104 | + new chrome.BrowserActionSetBadgeBackgroundColorParams(color: [192, 134, 76, 255]); |
| 105 | + chrome.BrowserActionSetBadgeBackgroundColorParams originalColor = |
| 106 | + new chrome.BrowserActionSetBadgeBackgroundColorParams(color: [0, 0, 0, 0]); |
| 107 | + |
| 108 | + chrome.browserAction.setBadgeBackgroundColor(badgeColor); |
| 109 | + chrome.browserAction.getBadgeBackgroundColor(new chrome.BrowserActionGetBadgeBackgroundColorParams()) |
| 110 | + .then(expectAsync1((chrome.ColorArray actual) { |
| 111 | + expect(actual.toJs()[0], equals(badgeColor.color[0])); |
| 112 | + expect(actual.toJs()[1], equals(badgeColor.color[1])); |
| 113 | + expect(actual.toJs()[2], equals(badgeColor.color[2])); |
| 114 | + expect(actual.toJs()[3], equals(badgeColor.color[3])); |
| 115 | + })); |
| 116 | + |
| 117 | + chrome.browserAction.setBadgeBackgroundColor(originalColor); |
| 118 | + chrome.browserAction.getBadgeBackgroundColor(new chrome.BrowserActionGetBadgeBackgroundColorParams()) |
| 119 | + .then(expectAsync1((chrome.ColorArray actual) { |
| 120 | + expect(actual.toJs()[0], equals(originalColor.color[0])); |
| 121 | + expect(actual.toJs()[1], equals(originalColor.color[1])); |
| 122 | + expect(actual.toJs()[2], equals(originalColor.color[2])); |
| 123 | + expect(actual.toJs()[3], equals(originalColor.color[3])); |
| 124 | + })); |
| 125 | + }); |
| 126 | + |
| 127 | + test('badge background color -- tab', () { |
| 128 | + chrome.tabs.getCurrent().then(expectAsync1((chrome.Tab tab) { |
| 129 | + chrome.BrowserActionSetBadgeBackgroundColorParams badgeColor = |
| 130 | + new chrome.BrowserActionSetBadgeBackgroundColorParams(color: [192, 134, 76, 255], tabId: tab.id); |
| 131 | + chrome.BrowserActionSetBadgeBackgroundColorParams originalColor = |
| 132 | + new chrome.BrowserActionSetBadgeBackgroundColorParams(color: [0, 0, 0, 0], tabId: tab.id); |
| 133 | + |
| 134 | + chrome.browserAction.setBadgeBackgroundColor(badgeColor); |
| 135 | + chrome.browserAction.getBadgeBackgroundColor(new chrome.BrowserActionGetBadgeBackgroundColorParams(tabId: tab.id)) |
| 136 | + .then(expectAsync1((chrome.ColorArray actual) { |
| 137 | + expect(actual.toJs()[0], equals(badgeColor.color[0])); |
| 138 | + expect(actual.toJs()[1], equals(badgeColor.color[1])); |
| 139 | + expect(actual.toJs()[2], equals(badgeColor.color[2])); |
| 140 | + expect(actual.toJs()[3], equals(badgeColor.color[3])); |
| 141 | + })); |
| 142 | + chrome.browserAction.setBadgeBackgroundColor(originalColor); |
| 143 | + chrome.browserAction.getBadgeBackgroundColor(new chrome.BrowserActionGetBadgeBackgroundColorParams(tabId: tab.id)) |
| 144 | + .then(expectAsync1((chrome.ColorArray actual) { |
| 145 | + expect(actual.toJs()[0], equals(originalColor.color[0])); |
| 146 | + expect(actual.toJs()[1], equals(originalColor.color[1])); |
| 147 | + expect(actual.toJs()[2], equals(originalColor.color[2])); |
| 148 | + expect(actual.toJs()[3], equals(originalColor.color[3])); |
| 149 | + })); |
| 150 | + })); |
| 151 | + }); |
| 152 | + |
| 153 | + test('popup -- global', () { |
| 154 | + String popupFile = "sample.html"; |
| 155 | + chrome.BrowserActionSetPopupParams popupParams = |
| 156 | + new chrome.BrowserActionSetPopupParams(popup: popupFile); |
| 157 | + chrome.browserAction.setPopup(popupParams); |
| 158 | + chrome.BrowserActionGetPopupParams getPopupParams = |
| 159 | + new chrome.BrowserActionGetPopupParams(); |
| 160 | + chrome.browserAction.getPopup(getPopupParams) |
| 161 | + .then(expectAsync1((String actual) { |
| 162 | + expect(actual, endsWith(popupFile)); // adds extension prefix |
| 163 | + })); |
| 164 | + |
| 165 | + chrome.BrowserActionSetPopupParams clearPopupParams = |
| 166 | + new chrome.BrowserActionSetPopupParams(popup: ""); |
| 167 | + chrome.browserAction.setPopup(clearPopupParams); |
| 168 | + chrome.browserAction.getPopup(getPopupParams) |
| 169 | + .then(expectAsync1((String actual) { |
| 170 | + expect(actual, equals("")); |
| 171 | + })); |
| 172 | + }); |
| 173 | + |
| 174 | + test('popup -- tab', () { |
| 175 | + String popupFile = "sample.html"; |
| 176 | + chrome.tabs.getCurrent().then(expectAsync1((chrome.Tab tab) { |
| 177 | + chrome.BrowserActionSetPopupParams popupParams = |
| 178 | + new chrome.BrowserActionSetPopupParams(popup: popupFile, tabId: tab.id); |
| 179 | + |
| 180 | + chrome.BrowserActionSetPopupParams clearPopupParams = |
| 181 | + new chrome.BrowserActionSetPopupParams(popup: "", tabId: tab.id); |
| 182 | + |
| 183 | + chrome.BrowserActionGetPopupParams getPopupParams = |
| 184 | + new chrome.BrowserActionGetPopupParams(tabId: tab.id); |
| 185 | + |
| 186 | + chrome.browserAction.setPopup(popupParams); |
| 187 | + chrome.browserAction.getPopup(getPopupParams) |
| 188 | + .then(expectAsync1((String actual) { |
| 189 | + expect(actual, endsWith(popupFile)); // adds extension prefix |
| 190 | + })); |
| 191 | + chrome.browserAction.setPopup(clearPopupParams); |
| 192 | + chrome.browserAction.getPopup(getPopupParams).then(expectAsync1((actual) { |
| 193 | + expect(actual, equals("")); |
| 194 | + })); |
| 195 | + })); |
| 196 | + }); |
| 197 | + |
| 198 | + test('disable/enable -- global', () { |
| 199 | + chrome.browserAction.disable(); |
| 200 | + chrome.browserAction.enable(); |
| 201 | + // TODO(DrMarcII): need to figure out a way to check if this is working. |
| 202 | + }); |
| 203 | + |
| 204 | + test('disable/enable -- tab', () { |
| 205 | + chrome.tabs.getCurrent().then(expectAsync1((chrome.Tab tab) { |
| 206 | + chrome.browserAction.disable(tab.id); |
| 207 | + chrome.browserAction.enable(tab.id); |
| 208 | + })); |
| 209 | + // TODO(DrMarcII): need to figure out a way to check if this is working. |
| 210 | + }); |
| 211 | + |
| 212 | + test('onClicked', () { |
| 213 | + chrome.browserAction.onClicked.listen((_) { }).cancel(); |
| 214 | + // TODO(DrMarcII): need to figure out a way to fire this event. |
| 215 | + }); |
| 216 | + }); |
| 217 | +} |
0 commit comments