| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 // These must match the files created in the C++ code. | 5 // These must match the files created in the C++ code. |
| 6 var EXPECTED_FILES_BEFORE = [ | 6 var EXPECTED_FILES_BEFORE = [ |
| 7 ['hello.txt', '123 bytes', 'Plain text', 'Sep 4, 1998 12:34 PM'], | 7 ['hello.txt', '123 bytes', 'Plain text', 'Sep 4, 1998 12:34 PM'], |
| 8 ['world.mpeg', '1,000 bytes', 'MPEG video', 'Jul 4, 2012 10:35 AM'], | 8 ['world.mpeg', '1,000 bytes', 'MPEG video', 'Jul 4, 2012 10:35 AM'], |
| 9 ['My Desktop Background.png', '1 KB', 'PNG image', 'Jan 18, 2038 1:02 AM'], | 9 ['My Desktop Background.png', '1 KB', 'PNG image', 'Jan 18, 2038 1:02 AM'], |
| 10 ['photos', '--', 'Folder', 'Jan 1, 1980 11:59 PM'] | 10 ['photos', '--', 'Folder', 'Jan 1, 1980 11:59 PM'] |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 else | 77 else |
| 78 window.setTimeout(helper, 50); | 78 window.setTimeout(helper, 50); |
| 79 }); | 79 }); |
| 80 } | 80 } |
| 81 helper(); | 81 helper(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 // Checks that the files initially added by the C++ side are displayed, and | 84 // Checks that the files initially added by the C++ side are displayed, and |
| 85 // that a subsequently added file shows up. | 85 // that a subsequently added file shows up. |
| 86 function testFileDisplay() { | 86 function testFileDisplay() { |
| 87 getFileList(function(actualFilesBefore) { | 87 waitForFileListChange( |
| 88 chrome.test.assertEq(EXPECTED_FILES_BEFORE, actualFilesBefore); | 88 0, |
| 89 chrome.test.sendMessage('initial check done', function(reply) { | 89 function(actualFilesBefore) { |
| 90 chrome.test.assertEq('file added', reply); | 90 chrome.test.assertEq(EXPECTED_FILES_BEFORE, actualFilesBefore); |
| 91 waitForFileListChange( | 91 chrome.test.sendMessage('initial check done', function(reply) { |
| 92 chrome.test.assertEq('file added', reply); |
| 93 waitForFileListChange( |
| 92 EXPECTED_FILES_BEFORE.length, | 94 EXPECTED_FILES_BEFORE.length, |
| 93 chrome.test.callbackPass(function(actualFilesAfter) { | 95 chrome.test.callbackPass(function(actualFilesAfter) { |
| 94 chrome.test.assertEq(EXPECTED_FILES_AFTER, actualFilesAfter); | 96 chrome.test.assertEq(EXPECTED_FILES_AFTER, actualFilesAfter); |
| 95 })); | 97 })); |
| 98 }); |
| 96 }); | 99 }); |
| 97 }); | |
| 98 } | 100 } |
| 99 | 101 |
| 100 // Injects the keyboard test code into the file manager tab and runs the | 102 // Injects the keyboard test code into the file manager tab and runs the |
| 101 // keyboard delete test. | 103 // keyboard delete test. |
| 102 function doKeyboardTestWithConfirmation(code) { | 104 function doKeyboardTestWithConfirmation(code) { |
| 103 chrome.tabs.executeScript(null, {file: 'fake_keypress.js'}, function(result) { | 105 // Wait until the file list is rendered. |
| 104 chrome.tabs.executeScript(null, {code: code}, function(result) { | 106 waitForFileListChange( |
| 105 chrome.test.assertFalse(!result[0]); | 107 0, |
| 106 waitAndAcceptDialog(function() { | 108 function(unused) { |
| 107 // Succeed here if anything happens; the C++ code checks what happened. | 109 // Once the file list is rendered, start the keyboard test. |
| 108 waitForFileListChange(EXPECTED_FILES_BEFORE.length, | 110 chrome.tabs.executeScript( |
| 109 chrome.test.succeed); | 111 null, {file: 'fake_keypress.js'}, function(result) { |
| 112 chrome.tabs.executeScript(null, {code: code}, function(result) { |
| 113 chrome.test.assertFalse(!result[0]); |
| 114 waitAndAcceptDialog(function() { |
| 115 // Succeed here if anything happens; the C++ code checks what |
| 116 // happened. |
| 117 waitForFileListChange(EXPECTED_FILES_BEFORE.length, |
| 118 chrome.test.succeed); |
| 119 }); |
| 120 }); |
| 110 }); | 121 }); |
| 111 }); | 122 }); |
| 112 }); | |
| 113 } | 123 } |
| 114 | 124 |
| 115 // Injects the keyboard test code into the file manager tab and runs the | 125 // Injects the keyboard test code into the file manager tab and runs the |
| 116 // keyboard copy test. | 126 // keyboard copy test. |
| 117 function doKeyboardTest(code) { | 127 function doKeyboardTest(code) { |
| 118 chrome.tabs.executeScript(null, {file: 'fake_keypress.js'}, function(result) { | 128 waitForFileListChange( |
| 119 chrome.tabs.executeScript(null, {code: code}, function(result) { | 129 0, |
| 120 chrome.test.assertFalse(!result[0]); | 130 function(unused) { |
| 121 // Succeed here if anything happens; the C++ code checks what happened. | 131 chrome.tabs.executeScript( |
| 122 waitForFileListChange(EXPECTED_FILES_BEFORE.length, chrome.test.succeed); | 132 null, {file: 'fake_keypress.js'}, function(result) { |
| 133 chrome.tabs.executeScript(null, {code: code}, function(result) { |
| 134 chrome.test.assertFalse(!result[0]); |
| 135 // Succeed here if anything happens; the C++ code checks what |
| 136 // happened. |
| 137 waitForFileListChange(EXPECTED_FILES_BEFORE.length, |
| 138 chrome.test.succeed); |
| 139 }); |
| 140 }); |
| 123 }); | 141 }); |
| 124 }); | |
| 125 } | 142 } |
| 126 | 143 |
| 127 chrome.test.runTests([ | 144 chrome.test.runTests([ |
| 128 // Waits for the C++ code to send a string identifying a test, then runs that | 145 // Waits for the C++ code to send a string identifying a test, then runs that |
| 129 // test. | 146 // test. |
| 130 function testRunner() { | 147 function testRunner() { |
| 131 chrome.test.sendMessage('which test', function(reply) { | 148 chrome.test.sendMessage('which test', function(reply) { |
| 132 // These test names are provided by file_manager_browsertest.cc. | 149 // These test names are provided by file_manager_browsertest.cc. |
| 133 if (reply === 'file display') { | 150 if (reply === 'file display') { |
| 134 testFileDisplay(); | 151 testFileDisplay(); |
| 135 } else if (reply === 'keyboard copy') { | 152 } else if (reply === 'keyboard copy') { |
| 136 doKeyboardTest('fakeFileCopy("world.mpeg");'); | 153 doKeyboardTest('fakeFileCopy("world.mpeg");'); |
| 137 } else if (reply === 'keyboard delete') { | 154 } else if (reply === 'keyboard delete') { |
| 138 doKeyboardTestWithConfirmation('fakeFileDelete("world.mpeg");'); | 155 doKeyboardTestWithConfirmation('fakeFileDelete("world.mpeg");'); |
| 139 } else { | 156 } else { |
| 140 chrome.test.fail('Bogus test name passed to testRunner()'); | 157 chrome.test.fail('Bogus test name passed to testRunner()'); |
| 141 } | 158 } |
| 142 }); | 159 }); |
| 143 } | 160 } |
| 144 ]); | 161 ]); |
| OLD | NEW |