Commit b39f703e authored by David Black's avatar David Black Committed by Commit Bot

Move generic helpers to Assistant test_support.

Bug: b:153496343
Change-Id: I859f09af03f1b93a03202bc3ef913da14c31de72
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2211137
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Reviewed-by: default avatarJeroen Dhollander <jeroendh@google.com>
Cr-Commit-Position: refs/heads/master@{#771306}
parent c46895e0
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/ui/ash/assistant/test/fake_s3_server.h" #include "chrome/browser/ui/ash/assistant/test_support/fake_s3_server.h"
#include "chrome/test/base/mixin_based_in_process_browser_test.h" #include "chrome/test/base/mixin_based_in_process_browser_test.h"
#include "ui/events/keycodes/keyboard_codes_posix.h" #include "ui/events/keycodes/keyboard_codes_posix.h"
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/test/icu_test_util.h" #include "base/test/icu_test_util.h"
#include "chrome/browser/ui/ash/assistant/assistant_test_mixin.h" #include "chrome/browser/ui/ash/assistant/assistant_test_mixin.h"
#include "chrome/browser/ui/ash/assistant/test_support/test_util.h"
#include "chrome/test/base/mixin_based_in_process_browser_test.h" #include "chrome/test/base/mixin_based_in_process_browser_test.h"
#include "chromeos/services/assistant/public/cpp/features.h" #include "chromeos/services/assistant/public/cpp/features.h"
#include "content/public/test/browser_test.h" #include "content/public/test/browser_test.h"
...@@ -62,33 +63,8 @@ constexpr int kVersion = 1; ...@@ -62,33 +63,8 @@ constexpr int kVersion = 1;
run_loop.Run(); \ run_loop.Run(); \
} }
// TODO(b:153496343): Move generic helpers to a more generic location for reuse.
// Helpers --------------------------------------------------------------------- // Helpers ---------------------------------------------------------------------
// Finds any descendents of |parent| with the desired |class_name| and pushes
// them onto the strongly typed |result| vector.
// NOTE: Callers are expected to ensure that casting to <T> makes sense.
template <typename T>
void FindDescendentsOfClass(views::View* parent,
std::string class_name,
std::vector<T*>* result) {
for (auto* child : parent->children()) {
if (child->GetClassName() == class_name)
result->push_back(static_cast<T*>(child));
FindDescendentsOfClass(child, class_name, result);
}
}
// Finds any descendents of |parent| with class name equal to the static class
// variable |kViewClassName| and pushes them onto the strongly typed |result|
// vector.
// NOTE: This variant of FindDescendentsOfClass is safer than the three argument
// variant and its usage should be preferred where possible.
template <typename T>
void FindDescendentsOfClass(views::View* parent, std::vector<T*>* result) {
FindDescendentsOfClass(parent, T::kViewClassName, result);
}
// Returns the status area widget. // Returns the status area widget.
ash::StatusAreaWidget* FindStatusAreaWidget() { ash::StatusAreaWidget* FindStatusAreaWidget() {
return ash::Shelf::ForWindow(ash::Shell::GetRootWindowForNewWindows()) return ash::Shelf::ForWindow(ash::Shell::GetRootWindowForNewWindows())
......
static_library("test_support") {
testonly = true
sources = [
"fake_s3_server.cc",
"fake_s3_server.h",
"test_util.h",
]
deps = [
"//chromeos/assistant/internal:internal",
"//chromeos/services/assistant:lib",
"//testing/gmock",
"//testing/gtest",
"//ui/views:views",
]
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/ui/ash/assistant/test/fake_s3_server.h" #include "chrome/browser/ui/ash/assistant/test_support/fake_s3_server.h"
#include <memory> #include <memory>
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_ASH_ASSISTANT_TEST_FAKE_S3_SERVER_H_ #ifndef CHROME_BROWSER_UI_ASH_ASSISTANT_TEST_SUPPORT_FAKE_S3_SERVER_H_
#define CHROME_BROWSER_UI_ASH_ASSISTANT_TEST_FAKE_S3_SERVER_H_ #define CHROME_BROWSER_UI_ASH_ASSISTANT_TEST_SUPPORT_FAKE_S3_SERVER_H_
#include <memory> #include <memory>
#include <string> #include <string>
...@@ -76,4 +76,4 @@ class FakeS3Server { ...@@ -76,4 +76,4 @@ class FakeS3Server {
} // namespace assistant } // namespace assistant
} // namespace chromeos } // namespace chromeos
#endif // CHROME_BROWSER_UI_ASH_ASSISTANT_TEST_FAKE_S3_SERVER_H_ #endif // CHROME_BROWSER_UI_ASH_ASSISTANT_TEST_SUPPORT_FAKE_S3_SERVER_H_
// Copyright 2020 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.
#ifndef CHROME_BROWSER_UI_ASH_ASSISTANT_TEST_SUPPORT_TEST_UTIL_H_
#define CHROME_BROWSER_UI_ASH_ASSISTANT_TEST_SUPPORT_TEST_UTIL_H_
#include <string>
#include <vector>
#include "ui/views/view.h"
namespace chromeos {
namespace assistant {
// Finds any descendents of |parent| with the desired |class_name| and pushes
// them onto the strongly typed |result| vector.
// NOTE: Callers are expected to ensure that casting to <T> makes sense. It is
// preferred to use the two argument variant of FindDescendentsOfClass() when
// possible for stronger type safety.
template <typename T>
void FindDescendentsOfClass(views::View* parent,
const std::string& class_name,
std::vector<T*>* result) {
for (auto* child : parent->children()) {
if (child->GetClassName() == class_name)
result->push_back(static_cast<T*>(child));
FindDescendentsOfClass(child, class_name, result);
}
}
// Finds any descendents of |parent| with class name equal to the static class
// variable |kViewClassName| and pushes them onto the strongly typed |result|
// vector.
// NOTE: This variant of FindDescendentsOfClass() is safer than the three
// argument variant and its usage should be preferred where possible.
template <typename T>
void FindDescendentsOfClass(views::View* parent, std::vector<T*>* result) {
FindDescendentsOfClass(parent, T::kViewClassName, result);
}
} // namespace assistant
} // namespace chromeos
#endif // CHROME_BROWSER_UI_ASH_ASSISTANT_TEST_SUPPORT_TEST_UTIL_H_
...@@ -2478,11 +2478,12 @@ if (!is_android) { ...@@ -2478,11 +2478,12 @@ if (!is_android) {
"../browser/ui/ash/assistant/assistant_test_mixin.h", "../browser/ui/ash/assistant/assistant_test_mixin.h",
"../browser/ui/ash/assistant/assistant_timers_browsertest.cc", "../browser/ui/ash/assistant/assistant_timers_browsertest.cc",
"../browser/ui/ash/assistant/assistant_web_view_impl_browsertest.cc", "../browser/ui/ash/assistant/assistant_web_view_impl_browsertest.cc",
"../browser/ui/ash/assistant/test/fake_s3_server.cc",
"../browser/ui/ash/assistant/test/fake_s3_server.h",
] ]
deps += [ "//chromeos/assistant/internal:internal" ] deps += [
"//chrome/browser/ui/ash/assistant/test_support",
"//chromeos/assistant/internal:internal",
]
data += [ "//chromeos/assistant/internal/test_data/" ] data += [ "//chromeos/assistant/internal/test_data/" ]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment