OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 var mediaGalleries = chrome.mediaGalleries; | 5 var mediaGalleries = chrome.mediaGalleries; |
6 | 6 |
7 function StartAndCancelMediaScanTest() { | 7 function MediaScanTest() { |
8 function StartMediaScanTest() { | 8 var scanProgress = 'start'; |
9 var startEventListener = function(details) { | 9 var initialGalleryCount = 0; |
10 chrome.test.assertEq('start', details.type); | 10 |
11 mediaGalleries.onScanProgress.removeListener(startEventListener); | 11 function OnScanResultsAdded(galleries) { |
12 CancelMediaScanTest(); | 12 chrome.test.assertEq(initialGalleryCount + 1, galleries.length); |
13 chrome.test.succeed(); | |
14 } | |
15 | |
16 function OnScanProgress(details) { | |
17 chrome.test.assertEq(scanProgress, details.type); | |
18 if (scanProgress == 'start') { | |
19 scanProgress = 'finish'; | |
20 } else { | |
Lei Zhang
2014/02/20 23:25:20
Is the state transition: start -> finish -> done?
vandebo (ex-Chrome)
2014/02/20 23:41:38
We don't get a third callback, I just want to chan
| |
21 scanProgress = 'done'; | |
22 chrome.test.runWithUserGesture(function() { | |
23 mediaGalleries.addScanResults(OnScanResultsAdded); | |
24 }); | |
13 } | 25 } |
14 mediaGalleries.onScanProgress.addListener(startEventListener); | 26 } |
15 | 27 |
28 function OnInitialMediaGalleries(galleries) { | |
29 initialGalleryCount = galleries.length; | |
30 mediaGalleries.onScanProgress.addListener(OnScanProgress); | |
16 mediaGalleries.startMediaScan(); | 31 mediaGalleries.startMediaScan(); |
17 } | 32 } |
18 | 33 |
19 function CancelMediaScanTest() { | 34 mediaGalleries.getMediaFileSystems(OnInitialMediaGalleries); |
20 var cancelEventListener = function(details) { | |
21 chrome.test.assertEq('cancel', details.type); | |
22 mediaGalleries.onScanProgress.removeListener(cancelEventListener); | |
23 chrome.test.succeed(); | |
24 }; | |
25 mediaGalleries.onScanProgress.addListener(cancelEventListener); | |
26 | |
27 mediaGalleries.cancelMediaScan(); | |
28 } | |
29 | |
30 StartMediaScanTest(); | |
31 } | 35 } |
32 | 36 |
33 CreateDummyWindowToPreventSleep(); | 37 CreateDummyWindowToPreventSleep(); |
34 | 38 |
35 chrome.test.runTests([ | 39 chrome.test.runTests([ |
36 StartAndCancelMediaScanTest, | 40 MediaScanTest, |
37 ]); | 41 ]); |
OLD | NEW |