Skip to content

Commit

Permalink
Files App: Move reportPromise,waitUntil to //ui/file_manager/base/js/…
Browse files Browse the repository at this point in the history
…test_error_reporting.js

These functions are currently in file_manager/file_manager/common/js/unittest_util.js
which has a lot of files-app specific stuff that media apps shouldn't
depend on.

 - Move MockAPIEvent to the only unittest (in gallery) that uses it.
 - Delete the redundant copy of waitUntil in list_thumbnail_loader_unittest.js
 - Updates the remaining handcrafted foo_unittest.html files in the files app
   * combination sed-script and manual edit.

Bug: 879035
Cq-Include-Trybots: luci.chromium.try:closure_compilation
Change-Id: I7d54cec253384b46d1cdb7c51f8ff0eb9596ebf1
Reviewed-on: https://chromium-review.googlesource.com/c/1275545
Commit-Queue: Trent Apted <[email protected]>
Reviewed-by: Luciano Pacheco <[email protected]>
Cr-Commit-Position: refs/heads/master@{#599115}
  • Loading branch information
tapted authored and Commit Bot committed Oct 12, 2018
1 parent 7d87839 commit e1c3184
Show file tree
Hide file tree
Showing 38 changed files with 171 additions and 168 deletions.
23 changes: 22 additions & 1 deletion ui/file_manager/base/js/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,25 @@ import("//third_party/closure_compiler/compile_js.gni")

visibility = [ "//ui/file_manager/*" ]

js_type_check("closure_compile") {
group("closure_compile") {
deps = [
":closure_compile_module",
":test_support_type_check",
]
}

js_type_check("closure_compile_module") {
deps = [
":filtered_volume_manager",
]
}

js_type_check("test_support_type_check") {
deps = [
":test_error_reporting",
]
}

js_library("filtered_volume_manager") {
deps = [
"//ui/file_manager/externs:file_manager_private",
Expand All @@ -25,3 +38,11 @@ js_library("filtered_volume_manager") {
externs_list =
[ "//ui/file_manager/externs/background/volume_manager_factory.js" ]
}

js_library("test_error_reporting") {
deps = [
# Note we allow targets depending on test_error_reporting to access
# webui_resource_test transitively.
"//ui/webui/resources/js:webui_resource_test",
]
}
42 changes: 42 additions & 0 deletions ui/file_manager/base/js/test_error_reporting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/**
* Invokes a callback function depending on the result of promise.
*
* @param {Promise} promise Promise.
* @param {function(boolean)} callback Callback function. True is passed if the
* test failed.
*/
function reportPromise(promise, callback) {
promise.then(
() => {
callback(/* error */ false);
},
(/** Error */ error) => {
console.error(error.stack || error);
callback(/* error */ true);
});
}

/**
* Waits until testFunction becomes true.
* @param {function(): boolean} testFunction A function which is tested.
* @return {!Promise} A promise which is fulfilled when the testFunction
* becomes true.
*/
function waitUntil(testFunction) {
const INTERVAL_FOR_WAIT_UNTIL = 100; // ms

return new Promise((resolve) => {
let tryTestFunction = () => {
if (testFunction())
resolve();
else
setTimeout(tryTestFunction, INTERVAL_FOR_WAIT_UNTIL);
};

tryTestFunction();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

<!-- Need to load async_util.js before device_handler.js -->
<script src="../../common/js/async_util.js"></script>
<script src="../../../base/js/test_error_reporting.js"></script>
<script src="../../common/js/unittest_util.js"></script>
<script src="../../common/js/mock_entry.js"></script>
<script src="../../common/js/volume_manager_common.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<script src="../../common/js/lru_cache.js"></script>
<script src="../../common/js/mock_entry.js"></script>
<script src="../../common/js/test_tracker.js"></script>
<script src="../../../base/js/test_error_reporting.js"></script>
<script src="../../common/js/unittest_util.js"></script>
<script src="../../common/js/files_app_entry_types.js"></script>
<script src="../../common/js/util.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<script src="../../../../../ui/webui/resources/js/cr/event_target.js"></script>

<script src="../../common/js/async_util.js"></script>
<script src="../../common/js/unittest_util.js"></script>
<script src="../../../base/js/test_error_reporting.js"></script>
<script src="../../common/js/util.js"></script>
<script src="../../common/js/lru_cache.js"></script>
<script src="../../common/js/mock_entry.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<script src="../../common/js/metrics_base.js"></script>
<script src="../../common/js/metrics_events.js"></script>
<script src="../../common/js/mock_entry.js"></script>
<script src="../../../base/js/test_error_reporting.js"></script>
<script src="../../common/js/unittest_util.js"></script>
<script src="../../common/js/util.js"></script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<script src="../../common/js/metrics_base.js"></script>
<script src="../../common/js/metrics_events.js"></script>
<script src="../../common/js/mock_entry.js"></script>
<script src="../../../base/js/test_error_reporting.js"></script>
<script src="../../common/js/unittest_util.js"></script>
<script src="../../common/js/files_app_entry_types.js"></script>
<script src="../../common/js/util.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<script src="../../common/js/lru_cache.js"></script>
<script src="../../common/js/mock_entry.js"></script>
<script src="../../common/js/mock_file_system.js"></script>
<script src="../../../base/js/test_error_reporting.js"></script>
<script src="../../common/js/unittest_util.js"></script>
<script src="../../common/js/util.js"></script>
<script src="metadata_proxy.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<script src="../../common/js/volume_manager_common.js"></script>
<script src="../../common/js/importer_common.js"></script>
<script src="../../common/js/unittest_util.js"></script>
<script src="../../../base/js/test_error_reporting.js"></script>
<script src="task_queue.js"></script>

<script src="task_queue_unittest.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<script src="../../common/js/async_util.js"></script>
<script src="../../common/js/mock_entry.js"></script>
<script src="../../../base/js/test_error_reporting.js"></script>
<script src="../../common/js/unittest_util.js"></script>
<script src="../../common/js/files_app_entry_types.js"></script>
<script src="../../common/js/util.js"></script>
Expand Down
40 changes: 22 additions & 18 deletions ui/file_manager/file_manager/common/js/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import("//third_party/closure_compiler/js_unit_tests.gni")
# TODO(tapted): This entire folder should move to //ui/file_manager/base.
visibility = [ "//ui/file_manager/*" ]

group("closure_compile") {
deps = [
":closure_compile_module",
":test_support_type_check",
":unit_tests_type_check",
]
}

js_type_check("closure_compile_module") {
deps = [
":async_util",
Expand All @@ -21,19 +29,25 @@ js_type_check("closure_compile_module") {
":metrics_events",
":mock_entry",
":progress_center_common",
":unittest_util",
":util",
":volume_manager_common",
]
}

js_type_check("test_support_type_check") {
deps = [
":test_importer_common",
":unittest_util",
]
}

js_library("async_util") {
}

js_library("async_util_unittest") {
deps = [
":async_util",
":unittest_util",
"//ui/file_manager/base/js:test_error_reporting",
]
}

Expand All @@ -50,8 +64,8 @@ js_library("files_app_entry_types") {
js_library("files_app_entry_types_unittest") {
deps = [
":files_app_entry_types",
":unittest_util",
":volume_manager_common",
"//ui/file_manager/base/js:test_error_reporting",
]
}

Expand Down Expand Up @@ -85,6 +99,7 @@ js_library("test_importer_common") {
deps = [
":importer_common",
":unittest_util",
"//ui/file_manager/base/js:test_error_reporting",
]
visibility = []
visibility = [ "//ui/file_manager/file_manager/*" ]
Expand Down Expand Up @@ -141,6 +156,9 @@ js_library("progress_center_common") {
}

js_library("unittest_util") {
# Only files app tests use this util file.
visibility = []
visibility = [ "//ui/file_manager/file_manager/*" ]
deps = [
"//ui/webui/resources/js:webui_resource_test",
]
Expand Down Expand Up @@ -168,8 +186,8 @@ js_library("util") {
js_library("util_unittest") {
deps = [
":mock_entry",
":unittest_util",
":util",
"//ui/file_manager/base/js:test_error_reporting",
]
}

Expand All @@ -188,17 +206,3 @@ js_unit_tests("unit_tests") {
":util_unittest",
]
}

js_type_check("test_support_type_check") {
deps = [
":test_importer_common",
]
}

group("closure_compile") {
deps = [
":closure_compile_module",
":test_support_type_check",
":unit_tests_type_check",
]
}
6 changes: 1 addition & 5 deletions ui/file_manager/file_manager/common/js/metrics_unittest.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@
<script src="../../../../../ui/webui/resources/js/cr/event_target.js"></script>
<script src="../../../../../ui/webui/resources/js/cr/ui/array_data_model.js"></script>
<script src="../../../../../ui/webui/resources/js/load_time_data.js"></script>

<script src="../../../../../third_party/analytics/google-analytics-bundle.js"></script>

<script src="unittest_util.js"></script>
<script src="../../../../file_manager/base/js/test_error_reporting.js"></script>
<script src="util.js"></script>
<script src="metrics_base.js"></script>
<script src="metrics.js"></script>


<script src="metrics_unittest.js"></script>
</body>
</html>
Loading

0 comments on commit e1c3184

Please sign in to comment.