Remove unused android files
Change-Id: I64d12853c00480a0525eb3831018bc4e143932ab
Reviewed-on: https://gn-review.googlesource.com/1406
Reviewed-by: Brett Wilson <brettw@chromium.org>
Commit-Queue: Scott Graham <scottmg@chromium.org>
diff --git a/base/base_paths_android.cc b/base/base_paths_android.cc
deleted file mode 100644
index 078f565..0000000
--- a/base/base_paths_android.cc
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright (c) 2012 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.
-
-// Defines base::PathProviderAndroid which replaces base::PathProviderPosix for
-// Android in base/path_service.cc.
-
-#include <limits.h>
-#include <unistd.h>
-
-#include "base/android/jni_android.h"
-#include "base/android/path_utils.h"
-#include "base/base_paths.h"
-#include "base/files/file_path.h"
-#include "base/files/file_util.h"
-#include "base/logging.h"
-#include "base/process/process_metrics.h"
-
-namespace base {
-
-bool PathProviderAndroid(int key, FilePath* result) {
- switch (key) {
- case base::FILE_EXE: {
- FilePath bin_dir;
- if (!ReadSymbolicLink(FilePath(kProcSelfExe), &bin_dir)) {
- NOTREACHED() << "Unable to resolve " << kProcSelfExe << ".";
- return false;
- }
- *result = bin_dir;
- return true;
- }
- case base::FILE_MODULE:
- // dladdr didn't work in Android as only the file name was returned.
- NOTIMPLEMENTED();
- return false;
- case base::DIR_MODULE:
- return base::android::GetNativeLibraryDirectory(result);
- case base::DIR_SOURCE_ROOT:
- // Used only by tests.
- // In that context, hooked up via base/test/test_support_android.cc.
- NOTIMPLEMENTED();
- return false;
- case base::DIR_USER_DESKTOP:
- // Android doesn't support GetUserDesktop.
- NOTIMPLEMENTED();
- return false;
- case base::DIR_CACHE:
- return base::android::GetCacheDirectory(result);
- case base::DIR_ASSETS:
- // On Android assets are normally loaded from the APK using
- // base::android::OpenApkAsset(). In tests, since the assets are no
- // packaged, DIR_ASSETS is overridden to point to the build directory.
- return false;
- case base::DIR_ANDROID_APP_DATA:
- return base::android::GetDataDirectory(result);
- case base::DIR_ANDROID_EXTERNAL_STORAGE:
- return base::android::GetExternalStorageDirectory(result);
- default:
- // Note: the path system expects this function to override the default
- // behavior. So no need to log an error if we don't support a given
- // path. The system will just use the default.
- return false;
- }
-}
-
-} // namespace base
diff --git a/base/base_paths_android.h b/base/base_paths_android.h
deleted file mode 100644
index 7a9ac4a..0000000
--- a/base/base_paths_android.h
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright (c) 2012 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 BASE_BASE_PATHS_ANDROID_H_
-#define BASE_BASE_PATHS_ANDROID_H_
-
-// This file declares Android-specific path keys for the base module.
-// These can be used with the PathService to access various special
-// directories and files.
-
-namespace base {
-
-enum {
- PATH_ANDROID_START = 300,
-
- DIR_ANDROID_APP_DATA, // Directory where to put Android app's data.
- DIR_ANDROID_EXTERNAL_STORAGE, // Android external storage directory.
-
- PATH_ANDROID_END
-};
-
-} // namespace base
-
-#endif // BASE_BASE_PATHS_ANDROID_H_
diff --git a/base/debug/stack_trace_android.cc b/base/debug/stack_trace_android.cc
deleted file mode 100644
index 329204c..0000000
--- a/base/debug/stack_trace_android.cc
+++ /dev/null
@@ -1,134 +0,0 @@
-// Copyright (c) 2012 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.
-
-#include "base/debug/stack_trace.h"
-
-#include <android/log.h>
-#include <stddef.h>
-#include <unwind.h>
-
-#include <algorithm>
-#include <ostream>
-
-#include "base/debug/proc_maps_linux.h"
-#include "base/strings/stringprintf.h"
-#include "base/threading/thread_restrictions.h"
-
-#ifdef __LP64__
-#define FMT_ADDR "0x%016lx"
-#else
-#define FMT_ADDR "0x%08x"
-#endif
-
-namespace {
-
-struct StackCrawlState {
- StackCrawlState(uintptr_t* frames, size_t max_depth)
- : frames(frames),
- frame_count(0),
- max_depth(max_depth),
- have_skipped_self(false) {}
-
- uintptr_t* frames;
- size_t frame_count;
- size_t max_depth;
- bool have_skipped_self;
-};
-
-_Unwind_Reason_Code TraceStackFrame(_Unwind_Context* context, void* arg) {
- StackCrawlState* state = static_cast<StackCrawlState*>(arg);
- uintptr_t ip = _Unwind_GetIP(context);
-
- // The first stack frame is this function itself. Skip it.
- if (ip != 0 && !state->have_skipped_self) {
- state->have_skipped_self = true;
- return _URC_NO_REASON;
- }
-
- state->frames[state->frame_count++] = ip;
- if (state->frame_count >= state->max_depth)
- return _URC_END_OF_STACK;
- return _URC_NO_REASON;
-}
-
-} // namespace
-
-namespace base {
-namespace debug {
-
-bool EnableInProcessStackDumping() {
- // When running in an application, our code typically expects SIGPIPE
- // to be ignored. Therefore, when testing that same code, it should run
- // with SIGPIPE ignored as well.
- // TODO(phajdan.jr): De-duplicate this SIGPIPE code.
- struct sigaction action;
- memset(&action, 0, sizeof(action));
- action.sa_handler = SIG_IGN;
- sigemptyset(&action.sa_mask);
- return (sigaction(SIGPIPE, &action, NULL) == 0);
-}
-
-StackTrace::StackTrace(size_t count) {
- count = std::min(arraysize(trace_), count);
-
- StackCrawlState state(reinterpret_cast<uintptr_t*>(trace_), count);
- _Unwind_Backtrace(&TraceStackFrame, &state);
- count_ = state.frame_count;
-}
-
-void StackTrace::Print() const {
- std::string backtrace = ToString();
- __android_log_write(ANDROID_LOG_ERROR, "chromium", backtrace.c_str());
-}
-
-// NOTE: Native libraries in APKs are stripped before installing. Print out the
-// relocatable address and library names so host computers can use tools to
-// symbolize and demangle (e.g., addr2line, c++filt).
-void StackTrace::OutputToStream(std::ostream* os) const {
- std::string proc_maps;
- std::vector<MappedMemoryRegion> regions;
- // Allow IO to read /proc/self/maps. Reading this file doesn't hit the disk
- // since it lives in procfs, and this is currently used to print a stack trace
- // on fatal log messages in debug builds only. If the restriction is enabled
- // then it will recursively trigger fatal failures when this enters on the
- // UI thread.
- base::ThreadRestrictions::ScopedAllowIO allow_io;
- if (!ReadProcMaps(&proc_maps)) {
- __android_log_write(
- ANDROID_LOG_ERROR, "chromium", "Failed to read /proc/self/maps");
- } else if (!ParseProcMaps(proc_maps, ®ions)) {
- __android_log_write(
- ANDROID_LOG_ERROR, "chromium", "Failed to parse /proc/self/maps");
- }
-
- for (size_t i = 0; i < count_; ++i) {
- // Subtract one as return address of function may be in the next
- // function when a function is annotated as noreturn.
- uintptr_t address = reinterpret_cast<uintptr_t>(trace_[i]) - 1;
-
- std::vector<MappedMemoryRegion>::iterator iter = regions.begin();
- while (iter != regions.end()) {
- if (address >= iter->start && address < iter->end &&
- !iter->path.empty()) {
- break;
- }
- ++iter;
- }
-
- *os << base::StringPrintf("#%02zd " FMT_ADDR " ", i, address);
-
- if (iter != regions.end()) {
- uintptr_t rel_pc = address - iter->start + iter->offset;
- const char* path = iter->path.c_str();
- *os << base::StringPrintf("%s+" FMT_ADDR, path, rel_pc);
- } else {
- *os << "<unknown>";
- }
-
- *os << "\n";
- }
-}
-
-} // namespace debug
-} // namespace base
diff --git a/base/files/file_util_android.cc b/base/files/file_util_android.cc
deleted file mode 100644
index b8b3b37..0000000
--- a/base/files/file_util_android.cc
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright (c) 2012 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.
-
-#include "base/files/file_util.h"
-
-#include "base/files/file_path.h"
-#include "base/path_service.h"
-
-namespace base {
-
-bool GetShmemTempDir(bool executable, base::FilePath* path) {
- return PathService::Get(base::DIR_CACHE, path);
-}
-
-} // namespace base
diff --git a/base/memory/platform_shared_memory_region_android.cc b/base/memory/platform_shared_memory_region_android.cc
deleted file mode 100644
index 664d3d4..0000000
--- a/base/memory/platform_shared_memory_region_android.cc
+++ /dev/null
@@ -1,190 +0,0 @@
-// 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.
-
-#include "base/memory/platform_shared_memory_region.h"
-
-#include <sys/mman.h>
-
-#include "base/memory/shared_memory_tracker.h"
-#include "base/posix/eintr_wrapper.h"
-#include "third_party/ashmem/ashmem.h"
-
-namespace base {
-namespace subtle {
-
-// For Android, we use ashmem to implement SharedMemory. ashmem_create_region
-// will automatically pin the region. We never explicitly call pin/unpin. When
-// all the file descriptors from different processes associated with the region
-// are closed, the memory buffer will go away.
-
-namespace {
-
-static int GetAshmemRegionProtectionMask(int fd) {
- int prot = ashmem_get_prot_region(fd);
- if (prot < 0) {
- DPLOG(ERROR) << "ashmem_get_prot_region failed";
- return -1;
- }
- return prot;
-}
-
-} // namespace
-
-// static
-PlatformSharedMemoryRegion PlatformSharedMemoryRegion::Take(
- ScopedFD fd,
- Mode mode,
- size_t size,
- const UnguessableToken& guid) {
- if (!fd.is_valid())
- return {};
-
- if (size == 0)
- return {};
-
- if (size > static_cast<size_t>(std::numeric_limits<int>::max()))
- return {};
-
- CHECK(CheckPlatformHandlePermissionsCorrespondToMode(fd.get(), mode, size));
-
- return PlatformSharedMemoryRegion(std::move(fd), mode, size, guid);
-}
-
-int PlatformSharedMemoryRegion::GetPlatformHandle() const {
- return handle_.get();
-}
-
-bool PlatformSharedMemoryRegion::IsValid() const {
- return handle_.is_valid();
-}
-
-PlatformSharedMemoryRegion PlatformSharedMemoryRegion::Duplicate() const {
- if (!IsValid())
- return {};
-
- CHECK_NE(mode_, Mode::kWritable)
- << "Duplicating a writable shared memory region is prohibited";
-
- ScopedFD duped_fd(HANDLE_EINTR(dup(handle_.get())));
- if (!duped_fd.is_valid()) {
- DPLOG(ERROR) << "dup(" << handle_.get() << ") failed";
- return {};
- }
-
- return PlatformSharedMemoryRegion(std::move(duped_fd), mode_, size_, guid_);
-}
-
-bool PlatformSharedMemoryRegion::ConvertToReadOnly() {
- if (!IsValid())
- return false;
-
- CHECK_EQ(mode_, Mode::kWritable)
- << "Only writable shared memory region can be converted to read-only";
-
- ScopedFD handle_copy(handle_.release());
-
- int prot = GetAshmemRegionProtectionMask(handle_copy.get());
- if (prot < 0)
- return false;
-
- prot &= ~PROT_WRITE;
- int ret = ashmem_set_prot_region(handle_copy.get(), prot);
- if (ret != 0) {
- DPLOG(ERROR) << "ashmem_set_prot_region failed";
- return false;
- }
-
- handle_ = std::move(handle_copy);
- mode_ = Mode::kReadOnly;
- return true;
-}
-
-bool PlatformSharedMemoryRegion::MapAt(off_t offset,
- size_t size,
- void** memory,
- size_t* mapped_size) const {
- if (!IsValid())
- return false;
-
- size_t end_byte;
- if (!CheckAdd(offset, size).AssignIfValid(&end_byte) || end_byte > size_) {
- return false;
- }
-
- bool write_allowed = mode_ != Mode::kReadOnly;
- *memory = mmap(nullptr, size, PROT_READ | (write_allowed ? PROT_WRITE : 0),
- MAP_SHARED, handle_.get(), offset);
-
- bool mmap_succeeded = *memory && *memory != reinterpret_cast<void*>(-1);
- if (!mmap_succeeded) {
- DPLOG(ERROR) << "mmap " << handle_.get() << " failed";
- return false;
- }
-
- *mapped_size = size;
- DCHECK_EQ(0U,
- reinterpret_cast<uintptr_t>(*memory) & (kMapMinimumAlignment - 1));
- return true;
-}
-
-// static
-PlatformSharedMemoryRegion PlatformSharedMemoryRegion::Create(Mode mode,
- size_t size) {
- if (size == 0)
- return {};
-
- if (size > static_cast<size_t>(std::numeric_limits<int>::max()))
- return {};
-
- CHECK_NE(mode, Mode::kReadOnly) << "Creating a region in read-only mode will "
- "lead to this region being non-modifiable";
-
- UnguessableToken guid = UnguessableToken::Create();
-
- ScopedFD fd(ashmem_create_region(
- SharedMemoryTracker::GetDumpNameForTracing(guid).c_str(), size));
- if (!fd.is_valid()) {
- DPLOG(ERROR) << "ashmem_create_region failed";
- return {};
- }
-
- int err = ashmem_set_prot_region(fd.get(), PROT_READ | PROT_WRITE);
- if (err < 0) {
- DPLOG(ERROR) << "ashmem_set_prot_region failed";
- return {};
- }
-
- return PlatformSharedMemoryRegion(std::move(fd), mode, size, guid);
-}
-
-bool PlatformSharedMemoryRegion::CheckPlatformHandlePermissionsCorrespondToMode(
- PlatformHandle handle,
- Mode mode,
- size_t size) {
- int prot = GetAshmemRegionProtectionMask(handle);
- if (prot < 0)
- return false;
-
- bool is_read_only = (prot & PROT_WRITE) == 0;
- bool expected_read_only = mode == Mode::kReadOnly;
-
- if (is_read_only != expected_read_only) {
- DLOG(ERROR) << "Ashmem region has a wrong protection mask: it is"
- << (is_read_only ? " " : " not ") << "read-only but it should"
- << (expected_read_only ? " " : " not ") << "be";
- return false;
- }
-
- return true;
-}
-
-PlatformSharedMemoryRegion::PlatformSharedMemoryRegion(
- ScopedFD fd,
- Mode mode,
- size_t size,
- const UnguessableToken& guid)
- : handle_(std::move(fd)), mode_(mode), size_(size), guid_(guid) {}
-
-} // namespace subtle
-} // namespace base
diff --git a/base/memory/shared_memory_android.cc b/base/memory/shared_memory_android.cc
deleted file mode 100644
index c126767..0000000
--- a/base/memory/shared_memory_android.cc
+++ /dev/null
@@ -1,75 +0,0 @@
-// Copyright (c) 2011 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.
-
-#include "base/memory/shared_memory.h"
-
-#include <stddef.h>
-#include <sys/mman.h>
-
-#include "base/logging.h"
-#include "third_party/ashmem/ashmem.h"
-
-namespace base {
-
-// For Android, we use ashmem to implement SharedMemory. ashmem_create_region
-// will automatically pin the region. We never explicitly call pin/unpin. When
-// all the file descriptors from different processes associated with the region
-// are closed, the memory buffer will go away.
-
-bool SharedMemory::Create(const SharedMemoryCreateOptions& options) {
- DCHECK(!shm_.IsValid());
-
- if (options.size > static_cast<size_t>(std::numeric_limits<int>::max()))
- return false;
-
- // "name" is just a label in ashmem. It is visible in /proc/pid/maps.
- int fd = ashmem_create_region(
- options.name_deprecated ? options.name_deprecated->c_str() : "",
- options.size);
- shm_ = SharedMemoryHandle::ImportHandle(fd, options.size);
- if (!shm_.IsValid()) {
- DLOG(ERROR) << "Shared memory creation failed";
- return false;
- }
-
- int flags = PROT_READ | PROT_WRITE | (options.executable ? PROT_EXEC : 0);
- int err = ashmem_set_prot_region(shm_.GetHandle(), flags);
- if (err < 0) {
- DLOG(ERROR) << "Error " << err << " when setting protection of ashmem";
- return false;
- }
-
- requested_size_ = options.size;
-
- return true;
-}
-
-bool SharedMemory::Delete(const std::string& name) {
- // Like on Windows, this is intentionally returning true as ashmem will
- // automatically releases the resource when all FDs on it are closed.
- return true;
-}
-
-bool SharedMemory::Open(const std::string& name, bool read_only) {
- // ashmem doesn't support name mapping
- NOTIMPLEMENTED();
- return false;
-}
-
-void SharedMemory::Close() {
- if (shm_.IsValid()) {
- shm_.Close();
- shm_ = SharedMemoryHandle();
- }
-}
-
-SharedMemoryHandle SharedMemory::GetReadOnlyHandle() const {
- // There are no read-only Ashmem descriptors on Android.
- // Instead, the protection mask is a property of the region itself.
- SharedMemoryHandle handle = shm_.Duplicate();
- handle.SetReadOnly();
- return handle;
-}
-
-} // namespace base
diff --git a/base/memory/shared_memory_handle_android.cc b/base/memory/shared_memory_handle_android.cc
deleted file mode 100644
index 1b61535..0000000
--- a/base/memory/shared_memory_handle_android.cc
+++ /dev/null
@@ -1,115 +0,0 @@
-// Copyright 2017 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.
-
-#include "base/memory/shared_memory_handle.h"
-
-#include <sys/mman.h>
-#include <unistd.h>
-
-#include "base/logging.h"
-#include "base/posix/eintr_wrapper.h"
-#include "base/posix/unix_domain_socket.h"
-#include "base/unguessable_token.h"
-#include "third_party/ashmem/ashmem.h"
-
-namespace base {
-
-static int GetAshmemRegionProtectionMask(int fd) {
- int prot = ashmem_get_prot_region(fd);
- if (prot < 0) {
- DPLOG(ERROR) << "ashmem_get_prot_region";
- return -1;
- }
- return prot;
-}
-
-SharedMemoryHandle::SharedMemoryHandle() = default;
-
-SharedMemoryHandle::SharedMemoryHandle(
- const base::FileDescriptor& file_descriptor,
- size_t size,
- const base::UnguessableToken& guid)
- : guid_(guid), size_(size) {
- DCHECK_GE(file_descriptor.fd, 0);
- file_descriptor_ = file_descriptor;
-}
-
-// static
-SharedMemoryHandle SharedMemoryHandle::ImportHandle(int fd, size_t size) {
- SharedMemoryHandle handle;
- handle.file_descriptor_.fd = fd;
- handle.file_descriptor_.auto_close = false;
- handle.guid_ = UnguessableToken::Create();
- handle.size_ = size;
- return handle;
-}
-
-int SharedMemoryHandle::GetHandle() const {
- DCHECK(IsValid());
- return file_descriptor_.fd;
-}
-
-bool SharedMemoryHandle::IsValid() const {
- return file_descriptor_.fd >= 0;
-}
-
-void SharedMemoryHandle::Close() const {
- DCHECK(IsValid());
- if (IGNORE_EINTR(close(file_descriptor_.fd)) < 0)
- PLOG(ERROR) << "close";
-}
-
-int SharedMemoryHandle::Release() {
- int old_fd = file_descriptor_.fd;
- file_descriptor_.fd = -1;
- return old_fd;
-}
-
-SharedMemoryHandle SharedMemoryHandle::Duplicate() const {
- DCHECK(IsValid());
- SharedMemoryHandle result;
- int duped_handle = HANDLE_EINTR(dup(file_descriptor_.fd));
- if (duped_handle >= 0) {
- result = SharedMemoryHandle(FileDescriptor(duped_handle, true), GetSize(),
- GetGUID());
- if (IsReadOnly())
- result.SetReadOnly();
- }
- return result;
-}
-
-void SharedMemoryHandle::SetOwnershipPassesToIPC(bool ownership_passes) {
- file_descriptor_.auto_close = ownership_passes;
-}
-
-bool SharedMemoryHandle::OwnershipPassesToIPC() const {
- return file_descriptor_.auto_close;
-}
-
-bool SharedMemoryHandle::IsRegionReadOnly() const {
- int prot = GetAshmemRegionProtectionMask(file_descriptor_.fd);
- return (prot >= 0 && (prot & PROT_WRITE) == 0);
-}
-
-bool SharedMemoryHandle::SetRegionReadOnly() const {
- int fd = file_descriptor_.fd;
- int prot = GetAshmemRegionProtectionMask(fd);
- if (prot < 0)
- return false;
-
- if ((prot & PROT_WRITE) == 0) {
- // Region is already read-only.
- return true;
- }
-
- prot &= ~PROT_WRITE;
- int ret = ashmem_set_prot_region(fd, prot);
- if (ret != 0) {
- DPLOG(ERROR) << "ashmem_set_prot_region";
- return false;
- }
- return true;
-}
-
-} // namespace base
diff --git a/base/message_loop/message_pump_android.cc b/base/message_loop/message_pump_android.cc
deleted file mode 100644
index 8c5bb57..0000000
--- a/base/message_loop/message_pump_android.cc
+++ /dev/null
@@ -1,165 +0,0 @@
-// Copyright (c) 2012 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.
-
-#include "base/message_loop/message_pump_android.h"
-
-#include <jni.h>
-
-#include "base/android/jni_android.h"
-#include "base/android/scoped_java_ref.h"
-#include "base/lazy_instance.h"
-#include "base/logging.h"
-#include "base/run_loop.h"
-#include "jni/SystemMessageHandler_jni.h"
-
-using base::android::JavaParamRef;
-using base::android::ScopedJavaLocalRef;
-
-namespace base {
-
-MessagePumpForUI::MessagePumpForUI() = default;
-MessagePumpForUI::~MessagePumpForUI() = default;
-
-// This is called by the java SystemMessageHandler whenever the message queue
-// detects an idle state (as in, control returns to the looper and there are no
-// tasks available to be run immediately).
-// See the comments in DoRunLoopOnce for how this differs from the
-// implementation on other platforms.
-void MessagePumpForUI::DoIdleWork(JNIEnv* env,
- const JavaParamRef<jobject>& obj) {
- delegate_->DoIdleWork();
-}
-
-void MessagePumpForUI::DoRunLoopOnce(JNIEnv* env,
- const JavaParamRef<jobject>& obj,
- jboolean delayed) {
- if (delayed)
- delayed_scheduled_time_ = base::TimeTicks();
-
- // If the pump has been aborted, tasks may continue to be queued up, but
- // shouldn't run.
- if (ShouldAbort())
- return;
-
- // This is based on MessagePumpForUI::DoRunLoop() from desktop.
- // Note however that our system queue is handled in the java side.
- // In desktop we inspect and process a single system message and then
- // we call DoWork() / DoDelayedWork(). This is then wrapped in a for loop and
- // repeated until no work is left to do, at which point DoIdleWork is called.
- // On Android, the java message queue may contain messages for other handlers
- // that will be processed before calling here again.
- // This means that unlike Desktop, we can't wrap a for loop around this
- // function and keep processing tasks until we have no work left to do - we
- // have to return control back to the Android Looper after each message. This
- // also means we have to perform idle detection differently, which is why we
- // add an IdleHandler to the message queue in SystemMessageHandler.java, which
- // calls DoIdleWork whenever control returns back to the looper and there are
- // no tasks queued up to run immediately.
- delegate_->DoWork();
- if (ShouldAbort()) {
- // There is a pending JNI exception, return to Java so that the exception is
- // thrown correctly.
- return;
- }
-
- base::TimeTicks next_delayed_work_time;
- delegate_->DoDelayedWork(&next_delayed_work_time);
- if (ShouldAbort()) {
- // There is a pending JNI exception, return to Java so that the exception is
- // thrown correctly
- return;
- }
-
- if (!next_delayed_work_time.is_null())
- ScheduleDelayedWork(next_delayed_work_time);
-}
-
-void MessagePumpForUI::Run(Delegate* delegate) {
- NOTREACHED() << "UnitTests should rely on MessagePumpForUIStub in"
- " test_stub_android.h";
-}
-
-void MessagePumpForUI::Start(Delegate* delegate) {
- DCHECK(!quit_);
- delegate_ = delegate;
- run_loop_ = std::make_unique<RunLoop>();
- // Since the RunLoop was just created above, BeforeRun should be guaranteed to
- // return true (it only returns false if the RunLoop has been Quit already).
- if (!run_loop_->BeforeRun())
- NOTREACHED();
-
- DCHECK(system_message_handler_obj_.is_null());
-
- JNIEnv* env = base::android::AttachCurrentThread();
- DCHECK(env);
- system_message_handler_obj_.Reset(
- Java_SystemMessageHandler_create(env, reinterpret_cast<jlong>(this)));
-}
-
-void MessagePumpForUI::Quit() {
- quit_ = true;
-
- if (!system_message_handler_obj_.is_null()) {
- JNIEnv* env = base::android::AttachCurrentThread();
- DCHECK(env);
-
- Java_SystemMessageHandler_shutdown(env, system_message_handler_obj_);
- system_message_handler_obj_.Reset();
- }
-
- if (run_loop_) {
- run_loop_->AfterRun();
- run_loop_ = nullptr;
- }
-}
-
-void MessagePumpForUI::ScheduleWork() {
- if (quit_)
- return;
- DCHECK(!system_message_handler_obj_.is_null());
-
- JNIEnv* env = base::android::AttachCurrentThread();
- DCHECK(env);
-
- Java_SystemMessageHandler_scheduleWork(env, system_message_handler_obj_);
-}
-
-void MessagePumpForUI::ScheduleDelayedWork(const TimeTicks& delayed_work_time) {
- if (quit_)
- return;
- // In the java side, |SystemMessageHandler| keeps a single "delayed" message.
- // It's an expensive operation to |removeMessage| there, so this is optimized
- // to avoid those calls.
- //
- // At this stage, |delayed_work_time| can be:
- // 1) The same as previously scheduled: nothing to be done, move along. This
- // is the typical case, since this method is called for every single message.
- //
- // 2) Not previously scheduled: just post a new message in java.
- //
- // 3) Shorter than previously scheduled: far less common. In this case,
- // |removeMessage| and post a new one.
- //
- // 4) Longer than previously scheduled (or null): nothing to be done, move
- // along.
- if (!delayed_scheduled_time_.is_null() &&
- delayed_work_time >= delayed_scheduled_time_) {
- return;
- }
- DCHECK(!delayed_work_time.is_null());
- DCHECK(!system_message_handler_obj_.is_null());
-
- JNIEnv* env = base::android::AttachCurrentThread();
- DCHECK(env);
-
- jlong millis =
- (delayed_work_time - TimeTicks::Now()).InMillisecondsRoundedUp();
- delayed_scheduled_time_ = delayed_work_time;
- // Note that we're truncating to milliseconds as required by the java side,
- // even though delayed_work_time is microseconds resolution.
- Java_SystemMessageHandler_scheduleDelayedWork(
- env, system_message_handler_obj_, millis);
-}
-
-} // namespace base
diff --git a/base/message_loop/message_pump_android.h b/base/message_loop/message_pump_android.h
deleted file mode 100644
index d09fdde..0000000
--- a/base/message_loop/message_pump_android.h
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright (c) 2012 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 BASE_MESSAGE_LOOP_MESSAGE_PUMP_ANDROID_H_
-#define BASE_MESSAGE_LOOP_MESSAGE_PUMP_ANDROID_H_
-
-#include <jni.h>
-#include <memory>
-
-#include "base/android/scoped_java_ref.h"
-#include "base/base_export.h"
-#include "base/compiler_specific.h"
-#include "base/macros.h"
-#include "base/message_loop/message_pump.h"
-#include "base/time/time.h"
-
-namespace base {
-
-class RunLoop;
-
-// This class implements a MessagePump needed for TYPE_UI MessageLoops on
-// OS_ANDROID platform.
-class BASE_EXPORT MessagePumpForUI : public MessagePump {
- public:
- MessagePumpForUI();
- ~MessagePumpForUI() override;
-
- void DoIdleWork(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj);
- void DoRunLoopOnce(JNIEnv* env,
- const base::android::JavaParamRef<jobject>& obj,
- jboolean delayed);
-
- void Run(Delegate* delegate) override;
- void Quit() override;
- void ScheduleWork() override;
- void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override;
-
- virtual void Start(Delegate* delegate);
-
- // We call Abort when there is a pending JNI exception, meaning that the
- // current thread will crash when we return to Java.
- // We can't call any JNI-methods before returning to Java as we would then
- // cause a native crash (instead of the original Java crash).
- void Abort() { should_abort_ = true; }
- bool ShouldAbort() const { return should_abort_; }
-
- private:
- std::unique_ptr<RunLoop> run_loop_;
- base::android::ScopedJavaGlobalRef<jobject> system_message_handler_obj_;
- bool should_abort_ = false;
- bool quit_ = false;
- Delegate* delegate_ = nullptr;
- base::TimeTicks delayed_scheduled_time_;
-
- DISALLOW_COPY_AND_ASSIGN(MessagePumpForUI);
-};
-
-} // namespace base
-
-#endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_ANDROID_H_
diff --git a/base/os_compat_android.cc b/base/os_compat_android.cc
deleted file mode 100644
index c1a2ac8..0000000
--- a/base/os_compat_android.cc
+++ /dev/null
@@ -1,178 +0,0 @@
-// Copyright (c) 2012 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.
-
-#include "base/os_compat_android.h"
-
-#include <asm/unistd.h>
-#include <errno.h>
-#include <limits.h>
-#include <math.h>
-#include <sys/stat.h>
-#include <sys/syscall.h>
-#include <unistd.h>
-
-#if !defined(__LP64__)
-#include <time64.h>
-#endif
-
-#include "base/rand_util.h"
-#include "base/strings/string_piece.h"
-#include "base/strings/stringprintf.h"
-
-extern "C" {
-// There is no futimes() avaiable in Bionic, so we provide our own
-// implementation until it is there.
-int futimes(int fd, const struct timeval tv[2]) {
- if (tv == NULL)
- return syscall(__NR_utimensat, fd, NULL, NULL, 0);
-
- if (tv[0].tv_usec < 0 || tv[0].tv_usec >= 1000000 ||
- tv[1].tv_usec < 0 || tv[1].tv_usec >= 1000000) {
- errno = EINVAL;
- return -1;
- }
-
- // Convert timeval to timespec.
- struct timespec ts[2];
- ts[0].tv_sec = tv[0].tv_sec;
- ts[0].tv_nsec = tv[0].tv_usec * 1000;
- ts[1].tv_sec = tv[1].tv_sec;
- ts[1].tv_nsec = tv[1].tv_usec * 1000;
- return syscall(__NR_utimensat, fd, NULL, ts, 0);
-}
-
-#if !defined(__LP64__)
-// 32-bit Android has only timegm64() and not timegm().
-// We replicate the behaviour of timegm() when the result overflows time_t.
-time_t timegm(struct tm* const t) {
- // time_t is signed on Android.
- static const time_t kTimeMax = ~(1L << (sizeof(time_t) * CHAR_BIT - 1));
- static const time_t kTimeMin = (1L << (sizeof(time_t) * CHAR_BIT - 1));
- time64_t result = timegm64(t);
- if (result < kTimeMin || result > kTimeMax)
- return -1;
- return result;
-}
-#endif
-
-// The following is only needed when building with GCC 4.6 or higher
-// (i.e. not with Android GCC 4.4.3, nor with Clang).
-//
-// GCC is now capable of optimizing successive calls to sin() and cos() into
-// a single call to sincos(). This means that source code that looks like:
-//
-// double c, s;
-// c = cos(angle);
-// s = sin(angle);
-//
-// Will generate machine code that looks like:
-//
-// double c, s;
-// sincos(angle, &s, &c);
-//
-// Unfortunately, sincos() and friends are not part of the Android libm.so
-// library provided by the NDK for API level 9. When the optimization kicks
-// in, it makes the final build fail with a puzzling message (puzzling
-// because 'sincos' doesn't appear anywhere in the sources!).
-//
-// To solve this, we provide our own implementation of the sincos() function
-// and related friends. Note that we must also explicitely tell GCC to disable
-// optimizations when generating these. Otherwise, the generated machine code
-// for each function would simply end up calling itself, resulting in a
-// runtime crash due to stack overflow.
-//
-#if defined(__GNUC__) && !defined(__clang__) && \
- !defined(ANDROID_SINCOS_PROVIDED)
-
-// For the record, Clang does not support the 'optimize' attribute.
-// In the unlikely event that it begins performing this optimization too,
-// we'll have to find a different way to achieve this. NOTE: Tested with O1
-// which still performs the optimization.
-//
-#define GCC_NO_OPTIMIZE __attribute__((optimize("O0")))
-
-GCC_NO_OPTIMIZE
-void sincos(double angle, double* s, double *c) {
- *c = cos(angle);
- *s = sin(angle);
-}
-
-GCC_NO_OPTIMIZE
-void sincosf(float angle, float* s, float* c) {
- *c = cosf(angle);
- *s = sinf(angle);
-}
-
-#endif // __GNUC__ && !__clang__
-
-// An implementation of mkdtemp, since it is not exposed by the NDK
-// for native API level 9 that we target.
-//
-// For any changes in the mkdtemp function, you should manually run the unittest
-// OsCompatAndroidTest.DISABLED_TestMkdTemp in your local machine to check if it
-// passes. Please don't enable it, since it creates a directory and may be
-// source of flakyness.
-char* mkdtemp(char* path) {
- if (path == NULL) {
- errno = EINVAL;
- return NULL;
- }
-
- const int path_len = strlen(path);
-
- // The last six characters of 'path' must be XXXXXX.
- const base::StringPiece kSuffix("XXXXXX");
- const int kSuffixLen = kSuffix.length();
- if (!base::StringPiece(path, path_len).ends_with(kSuffix)) {
- errno = EINVAL;
- return NULL;
- }
-
- // If the path contains a directory, as in /tmp/foo/XXXXXXXX, make sure
- // that /tmp/foo exists, otherwise we're going to loop a really long
- // time for nothing below
- char* dirsep = strrchr(path, '/');
- if (dirsep != NULL) {
- struct stat st;
- int ret;
-
- *dirsep = '\0'; // Terminating directory path temporarily
-
- ret = stat(path, &st);
-
- *dirsep = '/'; // Restoring directory separator
- if (ret < 0) // Directory probably does not exist
- return NULL;
- if (!S_ISDIR(st.st_mode)) { // Not a directory
- errno = ENOTDIR;
- return NULL;
- }
- }
-
- // Max number of tries using different random suffixes.
- const int kMaxTries = 100;
-
- // Now loop until we CAN create a directory by that name or we reach the max
- // number of tries.
- for (int i = 0; i < kMaxTries; ++i) {
- // Fill the suffix XXXXXX with a random string composed of a-z chars.
- for (int pos = 0; pos < kSuffixLen; ++pos) {
- char rand_char = static_cast<char>(base::RandInt('a', 'z'));
- path[path_len - kSuffixLen + pos] = rand_char;
- }
- if (mkdir(path, 0700) == 0) {
- // We just created the directory succesfully.
- return path;
- }
- if (errno != EEXIST) {
- // The directory doesn't exist, but an error occured
- return NULL;
- }
- }
-
- // We reached the max number of tries.
- return NULL;
-}
-
-} // extern "C"
diff --git a/base/os_compat_android.h b/base/os_compat_android.h
deleted file mode 100644
index e33b1f7..0000000
--- a/base/os_compat_android.h
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright (c) 2012 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 BASE_OS_COMPAT_ANDROID_H_
-#define BASE_OS_COMPAT_ANDROID_H_
-
-#include <fcntl.h>
-#include <sys/types.h>
-#include <utime.h>
-
-// Not implemented in Bionic.
-extern "C" int futimes(int fd, const struct timeval tv[2]);
-
-// Not exposed or implemented in Bionic.
-extern "C" char* mkdtemp(char* path);
-
-// Android has no timegm().
-extern "C" time_t timegm(struct tm* const t);
-
-#endif // BASE_OS_COMPAT_ANDROID_H_
diff --git a/base/power_monitor/power_monitor_device_source_android.cc b/base/power_monitor/power_monitor_device_source_android.cc
deleted file mode 100644
index 7688513..0000000
--- a/base/power_monitor/power_monitor_device_source_android.cc
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2013 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.
-
-#include "base/power_monitor/power_monitor.h"
-#include "base/power_monitor/power_monitor_device_source.h"
-#include "base/power_monitor/power_monitor_source.h"
-#include "jni/PowerMonitor_jni.h"
-
-namespace base {
-
-// A helper function which is a friend of PowerMonitorSource.
-void ProcessPowerEventHelper(PowerMonitorSource::PowerEvent event) {
- PowerMonitorSource::ProcessPowerEvent(event);
-}
-
-namespace android {
-
-// Native implementation of PowerMonitor.java. Note: This will be invoked by
-// PowerMonitor.java shortly after startup to set the correct initial value for
-// "is on battery power."
-void JNI_PowerMonitor_OnBatteryChargingChanged(
- JNIEnv* env,
- const JavaParamRef<jclass>& clazz) {
- ProcessPowerEventHelper(PowerMonitorSource::POWER_STATE_EVENT);
-}
-
-// Note: Android does not have the concept of suspend / resume as it's known by
-// other platforms. Thus we do not send Suspend/Resume notifications. See
-// http://crbug.com/644515
-
-} // namespace android
-
-bool PowerMonitorDeviceSource::IsOnBatteryPowerImpl() {
- JNIEnv* env = base::android::AttachCurrentThread();
- return base::android::Java_PowerMonitor_isBatteryPower(env);
-}
-
-} // namespace base
diff --git a/base/sys_info_android.cc b/base/sys_info_android.cc
deleted file mode 100644
index 7704796..0000000
--- a/base/sys_info_android.cc
+++ /dev/null
@@ -1,241 +0,0 @@
-// Copyright (c) 2012 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.
-
-#include "base/sys_info.h"
-
-#include <dlfcn.h>
-#include <stddef.h>
-#include <stdint.h>
-#include <sys/system_properties.h>
-
-#include "base/android/jni_android.h"
-#include "base/android/sys_utils.h"
-#include "base/lazy_instance.h"
-#include "base/logging.h"
-#include "base/strings/string_number_conversions.h"
-#include "base/strings/string_piece.h"
-#include "base/strings/stringprintf.h"
-#include "base/sys_info_internal.h"
-
-#if (__ANDROID_API__ >= 21 /* 5.0 - Lollipop */)
-
-namespace {
-
-typedef int (SystemPropertyGetFunction)(const char*, char*);
-
-SystemPropertyGetFunction* DynamicallyLoadRealSystemPropertyGet() {
- // libc.so should already be open, get a handle to it.
- void* handle = dlopen("libc.so", RTLD_NOLOAD);
- if (!handle) {
- LOG(FATAL) << "Cannot dlopen libc.so: " << dlerror();
- }
- SystemPropertyGetFunction* real_system_property_get =
- reinterpret_cast<SystemPropertyGetFunction*>(
- dlsym(handle, "__system_property_get"));
- if (!real_system_property_get) {
- LOG(FATAL) << "Cannot resolve __system_property_get(): " << dlerror();
- }
- return real_system_property_get;
-}
-
-static base::LazyInstance<base::internal::LazySysInfoValue<
- SystemPropertyGetFunction*, DynamicallyLoadRealSystemPropertyGet> >::Leaky
- g_lazy_real_system_property_get = LAZY_INSTANCE_INITIALIZER;
-
-} // namespace
-
-// Android 'L' removes __system_property_get from the NDK, however it is still
-// a hidden symbol in libc. Until we remove all calls of __system_property_get
-// from Chrome we work around this by defining a weak stub here, which uses
-// dlsym to but ensures that Chrome uses the real system
-// implementatation when loaded. http://crbug.com/392191.
-BASE_EXPORT int __system_property_get(const char* name, char* value) {
- return g_lazy_real_system_property_get.Get().value()(name, value);
-}
-
-#endif
-
-namespace {
-
-// Default version of Android to fall back to when actual version numbers
-// cannot be acquired. Use the latest Android release with a higher bug fix
-// version to avoid unnecessarily comparison errors with the latest release.
-// This should be manually kept up to date on each Android release.
-const int kDefaultAndroidMajorVersion = 8;
-const int kDefaultAndroidMinorVersion = 1;
-const int kDefaultAndroidBugfixVersion = 99;
-
-// Get and parse out the OS version numbers from the system properties.
-// Note if parse fails, the "default" version is returned as fallback.
-void GetOsVersionStringAndNumbers(std::string* version_string,
- int32_t* major_version,
- int32_t* minor_version,
- int32_t* bugfix_version) {
- // Read the version number string out from the properties.
- char os_version_str[PROP_VALUE_MAX];
- __system_property_get("ro.build.version.release", os_version_str);
-
- if (os_version_str[0]) {
- // Try to parse out the version numbers from the string.
- int num_read = sscanf(os_version_str, "%d.%d.%d", major_version,
- minor_version, bugfix_version);
-
- if (num_read > 0) {
- // If we don't have a full set of version numbers, make the extras 0.
- if (num_read < 2)
- *minor_version = 0;
- if (num_read < 3)
- *bugfix_version = 0;
- *version_string = std::string(os_version_str);
- return;
- }
- }
-
- // For some reason, we couldn't parse the version number string.
- *major_version = kDefaultAndroidMajorVersion;
- *minor_version = kDefaultAndroidMinorVersion;
- *bugfix_version = kDefaultAndroidBugfixVersion;
- *version_string = ::base::StringPrintf("%d.%d.%d", *major_version,
- *minor_version, *bugfix_version);
-}
-
-// Parses a system property (specified with unit 'k','m' or 'g').
-// Returns a value in bytes.
-// Returns -1 if the string could not be parsed.
-int64_t ParseSystemPropertyBytes(const base::StringPiece& str) {
- const int64_t KB = 1024;
- const int64_t MB = 1024 * KB;
- const int64_t GB = 1024 * MB;
- if (str.size() == 0u)
- return -1;
- int64_t unit_multiplier = 1;
- size_t length = str.size();
- if (str[length - 1] == 'k') {
- unit_multiplier = KB;
- length--;
- } else if (str[length - 1] == 'm') {
- unit_multiplier = MB;
- length--;
- } else if (str[length - 1] == 'g') {
- unit_multiplier = GB;
- length--;
- }
- int64_t result = 0;
- bool parsed = base::StringToInt64(str.substr(0, length), &result);
- bool negative = result <= 0;
- bool overflow =
- result >= std::numeric_limits<int64_t>::max() / unit_multiplier;
- if (!parsed || negative || overflow)
- return -1;
- return result * unit_multiplier;
-}
-
-int GetDalvikHeapSizeMB() {
- char heap_size_str[PROP_VALUE_MAX];
- __system_property_get("dalvik.vm.heapsize", heap_size_str);
- // dalvik.vm.heapsize property is writable by a root user.
- // Clamp it to reasonable range as a sanity check,
- // a typical android device will never have less than 48MB.
- const int64_t MB = 1024 * 1024;
- int64_t result = ParseSystemPropertyBytes(heap_size_str);
- if (result == -1) {
- // We should consider not exposing these values if they are not reliable.
- LOG(ERROR) << "Can't parse dalvik.vm.heapsize: " << heap_size_str;
- result = base::SysInfo::AmountOfPhysicalMemoryMB() / 3;
- }
- result =
- std::min<int64_t>(std::max<int64_t>(32 * MB, result), 1024 * MB) / MB;
- return static_cast<int>(result);
-}
-
-int GetDalvikHeapGrowthLimitMB() {
- char heap_size_str[PROP_VALUE_MAX];
- __system_property_get("dalvik.vm.heapgrowthlimit", heap_size_str);
- // dalvik.vm.heapgrowthlimit property is writable by a root user.
- // Clamp it to reasonable range as a sanity check,
- // a typical android device will never have less than 24MB.
- const int64_t MB = 1024 * 1024;
- int64_t result = ParseSystemPropertyBytes(heap_size_str);
- if (result == -1) {
- // We should consider not exposing these values if they are not reliable.
- LOG(ERROR) << "Can't parse dalvik.vm.heapgrowthlimit: " << heap_size_str;
- result = base::SysInfo::AmountOfPhysicalMemoryMB() / 6;
- }
- result = std::min<int64_t>(std::max<int64_t>(16 * MB, result), 512 * MB) / MB;
- return static_cast<int>(result);
-}
-
-} // anonymous namespace
-
-namespace base {
-
-std::string SysInfo::HardwareModelName() {
- char device_model_str[PROP_VALUE_MAX];
- __system_property_get("ro.product.model", device_model_str);
- return std::string(device_model_str);
-}
-
-std::string SysInfo::OperatingSystemName() {
- return "Android";
-}
-
-std::string SysInfo::OperatingSystemVersion() {
- std::string version_string;
- int32_t major, minor, bugfix;
- GetOsVersionStringAndNumbers(&version_string, &major, &minor, &bugfix);
- return version_string;
-}
-
-void SysInfo::OperatingSystemVersionNumbers(int32_t* major_version,
- int32_t* minor_version,
- int32_t* bugfix_version) {
- std::string version_string;
- GetOsVersionStringAndNumbers(&version_string, major_version, minor_version,
- bugfix_version);
-}
-
-std::string SysInfo::GetAndroidBuildCodename() {
- char os_version_codename_str[PROP_VALUE_MAX];
- __system_property_get("ro.build.version.codename", os_version_codename_str);
- return std::string(os_version_codename_str);
-}
-
-std::string SysInfo::GetAndroidBuildID() {
- char os_build_id_str[PROP_VALUE_MAX];
- __system_property_get("ro.build.id", os_build_id_str);
- return std::string(os_build_id_str);
-}
-
-int SysInfo::DalvikHeapSizeMB() {
- static int heap_size = GetDalvikHeapSizeMB();
- return heap_size;
-}
-
-int SysInfo::DalvikHeapGrowthLimitMB() {
- static int heap_growth_limit = GetDalvikHeapGrowthLimitMB();
- return heap_growth_limit;
-}
-
-static base::LazyInstance<
- base::internal::LazySysInfoValue<bool,
- android::SysUtils::IsLowEndDeviceFromJni> >::Leaky
- g_lazy_low_end_device = LAZY_INSTANCE_INITIALIZER;
-
-bool SysInfo::IsLowEndDeviceImpl() {
- // This code might be used in some environments
- // which might not have a Java environment.
- // Note that we need to call the Java version here.
- // There exists a complete native implementation in
- // sys_info.cc but calling that here would mean that
- // the Java code and the native code would call different
- // implementations which could give different results.
- // Also the Java code cannot depend on the native code
- // since it might not be loaded yet.
- if (!base::android::IsVMInitialized())
- return false;
- return g_lazy_low_end_device.Get().value();
-}
-
-
-} // namespace base
diff --git a/base/test/android/OWNERS b/base/test/android/OWNERS
deleted file mode 100644
index 2b0078b..0000000
--- a/base/test/android/OWNERS
+++ /dev/null
@@ -1,4 +0,0 @@
-jbudorick@chromium.org
-file://base/android/OWNERS
-
-# COMPONENT: Test>Android
diff --git a/base/test/android/java/src/org/chromium/base/ContentUriTestUtils.java b/base/test/android/java/src/org/chromium/base/ContentUriTestUtils.java
deleted file mode 100644
index fe9d540..0000000
--- a/base/test/android/java/src/org/chromium/base/ContentUriTestUtils.java
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright 2013 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.
-
-package org.chromium.base;
-
-import android.content.ContentValues;
-import android.database.Cursor;
-import android.net.Uri;
-import android.provider.MediaStore;
-
-import org.chromium.base.annotations.CalledByNative;
-
-/**
- * Utilities for testing operations on content URI.
- */
-public class ContentUriTestUtils {
- /**
- * Insert an image into the MediaStore, and return the content URI. If the
- * image already exists in the MediaStore, just retrieve the URI.
- *
- * @param path Path to the image file.
- * @return Content URI of the image.
- */
- @CalledByNative
- private static String insertImageIntoMediaStore(String path) {
- // Check whether the content URI exists.
- Cursor c = ContextUtils.getApplicationContext().getContentResolver().query(
- MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
- new String[] {MediaStore.Video.VideoColumns._ID},
- MediaStore.Images.Media.DATA + " LIKE ?", new String[] {path}, null);
- if (c != null && c.getCount() > 0) {
- c.moveToFirst();
- int id = c.getInt(0);
- return Uri.withAppendedPath(
- MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "" + id).toString();
- }
-
- // Insert the content URI into MediaStore.
- ContentValues values = new ContentValues();
- values.put(MediaStore.MediaColumns.DATA, path);
- Uri uri = ContextUtils.getApplicationContext().getContentResolver().insert(
- MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
- return uri.toString();
- }
-}
diff --git a/base/test/android/java/src/org/chromium/base/ITestCallback.aidl b/base/test/android/java/src/org/chromium/base/ITestCallback.aidl
deleted file mode 100644
index dd208d5..0000000
--- a/base/test/android/java/src/org/chromium/base/ITestCallback.aidl
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2016 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.
-
-package org.chromium.base;
-
-import org.chromium.base.ITestController;
-import org.chromium.base.process_launcher.FileDescriptorInfo;
-
-/**
- * This interface is called by the child process to pass its controller to its parent.
- */
-interface ITestCallback {
- oneway void childConnected(ITestController controller);
-
- /**
- * Invoked by the service to notify that the main method returned.
- * IMPORTANT! Should not be marked oneway as the caller will terminate the running process after
- * this call. Marking it oneway would make the call asynchronous and the process could terminate
- * before the call was actually sent.
- */
- void mainReturned(int returnCode);
-}
diff --git a/base/test/android/java/src/org/chromium/base/ITestController.aidl b/base/test/android/java/src/org/chromium/base/ITestController.aidl
deleted file mode 100644
index d927ee5..0000000
--- a/base/test/android/java/src/org/chromium/base/ITestController.aidl
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base;
-
-import org.chromium.base.process_launcher.FileDescriptorInfo;
-
-/**
- * This interface is used to control child processes.
- */
-interface ITestController {
- /**
- * Forces the service process to terminate and block until the process stops.
- * @param exitCode the exit code the process should terminate with.
- * @return always true, a return value is only returned to force the call to be synchronous.
- */
- boolean forceStopSynchronous(int exitCode);
-
- /**
- * Forces the service process to terminate.
- * @param exitCode the exit code the process should terminate with.
- */
- oneway void forceStop(int exitCode);
-}
diff --git a/base/test/android/java/src/org/chromium/base/JavaHandlerThreadHelpers.java b/base/test/android/java/src/org/chromium/base/JavaHandlerThreadHelpers.java
deleted file mode 100644
index 3da7ba8..0000000
--- a/base/test/android/java/src/org/chromium/base/JavaHandlerThreadHelpers.java
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base;
-
-import android.os.Handler;
-
-import org.chromium.base.annotations.CalledByNative;
-import org.chromium.base.annotations.CalledByNativeUnchecked;
-import org.chromium.base.annotations.JNINamespace;
-
-import java.util.concurrent.atomic.AtomicBoolean;
-
-@JNINamespace("base::android")
-class JavaHandlerThreadHelpers {
- private static class TestException extends Exception {}
-
- // This is executed as part of base_unittests. This tests that JavaHandlerThread can be used
- // by itself without attaching to its native peer.
- @CalledByNative
- private static JavaHandlerThread testAndGetJavaHandlerThread() {
- final AtomicBoolean taskExecuted = new AtomicBoolean();
- final Object lock = new Object();
- Runnable runnable = new Runnable() {
- @Override
- public void run() {
- synchronized (lock) {
- taskExecuted.set(true);
- lock.notifyAll();
- }
- }
- };
-
- JavaHandlerThread thread = new JavaHandlerThread("base_unittests_java");
- thread.maybeStart();
-
- Handler handler = new Handler(thread.getLooper());
- handler.post(runnable);
- synchronized (lock) {
- while (!taskExecuted.get()) {
- try {
- lock.wait();
- } catch (InterruptedException e) {
- // ignore interrupts
- }
- }
- }
-
- return thread;
- }
-
- @CalledByNativeUnchecked
- private static void throwException() throws TestException {
- throw new TestException();
- }
-
- @CalledByNative
- private static boolean isExceptionTestException(Throwable exception) {
- if (exception == null) return false;
- return exception instanceof TestException;
- }
-}
diff --git a/base/test/android/java/src/org/chromium/base/MainReturnCodeResult.java b/base/test/android/java/src/org/chromium/base/MainReturnCodeResult.java
deleted file mode 100644
index 9756c97..0000000
--- a/base/test/android/java/src/org/chromium/base/MainReturnCodeResult.java
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright 2016 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.
-
-package org.chromium.base;
-
-import org.chromium.base.annotations.CalledByNative;
-import org.chromium.base.annotations.JNINamespace;
-
-/**
- * Contains the result of a native main method that ran in a child process.
- */
-@JNINamespace("base::android")
-public final class MainReturnCodeResult {
- private final int mMainReturnCode;
- private final boolean mTimedOut;
-
- public static MainReturnCodeResult createMainResult(int returnCode) {
- return new MainReturnCodeResult(returnCode, false /* timedOut */);
- }
-
- public static MainReturnCodeResult createTimeoutMainResult() {
- return new MainReturnCodeResult(0, true /* timedOut */);
- }
-
- private MainReturnCodeResult(int mainReturnCode, boolean timedOut) {
- mMainReturnCode = mainReturnCode;
- mTimedOut = timedOut;
- }
-
- @CalledByNative
- public int getReturnCode() {
- return mMainReturnCode;
- }
-
- @CalledByNative
- public boolean hasTimedOut() {
- return mTimedOut;
- }
-}
diff --git a/base/test/android/java/src/org/chromium/base/MultiprocessTestClientLauncher.java b/base/test/android/java/src/org/chromium/base/MultiprocessTestClientLauncher.java
deleted file mode 100644
index d0b1850..0000000
--- a/base/test/android/java/src/org/chromium/base/MultiprocessTestClientLauncher.java
+++ /dev/null
@@ -1,383 +0,0 @@
-// Copyright 2016 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.
-
-package org.chromium.base;
-
-import android.os.Handler;
-import android.os.HandlerThread;
-import android.os.Looper;
-import android.os.ParcelFileDescriptor;
-import android.os.RemoteException;
-import android.util.SparseArray;
-
-import org.chromium.base.annotations.CalledByNative;
-import org.chromium.base.annotations.JNINamespace;
-import org.chromium.base.process_launcher.ChildConnectionAllocator;
-import org.chromium.base.process_launcher.ChildProcessConnection;
-import org.chromium.base.process_launcher.ChildProcessLauncher;
-import org.chromium.base.process_launcher.FileDescriptorInfo;
-import org.chromium.base.process_launcher.IChildProcessService;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.concurrent.Callable;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.FutureTask;
-import java.util.concurrent.Semaphore;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.ReentrantLock;
-
-import javax.annotation.concurrent.GuardedBy;
-
-/**
- * Helper class for launching test client processes for multiprocess unit tests.
- */
-@JNINamespace("base::android")
-public final class MultiprocessTestClientLauncher {
- private static final String TAG = "cr_MProcTCLauncher";
-
- private static final int CONNECTION_TIMEOUT_MS = 10 * 1000;
-
- private static final SparseArray<MultiprocessTestClientLauncher> sPidToLauncher =
- new SparseArray<>();
-
- private static final SparseArray<Integer> sPidToMainResult = new SparseArray<>();
-
- private static final Object sLauncherHandlerInitLock = new Object();
- private static Handler sLauncherHandler;
-
- private static ChildConnectionAllocator sConnectionAllocator;
-
- private final ITestCallback.Stub mCallback = new ITestCallback.Stub() {
- @Override
- public void childConnected(ITestController controller) {
- mTestController = controller;
- // This method can be called before onServiceConnected below has set the PID.
- // Wait for mPid to be set before notifying.
- try {
- mPidReceived.await();
- } catch (InterruptedException ie) {
- Log.e(TAG, "Interrupted while waiting for connection PID.");
- return;
- }
- // Now we are fully initialized, notify clients.
- mConnectedLock.lock();
- try {
- mConnected = true;
- mConnectedCondition.signal();
- } finally {
- mConnectedLock.unlock();
- }
- }
-
- @Override
- public void mainReturned(int returnCode) {
- mMainReturnCodeLock.lock();
- try {
- mMainReturnCode = returnCode;
- mMainReturnCodeCondition.signal();
- } finally {
- mMainReturnCodeLock.unlock();
- }
-
- // Also store the return code in a map as the connection might get disconnected
- // before waitForMainToReturn is called and then we would not have a way to retrieve
- // the connection.
- sPidToMainResult.put(mPid, returnCode);
- }
- };
-
- private final ChildProcessLauncher.Delegate mLauncherDelegate =
- new ChildProcessLauncher.Delegate() {
- @Override
- public void onConnectionEstablished(ChildProcessConnection connection) {
- assert isRunningOnLauncherThread();
- int pid = connection.getPid();
- sPidToLauncher.put(pid, MultiprocessTestClientLauncher.this);
- mPid = pid;
- mPidReceived.countDown();
- }
-
- @Override
- public void onConnectionLost(ChildProcessConnection connection) {
- assert isRunningOnLauncherThread();
- assert sPidToLauncher.get(connection.getPid())
- == MultiprocessTestClientLauncher.this;
- sPidToLauncher.remove(connection.getPid());
- }
- };
-
- private final CountDownLatch mPidReceived = new CountDownLatch(1);
-
- private final ChildProcessLauncher mLauncher;
-
- private final ReentrantLock mConnectedLock = new ReentrantLock();
- private final Condition mConnectedCondition = mConnectedLock.newCondition();
- @GuardedBy("mConnectedLock")
- private boolean mConnected;
-
- private IChildProcessService mService = null;
- private int mPid;
- private ITestController mTestController;
-
- private final ReentrantLock mMainReturnCodeLock = new ReentrantLock();
- private final Condition mMainReturnCodeCondition = mMainReturnCodeLock.newCondition();
- // The return code returned by the service's main method.
- // null if the service has not sent it yet.
- @GuardedBy("mMainReturnCodeLock")
- private Integer mMainReturnCode;
-
- private MultiprocessTestClientLauncher(String[] commandLine, FileDescriptorInfo[] filesToMap) {
- assert isRunningOnLauncherThread();
-
- if (sConnectionAllocator == null) {
- sConnectionAllocator = ChildConnectionAllocator.create(
- ContextUtils.getApplicationContext(), sLauncherHandler, null,
- "org.chromium.native_test", "org.chromium.base.MultiprocessTestClientService",
- "org.chromium.native_test.NUM_TEST_CLIENT_SERVICES", false /* bindToCaller */,
- false /* bindAsExternalService */, false /* useStrongBinding */);
- }
- mLauncher = new ChildProcessLauncher(sLauncherHandler, mLauncherDelegate, commandLine,
- filesToMap, sConnectionAllocator, Arrays.asList(mCallback));
- }
-
- private boolean waitForConnection(long timeoutMs) {
- assert !isRunningOnLauncherThread();
-
- long timeoutNs = TimeUnit.MILLISECONDS.toNanos(timeoutMs);
- mConnectedLock.lock();
- try {
- while (!mConnected) {
- if (timeoutNs <= 0L) {
- return false;
- }
- try {
- mConnectedCondition.awaitNanos(timeoutNs);
- } catch (InterruptedException ie) {
- Log.e(TAG, "Interrupted while waiting for connection.");
- }
- }
- } finally {
- mConnectedLock.unlock();
- }
- return true;
- }
-
- private Integer getMainReturnCode(long timeoutMs) {
- assert isRunningOnLauncherThread();
-
- long timeoutNs = TimeUnit.MILLISECONDS.toNanos(timeoutMs);
- mMainReturnCodeLock.lock();
- try {
- while (mMainReturnCode == null) {
- if (timeoutNs <= 0L) {
- return null;
- }
- try {
- timeoutNs = mMainReturnCodeCondition.awaitNanos(timeoutNs);
- } catch (InterruptedException ie) {
- Log.e(TAG, "Interrupted while waiting for main return code.");
- }
- }
- return mMainReturnCode;
- } finally {
- mMainReturnCodeLock.unlock();
- }
- }
-
- /**
- * Spawns and connects to a child process.
- * May not be called from the main thread.
- *
- * @param commandLine the child process command line argv.
- * @return the PID of the started process or 0 if the process could not be started.
- */
- @CalledByNative
- private static int launchClient(
- final String[] commandLine, final FileDescriptorInfo[] filesToMap) {
- initLauncherThread();
-
- final MultiprocessTestClientLauncher launcher =
- runOnLauncherAndGetResult(new Callable<MultiprocessTestClientLauncher>() {
- @Override
- public MultiprocessTestClientLauncher call() {
- return createAndStartLauncherOnLauncherThread(commandLine, filesToMap);
- }
- });
- if (launcher == null) {
- return 0;
- }
-
- if (!launcher.waitForConnection(CONNECTION_TIMEOUT_MS)) {
- return 0; // Timed-out.
- }
-
- return runOnLauncherAndGetResult(new Callable<Integer>() {
- @Override
- public Integer call() {
- int pid = launcher.mLauncher.getPid();
- assert pid > 0;
- sPidToLauncher.put(pid, launcher);
- return pid;
- }
- });
- }
-
- private static MultiprocessTestClientLauncher createAndStartLauncherOnLauncherThread(
- String[] commandLine, FileDescriptorInfo[] filesToMap) {
- assert isRunningOnLauncherThread();
-
- MultiprocessTestClientLauncher launcher =
- new MultiprocessTestClientLauncher(commandLine, filesToMap);
- if (!launcher.mLauncher.start(
- true /* setupConnection */, true /* queueIfNoFreeConnection */)) {
- return null;
- }
-
- return launcher;
- }
-
- /**
- * Blocks until the main method invoked by a previous call to launchClient terminates or until
- * the specified time-out expires.
- * Returns immediately if main has already returned.
- * @param pid the process ID that was returned by the call to launchClient
- * @param timeoutMs the timeout in milliseconds after which the method returns even if main has
- * not returned.
- * @return the return code returned by the main method or whether it timed-out.
- */
- @CalledByNative
- private static MainReturnCodeResult waitForMainToReturn(final int pid, final int timeoutMs) {
- return runOnLauncherAndGetResult(new Callable<MainReturnCodeResult>() {
- @Override
- public MainReturnCodeResult call() {
- return waitForMainToReturnOnLauncherThread(pid, timeoutMs);
- }
- });
- }
-
- private static MainReturnCodeResult waitForMainToReturnOnLauncherThread(
- int pid, int timeoutMs) {
- assert isRunningOnLauncherThread();
-
- MultiprocessTestClientLauncher launcher = sPidToLauncher.get(pid);
- // The launcher can be null if it got cleaned-up (because the connection was lost) before
- // this gets called.
- if (launcher != null) {
- Integer mainResult = launcher.getMainReturnCode(timeoutMs);
- return mainResult == null ? MainReturnCodeResult.createTimeoutMainResult()
- : MainReturnCodeResult.createMainResult(mainResult);
- }
-
- Integer mainResult = sPidToMainResult.get(pid);
- if (mainResult == null) {
- Log.e(TAG, "waitForMainToReturn called on unknown connection for pid " + pid);
- return null;
- }
- sPidToMainResult.remove(pid);
- return MainReturnCodeResult.createMainResult(mainResult);
- }
-
- @CalledByNative
- private static boolean terminate(final int pid, final int exitCode, final boolean wait) {
- return runOnLauncherAndGetResult(new Callable<Boolean>() {
- @Override
- public Boolean call() {
- return terminateOnLauncherThread(pid, exitCode, wait);
- }
- });
- }
-
- private static boolean terminateOnLauncherThread(int pid, int exitCode, boolean wait) {
- assert isRunningOnLauncherThread();
-
- MultiprocessTestClientLauncher launcher = sPidToLauncher.get(pid);
- if (launcher == null) {
- Log.e(TAG, "terminate called on unknown launcher for pid " + pid);
- return false;
- }
- try {
- if (wait) {
- launcher.mTestController.forceStopSynchronous(exitCode);
- } else {
- launcher.mTestController.forceStop(exitCode);
- }
- } catch (RemoteException e) {
- // We expect this failure, since the forceStop's service implementation calls
- // System.exit().
- }
- return true;
- }
-
- private static void initLauncherThread() {
- synchronized (sLauncherHandlerInitLock) {
- if (sLauncherHandler != null) return;
-
- HandlerThread launcherThread = new HandlerThread("LauncherThread");
- launcherThread.start();
- sLauncherHandler = new Handler(launcherThread.getLooper());
- }
- }
-
- /** Does not take ownership of of fds. */
- @CalledByNative
- private static FileDescriptorInfo[] makeFdInfoArray(int[] keys, int[] fds) {
- FileDescriptorInfo[] fdInfos = new FileDescriptorInfo[keys.length];
- for (int i = 0; i < keys.length; i++) {
- FileDescriptorInfo fdInfo = makeFdInfo(keys[i], fds[i]);
- if (fdInfo == null) {
- Log.e(TAG, "Failed to make file descriptor (" + keys[i] + ", " + fds[i] + ").");
- return null;
- }
- fdInfos[i] = fdInfo;
- }
- return fdInfos;
- }
-
- private static FileDescriptorInfo makeFdInfo(int id, int fd) {
- ParcelFileDescriptor parcelableFd = null;
- try {
- parcelableFd = ParcelFileDescriptor.fromFd(fd);
- } catch (IOException e) {
- Log.e(TAG, "Invalid FD provided for process connection, aborting connection.", e);
- return null;
- }
- return new FileDescriptorInfo(id, parcelableFd, 0 /* offset */, 0 /* size */);
- }
-
- private static boolean isRunningOnLauncherThread() {
- return sLauncherHandler.getLooper() == Looper.myLooper();
- }
-
- private static void runOnLauncherThreadBlocking(final Runnable runnable) {
- assert !isRunningOnLauncherThread();
- final Semaphore done = new Semaphore(0);
- sLauncherHandler.post(new Runnable() {
- @Override
- public void run() {
- runnable.run();
- done.release();
- }
- });
- done.acquireUninterruptibly();
- }
-
- private static <R> R runOnLauncherAndGetResult(Callable<R> callable) {
- if (isRunningOnLauncherThread()) {
- try {
- return callable.call();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- try {
- FutureTask<R> task = new FutureTask<R>(callable);
- sLauncherHandler.post(task);
- return task.get();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-}
diff --git a/base/test/android/java/src/org/chromium/base/MultiprocessTestClientService.java b/base/test/android/java/src/org/chromium/base/MultiprocessTestClientService.java
deleted file mode 100644
index 9b50001..0000000
--- a/base/test/android/java/src/org/chromium/base/MultiprocessTestClientService.java
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2016 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.
-
-package org.chromium.base;
-
-import org.chromium.base.process_launcher.ChildProcessService;
-
-/** The service implementation used to host all multiprocess test client code. */
-public class MultiprocessTestClientService extends ChildProcessService {
- public MultiprocessTestClientService() {
- super(new MultiprocessTestClientServiceDelegate());
- }
-}
diff --git a/base/test/android/java/src/org/chromium/base/MultiprocessTestClientService0.java b/base/test/android/java/src/org/chromium/base/MultiprocessTestClientService0.java
deleted file mode 100644
index 6bdd867..0000000
--- a/base/test/android/java/src/org/chromium/base/MultiprocessTestClientService0.java
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright 2016 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.
-
-package org.chromium.base;
-
-/**
- * A subclass used only to differentiate different test client service process instances.
- */
-public class MultiprocessTestClientService0 extends MultiprocessTestClientService {}
diff --git a/base/test/android/java/src/org/chromium/base/MultiprocessTestClientService1.java b/base/test/android/java/src/org/chromium/base/MultiprocessTestClientService1.java
deleted file mode 100644
index 69827f0..0000000
--- a/base/test/android/java/src/org/chromium/base/MultiprocessTestClientService1.java
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright 2016 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.
-
-package org.chromium.base;
-
-/**
- * A subclass used only to differentiate different test client service process instances.
- */
-public class MultiprocessTestClientService1 extends MultiprocessTestClientService {}
diff --git a/base/test/android/java/src/org/chromium/base/MultiprocessTestClientService2.java b/base/test/android/java/src/org/chromium/base/MultiprocessTestClientService2.java
deleted file mode 100644
index aad11f1..0000000
--- a/base/test/android/java/src/org/chromium/base/MultiprocessTestClientService2.java
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright 2016 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.
-
-package org.chromium.base;
-
-/**
- * A subclass used only to differentiate different test client service process instances.
- */
-public class MultiprocessTestClientService2 extends MultiprocessTestClientService {}
diff --git a/base/test/android/java/src/org/chromium/base/MultiprocessTestClientService3.java b/base/test/android/java/src/org/chromium/base/MultiprocessTestClientService3.java
deleted file mode 100644
index 20d2561..0000000
--- a/base/test/android/java/src/org/chromium/base/MultiprocessTestClientService3.java
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright 2016 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.
-
-package org.chromium.base;
-
-/**
- * A subclass used only to differentiate different test client service process instances.
- */
-public class MultiprocessTestClientService3 extends MultiprocessTestClientService {}
diff --git a/base/test/android/java/src/org/chromium/base/MultiprocessTestClientService4.java b/base/test/android/java/src/org/chromium/base/MultiprocessTestClientService4.java
deleted file mode 100644
index 4b14551..0000000
--- a/base/test/android/java/src/org/chromium/base/MultiprocessTestClientService4.java
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright 2016 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.
-
-package org.chromium.base;
-
-/**
- * A subclass used only to differentiate different test client service process instances.
- */
-public class MultiprocessTestClientService4 extends MultiprocessTestClientService {}
diff --git a/base/test/android/java/src/org/chromium/base/MultiprocessTestClientServiceDelegate.java b/base/test/android/java/src/org/chromium/base/MultiprocessTestClientServiceDelegate.java
deleted file mode 100644
index 83ccaca..0000000
--- a/base/test/android/java/src/org/chromium/base/MultiprocessTestClientServiceDelegate.java
+++ /dev/null
@@ -1,99 +0,0 @@
-// Copyright 2017 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.
-package org.chromium.base;
-
-import android.content.Context;
-import android.content.Intent;
-import android.os.Bundle;
-import android.os.IBinder;
-import android.os.RemoteException;
-import android.util.SparseArray;
-
-import org.chromium.base.library_loader.LibraryLoader;
-import org.chromium.base.library_loader.LibraryProcessType;
-import org.chromium.base.library_loader.ProcessInitException;
-import org.chromium.base.process_launcher.ChildProcessServiceDelegate;
-import org.chromium.native_test.MainRunner;
-
-import java.util.List;
-
-/** Implementation of the ChildProcessServiceDelegate used for the Multiprocess tests. */
-public class MultiprocessTestClientServiceDelegate implements ChildProcessServiceDelegate {
- private static final String TAG = "MPTestCSDelegate";
-
- private ITestCallback mTestCallback;
-
- private final ITestController.Stub mTestController = new ITestController.Stub() {
- @Override
- public boolean forceStopSynchronous(int exitCode) {
- System.exit(exitCode);
- return true;
- }
-
- @Override
- public void forceStop(int exitCode) {
- System.exit(exitCode);
- }
- };
-
- @Override
- public void onServiceCreated() {
- PathUtils.setPrivateDataDirectorySuffix("chrome_multiprocess_test_client_service");
- }
-
- @Override
- public void onServiceBound(Intent intent) {}
-
- @Override
- public void onConnectionSetup(Bundle connectionBundle, List<IBinder> callbacks) {
- mTestCallback = ITestCallback.Stub.asInterface(callbacks.get(0));
- }
-
- @Override
- public void onDestroy() {}
-
- @Override
- public void preloadNativeLibrary(Context hostContext) {
- try {
- LibraryLoader.get(LibraryProcessType.PROCESS_CHILD).preloadNow();
- } catch (ProcessInitException pie) {
- Log.w(TAG, "Unable to preload native libraries.", pie);
- }
- }
-
- @Override
- public boolean loadNativeLibrary(Context hostContext) {
- try {
- LibraryLoader.get(LibraryProcessType.PROCESS_CHILD).loadNow();
- return true;
- } catch (ProcessInitException pie) {
- Log.e(TAG, "Unable to load native libraries.", pie);
- return false;
- }
- }
-
- @Override
- public SparseArray<String> getFileDescriptorsIdsToKeys() {
- return null;
- }
-
- @Override
- public void onBeforeMain() {
- try {
- mTestCallback.childConnected(mTestController);
- } catch (RemoteException re) {
- Log.e(TAG, "Failed to notify parent process of connection.");
- }
- }
-
- @Override
- public void runMain() {
- int result = MainRunner.runMain(CommandLine.getJavaSwitchesOrNull());
- try {
- mTestCallback.mainReturned(result);
- } catch (RemoteException re) {
- Log.e(TAG, "Failed to notify parent process of main returning.");
- }
- }
-}
diff --git a/base/test/android/java/src/org/chromium/base/OWNERS b/base/test/android/java/src/org/chromium/base/OWNERS
deleted file mode 100644
index 89442ab..0000000
--- a/base/test/android/java/src/org/chromium/base/OWNERS
+++ /dev/null
@@ -1,2 +0,0 @@
-per-file *.aidl=set noparent
-per-file *.aidl=file://ipc/SECURITY_OWNERS
\ No newline at end of file
diff --git a/base/test/android/java/src/org/chromium/base/TestUiThread.java b/base/test/android/java/src/org/chromium/base/TestUiThread.java
deleted file mode 100644
index 237c0ec..0000000
--- a/base/test/android/java/src/org/chromium/base/TestUiThread.java
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright 2015 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.
-
-package org.chromium.base;
-
-import android.os.Looper;
-
-import org.chromium.base.annotations.CalledByNative;
-
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import javax.annotation.concurrent.ThreadSafe;
-
-/**
- * Set up a thread as the Chromium UI Thread, and run its looper. This is is intended for C++ unit
- * tests (e.g. the net unit tests) that don't run with the UI thread as their main looper, but test
- * code that, on Android, uses UI thread events, so need a running UI thread.
- */
-@ThreadSafe
-public class TestUiThread {
- private static final AtomicBoolean sStarted = new AtomicBoolean(false);
- private static final String TAG = "cr.TestUiThread";
-
- @CalledByNative
- private static void loop() {
- // @{link ThreadUtils#setUiThread(Looper)} can only be called once in a test run, so do this
- // once, and leave it running.
- if (sStarted.getAndSet(true)) return;
-
- final CountDownLatch startLatch = new CountDownLatch(1);
- new Thread(new Runnable() {
-
- @Override
- public void run() {
- Looper.prepare();
- ThreadUtils.setUiThread(Looper.myLooper());
- startLatch.countDown();
- Looper.loop();
- }
-
- }).start();
-
- try {
- startLatch.await();
- } catch (InterruptedException e) {
- Log.e(TAG, "Failed to set UI Thread");
- }
- }
-}
diff --git a/base/test/android/java_handler_thread_helpers.cc b/base/test/android/java_handler_thread_helpers.cc
deleted file mode 100644
index 925dc9d..0000000
--- a/base/test/android/java_handler_thread_helpers.cc
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2016 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.
-
-#include "base/test/android/java_handler_thread_helpers.h"
-
-#include "base/android/java_handler_thread.h"
-#include "base/message_loop/message_loop_current.h"
-#include "base/synchronization/waitable_event.h"
-#include "jni/JavaHandlerThreadHelpers_jni.h"
-
-namespace base {
-namespace android {
-
-// static
-std::unique_ptr<JavaHandlerThread> JavaHandlerThreadHelpers::CreateJavaFirst() {
- return std::make_unique<JavaHandlerThread>(
- Java_JavaHandlerThreadHelpers_testAndGetJavaHandlerThread(
- base::android::AttachCurrentThread()));
-}
-
-// static
-void JavaHandlerThreadHelpers::ThrowExceptionAndAbort(WaitableEvent* event) {
- JNIEnv* env = AttachCurrentThread();
- Java_JavaHandlerThreadHelpers_throwException(env);
- DCHECK(HasException(env));
- base::MessageLoopCurrentForUI::Get()->Abort();
- event->Signal();
-}
-
-// static
-bool JavaHandlerThreadHelpers::IsExceptionTestException(
- ScopedJavaLocalRef<jthrowable> exception) {
- JNIEnv* env = AttachCurrentThread();
- return Java_JavaHandlerThreadHelpers_isExceptionTestException(env, exception);
-}
-
-} // namespace android
-} // namespace base
diff --git a/base/test/android/java_handler_thread_helpers.h b/base/test/android/java_handler_thread_helpers.h
deleted file mode 100644
index 5f05cbc..0000000
--- a/base/test/android/java_handler_thread_helpers.h
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2016 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 BASE_ANDROID_JAVA_HANDLER_THREAD_FOR_TESTING_H_
-#define BASE_ANDROID_JAVA_HANDLER_THREAD_FOR_TESTING_H_
-
-#include <jni.h>
-
-#include <memory>
-
-#include "base/android/scoped_java_ref.h"
-
-namespace base {
-
-class WaitableEvent;
-
-namespace android {
-
-class JavaHandlerThread;
-
-// Test-only helpers for working with JavaHandlerThread.
-class JavaHandlerThreadHelpers {
- public:
- // Create the Java peer first and test that it works before connecting to the
- // native object.
- static std::unique_ptr<JavaHandlerThread> CreateJavaFirst();
-
- static void ThrowExceptionAndAbort(WaitableEvent* event);
-
- static bool IsExceptionTestException(
- ScopedJavaLocalRef<jthrowable> exception);
-
- private:
- JavaHandlerThreadHelpers() = default;
- ~JavaHandlerThreadHelpers() = default;
-};
-
-} // namespace android
-} // namespace base
-
-#endif // BASE_ANDROID_JAVA_HANDLER_THREAD_FOR_TESTING_H_
diff --git a/base/test/android/javatests/src/org/chromium/base/test/BaseChromiumAndroidJUnitRunner.java b/base/test/android/javatests/src/org/chromium/base/test/BaseChromiumAndroidJUnitRunner.java
deleted file mode 100644
index 59ab519..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/BaseChromiumAndroidJUnitRunner.java
+++ /dev/null
@@ -1,282 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test;
-
-import android.app.Activity;
-import android.app.Application;
-import android.app.Instrumentation;
-import android.content.Context;
-import android.content.pm.InstrumentationInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.os.Bundle;
-import android.support.test.InstrumentationRegistry;
-import android.support.test.internal.runner.RunnerArgs;
-import android.support.test.internal.runner.TestExecutor;
-import android.support.test.internal.runner.TestLoader;
-import android.support.test.internal.runner.TestRequest;
-import android.support.test.internal.runner.TestRequestBuilder;
-import android.support.test.runner.AndroidJUnitRunner;
-
-import dalvik.system.DexFile;
-
-import org.chromium.base.BuildConfig;
-import org.chromium.base.Log;
-import org.chromium.base.annotations.MainDex;
-import org.chromium.base.multidex.ChromiumMultiDexInstaller;
-
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.util.Enumeration;
-
-/**
- * A custom AndroidJUnitRunner that supports multidex installer and list out test information.
- *
- * This class is the equivalent of BaseChromiumInstrumentationTestRunner in JUnit3. Please
- * beware that is this not a class runner. It is declared in test apk AndroidManifest.xml
- * <instrumentation>
- *
- * TODO(yolandyan): remove this class after all tests are converted to JUnit4. Use class runner
- * for test listing.
- */
-@MainDex
-public class BaseChromiumAndroidJUnitRunner extends AndroidJUnitRunner {
- private static final String LIST_ALL_TESTS_FLAG =
- "org.chromium.base.test.BaseChromiumAndroidJUnitRunner.TestList";
- private static final String LIST_TESTS_PACKAGE_FLAG =
- "org.chromium.base.test.BaseChromiumAndroidJUnitRunner.TestListPackage";
- /**
- * This flag is supported by AndroidJUnitRunner.
- *
- * See the following page for detail
- * https://developer.android.com/reference/android/support/test/runner/AndroidJUnitRunner.html
- */
- private static final String ARGUMENT_TEST_PACKAGE = "package";
-
- /**
- * The following arguments are corresponding to AndroidJUnitRunner command line arguments.
- * `annotation`: run with only the argument annotation
- * `notAnnotation`: run all tests except the ones with argument annotation
- * `log`: run in log only mode, do not execute tests
- *
- * For more detail, please check
- * https://developer.android.com/reference/android/support/test/runner/AndroidJUnitRunner.html
- */
- private static final String ARGUMENT_ANNOTATION = "annotation";
- private static final String ARGUMENT_NOT_ANNOTATION = "notAnnotation";
- private static final String ARGUMENT_LOG_ONLY = "log";
-
- private static final String TAG = "BaseJUnitRunner";
-
- @Override
- public Application newApplication(ClassLoader cl, String className, Context context)
- throws ClassNotFoundException, IllegalAccessException, InstantiationException {
- // The multidex support library doesn't currently support having the test apk be multidex
- // as well as the under-test apk being multidex. If MultiDex.install() is called for both,
- // then re-extraction is triggered every time due to the support library caching only a
- // single timestamp & crc.
- //
- // Attempt to install test apk multidex only if the apk-under-test is not multidex.
- // It will likely continue to be true that the two are mutually exclusive because:
- // * ProGuard enabled =>
- // Under-test apk is single dex.
- // Test apk duplicates under-test classes, so may need multidex.
- // * ProGuard disabled =>
- // Under-test apk might be multidex
- // Test apk does not duplicate classes, so does not need multidex.
- // https://crbug.com/824523
- if (!BuildConfig.IS_MULTIDEX_ENABLED) {
- ChromiumMultiDexInstaller.install(new BaseChromiumRunnerCommon.MultiDexContextWrapper(
- getContext(), getTargetContext()));
- BaseChromiumRunnerCommon.reorderDexPathElements(cl, getContext(), getTargetContext());
- }
- return super.newApplication(cl, className, context);
- }
-
- /**
- * Add TestListInstrumentationRunListener when argument ask the runner to list tests info.
- *
- * The running mechanism when argument has "listAllTests" is equivalent to that of
- * {@link android.support.test.runner.AndroidJUnitRunner#onStart()} except it adds
- * only TestListInstrumentationRunListener to monitor the tests.
- */
- @Override
- public void onStart() {
- Bundle arguments = InstrumentationRegistry.getArguments();
- if (arguments != null && arguments.getString(LIST_ALL_TESTS_FLAG) != null) {
- Log.w(TAG,
- String.format("Runner will list out tests info in JSON without running tests. "
- + "Arguments: %s",
- arguments.toString()));
- listTests(); // Intentionally not calling super.onStart() to avoid additional work.
- } else {
- if (arguments != null && arguments.getString(ARGUMENT_LOG_ONLY) != null) {
- Log.e(TAG,
- String.format("Runner will log the tests without running tests."
- + " If this cause a test run to fail, please report to"
- + " crbug.com/754015. Arguments: %s",
- arguments.toString()));
- }
- super.onStart();
- }
- }
-
- // TODO(yolandyan): Move this to test harness side once this class gets removed
- private void addTestListPackage(Bundle bundle) {
- PackageManager pm = getContext().getPackageManager();
- InstrumentationInfo info;
- try {
- info = pm.getInstrumentationInfo(getComponentName(), PackageManager.GET_META_DATA);
- } catch (NameNotFoundException e) {
- Log.e(TAG, String.format("Could not find component %s", getComponentName()));
- throw new RuntimeException(e);
- }
- Bundle metaDataBundle = info.metaData;
- if (metaDataBundle != null && metaDataBundle.getString(LIST_TESTS_PACKAGE_FLAG) != null) {
- bundle.putString(
- ARGUMENT_TEST_PACKAGE, metaDataBundle.getString(LIST_TESTS_PACKAGE_FLAG));
- }
- }
-
- private void listTests() {
- Bundle results = new Bundle();
- TestListInstrumentationRunListener listener = new TestListInstrumentationRunListener();
- try {
- TestExecutor.Builder executorBuilder = new TestExecutor.Builder(this);
- executorBuilder.addRunListener(listener);
- Bundle junit3Arguments = new Bundle(InstrumentationRegistry.getArguments());
- junit3Arguments.putString(ARGUMENT_NOT_ANNOTATION, "org.junit.runner.RunWith");
- addTestListPackage(junit3Arguments);
- TestRequest listJUnit3TestRequest = createListTestRequest(junit3Arguments);
- results = executorBuilder.build().execute(listJUnit3TestRequest);
-
- Bundle junit4Arguments = new Bundle(InstrumentationRegistry.getArguments());
- junit4Arguments.putString(ARGUMENT_ANNOTATION, "org.junit.runner.RunWith");
- addTestListPackage(junit4Arguments);
-
- // Do not use Log runner from android test support.
- //
- // Test logging and execution skipping is handled by BaseJUnit4ClassRunner,
- // having ARGUMENT_LOG_ONLY in argument bundle here causes AndroidJUnitRunner
- // to use its own log-only class runner instead of BaseJUnit4ClassRunner.
- junit4Arguments.remove(ARGUMENT_LOG_ONLY);
-
- TestRequest listJUnit4TestRequest = createListTestRequest(junit4Arguments);
- results.putAll(executorBuilder.build().execute(listJUnit4TestRequest));
- listener.saveTestsToJson(
- InstrumentationRegistry.getArguments().getString(LIST_ALL_TESTS_FLAG));
- } catch (IOException | RuntimeException e) {
- String msg = "Fatal exception when running tests";
- Log.e(TAG, msg, e);
- // report the exception to instrumentation out
- results.putString(Instrumentation.REPORT_KEY_STREAMRESULT,
- msg + "\n" + Log.getStackTraceString(e));
- }
- finish(Activity.RESULT_OK, results);
- }
-
- private TestRequest createListTestRequest(Bundle arguments) {
- RunnerArgs runnerArgs =
- new RunnerArgs.Builder().fromManifest(this).fromBundle(arguments).build();
- TestRequestBuilder builder = new IncrementalInstallTestRequestBuilder(this, arguments);
- builder.addFromRunnerArgs(runnerArgs);
- builder.addApkToScan(getContext().getPackageCodePath());
- return builder.build();
- }
-
- static boolean shouldListTests(Bundle arguments) {
- return arguments != null && arguments.getString(LIST_ALL_TESTS_FLAG) != null;
- }
-
- /**
- * Wraps TestRequestBuilder to make it work with incremental install.
- */
- private static class IncrementalInstallTestRequestBuilder extends TestRequestBuilder {
- boolean mHasClassList;
-
- public IncrementalInstallTestRequestBuilder(Instrumentation instr, Bundle bundle) {
- super(instr, bundle);
- }
-
- @Override
- public TestRequestBuilder addTestClass(String className) {
- mHasClassList = true;
- return super.addTestClass(className);
- }
-
- @Override
- public TestRequestBuilder addTestMethod(String testClassName, String testMethodName) {
- mHasClassList = true;
- return super.addTestMethod(testClassName, testMethodName);
- }
-
- @Override
- public TestRequest build() {
- // See crbug://841695. TestLoader.isTestClass is incorrectly deciding that
- // InstrumentationTestSuite is a test class.
- removeTestClass("android.test.InstrumentationTestSuite");
- // If a test class was requested, then no need to iterate class loader.
- if (mHasClassList) {
- return super.build();
- }
- maybeScanIncrementalClasspath();
- return super.build();
- }
-
- private void maybeScanIncrementalClasspath() {
- DexFile[] incrementalJars = null;
- try {
- Class<?> bootstrapClass =
- Class.forName("org.chromium.incrementalinstall.BootstrapApplication");
- incrementalJars =
- (DexFile[]) bootstrapClass.getDeclaredField("sIncrementalDexFiles")
- .get(null);
- } catch (Exception e) {
- // Not an incremental apk.
- }
- if (incrementalJars != null) {
- // builder.addApkToScan uses new DexFile(path) under the hood, which on Dalvik OS's
- // assumes that the optimized dex is in the default location (crashes).
- // Perform our own dex file scanning instead as a workaround.
- addTestClasses(incrementalJars, this);
- }
- }
-
- private boolean startsWithAny(String str, String[] prefixes) {
- for (String prefix : prefixes) {
- if (str.startsWith(prefix)) {
- return true;
- }
- }
- return false;
- }
-
- private void addTestClasses(DexFile[] dexFiles, TestRequestBuilder builder) {
- Log.i(TAG, "Scanning incremental classpath.");
- String[] excludedPrefixes;
- try {
- Field excludedPackagesField =
- TestRequestBuilder.class.getDeclaredField("DEFAULT_EXCLUDED_PACKAGES");
- excludedPackagesField.setAccessible(true);
- excludedPrefixes = (String[]) excludedPackagesField.get(null);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
-
- // Mirror TestRequestBuilder.getClassNamesFromClassPath().
- TestLoader loader = new TestLoader();
- for (DexFile dexFile : dexFiles) {
- Enumeration<String> classNames = dexFile.entries();
- while (classNames.hasMoreElements()) {
- String className = classNames.nextElement();
- if (!className.contains("$") && !startsWithAny(className, excludedPrefixes)
- && loader.loadIfTest(className) != null) {
- addTestClass(className);
- }
- }
- }
- }
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/BaseChromiumRunnerCommon.java b/base/test/android/javatests/src/org/chromium/base/test/BaseChromiumRunnerCommon.java
deleted file mode 100644
index e5eb273..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/BaseChromiumRunnerCommon.java
+++ /dev/null
@@ -1,162 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test;
-
-import android.content.Context;
-import android.content.ContextWrapper;
-import android.content.SharedPreferences;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager;
-import android.support.v4.content.ContextCompat;
-
-import org.chromium.android.support.PackageManagerWrapper;
-import org.chromium.base.Log;
-import org.chromium.base.annotations.MainDex;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.Serializable;
-import java.lang.reflect.Field;
-import java.util.Arrays;
-import java.util.Comparator;
-
-/**
- * Functionality common to the JUnit3 and JUnit4 runners.
- */
-@MainDex
-class BaseChromiumRunnerCommon {
- private static final String TAG = "base_test";
-
- /**
- * A ContextWrapper that allows multidex test APKs to extract secondary dexes into
- * the APK under test's data directory.
- */
- @MainDex
- static class MultiDexContextWrapper extends ContextWrapper {
- private Context mAppContext;
-
- MultiDexContextWrapper(Context instrContext, Context appContext) {
- super(instrContext);
- mAppContext = appContext;
- }
-
- @Override
- public File getFilesDir() {
- return mAppContext.getFilesDir();
- }
-
- @Override
- public SharedPreferences getSharedPreferences(String name, int mode) {
- return mAppContext.getSharedPreferences(name, mode);
- }
-
- @Override
- public PackageManager getPackageManager() {
- return new PackageManagerWrapper(super.getPackageManager()) {
- @Override
- public ApplicationInfo getApplicationInfo(String packageName, int flags) {
- try {
- ApplicationInfo ai = super.getApplicationInfo(packageName, flags);
- if (packageName.equals(getPackageName())) {
- File dataDir = new File(
- ContextCompat.getCodeCacheDir(mAppContext), "test-multidex");
- if (!dataDir.exists() && !dataDir.mkdirs()) {
- throw new IOException(String.format(
- "Unable to create test multidex directory \"%s\"",
- dataDir.getPath()));
- }
- ai.dataDir = dataDir.getPath();
- }
- return ai;
- } catch (Exception e) {
- Log.e(TAG, "Failed to get application info for %s", packageName, e);
- }
- return null;
- }
- };
- }
- }
-
- /**
- * Ensure all test dex entries precede app dex entries.
- *
- * @param cl ClassLoader to modify. Assumed to be a derivative of
- * {@link dalvik.system.BaseDexClassLoader}. If this isn't
- * the case, reordering will fail.
- */
- static void reorderDexPathElements(ClassLoader cl, Context context, Context targetContext) {
- try {
- Log.i(TAG,
- "Reordering dex files. If you're building a multidex test APK and see a "
- + "class resolving to an unexpected implementation, this may be why.");
- Field pathListField = findField(cl, "pathList");
- Object dexPathList = pathListField.get(cl);
- Field dexElementsField = findField(dexPathList, "dexElements");
- Object[] dexElementsList = (Object[]) dexElementsField.get(dexPathList);
- Arrays.sort(dexElementsList,
- new DexListReorderingComparator(
- context.getPackageName(), targetContext.getPackageName()));
- dexElementsField.set(dexPathList, dexElementsList);
- } catch (Exception e) {
- Log.e(TAG, "Failed to reorder dex elements for testing.", e);
- }
- }
-
- /**
- * Comparator for sorting dex list entries.
- *
- * Using this to sort a list of dex list entries will result in the following order:
- * - Strings that contain neither the test package nor the app package in lexicographical
- * order.
- * - Strings that contain the test package in lexicographical order.
- * - Strings that contain the app package but not the test package in lexicographical order.
- */
- private static class DexListReorderingComparator implements Comparator<Object>, Serializable {
- private String mTestPackage;
- private String mAppPackage;
-
- public DexListReorderingComparator(String testPackage, String appPackage) {
- mTestPackage = testPackage;
- mAppPackage = appPackage;
- }
-
- @Override
- public int compare(Object o1, Object o2) {
- String s1 = o1.toString();
- String s2 = o2.toString();
- if (s1.contains(mTestPackage)) {
- if (!s2.contains(mTestPackage)) {
- if (s2.contains(mAppPackage)) {
- return -1;
- } else {
- return 1;
- }
- }
- } else if (s1.contains(mAppPackage)) {
- if (s2.contains(mTestPackage)) {
- return 1;
- } else if (!s2.contains(mAppPackage)) {
- return 1;
- }
- } else if (s2.contains(mTestPackage) || s2.contains(mAppPackage)) {
- return -1;
- }
- return s1.compareTo(s2);
- }
- }
-
- private static Field findField(Object instance, String name) throws NoSuchFieldException {
- for (Class<?> clazz = instance.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
- try {
- Field f = clazz.getDeclaredField(name);
- f.setAccessible(true);
- return f;
- } catch (NoSuchFieldException e) {
- }
- }
- throw new NoSuchFieldException(
- "Unable to find field " + name + " in " + instance.getClass());
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/BaseJUnit4ClassRunner.java b/base/test/android/javatests/src/org/chromium/base/test/BaseJUnit4ClassRunner.java
deleted file mode 100644
index 102e082..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/BaseJUnit4ClassRunner.java
+++ /dev/null
@@ -1,242 +0,0 @@
-// Copyright 2016 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.
-
-package org.chromium.base.test;
-
-import static org.chromium.base.test.BaseChromiumAndroidJUnitRunner.shouldListTests;
-
-import android.content.Context;
-import android.support.test.InstrumentationRegistry;
-import android.support.test.internal.runner.junit4.AndroidJUnit4ClassRunner;
-import android.support.test.internal.util.AndroidRunnerParams;
-
-import org.junit.runner.Description;
-import org.junit.runner.notification.RunNotifier;
-import org.junit.runners.model.FrameworkMethod;
-import org.junit.runners.model.InitializationError;
-import org.junit.runners.model.Statement;
-
-import org.chromium.base.CollectionUtil;
-import org.chromium.base.CommandLine;
-import org.chromium.base.ContextUtils;
-import org.chromium.base.Log;
-import org.chromium.base.test.BaseTestResult.PreTestHook;
-import org.chromium.base.test.util.DisableIfSkipCheck;
-import org.chromium.base.test.util.ManualSkipCheck;
-import org.chromium.base.test.util.MinAndroidSdkLevelSkipCheck;
-import org.chromium.base.test.util.RestrictionSkipCheck;
-import org.chromium.base.test.util.SkipCheck;
-
-import java.io.File;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * A custom runner for JUnit4 tests that checks requirements to conditionally ignore tests.
- *
- * This ClassRunner imports from AndroidJUnit4ClassRunner which is a hidden but accessible
- * class. The reason is that default JUnit4 runner for Android is a final class,
- * AndroidJUnit4. We need to extends an inheritable class to change {@link #runChild}
- * and {@link #isIgnored} to add SkipChecks and PreTesthook.
- */
-public class BaseJUnit4ClassRunner extends AndroidJUnit4ClassRunner {
- private static final String TAG = "BaseJUnit4ClassRunnr";
- private final List<SkipCheck> mSkipChecks;
- private final List<PreTestHook> mPreTestHooks;
-
- private static final String EXTRA_TRACE_FILE =
- "org.chromium.base.test.BaseJUnit4ClassRunner.TraceFile";
-
- /**
- * Create a BaseJUnit4ClassRunner to run {@code klass} and initialize values
- *
- * @throws InitializationError if the test class malformed
- */
- public BaseJUnit4ClassRunner(final Class<?> klass) throws InitializationError {
- this(klass, null, null);
- }
-
- /**
- * Create a BaseJUnit4ClassRunner to run {@code klass} and initialize values.
- *
- * To add more SkipCheck or PreTestHook in subclass, create Lists of checks and hooks,
- * pass them into the super constructors. If you want make a subclass extendable by other
- * class runners, you also have to create a constructor similar to the following one that
- * merges default checks or hooks with this checks and hooks passed in by constructor.
- *
- * <pre>
- * <code>
- * e.g.
- * public ChildRunner extends BaseJUnit4ClassRunner {
- * public ChildRunner(final Class<?> klass) {
- * throws InitializationError {
- * this(klass, null, null);
- * }
- *
- * public ChildRunner(
- * final Class<?> klass, List<SkipCheck> checks, List<PreTestHook> hook) {
- * throws InitializationError {
- * super(klass, mergeList(
- * checks, defaultSkipChecks()), mergeList(hooks, DEFAULT_HOOKS));
- * }
- *
- * public List<SkipCheck> defaultSkipChecks() {...}
- *
- * public List<PreTestHook> defaultPreTestHooks() {...}
- * </code>
- * </pre>
- *
- * @throws InitializationError if the test class malformed
- */
- public BaseJUnit4ClassRunner(
- final Class<?> klass, List<SkipCheck> checks, List<PreTestHook> hooks)
- throws InitializationError {
- super(klass,
- new AndroidRunnerParams(InstrumentationRegistry.getInstrumentation(),
- InstrumentationRegistry.getArguments(), false, 0L, false));
-
- String traceOutput = InstrumentationRegistry.getArguments().getString(EXTRA_TRACE_FILE);
-
- if (traceOutput != null) {
- File traceOutputFile = new File(traceOutput);
- File traceOutputDir = traceOutputFile.getParentFile();
-
- if (traceOutputDir != null) {
- if (traceOutputDir.exists() || traceOutputDir.mkdirs()) {
- TestTraceEvent.enable(traceOutputFile);
- }
- }
- }
-
- mSkipChecks = mergeList(checks, defaultSkipChecks());
- mPreTestHooks = mergeList(hooks, defaultPreTestHooks());
- }
-
- /**
- * Merge two List into a new ArrayList.
- *
- * Used to merge the default SkipChecks/PreTestHooks with the subclasses's
- * SkipChecks/PreTestHooks.
- */
- protected static final <T> List<T> mergeList(List<T> listA, List<T> listB) {
- List<T> l = new ArrayList<>();
- if (listA != null) {
- l.addAll(listA);
- }
- if (listB != null) {
- l.addAll(listB);
- }
- return l;
- }
-
- @Override
- protected void collectInitializationErrors(List<Throwable> errors) {
- super.collectInitializationErrors(errors);
- // Log any initialization errors to help debugging, as the host-side test runner can get
- // confused by the thrown exception.
- if (!errors.isEmpty()) {
- Log.e(TAG, "Initialization errors in %s: %s", getTestClass().getName(), errors);
- }
- }
-
- /**
- * Change this static function to add or take out default {@code SkipCheck}s.
- */
- private static List<SkipCheck> defaultSkipChecks() {
- return CollectionUtil.newArrayList(
- new RestrictionSkipCheck(InstrumentationRegistry.getTargetContext()),
- new MinAndroidSdkLevelSkipCheck(), new DisableIfSkipCheck(), new ManualSkipCheck());
- }
-
- /**
- * Change this static function to add or take out default {@code PreTestHook}s.
- */
- private static List<PreTestHook> defaultPreTestHooks() {
- return null;
- }
-
- /**
- * Evaluate whether a FrameworkMethod is ignored based on {@code SkipCheck}s.
- */
- @Override
- protected boolean isIgnored(FrameworkMethod method) {
- return super.isIgnored(method) || shouldSkip(method);
- }
-
- /**
- * Run test with or without execution based on bundle arguments.
- */
- @Override
- public void run(RunNotifier notifier) {
- ContextUtils.initApplicationContext(
- InstrumentationRegistry.getTargetContext().getApplicationContext());
- if (shouldListTests(InstrumentationRegistry.getArguments())) {
- for (Description child : getDescription().getChildren()) {
- notifier.fireTestStarted(child);
- notifier.fireTestFinished(child);
- }
- } else {
- if (!CommandLine.isInitialized()) {
- initCommandLineForTest();
- }
- super.run(notifier);
- }
- }
-
- /**
- * Override this method to change how test class runner initiate commandline flags
- */
- protected void initCommandLineForTest() {
- CommandLine.init(null);
- }
-
- @Override
- protected void runChild(FrameworkMethod method, RunNotifier notifier) {
- String testName = method.getName();
- TestTraceEvent.begin(testName);
-
- runPreTestHooks(method);
-
- super.runChild(method, notifier);
-
- TestTraceEvent.end(testName);
-
- // A new instance of BaseJUnit4ClassRunner is created on the device
- // for each new method, so runChild will only be called once. Thus, we
- // can disable tracing, and dump the output, once we get here.
- TestTraceEvent.disable();
- }
-
- /**
- * Loop through all the {@code PreTestHook}s to run them
- */
- private void runPreTestHooks(FrameworkMethod frameworkMethod) {
- Method testMethod = frameworkMethod.getMethod();
- Context targetContext = InstrumentationRegistry.getTargetContext();
- for (PreTestHook hook : mPreTestHooks) {
- hook.run(targetContext, testMethod);
- }
- }
-
- /**
- * Loop through all the {@code SkipCheck}s to confirm whether a test should be ignored
- */
- private boolean shouldSkip(FrameworkMethod method) {
- for (SkipCheck s : mSkipChecks) {
- if (s.shouldSkip(method)) {
- return true;
- }
- }
- return false;
- }
-
- /*
- * Overriding this method to take screenshot of failure before tear down functions are run.
- */
- @Override
- protected Statement withAfters(FrameworkMethod method, Object test, Statement base) {
- return super.withAfters(method, test, new ScreenshotOnFailureStatement(base));
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/BaseTestResult.java b/base/test/android/javatests/src/org/chromium/base/test/BaseTestResult.java
deleted file mode 100644
index a80e0cc..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/BaseTestResult.java
+++ /dev/null
@@ -1,137 +0,0 @@
-// Copyright 2015 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.
-
-package org.chromium.base.test;
-
-import android.app.Instrumentation;
-import android.content.Context;
-import android.os.Bundle;
-import android.os.SystemClock;
-
-import junit.framework.TestCase;
-import junit.framework.TestResult;
-
-import org.chromium.base.Log;
-import org.chromium.base.test.util.SkipCheck;
-
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * A test result that can skip tests.
- */
-public class BaseTestResult extends TestResult {
- private static final String TAG = "base_test";
-
- private static final int SLEEP_INTERVAL_MS = 50;
- private static final int WAIT_DURATION_MS = 5000;
-
- private final Instrumentation mInstrumentation;
- private final List<SkipCheck> mSkipChecks;
- private final List<PreTestHook> mPreTestHooks;
-
- /**
- * Creates an instance of BaseTestResult.
- */
- public BaseTestResult(Instrumentation instrumentation) {
- mSkipChecks = new ArrayList<>();
- mPreTestHooks = new ArrayList<>();
- mInstrumentation = instrumentation;
- }
-
- /**
- * An interface for classes that have some code to run before a test. They run after
- * {@link SkipCheck}s. Provides access to the test method (and the annotations defined for it)
- * and the instrumentation context.
- */
- public interface PreTestHook {
- /**
- * @param targetContext the instrumentation context that will be used during the test.
- * @param testMethod the test method to be run.
- */
- public void run(Context targetContext, Method testMethod);
- }
-
- /**
- * Adds a check for whether a test should run.
- *
- * @param skipCheck The check to add.
- */
- public void addSkipCheck(SkipCheck skipCheck) {
- mSkipChecks.add(skipCheck);
- }
-
- /**
- * Adds hooks that will be executed before each test that runs.
- *
- * @param preTestHook The hook to add.
- */
- public void addPreTestHook(PreTestHook preTestHook) {
- mPreTestHooks.add(preTestHook);
- }
-
- protected boolean shouldSkip(TestCase test) {
- for (SkipCheck s : mSkipChecks) {
- if (s.shouldSkip(test)) return true;
- }
- return false;
- }
-
- private void runPreTestHooks(TestCase test) {
- try {
- Method testMethod = test.getClass().getMethod(test.getName());
- Context targetContext = getTargetContext();
-
- for (PreTestHook hook : mPreTestHooks) {
- hook.run(targetContext, testMethod);
- }
- } catch (NoSuchMethodException e) {
- Log.e(TAG, "Unable to run pre test hooks.", e);
- }
- }
-
- @Override
- protected void run(TestCase test) {
- runPreTestHooks(test);
-
- if (shouldSkip(test)) {
- startTest(test);
-
- Bundle skipResult = new Bundle();
- skipResult.putString("class", test.getClass().getName());
- skipResult.putString("test", test.getName());
- skipResult.putBoolean("test_skipped", true);
- mInstrumentation.sendStatus(0, skipResult);
-
- endTest(test);
- } else {
- super.run(test);
- }
- }
-
- /**
- * Gets the target context.
- *
- * On older versions of Android, getTargetContext() may initially return null, so we have to
- * wait for it to become available.
- *
- * @return The target {@link Context} if available; null otherwise.
- */
- public Context getTargetContext() {
- Context targetContext = mInstrumentation.getTargetContext();
- try {
- long startTime = SystemClock.uptimeMillis();
- // TODO(jbudorick): Convert this to CriteriaHelper once that moves to base/.
- while (targetContext == null
- && SystemClock.uptimeMillis() - startTime < WAIT_DURATION_MS) {
- Thread.sleep(SLEEP_INTERVAL_MS);
- targetContext = mInstrumentation.getTargetContext();
- }
- } catch (InterruptedException e) {
- Log.e(TAG, "Interrupted while attempting to initialize the command line.");
- }
- return targetContext;
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/ScreenshotOnFailureStatement.java b/base/test/android/javatests/src/org/chromium/base/test/ScreenshotOnFailureStatement.java
deleted file mode 100644
index 397e8ab..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/ScreenshotOnFailureStatement.java
+++ /dev/null
@@ -1,83 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test;
-
-import android.support.test.InstrumentationRegistry;
-import android.support.test.uiautomator.UiDevice;
-
-import org.junit.runners.model.Statement;
-
-import org.chromium.base.Log;
-
-import java.io.File;
-
-/**
- * Statement that captures screenshots if |base| statement fails.
- *
- * If --screenshot-path commandline flag is given, this |Statement|
- * will save a screenshot to the specified path in the case of a test failure.
- */
-public class ScreenshotOnFailureStatement extends Statement {
- private static final String TAG = "ScreenshotOnFail";
-
- private static final String EXTRA_SCREENSHOT_FILE =
- "org.chromium.base.test.ScreenshotOnFailureStatement.ScreenshotFile";
-
- private final Statement mBase;
-
- public ScreenshotOnFailureStatement(final Statement base) {
- mBase = base;
- }
-
- @Override
- public void evaluate() throws Throwable {
- try {
- mBase.evaluate();
- } catch (Throwable e) {
- takeScreenshot();
- throw e;
- }
- }
-
- private void takeScreenshot() {
- String screenshotFilePath =
- InstrumentationRegistry.getArguments().getString(EXTRA_SCREENSHOT_FILE);
- if (screenshotFilePath == null) {
- Log.d(TAG,
- String.format("Did not save screenshot of failure. Must specify %s "
- + "instrumentation argument to enable this feature.",
- EXTRA_SCREENSHOT_FILE));
- return;
- }
-
- UiDevice uiDevice = null;
- try {
- uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
- } catch (RuntimeException ex) {
- Log.d(TAG, "Failed to initialize UiDevice", ex);
- return;
- }
-
- File screenshotFile = new File(screenshotFilePath);
- File screenshotDir = screenshotFile.getParentFile();
- if (screenshotDir == null) {
- Log.d(TAG,
- String.format(
- "Failed to create parent directory for %s. Can't save screenshot.",
- screenshotFile));
- return;
- }
- if (!screenshotDir.exists()) {
- if (!screenshotDir.mkdirs()) {
- Log.d(TAG,
- String.format(
- "Failed to create %s. Can't save screenshot.", screenshotDir));
- return;
- }
- }
- Log.d(TAG, String.format("Saving screenshot of test failure, %s", screenshotFile));
- uiDevice.takeScreenshot(screenshotFile);
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/SetUpStatement.java b/base/test/android/javatests/src/org/chromium/base/test/SetUpStatement.java
deleted file mode 100644
index 30ac2b6..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/SetUpStatement.java
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test;
-
-import org.junit.rules.TestRule;
-import org.junit.runners.model.Statement;
-
-/**
- * Custom Statement for SetUpTestRules.
- *
- * Calls {@link SetUpTestRule#setUp} before evaluating {@link SetUpTestRule#base} if
- * {@link SetUpTestRule#shouldSetUp} is true
- */
-public class SetUpStatement extends Statement {
- private final Statement mBase;
- private final SetUpTestRule<? extends TestRule> mSetUpTestRule;
- private final boolean mShouldSetUp;
-
- public SetUpStatement(
- final Statement base, SetUpTestRule<? extends TestRule> callback, boolean shouldSetUp) {
- mBase = base;
- mSetUpTestRule = callback;
- mShouldSetUp = shouldSetUp;
- }
-
- @Override
- public void evaluate() throws Throwable {
- if (mShouldSetUp) {
- mSetUpTestRule.setUp();
- }
- mBase.evaluate();
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/SetUpTestRule.java b/base/test/android/javatests/src/org/chromium/base/test/SetUpTestRule.java
deleted file mode 100644
index 57dd8db..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/SetUpTestRule.java
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test;
-
-import org.junit.rules.TestRule;
-
-/**
- * An interface for TestRules that can be configured to automatically run set-up logic prior
- * to @Before.
- *
- * TestRules that implement this interface should return a {@link SetUpStatement} from their {@link
- * TestRule#apply} method
- *
- * @param <T> TestRule type that implements this SetUpTestRule
- */
-public interface SetUpTestRule<T extends TestRule> {
- /**
- * Set whether the TestRule should run setUp automatically.
- *
- * So TestRule can be declared in test like this:
- * <code>
- * @Rule TestRule mRule = new MySetUpTestRule().shouldSetUp(true);
- * </code>
- *
- * @return itself to chain up the calls for convenience
- */
- T shouldSetUp(boolean runSetUp);
-
- /**
- * Specify setUp action in this method
- */
- void setUp();
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/TestChildProcessConnection.java b/base/test/android/javatests/src/org/chromium/base/test/TestChildProcessConnection.java
deleted file mode 100644
index ae91b44..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/TestChildProcessConnection.java
+++ /dev/null
@@ -1,87 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test;
-
-import android.content.ComponentName;
-import android.content.Intent;
-import android.os.Bundle;
-
-import org.chromium.base.process_launcher.ChildProcessConnection;
-
-/** An implementation of ChildProcessConnection that does not connect to a real service. */
-public class TestChildProcessConnection extends ChildProcessConnection {
- private static class MockChildServiceConnection
- implements ChildProcessConnection.ChildServiceConnection {
- private boolean mBound;
-
- @Override
- public boolean bind() {
- mBound = true;
- return true;
- }
-
- @Override
- public void unbind() {
- mBound = false;
- }
-
- @Override
- public boolean isBound() {
- return mBound;
- }
- }
-
- private int mPid;
- private boolean mConnected;
- private ServiceCallback mServiceCallback;
-
- /**
- * Creates a mock binding corresponding to real ManagedChildProcessConnection after the
- * connection is established: with initial binding bound and no strong binding.
- */
- public TestChildProcessConnection(ComponentName serviceName, boolean bindToCaller,
- boolean bindAsExternalService, Bundle serviceBundle) {
- super(null /* context */, serviceName, bindToCaller, bindAsExternalService, serviceBundle,
- new ChildServiceConnectionFactory() {
- @Override
- public ChildServiceConnection createConnection(Intent bindIntent, int bindFlags,
- ChildServiceConnectionDelegate delegate) {
- return new MockChildServiceConnection();
- }
- });
- }
-
- public void setPid(int pid) {
- mPid = pid;
- }
-
- @Override
- public int getPid() {
- return mPid;
- }
-
- // We don't have a real service so we have to mock the connection status.
- @Override
- public void start(boolean useStrongBinding, ServiceCallback serviceCallback) {
- super.start(useStrongBinding, serviceCallback);
- mConnected = true;
- mServiceCallback = serviceCallback;
- }
-
- @Override
- public void stop() {
- super.stop();
- mConnected = false;
- }
-
- @Override
- public boolean isConnected() {
- return mConnected;
- }
-
- public ServiceCallback getServiceCallback() {
- return mServiceCallback;
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/TestListInstrumentationRunListener.java b/base/test/android/javatests/src/org/chromium/base/test/TestListInstrumentationRunListener.java
deleted file mode 100644
index 8cde570..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/TestListInstrumentationRunListener.java
+++ /dev/null
@@ -1,142 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test;
-
-import android.support.test.internal.runner.listener.InstrumentationRunListener;
-
-import org.json.JSONArray;
-import org.json.JSONObject;
-import org.junit.runner.Description;
-
-import org.chromium.base.Log;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * A RunListener that list out all the test information into a json file.
- */
-public class TestListInstrumentationRunListener extends InstrumentationRunListener {
- private static final String TAG = "TestListRunListener";
- private static final Set<String> SKIP_METHODS = new HashSet<>(
- Arrays.asList(new String[] {"toString", "hashCode", "annotationType", "equals"}));
-
- private final Map<Class<?>, JSONObject> mTestClassJsonMap = new HashMap<>();
-
- /**
- * Store the test method description to a Map at the beginning of a test run.
- */
- @Override
- public void testStarted(Description desc) throws Exception {
- if (mTestClassJsonMap.containsKey(desc.getTestClass())) {
- ((JSONArray) mTestClassJsonMap.get(desc.getTestClass()).get("methods"))
- .put(getTestMethodJSON(desc));
- } else {
- Class<?> testClass = desc.getTestClass();
- mTestClassJsonMap.put(desc.getTestClass(), new JSONObject()
- .put("class", testClass.getName())
- .put("superclass", testClass.getSuperclass().getName())
- .put("annotations",
- getAnnotationJSON(Arrays.asList(testClass.getAnnotations())))
- .put("methods", new JSONArray().put(getTestMethodJSON(desc))));
- }
- }
-
- /**
- * Create a JSONArray with all the test class JSONObjects and save it to listed output path.
- */
- public void saveTestsToJson(String outputPath) throws IOException {
- Writer writer = null;
- File file = new File(outputPath);
- try {
- writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
- JSONArray allTestClassesJSON = new JSONArray(mTestClassJsonMap.values());
- writer.write(allTestClassesJSON.toString());
- } catch (IOException e) {
- Log.e(TAG, "failed to write json to file", e);
- throw e;
- } finally {
- if (writer != null) {
- try {
- writer.close();
- } catch (IOException e) {
- // Intentionally ignore IOException when closing writer
- }
- }
- }
- }
-
- /**
- * Return a JSONOject that represent a Description of a method".
- */
- static JSONObject getTestMethodJSON(Description desc) throws Exception {
- return new JSONObject()
- .put("method", desc.getMethodName())
- .put("annotations", getAnnotationJSON(desc.getAnnotations()));
- }
-
- /**
- * Create a JSONObject that represent a collection of anntations.
- *
- * For example, for the following group of annotations for ExampleClass
- * <code>
- * @A
- * @B(message = "hello", level = 3)
- * public class ExampleClass() {}
- * </code>
- *
- * This method would return a JSONObject as such:
- * <code>
- * {
- * "A": {},
- * "B": {
- * "message": "hello",
- * "level": "3"
- * }
- * }
- * </code>
- *
- * The method accomplish this by though through each annotation and reflectively call the
- * annotation's method to get the element value, with exceptions to methods like "equals()"
- * or "hashCode".
- */
- static JSONObject getAnnotationJSON(Collection<Annotation> annotations)
- throws Exception {
- JSONObject annotationsJsons = new JSONObject();
- for (Annotation a : annotations) {
- JSONObject elementJsonObject = new JSONObject();
- for (Method method : a.annotationType().getMethods()) {
- if (SKIP_METHODS.contains(method.getName())) {
- continue;
- }
- try {
- Object value = method.invoke(a);
- if (value == null) {
- elementJsonObject.put(method.getName(), null);
- } else {
- elementJsonObject.put(method.getName(),
- value.getClass().isArray()
- ? new JSONArray(Arrays.asList((Object[]) value))
- : value.toString());
- }
- } catch (IllegalArgumentException e) {
- }
- }
- annotationsJsons.put(a.annotationType().getSimpleName(), elementJsonObject);
- }
- return annotationsJsons;
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/TestTraceEvent.java b/base/test/android/javatests/src/org/chromium/base/test/TestTraceEvent.java
deleted file mode 100644
index 5e0f6b3..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/TestTraceEvent.java
+++ /dev/null
@@ -1,168 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import org.chromium.base.Log;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.PrintStream;
-
-/**
- * TestTraceEvent is a modified version of TraceEvent, intended for tracing test runs.
- */
-public class TestTraceEvent {
- private static final String TAG = "TestTraceEvent";
-
- /** The event types understood by the trace scripts. */
- private enum EventType {
- BEGIN("B"),
- END("E"),
- INSTANT("I");
-
- private final String mTypeStr;
-
- EventType(String typeStr) {
- mTypeStr = typeStr;
- }
-
- @Override
- public String toString() {
- return mTypeStr;
- }
- }
-
- // Locks internal fields.
- private static final Object sLock = new Object();
-
- private static File sOutputFile;
-
- private static boolean sEnabled;
-
- // A list of trace event strings.
- private static JSONArray sTraceStrings;
-
- /**
- * Enable tracing, and set a specific output file. If tracing was previously enabled and
- * disabled, that data is cleared.
- *
- * @param file Which file to append the trace data to.
- */
- public static void enable(File outputFile) {
- synchronized (sLock) {
- if (sEnabled) return;
-
- sEnabled = true;
- sOutputFile = outputFile;
- sTraceStrings = new JSONArray();
- }
- }
-
- /**
- * Disabling of tracing will dump trace data to the system log.
- */
- public static void disable() {
- synchronized (sLock) {
- if (!sEnabled) return;
-
- sEnabled = false;
- dumpTraceOutput();
- sTraceStrings = null;
- }
- }
-
- /**
- * @return True if tracing is enabled, false otherwise.
- */
- public static boolean isEnabled() {
- synchronized (sLock) {
- return sEnabled;
- }
- }
-
- /**
- * Record an "instant" trace event. E.g. "screen update happened".
- */
- public static void instant(String name) {
- synchronized (sLock) {
- if (!sEnabled) return;
-
- saveTraceString(name, name.hashCode(), EventType.INSTANT);
- }
- }
-
- /**
- * Record an "begin" trace event. Begin trace events should have a matching end event (recorded
- * by calling {@link #end(String)}).
- */
- public static void begin(String name) {
- synchronized (sLock) {
- if (!sEnabled) return;
-
- saveTraceString(name, name.hashCode(), EventType.BEGIN);
- }
- }
-
- /**
- * Record an "end" trace event, to match a begin event (recorded by calling {@link
- * #begin(String)}). The time delta between begin and end is usually interesting to graph code.
- */
- public static void end(String name) {
- synchronized (sLock) {
- if (!sEnabled) return;
-
- saveTraceString(name, name.hashCode(), EventType.END);
- }
- }
-
- /**
- * Save a trace event as a JSON dict.
- *
- * @param name The trace data.
- * @param id An identifier for the event, to be saved as the thread ID.
- * @param type the type of trace event (B, E, I).
- */
- private static void saveTraceString(String name, long id, EventType type) {
- // We use System.currentTimeMillis() because it agrees with the value of
- // the $EPOCHREALTIME environment variable. The Python test runner code
- // uses that variable to synchronize timing.
- long timeMicroseconds = System.currentTimeMillis() * 1000;
-
- try {
- JSONObject traceObj = new JSONObject();
- traceObj.put("cat", "Java");
- traceObj.put("ts", timeMicroseconds);
- traceObj.put("ph", type);
- traceObj.put("name", name);
- traceObj.put("tid", id);
-
- sTraceStrings.put(traceObj);
- } catch (JSONException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Dump all tracing data we have saved up to the log.
- * Output as JSON for parsing convenience.
- */
- private static void dumpTraceOutput() {
- try {
- PrintStream stream = new PrintStream(new FileOutputStream(sOutputFile, true));
- try {
- stream.print(sTraceStrings);
- } finally {
- if (stream != null) stream.close();
- }
- } catch (FileNotFoundException ex) {
- Log.e(TAG, "Unable to dump trace data to output file.");
- }
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/params/BaseJUnit4RunnerDelegate.java b/base/test/android/javatests/src/org/chromium/base/test/params/BaseJUnit4RunnerDelegate.java
deleted file mode 100644
index c0dcd46..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/params/BaseJUnit4RunnerDelegate.java
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test.params;
-
-import org.junit.runners.model.FrameworkMethod;
-import org.junit.runners.model.InitializationError;
-
-import org.chromium.base.test.BaseJUnit4ClassRunner;
-import org.chromium.base.test.params.ParameterizedRunner.ParameterizedTestInstantiationException;
-
-import java.util.List;
-
-/**
- * Class runner delegate that extends BaseJUnit4ClassRunner
- */
-public final class BaseJUnit4RunnerDelegate
- extends BaseJUnit4ClassRunner implements ParameterizedRunnerDelegate {
- private ParameterizedRunnerDelegateCommon mDelegateCommon;
-
- public BaseJUnit4RunnerDelegate(Class<?> klass,
- ParameterizedRunnerDelegateCommon delegateCommon) throws InitializationError {
- super(klass);
- mDelegateCommon = delegateCommon;
- }
-
- @Override
- public void collectInitializationErrors(List<Throwable> errors) {
- ParameterizedRunnerDelegateCommon.collectInitializationErrors(errors);
- }
-
- @Override
- public List<FrameworkMethod> computeTestMethods() {
- return mDelegateCommon.computeTestMethods();
- }
-
- @Override
- public Object createTest() throws ParameterizedTestInstantiationException {
- return mDelegateCommon.createTest();
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/params/BlockJUnit4RunnerDelegate.java b/base/test/android/javatests/src/org/chromium/base/test/params/BlockJUnit4RunnerDelegate.java
deleted file mode 100644
index 7c948bb..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/params/BlockJUnit4RunnerDelegate.java
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test.params;
-
-import org.junit.runners.BlockJUnit4ClassRunner;
-import org.junit.runners.model.FrameworkMethod;
-import org.junit.runners.model.InitializationError;
-
-import org.chromium.base.test.params.ParameterizedRunner.ParameterizedTestInstantiationException;
-
-import java.util.List;
-
-/**
- * Parameterized class runner delegate that extends BlockJUnit4ClassRunner
- */
-public final class BlockJUnit4RunnerDelegate
- extends BlockJUnit4ClassRunner implements ParameterizedRunnerDelegate {
- private ParameterizedRunnerDelegateCommon mDelegateCommon;
-
- public BlockJUnit4RunnerDelegate(Class<?> klass,
- ParameterizedRunnerDelegateCommon delegateCommon) throws InitializationError {
- super(klass);
- mDelegateCommon = delegateCommon;
- }
-
- @Override
- public void collectInitializationErrors(List<Throwable> errors) {
- ParameterizedRunnerDelegateCommon.collectInitializationErrors(errors);
- }
-
- @Override
- public List<FrameworkMethod> computeTestMethods() {
- return mDelegateCommon.computeTestMethods();
- }
-
- @Override
- public Object createTest() throws ParameterizedTestInstantiationException {
- return mDelegateCommon.createTest();
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/params/MethodParamAnnotationRule.java b/base/test/android/javatests/src/org/chromium/base/test/params/MethodParamAnnotationRule.java
deleted file mode 100644
index 2986b96..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/params/MethodParamAnnotationRule.java
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test.params;
-
-import org.junit.runners.model.Statement;
-
-import org.chromium.base.test.params.ParameterAnnotations.UseMethodParameterAfter;
-import org.chromium.base.test.params.ParameterAnnotations.UseMethodParameterBefore;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Processes {@link UseMethodParameterBefore} and {@link UseMethodParameterAfter} annotations to run
- * the corresponding methods. To use, add an instance to the test class and annotate it with
- * {@code @}{@link org.junit.Rule Rule}.
- */
-public class MethodParamAnnotationRule extends MethodParamRule {
- @Override
- protected Statement applyParameterAndValues(final Statement base, Object target,
- Class<? extends ParameterProvider> parameterProvider, List<Object> values) {
- final List<Method> beforeMethods = new ArrayList<>();
- final List<Method> afterMethods = new ArrayList<>();
- for (Method m : target.getClass().getDeclaredMethods()) {
- if (!m.getReturnType().equals(Void.TYPE)) continue;
- if (!Modifier.isPublic(m.getModifiers())) continue;
-
- UseMethodParameterBefore beforeAnnotation =
- m.getAnnotation(UseMethodParameterBefore.class);
- if (beforeAnnotation != null && beforeAnnotation.value().equals(parameterProvider)) {
- beforeMethods.add(m);
- }
-
- UseMethodParameterAfter afterAnnotation =
- m.getAnnotation(UseMethodParameterAfter.class);
- if (afterAnnotation != null && afterAnnotation.value().equals(parameterProvider)) {
- afterMethods.add(m);
- }
- }
-
- if (beforeMethods.isEmpty() && afterMethods.isEmpty()) return base;
-
- return new Statement() {
- @Override
- public void evaluate() throws Throwable {
- for (Method m : beforeMethods) {
- m.invoke(target, values.toArray());
- }
-
- base.evaluate();
-
- for (Method m : afterMethods) {
- m.invoke(target, values.toArray());
- }
- }
- };
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/params/MethodParamRule.java b/base/test/android/javatests/src/org/chromium/base/test/params/MethodParamRule.java
deleted file mode 100644
index 440831a..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/params/MethodParamRule.java
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test.params;
-
-import org.junit.rules.MethodRule;
-import org.junit.runners.model.FrameworkMethod;
-import org.junit.runners.model.Statement;
-
-import org.chromium.base.test.params.ParameterAnnotations.UseMethodParameter;
-
-import java.util.List;
-
-/**
- * Abstract base class for rules that are applied to test methods using
- * {@link org.chromium.base.test.params.ParameterAnnotations.UseMethodParameter method parameters}.
- */
-public abstract class MethodParamRule implements MethodRule {
- @Override
- public Statement apply(final Statement base, FrameworkMethod method, Object target) {
- UseMethodParameter useParameterProvider = method.getAnnotation(UseMethodParameter.class);
- if (useParameterProvider == null) return base;
- Class<? extends ParameterProvider> parameterProvider = useParameterProvider.value();
-
- if (!(method instanceof ParameterizedFrameworkMethod)) return base;
- ParameterSet parameters = ((ParameterizedFrameworkMethod) method).getParameterSet();
- List<Object> values = parameters.getValues();
-
- return applyParameterAndValues(base, target, parameterProvider, values);
- }
-
- protected abstract Statement applyParameterAndValues(final Statement base, Object target,
- Class<? extends ParameterProvider> parameterProvider, List<Object> values);
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/params/ParameterAnnotations.java b/base/test/android/javatests/src/org/chromium/base/test/params/ParameterAnnotations.java
deleted file mode 100644
index 7918369..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/params/ParameterAnnotations.java
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test.params;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotations for Parameterized Tests
- */
-public class ParameterAnnotations {
- /**
- * Annotation for test methods to indicate associated {@link ParameterProvider}.
- * Note: the class referred to must be public and have a public default constructor.
- */
- @Retention(RetentionPolicy.RUNTIME)
- @Target(ElementType.METHOD)
- public @interface UseMethodParameter {
- Class<? extends ParameterProvider> value();
- }
-
- /**
- * Annotation for methods that should be called before running a test with method parameters.
- *
- * In order to use this, add a {@link MethodParamAnnotationRule} annotated with
- * {@code @}{@link org.junit.Rule Rule} to your test class.
- * @see ParameterProvider
- * @see UseMethodParameterAfter
- */
- @Retention(RetentionPolicy.RUNTIME)
- @Target(ElementType.METHOD)
- public @interface UseMethodParameterBefore {
- Class<? extends ParameterProvider> value();
- }
-
- /**
- * Annotation for methods that should be called after running a test with method parameters.
- *
- * In order to use this, add a {@link MethodParamAnnotationRule} annotated with
- * {@code @}{@link org.junit.Rule Rule} to your test class.
- * @see ParameterProvider
- * @see UseMethodParameterBefore
- */
- @Retention(RetentionPolicy.RUNTIME)
- @Target(ElementType.METHOD)
- public @interface UseMethodParameterAfter {
- Class<? extends ParameterProvider> value();
- }
-
- /**
- * Annotation for static field of a `List<ParameterSet>` for entire test class
- */
- @Retention(RetentionPolicy.RUNTIME)
- @Target(ElementType.FIELD)
- public @interface ClassParameter {}
-
- /**
- * Annotation for static field of a `List<ParameterSet>` of TestRule
- */
- @Retention(RetentionPolicy.RUNTIME)
- @Target(ElementType.FIELD)
- public @interface RuleParameter {}
-
- /**
- * Annotation for test class, it specifies which ParameterizeRunnerDelegate to use.
- *
- * The default ParameterizedRunnerDelegate is BaseJUnit4RunnerDelegate.class
- */
- @Retention(RetentionPolicy.RUNTIME)
- @Target(ElementType.TYPE)
- public @interface UseRunnerDelegate {
- Class<? extends ParameterizedRunnerDelegate> value();
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/params/ParameterProvider.java b/base/test/android/javatests/src/org/chromium/base/test/params/ParameterProvider.java
deleted file mode 100644
index 9bf27bd..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/params/ParameterProvider.java
+++ /dev/null
@@ -1,11 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test.params;
-
-/**
- * Generator to use generate arguments for parameterized test methods.
- * @see ParameterAnnotations.UseMethodParameter
- */
-public interface ParameterProvider { Iterable<ParameterSet> getParameters(); }
diff --git a/base/test/android/javatests/src/org/chromium/base/test/params/ParameterSet.java b/base/test/android/javatests/src/org/chromium/base/test/params/ParameterSet.java
deleted file mode 100644
index 1cdb576..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/params/ParameterSet.java
+++ /dev/null
@@ -1,129 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test.params;
-
-import org.junit.Assert;
-
-import java.io.File;
-import java.net.URI;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.Callable;
-
-/**
- * A set of parameters for one *SINGLE* test method or test class constructor.
- *
- * For example, <code>new ParameterSet().value("a", "b")</code> is intended for
- * a test method/constructor that takes in two string as arguments.
- * <code>public void testSimple(String a, String b) {...}</code>
- * or
- * <code>public MyTestClass(String a, String b) {...}</code>
- *
- * To parameterize testSimple or MyTestClass's tests, create multiple ParameterSets
- * <code>
- * static List<ParameterSet> sAllParameterSets = new ArrayList<>();
- * static {
- * sAllParameterSets.add(new ParameterSet().value("a", "b");
- * sAllParameterSets.add(new ParameterSet().value("c", "d");
- * }
- */
-public class ParameterSet {
- private List<Object> mValues;
- private String mName;
-
- public ParameterSet() {}
-
- public ParameterSet value(Object firstArg, Object... objects) {
- List<Object> parameterList = new ArrayList<Object>();
- parameterList.add(firstArg);
- parameterList.addAll(Arrays.asList(objects));
- Assert.assertTrue(
- "Can not create ParameterSet with no parameters", parameterList.size() != 0);
- mValues = validateAndCopy(parameterList);
- return this;
- }
-
- public ParameterSet name(String name) {
- mName = name;
- return this;
- }
-
- @Override
- public String toString() {
- if (mValues == null) {
- return "null";
- }
- return Arrays.toString(mValues.toArray());
- }
-
- private List<Object> validateAndCopy(List<Object> values) {
- List<Object> tempValues = new ArrayList<>();
- for (Object o : values) {
- if (o == null) {
- tempValues.add(null);
- } else {
- if (o.getClass().isPrimitive() || ACCEPTABLE_TYPES.contains(o.getClass())
- || o instanceof Callable) {
- tempValues.add(o);
- } else {
- // TODO(yolandyan): maybe come up with way to support
- // complex object while handling immutability at the
- // same time
- throw new IllegalArgumentException("Type \"%s\" is not supported in"
- + " parameterized testing at this time. Accepted types include"
- + " all primitive types along with "
- + Arrays.toString(ACCEPTABLE_TYPES.toArray(
- new String[ACCEPTABLE_TYPES.size()])));
- }
- }
- }
- return Collections.unmodifiableList(tempValues);
- }
-
- String getName() {
- if (mName == null) {
- return "";
- }
- return mName;
- }
-
- List<Object> getValues() {
- return mValues;
- }
-
- int size() {
- if (mValues == null) return 0;
- return mValues.size();
- }
-
- private static final Set<Class<?>> ACCEPTABLE_TYPES = getAcceptableTypes();
-
- /**
- * Any immutable class is acceptable.
- */
- private static Set<Class<?>> getAcceptableTypes() {
- Set<Class<?>> ret = new HashSet<Class<?>>();
- ret.add(Boolean.class);
- ret.add(Byte.class);
- ret.add(Character.class);
- ret.add(Class.class);
- ret.add(Double.class);
- ret.add(File.class);
- ret.add(Float.class);
- ret.add(Integer.class);
- ret.add(Long.class);
- ret.add(Short.class);
- ret.add(String.class);
- ret.add(URI.class);
- ret.add(URL.class);
- ret.add(Void.class);
- return ret;
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/params/ParameterizedFrameworkMethod.java b/base/test/android/javatests/src/org/chromium/base/test/params/ParameterizedFrameworkMethod.java
deleted file mode 100644
index f3333b5..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/params/ParameterizedFrameworkMethod.java
+++ /dev/null
@@ -1,94 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test.params;
-
-import org.junit.runners.model.FrameworkMethod;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-/**
- * Custom FrameworkMethod that includes a {@code ParameterSet} that
- * represents the parameters for this test method
- */
-public class ParameterizedFrameworkMethod extends FrameworkMethod {
- private ParameterSet mParameterSet;
- private String mName;
-
- public ParameterizedFrameworkMethod(
- Method method, ParameterSet parameterSet, String classParameterSetName) {
- super(method);
- mParameterSet = parameterSet;
- String postFix = "";
- if (classParameterSetName != null && !classParameterSetName.isEmpty()) {
- postFix += "_" + classParameterSetName;
- }
- if (parameterSet != null && !parameterSet.getName().isEmpty()) {
- postFix += "_" + parameterSet.getName();
- }
- mName = postFix.isEmpty() ? method.getName() : method.getName() + "_" + postFix;
- }
-
- @Override
- public String getName() {
- return mName;
- }
-
- @Override
- public Object invokeExplosively(Object target, Object... params) throws Throwable {
- if (mParameterSet != null) {
- return super.invokeExplosively(target, mParameterSet.getValues().toArray());
- }
- return super.invokeExplosively(target, params);
- }
-
- static List<FrameworkMethod> wrapAllFrameworkMethods(
- Collection<FrameworkMethod> frameworkMethods, String classParameterSetName) {
- List<FrameworkMethod> results = new ArrayList<>();
- for (FrameworkMethod frameworkMethod : frameworkMethods) {
- results.add(new ParameterizedFrameworkMethod(
- frameworkMethod.getMethod(), null, classParameterSetName));
- }
- return results;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof ParameterizedFrameworkMethod) {
- ParameterizedFrameworkMethod method = (ParameterizedFrameworkMethod) obj;
- return super.equals(obj) && method.getParameterSet().equals(getParameterSet())
- && method.getName().equals(getName());
- }
- return false;
- }
-
- /**
- * Override hashCode method to distinguish two ParameterizedFrameworkmethod with same
- * Method object.
- */
- @Override
- public int hashCode() {
- int result = 17;
- result = 31 * result + super.hashCode();
- result = 31 * result + getName().hashCode();
- if (getParameterSet() != null) {
- result = 31 * result + getParameterSet().hashCode();
- }
- return result;
- }
-
- Annotation[] getTestAnnotations() {
- // TODO(yolandyan): add annotation from the ParameterSet, enable
- // test writing to add SkipCheck for an individual parameter
- return getMethod().getAnnotations();
- }
-
- public ParameterSet getParameterSet() {
- return mParameterSet;
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/params/ParameterizedRunner.java b/base/test/android/javatests/src/org/chromium/base/test/params/ParameterizedRunner.java
deleted file mode 100644
index 113f176..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/params/ParameterizedRunner.java
+++ /dev/null
@@ -1,220 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test.params;
-
-import org.junit.Test;
-import org.junit.runner.Runner;
-import org.junit.runners.BlockJUnit4ClassRunner;
-import org.junit.runners.Suite;
-import org.junit.runners.model.FrameworkField;
-import org.junit.runners.model.TestClass;
-
-import org.chromium.base.test.params.ParameterAnnotations.ClassParameter;
-import org.chromium.base.test.params.ParameterAnnotations.UseMethodParameter;
-import org.chromium.base.test.params.ParameterAnnotations.UseRunnerDelegate;
-import org.chromium.base.test.params.ParameterizedRunnerDelegateFactory.ParameterizedRunnerDelegateInstantiationException;
-
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Locale;
-
-/**
- * ParameterizedRunner generates a list of runners for each of class parameter set in a test class.
- *
- * ParameterizedRunner looks for {@code @ClassParameter} annotation in test class and
- * generates a list of ParameterizedRunnerDelegate runners for each ParameterSet.
- */
-public final class ParameterizedRunner extends Suite {
- private final List<Runner> mRunners;
-
- /**
- * Create a ParameterizedRunner to run test class
- *
- * @param klass the Class of the test class, test class should be atomic
- * (extends only Object)
- */
- public ParameterizedRunner(Class<?> klass) throws Throwable {
- super(klass, Collections.emptyList()); // pass in empty list of runners
- validate();
- mRunners = createRunners(getTestClass());
- }
-
- @Override
- protected List<Runner> getChildren() {
- return mRunners;
- }
-
- /**
- * ParentRunner calls collectInitializationErrors() to check for errors in Test class.
- * Parameterized tests are written in unconventional ways, therefore, this method is
- * overridden and validation is done seperately.
- */
- @Override
- protected void collectInitializationErrors(List<Throwable> errors) {
- // Do not call super collectInitializationErrors
- }
-
- private void validate() throws Throwable {
- validateNoNonStaticInnerClass();
- validateOnlyOneConstructor();
- validateInstanceMethods();
- validateOnlyOneClassParameterField();
- validateAtLeastOneParameterSetField();
- }
-
- private void validateNoNonStaticInnerClass() throws Exception {
- if (getTestClass().isANonStaticInnerClass()) {
- throw new Exception("The inner class " + getTestClass().getName() + " is not static.");
- }
- }
-
- private void validateOnlyOneConstructor() throws Exception {
- if (!hasOneConstructor()) {
- throw new Exception("Test class should have exactly one public constructor");
- }
- }
-
- private boolean hasOneConstructor() {
- return getTestClass().getJavaClass().getConstructors().length == 1;
- }
-
- private void validateOnlyOneClassParameterField() {
- if (getTestClass().getAnnotatedFields(ClassParameter.class).size() > 1) {
- throw new IllegalParameterArgumentException(
- "%s class has more than one @ClassParameter, only one is allowed");
- }
- }
-
- private void validateAtLeastOneParameterSetField() {
- if (getTestClass().getAnnotatedFields(ClassParameter.class).isEmpty()
- && getTestClass().getAnnotatedMethods(UseMethodParameter.class).isEmpty()) {
- throw new IllegalArgumentException(String.format(Locale.getDefault(),
- "%s has no field annotated with @ClassParameter or method annotated with"
- + "@UseMethodParameter; it should not use ParameterizedRunner",
- getTestClass().getName()));
- }
- }
-
- private void validateInstanceMethods() throws Exception {
- if (getTestClass().getAnnotatedMethods(Test.class).size() == 0) {
- throw new Exception("No runnable methods");
- }
- }
-
- /**
- * Return a list of runner delegates through ParameterizedRunnerDelegateFactory.
- *
- * For class parameter set: each class can only have one list of class parameter sets.
- * Each parameter set will be used to create one runner.
- *
- * For method parameter set: a single list method parameter sets is associated with
- * a string tag, an immutable map of string to parameter set list will be created and
- * passed into factory for each runner delegate to create multiple tests. Only one
- * Runner will be created for a method that uses @UseMethodParameter, regardless of the
- * number of ParameterSets in the associated list.
- *
- * @return a list of runners
- * @throws ParameterizedRunnerDelegateInstantiationException if runner delegate can not
- * be instantiated with constructor reflectively
- * @throws IllegalAccessError if the field in tests are not accessible
- */
- static List<Runner> createRunners(TestClass testClass)
- throws IllegalAccessException, ParameterizedRunnerDelegateInstantiationException {
- List<ParameterSet> classParameterSetList;
- if (testClass.getAnnotatedFields(ClassParameter.class).isEmpty()) {
- classParameterSetList = new ArrayList<>();
- classParameterSetList.add(null);
- } else {
- classParameterSetList = getParameterSetList(
- testClass.getAnnotatedFields(ClassParameter.class).get(0), testClass);
- validateWidth(classParameterSetList);
- }
-
- Class<? extends ParameterizedRunnerDelegate> runnerDelegateClass =
- getRunnerDelegateClass(testClass);
- ParameterizedRunnerDelegateFactory factory = new ParameterizedRunnerDelegateFactory();
- List<Runner> runnersForTestClass = new ArrayList<>();
- for (ParameterSet classParameterSet : classParameterSetList) {
- BlockJUnit4ClassRunner runner = (BlockJUnit4ClassRunner) factory.createRunner(
- testClass, classParameterSet, runnerDelegateClass);
- runnersForTestClass.add(runner);
- }
- return runnersForTestClass;
- }
-
- /**
- * Return an unmodifiable list of ParameterSet through a FrameworkField
- */
- private static List<ParameterSet> getParameterSetList(FrameworkField field, TestClass testClass)
- throws IllegalAccessException {
- field.getField().setAccessible(true);
- if (!Modifier.isStatic(field.getField().getModifiers())) {
- throw new IllegalParameterArgumentException(String.format(Locale.getDefault(),
- "ParameterSetList fields must be static, this field %s in %s is not",
- field.getName(), testClass.getName()));
- }
- if (!(field.get(testClass.getJavaClass()) instanceof List)) {
- throw new IllegalArgumentException(String.format(Locale.getDefault(),
- "Fields with @ClassParameter annotations must be an instance of List, "
- + "this field %s in %s is not list",
- field.getName(), testClass.getName()));
- }
- @SuppressWarnings("unchecked") // checked above
- List<ParameterSet> result = (List<ParameterSet>) field.get(testClass.getJavaClass());
- return Collections.unmodifiableList(result);
- }
-
- static void validateWidth(Iterable<ParameterSet> parameterSetList) {
- int lastSize = -1;
- for (ParameterSet set : parameterSetList) {
- if (set.size() == 0) {
- throw new IllegalParameterArgumentException(
- "No parameter is added to method ParameterSet");
- }
- if (lastSize == -1 || set.size() == lastSize) {
- lastSize = set.size();
- } else {
- throw new IllegalParameterArgumentException(String.format(Locale.getDefault(),
- "All ParameterSets in a list of ParameterSet must have equal"
- + " length. The current ParameterSet (%s) contains %d parameters,"
- + " while previous ParameterSet contains %d parameters",
- Arrays.toString(set.getValues().toArray()), set.size(), lastSize));
- }
- }
- }
-
- /**
- * Get the runner delegate class for the test class if {@code @UseRunnerDelegate} is used.
- * The default runner delegate is BaseJUnit4RunnerDelegate.class
- */
- private static Class<? extends ParameterizedRunnerDelegate> getRunnerDelegateClass(
- TestClass testClass) {
- if (testClass.getAnnotation(UseRunnerDelegate.class) != null) {
- return testClass.getAnnotation(UseRunnerDelegate.class).value();
- }
- return BaseJUnit4RunnerDelegate.class;
- }
-
- static class IllegalParameterArgumentException extends IllegalArgumentException {
- IllegalParameterArgumentException(String msg) {
- super(msg);
- }
- }
-
- public static class ParameterizedTestInstantiationException extends Exception {
- ParameterizedTestInstantiationException(
- TestClass testClass, String parameterSetString, Exception e) {
- super(String.format(
- "Test class %s can not be initiated, the provided parameters are %s,"
- + " the required parameter types are %s",
- testClass.getJavaClass().toString(), parameterSetString,
- Arrays.toString(testClass.getOnlyConstructor().getParameterTypes())),
- e);
- }
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/params/ParameterizedRunnerDelegate.java b/base/test/android/javatests/src/org/chromium/base/test/params/ParameterizedRunnerDelegate.java
deleted file mode 100644
index d3698a9..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/params/ParameterizedRunnerDelegate.java
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test.params;
-
-import org.junit.runners.model.FrameworkMethod;
-
-import org.chromium.base.test.params.ParameterizedRunner.ParameterizedTestInstantiationException;
-
-import java.util.List;
-
-/**
- * This interface defines the methods that needs to be overriden for a Runner to
- * be used by ParameterizedRunner to generate individual runners for parameters.
- *
- * To create a ParameterizedRunnerDelegate, extends from any BlockJUnit4Runner
- * children class. You can copy all the implementation from
- * org.chromium.base.test.params.BaseJUnit4RunnerDelegate.
- */
-public interface ParameterizedRunnerDelegate {
- /**
- * Override to use DelegateCommon's implementation
- */
- void collectInitializationErrors(List<Throwable> errors);
-
- /**
- * Override to use DelegateCommon's implementation
- */
- List<FrameworkMethod> computeTestMethods();
-
- /**
- * Override to use DelegateCommon's implementation
- */
- Object createTest() throws ParameterizedTestInstantiationException;
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/params/ParameterizedRunnerDelegateCommon.java b/base/test/android/javatests/src/org/chromium/base/test/params/ParameterizedRunnerDelegateCommon.java
deleted file mode 100644
index f25e2b2..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/params/ParameterizedRunnerDelegateCommon.java
+++ /dev/null
@@ -1,69 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test.params;
-
-import org.junit.runners.model.FrameworkMethod;
-import org.junit.runners.model.TestClass;
-
-import org.chromium.base.test.params.ParameterizedRunner.ParameterizedTestInstantiationException;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.List;
-
-/**
- * Parameterized runner delegate common that implements method that needed to be
- * delegated for parameterization purposes
- */
-public final class ParameterizedRunnerDelegateCommon {
- private final TestClass mTestClass;
- private final ParameterSet mClassParameterSet;
- private final List<FrameworkMethod> mParameterizedFrameworkMethodList;
-
- public ParameterizedRunnerDelegateCommon(TestClass testClass, ParameterSet classParameterSet,
- List<FrameworkMethod> parameterizedFrameworkMethods) {
- mTestClass = testClass;
- mClassParameterSet = classParameterSet;
- mParameterizedFrameworkMethodList = parameterizedFrameworkMethods;
- }
-
- /**
- * Do not do any validation here because running the default class runner's
- * collectInitializationErrors fail due to the overridden computeTestMethod relying on a local
- * member variable
- *
- * The validation needed for parameterized tests is already done by ParameterizedRunner.
- */
- public static void collectInitializationErrors(
- @SuppressWarnings("unused") List<Throwable> errors) {}
-
- public List<FrameworkMethod> computeTestMethods() {
- return mParameterizedFrameworkMethodList;
- }
-
- private void throwInstantiationException(Exception e)
- throws ParameterizedTestInstantiationException {
- String parameterSetString =
- mClassParameterSet == null ? "null" : mClassParameterSet.toString();
- throw new ParameterizedTestInstantiationException(mTestClass, parameterSetString, e);
- }
-
- public Object createTest() throws ParameterizedTestInstantiationException {
- try {
- if (mClassParameterSet == null) {
- return mTestClass.getOnlyConstructor().newInstance();
- }
- return mTestClass.getOnlyConstructor().newInstance(
- mClassParameterSet.getValues().toArray());
- } catch (InstantiationException e) {
- throwInstantiationException(e);
- } catch (IllegalAccessException e) {
- throwInstantiationException(e);
- } catch (InvocationTargetException e) {
- throwInstantiationException(e);
- }
- assert false;
- return null;
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/params/ParameterizedRunnerDelegateFactory.java b/base/test/android/javatests/src/org/chromium/base/test/params/ParameterizedRunnerDelegateFactory.java
deleted file mode 100644
index f829981..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/params/ParameterizedRunnerDelegateFactory.java
+++ /dev/null
@@ -1,115 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test.params;
-
-import org.junit.Test;
-import org.junit.runners.model.FrameworkMethod;
-import org.junit.runners.model.TestClass;
-
-import org.chromium.base.test.params.ParameterAnnotations.UseMethodParameter;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * Factory to generate delegate class runners for ParameterizedRunner
- */
-public class ParameterizedRunnerDelegateFactory {
- /**
- * Create a runner that implements ParameterizedRunner and extends BlockJUnit4ClassRunner
- *
- * @param testClass the TestClass object for current test class
- * @param classParameterSet A parameter set for test constructor arguments
- * @param parameterizedRunnerDelegateClass the parameterized runner delegate class specified
- * through {@code @UseRunnerDelegate}
- */
- <T extends ParameterizedRunnerDelegate> T createRunner(TestClass testClass,
- ParameterSet classParameterSet, Class<T> parameterizedRunnerDelegateClass)
- throws ParameterizedRunnerDelegateInstantiationException {
- String testMethodPostfix = classParameterSet == null ? null : classParameterSet.getName();
- List<FrameworkMethod> unmodifiableFrameworkMethodList =
- generateUnmodifiableFrameworkMethodList(testClass, testMethodPostfix);
- ParameterizedRunnerDelegateCommon delegateCommon = new ParameterizedRunnerDelegateCommon(
- testClass, classParameterSet, unmodifiableFrameworkMethodList);
- try {
- return parameterizedRunnerDelegateClass
- .getDeclaredConstructor(Class.class, ParameterizedRunnerDelegateCommon.class)
- .newInstance(testClass.getJavaClass(), delegateCommon);
- } catch (Exception e) {
- throw new ParameterizedRunnerDelegateInstantiationException(
- parameterizedRunnerDelegateClass.toString(), e);
- }
- }
-
- /**
- * Match test methods annotated by @UseMethodParameter(X) with
- * ParameterSetList annotated by @MethodParameter(X)
- *
- * @param testClass a {@code TestClass} that wraps around the actual java
- * test class
- * @param postFix a name postfix for each test
- * @return a list of ParameterizedFrameworkMethod
- */
- static List<FrameworkMethod> generateUnmodifiableFrameworkMethodList(
- TestClass testClass, String postFix) {
- // Represent the list of all ParameterizedFrameworkMethod in this test class
- List<FrameworkMethod> returnList = new ArrayList<>();
-
- for (FrameworkMethod method : testClass.getAnnotatedMethods(Test.class)) {
- if (method.getMethod().isAnnotationPresent(UseMethodParameter.class)) {
- Iterable<ParameterSet> parameterSets =
- getParameters(method.getAnnotation(UseMethodParameter.class).value());
- returnList.addAll(createParameterizedMethods(method, parameterSets, postFix));
- } else {
- // If test method is not parameterized (does not have UseMethodParameter annotation)
- returnList.add(new ParameterizedFrameworkMethod(method.getMethod(), null, postFix));
- }
- }
-
- return Collections.unmodifiableList(returnList);
- }
-
- /**
- * Exception caused by instantiating the provided Runner delegate
- * Potentially caused by not overriding collecInitializationErrors() method
- * to be empty
- */
- public static class ParameterizedRunnerDelegateInstantiationException extends Exception {
- private ParameterizedRunnerDelegateInstantiationException(
- String runnerDelegateClass, Exception e) {
- super(String.format("Current class runner delegate %s can not be instantiated.",
- runnerDelegateClass),
- e);
- }
- }
-
- private static Iterable<ParameterSet> getParameters(Class<? extends ParameterProvider> clazz) {
- ParameterProvider parameterProvider;
- try {
- parameterProvider = clazz.getDeclaredConstructor().newInstance();
- } catch (IllegalAccessException e) {
- throw new IllegalStateException("Failed instantiating " + clazz.getCanonicalName(), e);
- } catch (InstantiationException e) {
- throw new IllegalStateException("Failed instantiating " + clazz.getCanonicalName(), e);
- } catch (NoSuchMethodException e) {
- throw new IllegalStateException("Failed instantiating " + clazz.getCanonicalName(), e);
- } catch (InvocationTargetException e) {
- throw new IllegalStateException("Failed instantiating " + clazz.getCanonicalName(), e);
- }
- return parameterProvider.getParameters();
- }
-
- private static List<FrameworkMethod> createParameterizedMethods(
- FrameworkMethod baseMethod, Iterable<ParameterSet> parameterSetList, String suffix) {
- ParameterizedRunner.validateWidth(parameterSetList);
- List<FrameworkMethod> returnList = new ArrayList<>();
- for (ParameterSet set : parameterSetList) {
- returnList.add(new ParameterizedFrameworkMethod(baseMethod.getMethod(), set, suffix));
- }
- return returnList;
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/AdvancedMockContext.java b/base/test/android/javatests/src/org/chromium/base/test/util/AdvancedMockContext.java
deleted file mode 100644
index c8117f7..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/AdvancedMockContext.java
+++ /dev/null
@@ -1,118 +0,0 @@
-// Copyright 2013 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.
-
-package org.chromium.base.test.util;
-
-import android.content.ComponentCallbacks;
-import android.content.ContentResolver;
-import android.content.Context;
-import android.content.ContextWrapper;
-import android.content.SharedPreferences;
-import android.test.mock.MockContentResolver;
-import android.test.mock.MockContext;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * ContextWrapper that adds functionality for SharedPreferences and a way to set and retrieve flags.
- */
-public class AdvancedMockContext extends ContextWrapper {
-
- private final MockContentResolver mMockContentResolver = new MockContentResolver();
-
- private final Map<String, SharedPreferences> mSharedPreferences =
- new HashMap<String, SharedPreferences>();
-
- private final Map<String, Boolean> mFlags = new HashMap<String, Boolean>();
-
- public AdvancedMockContext(Context base) {
- super(base);
- }
-
- public AdvancedMockContext() {
- super(new MockContext());
- }
-
- @Override
- public String getPackageName() {
- return getBaseContext().getPackageName();
- }
-
- @Override
- public Context getApplicationContext() {
- return this;
- }
-
- @Override
- public ContentResolver getContentResolver() {
- return mMockContentResolver;
- }
-
- public MockContentResolver getMockContentResolver() {
- return mMockContentResolver;
- }
-
- @Override
- public SharedPreferences getSharedPreferences(String name, int mode) {
- synchronized (mSharedPreferences) {
- if (!mSharedPreferences.containsKey(name)) {
- // Auto-create shared preferences to mimic Android Context behavior
- mSharedPreferences.put(name, new InMemorySharedPreferences());
- }
- return mSharedPreferences.get(name);
- }
- }
-
- @Override
- public void registerComponentCallbacks(ComponentCallbacks callback) {
- getBaseContext().registerComponentCallbacks(callback);
- }
-
- @Override
- public void unregisterComponentCallbacks(ComponentCallbacks callback) {
- getBaseContext().unregisterComponentCallbacks(callback);
- }
-
- public void addSharedPreferences(String name, Map<String, Object> data) {
- synchronized (mSharedPreferences) {
- mSharedPreferences.put(name, new InMemorySharedPreferences(data));
- }
- }
-
- public void setFlag(String key) {
- mFlags.put(key, true);
- }
-
- public void clearFlag(String key) {
- mFlags.remove(key);
- }
-
- public boolean isFlagSet(String key) {
- return mFlags.containsKey(key) && mFlags.get(key);
- }
-
- /**
- * Builder for maps of type Map<String, Object> to be used with
- * {@link #addSharedPreferences(String, java.util.Map)}.
- */
- public static class MapBuilder {
-
- private final Map<String, Object> mData = new HashMap<String, Object>();
-
- public static MapBuilder create() {
- return new MapBuilder();
- }
-
- public MapBuilder add(String key, Object value) {
- mData.put(key, value);
- return this;
- }
-
- public Map<String, Object> build() {
- return mData;
- }
-
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/AnnotationProcessingUtils.java b/base/test/android/javatests/src/org/chromium/base/test/util/AnnotationProcessingUtils.java
deleted file mode 100644
index d335412..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/AnnotationProcessingUtils.java
+++ /dev/null
@@ -1,259 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test.util;
-
-import android.support.annotation.Nullable;
-
-import org.junit.runner.Description;
-
-import org.chromium.base.VisibleForTesting;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Queue;
-import java.util.Set;
-
-/**
- * Utility class to help with processing annotations, going around the code to collect them, etc.
- */
-public abstract class AnnotationProcessingUtils {
- /**
- * Returns the closest instance of the requested annotation or null if there is none.
- * See {@link AnnotationExtractor} for context of "closest".
- */
- @SuppressWarnings("unchecked")
- public static <A extends Annotation> A getAnnotation(Description description, Class<A> clazz) {
- AnnotationExtractor extractor = new AnnotationExtractor(clazz);
- return (A) extractor.getClosest(extractor.getMatchingAnnotations(description));
- }
-
- /**
- * Returns the closest instance of the requested annotation or null if there is none.
- * See {@link AnnotationExtractor} for context of "closest".
- */
- @SuppressWarnings("unchecked")
- public static <A extends Annotation> A getAnnotation(AnnotatedElement element, Class<A> clazz) {
- AnnotationExtractor extractor = new AnnotationExtractor(clazz);
- return (A) extractor.getClosest(extractor.getMatchingAnnotations(element));
- }
-
- /** See {@link AnnotationExtractor} for details about the output sorting order. */
- @SuppressWarnings("unchecked")
- public static <A extends Annotation> List<A> getAnnotations(
- Description description, Class<A> annotationType) {
- return (List<A>) new AnnotationExtractor(annotationType)
- .getMatchingAnnotations(description);
- }
-
- /** See {@link AnnotationExtractor} for details about the output sorting order. */
- @SuppressWarnings("unchecked")
- public static <A extends Annotation> List<A> getAnnotations(
- AnnotatedElement annotatedElement, Class<A> annotationType) {
- return (List<A>) new AnnotationExtractor(annotationType)
- .getMatchingAnnotations(annotatedElement);
- }
-
- private static boolean isChromiumAnnotation(Annotation annotation) {
- Package pkg = annotation.annotationType().getPackage();
- return pkg != null && pkg.getName().startsWith("org.chromium");
- }
-
- /**
- * Processes various types of annotated elements ({@link Class}es, {@link Annotation}s,
- * {@link Description}s, etc.) and extracts the targeted annotations from it. The output will be
- * sorted in BFS-like order.
- *
- * For example, for a method we would get in reverse order:
- * - the method annotations
- * - the meta-annotations present on the method annotations,
- * - the class annotations
- * - the meta-annotations present on the class annotations,
- * - the annotations present on the super class,
- * - the meta-annotations present on the super class annotations,
- * - etc.
- *
- * When multiple annotations are targeted, if more than one is picked up at a given level (for
- * example directly on the method), they will be returned in the reverse order that they were
- * provided to the constructor.
- *
- * Note: We return the annotations in reverse order because we assume that if some processing
- * is going to be made on related annotations, the later annotations would likely override
- * modifications made by the former.
- *
- * Note: While resolving meta annotations, we don't expand the explorations to annotations types
- * that have already been visited. Please file a bug and assign to dgn@ if you think it caused
- * an issue.
- */
- public static class AnnotationExtractor {
- private final List<Class<? extends Annotation>> mAnnotationTypes;
- private final Comparator<Class<? extends Annotation>> mAnnotationTypeComparator;
- private final Comparator<Annotation> mAnnotationComparator;
-
- @SafeVarargs
- public AnnotationExtractor(Class<? extends Annotation>... additionalTypes) {
- this(Arrays.asList(additionalTypes));
- }
-
- public AnnotationExtractor(List<Class<? extends Annotation>> additionalTypes) {
- assert !additionalTypes.isEmpty();
- mAnnotationTypes = Collections.unmodifiableList(additionalTypes);
- mAnnotationTypeComparator =
- (t1, t2) -> mAnnotationTypes.indexOf(t1) - mAnnotationTypes.indexOf(t2);
- mAnnotationComparator = (t1, t2)
- -> mAnnotationTypeComparator.compare(t1.annotationType(), t2.annotationType());
- }
-
- public List<Annotation> getMatchingAnnotations(Description description) {
- return getMatchingAnnotations(new AnnotatedNode.DescriptionNode(description));
- }
-
- public List<Annotation> getMatchingAnnotations(AnnotatedElement annotatedElement) {
- AnnotatedNode annotatedNode;
- if (annotatedElement instanceof Method) {
- annotatedNode = new AnnotatedNode.MethodNode((Method) annotatedElement);
- } else if (annotatedElement instanceof Class) {
- annotatedNode = new AnnotatedNode.ClassNode((Class) annotatedElement);
- } else {
- throw new IllegalArgumentException("Unsupported type for " + annotatedElement);
- }
-
- return getMatchingAnnotations(annotatedNode);
- }
-
- /**
- * For a given list obtained from the extractor, returns the {@link Annotation} that would
- * be closest from the extraction point, or {@code null} if the list is empty.
- */
- @Nullable
- public Annotation getClosest(List<Annotation> annotationList) {
- return annotationList.isEmpty() ? null : annotationList.get(annotationList.size() - 1);
- }
-
- @VisibleForTesting
- Comparator<Class<? extends Annotation>> getTypeComparator() {
- return mAnnotationTypeComparator;
- }
-
- private List<Annotation> getMatchingAnnotations(AnnotatedNode annotatedNode) {
- List<Annotation> collectedAnnotations = new ArrayList<>();
- Queue<Annotation> workingSet = new LinkedList<>();
- Set<Class<? extends Annotation>> visited = new HashSet<>();
-
- AnnotatedNode currentAnnotationLayer = annotatedNode;
- while (currentAnnotationLayer != null) {
- queueAnnotations(currentAnnotationLayer.getAnnotations(), workingSet);
-
- while (!workingSet.isEmpty()) {
- sweepAnnotations(collectedAnnotations, workingSet, visited);
- }
-
- currentAnnotationLayer = currentAnnotationLayer.getParent();
- }
-
- return collectedAnnotations;
- }
-
- private void queueAnnotations(List<Annotation> annotations, Queue<Annotation> workingSet) {
- Collections.sort(annotations, mAnnotationComparator);
- workingSet.addAll(annotations);
- }
-
- private void sweepAnnotations(List<Annotation> collectedAnnotations,
- Queue<Annotation> workingSet, Set<Class<? extends Annotation>> visited) {
- // 1. Grab node at the front of the working set.
- Annotation annotation = workingSet.remove();
-
- // 2. If it's an annotation of interest, put it aside for the output.
- if (mAnnotationTypes.contains(annotation.annotationType())) {
- collectedAnnotations.add(0, annotation);
- }
-
- // 3. Check if we can get skip some redundant iterations and avoid cycles.
- if (!visited.add(annotation.annotationType())) return;
- if (!isChromiumAnnotation(annotation)) return;
-
- // 4. Expand the working set
- queueAnnotations(Arrays.asList(annotation.annotationType().getDeclaredAnnotations()),
- workingSet);
- }
- }
-
- /**
- * Abstraction to hide differences between Class, Method and Description with regards to their
- * annotations and what should be analyzed next.
- */
- private static abstract class AnnotatedNode {
- @Nullable
- abstract AnnotatedNode getParent();
-
- abstract List<Annotation> getAnnotations();
-
- static class DescriptionNode extends AnnotatedNode {
- final Description mDescription;
-
- DescriptionNode(Description description) {
- mDescription = description;
- }
-
- @Nullable
- @Override
- AnnotatedNode getParent() {
- return new ClassNode(mDescription.getTestClass());
- }
-
- @Override
- List<Annotation> getAnnotations() {
- return new ArrayList<>(mDescription.getAnnotations());
- }
- }
-
- static class ClassNode extends AnnotatedNode {
- final Class<?> mClass;
-
- ClassNode(Class<?> clazz) {
- mClass = clazz;
- }
-
- @Nullable
- @Override
- AnnotatedNode getParent() {
- Class<?> superClass = mClass.getSuperclass();
- return superClass == null ? null : new ClassNode(superClass);
- }
-
- @Override
- List<Annotation> getAnnotations() {
- return Arrays.asList(mClass.getDeclaredAnnotations());
- }
- }
-
- static class MethodNode extends AnnotatedNode {
- final Method mMethod;
-
- MethodNode(Method method) {
- mMethod = method;
- }
-
- @Nullable
- @Override
- AnnotatedNode getParent() {
- return new ClassNode(mMethod.getDeclaringClass());
- }
-
- @Override
- List<Annotation> getAnnotations() {
- return Arrays.asList(mMethod.getDeclaredAnnotations());
- }
- }
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/AnnotationRule.java b/base/test/android/javatests/src/org/chromium/base/test/util/AnnotationRule.java
deleted file mode 100644
index a361ac3..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/AnnotationRule.java
+++ /dev/null
@@ -1,139 +0,0 @@
-// Copyright 2016 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.
-
-package org.chromium.base.test.util;
-
-import android.support.annotation.CallSuper;
-import android.support.annotation.Nullable;
-
-import org.junit.rules.ExternalResource;
-import org.junit.runner.Description;
-import org.junit.runners.model.Statement;
-
-import java.lang.annotation.Annotation;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.ListIterator;
-
-/**
- * Test rule that collects specific annotations to help with test set up and tear down. It is set up
- * with a list of annotations to look for and exposes the ones picked up on the test through
- * {@link #getAnnotations()} and related methods.
- *
- * Note: The rule always apply, whether it picked up annotations or not.
- *
- * Usage:
- *
- * <pre>
- * public class Test {
- * @Rule
- * public AnnotationRule rule = new AnnotationRule(Foo.class) {
- * @Override
- * protected void before() { ... }
- *
- * @Override
- * protected void after() { ... }
- * };
- *
- * @Test
- * @Foo
- * public void myTest() { ... }
- * }
- * </pre>
- *
- * It can also be used to trigger for multiple annotations:
- *
- * <pre>
- * @DisableFoo
- * public class Test {
- * @Rule
- * public AnnotationRule rule = new AnnotationRule(EnableFoo.class, DisableFoo.class) {
- * @Override
- * protected void before() {
- * // Loops through all the picked up annotations. For myTest(), it would process
- * // DisableFoo first, then EnableFoo.
- * for (Annotation annotation : getAnnotations()) {
- * if (annotation instanceof EnableFoo) { ... }
- * else if (annotation instanceof DisableFoo) { ... }
- * }
- * }
- *
- * @Override
- * protected void after() {
- * // For myTest(), would return EnableFoo as it's directly set on the method.
- * Annotation a = getClosestAnnotation();
- * ...
- * }
- * };
- *
- * @Test
- * @EnableFoo
- * public void myTest() { ... }
- * }
- * </pre>
- *
- * @see AnnotationProcessingUtils.AnnotationExtractor
- */
-public abstract class AnnotationRule extends ExternalResource {
- private final AnnotationProcessingUtils.AnnotationExtractor mAnnotationExtractor;
- private List<Annotation> mCollectedAnnotations;
- private Description mTestDescription;
-
- @SafeVarargs
- public AnnotationRule(Class<? extends Annotation> firstAnnotationType,
- Class<? extends Annotation>... additionalTypes) {
- List<Class<? extends Annotation>> mAnnotationTypes = new ArrayList<>();
- mAnnotationTypes.add(firstAnnotationType);
- mAnnotationTypes.addAll(Arrays.asList(additionalTypes));
- mAnnotationExtractor = new AnnotationProcessingUtils.AnnotationExtractor(mAnnotationTypes);
- }
-
- @CallSuper
- @Override
- public Statement apply(Statement base, Description description) {
- mTestDescription = description;
-
- mCollectedAnnotations = mAnnotationExtractor.getMatchingAnnotations(description);
-
- // Return the wrapped statement to execute before() and after().
- return super.apply(base, description);
- }
-
- /** @return {@link Description} of the current test. */
- protected Description getTestDescription() {
- return mTestDescription;
- }
-
- /**
- * @return The collected annotations that match the declared type(s).
- * @throws NullPointerException if this is called before annotations have been collected,
- * which happens when the rule is applied to the {@link Statement}.
- */
- protected List<Annotation> getAnnotations() {
- return Collections.unmodifiableList(mCollectedAnnotations);
- }
-
- /**
- * @return The closest annotation matching the provided type, or {@code null} if there is none.
- */
- @SuppressWarnings("unchecked")
- protected @Nullable <A extends Annotation> A getAnnotation(Class<A> annnotationType) {
- ListIterator<Annotation> iteratorFromEnd =
- mCollectedAnnotations.listIterator(mCollectedAnnotations.size());
- while (iteratorFromEnd.hasPrevious()) {
- Annotation annotation = iteratorFromEnd.previous();
- if (annnotationType.isAssignableFrom(annotation.annotationType())) {
- return (A) annotation;
- }
- }
- return null;
- }
-
- protected @Nullable Annotation getClosestAnnotation() {
- if (mCollectedAnnotations.isEmpty()) return null;
- return mCollectedAnnotations.get(mCollectedAnnotations.size() - 1);
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/CallbackHelper.java b/base/test/android/javatests/src/org/chromium/base/test/util/CallbackHelper.java
deleted file mode 100644
index bf064c4..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/CallbackHelper.java
+++ /dev/null
@@ -1,252 +0,0 @@
-// Copyright 2012 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.
-
-package org.chromium.base.test.util;
-
-import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
-
-import org.junit.Assert;
-
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
-/**
- * A helper class that encapsulates listening and blocking for callbacks.
- *
- * Sample usage:
- *
- * // Let us assume that this interface is defined by some piece of production code and is used
- * // to communicate events that occur in that piece of code. Let us further assume that the
- * // production code runs on the main thread test code runs on a separate test thread.
- * // An instance that implements this interface would be injected by test code to ensure that the
- * // methods are being called on another thread.
- * interface Delegate {
- * void onOperationFailed(String errorMessage);
- * void onDataPersisted();
- * }
- *
- * // This is the inner class you'd write in your test case to later inject into the production
- * // code.
- * class TestDelegate implements Delegate {
- * // This is the preferred way to create a helper that stores the parameters it receives
- * // when called by production code.
- * public static class OnOperationFailedHelper extends CallbackHelper {
- * private String mErrorMessage;
- *
- * public void getErrorMessage() {
- * assert getCallCount() > 0;
- * return mErrorMessage;
- * }
- *
- * public void notifyCalled(String errorMessage) {
- * mErrorMessage = errorMessage;
- * // It's important to call this after all parameter assignments.
- * notifyCalled();
- * }
- * }
- *
- * // There should be one CallbackHelper instance per method.
- * private OnOperationFailedHelper mOnOperationFailedHelper;
- * private CallbackHelper mOnDataPersistedHelper;
- *
- * public OnOperationFailedHelper getOnOperationFailedHelper() {
- * return mOnOperationFailedHelper;
- * }
- *
- * public CallbackHelper getOnDataPersistedHelper() {
- * return mOnDataPersistedHelper;
- * }
- *
- * @Override
- * public void onOperationFailed(String errorMessage) {
- * mOnOperationFailedHelper.notifyCalled(errorMessage);
- * }
- *
- * @Override
- * public void onDataPersisted() {
- * mOnDataPersistedHelper.notifyCalled();
- * }
- * }
- *
- * // This is a sample test case.
- * public void testCase() throws Exception {
- * // Create the TestDelegate to inject into production code.
- * TestDelegate delegate = new TestDelegate();
- * // Create the production class instance that is being tested and inject the test delegate.
- * CodeUnderTest codeUnderTest = new CodeUnderTest();
- * codeUnderTest.setDelegate(delegate);
- *
- * // Typically you'd get the current call count before performing the operation you expect to
- * // trigger the callback. There can't be any callbacks 'in flight' at this moment, otherwise
- * // the call count is unpredictable and the test will be flaky.
- * int onOperationFailedCallCount = delegate.getOnOperationFailedHelper().getCallCount();
- * codeUnderTest.doSomethingThatEndsUpCallingOnOperationFailedFromAnotherThread();
- * // It's safe to do other stuff here, if needed.
- * ....
- * // Wait for the callback if it hadn't been called yet, otherwise return immediately. This
- * // can throw an exception if the callback doesn't arrive within the timeout.
- * delegate.getOnOperationFailedHelper().waitForCallback(onOperationFailedCallCount);
- * // Access to method parameters is now safe.
- * assertEquals("server error", delegate.getOnOperationFailedHelper().getErrorMessage());
- *
- * // Being able to pass the helper around lets us build methods which encapsulate commonly
- * // performed tasks.
- * doSomeOperationAndWait(codeUnerTest, delegate.getOnOperationFailedHelper());
- *
- * // The helper can be reused for as many calls as needed, just be sure to get the count each
- * // time.
- * onOperationFailedCallCount = delegate.getOnOperationFailedHelper().getCallCount();
- * codeUnderTest.doSomethingElseButStillFailOnAnotherThread();
- * delegate.getOnOperationFailedHelper().waitForCallback(onOperationFailedCallCount);
- *
- * // It is also possible to use more than one helper at a time.
- * onOperationFailedCallCount = delegate.getOnOperationFailedHelper().getCallCount();
- * int onDataPersistedCallCount = delegate.getOnDataPersistedHelper().getCallCount();
- * codeUnderTest.doSomethingThatPersistsDataButFailsInSomeOtherWayOnAnotherThread();
- * delegate.getOnDataPersistedHelper().waitForCallback(onDataPersistedCallCount);
- * delegate.getOnOperationFailedHelper().waitForCallback(onOperationFailedCallCount);
- * }
- *
- * // Shows how to turn an async operation + completion callback into a synchronous operation.
- * private void doSomeOperationAndWait(final CodeUnderTest underTest,
- * CallbackHelper operationHelper) throws InterruptedException, TimeoutException {
- * final int callCount = operationHelper.getCallCount();
- * getInstrumentation().runOnMainSync(new Runnable() {
- * @Override
- * public void run() {
- * // This schedules a call to a method on the injected TestDelegate. The TestDelegate
- * // implementation will then call operationHelper.notifyCalled().
- * underTest.operation();
- * }
- * });
- * operationHelper.waitForCallback(callCount);
- * }
- *
- */
-public class CallbackHelper {
- /** The default timeout (in seconds) for a callback to wait. */
- public static final long WAIT_TIMEOUT_SECONDS = scaleTimeout(5);
-
- private final Object mLock = new Object();
- private int mCallCount;
- private String mFailureString;
-
- /**
- * Gets the number of times the callback has been called.
- *
- * The call count can be used with the waitForCallback() method, indicating a point
- * in time after which the caller wishes to record calls to the callback.
- *
- * In order to wait for a callback caused by X, the call count should be obtained
- * before X occurs.
- *
- * NOTE: any call to the callback that occurs after the call count is obtained
- * will result in the corresponding wait call to resume execution. The call count
- * is intended to 'catch' callbacks that occur after X but before waitForCallback()
- * is called.
- */
- public int getCallCount() {
- synchronized (mLock) {
- return mCallCount;
- }
- }
-
- /**
- * Blocks until the callback is called the specified number of
- * times or throws an exception if we exceeded the specified time frame.
- *
- * This will wait for a callback to be called a specified number of times after
- * the point in time at which the call count was obtained. The method will return
- * immediately if a call occurred the specified number of times after the
- * call count was obtained but before the method was called, otherwise the method will
- * block until the specified call count is reached.
- *
- * @param msg The error message to use if the callback times out.
- * @param currentCallCount the value obtained by calling getCallCount().
- * @param numberOfCallsToWaitFor number of calls (counting since
- * currentCallCount was obtained) that we will wait for.
- * @param timeout timeout value. We will wait the specified amount of time for a single
- * callback to occur so the method call may block up to
- * <code>numberOfCallsToWaitFor * timeout</code> units.
- * @param unit timeout unit.
- * @throws InterruptedException
- * @throws TimeoutException Thrown if the method times out before onPageFinished is called.
- */
- public void waitForCallback(String msg, int currentCallCount, int numberOfCallsToWaitFor,
- long timeout, TimeUnit unit) throws InterruptedException, TimeoutException {
- assert mCallCount >= currentCallCount;
- assert numberOfCallsToWaitFor > 0;
- synchronized (mLock) {
- int callCountWhenDoneWaiting = currentCallCount + numberOfCallsToWaitFor;
- while (callCountWhenDoneWaiting > mCallCount) {
- int callCountBeforeWait = mCallCount;
- mLock.wait(unit.toMillis(timeout));
- if (mFailureString != null) {
- String s = mFailureString;
- mFailureString = null;
- Assert.fail(s);
- }
- if (callCountBeforeWait == mCallCount) {
- throw new TimeoutException(msg == null ? "waitForCallback timed out!" : msg);
- }
- }
- }
- }
-
- /**
- * @see #waitForCallback(String, int, int, long, TimeUnit)
- */
- public void waitForCallback(int currentCallCount, int numberOfCallsToWaitFor, long timeout,
- TimeUnit unit) throws InterruptedException, TimeoutException {
- waitForCallback(null, currentCallCount, numberOfCallsToWaitFor, timeout, unit);
- }
-
- /**
- * @see #waitForCallback(String, int, int, long, TimeUnit)
- */
- public void waitForCallback(int currentCallCount, int numberOfCallsToWaitFor)
- throws InterruptedException, TimeoutException {
- waitForCallback(null, currentCallCount, numberOfCallsToWaitFor,
- WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
- }
-
- /**
- * @see #waitForCallback(String, int, int, long, TimeUnit)
- */
- public void waitForCallback(String msg, int currentCallCount)
- throws InterruptedException, TimeoutException {
- waitForCallback(msg, currentCallCount, 1, WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
- }
-
- /**
- * @see #waitForCallback(String, int, int, long, TimeUnit)
- */
- public void waitForCallback(int currentCallCount)
- throws InterruptedException, TimeoutException {
- waitForCallback(null, currentCallCount, 1, WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
- }
-
- /**
- * Should be called when the callback associated with this helper object is called.
- */
- public void notifyCalled() {
- synchronized (mLock) {
- mCallCount++;
- mLock.notifyAll();
- }
- }
-
- /**
- * Should be called when the callback associated with this helper object wants to
- * indicate a failure.
- *
- * @param s The failure message.
- */
- public void notifyFailed(String s) {
- synchronized (mLock) {
- mFailureString = s;
- mLock.notifyAll();
- }
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/CommandLineFlags.java b/base/test/android/javatests/src/org/chromium/base/test/util/CommandLineFlags.java
deleted file mode 100644
index 71ef8e9..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/CommandLineFlags.java
+++ /dev/null
@@ -1,188 +0,0 @@
-// Copyright 2015 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.
-
-package org.chromium.base.test.util;
-
-import android.text.TextUtils;
-
-import org.junit.Assert;
-import org.junit.Rule;
-
-import org.chromium.base.CommandLine;
-import org.chromium.base.CommandLineInitUtil;
-import org.chromium.base.test.BaseTestResult.PreTestHook;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Provides annotations related to command-line flag handling.
- *
- * Uses of these annotations on a derived class will take precedence over uses on its base classes,
- * so a derived class can add a command-line flag that a base class has removed (or vice versa).
- * Similarly, uses of these annotations on a test method will take precedence over uses on the
- * containing class.
- * <p>
- * These annonations may also be used on Junit4 Rule classes and on their base classes. Note,
- * however that the annotation processor only looks at the declared type of the Rule, not its actual
- * type, so in, for example:
- *
- * <pre>
- * @Rule
- * TestRule mRule = new ChromeActivityTestRule();
- * </pre>
- *
- * will only look for CommandLineFlags annotations on TestRule, not for CommandLineFlags annotations
- * on ChromeActivityTestRule.
- * <p>
- * In addition a rule may not remove flags added by an independently invoked rule, although it may
- * remove flags added by its base classes.
- * <p>
- * Uses of these annotations on the test class or methods take precedence over uses on Rule classes.
- * <p>
- * Note that this class should never be instantiated.
- */
-public final class CommandLineFlags {
- private static final String DISABLE_FEATURES = "disable-features";
- private static final String ENABLE_FEATURES = "enable-features";
-
- /**
- * Adds command-line flags to the {@link org.chromium.base.CommandLine} for this test.
- */
- @Inherited
- @Retention(RetentionPolicy.RUNTIME)
- @Target({ElementType.METHOD, ElementType.TYPE})
- public @interface Add {
- String[] value();
- }
-
- /**
- * Removes command-line flags from the {@link org.chromium.base.CommandLine} from this test.
- *
- * Note that this can only remove flags added via {@link Add} above.
- */
- @Inherited
- @Retention(RetentionPolicy.RUNTIME)
- @Target({ElementType.METHOD, ElementType.TYPE})
- public @interface Remove {
- String[] value();
- }
-
- /**
- * Sets up the CommandLine with the appropriate flags.
- *
- * This will add the difference of the sets of flags specified by {@link CommandLineFlags.Add}
- * and {@link CommandLineFlags.Remove} to the {@link org.chromium.base.CommandLine}. Note that
- * trying to remove a flag set externally, i.e. by the command-line flags file, will not work.
- */
- public static void setUp(AnnotatedElement element) {
- CommandLine.reset();
- CommandLineInitUtil.initCommandLine(getTestCmdLineFile());
- Set<String> enableFeatures = new HashSet<String>();
- Set<String> disableFeatures = new HashSet<String>();
- Set<String> flags = getFlags(element);
- for (String flag : flags) {
- String[] parsedFlags = flag.split("=", 2);
- if (parsedFlags.length == 1) {
- CommandLine.getInstance().appendSwitch(flag);
- } else if (ENABLE_FEATURES.equals(parsedFlags[0])) {
- // We collect enable/disable features flags separately and aggregate them because
- // they may be specified multiple times, in which case the values will trample each
- // other.
- Collections.addAll(enableFeatures, parsedFlags[1].split(","));
- } else if (DISABLE_FEATURES.equals(parsedFlags[0])) {
- Collections.addAll(disableFeatures, parsedFlags[1].split(","));
- } else {
- CommandLine.getInstance().appendSwitchWithValue(parsedFlags[0], parsedFlags[1]);
- }
- }
-
- if (enableFeatures.size() > 0) {
- CommandLine.getInstance().appendSwitchWithValue(
- ENABLE_FEATURES, TextUtils.join(",", enableFeatures));
- }
- if (disableFeatures.size() > 0) {
- CommandLine.getInstance().appendSwitchWithValue(
- DISABLE_FEATURES, TextUtils.join(",", disableFeatures));
- }
- }
-
- private static Set<String> getFlags(AnnotatedElement type) {
- Set<String> rule_flags = new HashSet<>();
- updateFlagsForElement(type, rule_flags);
- return rule_flags;
- }
-
- private static void updateFlagsForElement(AnnotatedElement element, Set<String> flags) {
- if (element instanceof Class<?>) {
- // Get flags from rules within the class.
- for (Field field : ((Class<?>) element).getFields()) {
- if (field.isAnnotationPresent(Rule.class)) {
- // The order in which fields are returned is undefined, so, for consistency,
- // a rule must not remove a flag added by a different rule. Ensure this by
- // initially getting the flags into a new set.
- Set<String> rule_flags = getFlags(field.getType());
- flags.addAll(rule_flags);
- }
- }
- for (Method method : ((Class<?>) element).getMethods()) {
- if (method.isAnnotationPresent(Rule.class)) {
- // The order in which methods are returned is undefined, so, for consistency,
- // a rule must not remove a flag added by a different rule. Ensure this by
- // initially getting the flags into a new set.
- Set<String> rule_flags = getFlags(method.getReturnType());
- flags.addAll(rule_flags);
- }
- }
- }
-
- // Add the flags from the parent. Override any flags defined by the rules.
- AnnotatedElement parent = (element instanceof Method)
- ? ((Method) element).getDeclaringClass()
- : ((Class<?>) element).getSuperclass();
- if (parent != null) updateFlagsForElement(parent, flags);
-
- // Flags on the element itself override all other flag sources.
- if (element.isAnnotationPresent(CommandLineFlags.Add.class)) {
- flags.addAll(
- Arrays.asList(element.getAnnotation(CommandLineFlags.Add.class).value()));
- }
-
- if (element.isAnnotationPresent(CommandLineFlags.Remove.class)) {
- List<String> flagsToRemove =
- Arrays.asList(element.getAnnotation(CommandLineFlags.Remove.class).value());
- for (String flagToRemove : flagsToRemove) {
- // If your test fails here, you have tried to remove a command-line flag via
- // CommandLineFlags.Remove that was loaded into CommandLine via something other
- // than CommandLineFlags.Add (probably the command-line flag file).
- Assert.assertFalse("Unable to remove command-line flag \"" + flagToRemove + "\".",
- CommandLine.getInstance().hasSwitch(flagToRemove));
- }
- flags.removeAll(flagsToRemove);
- }
- }
-
- private CommandLineFlags() {
- throw new AssertionError("CommandLineFlags is a non-instantiable class");
- }
-
- public static PreTestHook getRegistrationHook() {
- return (targetContext, testMethod) -> CommandLineFlags.setUp(testMethod);
- }
-
- public static String getTestCmdLineFile() {
- return "test-cmdline-file";
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/DisableIf.java b/base/test/android/javatests/src/org/chromium/base/test/util/DisableIf.java
deleted file mode 100644
index c0303b6..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/DisableIf.java
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2015 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.
-
-package org.chromium.base.test.util;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotations to support conditional test disabling.
- *
- * These annotations should only be used to disable tests that are temporarily failing
- * in some configurations. If a test should never run at all in some configurations, use
- * {@link Restriction}.
- */
-public class DisableIf {
-
- /** Conditional disabling based on {@link android.os.Build}.
- */
- @Target({ElementType.METHOD, ElementType.TYPE})
- @Retention(RetentionPolicy.RUNTIME)
- public static @interface Build {
- String message() default "";
-
- int sdk_is_greater_than() default 0;
- int sdk_is_less_than() default Integer.MAX_VALUE;
-
- String supported_abis_includes() default "";
-
- String hardware_is() default "";
-
- String product_name_includes() default "";
- }
-
- @Target({ElementType.METHOD, ElementType.TYPE})
- @Retention(RetentionPolicy.RUNTIME)
- public static @interface Device {
- /**
- * @return A list of disabled types.
- */
- public String[] type();
- }
-
- /* Objects of this type should not be created. */
- private DisableIf() {}
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/DisableIfSkipCheck.java b/base/test/android/javatests/src/org/chromium/base/test/util/DisableIfSkipCheck.java
deleted file mode 100644
index e46b979..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/DisableIfSkipCheck.java
+++ /dev/null
@@ -1,84 +0,0 @@
-// Copyright 2015 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.
-
-package org.chromium.base.test.util;
-
-import android.os.Build;
-
-import org.junit.runners.model.FrameworkMethod;
-
-import org.chromium.base.Log;
-
-import java.util.Arrays;
-
-/**
- * Checks for conditional disables.
- *
- * Currently, this only includes checks against a few {@link android.os.Build} values.
- */
-public class DisableIfSkipCheck extends SkipCheck {
-
- private static final String TAG = "cr_base_test";
-
- @Override
- public boolean shouldSkip(FrameworkMethod method) {
- if (method == null) return true;
- for (DisableIf.Build v : AnnotationProcessingUtils.getAnnotations(
- method.getMethod(), DisableIf.Build.class)) {
- if (abi(v) && hardware(v) && product(v) && sdk(v)) {
- if (!v.message().isEmpty()) {
- Log.i(TAG, "%s is disabled: %s", method.getName(), v.message());
- }
- return true;
- }
- }
-
- for (DisableIf.Device d : AnnotationProcessingUtils.getAnnotations(
- method.getMethod(), DisableIf.Device.class)) {
- for (String deviceType : d.type()) {
- if (deviceTypeApplies(deviceType)) {
- Log.i(TAG, "Test " + method.getDeclaringClass().getName() + "#"
- + method.getName() + " disabled because of "
- + d);
- return true;
- }
- }
- }
-
- return false;
- }
-
- @SuppressWarnings("deprecation")
- private boolean abi(DisableIf.Build v) {
- if (v.supported_abis_includes().isEmpty()) return true;
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- return Arrays.asList(Build.SUPPORTED_ABIS).contains(
- v.supported_abis_includes());
- } else {
- return Build.CPU_ABI.equals(v.supported_abis_includes())
- || Build.CPU_ABI2.equals(v.supported_abis_includes());
- }
- }
-
- private boolean hardware(DisableIf.Build v) {
- return v.hardware_is().isEmpty() || Build.HARDWARE.equals(v.hardware_is());
- }
-
- private boolean product(DisableIf.Build v) {
- return v.product_name_includes().isEmpty()
- || Build.PRODUCT.contains(v.product_name_includes());
- }
-
- private boolean sdk(DisableIf.Build v) {
- return Build.VERSION.SDK_INT > v.sdk_is_greater_than()
- && Build.VERSION.SDK_INT < v.sdk_is_less_than();
- }
-
- protected boolean deviceTypeApplies(String type) {
- return false;
- }
-
-}
-
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/DisabledTest.java b/base/test/android/javatests/src/org/chromium/base/test/util/DisabledTest.java
deleted file mode 100644
index a3e4e8e..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/DisabledTest.java
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2012 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.
-
-package org.chromium.base.test.util;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * This annotation is for disabled tests.
- * <p>
- * Tests with this annotation will not be run on any of the normal bots.
- * Please note that they might eventually run on a special bot.
- */
-@Target({ElementType.METHOD, ElementType.TYPE})
-@Retention(RetentionPolicy.RUNTIME)
-public @interface DisabledTest {
- String message() default "";
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/EnormousTest.java b/base/test/android/javatests/src/org/chromium/base/test/util/EnormousTest.java
deleted file mode 100644
index af483ec..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/EnormousTest.java
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2012 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.
-
-package org.chromium.base.test.util;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * This annotation is for enormous tests.
- * <p>
- * Examples of enormous tests are tests that depend on external web sites or
- * tests that are long running.
- * <p>
- * Such tests are likely NOT reliable enough to run on tree closing bots and
- * should only be run on FYI bots.
- */
-@Target(ElementType.METHOD)
-@Retention(RetentionPolicy.RUNTIME)
-public @interface EnormousTest {
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/Feature.java b/base/test/android/javatests/src/org/chromium/base/test/util/Feature.java
deleted file mode 100644
index 1bc9226..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/Feature.java
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2012 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.
-
-package org.chromium.base.test.util;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * The java instrumentation tests are normally fairly large (in terms of
- * dependencies), and the test suite ends up containing a large amount of
- * tests that are not trivial to filter / group just by their names.
- * Instead, we use this annotation: each test should be annotated as:
- * @Feature({"Foo", "Bar"})
- * in order for the test runner scripts to be able to filter and group
- * them accordingly (for instance, this enable us to run all tests that exercise
- * feature Foo).
- */
-@Target(ElementType.METHOD)
-@Retention(RetentionPolicy.RUNTIME)
-public @interface Feature {
- /**
- * @return A list of feature names.
- */
- public String[] value();
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/FlakyTest.java b/base/test/android/javatests/src/org/chromium/base/test/util/FlakyTest.java
deleted file mode 100644
index 83f8e9f..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/FlakyTest.java
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2016 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.
-
-package org.chromium.base.test.util;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * This annotation is for flaky tests.
- * <p>
- * Tests with this annotation will not be run on any of the normal bots.
- * Please note that they might eventually run on a special bot.
- */
-@Target({ElementType.METHOD, ElementType.TYPE})
-@Retention(RetentionPolicy.RUNTIME)
-public @interface FlakyTest {
- String message() default "";
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/InMemorySharedPreferences.java b/base/test/android/javatests/src/org/chromium/base/test/util/InMemorySharedPreferences.java
deleted file mode 100644
index 2587d72..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/InMemorySharedPreferences.java
+++ /dev/null
@@ -1,238 +0,0 @@
-// Copyright 2013 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.
-
-package org.chromium.base.test.util;
-
-import android.content.SharedPreferences;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * An implementation of SharedPreferences that can be used in tests.
- * <p/>
- * It keeps all state in memory, and there is no difference between apply() and commit().
- */
-public class InMemorySharedPreferences implements SharedPreferences {
-
- // Guarded on its own monitor.
- private final Map<String, Object> mData;
-
- public InMemorySharedPreferences() {
- mData = new HashMap<String, Object>();
- }
-
- public InMemorySharedPreferences(Map<String, Object> data) {
- mData = data;
- }
-
- @Override
- public Map<String, ?> getAll() {
- synchronized (mData) {
- return Collections.unmodifiableMap(mData);
- }
- }
-
- @Override
- public String getString(String key, String defValue) {
- synchronized (mData) {
- if (mData.containsKey(key)) {
- return (String) mData.get(key);
- }
- }
- return defValue;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Set<String> getStringSet(String key, Set<String> defValues) {
- synchronized (mData) {
- if (mData.containsKey(key)) {
- return Collections.unmodifiableSet((Set<String>) mData.get(key));
- }
- }
- return defValues;
- }
-
- @Override
- public int getInt(String key, int defValue) {
- synchronized (mData) {
- if (mData.containsKey(key)) {
- return (Integer) mData.get(key);
- }
- }
- return defValue;
- }
-
- @Override
- public long getLong(String key, long defValue) {
- synchronized (mData) {
- if (mData.containsKey(key)) {
- return (Long) mData.get(key);
- }
- }
- return defValue;
- }
-
- @Override
- public float getFloat(String key, float defValue) {
- synchronized (mData) {
- if (mData.containsKey(key)) {
- return (Float) mData.get(key);
- }
- }
- return defValue;
- }
-
- @Override
- public boolean getBoolean(String key, boolean defValue) {
- synchronized (mData) {
- if (mData.containsKey(key)) {
- return (Boolean) mData.get(key);
- }
- }
- return defValue;
- }
-
- @Override
- public boolean contains(String key) {
- synchronized (mData) {
- return mData.containsKey(key);
- }
- }
-
- @Override
- public SharedPreferences.Editor edit() {
- return new InMemoryEditor();
- }
-
- @Override
- public void registerOnSharedPreferenceChangeListener(
- SharedPreferences.OnSharedPreferenceChangeListener
- listener) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void unregisterOnSharedPreferenceChangeListener(
- SharedPreferences.OnSharedPreferenceChangeListener listener) {
- throw new UnsupportedOperationException();
- }
-
- private class InMemoryEditor implements SharedPreferences.Editor {
-
- // All guarded by |mChanges|
- private boolean mClearCalled;
- private volatile boolean mApplyCalled;
- private final Map<String, Object> mChanges = new HashMap<String, Object>();
-
- @Override
- public SharedPreferences.Editor putString(String key, String value) {
- synchronized (mChanges) {
- if (mApplyCalled) throw new IllegalStateException();
- mChanges.put(key, value);
- return this;
- }
- }
-
- @Override
- public SharedPreferences.Editor putStringSet(String key, Set<String> values) {
- synchronized (mChanges) {
- if (mApplyCalled) throw new IllegalStateException();
- mChanges.put(key, values);
- return this;
- }
- }
-
- @Override
- public SharedPreferences.Editor putInt(String key, int value) {
- synchronized (mChanges) {
- if (mApplyCalled) throw new IllegalStateException();
- mChanges.put(key, value);
- return this;
- }
- }
-
- @Override
- public SharedPreferences.Editor putLong(String key, long value) {
- synchronized (mChanges) {
- if (mApplyCalled) throw new IllegalStateException();
- mChanges.put(key, value);
- return this;
- }
- }
-
- @Override
- public SharedPreferences.Editor putFloat(String key, float value) {
- synchronized (mChanges) {
- if (mApplyCalled) throw new IllegalStateException();
- mChanges.put(key, value);
- return this;
- }
- }
-
- @Override
- public SharedPreferences.Editor putBoolean(String key, boolean value) {
- synchronized (mChanges) {
- if (mApplyCalled) throw new IllegalStateException();
- mChanges.put(key, value);
- return this;
- }
- }
-
- @Override
- public SharedPreferences.Editor remove(String key) {
- synchronized (mChanges) {
- if (mApplyCalled) throw new IllegalStateException();
- // Magic value for removes
- mChanges.put(key, this);
- return this;
- }
- }
-
- @Override
- public SharedPreferences.Editor clear() {
- synchronized (mChanges) {
- if (mApplyCalled) throw new IllegalStateException();
- mClearCalled = true;
- return this;
- }
- }
-
- @Override
- public boolean commit() {
- apply();
- return true;
- }
-
- @Override
- public void apply() {
- synchronized (mData) {
- synchronized (mChanges) {
- if (mApplyCalled) throw new IllegalStateException();
- if (mClearCalled) {
- mData.clear();
- }
- for (Map.Entry<String, Object> entry : mChanges.entrySet()) {
- String key = entry.getKey();
- Object value = entry.getValue();
- if (value == this) {
- // Special value for removal
- mData.remove(key);
- } else {
- mData.put(key, value);
- }
- }
- // The real shared prefs clears out the temporaries allowing the caller to
- // reuse the Editor instance, however this is undocumented behavior and subtle
- // to read, so instead we just ban any future use of this instance.
- mApplyCalled = true;
- }
- }
- }
- }
-
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/InstrumentationUtils.java b/base/test/android/javatests/src/org/chromium/base/test/util/InstrumentationUtils.java
deleted file mode 100644
index 20cfd9d..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/InstrumentationUtils.java
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright 2012 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.
-
-package org.chromium.base.test.util;
-
-import android.app.Instrumentation;
-
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.FutureTask;
-
-/**
- * Utility methods built around the android.app.Instrumentation class.
- */
-public final class InstrumentationUtils {
-
- private InstrumentationUtils() {
- }
-
- public static <R> R runOnMainSyncAndGetResult(Instrumentation instrumentation,
- Callable<R> callable) throws Throwable {
- FutureTask<R> task = new FutureTask<R>(callable);
- instrumentation.runOnMainSync(task);
- try {
- return task.get();
- } catch (ExecutionException e) {
- // Unwrap the cause of the exception and re-throw it.
- throw e.getCause();
- }
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/IntegrationTest.java b/base/test/android/javatests/src/org/chromium/base/test/util/IntegrationTest.java
deleted file mode 100644
index 8b6550d..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/IntegrationTest.java
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2014 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.
-
-package org.chromium.base.test.util;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * This annotation is for integration tests.
- * <p>
- * Examples of integration tests are tests that rely on real instances of the
- * application's services and components (e.g. Search) to test the system as
- * a whole. These tests may use additional command-line flags to configure the
- * existing backends to use.
- * <p>
- * Such tests are likely NOT reliable enough to run on tree closing bots and
- * should only be run on FYI bots.
- */
-@Target(ElementType.METHOD)
-@Retention(RetentionPolicy.RUNTIME)
-public @interface IntegrationTest {
-}
\ No newline at end of file
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/Manual.java b/base/test/android/javatests/src/org/chromium/base/test/util/Manual.java
deleted file mode 100644
index 31f3977..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/Manual.java
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright 2012 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.
-
-package org.chromium.base.test.util;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * This annotation can be used to mark a test that should only be run manually.
- * <p>
- * Tests with this annotation will not be run on bots, because they take too long
- * or need manual monitoring.
- */
-@Target(ElementType.METHOD)
-@Retention(RetentionPolicy.RUNTIME)
-public @interface Manual {
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/ManualSkipCheck.java b/base/test/android/javatests/src/org/chromium/base/test/util/ManualSkipCheck.java
deleted file mode 100644
index a916bdf..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/ManualSkipCheck.java
+++ /dev/null
@@ -1,18 +0,0 @@
-// 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.
-
-package org.chromium.base.test.util;
-
-import org.junit.runners.model.FrameworkMethod;
-
-/**
- * Skips any test methods annotated with {@code @}{@link Manual}.
- */
-public class ManualSkipCheck extends SkipCheck {
- @Override
- public boolean shouldSkip(FrameworkMethod testMethod) {
- return !AnnotationProcessingUtils.getAnnotations(testMethod.getMethod(), Manual.class)
- .isEmpty();
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/Matchers.java b/base/test/android/javatests/src/org/chromium/base/test/util/Matchers.java
deleted file mode 100644
index fc9d689..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/Matchers.java
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2016 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.
-
-package org.chromium.base.test.util;
-
-import org.hamcrest.CoreMatchers;
-import org.hamcrest.Description;
-import org.hamcrest.Matcher;
-import org.hamcrest.TypeSafeMatcher;
-
-/**
- * Helper class containing Hamcrest matchers.
- */
-public class Matchers extends CoreMatchers {
- private static class GreaterThanOrEqualTo<T extends Comparable<T>>
- extends TypeSafeMatcher<T> {
-
- private final T mComparisonValue;
-
- public GreaterThanOrEqualTo(T comparisonValue) {
- mComparisonValue = comparisonValue;
- }
-
- @Override
- public void describeTo(Description description) {
- description.appendText("greater than or equal to ").appendValue(mComparisonValue);
- }
-
- @Override
- protected boolean matchesSafely(T item) {
- return item.compareTo(mComparisonValue) >= 0;
- }
- }
-
- /**
- * @param <T> A Comparable type.
- * @param comparisonValue The value to be compared against.
- * @return A matcher that expects the value to be greater than the |comparisonValue|.
- */
- public static <T extends Comparable<T>> Matcher<T> greaterThanOrEqualTo(T comparisonValue) {
- return new GreaterThanOrEqualTo<>(comparisonValue);
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/MetricsUtils.java b/base/test/android/javatests/src/org/chromium/base/test/util/MetricsUtils.java
deleted file mode 100644
index c4664d6..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/MetricsUtils.java
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright 2014 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.
-
-package org.chromium.base.test.util;
-
-import org.chromium.base.metrics.RecordHistogram;
-
-/**
- * Helpers for testing UMA metrics.
- */
-public class MetricsUtils {
- /**
- * Helper class that snapshots the given bucket of the given UMA histogram on its creation,
- * allowing to inspect the number of samples recorded during its lifetime.
- */
- public static class HistogramDelta {
- private final String mHistogram;
- private final int mSampleValue;
-
- private final int mInitialCount;
-
- private int get() {
- return RecordHistogram.getHistogramValueCountForTesting(mHistogram, mSampleValue);
- }
-
- /**
- * Snapshots the given bucket of the given histogram.
- * @param histogram name of the histogram to snapshot
- * @param sampleValue the bucket that contains this value will be snapshot
- */
- public HistogramDelta(String histogram, int sampleValue) {
- mHistogram = histogram;
- mSampleValue = sampleValue;
- mInitialCount = get();
- }
-
- /** Returns the number of samples of the snapshot bucket recorded since creation */
- public int getDelta() {
- return get() - mInitialCount;
- }
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/MinAndroidSdkLevel.java b/base/test/android/javatests/src/org/chromium/base/test/util/MinAndroidSdkLevel.java
deleted file mode 100644
index 13e2578..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/MinAndroidSdkLevel.java
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright 2014 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.
-
-package org.chromium.base.test.util;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Inherited
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD, ElementType.TYPE})
-public @interface MinAndroidSdkLevel {
- int value() default 0;
-}
-
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/MinAndroidSdkLevelSkipCheck.java b/base/test/android/javatests/src/org/chromium/base/test/util/MinAndroidSdkLevelSkipCheck.java
deleted file mode 100644
index 8b07c0f..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/MinAndroidSdkLevelSkipCheck.java
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright 2016 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.
-
-package org.chromium.base.test.util;
-
-import android.os.Build;
-
-import org.junit.runners.model.FrameworkMethod;
-
-import org.chromium.base.Log;
-
-/**
- * Checks the device's SDK level against any specified minimum requirement.
- */
-public class MinAndroidSdkLevelSkipCheck extends SkipCheck {
-
- private static final String TAG = "base_test";
-
- /**
- * If {@link MinAndroidSdkLevel} is present, checks its value
- * against the device's SDK level.
- *
- * @param testCase The test to check.
- * @return true if the device's SDK level is below the specified minimum.
- */
- @Override
- public boolean shouldSkip(FrameworkMethod frameworkMethod) {
- int minSdkLevel = 0;
- for (MinAndroidSdkLevel m : AnnotationProcessingUtils.getAnnotations(
- frameworkMethod.getMethod(), MinAndroidSdkLevel.class)) {
- minSdkLevel = Math.max(minSdkLevel, m.value());
- }
- if (Build.VERSION.SDK_INT < minSdkLevel) {
- Log.i(TAG, "Test " + frameworkMethod.getDeclaringClass().getName() + "#"
- + frameworkMethod.getName() + " is not enabled at SDK level "
- + Build.VERSION.SDK_INT + ".");
- return true;
- }
- return false;
- }
-
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/Restriction.java b/base/test/android/javatests/src/org/chromium/base/test/util/Restriction.java
deleted file mode 100644
index f39bfbd..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/Restriction.java
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2013 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.
-
-package org.chromium.base.test.util;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * An annotation for listing restrictions for a test method. For example, if a test method is only
- * applicable on a phone with small memory:
- * @Restriction({RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_SMALL_MEMORY})
- * Test classes are free to define restrictions and enforce them using reflection at runtime.
- */
-@Target({ElementType.METHOD, ElementType.TYPE})
-@Retention(RetentionPolicy.RUNTIME)
-public @interface Restriction {
- /** Specifies the test is only valid on low end devices that have less memory. */
- public static final String RESTRICTION_TYPE_LOW_END_DEVICE = "Low_End_Device";
-
- /** Specifies the test is only valid on non-low end devices. */
- public static final String RESTRICTION_TYPE_NON_LOW_END_DEVICE = "Non_Low_End_Device";
-
- /** Specifies the test is only valid on a device that can reach the internet. */
- public static final String RESTRICTION_TYPE_INTERNET = "Internet";
-
- /** Specifies the test is only valid on a device that has a camera. */
- public static final String RESTRICTION_TYPE_HAS_CAMERA = "Has_Camera";
-
- /**
- * @return A list of restrictions.
- */
- public String[] value();
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/RestrictionSkipCheck.java b/base/test/android/javatests/src/org/chromium/base/test/util/RestrictionSkipCheck.java
deleted file mode 100644
index a27dd1f..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/RestrictionSkipCheck.java
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright 2016 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.
-
-package org.chromium.base.test.util;
-
-import android.content.Context;
-import android.net.ConnectivityManager;
-import android.net.NetworkInfo;
-import android.text.TextUtils;
-
-import org.junit.runners.model.FrameworkMethod;
-
-import org.chromium.base.Log;
-import org.chromium.base.SysUtils;
-
-/**
- * Checks if any restrictions exist and skip the test if it meets those restrictions.
- */
-public class RestrictionSkipCheck extends SkipCheck {
-
- private static final String TAG = "base_test";
-
- private final Context mTargetContext;
-
- public RestrictionSkipCheck(Context targetContext) {
- mTargetContext = targetContext;
- }
-
- protected Context getTargetContext() {
- return mTargetContext;
- }
-
- @Override
- public boolean shouldSkip(FrameworkMethod frameworkMethod) {
- if (frameworkMethod == null) return true;
-
- for (Restriction restriction : AnnotationProcessingUtils.getAnnotations(
- frameworkMethod.getMethod(), Restriction.class)) {
- for (String restrictionVal : restriction.value()) {
- if (restrictionApplies(restrictionVal)) {
- Log.i(TAG, "Test " + frameworkMethod.getDeclaringClass().getName() + "#"
- + frameworkMethod.getName() + " skipped because of restriction "
- + restriction);
- return true;
- }
- }
- }
- return false;
- }
-
- protected boolean restrictionApplies(String restriction) {
- if (TextUtils.equals(restriction, Restriction.RESTRICTION_TYPE_LOW_END_DEVICE)
- && !SysUtils.isLowEndDevice()) {
- return true;
- }
- if (TextUtils.equals(restriction, Restriction.RESTRICTION_TYPE_NON_LOW_END_DEVICE)
- && SysUtils.isLowEndDevice()) {
- return true;
- }
- if (TextUtils.equals(restriction, Restriction.RESTRICTION_TYPE_INTERNET)
- && !isNetworkAvailable()) {
- return true;
- }
- if (TextUtils.equals(restriction, Restriction.RESTRICTION_TYPE_HAS_CAMERA)
- && !SysUtils.hasCamera(mTargetContext)) {
- return true;
- }
- return false;
- }
-
- private boolean isNetworkAvailable() {
- final ConnectivityManager connectivityManager = (ConnectivityManager)
- mTargetContext.getSystemService(Context.CONNECTIVITY_SERVICE);
- final NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
- return activeNetworkInfo != null && activeNetworkInfo.isConnected();
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/RetryOnFailure.java b/base/test/android/javatests/src/org/chromium/base/test/util/RetryOnFailure.java
deleted file mode 100644
index eb98008..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/RetryOnFailure.java
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2016 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.
-
-package org.chromium.base.test.util;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-// Note this annotation may be a NOOP. Check http://crbug.com/797002 for latest status (also see
-// http://crbug.com/619055). Current default behavior is to retry all tests on failure.
-/**
- * Mark a test as flaky and should be retried on failure. The test is
- * considered passed by the test script if any retry succeeds.
- *
- * Long term, this should be merged with @FlakyTest. But @FlakyTest means
- * has specific meaning that is currently different from RetryOnFailure.
- */
-@Target({ElementType.METHOD, ElementType.TYPE})
-@Retention(RetentionPolicy.RUNTIME)
-public @interface RetryOnFailure {
- String message() default "";
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/ScalableTimeout.java b/base/test/android/javatests/src/org/chromium/base/test/util/ScalableTimeout.java
deleted file mode 100644
index 7a815c0..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/ScalableTimeout.java
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2012 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.
-
-package org.chromium.base.test.util;
-
-/**
- * Utility class for scaling various timeouts by a common factor.
- * For example, to run tests under slow memory tools, you might do
- * something like this:
- * adb shell "echo 20.0 > /data/local/tmp/chrome_timeout_scale"
- */
-public class ScalableTimeout {
- private static Double sTimeoutScale;
- public static final String PROPERTY_FILE = "/data/local/tmp/chrome_timeout_scale";
-
- public static long scaleTimeout(long timeout) {
- if (sTimeoutScale == null) {
- try {
- char[] data = TestFileUtil.readUtf8File(PROPERTY_FILE, 32);
- sTimeoutScale = Double.parseDouble(new String(data));
- } catch (Exception e) {
- // NumberFormatException, FileNotFoundException, IOException
- sTimeoutScale = 1.0;
- }
- }
- return (long) (timeout * sTimeoutScale);
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/SkipCheck.java b/base/test/android/javatests/src/org/chromium/base/test/util/SkipCheck.java
deleted file mode 100644
index d1dd7be..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/SkipCheck.java
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2015 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.
-
-package org.chromium.base.test.util;
-
-import junit.framework.TestCase;
-
-import org.junit.runners.model.FrameworkMethod;
-
-import org.chromium.base.Log;
-
-import java.lang.reflect.Method;
-
-/**
- * Check whether a test case should be skipped.
- */
-public abstract class SkipCheck {
-
- private static final String TAG = "base_test";
-
- /**
- *
- * Checks whether the given test method should be skipped.
- *
- * @param testMethod The test method to check.
- * @return Whether the test case should be skipped.
- */
- public abstract boolean shouldSkip(FrameworkMethod testMethod);
-
- /**
- *
- * Checks whether the given test case should be skipped.
- *
- * @param testCase The test case to check.
- * @return Whether the test case should be skipped.
- */
- public boolean shouldSkip(TestCase testCase) {
- try {
- Method m = testCase.getClass().getMethod(testCase.getName(), (Class[]) null);
- return shouldSkip(new FrameworkMethod(m));
- } catch (NoSuchMethodException e) {
- Log.e(TAG, "Unable to find %s in %s", testCase.getName(),
- testCase.getClass().getName(), e);
- return false;
- }
- }
-}
-
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/TestFileUtil.java b/base/test/android/javatests/src/org/chromium/base/test/util/TestFileUtil.java
deleted file mode 100644
index 6d89121..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/TestFileUtil.java
+++ /dev/null
@@ -1,85 +0,0 @@
-// Copyright 2012 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.
-
-package org.chromium.base.test.util;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.Reader;
-import java.io.Writer;
-import java.util.Arrays;
-
-/**
- * Utility class for dealing with files for test.
- */
-public class TestFileUtil {
- public static void createNewHtmlFile(String name, String title, String body)
- throws IOException {
- createNewHtmlFile(new File(name), title, body);
- }
-
- public static void createNewHtmlFile(File file, String title, String body)
- throws IOException {
- if (!file.createNewFile()) {
- throw new IOException("File \"" + file.getAbsolutePath() + "\" already exists");
- }
-
- Writer writer = null;
- try {
- writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
- writer.write("<html><meta charset=\"UTF-8\" />"
- + " <head><title>" + title + "</title></head>"
- + " <body>"
- + (body != null ? body : "")
- + " </body>"
- + " </html>");
- } finally {
- if (writer != null) {
- writer.close();
- }
- }
- }
-
- public static void deleteFile(String name) {
- deleteFile(new File(name));
- }
-
- public static void deleteFile(File file) {
- boolean deleted = file.delete();
- assert (deleted || !file.exists());
- }
-
- /**
- * @param fileName the file to read in.
- * @param sizeLimit cap on the file size: will throw an exception if exceeded
- * @return Array of chars read from the file
- * @throws FileNotFoundException file does not exceed
- * @throws IOException error encountered accessing the file
- */
- public static char[] readUtf8File(String fileName, int sizeLimit) throws
- FileNotFoundException, IOException {
- Reader reader = null;
- try {
- File f = new File(fileName);
- if (f.length() > sizeLimit) {
- throw new IOException("File " + fileName + " length " + f.length()
- + " exceeds limit " + sizeLimit);
- }
- char[] buffer = new char[(int) f.length()];
- reader = new InputStreamReader(new FileInputStream(f), "UTF-8");
- int charsRead = reader.read(buffer);
- // Debug check that we've exhausted the input stream (will fail e.g. if the
- // file grew after we inspected its length).
- assert !reader.ready();
- return charsRead < buffer.length ? Arrays.copyOfRange(buffer, 0, charsRead) : buffer;
- } finally {
- if (reader != null) reader.close();
- }
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/TestThread.java b/base/test/android/javatests/src/org/chromium/base/test/util/TestThread.java
deleted file mode 100644
index 4f62969..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/TestThread.java
+++ /dev/null
@@ -1,143 +0,0 @@
-// Copyright 2012 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.
-
-package org.chromium.base.test.util;
-
-import android.os.Handler;
-import android.os.Looper;
-
-import java.util.concurrent.atomic.AtomicBoolean;
-
-/**
- * This class is usefull when writing instrumentation tests that exercise code that posts tasks
- * (to the same thread).
- * Since the test code is run in a single thread, the posted tasks are never executed.
- * The TestThread class lets you run that code on a specific thread synchronously and flush the
- * message loop on that thread.
- *
- * Example of test using this:
- *
- * public void testMyAwesomeClass() {
- * TestThread testThread = new TestThread();
- * testThread.startAndWaitForReadyState();
- *
- * testThread.runOnTestThreadSyncAndProcessPendingTasks(new Runnable() {
- * @Override
- * public void run() {
- * MyAwesomeClass.doStuffAsync();
- * }
- * });
- * // Once we get there we know doStuffAsync has been executed and all the tasks it posted.
- * assertTrue(MyAwesomeClass.stuffWasDone());
- * }
- *
- * Notes:
- * - this is only for tasks posted to the same thread. Anyway if you were posting to a different
- * thread, you'd probably need to set that other thread up.
- * - this only supports tasks posted using Handler.post(), it won't work with postDelayed and
- * postAtTime.
- * - if your test instanciates an object and that object is the one doing the posting of tasks, you
- * probably want to instanciate it on the test thread as it might create the Handler it posts
- * tasks to in the constructor.
- */
-
-public class TestThread extends Thread {
- private final Object mThreadReadyLock;
- private AtomicBoolean mThreadReady;
- private Handler mMainThreadHandler;
- private Handler mTestThreadHandler;
-
- public TestThread() {
- mMainThreadHandler = new Handler();
- // We can't use the AtomicBoolean as the lock or findbugs will freak out...
- mThreadReadyLock = new Object();
- mThreadReady = new AtomicBoolean();
- }
-
- @Override
- public void run() {
- Looper.prepare();
- mTestThreadHandler = new Handler();
- mTestThreadHandler.post(new Runnable() {
- @Override
- public void run() {
- synchronized (mThreadReadyLock) {
- mThreadReady.set(true);
- mThreadReadyLock.notify();
- }
- }
- });
- Looper.loop();
- }
-
- /**
- * Starts this TestThread and blocks until it's ready to accept calls.
- */
- public void startAndWaitForReadyState() {
- checkOnMainThread();
- start();
- synchronized (mThreadReadyLock) {
- try {
- // Note the mThreadReady and while are not really needed.
- // There are there so findbugs don't report warnings.
- while (!mThreadReady.get()) {
- mThreadReadyLock.wait();
- }
- } catch (InterruptedException ie) {
- System.err.println("Error starting TestThread.");
- ie.printStackTrace();
- }
- }
- }
-
- /**
- * Runs the passed Runnable synchronously on the TestThread and returns when all pending
- * runnables have been excuted.
- * Should be called from the main thread.
- */
- public void runOnTestThreadSyncAndProcessPendingTasks(Runnable r) {
- checkOnMainThread();
-
- runOnTestThreadSync(r);
-
- // Run another task, when it's done it means all pendings tasks have executed.
- runOnTestThreadSync(null);
- }
-
- /**
- * Runs the passed Runnable on the test thread and blocks until it has finished executing.
- * Should be called from the main thread.
- * @param r The runnable to be executed.
- */
- public void runOnTestThreadSync(final Runnable r) {
- checkOnMainThread();
- final Object lock = new Object();
- // Task executed is not really needed since we are only on one thread, it is here to appease
- // findbugs.
- final AtomicBoolean taskExecuted = new AtomicBoolean();
- mTestThreadHandler.post(new Runnable() {
- @Override
- public void run() {
- if (r != null) r.run();
- synchronized (lock) {
- taskExecuted.set(true);
- lock.notify();
- }
- }
- });
- synchronized (lock) {
- try {
- while (!taskExecuted.get()) {
- lock.wait();
- }
- } catch (InterruptedException ie) {
- ie.printStackTrace();
- }
- }
- }
-
- private void checkOnMainThread() {
- assert Looper.myLooper() == mMainThreadHandler.getLooper();
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/TimeoutScale.java b/base/test/android/javatests/src/org/chromium/base/test/util/TimeoutScale.java
deleted file mode 100644
index 5aee05e..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/TimeoutScale.java
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2012 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.
-
-package org.chromium.base.test.util;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * This annotation can be used to scale a specific test timeout.
- */
-@Target(ElementType.METHOD)
-@Retention(RetentionPolicy.RUNTIME)
-public @interface TimeoutScale {
- /**
- * @return A number to scale the test timeout.
- */
- public int value();
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/UrlUtils.java b/base/test/android/javatests/src/org/chromium/base/test/util/UrlUtils.java
deleted file mode 100644
index 9ca3fcc..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/UrlUtils.java
+++ /dev/null
@@ -1,84 +0,0 @@
-// Copyright 2012 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.
-
-package org.chromium.base.test.util;
-
-import org.junit.Assert;
-
-import org.chromium.base.PathUtils;
-import org.chromium.base.annotations.CalledByNative;
-import org.chromium.base.annotations.MainDex;
-
-/**
- * Collection of URL utilities.
- */
-@MainDex
-public class UrlUtils {
- private static final String DATA_DIR = "/chrome/test/data/";
-
- /**
- * Construct the full path of a test data file.
- * @param path Pathname relative to external/chrome/test/data
- */
- public static String getTestFilePath(String path) {
- // TODO(jbudorick): Remove DATA_DIR once everything has been isolated. crbug/400499
- return getIsolatedTestFilePath(DATA_DIR + path);
- }
-
- // TODO(jbudorick): Remove this function once everything has been isolated and switched back
- // to getTestFilePath. crbug/400499
- /**
- * Construct the full path of a test data file.
- * @param path Pathname relative to external/
- */
- public static String getIsolatedTestFilePath(String path) {
- return getIsolatedTestRoot() + "/" + path;
- }
-
- /**
- * Returns the root of the test data directory.
- */
- @CalledByNative
- public static String getIsolatedTestRoot() {
- return PathUtils.getExternalStorageDirectory() + "/chromium_tests_root";
- }
-
- /**
- * Construct a suitable URL for loading a test data file.
- * @param path Pathname relative to external/chrome/test/data
- */
- public static String getTestFileUrl(String path) {
- return "file://" + getTestFilePath(path);
- }
-
- // TODO(jbudorick): Remove this function once everything has been isolated and switched back
- // to getTestFileUrl. crbug/400499
- /**
- * Construct a suitable URL for loading a test data file.
- * @param path Pathname relative to external/
- */
- public static String getIsolatedTestFileUrl(String path) {
- return "file://" + getIsolatedTestFilePath(path);
- }
-
- /**
- * Construct a data:text/html URI for loading from an inline HTML.
- * @param html An unencoded HTML
- * @return String An URI that contains the given HTML
- */
- public static String encodeHtmlDataUri(String html) {
- try {
- // URLEncoder encodes into application/x-www-form-encoded, so
- // ' '->'+' needs to be undone and replaced with ' '->'%20'
- // to match the Data URI requirements.
- String encoded =
- "data:text/html;utf-8," + java.net.URLEncoder.encode(html, "UTF-8");
- encoded = encoded.replace("+", "%20");
- return encoded;
- } catch (java.io.UnsupportedEncodingException e) {
- Assert.fail("Unsupported encoding: " + e.getMessage());
- return null;
- }
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/UserActionTester.java b/base/test/android/javatests/src/org/chromium/base/test/util/UserActionTester.java
deleted file mode 100644
index 88e3551..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/UserActionTester.java
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test.util;
-
-import org.chromium.base.ThreadUtils;
-import org.chromium.base.metrics.RecordUserAction;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * A util class that records UserActions.
- */
-public class UserActionTester implements RecordUserAction.UserActionCallback {
- private List<String> mActions;
-
- public UserActionTester() {
- mActions = new ArrayList<>();
- ThreadUtils.runOnUiThreadBlocking(new Runnable() {
- @Override
- public void run() {
- RecordUserAction.setActionCallbackForTesting(UserActionTester.this);
- }
- });
- }
-
- public void tearDown() {
- ThreadUtils.runOnUiThreadBlocking(new Runnable() {
- @Override
- public void run() {
- RecordUserAction.removeActionCallbackForTesting();
- }
- });
- }
-
- @Override
- public void onActionRecorded(String action) {
- mActions.add(action);
- }
-
- public List<String> getActions() {
- return mActions;
- }
-
- @Override
- public String toString() {
- return "Actions: " + mActions.toString();
- }
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/parameter/CommandLineParameter.java b/base/test/android/javatests/src/org/chromium/base/test/util/parameter/CommandLineParameter.java
deleted file mode 100644
index e6f5506..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/parameter/CommandLineParameter.java
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright 2015 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.
-
-package org.chromium.base.test.util.parameter;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * The annotation for parametering CommandLineFlags in JUnit3 instrumentation tests.
- *
- * E.g. if you add the following annotation to your test class:
- *
- * <code>
- * @CommandLineParameter({"", FLAG_A, FLAG_B})
- * public class MyTestClass
- * </code>
- *
- * The test harness would run the test 3 times with each of the flag added to commandline
- * file.
- */
-
-@Inherited
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD, ElementType.TYPE})
-public @interface CommandLineParameter {
- String[] value() default {};
-}
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/parameter/SkipCommandLineParameterization.java b/base/test/android/javatests/src/org/chromium/base/test/util/parameter/SkipCommandLineParameterization.java
deleted file mode 100644
index 2181031..0000000
--- a/base/test/android/javatests/src/org/chromium/base/test/util/parameter/SkipCommandLineParameterization.java
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2017 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.
-package org.chromium.base.test.util.parameter;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * BaseJUnit4ClassRunner and host side test harness skips commandline parameterization for test
- * classes or methods annotated with SkipCommandLineParameterization.
- *
- * This usually used by test that only runs in WebView javatests that only runs in sandboxed mode
- * or single process mode.
- */
-
-@Inherited
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD, ElementType.TYPE})
-public @interface SkipCommandLineParameterization {}
diff --git a/base/test/android/junit/src/org/chromium/base/test/BaseRobolectricTestRunner.java b/base/test/android/junit/src/org/chromium/base/test/BaseRobolectricTestRunner.java
deleted file mode 100644
index 3ca756a..0000000
--- a/base/test/android/junit/src/org/chromium/base/test/BaseRobolectricTestRunner.java
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2015 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.
-
-package org.chromium.base.test;
-
-import org.junit.runners.model.InitializationError;
-import org.robolectric.DefaultTestLifecycle;
-import org.robolectric.RuntimeEnvironment;
-import org.robolectric.TestLifecycle;
-
-import org.chromium.base.ApplicationStatus;
-import org.chromium.base.CommandLine;
-import org.chromium.base.ContextUtils;
-import org.chromium.testing.local.LocalRobolectricTestRunner;
-
-import java.lang.reflect.Method;
-
-/**
- * A Robolectric Test Runner that initializes base globals.
- */
-public class BaseRobolectricTestRunner extends LocalRobolectricTestRunner {
- /**
- * Enables a per-test setUp / tearDown hook.
- */
- public static class BaseTestLifecycle extends DefaultTestLifecycle {
- @Override
- public void beforeTest(Method method) {
- ContextUtils.initApplicationContextForTests(RuntimeEnvironment.application);
- CommandLine.init(null);
- super.beforeTest(method);
- }
-
- @Override
- public void afterTest(Method method) {
- ApplicationStatus.destroyForJUnitTests();
- super.afterTest(method);
- }
- }
-
- public BaseRobolectricTestRunner(Class<?> testClass) throws InitializationError {
- super(testClass);
- }
-
- @Override
- protected Class<? extends TestLifecycle> getTestLifecycleClass() {
- return BaseTestLifecycle.class;
- }
-}
diff --git a/base/test/android/junit/src/org/chromium/base/test/SetUpStatementTest.java b/base/test/android/junit/src/org/chromium/base/test/SetUpStatementTest.java
deleted file mode 100644
index 722bd1a..0000000
--- a/base/test/android/junit/src/org/chromium/base/test/SetUpStatementTest.java
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test;
-
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.rules.TestRule;
-import org.junit.runner.RunWith;
-import org.junit.runners.BlockJUnit4ClassRunner;
-import org.junit.runners.model.Statement;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Test SetUpStatement is working as intended with SetUpTestRule.
- */
-@RunWith(BlockJUnit4ClassRunner.class)
-public class SetUpStatementTest {
- private Statement mBase;
- private SetUpTestRule<TestRule> mRule;
- private List<Integer> mList;
-
- @Before
- public void setUp() {
- mBase = new Statement() {
- @Override
- public void evaluate() {
- mList.add(1);
- }
- };
- mList = new ArrayList<>();
- mRule = new SetUpTestRule<TestRule>() {
- @Override
- public void setUp() {
- mList.add(0);
- }
-
- @Override
- public TestRule shouldSetUp(boolean toSetUp) {
- return null;
- }
- };
- }
-
- @Test
- public void testSetUpStatementShouldSetUp() throws Throwable {
- SetUpStatement statement = new SetUpStatement(mBase, mRule, true);
- statement.evaluate();
- Integer[] expected = {0, 1};
- Assert.assertArrayEquals(expected, mList.toArray());
- }
-
- @Test
- public void testSetUpStatementShouldNotSetUp() throws Throwable {
- SetUpStatement statement = new SetUpStatement(mBase, mRule, false);
- statement.evaluate();
- Integer[] expected = {1};
- Assert.assertArrayEquals(expected, mList.toArray());
- }
-}
diff --git a/base/test/android/junit/src/org/chromium/base/test/TestListInstrumentationRunListenerTest.java b/base/test/android/junit/src/org/chromium/base/test/TestListInstrumentationRunListenerTest.java
deleted file mode 100644
index 63fa560..0000000
--- a/base/test/android/junit/src/org/chromium/base/test/TestListInstrumentationRunListenerTest.java
+++ /dev/null
@@ -1,119 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test;
-
-import static org.chromium.base.test.TestListInstrumentationRunListener.getAnnotationJSON;
-import static org.chromium.base.test.TestListInstrumentationRunListener.getTestMethodJSON;
-
-import org.json.JSONObject;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.runner.Description;
-import org.junit.runner.RunWith;
-import org.robolectric.annotation.Config;
-
-import org.chromium.base.test.util.CommandLineFlags;
-
-import java.util.Arrays;
-
-/**
- * Robolectric test to ensure static methods in TestListInstrumentationRunListener works properly.
- */
-@RunWith(BaseRobolectricTestRunner.class)
-@Config(manifest = Config.NONE)
-public class TestListInstrumentationRunListenerTest {
- @CommandLineFlags.Add("hello")
- private static class ParentClass {
- public void testA() {}
-
- @CommandLineFlags.Add("world")
- public void testB() {}
- }
-
- @CommandLineFlags.Remove("hello")
- private static class ChildClass extends ParentClass {
- }
-
- @Test
- public void testGetTestMethodJSON_testA() throws Throwable {
- Description desc = Description.createTestDescription(
- ParentClass.class, "testA",
- ParentClass.class.getMethod("testA").getAnnotations());
- JSONObject json = getTestMethodJSON(desc);
- String expectedJsonString =
- "{"
- + "'method': 'testA',"
- + "'annotations': {}"
- + "}";
- expectedJsonString = expectedJsonString
- .replaceAll("\\s", "")
- .replaceAll("'", "\"");
- Assert.assertEquals(expectedJsonString, json.toString());
- }
-
- @Test
- public void testGetTestMethodJSON_testB() throws Throwable {
- Description desc = Description.createTestDescription(
- ParentClass.class, "testB",
- ParentClass.class.getMethod("testB").getAnnotations());
- JSONObject json = getTestMethodJSON(desc);
- String expectedJsonString =
- "{"
- + "'method': 'testB',"
- + "'annotations': {"
- + " 'Add': {"
- + " 'value': ['world']"
- + " }"
- + " }"
- + "}";
- expectedJsonString = expectedJsonString
- .replaceAll("\\s", "")
- .replaceAll("'", "\"");
- Assert.assertEquals(expectedJsonString, json.toString());
- }
-
-
- @Test
- public void testGetTestMethodJSONForInheritedClass() throws Throwable {
- Description desc = Description.createTestDescription(
- ChildClass.class, "testB",
- ChildClass.class.getMethod("testB").getAnnotations());
- JSONObject json = getTestMethodJSON(desc);
- String expectedJsonString =
- "{"
- + "'method': 'testB',"
- + "'annotations': {"
- + " 'Add': {"
- + " 'value': ['world']"
- + " }"
- + " }"
- + "}";
- expectedJsonString = expectedJsonString
- .replaceAll("\\s", "")
- .replaceAll("'", "\"");
- Assert.assertEquals(expectedJsonString, json.toString());
- }
-
- @Test
- public void testGetAnnotationJSONForParentClass() throws Throwable {
- JSONObject json = getAnnotationJSON(Arrays.asList(ParentClass.class.getAnnotations()));
- String expectedJsonString = "{'Add':{'value':['hello']}}";
- expectedJsonString = expectedJsonString
- .replaceAll("\\s", "")
- .replaceAll("'", "\"");
- Assert.assertEquals(expectedJsonString, json.toString());
- }
-
- @Test
- public void testGetAnnotationJSONForChildClass() throws Throwable {
- JSONObject json = getAnnotationJSON(Arrays.asList(ChildClass.class.getAnnotations()));
- String expectedJsonString = "{'Add':{'value':['hello']},'Remove':{'value':['hello']}}";
- expectedJsonString = expectedJsonString
- .replaceAll("\\s", "")
- .replaceAll("'", "\"");
- Assert.assertEquals(expectedJsonString, json.toString());
- }
-}
-
diff --git a/base/test/android/junit/src/org/chromium/base/test/params/ExampleParameterizedTest.java b/base/test/android/junit/src/org/chromium/base/test/params/ExampleParameterizedTest.java
deleted file mode 100644
index 6ffccad..0000000
--- a/base/test/android/junit/src/org/chromium/base/test/params/ExampleParameterizedTest.java
+++ /dev/null
@@ -1,105 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test.params;
-
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.MethodRule;
-import org.junit.runner.RunWith;
-
-import org.chromium.base.test.params.ParameterAnnotations.ClassParameter;
-import org.chromium.base.test.params.ParameterAnnotations.UseMethodParameter;
-import org.chromium.base.test.params.ParameterAnnotations.UseMethodParameterAfter;
-import org.chromium.base.test.params.ParameterAnnotations.UseMethodParameterBefore;
-import org.chromium.base.test.params.ParameterAnnotations.UseRunnerDelegate;
-
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * Example test that uses ParameterizedRunner
- */
-@RunWith(ParameterizedRunner.class)
-@UseRunnerDelegate(BlockJUnit4RunnerDelegate.class)
-public class ExampleParameterizedTest {
- @ClassParameter
- private static List<ParameterSet> sClassParams =
- Arrays.asList(new ParameterSet().value("hello", "world").name("HelloWorld"),
- new ParameterSet().value("Xxxx", "Yyyy").name("XxxxYyyy"),
- new ParameterSet().value("aa", "yy").name("AaYy"));
-
- public static class MethodParamsA implements ParameterProvider {
- private static List<ParameterSet> sMethodParamA =
- Arrays.asList(new ParameterSet().value(1, 2).name("OneTwo"),
- new ParameterSet().value(2, 3).name("TwoThree"),
- new ParameterSet().value(3, 4).name("ThreeFour"));
-
- @Override
- public List<ParameterSet> getParameters() {
- return sMethodParamA;
- }
- }
-
- public static class MethodParamsB implements ParameterProvider {
- private static List<ParameterSet> sMethodParamB =
- Arrays.asList(new ParameterSet().value("a", "b").name("Ab"),
- new ParameterSet().value("b", "c").name("Bc"),
- new ParameterSet().value("c", "d").name("Cd"),
- new ParameterSet().value("d", "e").name("De"));
-
- @Override
- public List<ParameterSet> getParameters() {
- return sMethodParamB;
- }
- }
-
- private String mStringA;
- private String mStringB;
-
- public ExampleParameterizedTest(String a, String b) {
- mStringA = a;
- mStringB = b;
- }
-
- @Test
- public void testSimple() {
- Assert.assertEquals(
- "A and B string length aren't equal", mStringA.length(), mStringB.length());
- }
-
- @Rule
- public MethodRule mMethodParamAnnotationProcessor = new MethodParamAnnotationRule();
-
- private Integer mSum;
-
- @UseMethodParameterBefore(MethodParamsA.class)
- public void setupWithOnlyA(int intA, int intB) {
- mSum = intA + intB;
- }
-
- @Test
- @UseMethodParameter(MethodParamsA.class)
- public void testWithOnlyA(int intA, int intB) {
- Assert.assertEquals(intA + 1, intB);
- Assert.assertEquals(mSum, Integer.valueOf(intA + intB));
- mSum = null;
- }
-
- private String mConcatenation;
-
- @Test
- @UseMethodParameter(MethodParamsB.class)
- public void testWithOnlyB(String a, String b) {
- Assert.assertTrue(!a.equals(b));
- mConcatenation = a + b;
- }
-
- @UseMethodParameterAfter(MethodParamsB.class)
- public void teardownWithOnlyB(String a, String b) {
- Assert.assertEquals(mConcatenation, a + b);
- mConcatenation = null;
- }
-}
diff --git a/base/test/android/junit/src/org/chromium/base/test/params/ParameterizedRunnerDelegateCommonTest.java b/base/test/android/junit/src/org/chromium/base/test/params/ParameterizedRunnerDelegateCommonTest.java
deleted file mode 100644
index 6d854c5..0000000
--- a/base/test/android/junit/src/org/chromium/base/test/params/ParameterizedRunnerDelegateCommonTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-// 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.
-
-package org.chromium.base.test.params;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.BlockJUnit4ClassRunner;
-import org.junit.runners.model.TestClass;
-
-import org.chromium.base.test.params.ParameterizedRunner.ParameterizedTestInstantiationException;
-
-import java.util.Collections;
-
-@RunWith(BlockJUnit4ClassRunner.class)
-public class ParameterizedRunnerDelegateCommonTest {
- /**
- * Create a test object using the list of class parameter set
- *
- * @param testClass the {@link TestClass} object for current test class
- * @param classParameterSet the parameter set needed for the test class constructor
- */
- private static Object createTest(TestClass testClass, ParameterSet classParameterSet)
- throws ParameterizedTestInstantiationException {
- return new ParameterizedRunnerDelegateCommon(
- testClass, classParameterSet, Collections.emptyList())
- .createTest();
- }
-
- static class BadTestClassWithMoreThanOneConstructor {
- public BadTestClassWithMoreThanOneConstructor() {}
- @SuppressWarnings("unused")
- public BadTestClassWithMoreThanOneConstructor(String argument) {}
- }
-
- static class BadTestClassWithTwoArgumentConstructor {
- @SuppressWarnings("unused")
- public BadTestClassWithTwoArgumentConstructor(int a, int b) {}
- }
-
- static abstract class BadTestClassAbstract {
- public BadTestClassAbstract() {}
- }
-
- static class BadTestClassConstructorThrows {
- public BadTestClassConstructorThrows() {
- throw new RuntimeException();
- }
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testCreateTestWithMoreThanOneConstructor() throws Throwable {
- TestClass testClass = new TestClass(BadTestClassWithMoreThanOneConstructor.class);
- createTest(testClass, null);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testCreateTestWithIncorrectArguments() throws Throwable {
- TestClass testClass = new TestClass(BadTestClassWithTwoArgumentConstructor.class);
- ParameterSet pSet = new ParameterSet().value(1, 2, 3);
- createTest(testClass, pSet);
- }
-
- @Test(expected = ParameterizedTestInstantiationException.class)
- public void testCreateTestWithAbstractClass() throws ParameterizedTestInstantiationException {
- TestClass testClass = new TestClass(BadTestClassAbstract.class);
- createTest(testClass, null);
- }
-
- @Test(expected = ParameterizedTestInstantiationException.class)
- public void testCreateTestWithThrowingConstructor()
- throws ParameterizedTestInstantiationException {
- TestClass testClass = new TestClass(BadTestClassConstructorThrows.class);
- createTest(testClass, null);
- }
-}
diff --git a/base/test/android/junit/src/org/chromium/base/test/params/ParameterizedRunnerDelegateFactoryTest.java b/base/test/android/junit/src/org/chromium/base/test/params/ParameterizedRunnerDelegateFactoryTest.java
deleted file mode 100644
index 723382d..0000000
--- a/base/test/android/junit/src/org/chromium/base/test/params/ParameterizedRunnerDelegateFactoryTest.java
+++ /dev/null
@@ -1,133 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test.params;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.BlockJUnit4ClassRunner;
-import org.junit.runners.model.FrameworkMethod;
-import org.junit.runners.model.InitializationError;
-import org.junit.runners.model.TestClass;
-
-import org.chromium.base.test.params.ParameterAnnotations.UseMethodParameter;
-import org.chromium.base.test.params.ParameterizedRunnerDelegateFactory.ParameterizedRunnerDelegateInstantiationException;
-
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Test for org.chromium.base.test.params.ParameterizedRunnerDelegateFactory
- */
-@RunWith(BlockJUnit4ClassRunner.class)
-public class ParameterizedRunnerDelegateFactoryTest {
- /**
- * This RunnerDelegate calls `super.collectInitializationErrors()` and would
- * cause BlockJUnit4ClassRunner to validate test classes.
- */
- public static class BadExampleRunnerDelegate
- extends BlockJUnit4ClassRunner implements ParameterizedRunnerDelegate {
- public static class LalaTestClass {}
-
- private final List<FrameworkMethod> mParameterizedFrameworkMethodList;
-
- BadExampleRunnerDelegate(Class<?> klass,
- List<FrameworkMethod> parameterizedFrameworkMethods) throws InitializationError {
- super(klass);
- mParameterizedFrameworkMethodList = parameterizedFrameworkMethods;
- }
-
- @Override
- public void collectInitializationErrors(List<Throwable> errors) {
- super.collectInitializationErrors(errors); // This is wrong!!
- }
-
- @Override
- public List<FrameworkMethod> computeTestMethods() {
- return mParameterizedFrameworkMethodList;
- }
-
- @Override
- public Object createTest() {
- return null;
- }
- }
-
- static class ExampleTestClass {
- static class MethodParamsA implements ParameterProvider {
- @Override
- public Iterable<ParameterSet> getParameters() {
- return Arrays.asList(
- new ParameterSet().value("a").name("testWithValue_a"),
- new ParameterSet().value("b").name("testWithValue_b")
- );
- }
- }
-
- @SuppressWarnings("unused")
- @UseMethodParameter(MethodParamsA.class)
- @Test
- public void testA(String a) {}
-
- static class MethodParamsB implements ParameterProvider {
- @Override
- public Iterable<ParameterSet> getParameters() {
- return Arrays.asList(
- new ParameterSet().value(1).name("testWithValue_1"),
- new ParameterSet().value(2).name("testWithValue_2"),
- new ParameterSet().value(3).name("testWithValue_3")
- );
- }
- }
-
- @SuppressWarnings("unused")
- @UseMethodParameter(MethodParamsB.class)
- @Test
- public void testB(int b) {}
-
- @Test
- public void testByMyself() {}
- }
-
- /**
- * This test validates ParameterizedRunnerDelegateFactory throws exception when
- * a runner delegate does not override the collectInitializationErrors method.
- */
- @Test(expected = ParameterizedRunnerDelegateInstantiationException.class)
- public void testBadRunnerDelegateWithIncorrectValidationCall() throws Throwable {
- ParameterizedRunnerDelegateFactory factory = new ParameterizedRunnerDelegateFactory();
- TestClass testClass = new TestClass(BadExampleRunnerDelegate.LalaTestClass.class);
- factory.createRunner(testClass, null, BadExampleRunnerDelegate.class);
- }
-
- @Test
- public void testGenerateParameterizedFrameworkMethod() throws Throwable {
- List<FrameworkMethod> methods =
- ParameterizedRunnerDelegateFactory.generateUnmodifiableFrameworkMethodList(
- new TestClass(ExampleTestClass.class), "");
-
- Assert.assertEquals(methods.size(), 6);
-
- Map<String, Method> expectedTests = new HashMap<>();
- Method testMethodA = ExampleTestClass.class.getDeclaredMethod("testA", String.class);
- Method testMethodB = ExampleTestClass.class.getDeclaredMethod("testB", int.class);
- Method testMethodByMyself = ExampleTestClass.class.getDeclaredMethod("testByMyself");
- expectedTests.put("testA__testWithValue_a", testMethodA);
- expectedTests.put("testA__testWithValue_b", testMethodA);
- expectedTests.put("testB__testWithValue_1", testMethodB);
- expectedTests.put("testB__testWithValue_2", testMethodB);
- expectedTests.put("testB__testWithValue_3", testMethodB);
- expectedTests.put("testByMyself", testMethodByMyself);
- for (FrameworkMethod method : methods) {
- Assert.assertNotNull(expectedTests.get(method.getName()));
- Assert.assertEquals(expectedTests.get(method.getName()), method.getMethod());
- expectedTests.remove(method.getName());
- }
- Assert.assertTrue(expectedTests.isEmpty());
- }
-}
diff --git a/base/test/android/junit/src/org/chromium/base/test/params/ParameterizedRunnerTest.java b/base/test/android/junit/src/org/chromium/base/test/params/ParameterizedRunnerTest.java
deleted file mode 100644
index 170ff69..0000000
--- a/base/test/android/junit/src/org/chromium/base/test/params/ParameterizedRunnerTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test.params;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.BlockJUnit4ClassRunner;
-
-import org.chromium.base.test.params.ParameterAnnotations.ClassParameter;
-import org.chromium.base.test.params.ParameterAnnotations.UseRunnerDelegate;
-import org.chromium.base.test.params.ParameterizedRunner.IllegalParameterArgumentException;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Test for org.chromium.base.test.params.ParameterizedRunner
- */
-@RunWith(BlockJUnit4ClassRunner.class)
-public class ParameterizedRunnerTest {
- @UseRunnerDelegate(BlockJUnit4RunnerDelegate.class)
- public static class BadTestClassWithMoreThanOneConstructor {
- @ClassParameter
- static List<ParameterSet> sClassParams = new ArrayList<>();
-
- public BadTestClassWithMoreThanOneConstructor() {}
-
- public BadTestClassWithMoreThanOneConstructor(String x) {}
- }
-
- @UseRunnerDelegate(BlockJUnit4RunnerDelegate.class)
- public static class BadTestClassWithNonListParameters {
- @ClassParameter
- static String[] sMethodParamA = {"1", "2"};
-
- @Test
- public void test() {}
- }
-
- @UseRunnerDelegate(BlockJUnit4RunnerDelegate.class)
- public static class BadTestClassWithoutNeedForParameterization {
- @Test
- public void test() {}
- }
-
- @UseRunnerDelegate(BlockJUnit4RunnerDelegate.class)
- public static class BadTestClassWithNonStaticParameterSetList {
- @ClassParameter
- public List<ParameterSet> mClassParams = new ArrayList<>();
-
- @Test
- public void test() {}
- }
-
- @UseRunnerDelegate(BlockJUnit4RunnerDelegate.class)
- public static class BadTestClassWithMultipleClassParameter {
- @ClassParameter
- private static List<ParameterSet> sParamA = new ArrayList<>();
-
- @ClassParameter
- private static List<ParameterSet> sParamB = new ArrayList<>();
- }
-
- @Test(expected = ParameterizedRunner.IllegalParameterArgumentException.class)
- public void testEmptyParameterSet() {
- List<ParameterSet> paramList = new ArrayList<>();
- paramList.add(new ParameterSet());
- ParameterizedRunner.validateWidth(paramList);
- }
-
- @Test(expected = ParameterizedRunner.IllegalParameterArgumentException.class)
- public void testUnequalWidthParameterSetList() {
- List<ParameterSet> paramList = new ArrayList<>();
- paramList.add(new ParameterSet().value(1, 2));
- paramList.add(new ParameterSet().value(3, 4, 5));
- ParameterizedRunner.validateWidth(paramList);
- }
-
- @Test(expected = ParameterizedRunner.IllegalParameterArgumentException.class)
- public void testUnequalWidthParameterSetListWithNull() {
- List<ParameterSet> paramList = new ArrayList<>();
- paramList.add(new ParameterSet().value(null));
- paramList.add(new ParameterSet().value(1, 2));
- ParameterizedRunner.validateWidth(paramList);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testBadClassWithNonListParameters() throws Throwable {
- new ParameterizedRunner(BadTestClassWithNonListParameters.class);
- }
-
- @Test(expected = IllegalParameterArgumentException.class)
- public void testBadClassWithNonStaticParameterSetList() throws Throwable {
- new ParameterizedRunner(BadTestClassWithNonStaticParameterSetList.class);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testBadClassWithoutNeedForParameterization() throws Throwable {
- new ParameterizedRunner(BadTestClassWithoutNeedForParameterization.class);
- }
-
- @Test(expected = Exception.class)
- public void testBadClassWithMoreThanOneConstructor() throws Throwable {
- new ParameterizedRunner(BadTestClassWithMoreThanOneConstructor.class);
- }
-}
diff --git a/base/test/android/junit/src/org/chromium/base/test/params/ParameterizedTestNameTest.java b/base/test/android/junit/src/org/chromium/base/test/params/ParameterizedTestNameTest.java
deleted file mode 100644
index e79f5c5..0000000
--- a/base/test/android/junit/src/org/chromium/base/test/params/ParameterizedTestNameTest.java
+++ /dev/null
@@ -1,201 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test.params;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runner.Runner;
-import org.junit.runners.BlockJUnit4ClassRunner;
-import org.junit.runners.model.FrameworkMethod;
-import org.junit.runners.model.TestClass;
-
-import org.chromium.base.test.params.ParameterAnnotations.ClassParameter;
-import org.chromium.base.test.params.ParameterAnnotations.UseMethodParameter;
-import org.chromium.base.test.params.ParameterAnnotations.UseRunnerDelegate;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * Test for verify the names and test method Description works properly
- */
-@RunWith(BlockJUnit4ClassRunner.class)
-public class ParameterizedTestNameTest {
- @UseRunnerDelegate(BlockJUnit4RunnerDelegate.class)
- public static class TestClassWithClassParameterAppendName {
- @ClassParameter
- static List<ParameterSet> sAllName = Arrays.asList(
- new ParameterSet().value("hello").name("Hello"),
- new ParameterSet().value("world").name("World")
- );
-
- public TestClassWithClassParameterAppendName(String a) {}
-
- @Test
- public void test() {}
- }
-
- @UseRunnerDelegate(BlockJUnit4RunnerDelegate.class)
- public static class TestClassWithClassParameterDefaultName {
- @ClassParameter
- static List<ParameterSet> sAllName = Arrays.asList(
- new ParameterSet().value("hello"),
- new ParameterSet().value("world")
- );
-
- public TestClassWithClassParameterDefaultName(String a) {}
-
- @Test
- public void test() {}
- }
-
- @UseRunnerDelegate(BlockJUnit4RunnerDelegate.class)
- public static class TestClassWithMethodParameter {
- static class AppendNameParams implements ParameterProvider {
- @Override
- public Iterable<ParameterSet> getParameters() {
- return Arrays.asList(
- new ParameterSet().value("hello").name("Hello"),
- new ParameterSet().value("world").name("World")
- );
- }
- }
-
- static class DefaultNameParams implements ParameterProvider {
- @Override
- public Iterable<ParameterSet> getParameters() {
- return Arrays.asList(
- new ParameterSet().value("hello"),
- new ParameterSet().value("world")
- );
- }
- }
-
- @UseMethodParameter(AppendNameParams.class)
- @Test
- public void test(String a) {}
-
- @UseMethodParameter(DefaultNameParams.class)
- @Test
- public void testDefaultName(String b) {}
- }
-
- @UseRunnerDelegate(BlockJUnit4RunnerDelegate.class)
- public static class TestClassWithMixedParameter {
- @ClassParameter
- static List<ParameterSet> sAllName = Arrays.asList(
- new ParameterSet().value("hello").name("Hello"),
- new ParameterSet().value("world").name("World")
- );
-
- static class AppendNameParams implements ParameterProvider {
- @Override
- public Iterable<ParameterSet> getParameters() {
- return Arrays.asList(
- new ParameterSet().value("1").name("A"),
- new ParameterSet().value("2").name("B")
- );
- }
- }
-
- public TestClassWithMixedParameter(String a) {}
-
- @UseMethodParameter(AppendNameParams.class)
- @Test
- public void testA(String a) {}
-
- @Test
- public void test() {}
- }
-
- @Test
- public void testClassParameterAppendName() throws Throwable {
- List<Runner> runners = ParameterizedRunner.createRunners(
- new TestClass(TestClassWithClassParameterAppendName.class));
- List<String> expectedTestNames =
- new LinkedList<String>(Arrays.asList("test__Hello", "test__World"));
- List<String> computedMethodNames = new ArrayList<>();
- for (Runner r : runners) {
- BlockJUnit4RunnerDelegate castedRunner = (BlockJUnit4RunnerDelegate) r;
- for (FrameworkMethod method : castedRunner.computeTestMethods()) {
- computedMethodNames.add(method.getName());
- Assert.assertTrue("This test name is not expected: " + method.getName(),
- expectedTestNames.contains(method.getName()));
- expectedTestNames.remove(method.getName());
- method.getName();
- }
- }
- Assert.assertTrue(
- String.format(
- "These names were provided: %s, these expected names are not found: %s",
- Arrays.toString(computedMethodNames.toArray()),
- Arrays.toString(expectedTestNames.toArray())),
- expectedTestNames.isEmpty());
- }
-
- @Test
- public void testClassParameterDefaultName() throws Throwable {
- List<Runner> runners = ParameterizedRunner.createRunners(
- new TestClass(TestClassWithClassParameterDefaultName.class));
- List<String> expectedTestNames = new LinkedList<String>(Arrays.asList("test", "test"));
- for (Runner r : runners) {
- @SuppressWarnings("unchecked")
- BlockJUnit4RunnerDelegate castedRunner = (BlockJUnit4RunnerDelegate) r;
- for (FrameworkMethod method : castedRunner.computeTestMethods()) {
- Assert.assertTrue("This test name is not expected: " + method.getName(),
- expectedTestNames.contains(method.getName()));
- expectedTestNames.remove(method.getName());
- method.getName();
- }
- }
- Assert.assertTrue("These expected names are not found: "
- + Arrays.toString(expectedTestNames.toArray()),
- expectedTestNames.isEmpty());
- }
-
- @Test
- public void testMethodParameter() throws Throwable {
- List<Runner> runners = ParameterizedRunner.createRunners(
- new TestClass(TestClassWithMethodParameter.class));
- List<String> expectedTestNames = new LinkedList<String>(
- Arrays.asList("test__Hello", "test__World", "testDefaultName", "testDefaultName"));
- for (Runner r : runners) {
- BlockJUnit4RunnerDelegate castedRunner = (BlockJUnit4RunnerDelegate) r;
- for (FrameworkMethod method : castedRunner.computeTestMethods()) {
- Assert.assertTrue("This test name is not expected: " + method.getName(),
- expectedTestNames.contains(method.getName()));
- expectedTestNames.remove(method.getName());
- method.getName();
- }
- }
- Assert.assertTrue("These expected names are not found: "
- + Arrays.toString(expectedTestNames.toArray()),
- expectedTestNames.isEmpty());
- }
-
- @Test
- public void testMixedParameterTestA() throws Throwable {
- List<Runner> runners =
- ParameterizedRunner.createRunners(new TestClass(TestClassWithMixedParameter.class));
- List<String> expectedTestNames =
- new LinkedList<String>(Arrays.asList("testA__Hello_A", "testA__World_A",
- "testA__Hello_B", "testA__World_B", "test__Hello", "test__World"));
- for (Runner r : runners) {
- BlockJUnit4RunnerDelegate castedRunner = (BlockJUnit4RunnerDelegate) r;
- for (FrameworkMethod method : castedRunner.computeTestMethods()) {
- Assert.assertTrue("This test name is not expected: " + method.getName(),
- expectedTestNames.contains(method.getName()));
- expectedTestNames.remove(method.getName());
- method.getName();
- }
- }
- Assert.assertTrue("These expected names are not found: "
- + Arrays.toString(expectedTestNames.toArray()),
- expectedTestNames.isEmpty());
- }
-}
diff --git a/base/test/android/junit/src/org/chromium/base/test/util/AnnotationProcessingUtilsTest.java b/base/test/android/junit/src/org/chromium/base/test/util/AnnotationProcessingUtilsTest.java
deleted file mode 100644
index 9acd141..0000000
--- a/base/test/android/junit/src/org/chromium/base/test/util/AnnotationProcessingUtilsTest.java
+++ /dev/null
@@ -1,377 +0,0 @@
-// Copyright 2017 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.
-
-package org.chromium.base.test.util;
-
-import static org.hamcrest.Matchers.contains;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
-import static org.junit.runner.Description.createTestDescription;
-
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TestRule;
-import org.junit.runner.Description;
-import org.junit.runner.RunWith;
-import org.junit.runners.BlockJUnit4ClassRunner;
-import org.junit.runners.model.FrameworkMethod;
-import org.junit.runners.model.InitializationError;
-import org.junit.runners.model.Statement;
-
-import org.chromium.base.test.util.AnnotationProcessingUtils.AnnotationExtractor;
-
-import java.lang.annotation.Annotation;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.List;
-
-/** Test for {@link AnnotationProcessingUtils}. */
-@RunWith(BlockJUnit4ClassRunner.class)
-public class AnnotationProcessingUtilsTest {
- @Test
- public void testGetTargetAnnotation_NotOnClassNorMethod() {
- TargetAnnotation retrievedAnnotation;
-
- retrievedAnnotation = AnnotationProcessingUtils.getAnnotation(
- createTestDescription(
- ClassWithoutTargetAnnotation.class, "methodWithoutAnnotation"),
- TargetAnnotation.class);
- assertNull(retrievedAnnotation);
- }
-
- @Test
- public void testGetTargetAnnotation_NotOnClassButOnMethod() {
- TargetAnnotation retrievedAnnotation;
-
- retrievedAnnotation = AnnotationProcessingUtils.getAnnotation(
- getTest(ClassWithoutTargetAnnotation.class, "methodWithTargetAnnotation"),
- TargetAnnotation.class);
- assertNotNull(retrievedAnnotation);
- }
-
- @Test
- public void testGetTargetAnnotation_NotOnClassDifferentOneOnMethod() {
- TargetAnnotation retrievedAnnotation;
-
- retrievedAnnotation = AnnotationProcessingUtils.getAnnotation(
- getTest(ClassWithoutTargetAnnotation.class, "methodWithAnnotatedAnnotation"),
- TargetAnnotation.class);
- assertNull(retrievedAnnotation);
- }
-
- @Test
- public void testGetTargetAnnotation_OnClassButNotOnMethod() {
- TargetAnnotation retrievedAnnotation;
-
- retrievedAnnotation = AnnotationProcessingUtils.getAnnotation(
- getTest(ClassWithAnnotation.class, "methodWithoutAnnotation"),
- TargetAnnotation.class);
- assertNotNull(retrievedAnnotation);
- assertEquals(Location.Class, retrievedAnnotation.value());
- }
-
- @Test
- public void testGetTargetAnnotation_OnClassAndMethod() {
- TargetAnnotation retrievedAnnotation;
-
- retrievedAnnotation = AnnotationProcessingUtils.getAnnotation(
- getTest(ClassWithAnnotation.class, "methodWithTargetAnnotation"),
- TargetAnnotation.class);
- assertNotNull(retrievedAnnotation);
- assertEquals(Location.Method, retrievedAnnotation.value());
- }
-
- @Test
- @Ignore("Rules not supported yet.")
- public void testGetTargetAnnotation_OnRuleButNotOnMethod() {
- TargetAnnotation retrievedAnnotation;
-
- retrievedAnnotation = AnnotationProcessingUtils.getAnnotation(
- getTest(ClassWithRule.class, "methodWithoutAnnotation"), TargetAnnotation.class);
- assertNotNull(retrievedAnnotation);
- assertEquals(Location.Rule, retrievedAnnotation.value());
- }
-
- @Test
- @Ignore("Rules not supported yet.")
- public void testGetTargetAnnotation_OnRuleAndMethod() {
- TargetAnnotation retrievedAnnotation;
-
- retrievedAnnotation = AnnotationProcessingUtils.getAnnotation(
- getTest(ClassWithRule.class, "methodWithTargetAnnotation"), TargetAnnotation.class);
- assertNotNull(retrievedAnnotation);
- assertEquals(Location.Method, retrievedAnnotation.value());
- }
-
- @Test
- public void testGetMetaAnnotation_Indirectly() {
- MetaAnnotation retrievedAnnotation;
-
- retrievedAnnotation = AnnotationProcessingUtils.getAnnotation(
- getTest(ClassWithoutTargetAnnotation.class, "methodWithAnnotatedAnnotation"),
- MetaAnnotation.class);
- assertNotNull(retrievedAnnotation);
- }
-
- @Test
- public void testGetAllTargetAnnotations() {
- List<TargetAnnotation> retrievedAnnotations;
-
- retrievedAnnotations = AnnotationProcessingUtils.getAnnotations(
- getTest(ClassWithAnnotation.class, "methodWithTargetAnnotation"),
- TargetAnnotation.class);
- assertEquals(2, retrievedAnnotations.size());
- assertEquals(Location.Class, retrievedAnnotations.get(0).value());
- assertEquals(Location.Method, retrievedAnnotations.get(1).value());
- }
-
- @Test
- public void testGetAllTargetAnnotations_OnParentClass() {
- List<TargetAnnotation> retrievedAnnotations;
-
- retrievedAnnotations = AnnotationProcessingUtils.getAnnotations(
- getTest(DerivedClassWithoutAnnotation.class, "newMethodWithoutAnnotation"),
- TargetAnnotation.class);
- assertEquals(1, retrievedAnnotations.size());
- assertEquals(Location.Class, retrievedAnnotations.get(0).value());
- }
-
- @Test
- public void testGetAllTargetAnnotations_OnDerivedMethodAndParentClass() {
- List<TargetAnnotation> retrievedAnnotations;
-
- retrievedAnnotations = AnnotationProcessingUtils.getAnnotations(
- getTest(DerivedClassWithoutAnnotation.class, "newMethodWithTargetAnnotation"),
- TargetAnnotation.class);
- assertEquals(2, retrievedAnnotations.size());
- assertEquals(Location.Class, retrievedAnnotations.get(0).value());
- assertEquals(Location.DerivedMethod, retrievedAnnotations.get(1).value());
- }
-
- @Test
- public void testGetAllTargetAnnotations_OnDerivedMethodAndParentClassAndMethod() {
- List<TargetAnnotation> retrievedAnnotations;
-
- retrievedAnnotations = AnnotationProcessingUtils.getAnnotations(
- getTest(DerivedClassWithoutAnnotation.class, "methodWithTargetAnnotation"),
- TargetAnnotation.class);
- // We should not look at the base implementation of the method. Mostly it should not happen
- // in the context of tests.
- assertEquals(2, retrievedAnnotations.size());
- assertEquals(Location.Class, retrievedAnnotations.get(0).value());
- assertEquals(Location.DerivedMethod, retrievedAnnotations.get(1).value());
- }
-
- @Test
- public void testGetAllTargetAnnotations_OnDerivedParentAndParentClass() {
- List<TargetAnnotation> retrievedAnnotations;
-
- retrievedAnnotations = AnnotationProcessingUtils.getAnnotations(
- getTest(DerivedClassWithAnnotation.class, "methodWithoutAnnotation"),
- TargetAnnotation.class);
- assertEquals(2, retrievedAnnotations.size());
- assertEquals(Location.Class, retrievedAnnotations.get(0).value());
- assertEquals(Location.DerivedClass, retrievedAnnotations.get(1).value());
- }
-
- @Test
- public void testGetAllAnnotations() {
- List<Annotation> annotations;
-
- AnnotationExtractor annotationExtractor = new AnnotationExtractor(
- TargetAnnotation.class, MetaAnnotation.class, AnnotatedAnnotation.class);
- annotations = annotationExtractor.getMatchingAnnotations(
- getTest(DerivedClassWithAnnotation.class, "methodWithTwoAnnotations"));
- assertEquals(5, annotations.size());
-
- // Retrieved annotation order:
- // On Parent Class
- assertEquals(TargetAnnotation.class, annotations.get(0).annotationType());
- assertEquals(Location.Class, ((TargetAnnotation) annotations.get(0)).value());
-
- // On Class
- assertEquals(TargetAnnotation.class, annotations.get(1).annotationType());
- assertEquals(Location.DerivedClass, ((TargetAnnotation) annotations.get(1)).value());
-
- // Meta-annotations from method
- assertEquals(MetaAnnotation.class, annotations.get(2).annotationType());
-
- // On Method
- assertEquals(AnnotatedAnnotation.class, annotations.get(3).annotationType());
- assertEquals(TargetAnnotation.class, annotations.get(4).annotationType());
- assertEquals(Location.DerivedMethod, ((TargetAnnotation) annotations.get(4)).value());
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testAnnotationExtractorSortOrder_UnknownAnnotations() {
- AnnotationExtractor annotationExtractor = new AnnotationExtractor(Target.class);
- Comparator<Class<? extends Annotation>> comparator =
- annotationExtractor.getTypeComparator();
- List<Class<? extends Annotation>> testList =
- Arrays.asList(Rule.class, Test.class, Override.class, Target.class, Rule.class);
- testList.sort(comparator);
- assertThat("Unknown annotations should not be reordered and come before the known ones.",
- testList,
- contains(Rule.class, Test.class, Override.class, Rule.class, Target.class));
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testAnnotationExtractorSortOrder_KnownAnnotations() {
- AnnotationExtractor annotationExtractor =
- new AnnotationExtractor(Test.class, Target.class, Rule.class);
- Comparator<Class<? extends Annotation>> comparator =
- annotationExtractor.getTypeComparator();
- List<Class<? extends Annotation>> testList =
- Arrays.asList(Rule.class, Test.class, Override.class, Target.class, Rule.class);
- testList.sort(comparator);
- assertThat(
- "Known annotations should be sorted in the same order as provided to the extractor",
- testList,
- contains(Override.class, Test.class, Target.class, Rule.class, Rule.class));
- }
-
- private static Description getTest(Class<?> klass, String testName) {
- Description description = null;
- try {
- description = new DummyTestRunner(klass).describe(testName);
- } catch (InitializationError initializationError) {
- initializationError.printStackTrace();
- fail("DummyTestRunner initialization failed:" + initializationError.getMessage());
- }
- if (description == null) {
- fail("Not test named '" + testName + "' in class" + klass.getSimpleName());
- }
- return description;
- }
-
- // region Test Data: Annotations and dummy test classes
- private enum Location { Unspecified, Class, Method, Rule, DerivedClass, DerivedMethod }
-
- @Retention(RetentionPolicy.RUNTIME)
- @Target({ElementType.TYPE, ElementType.METHOD})
- private @interface TargetAnnotation {
- Location value() default Location.Unspecified;
- }
-
- @Retention(RetentionPolicy.RUNTIME)
- @Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.METHOD})
- private @interface MetaAnnotation {}
-
- @Retention(RetentionPolicy.RUNTIME)
- @Target({ElementType.TYPE, ElementType.METHOD})
- @MetaAnnotation
- private @interface AnnotatedAnnotation {}
-
- private @interface SimpleAnnotation {}
-
- @SimpleAnnotation
- private static class ClassWithoutTargetAnnotation {
- @Test
- public void methodWithoutAnnotation() {}
-
- @Test
- @TargetAnnotation
- public void methodWithTargetAnnotation() {}
-
- @Test
- @AnnotatedAnnotation
- public void methodWithAnnotatedAnnotation() {}
- }
-
- @TargetAnnotation(Location.Class)
- private static class ClassWithAnnotation {
- @Test
- public void methodWithoutAnnotation() {}
-
- @Test
- @TargetAnnotation(Location.Method)
- public void methodWithTargetAnnotation() {}
-
- @Test
- @MetaAnnotation
- public void methodWithMetaAnnotation() {}
-
- @Test
- @AnnotatedAnnotation
- public void methodWithAnnotatedAnnotation() {}
- }
-
- private static class DerivedClassWithoutAnnotation extends ClassWithAnnotation {
- @Test
- public void newMethodWithoutAnnotation() {}
-
- @Test
- @TargetAnnotation(Location.DerivedMethod)
- public void newMethodWithTargetAnnotation() {}
-
- @Test
- @Override
- @TargetAnnotation(Location.DerivedMethod)
- public void methodWithTargetAnnotation() {}
- }
-
- @TargetAnnotation(Location.DerivedClass)
- private static class DerivedClassWithAnnotation extends ClassWithAnnotation {
- @Test
- public void newMethodWithoutAnnotation() {}
-
- @Test
- @AnnotatedAnnotation
- @TargetAnnotation(Location.DerivedMethod)
- public void methodWithTwoAnnotations() {}
- }
-
- private static class ClassWithRule {
- @Rule
- Rule1 mRule = new Rule1();
-
- @Test
- public void methodWithoutAnnotation() {}
-
- @Test
- @TargetAnnotation
- public void methodWithTargetAnnotation() {}
- }
-
- @TargetAnnotation(Location.Rule)
- @MetaAnnotation
- private static class Rule1 implements TestRule {
- @Override
- public Statement apply(Statement statement, Description description) {
- return null;
- }
- }
-
- private static class DummyTestRunner extends BlockJUnit4ClassRunner {
- public DummyTestRunner(Class<?> klass) throws InitializationError {
- super(klass);
- }
-
- @Override
- protected void collectInitializationErrors(List<Throwable> errors) {
- // Do nothing. BlockJUnit4ClassRunner requires the class to be public, but we don't
- // want/need it.
- }
-
- public Description describe(String testName) {
- List<FrameworkMethod> tests = getTestClass().getAnnotatedMethods(Test.class);
- for (FrameworkMethod testMethod : tests) {
- if (testMethod.getName().equals(testName)) return describeChild(testMethod);
- }
- return null;
- }
- }
-
- // endregion
- }
diff --git a/base/test/android/junit/src/org/chromium/base/test/util/DisableIfTest.java b/base/test/android/junit/src/org/chromium/base/test/util/DisableIfTest.java
deleted file mode 100644
index a147435..0000000
--- a/base/test/android/junit/src/org/chromium/base/test/util/DisableIfTest.java
+++ /dev/null
@@ -1,193 +0,0 @@
-// Copyright 2015 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.
-
-package org.chromium.base.test.util;
-
-import android.os.Build;
-
-import junit.framework.TestCase;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.annotation.Config;
-import org.robolectric.util.ReflectionHelpers;
-
-import org.chromium.base.test.BaseRobolectricTestRunner;
-
-/** Unit tests for the DisableIf annotation and its SkipCheck implementation. */
-@RunWith(BaseRobolectricTestRunner.class)
-@Config(manifest = Config.NONE, sdk = 21)
-public class DisableIfTest {
- @Test
- public void testSdkIsLessThanAndIsLessThan() {
- TestCase sdkIsLessThan = new TestCase("sdkIsLessThan") {
- @DisableIf.Build(sdk_is_less_than = 22)
- public void sdkIsLessThan() {}
- };
- Assert.assertTrue(new DisableIfSkipCheck().shouldSkip(sdkIsLessThan));
- }
-
- @Test
- public void testSdkIsLessThanButIsEqual() {
- TestCase sdkIsEqual = new TestCase("sdkIsEqual") {
- @DisableIf.Build(sdk_is_less_than = 21)
- public void sdkIsEqual() {}
- };
- Assert.assertFalse(new DisableIfSkipCheck().shouldSkip(sdkIsEqual));
- }
-
- @Test
- public void testSdkIsLessThanButIsGreaterThan() {
- TestCase sdkIsGreaterThan = new TestCase("sdkIsGreaterThan") {
- @DisableIf.Build(sdk_is_less_than = 20)
- public void sdkIsGreaterThan() {}
- };
- Assert.assertFalse(new DisableIfSkipCheck().shouldSkip(sdkIsGreaterThan));
- }
-
- @Test
- public void testSdkIsGreaterThanButIsLessThan() {
- TestCase sdkIsLessThan = new TestCase("sdkIsLessThan") {
- @DisableIf.Build(sdk_is_greater_than = 22)
- public void sdkIsLessThan() {}
- };
- Assert.assertFalse(new DisableIfSkipCheck().shouldSkip(sdkIsLessThan));
- }
-
- @Test
- public void testSdkIsGreaterThanButIsEqual() {
- TestCase sdkIsEqual = new TestCase("sdkIsEqual") {
- @DisableIf.Build(sdk_is_greater_than = 21)
- public void sdkIsEqual() {}
- };
- Assert.assertFalse(new DisableIfSkipCheck().shouldSkip(sdkIsEqual));
- }
-
- @Test
- public void testSdkIsGreaterThanAndIsGreaterThan() {
- TestCase sdkIsGreaterThan = new TestCase("sdkIsGreaterThan") {
- @DisableIf.Build(sdk_is_greater_than = 20)
- public void sdkIsGreaterThan() {}
- };
- Assert.assertTrue(new DisableIfSkipCheck().shouldSkip(sdkIsGreaterThan));
- }
-
- @Test
- public void testSupportedAbiIncludesAndCpuAbiMatches() {
- TestCase supportedAbisCpuAbiMatch = new TestCase("supportedAbisCpuAbiMatch") {
- @DisableIf.Build(supported_abis_includes = "foo")
- public void supportedAbisCpuAbiMatch() {}
- };
- String[] originalAbis = Build.SUPPORTED_ABIS;
- try {
- ReflectionHelpers.setStaticField(Build.class, "SUPPORTED_ABIS",
- new String[] {"foo", "bar"});
- Assert.assertTrue(new DisableIfSkipCheck().shouldSkip(supportedAbisCpuAbiMatch));
- } finally {
- ReflectionHelpers.setStaticField(Build.class, "SUPPORTED_ABIS", originalAbis);
- }
- }
-
- @Test
- public void testSupportedAbiIncludesAndCpuAbi2Matches() {
- TestCase supportedAbisCpuAbi2Match = new TestCase("supportedAbisCpuAbi2Match") {
- @DisableIf.Build(supported_abis_includes = "bar")
- public void supportedAbisCpuAbi2Match() {}
- };
- String[] originalAbis = Build.SUPPORTED_ABIS;
- try {
- ReflectionHelpers.setStaticField(Build.class, "SUPPORTED_ABIS",
- new String[] {"foo", "bar"});
- Assert.assertTrue(new DisableIfSkipCheck().shouldSkip(supportedAbisCpuAbi2Match));
- } finally {
- ReflectionHelpers.setStaticField(Build.class, "SUPPORTED_ABIS", originalAbis);
- }
- }
-
- @Test
- public void testSupportedAbiIncludesButNoMatch() {
- TestCase supportedAbisNoMatch = new TestCase("supportedAbisNoMatch") {
- @DisableIf.Build(supported_abis_includes = "baz")
- public void supportedAbisNoMatch() {}
- };
- String[] originalAbis = Build.SUPPORTED_ABIS;
- try {
- ReflectionHelpers.setStaticField(Build.class, "SUPPORTED_ABIS",
- new String[] {"foo", "bar"});
- Assert.assertFalse(new DisableIfSkipCheck().shouldSkip(supportedAbisNoMatch));
- } finally {
- ReflectionHelpers.setStaticField(Build.class, "SUPPORTED_ABIS", originalAbis);
- }
- }
-
- @Test
- public void testHardwareIsMatches() {
- TestCase hardwareIsMatches = new TestCase("hardwareIsMatches") {
- @DisableIf.Build(hardware_is = "hammerhead")
- public void hardwareIsMatches() {}
- };
- String originalHardware = Build.HARDWARE;
- try {
- ReflectionHelpers.setStaticField(Build.class, "HARDWARE", "hammerhead");
- Assert.assertTrue(new DisableIfSkipCheck().shouldSkip(hardwareIsMatches));
- } finally {
- ReflectionHelpers.setStaticField(Build.class, "HARDWARE", originalHardware);
- }
- }
-
- @Test
- public void testHardwareIsDoesntMatch() {
- TestCase hardwareIsDoesntMatch = new TestCase("hardwareIsDoesntMatch") {
- @DisableIf.Build(hardware_is = "hammerhead")
- public void hardwareIsDoesntMatch() {}
- };
- String originalHardware = Build.HARDWARE;
- try {
- ReflectionHelpers.setStaticField(Build.class, "HARDWARE", "mako");
- Assert.assertFalse(new DisableIfSkipCheck().shouldSkip(hardwareIsDoesntMatch));
- } finally {
- ReflectionHelpers.setStaticField(Build.class, "HARDWARE", originalHardware);
- }
- }
-
- @DisableIf.Build(supported_abis_includes = "foo")
- private static class DisableIfSuperclassTestCase extends TestCase {
- public DisableIfSuperclassTestCase(String name) {
- super(name);
- }
- }
-
- @DisableIf.Build(hardware_is = "hammerhead")
- private static class DisableIfTestCase extends DisableIfSuperclassTestCase {
- public DisableIfTestCase(String name) {
- super(name);
- }
- public void sampleTestMethod() {}
- }
-
- @Test
- public void testDisableClass() {
- TestCase sampleTestMethod = new DisableIfTestCase("sampleTestMethod");
- String originalHardware = Build.HARDWARE;
- try {
- ReflectionHelpers.setStaticField(Build.class, "HARDWARE", "hammerhead");
- Assert.assertTrue(new DisableIfSkipCheck().shouldSkip(sampleTestMethod));
- } finally {
- ReflectionHelpers.setStaticField(Build.class, "HARDWARE", originalHardware);
- }
- }
-
- @Test
- public void testDisableSuperClass() {
- TestCase sampleTestMethod = new DisableIfTestCase("sampleTestMethod");
- String[] originalAbis = Build.SUPPORTED_ABIS;
- try {
- ReflectionHelpers.setStaticField(Build.class, "SUPPORTED_ABIS", new String[] {"foo"});
- Assert.assertTrue(new DisableIfSkipCheck().shouldSkip(sampleTestMethod));
- } finally {
- ReflectionHelpers.setStaticField(Build.class, "SUPPORTED_ABIS", originalAbis);
- }
- }
-}
diff --git a/base/test/android/junit/src/org/chromium/base/test/util/ManualSkipCheckTest.java b/base/test/android/junit/src/org/chromium/base/test/util/ManualSkipCheckTest.java
deleted file mode 100644
index 0c3e955..0000000
--- a/base/test/android/junit/src/org/chromium/base/test/util/ManualSkipCheckTest.java
+++ /dev/null
@@ -1,145 +0,0 @@
-// 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.
-
-package org.chromium.base.test.util;
-
-import static org.hamcrest.Matchers.contains;
-import static org.hamcrest.Matchers.isIn;
-
-import android.app.Instrumentation;
-import android.content.Context;
-import android.os.Bundle;
-import android.support.test.InstrumentationRegistry;
-
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ErrorCollector;
-import org.junit.rules.ExternalResource;
-import org.junit.rules.TestRule;
-import org.junit.runner.Description;
-import org.junit.runner.RunWith;
-import org.junit.runner.notification.Failure;
-import org.junit.runner.notification.RunListener;
-import org.junit.runner.notification.RunNotifier;
-import org.junit.runners.model.FrameworkMethod;
-import org.robolectric.RuntimeEnvironment;
-import org.robolectric.annotation.Config;
-
-import org.chromium.base.test.BaseJUnit4ClassRunner;
-import org.chromium.base.test.BaseRobolectricTestRunner;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Unit tests for skipping tests annotated with {@code @}{@link Manual}.
- */
-@RunWith(BaseRobolectricTestRunner.class)
-@Config(manifest = Config.NONE)
-public class ManualSkipCheckTest {
- /**
- * Example test class.
- */
- public static class ManualTest {
- @Test
- @Manual
- public void manualTest() {}
-
- @Test
- public void nonManualTest() {}
- }
-
- @Test
- public void testManual() throws NoSuchMethodException {
- FrameworkMethod method = new FrameworkMethod(ManualTest.class.getMethod("manualTest"));
- Assert.assertTrue(new ManualSkipCheck().shouldSkip(method));
- }
-
- @Test
- public void testNonManual() throws NoSuchMethodException {
- FrameworkMethod method = new FrameworkMethod(ManualTest.class.getMethod("nonManualTest"));
- Assert.assertFalse(new ManualSkipCheck().shouldSkip(method));
- }
-
- private static class MockRunListener extends RunListener {
- private List<Description> mRunTests = new ArrayList<>();
- private List<Description> mSkippedTests = new ArrayList<>();
-
- public List<Description> getRunTests() {
- return mRunTests;
- }
-
- public List<Description> getSkippedTests() {
- return mSkippedTests;
- }
-
- @Override
- public void testStarted(Description description) throws Exception {
- mRunTests.add(description);
- }
-
- @Override
- public void testFinished(Description description) throws Exception {
- Assert.assertThat(description, isIn(mRunTests));
- }
-
- @Override
- public void testFailure(Failure failure) throws Exception {
- Assert.fail(failure.toString());
- }
-
- @Override
- public void testAssumptionFailure(Failure failure) {
- Assert.fail(failure.toString());
- }
-
- @Override
- public void testIgnored(Description description) throws Exception {
- mSkippedTests.add(description);
- }
- }
-
- /**
- * Registers a fake {@link Instrumentation} so that class runners for instrumentation tests can
- * be run even in Robolectric tests.
- */
- private static class MockInstrumentationRule extends ExternalResource {
- @Override
- protected void before() throws Throwable {
- Instrumentation instrumentation = new Instrumentation() {
- @Override
- public Context getTargetContext() {
- return RuntimeEnvironment.application;
- }
- };
- InstrumentationRegistry.registerInstance(instrumentation, new Bundle());
- }
-
- @Override
- protected void after() {
- InstrumentationRegistry.registerInstance(null, new Bundle());
- }
- }
-
- @Rule
- public TestRule mMockInstrumentationRule = new MockInstrumentationRule();
-
- @Rule
- public ErrorCollector mErrorCollector = new ErrorCollector();
-
- @Test
- public void testWithTestRunner() throws Exception {
- // TODO(bauerb): Using Mockito mock() or spy() throws a ClassCastException.
- MockRunListener runListener = new MockRunListener();
- RunNotifier runNotifier = new RunNotifier();
- runNotifier.addListener(runListener);
- new BaseJUnit4ClassRunner(ManualTest.class).run(runNotifier);
-
- mErrorCollector.checkThat(runListener.getRunTests(),
- contains(Description.createTestDescription(ManualTest.class, "nonManualTest")));
- mErrorCollector.checkThat(runListener.getSkippedTests(),
- contains(Description.createTestDescription(ManualTest.class, "manualTest")));
- }
-}
diff --git a/base/test/android/junit/src/org/chromium/base/test/util/MinAndroidSdkLevelSkipCheckTest.java b/base/test/android/junit/src/org/chromium/base/test/util/MinAndroidSdkLevelSkipCheckTest.java
deleted file mode 100644
index 050cb10..0000000
--- a/base/test/android/junit/src/org/chromium/base/test/util/MinAndroidSdkLevelSkipCheckTest.java
+++ /dev/null
@@ -1,95 +0,0 @@
-// Copyright 2016 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.
-
-package org.chromium.base.test.util;
-
-import junit.framework.TestCase;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.annotation.Config;
-
-import org.chromium.base.test.BaseRobolectricTestRunner;
-
-/** Unit tests for MinAndroidSdkLevelSkipCheck. */
-@RunWith(BaseRobolectricTestRunner.class)
-@Config(manifest = Config.NONE, sdk = 18)
-public class MinAndroidSdkLevelSkipCheckTest {
- private static class UnannotatedBaseClass extends TestCase {
- public UnannotatedBaseClass(String name) {
- super(name);
- }
- @MinAndroidSdkLevel(17) public void min17Method() {}
- @MinAndroidSdkLevel(20) public void min20Method() {}
- }
-
- @MinAndroidSdkLevel(17)
- private static class Min17Class extends UnannotatedBaseClass {
- public Min17Class(String name) {
- super(name);
- }
- public void unannotatedMethod() {}
- }
-
- @MinAndroidSdkLevel(20)
- private static class Min20Class extends UnannotatedBaseClass {
- public Min20Class(String name) {
- super(name);
- }
- public void unannotatedMethod() {}
- }
-
- private static class ExtendsMin17Class extends Min17Class {
- public ExtendsMin17Class(String name) {
- super(name);
- }
- @Override
- public void unannotatedMethod() {}
- }
-
- private static class ExtendsMin20Class extends Min20Class {
- public ExtendsMin20Class(String name) {
- super(name);
- }
- @Override
- public void unannotatedMethod() {}
- }
-
- @Test
- public void testAnnotatedMethodAboveMin() {
- Assert.assertFalse(new MinAndroidSdkLevelSkipCheck().shouldSkip(
- new UnannotatedBaseClass("min17Method")));
- }
-
- @Test
- public void testAnnotatedMethodBelowMin() {
- Assert.assertTrue(new MinAndroidSdkLevelSkipCheck().shouldSkip(
- new UnannotatedBaseClass("min20Method")));
- }
-
- @Test
- public void testAnnotatedClassAboveMin() {
- Assert.assertFalse(new MinAndroidSdkLevelSkipCheck().shouldSkip(
- new Min17Class("unannotatedMethod")));
- }
-
- @Test
- public void testAnnotatedClassBelowMin() {
- Assert.assertTrue(new MinAndroidSdkLevelSkipCheck().shouldSkip(
- new Min20Class("unannotatedMethod")));
- }
-
- @Test
- public void testAnnotatedSuperclassAboveMin() {
- Assert.assertFalse(new MinAndroidSdkLevelSkipCheck().shouldSkip(
- new ExtendsMin17Class("unannotatedMethod")));
- }
-
- @Test
- public void testAnnotatedSuperclassBelowMin() {
- Assert.assertTrue(new MinAndroidSdkLevelSkipCheck().shouldSkip(
- new ExtendsMin20Class("unannotatedMethod")));
- }
-}
diff --git a/base/test/android/junit/src/org/chromium/base/test/util/RestrictionSkipCheckTest.java b/base/test/android/junit/src/org/chromium/base/test/util/RestrictionSkipCheckTest.java
deleted file mode 100644
index 86285de..0000000
--- a/base/test/android/junit/src/org/chromium/base/test/util/RestrictionSkipCheckTest.java
+++ /dev/null
@@ -1,129 +0,0 @@
-// Copyright 2016 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.
-
-package org.chromium.base.test.util;
-
-import android.text.TextUtils;
-
-import junit.framework.TestCase;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.annotation.Config;
-
-import org.chromium.base.test.BaseRobolectricTestRunner;
-
-/** Unit tests for RestrictionSkipCheck. */
-@RunWith(BaseRobolectricTestRunner.class)
-@Config(manifest = Config.NONE)
-public class RestrictionSkipCheckTest {
- private static final String TEST_RESTRICTION_APPLIES =
- "org.chromium.base.test.util.RestrictionSkipCheckTest.TEST_RESTRICTION_APPLIES";
- private static final String TEST_RESTRICTION_DOES_NOT_APPLY =
- "org.chromium.base.test.util.RestrictionSkipCheckTest.TEST_RESTRICTION_DOES_NOT_APPLY";
-
- private static class TestRestrictionSkipCheck extends RestrictionSkipCheck {
- public TestRestrictionSkipCheck() {
- super(null);
- }
- @Override
- protected boolean restrictionApplies(String restriction) {
- return TextUtils.equals(restriction, TEST_RESTRICTION_APPLIES);
- }
- }
-
- private static class UnannotatedBaseClass extends TestCase {
- public UnannotatedBaseClass(String name) {
- super(name);
- }
- @Restriction({TEST_RESTRICTION_APPLIES}) public void restrictedMethod() {}
- @Restriction({TEST_RESTRICTION_DOES_NOT_APPLY}) public void unrestrictedMethod() {}
- }
-
- @Restriction({TEST_RESTRICTION_APPLIES})
- private static class RestrictedClass extends UnannotatedBaseClass {
- public RestrictedClass(String name) {
- super(name);
- }
- public void unannotatedMethod() {}
- }
-
- @Restriction({TEST_RESTRICTION_DOES_NOT_APPLY})
- private static class UnrestrictedClass extends UnannotatedBaseClass {
- public UnrestrictedClass(String name) {
- super(name);
- }
- public void unannotatedMethod() {}
- }
-
- @Restriction({
- TEST_RESTRICTION_APPLIES,
- TEST_RESTRICTION_DOES_NOT_APPLY})
- private static class MultipleRestrictionsRestrictedClass extends UnannotatedBaseClass {
- public MultipleRestrictionsRestrictedClass(String name) {
- super(name);
- }
- public void unannotatedMethod() {}
- }
-
- private static class ExtendsRestrictedClass extends RestrictedClass {
- public ExtendsRestrictedClass(String name) {
- super(name);
- }
- @Override
- public void unannotatedMethod() {}
- }
-
- private static class ExtendsUnrestrictedClass extends UnrestrictedClass {
- public ExtendsUnrestrictedClass(String name) {
- super(name);
- }
- @Override
- public void unannotatedMethod() {}
- }
-
- @Test
- public void testMethodRestricted() {
- Assert.assertTrue(new TestRestrictionSkipCheck().shouldSkip(
- new UnannotatedBaseClass("restrictedMethod")));
- }
-
- @Test
- public void testMethodUnrestricted() {
- Assert.assertFalse(new TestRestrictionSkipCheck().shouldSkip(
- new UnannotatedBaseClass("unrestrictedMethod")));
- }
-
- @Test
- public void testClassRestricted() {
- Assert.assertTrue(new TestRestrictionSkipCheck().shouldSkip(
- new RestrictedClass("unannotatedMethod")));
- }
-
- @Test
- public void testClassUnrestricted() {
- Assert.assertFalse(new TestRestrictionSkipCheck().shouldSkip(
- new UnrestrictedClass("unannotatedMethod")));
- }
-
- @Test
- public void testMultipleRestrictionsClassRestricted() {
- Assert.assertTrue(new TestRestrictionSkipCheck().shouldSkip(
- new MultipleRestrictionsRestrictedClass("unannotatedMethod")));
- }
-
- @Test
- public void testSuperclassRestricted() {
- Assert.assertTrue(new TestRestrictionSkipCheck().shouldSkip(
- new ExtendsRestrictedClass("unannotatedMethod")));
- }
-
- @Test
- public void testSuperclassUnrestricted() {
- Assert.assertFalse(new TestRestrictionSkipCheck().shouldSkip(
- new ExtendsUnrestrictedClass("unannotatedMethod")));
- }
-}
-
diff --git a/base/test/android/junit/src/org/chromium/base/test/util/SkipCheckTest.java b/base/test/android/junit/src/org/chromium/base/test/util/SkipCheckTest.java
deleted file mode 100644
index 51c7516..0000000
--- a/base/test/android/junit/src/org/chromium/base/test/util/SkipCheckTest.java
+++ /dev/null
@@ -1,130 +0,0 @@
-// Copyright 2016 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.
-
-package org.chromium.base.test.util;
-
-import junit.framework.TestCase;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.model.FrameworkMethod;
-import org.robolectric.annotation.Config;
-
-import org.chromium.base.test.BaseRobolectricTestRunner;
-
-import java.lang.annotation.Annotation;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.Method;
-import java.util.List;
-
-/** Unit tests for SkipCheck. */
-@RunWith(BaseRobolectricTestRunner.class)
-@Config(manifest = Config.NONE)
-public class SkipCheckTest {
- private static class TestableSkipCheck extends SkipCheck {
- public static <T extends Annotation> List<T> getAnnotationsForTesting(
- AnnotatedElement element, Class<T> annotationClass) {
- return AnnotationProcessingUtils.getAnnotations(element, annotationClass);
- }
-
- @Override
- public boolean shouldSkip(FrameworkMethod m) {
- return false;
- }
- }
-
- @Retention(RetentionPolicy.RUNTIME)
- private @interface TestAnnotation {}
-
- @TestAnnotation
- private class AnnotatedBaseClass {
- public void unannotatedMethod() {}
- @TestAnnotation public void annotatedMethod() {}
- }
-
- private class ExtendsAnnotatedBaseClass extends AnnotatedBaseClass {
- public void anotherUnannotatedMethod() {}
- }
-
- private class ExtendsTestCaseClass extends TestCase {
- public ExtendsTestCaseClass(String name) {
- super(name);
- }
- public void testMethodA() {}
- }
-
- private class UnannotatedBaseClass {
- public void unannotatedMethod() {}
- @TestAnnotation public void annotatedMethod() {}
- }
-
- @Test
- public void getAnnotationsForClassNone() {
- List<TestAnnotation> annotations = TestableSkipCheck.getAnnotationsForTesting(
- UnannotatedBaseClass.class, TestAnnotation.class);
- Assert.assertEquals(0, annotations.size());
- }
-
- @Test
- public void getAnnotationsForClassOnClass() {
- List<TestAnnotation> annotations = TestableSkipCheck.getAnnotationsForTesting(
- AnnotatedBaseClass.class, TestAnnotation.class);
- Assert.assertEquals(1, annotations.size());
- }
-
- @Test
- public void getAnnotationsForClassOnSuperclass() {
- List<TestAnnotation> annotations = TestableSkipCheck.getAnnotationsForTesting(
- ExtendsAnnotatedBaseClass.class, TestAnnotation.class);
- Assert.assertEquals(1, annotations.size());
- }
-
- @Test
- public void getAnnotationsForMethodNone() throws NoSuchMethodException {
- Method testMethod = UnannotatedBaseClass.class.getMethod("unannotatedMethod",
- (Class[]) null);
- List<TestAnnotation> annotations = TestableSkipCheck.getAnnotationsForTesting(
- testMethod, TestAnnotation.class);
- Assert.assertEquals(0, annotations.size());
- }
-
- @Test
- public void getAnnotationsForMethodOnMethod() throws NoSuchMethodException {
- Method testMethod = UnannotatedBaseClass.class.getMethod("annotatedMethod",
- (Class[]) null);
- List<TestAnnotation> annotations = TestableSkipCheck.getAnnotationsForTesting(
- testMethod, TestAnnotation.class);
- Assert.assertEquals(1, annotations.size());
- }
-
- @Test
- public void getAnnotationsForMethodOnClass() throws NoSuchMethodException {
- Method testMethod = AnnotatedBaseClass.class.getMethod("unannotatedMethod",
- (Class[]) null);
- List<TestAnnotation> annotations = TestableSkipCheck.getAnnotationsForTesting(
- testMethod, TestAnnotation.class);
- Assert.assertEquals(1, annotations.size());
- }
-
- @Test
- public void getAnnotationsForMethodOnSuperclass() throws NoSuchMethodException {
- Method testMethod = ExtendsAnnotatedBaseClass.class.getMethod("unannotatedMethod",
- (Class[]) null);
- List<TestAnnotation> annotations = TestableSkipCheck.getAnnotationsForTesting(
- testMethod, TestAnnotation.class);
- Assert.assertEquals(1, annotations.size());
- }
-
- @Test
- public void getAnnotationsOverlapping() throws NoSuchMethodException {
- Method testMethod = AnnotatedBaseClass.class.getMethod("annotatedMethod",
- (Class[]) null);
- List<TestAnnotation> annotations = TestableSkipCheck.getAnnotationsForTesting(
- testMethod, TestAnnotation.class);
- Assert.assertEquals(2, annotations.size());
- }
-}
diff --git a/base/test/android/url_utils.cc b/base/test/android/url_utils.cc
deleted file mode 100644
index 7d2a8ed..0000000
--- a/base/test/android/url_utils.cc
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2017 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.
-
-#include "base/test/android/url_utils.h"
-
-#include "base/android/jni_string.h"
-#include "base/android/scoped_java_ref.h"
-#include "jni/UrlUtils_jni.h"
-
-namespace base {
-namespace android {
-
-FilePath GetIsolatedTestRoot() {
- JNIEnv* env = base::android::AttachCurrentThread();
- ScopedJavaLocalRef<jstring> jtest_data_dir =
- Java_UrlUtils_getIsolatedTestRoot(env);
- base::FilePath test_data_dir(
- base::android::ConvertJavaStringToUTF8(env, jtest_data_dir));
- return test_data_dir;
-}
-
-} // namespace android
-} // namespace base
diff --git a/base/test/android/url_utils.h b/base/test/android/url_utils.h
deleted file mode 100644
index 3769bd2..0000000
--- a/base/test/android/url_utils.h
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2017 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 BASE_TEST_ANDROID_URL_UTILS_H_
-#define BASE_TEST_ANDROID_URL_UTILS_H_
-
-#include <jni.h>
-
-#include "base/base_export.h"
-#include "base/files/file_path.h"
-
-namespace base {
-namespace android {
-
-// Returns the root of the test data directory. This function will call into
-// Java class UrlUtils through JNI bridge.
-BASE_EXPORT FilePath GetIsolatedTestRoot();
-
-} // namespace android
-} // namespace base
-
-#endif // BASE_TEST_ANDROID_URL_UTILS_H_
diff --git a/base/test/multiprocess_test_android.cc b/base/test/multiprocess_test_android.cc
deleted file mode 100644
index 4108593..0000000
--- a/base/test/multiprocess_test_android.cc
+++ /dev/null
@@ -1,86 +0,0 @@
-// Copyright (c) 2012 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.
-
-#include "base/test/multiprocess_test.h"
-
-#include <string.h>
-#include <vector>
-
-#include "base/android/jni_android.h"
-#include "base/android/jni_array.h"
-#include "base/android/scoped_java_ref.h"
-#include "base/base_switches.h"
-#include "base/command_line.h"
-#include "base/logging.h"
-#include "jni/MainReturnCodeResult_jni.h"
-#include "jni/MultiprocessTestClientLauncher_jni.h"
-
-namespace base {
-
-// A very basic implementation for Android. On Android tests can run in an APK
-// and we don't have an executable to exec*. This implementation does the bare
-// minimum to execute the method specified by procname (in the child process).
-// - All options except |fds_to_remap| are ignored.
-//
-// NOTE: This MUST NOT run on the main thread of the NativeTest application.
-Process SpawnMultiProcessTestChild(const std::string& procname,
- const CommandLine& base_command_line,
- const LaunchOptions& options) {
- JNIEnv* env = android::AttachCurrentThread();
- DCHECK(env);
-
- std::vector<int> fd_keys;
- std::vector<int> fd_fds;
- for (auto& iter : options.fds_to_remap) {
- fd_keys.push_back(iter.second);
- fd_fds.push_back(iter.first);
- }
-
- android::ScopedJavaLocalRef<jobjectArray> fds =
- android::Java_MultiprocessTestClientLauncher_makeFdInfoArray(
- env, base::android::ToJavaIntArray(env, fd_keys),
- base::android::ToJavaIntArray(env, fd_fds));
-
- CommandLine command_line(base_command_line);
- if (!command_line.HasSwitch(switches::kTestChildProcess)) {
- command_line.AppendSwitchASCII(switches::kTestChildProcess, procname);
- }
-
- android::ScopedJavaLocalRef<jobjectArray> j_argv =
- android::ToJavaArrayOfStrings(env, command_line.argv());
- jint pid = android::Java_MultiprocessTestClientLauncher_launchClient(
- env, j_argv, fds);
- return Process(pid);
-}
-
-bool WaitForMultiprocessTestChildExit(const Process& process,
- TimeDelta timeout,
- int* exit_code) {
- JNIEnv* env = android::AttachCurrentThread();
- DCHECK(env);
-
- base::android::ScopedJavaLocalRef<jobject> result_code =
- android::Java_MultiprocessTestClientLauncher_waitForMainToReturn(
- env, process.Pid(), static_cast<int32_t>(timeout.InMilliseconds()));
- if (result_code.is_null() ||
- Java_MainReturnCodeResult_hasTimedOut(env, result_code)) {
- return false;
- }
- if (exit_code) {
- *exit_code = Java_MainReturnCodeResult_getReturnCode(env, result_code);
- }
- return true;
-}
-
-bool TerminateMultiProcessTestChild(const Process& process,
- int exit_code,
- bool wait) {
- JNIEnv* env = android::AttachCurrentThread();
- DCHECK(env);
-
- return android::Java_MultiprocessTestClientLauncher_terminate(
- env, process.Pid(), exit_code, wait);
-}
-
-} // namespace base
diff --git a/base/test/test_file_util_android.cc b/base/test/test_file_util_android.cc
deleted file mode 100644
index 6e93e24..0000000
--- a/base/test/test_file_util_android.cc
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2013 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.
-
-#include "base/test/test_file_util.h"
-
-#include "base/android/jni_android.h"
-#include "base/android/jni_string.h"
-#include "base/files/file_path.h"
-#include "jni/ContentUriTestUtils_jni.h"
-
-using base::android::ScopedJavaLocalRef;
-
-namespace base {
-
-FilePath InsertImageIntoMediaStore(const FilePath& path) {
- JNIEnv* env = base::android::AttachCurrentThread();
- ScopedJavaLocalRef<jstring> j_path =
- base::android::ConvertUTF8ToJavaString(env, path.value());
- ScopedJavaLocalRef<jstring> j_uri =
- Java_ContentUriTestUtils_insertImageIntoMediaStore(env, j_path);
- std::string uri = base::android::ConvertJavaStringToUTF8(j_uri);
- return FilePath(uri);
-}
-
-} // namespace base
diff --git a/base/test/test_support_android.cc b/base/test/test_support_android.cc
deleted file mode 100644
index 33a6628..0000000
--- a/base/test/test_support_android.cc
+++ /dev/null
@@ -1,194 +0,0 @@
-// Copyright (c) 2012 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.
-
-#include <stdarg.h>
-#include <string.h>
-
-#include "base/android/path_utils.h"
-#include "base/files/file_path.h"
-#include "base/logging.h"
-#include "base/macros.h"
-#include "base/memory/singleton.h"
-#include "base/message_loop/message_loop.h"
-#include "base/message_loop/message_pump_android.h"
-#include "base/path_service.h"
-#include "base/synchronization/waitable_event.h"
-#include "base/test/multiprocess_test.h"
-
-namespace {
-
-base::FilePath* g_test_data_dir = nullptr;
-
-struct RunState {
- RunState(base::MessagePump::Delegate* delegate, int run_depth)
- : delegate(delegate),
- run_depth(run_depth),
- should_quit(false) {
- }
-
- base::MessagePump::Delegate* delegate;
-
- // Used to count how many Run() invocations are on the stack.
- int run_depth;
-
- // Used to flag that the current Run() invocation should return ASAP.
- bool should_quit;
-};
-
-RunState* g_state = NULL;
-
-// A singleton WaitableEvent wrapper so we avoid a busy loop in
-// MessagePumpForUIStub. Other platforms use the native event loop which blocks
-// when there are no pending messages.
-class Waitable {
- public:
- static Waitable* GetInstance() {
- return base::Singleton<Waitable,
- base::LeakySingletonTraits<Waitable>>::get();
- }
-
- // Signals that there are more work to do.
- void Signal() { waitable_event_.Signal(); }
-
- // Blocks until more work is scheduled.
- void Block() { waitable_event_.Wait(); }
-
- void Quit() {
- g_state->should_quit = true;
- Signal();
- }
-
- private:
- friend struct base::DefaultSingletonTraits<Waitable>;
-
- Waitable()
- : waitable_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
- base::WaitableEvent::InitialState::NOT_SIGNALED) {}
-
- base::WaitableEvent waitable_event_;
-
- DISALLOW_COPY_AND_ASSIGN(Waitable);
-};
-
-// The MessagePumpForUI implementation for test purpose.
-class MessagePumpForUIStub : public base::MessagePumpForUI {
- ~MessagePumpForUIStub() override {}
-
- void Start(base::MessagePump::Delegate* delegate) override {
- NOTREACHED() << "The Start() method shouldn't be called in test, using"
- " Run() method should be used.";
- }
-
- void Run(base::MessagePump::Delegate* delegate) override {
- // The following was based on message_pump_glib.cc, except we're using a
- // WaitableEvent since there are no native message loop to use.
- RunState state(delegate, g_state ? g_state->run_depth + 1 : 1);
-
- RunState* previous_state = g_state;
- g_state = &state;
-
- bool more_work_is_plausible = true;
-
- for (;;) {
- if (!more_work_is_plausible) {
- Waitable::GetInstance()->Block();
- if (g_state->should_quit)
- break;
- }
-
- more_work_is_plausible = g_state->delegate->DoWork();
- if (g_state->should_quit)
- break;
-
- base::TimeTicks delayed_work_time;
- more_work_is_plausible |=
- g_state->delegate->DoDelayedWork(&delayed_work_time);
- if (g_state->should_quit)
- break;
-
- if (more_work_is_plausible)
- continue;
-
- more_work_is_plausible = g_state->delegate->DoIdleWork();
- if (g_state->should_quit)
- break;
-
- more_work_is_plausible |= !delayed_work_time.is_null();
- }
-
- g_state = previous_state;
- }
-
- void Quit() override { Waitable::GetInstance()->Quit(); }
-
- void ScheduleWork() override { Waitable::GetInstance()->Signal(); }
-
- void ScheduleDelayedWork(const base::TimeTicks& delayed_work_time) override {
- Waitable::GetInstance()->Signal();
- }
-};
-
-std::unique_ptr<base::MessagePump> CreateMessagePumpForUIStub() {
- return std::unique_ptr<base::MessagePump>(new MessagePumpForUIStub());
-};
-
-// Provides the test path for DIR_SOURCE_ROOT and DIR_ANDROID_APP_DATA.
-bool GetTestProviderPath(int key, base::FilePath* result) {
- switch (key) {
- // TODO(agrieve): Stop overriding DIR_ANDROID_APP_DATA.
- // https://crbug.com/617734
- // Instead DIR_ASSETS should be used to discover assets file location in
- // tests.
- case base::DIR_ANDROID_APP_DATA:
- case base::DIR_ASSETS:
- case base::DIR_SOURCE_ROOT:
- CHECK(g_test_data_dir != nullptr);
- *result = *g_test_data_dir;
- return true;
- default:
- return false;
- }
-}
-
-void InitPathProvider(int key) {
- base::FilePath path;
- // If failed to override the key, that means the way has not been registered.
- if (GetTestProviderPath(key, &path) &&
- !base::PathService::Override(key, path)) {
- base::PathService::RegisterProvider(&GetTestProviderPath, key, key + 1);
- }
-}
-
-} // namespace
-
-namespace base {
-
-void InitAndroidTestLogging() {
- logging::LoggingSettings settings;
- settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
- logging::InitLogging(settings);
- // To view log output with IDs and timestamps use "adb logcat -v threadtime".
- logging::SetLogItems(false, // Process ID
- false, // Thread ID
- false, // Timestamp
- false); // Tick count
-}
-
-void InitAndroidTestPaths(const FilePath& test_data_dir) {
- if (g_test_data_dir) {
- CHECK(test_data_dir == *g_test_data_dir);
- return;
- }
- g_test_data_dir = new FilePath(test_data_dir);
- InitPathProvider(DIR_SOURCE_ROOT);
- InitPathProvider(DIR_ANDROID_APP_DATA);
- InitPathProvider(DIR_ASSETS);
-}
-
-void InitAndroidTestMessageLoop() {
- if (!MessageLoop::InitMessagePumpForUIFactory(&CreateMessagePumpForUIStub))
- LOG(INFO) << "MessagePumpForUIFactory already set, unable to override.";
-}
-
-} // namespace base
diff --git a/base/test/test_support_android.h b/base/test/test_support_android.h
deleted file mode 100644
index 4942e54..0000000
--- a/base/test/test_support_android.h
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright (c) 2012 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 BASE_TEST_TEST_SUPPORT_ANDROID_H_
-#define BASE_TEST_TEST_SUPPORT_ANDROID_H_
-
-#include "base/base_export.h"
-
-namespace base {
-
-class FilePath;
-
-// Init logging for tests on Android. Logs will be output into Android's logcat.
-BASE_EXPORT void InitAndroidTestLogging();
-
-// Init path providers for tests on Android.
-BASE_EXPORT void InitAndroidTestPaths(const FilePath& test_data_dir);
-
-// Init the message loop for tests on Android.
-BASE_EXPORT void InitAndroidTestMessageLoop();
-
-} // namespace base
-
-#endif // BASE_TEST_TEST_SUPPORT_ANDROID_H_
diff --git a/base/test/test_ui_thread_android.cc b/base/test/test_ui_thread_android.cc
deleted file mode 100644
index d19fefa..0000000
--- a/base/test/test_ui_thread_android.cc
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2015 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.
-#include "base/test/test_ui_thread_android.h"
-
-#include "jni/TestUiThread_jni.h"
-
-namespace base {
-
-void StartTestUiThreadLooper() {
- Java_TestUiThread_loop(base::android::AttachCurrentThread());
-}
-
-} // namespace base
diff --git a/base/test/test_ui_thread_android.h b/base/test/test_ui_thread_android.h
deleted file mode 100644
index 233911a..0000000
--- a/base/test/test_ui_thread_android.h
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2015 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 BASE_TEST_TEST_UI_THREAD_ANDROID_
-#define BASE_TEST_TEST_UI_THREAD_ANDROID_
-
-#include <jni.h>
-
-namespace base {
-
-// Set up a thread as the Chromium UI Thread, and run its looper. This is is
-// intended for C++ unit tests (e.g. the net unit tests) that don't run with the
-// UI thread as their main looper, but test code that, on Android, uses UI
-// thread events, so need a running UI thread.
-void StartTestUiThreadLooper();
-
-} // namespace base
-
-#endif // BASE_TEST_TEST_UI_THREAD_ANDROID_
diff --git a/base/third_party/libevent/android/config.h b/base/third_party/libevent/android/config.h
deleted file mode 100644
index 91f4dda..0000000
--- a/base/third_party/libevent/android/config.h
+++ /dev/null
@@ -1,266 +0,0 @@
-/* Copied from Linux version and changed the features according Android, which
- * is close to Linux */
-
-/* Define if clock_gettime is available in libc */
-#define DNS_USE_CPU_CLOCK_FOR_ID 1
-
-/* Define is no secure id variant is available */
-/* #undef DNS_USE_GETTIMEOFDAY_FOR_ID */
-
-/* Define to 1 if you have the `clock_gettime' function. */
-#define HAVE_CLOCK_GETTIME 1
-
-/* Define if /dev/poll is available */
-/* #undef HAVE_DEVPOLL */
-
-/* Define to 1 if you have the <dlfcn.h> header file. */
-#define HAVE_DLFCN_H 1
-
-/* Define if your system supports the epoll system calls */
-#define HAVE_EPOLL 1
-
-/* Define to 1 if you have the `epoll_ctl' function. */
-#define HAVE_EPOLL_CTL 1
-
-/* Define if your system supports event ports */
-/* #undef HAVE_EVENT_PORTS */
-
-/* Define to 1 if you have the `fcntl' function. */
-#define HAVE_FCNTL 1
-
-/* Define to 1 if you have the <fcntl.h> header file. */
-#define HAVE_FCNTL_H 1
-
-/* Define to 1 if the system has the type `fd_mask'. */
-/* #undef HAVE_FD_MASK */
-
-/* Define to 1 if you have the `getaddrinfo' function. */
-#define HAVE_GETADDRINFO 1
-
-/* Define to 1 if you have the `getegid' function. */
-#define HAVE_GETEGID 1
-
-/* Define to 1 if you have the `geteuid' function. */
-#define HAVE_GETEUID 1
-
-/* Define to 1 if you have the `getnameinfo' function. */
-#define HAVE_GETNAMEINFO 1
-
-/* Define to 1 if you have the `gettimeofday' function. */
-#define HAVE_GETTIMEOFDAY 1
-
-/* Define to 1 if you have the `inet_ntop' function. */
-#define HAVE_INET_NTOP 1
-
-/* Define to 1 if you have the <inttypes.h> header file. */
-#define HAVE_INTTYPES_H 1
-
-/* Define to 1 if you have the `issetugid' function. */
-/* #undef HAVE_ISSETUGID */
-
-/* Define to 1 if you have the `kqueue' function. */
-/* #undef HAVE_KQUEUE */
-
-/* Define to 1 if you have the `nsl' library (-lnsl). */
-#define HAVE_LIBNSL 1
-
-/* Define to 1 if you have the `resolv' library (-lresolv). */
-#define HAVE_LIBRESOLV 1
-
-/* Define to 1 if you have the `rt' library (-lrt). */
-#define HAVE_LIBRT 1
-
-/* Define to 1 if you have the `socket' library (-lsocket). */
-/* #undef HAVE_LIBSOCKET */
-
-/* Define to 1 if you have the <memory.h> header file. */
-#define HAVE_MEMORY_H 1
-
-/* Define to 1 if you have the <netinet/in6.h> header file. */
-/* #undef HAVE_NETINET_IN6_H */
-
-/* Define to 1 if you have the `poll' function. */
-#define HAVE_POLL 1
-
-/* Define to 1 if you have the <poll.h> header file. */
-#define HAVE_POLL_H 1
-
-/* Define to 1 if you have the `port_create' function. */
-/* #undef HAVE_PORT_CREATE */
-
-/* Define to 1 if you have the <port.h> header file. */
-/* #undef HAVE_PORT_H */
-
-/* Define to 1 if you have the `select' function. */
-#define HAVE_SELECT 1
-
-/* Define if F_SETFD is defined in <fcntl.h> */
-#define HAVE_SETFD 1
-
-/* Define to 1 if you have the `sigaction' function. */
-#define HAVE_SIGACTION 1
-
-/* Define to 1 if you have the `signal' function. */
-#define HAVE_SIGNAL 1
-
-/* Define to 1 if you have the <signal.h> header file. */
-#define HAVE_SIGNAL_H 1
-
-/* Define to 1 if you have the <stdarg.h> header file. */
-#define HAVE_STDARG_H 1
-
-/* Define to 1 if you have the <stdint.h> header file. */
-#define HAVE_STDINT_H 1
-
-/* Define to 1 if you have the <stdlib.h> header file. */
-#define HAVE_STDLIB_H 1
-
-/* Define to 1 if you have the <strings.h> header file. */
-#define HAVE_STRINGS_H 1
-
-/* Define to 1 if you have the <string.h> header file. */
-#define HAVE_STRING_H 1
-
-/* Define to 1 if you have the `strlcpy' function. */
-#define HAVE_STRLCPY 1
-
-/* Define to 1 if you have the `strsep' function. */
-#define HAVE_STRSEP 1
-
-/* Define to 1 if you have the `strtok_r' function. */
-#define HAVE_STRTOK_R 1
-
-/* Define to 1 if you have the `strtoll' function. */
-#define HAVE_STRTOLL 1
-
-/* Define to 1 if the system has the type `struct in6_addr'. */
-#define HAVE_STRUCT_IN6_ADDR 1
-
-/* Define to 1 if you have the <sys/devpoll.h> header file. */
-/* #undef HAVE_SYS_DEVPOLL_H */
-
-/* Define to 1 if you have the <sys/epoll.h> header file. */
-#define HAVE_SYS_EPOLL_H 1
-
-/* Define to 1 if you have the <sys/event.h> header file. */
-/* #undef HAVE_SYS_EVENT_H */
-
-/* Define to 1 if you have the <sys/ioctl.h> header file. */
-#define HAVE_SYS_IOCTL_H 1
-
-/* Define to 1 if you have the <sys/param.h> header file. */
-#define HAVE_SYS_PARAM_H 1
-
-/* Define to 1 if you have the <sys/queue.h> header file. */
-#define HAVE_SYS_QUEUE_H 1
-
-/* Define to 1 if you have the <sys/select.h> header file. */
-#define HAVE_SYS_SELECT_H 1
-
-/* Define to 1 if you have the <sys/socket.h> header file. */
-#define HAVE_SYS_SOCKET_H 1
-
-/* Define to 1 if you have the <sys/stat.h> header file. */
-#define HAVE_SYS_STAT_H 1
-
-/* Define to 1 if you have the <sys/time.h> header file. */
-#define HAVE_SYS_TIME_H 1
-
-/* Define to 1 if you have the <sys/types.h> header file. */
-#define HAVE_SYS_TYPES_H 1
-
-/* Define if TAILQ_FOREACH is defined in <sys/queue.h> */
-#define HAVE_TAILQFOREACH 1
-
-/* Define if timeradd is defined in <sys/time.h> */
-#define HAVE_TIMERADD 1
-
-/* Define if timerclear is defined in <sys/time.h> */
-#define HAVE_TIMERCLEAR 1
-
-/* Define if timercmp is defined in <sys/time.h> */
-#define HAVE_TIMERCMP 1
-
-/* Define if timerisset is defined in <sys/time.h> */
-#define HAVE_TIMERISSET 1
-
-/* Define to 1 if the system has the type `uint16_t'. */
-#define HAVE_UINT16_T 1
-
-/* Define to 1 if the system has the type `uint32_t'. */
-#define HAVE_UINT32_T 1
-
-/* Define to 1 if the system has the type `uint64_t'. */
-#define HAVE_UINT64_T 1
-
-/* Define to 1 if the system has the type `uint8_t'. */
-#define HAVE_UINT8_T 1
-
-/* Define to 1 if you have the <unistd.h> header file. */
-#define HAVE_UNISTD_H 1
-
-/* Define to 1 if you have the `vasprintf' function. */
-#define HAVE_VASPRINTF 1
-
-/* Define if kqueue works correctly with pipes */
-/* #undef HAVE_WORKING_KQUEUE */
-
-/* Name of package */
-#define PACKAGE "libevent"
-
-/* Define to the address where bug reports for this package should be sent. */
-#define PACKAGE_BUGREPORT ""
-
-/* Define to the full name of this package. */
-#define PACKAGE_NAME ""
-
-/* Define to the full name and version of this package. */
-#define PACKAGE_STRING ""
-
-/* Define to the one symbol short name of this package. */
-#define PACKAGE_TARNAME ""
-
-/* Define to the version of this package. */
-#define PACKAGE_VERSION ""
-
-/* The size of `int', as computed by sizeof. */
-#define SIZEOF_INT 4
-
-/* The size of `long', as computed by sizeof. */
-#define SIZEOF_LONG 8
-
-/* The size of `long long', as computed by sizeof. */
-#define SIZEOF_LONG_LONG 8
-
-/* The size of `short', as computed by sizeof. */
-#define SIZEOF_SHORT 2
-
-/* Define to 1 if you have the ANSI C header files. */
-#define STDC_HEADERS 1
-
-/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
-#define TIME_WITH_SYS_TIME 1
-
-/* Version number of package */
-#define VERSION "1.4.13-stable"
-
-/* Define to appropriate substitue if compiler doesnt have __func__ */
-/* #undef __func__ */
-
-/* Define to empty if `const' does not conform to ANSI C. */
-/* #undef const */
-
-/* Define to `__inline__' or `__inline' if that's what the C compiler
- calls it, or to nothing if 'inline' is not supported under any name. */
-#ifndef __cplusplus
-/* #undef inline */
-#endif
-
-/* Define to `int' if <sys/types.h> does not define. */
-/* #undef pid_t */
-
-/* Define to `unsigned int' if <sys/types.h> does not define. */
-/* #undef size_t */
-
-/* Define to unsigned int if you dont have it */
-/* #undef socklen_t */
diff --git a/base/third_party/libevent/android/event-config.h b/base/third_party/libevent/android/event-config.h
deleted file mode 100644
index 6563cb7..0000000
--- a/base/third_party/libevent/android/event-config.h
+++ /dev/null
@@ -1,281 +0,0 @@
-/* Copied from Linux version and changed the features according Android, which
- * is close to Linux */
-#ifndef _EVENT_CONFIG_H_
-#define _EVENT_CONFIG_H_
-/* config.h. Generated from config.h.in by configure. */
-/* config.h.in. Generated from configure.in by autoheader. */
-
-/* Define if clock_gettime is available in libc */
-#define _EVENT_DNS_USE_CPU_CLOCK_FOR_ID 1
-
-/* Define is no secure id variant is available */
-/* #undef _EVENT_DNS_USE_GETTIMEOFDAY_FOR_ID */
-
-/* Define to 1 if you have the `clock_gettime' function. */
-#define _EVENT_HAVE_CLOCK_GETTIME 1
-
-/* Define if /dev/poll is available */
-/* #undef _EVENT_HAVE_DEVPOLL */
-
-/* Define to 1 if you have the <dlfcn.h> header file. */
-#define _EVENT_HAVE_DLFCN_H 1
-
-/* Define if your system supports the epoll system calls */
-#define _EVENT_HAVE_EPOLL 1
-
-/* Define to 1 if you have the `epoll_ctl' function. */
-#define _EVENT_HAVE_EPOLL_CTL 1
-
-/* Define if your system supports event ports */
-/* #undef _EVENT_HAVE_EVENT_PORTS */
-
-/* Define to 1 if you have the `fcntl' function. */
-#define _EVENT_HAVE_FCNTL 1
-
-/* Define to 1 if you have the <fcntl.h> header file. */
-#define _EVENT_HAVE_FCNTL_H 1
-
-/* Define to 1 if the system has the type `fd_mask'. */
-/* #undef _EVENT_HAVE_FD_MASK 1 */
-
-/* Define to 1 if you have the `getaddrinfo' function. */
-#define _EVENT_HAVE_GETADDRINFO 1
-
-/* Define to 1 if you have the `getegid' function. */
-#define _EVENT_HAVE_GETEGID 1
-
-/* Define to 1 if you have the `geteuid' function. */
-#define _EVENT_HAVE_GETEUID 1
-
-/* Define to 1 if you have the `getnameinfo' function. */
-#define _EVENT_HAVE_GETNAMEINFO 1
-
-/* Define to 1 if you have the `gettimeofday' function. */
-#define _EVENT_HAVE_GETTIMEOFDAY 1
-
-/* Define to 1 if you have the `inet_ntop' function. */
-#define _EVENT_HAVE_INET_NTOP 1
-
-/* Define to 1 if you have the <inttypes.h> header file. */
-#define _EVENT_HAVE_INTTYPES_H 1
-
-/* Define to 1 if you have the `issetugid' function. */
-/* #undef _EVENT_HAVE_ISSETUGID */
-
-/* Define to 1 if you have the `kqueue' function. */
-/* #undef _EVENT_HAVE_KQUEUE */
-
-/* Define to 1 if you have the `nsl' library (-lnsl). */
-#define _EVENT_HAVE_LIBNSL 1
-
-/* Define to 1 if you have the `resolv' library (-lresolv). */
-#define _EVENT_HAVE_LIBRESOLV 1
-
-/* Define to 1 if you have the `rt' library (-lrt). */
-#define _EVENT_HAVE_LIBRT 1
-
-/* Define to 1 if you have the `socket' library (-lsocket). */
-/* #undef _EVENT_HAVE_LIBSOCKET */
-
-/* Define to 1 if you have the <memory.h> header file. */
-#define _EVENT_HAVE_MEMORY_H 1
-
-/* Define to 1 if you have the <netinet/in6.h> header file. */
-/* #undef _EVENT_HAVE_NETINET_IN6_H */
-
-/* Define to 1 if you have the `poll' function. */
-#define _EVENT_HAVE_POLL 1
-
-/* Define to 1 if you have the <poll.h> header file. */
-#define _EVENT_HAVE_POLL_H 1
-
-/* Define to 1 if you have the `port_create' function. */
-/* #undef _EVENT_HAVE_PORT_CREATE */
-
-/* Define to 1 if you have the <port.h> header file. */
-/* #undef _EVENT_HAVE_PORT_H */
-
-/* Define to 1 if you have the `select' function. */
-#define _EVENT_HAVE_SELECT 1
-
-/* Define if F_SETFD is defined in <fcntl.h> */
-#define _EVENT_HAVE_SETFD 1
-
-/* Define to 1 if you have the `sigaction' function. */
-#define _EVENT_HAVE_SIGACTION 1
-
-/* Define to 1 if you have the `signal' function. */
-#define _EVENT_HAVE_SIGNAL 1
-
-/* Define to 1 if you have the <signal.h> header file. */
-#define _EVENT_HAVE_SIGNAL_H 1
-
-/* Define to 1 if you have the <stdarg.h> header file. */
-#define _EVENT_HAVE_STDARG_H 1
-
-/* Define to 1 if you have the <stdint.h> header file. */
-#define _EVENT_HAVE_STDINT_H 1
-
-/* Define to 1 if you have the <stdlib.h> header file. */
-#define _EVENT_HAVE_STDLIB_H 1
-
-/* Define to 1 if you have the <strings.h> header file. */
-#define _EVENT_HAVE_STRINGS_H 1
-
-/* Define to 1 if you have the <string.h> header file. */
-#define _EVENT_HAVE_STRING_H 1
-
-/* Define to 1 if you have the `strlcpy' function. */
-#define _EVENT_HAVE_STRLCPY 1
-
-/* Define to 1 if you have the `strsep' function. */
-#define _EVENT_HAVE_STRSEP 1
-
-/* Define to 1 if you have the `strtok_r' function. */
-#define _EVENT_HAVE_STRTOK_R 1
-
-/* Define to 1 if you have the `strtoll' function. */
-#define _EVENT_HAVE_STRTOLL 1
-
-/* Define to 1 if the system has the type `struct in6_addr'. */
-#define _EVENT_HAVE_STRUCT_IN6_ADDR 1
-
-/* Define to 1 if you have the <sys/devpoll.h> header file. */
-/* #undef _EVENT_HAVE_SYS_DEVPOLL_H */
-
-/* Define to 1 if you have the <sys/epoll.h> header file. */
-#define _EVENT_HAVE_SYS_EPOLL_H 1
-
-/* Define to 1 if you have the <sys/event.h> header file. */
-/* #undef _EVENT_HAVE_SYS_EVENT_H */
-
-/* Define to 1 if you have the <sys/ioctl.h> header file. */
-#define _EVENT_HAVE_SYS_IOCTL_H 1
-
-/* Define to 1 if you have the <sys/param.h> header file. */
-#define _EVENT_HAVE_SYS_PARAM_H 1
-
-/* Define to 1 if you have the <sys/queue.h> header file. */
-#define _EVENT_HAVE_SYS_QUEUE_H 1
-
-/* Define to 1 if you have the <sys/select.h> header file. */
-#define _EVENT_HAVE_SYS_SELECT_H 1
-
-/* Define to 1 if you have the <sys/socket.h> header file. */
-#define _EVENT_HAVE_SYS_SOCKET_H 1
-
-/* Define to 1 if you have the <sys/stat.h> header file. */
-#define _EVENT_HAVE_SYS_STAT_H 1
-
-/* Define to 1 if you have the <sys/time.h> header file. */
-#define _EVENT_HAVE_SYS_TIME_H 1
-
-/* Define to 1 if you have the <sys/types.h> header file. */
-#define _EVENT_HAVE_SYS_TYPES_H 1
-
-/* Define if TAILQ_FOREACH is defined in <sys/queue.h> */
-#define _EVENT_HAVE_TAILQFOREACH 1
-
-/* Define if timeradd is defined in <sys/time.h> */
-#define _EVENT_HAVE_TIMERADD 1
-
-/* Define if timerclear is defined in <sys/time.h> */
-#define _EVENT_HAVE_TIMERCLEAR 1
-
-/* Define if timercmp is defined in <sys/time.h> */
-#define _EVENT_HAVE_TIMERCMP 1
-
-/* Define if timerisset is defined in <sys/time.h> */
-#define _EVENT_HAVE_TIMERISSET 1
-
-/* Define to 1 if the system has the type `uint16_t'. */
-#define _EVENT_HAVE_UINT16_T 1
-
-/* Define to 1 if the system has the type `uint32_t'. */
-#define _EVENT_HAVE_UINT32_T 1
-
-/* Define to 1 if the system has the type `uint64_t'. */
-#define _EVENT_HAVE_UINT64_T 1
-
-/* Define to 1 if the system has the type `uint8_t'. */
-#define _EVENT_HAVE_UINT8_T 1
-
-/* Define to 1 if you have the <unistd.h> header file. */
-#define _EVENT_HAVE_UNISTD_H 1
-
-/* Define to 1 if you have the `vasprintf' function. */
-#define _EVENT_HAVE_VASPRINTF 1
-
-/* Define if kqueue works correctly with pipes */
-/* #undef _EVENT_HAVE_WORKING_KQUEUE */
-
-/* Define to the sub-directory in which libtool stores uninstalled libraries.
- */
-#define _EVENT_LT_OBJDIR ".libs/"
-
-/* Numeric representation of the version */
-#define _EVENT_NUMERIC_VERSION 0x01040f00
-
-/* Name of package */
-#define _EVENT_PACKAGE "libevent"
-
-/* Define to the address where bug reports for this package should be sent. */
-#define _EVENT_PACKAGE_BUGREPORT ""
-
-/* Define to the full name of this package. */
-#define _EVENT_PACKAGE_NAME ""
-
-/* Define to the full name and version of this package. */
-#define _EVENT_PACKAGE_STRING ""
-
-/* Define to the one symbol short name of this package. */
-#define _EVENT_PACKAGE_TARNAME ""
-
-/* Define to the home page for this package. */
-#define _EVENT_PACKAGE_URL ""
-
-/* Define to the version of this package. */
-#define _EVENT_PACKAGE_VERSION ""
-
-/* The size of `int', as computed by sizeof. */
-#define _EVENT_SIZEOF_INT 4
-
-/* The size of `long', as computed by sizeof. */
-#define _EVENT_SIZEOF_LONG 8
-
-/* The size of `long long', as computed by sizeof. */
-#define _EVENT_SIZEOF_LONG_LONG 8
-
-/* The size of `short', as computed by sizeof. */
-#define _EVENT_SIZEOF_SHORT 2
-
-/* Define to 1 if you have the ANSI C header files. */
-#define _EVENT_STDC_HEADERS 1
-
-/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
-#define _EVENT_TIME_WITH_SYS_TIME 1
-
-/* Version number of package */
-#define _EVENT_VERSION "1.4.15"
-
-/* Define to appropriate substitue if compiler doesnt have __func__ */
-/* #undef _EVENT___func__ */
-
-/* Define to empty if `const' does not conform to ANSI C. */
-/* #undef _EVENT_const */
-
-/* Define to `__inline__' or `__inline' if that's what the C compiler
- calls it, or to nothing if 'inline' is not supported under any name. */
-#ifndef _EVENT___cplusplus
-/* #undef _EVENT_inline */
-#endif
-
-/* Define to `int' if <sys/types.h> does not define. */
-/* #undef _EVENT_pid_t */
-
-/* Define to `unsigned int' if <sys/types.h> does not define. */
-/* #undef _EVENT_size_t */
-
-/* Define to unsigned int if you dont have it */
-/* #undef _EVENT_socklen_t */
-#endif
diff --git a/base/threading/platform_thread_android.cc b/base/threading/platform_thread_android.cc
deleted file mode 100644
index fd90d35..0000000
--- a/base/threading/platform_thread_android.cc
+++ /dev/null
@@ -1,96 +0,0 @@
-// Copyright (c) 2012 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.
-
-#include "base/threading/platform_thread.h"
-
-#include <errno.h>
-#include <stddef.h>
-#include <sys/prctl.h>
-#include <sys/resource.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include "base/android/jni_android.h"
-#include "base/lazy_instance.h"
-#include "base/logging.h"
-#include "base/threading/platform_thread_internal_posix.h"
-#include "base/threading/thread_id_name_manager.h"
-#include "jni/ThreadUtils_jni.h"
-
-namespace base {
-
-namespace internal {
-
-// - BACKGROUND corresponds to Android's PRIORITY_BACKGROUND = 10 value and can
-// result in heavy throttling and force the thread onto a little core on
-// big.LITTLE devices.
-// - DISPLAY corresponds to Android's PRIORITY_DISPLAY = -4 value.
-// - REALTIME_AUDIO corresponds to Android's PRIORITY_AUDIO = -16 value.
-const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = {
- {ThreadPriority::BACKGROUND, 10},
- {ThreadPriority::NORMAL, 0},
- {ThreadPriority::DISPLAY, -4},
- {ThreadPriority::REALTIME_AUDIO, -16},
-};
-
-bool SetCurrentThreadPriorityForPlatform(ThreadPriority priority) {
- // On Android, we set the Audio priority through JNI as Audio priority
- // will also allow the process to run while it is backgrounded.
- if (priority == ThreadPriority::REALTIME_AUDIO) {
- JNIEnv* env = base::android::AttachCurrentThread();
- Java_ThreadUtils_setThreadPriorityAudio(env, PlatformThread::CurrentId());
- return true;
- }
- return false;
-}
-
-bool GetCurrentThreadPriorityForPlatform(ThreadPriority* priority) {
- DCHECK(priority);
- *priority = ThreadPriority::NORMAL;
- JNIEnv* env = base::android::AttachCurrentThread();
- if (Java_ThreadUtils_isThreadPriorityAudio(
- env, PlatformThread::CurrentId())) {
- *priority = ThreadPriority::REALTIME_AUDIO;
- return true;
- }
- return false;
-}
-
-} // namespace internal
-
-void PlatformThread::SetName(const std::string& name) {
- ThreadIdNameManager::GetInstance()->SetName(name);
-
- // Like linux, on android we can get the thread names to show up in the
- // debugger by setting the process name for the LWP.
- // We don't want to do this for the main thread because that would rename
- // the process, causing tools like killall to stop working.
- if (PlatformThread::CurrentId() == getpid())
- return;
-
- // Set the name for the LWP (which gets truncated to 15 characters).
- int err = prctl(PR_SET_NAME, name.c_str());
- if (err < 0 && errno != EPERM)
- DPLOG(ERROR) << "prctl(PR_SET_NAME)";
-}
-
-
-void InitThreading() {
-}
-
-void TerminateOnThread() {
- base::android::DetachFromVM();
-}
-
-size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) {
-#if !defined(ADDRESS_SANITIZER)
- return 0;
-#else
- // AddressSanitizer bloats the stack approximately 2x. Default stack size of
- // 1Mb is not enough for some tests (see http://crbug.com/263749 for example).
- return 2 * (1 << 20); // 2Mb
-#endif
-}
-
-} // namespace base
diff --git a/base/time/time_android.cc b/base/time/time_android.cc
deleted file mode 100644
index e0c4914..0000000
--- a/base/time/time_android.cc
+++ /dev/null
@@ -1,26 +0,0 @@
-// 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.
-
-#include "base/time/time.h"
-
-namespace base {
-
-// static
-TimeTicks TimeTicks::FromUptimeMillis(jlong uptime_millis_value) {
- // The implementation of the SystemClock.uptimeMillis() in AOSP uses the same
- // clock as base::TimeTicks::Now(): clock_gettime(CLOCK_MONOTONIC), see in
- // platform/system/code:
- // 1. libutils/SystemClock.cpp
- // 2. libutils/Timers.cpp
- //
- // We are not aware of any motivations for Android OEMs to modify the AOSP
- // implementation of either uptimeMillis() or clock_gettime(CLOCK_MONOTONIC),
- // so we assume that there are no such customizations.
- //
- // Under these assumptions the conversion is as safe as copying the value of
- // base::TimeTicks::Now() with a loss of sub-millisecond precision.
- return TimeTicks(uptime_millis_value * Time::kMicrosecondsPerMillisecond);
-}
-
-} // namespace base