4 <script src=
"mock_controller.js"></script>
9 var mockControl
, mockWindow
, oldIsMac
;
10 var chrome
= chrome
|| {};
11 chrome
.tabs
= chrome
.tabs
|| {};
12 chrome
.windows
= chrome
.windows
|| {};
16 getStringF: function(msg
, number
) {
17 assertEquals('should_open_all', msg
);
22 var URL1
= 'http://chromium.org/';
24 var BASE
= 'http://www.google.com/';
27 mockController
= new MockController();
28 mockController
.createFunctionMock(chrome
.tabs
, 'create');
29 mockController
.createFunctionMock(chrome
.windows
, 'create');
30 oldIsMac
= Object
.getOwnPropertyDescriptor(cr
, 'isMac');
33 confirm
: mockController
.createFunctionMock(),
39 assertEquals(URL1
, url
);
43 mockWindow
.confirm
.returnValue
= false;
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() {
77 openUrlFromEventHelper(e
, false, cr
.LinkKind
.FOREGROUND_TAB
);
80 function testOpenUrlFromEventForegroundTabMac() {
87 openUrlFromEventHelper(e
, true, cr
.LinkKind
.FOREGROUND_TAB
);
90 function testOpenUrlFromEventForegroundTabEnter() {
93 keyIdentifier
: 'Enter',
97 openUrlFromEventHelper(e
, false, cr
.LinkKind
.FOREGROUND_TAB
);
100 function testOpenUrlFromEventForegroundTabEnterMac() {
103 keyIdentifier
: 'Enter',
107 openUrlFromEventHelper(e
, true, cr
.LinkKind
.FOREGROUND_TAB
);
110 function testOpenUrlFromEventForegroundTabMiddleClick() {
116 openUrlFromEventHelper(e
, false, cr
.LinkKind
.FOREGROUND_TAB
);
119 ///////////////////////////////////////////////////////////////////////////////
121 function testOpenUrlFromEventBackgroundTab() {
127 openUrlFromEventHelper(e
, false, cr
.LinkKind
.BACKGROUND_TAB
);
130 function testOpenUrlFromEventBackgroundTabMac() {
136 openUrlFromEventHelper(e
, true, cr
.LinkKind
.BACKGROUND_TAB
);
139 function testOpenUrlFromEventBackgroundTabEnter() {
142 keyIdentifier
: 'Enter',
145 openUrlFromEventHelper(e
, false, cr
.LinkKind
.BACKGROUND_TAB
);
148 function testOpenUrlFromEventBackgroundTabEnterMac() {
151 keyIdentifier
: 'Enter',
154 openUrlFromEventHelper(e
, true, cr
.LinkKind
.BACKGROUND_TAB
);
157 function testOpenUrlFromEventBackgroundTabMiddleClick() {
162 openUrlFromEventHelper(e
, false, cr
.LinkKind
.BACKGROUND_TAB
);
165 ///////////////////////////////////////////////////////////////////////////////
167 function testOpenUrlFromEventWindow() {
173 openUrlFromEventHelper(e
, false, cr
.LinkKind
.WINDOW
);
176 function testOpenUrlFromEventWindowEnter() {
179 keyIdentifier
: 'Enter',
182 openUrlFromEventHelper(e
, false, cr
.LinkKind
.WINDOW
);
185 ///////////////////////////////////////////////////////////////////////////////
187 function testOpenUrlFromEventSelf() {
192 openUrlFromEventHelper(e
, false, cr
.LinkKind
.SELF
);
195 function testOpenUrlFromEventSelfEnter() {
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
);
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({
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({
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
],
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
],
287 lc
.openUrls([URL1
, URL2
], cr
.LinkKind
.INCOGNITO
);