Do not announce robot account token before account ID is available
[chromium-blink-merge.git] / chrome / test / data / webui / link_controller_test.html
blob9dd2587161ed3a02854bdc0b76716edcb21d5044
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="mock_controller.js"></script>
5 </head>
6 <body>
7 <script>
9 var mockControl, mockWindow, oldIsMac;
10 var chrome = chrome || {};
11 chrome.tabs = chrome.tabs || {};
12 chrome.windows = chrome.windows || {};
14 var MSG = 'MSG';
15 var localStrings = {
16 getStringF: function(msg, number) {
17 assertEquals('should_open_all', msg);
18 return MSG + number;
22 var URL1 = 'http://chromium.org/';
23 var URL2 = '#hash';
24 var BASE = 'http://www.google.com/';
26 function setUp() {
27 mockController = new MockController();
28 mockController.createFunctionMock(chrome.tabs, 'create');
29 mockController.createFunctionMock(chrome.windows, 'create');
30 oldIsMac = Object.getOwnPropertyDescriptor(cr, 'isMac');
32 mockWindow = {
33 confirm: mockController.createFunctionMock(),
34 location: {
35 get href() {
36 return BASE;
38 set href(url) {
39 assertEquals(URL1, url);
43 mockWindow.confirm.returnValue = false;
46 function tearDown() {
47 mockController.verifyMocks();
48 mockController.reset();
49 Object.defineProperty(cr, 'isMac', oldIsMac);
52 function testGetWarningMessage() {
53 var lc = new cr.LinkController(localStrings);
54 var msg = lc.getWarningMessage(10);
55 assertEquals(MSG + 10, msg);
58 function openUrlFromEventHelper(event, isMac, expectedKind) {
59 var lc = new cr.LinkController(localStrings);
61 Object.defineProperty(cr, 'isMac', {get: function() { return isMac }});
63 var mock = lc.openUrls = mockController.createFunctionMock();
64 mock.addExpectation([URL1], expectedKind);
65 lc.openUrlFromEvent(URL1, event);
68 ///////////////////////////////////////////////////////////////////////////////
70 function testOpenUrlFromEventForegroundTab() {
71 var e = {
72 type: 'click',
73 button: 0,
74 shiftKey: true,
75 ctrlKey: true
77 openUrlFromEventHelper(e, false, cr.LinkKind.FOREGROUND_TAB);
80 function testOpenUrlFromEventForegroundTabMac() {
81 var e = {
82 type: 'click',
83 button: 0,
84 shiftKey: true,
85 metaKey: true
87 openUrlFromEventHelper(e, true, cr.LinkKind.FOREGROUND_TAB);
90 function testOpenUrlFromEventForegroundTabEnter() {
91 var e = {
92 type: 'keydown',
93 keyIdentifier: 'Enter',
94 shiftKey: true,
95 ctrlKey: true
97 openUrlFromEventHelper(e, false, cr.LinkKind.FOREGROUND_TAB);
100 function testOpenUrlFromEventForegroundTabEnterMac() {
101 var e = {
102 type: 'keydown',
103 keyIdentifier: 'Enter',
104 shiftKey: true,
105 metaKey: true
107 openUrlFromEventHelper(e, true, cr.LinkKind.FOREGROUND_TAB);
110 function testOpenUrlFromEventForegroundTabMiddleClick() {
111 var e = {
112 type: 'click',
113 button: 1,
114 shiftKey: true
116 openUrlFromEventHelper(e, false, cr.LinkKind.FOREGROUND_TAB);
119 ///////////////////////////////////////////////////////////////////////////////
121 function testOpenUrlFromEventBackgroundTab() {
122 var e = {
123 type: 'click',
124 button: 0,
125 ctrlKey: true
127 openUrlFromEventHelper(e, false, cr.LinkKind.BACKGROUND_TAB);
130 function testOpenUrlFromEventBackgroundTabMac() {
131 var e = {
132 type: 'click',
133 button: 0,
134 metaKey: true
136 openUrlFromEventHelper(e, true, cr.LinkKind.BACKGROUND_TAB);
139 function testOpenUrlFromEventBackgroundTabEnter() {
140 var e = {
141 type: 'keydown',
142 keyIdentifier: 'Enter',
143 ctrlKey: true
145 openUrlFromEventHelper(e, false, cr.LinkKind.BACKGROUND_TAB);
148 function testOpenUrlFromEventBackgroundTabEnterMac() {
149 var e = {
150 type: 'keydown',
151 keyIdentifier: 'Enter',
152 metaKey: true
154 openUrlFromEventHelper(e, true, cr.LinkKind.BACKGROUND_TAB);
157 function testOpenUrlFromEventBackgroundTabMiddleClick() {
158 var e = {
159 type: 'click',
160 button: 1
162 openUrlFromEventHelper(e, false, cr.LinkKind.BACKGROUND_TAB);
165 ///////////////////////////////////////////////////////////////////////////////
167 function testOpenUrlFromEventWindow() {
168 var e = {
169 type: 'click',
170 button: 0,
171 shiftKey: true
173 openUrlFromEventHelper(e, false, cr.LinkKind.WINDOW);
176 function testOpenUrlFromEventWindowEnter() {
177 var e = {
178 type: 'keydown',
179 keyIdentifier: 'Enter',
180 shiftKey: true
182 openUrlFromEventHelper(e, false, cr.LinkKind.WINDOW);
185 ///////////////////////////////////////////////////////////////////////////////
187 function testOpenUrlFromEventSelf() {
188 var e = {
189 type: 'click',
190 button: 0
192 openUrlFromEventHelper(e, false, cr.LinkKind.SELF);
195 function testOpenUrlFromEventSelfEnter() {
196 var e = {
197 type: 'keydown',
198 keyIdentifier: 'Enter'
200 openUrlFromEventHelper(e, false, cr.LinkKind.SELF);
203 ///////////////////////////////////////////////////////////////////////////////
205 function testOpenUrl() {
206 var lc = new cr.LinkController(localStrings);
208 var mock = mockController.createFunctionMock(lc, 'openUrls');
209 mock.addExpectation([URL1], cr.LinkKind.SELF);
210 lc.openUrl(URL1, cr.LinkKind.SELF);
213 /////////////////////////////// OpenUrls //////////////////////////////////////
215 function testOpenUrlsTooFew() {
216 var lc = new cr.LinkController(localStrings);
218 lc.openUrls([], cr.LinkKind.SELF);
221 function testOpenUrlsTooMany() {
222 var lc = new cr.LinkController(localStrings);
223 lc.warningLimit = 9;
225 var urls = new Array(lc.warningLimit + 1);
227 lc.window = mockWindow;
228 lc.window.confirm.addExpectation('MSG10');
230 lc.openUrls(urls, cr.LinkKind.SELF);
233 function testOpenUrlsSelf() {
234 var lc = new cr.LinkController(localStrings);
235 lc.window = mockWindow;
237 lc.openUrls([URL1], cr.LinkKind.SELF);
240 function testOpenUrlsForegroundTab() {
241 var lc = new cr.LinkController(localStrings);
242 lc.window = mockWindow;
244 chrome.tabs.create.addExpectation({url: URL1, selected: true});
245 chrome.tabs.create.addExpectation({
246 url: BASE + URL2,
247 selected: false
250 lc.openUrls([URL1, URL2], cr.LinkKind.FOREGROUND_TAB);
253 function testOpenUrlsBackgroundTab() {
254 var lc = new cr.LinkController(localStrings);
255 lc.window = mockWindow;
257 chrome.tabs.create.addExpectation({url: URL1, selected: false});
258 chrome.tabs.create.addExpectation({
259 url: BASE + URL2,
260 selected: false
263 lc.openUrls([URL1, URL2], cr.LinkKind.BACKGROUND_TAB);
266 function testOpenUrlsWindow() {
267 var lc = new cr.LinkController(localStrings);
268 lc.window = mockWindow;
270 chrome.windows.create.addExpectation({
271 url: [URL1, BASE + URL2],
272 incognito: false
275 lc.openUrls([URL1, URL2], cr.LinkKind.WINDOW);
278 function testOpenUrlsIncognito() {
279 var lc = new cr.LinkController(localStrings);
280 lc.window = mockWindow;
282 chrome.windows.create.addExpectation({
283 url: [URL1, BASE + URL2],
284 incognito: true
287 lc.openUrls([URL1, URL2], cr.LinkKind.INCOGNITO);
290 </script>
291 </body>
292 </html>