Index: chrome/test/data/extensions/api_test/systeminfo/storage/test_storage_api.js |
diff --git a/chrome/test/data/extensions/api_test/systeminfo/storage/test_storage_api.js b/chrome/test/data/extensions/api_test/systeminfo/storage/test_storage_api.js |
index 06c9c658cb5d50d7db2e313597479bca57cfd3ec..a679dd88812f958c6f0f2f251d7788a84713bf51 100644 |
--- a/chrome/test/data/extensions/api_test/systeminfo/storage/test_storage_api.js |
+++ b/chrome/test/data/extensions/api_test/systeminfo/storage/test_storage_api.js |
@@ -3,34 +3,57 @@ |
// found in the LICENSE file. |
// systemInfo.storage api test |
-// browser_tests.exe --gtest_filter=SystemInfoStorageApiTest.Storage |
+// browser_tests --gtest_filter=SystemInfoStorageApiTest.Storage |
chrome.systemInfo = chrome.experimental.systemInfo; |
+// Testing data should be the same as that in system_info_storage_apitest.cc |
+var testData = [ |
+ { id: "0xbeaf", type: "unknown", capacity: 4098, |
+ availableCapacity: 1000, step: 0 }, |
+ { id: "/home", type: "harddisk", capacity: 4098, |
+ availableCapacity: 1000, step: 10 }, |
+ { id: "/data", type: "harddisk", capacity: 10000, |
+ availableCapacity: 1000, step: 4097 } |
+]; |
+ |
chrome.test.runTests([ |
function testGet() { |
chrome.systemInfo.storage.get(chrome.test.callbackPass(function(units) { |
- chrome.test.assertTrue(units.length == 1); |
- var unit = units[0]; |
- chrome.test.assertTrue(unit.id == "0xbeaf"); |
- chrome.test.assertTrue(unit.type == "unknown"); |
- chrome.test.assertTrue(unit.capacity == 4098); |
- chrome.test.assertTrue(unit.availableCapacity == 1024); |
+ chrome.test.assertTrue(units.length == 3); |
+ for (var i = 0; i < units.length; ++i) { |
+ chrome.test.assertEq(testData[i].id, units[i].id); |
+ chrome.test.assertEq(testData[i].type, units[i].type); |
+ chrome.test.assertEq(testData[i].capacity, units[i].capacity); |
+ chrome.test.assertEq(testData[i].availableCapacity, |
+ units[i].availableCapacity); |
+ testData[i].availableCapacity += testData[i].step; |
+ } |
})); |
}, |
function testChangedEvent() { |
- chrome.test.sendMessage("ready", function() { |
- var numOfChangedEvent = 0; |
- var base = 10000; |
- var step = 10; |
- var doneChangedEvent = chrome.test.listenForever( |
- chrome.systemInfo.storage.onAvailableCapacityChanged, |
- function listener(changedInfo) { |
- chrome.test.assertTrue(changedInfo.id == "/dev/sda1"); |
- chrome.test.assertTrue( |
- changedInfo.availableCapacity == (base - step*numOfChangedEvent)); |
- if (++numOfChangedEvent > 5) |
- doneChangedEvent(); |
- }); |
- }); |
- } |
+ var numOfChangedEvent = 0; |
+ var callbackCompleted = chrome.test.callbackAdded(); |
+ chrome.systemInfo.storage.onAvailableCapacityChanged.addListener( |
+ function listener(changeInfo) { |
+ for (var i = 0; i < testData.length; ++i) { |
+ if (changeInfo.id == testData[i].id) { |
+ // Increase its availableCapacity since it will be queried before |
+ // triggering onChanged event. |
+ testData[i].availableCapacity += testData[i].step; |
+ chrome.test.assertEq(testData[i].availableCapacity, |
+ changeInfo.availableCapacity); |
+ break; |
+ } |
+ } |
+ |
+ if (i >= testData.length) |
+ chrome.test.fail("No matched storage id is found!"); |
+ |
+ if (++numOfChangedEvent > 10) { |
+ chrome.systemInfo.storage.onAvailableCapacityChanged.removeListener( |
+ listener); |
+ setTimeout(callbackCompleted, 0); |
+ } |
+ }); |
+ } |
]); |