// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CONTENT_PUBLIC_TEST_TEST_FILE_ERROR_INJECTOR_H_ #define CONTENT_PUBLIC_TEST_TEST_FILE_ERROR_INJECTOR_H_ #include <stddef.h> #include <memory> #include <string> #include "base/memory/raw_ptr.h" #include "base/memory/ref_counted.h" #include "components/download/public/common/download_interrupt_reasons.h" #include "url/gurl.h" namespace content { class DownloadFileWithErrorFactory; class DownloadManager; class DownloadManagerImpl; // Test helper for injecting errors into download file operations. All errors // for a download must be injected before it starts. This class needs to be // |RefCountedThreadSafe| because the implementation is referenced by other // classes that live past the time when the user is nominally done with it. // // Once created, an error injected via InjectError() will cause any // DownloadFiles created to fail with that error. Call ClearError() to stop // injecting errors. // // Example: // // FileErrorInfo a = { ... }; // // scoped_refptr<TestFileErrorInjector> injector = // TestFileErrorInjector::Create(download_manager); // // injector->InjectError(a); // // download_manager->DownloadUrl(url1, ...); // Will be interrupted due to |a|. // download_manager->DownloadUrl(url2, ...); // Will be interrupted due to |a|. // // injector->ClearError(); // // download_manager->DownloadUrl(url3, ...); // Won't be interrupted due to |a|. class TestFileErrorInjector : public base::RefCountedThreadSafe<TestFileErrorInjector> { … }; } // namespace content #endif // CONTENT_PUBLIC_TEST_TEST_FILE_ERROR_INJECTOR_H_