summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgrogan@chromium.org <dgrogan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-09 22:16:44 +0000
committerdgrogan@chromium.org <dgrogan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-09 22:16:44 +0000
commitf7ab73985d0e82fed573d956118a35b7047a0bce (patch)
treeeedda566262bdf1ab73464959551d8c9a6c4592a
parent2fd86ea18d370d3c4d9d8f4bf74b865c3204f9e3 (diff)
downloadchromium_src-f7ab73985d0e82fed573d956118a35b7047a0bce.zip
chromium_src-f7ab73985d0e82fed573d956118a35b7047a0bce.tar.gz
chromium_src-f7ab73985d0e82fed573d956118a35b7047a0bce.tar.bz2
Revert 282130 "Adds API test for imageWriterPrivate.writeFromFile"
> Adds API test for imageWriterPrivate.writeFromFile > > BUG=384650 > > Review URL: https://codereview.chromium.org/336923002 TBR=haven@chromium.org Review URL: https://codereview.chromium.org/384513002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282141 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/extensions/api/image_writer_private/destroy_partitions_operation_unittest.cc20
-rw-r--r--chrome/browser/extensions/api/image_writer_private/image_writer_private_apitest.cc89
-rw-r--r--chrome/browser/extensions/api/image_writer_private/operation.cc15
-rw-r--r--chrome/browser/extensions/api/image_writer_private/operation.h2
-rw-r--r--chrome/browser/extensions/api/image_writer_private/operation_manager_unittest.cc15
-rw-r--r--chrome/browser/extensions/api/image_writer_private/operation_unittest.cc56
-rw-r--r--chrome/browser/extensions/api/image_writer_private/test_utils.cc128
-rw-r--r--chrome/browser/extensions/api/image_writer_private/test_utils.h80
-rw-r--r--chrome/browser/extensions/api/image_writer_private/write_from_file_operation_unittest.cc31
-rw-r--r--chrome/browser/extensions/api/image_writer_private/write_from_url_operation_unittest.cc16
-rw-r--r--chrome/chrome_tests.gypi1
-rw-r--r--chrome/test/data/extensions/api_test/image_writer_private/list_devices/test.js10
-rw-r--r--chrome/test/data/extensions/api_test/image_writer_private/write_from_file/background.js8
-rw-r--r--chrome/test/data/extensions/api_test/image_writer_private/write_from_file/manifest.json12
-rw-r--r--chrome/test/data/extensions/api_test/image_writer_private/write_from_file/test.html3
-rw-r--r--chrome/test/data/extensions/api_test/image_writer_private/write_from_file/test.js71
16 files changed, 144 insertions, 413 deletions
diff --git a/chrome/browser/extensions/api/image_writer_private/destroy_partitions_operation_unittest.cc b/chrome/browser/extensions/api/image_writer_private/destroy_partitions_operation_unittest.cc
index 9363a1a..af09c42 100644
--- a/chrome/browser/extensions/api/image_writer_private/destroy_partitions_operation_unittest.cc
+++ b/chrome/browser/extensions/api/image_writer_private/destroy_partitions_operation_unittest.cc
@@ -22,12 +22,16 @@ class ImageWriterDestroyPartitionsOperationTest
TEST_F(ImageWriterDestroyPartitionsOperationTest, EndToEnd) {
TestingProfile profile;
MockOperationManager manager(&profile);
+ scoped_refptr<FakeImageWriterClient> client = FakeImageWriterClient::Create();
scoped_refptr<DestroyPartitionsOperation> operation(
- new DestroyPartitionsOperation(
- manager.AsWeakPtr(),
- kDummyExtensionId,
- test_utils_.GetDevicePath().AsUTF8Unsafe()));
+ new DestroyPartitionsOperation(manager.AsWeakPtr(),
+ kDummyExtensionId,
+ test_device_path_.AsUTF8Unsafe()));
+
+#if !defined(OS_CHROMEOS)
+ operation->SetUtilityClientForTesting(client);
+#endif
EXPECT_CALL(
manager,
@@ -50,10 +54,10 @@ TEST_F(ImageWriterDestroyPartitionsOperationTest, EndToEnd) {
base::RunLoop().RunUntilIdle();
#if !defined(OS_CHROMEOS)
- test_utils_.GetUtilityClient()->Progress(0);
- test_utils_.GetUtilityClient()->Progress(50);
- test_utils_.GetUtilityClient()->Progress(100);
- test_utils_.GetUtilityClient()->Success();
+ client->Progress(0);
+ client->Progress(50);
+ client->Progress(100);
+ client->Success();
base::RunLoop().RunUntilIdle();
#endif
diff --git a/chrome/browser/extensions/api/image_writer_private/image_writer_private_apitest.cc b/chrome/browser/extensions/api/image_writer_private/image_writer_private_apitest.cc
index 43ec859..1c5fab9 100644
--- a/chrome/browser/extensions/api/image_writer_private/image_writer_private_apitest.cc
+++ b/chrome/browser/extensions/api/image_writer_private/image_writer_private_apitest.cc
@@ -2,54 +2,30 @@
// 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_loop.h"
-#include "chrome/browser/extensions/api/file_system/file_system_api.h"
-#include "chrome/browser/extensions/api/image_writer_private/operation.h"
#include "chrome/browser/extensions/api/image_writer_private/removable_storage_provider.h"
-#include "chrome/browser/extensions/api/image_writer_private/test_utils.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/common/extensions/api/image_writer_private.h"
-#include "content/public/browser/browser_thread.h"
namespace extensions {
using api::image_writer_private::RemovableStorageDevice;
-using extensions::image_writer::FakeImageWriterClient;
class ImageWriterPrivateApiTest : public ExtensionApiTest {
public:
- virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
- ExtensionApiTest::SetUpInProcessBrowserTestFixture();
- test_utils_.SetUp(true);
-
- ASSERT_TRUE(test_utils_.FillFile(test_utils_.GetImagePath(),
- image_writer::kImagePattern,
- image_writer::kTestFileSize));
- ASSERT_TRUE(test_utils_.FillFile(test_utils_.GetDevicePath(),
- image_writer::kDevicePattern,
- image_writer::kTestFileSize));
-
+ virtual void SetUpOnMainThread() OVERRIDE {
scoped_refptr<StorageDeviceList> device_list(new StorageDeviceList);
RemovableStorageDevice* expected1 = new RemovableStorageDevice();
expected1->vendor = "Vendor 1";
expected1->model = "Model 1";
- expected1->capacity = image_writer::kTestFileSize;
-#if defined(OS_WIN)
- expected1->storage_unit_id = test_utils_.GetDevicePath().AsUTF8Unsafe();
-#else
- expected1->storage_unit_id = test_utils_.GetDevicePath().value();
-#endif
+ expected1->capacity = 1 << 20;
+ expected1->storage_unit_id = "/test/id/1";
RemovableStorageDevice* expected2 = new RemovableStorageDevice();
expected2->vendor = "Vendor 2";
expected2->model = "Model 2";
- expected2->capacity = image_writer::kTestFileSize << 2;
-#if defined(OS_WIN)
- expected2->storage_unit_id = test_utils_.GetDevicePath().AsUTF8Unsafe();
-#else
- expected2->storage_unit_id = test_utils_.GetDevicePath().value();
-#endif
+ expected2->capacity = 1 << 22;
+ expected2->storage_unit_id = "/test/id/2";
linked_ptr<RemovableStorageDevice> device1(expected1);
device_list->data.push_back(device1);
@@ -59,43 +35,9 @@ class ImageWriterPrivateApiTest : public ExtensionApiTest {
RemovableStorageProvider::SetDeviceListForTesting(device_list);
}
- virtual void TearDownInProcessBrowserTestFixture() OVERRIDE {
- ExtensionApiTest::TearDownInProcessBrowserTestFixture();
- test_utils_.TearDown();
+ virtual void CleanUpOnMainThread() OVERRIDE {
RemovableStorageProvider::ClearDeviceListForTesting();
- FileSystemChooseEntryFunction::StopSkippingPickerForTest();
- }
-
-#if !defined(OS_CHROMEOS)
- void ImageWriterUtilityClientCall() {
- content::BrowserThread::PostTask(
- content::BrowserThread::FILE,
- FROM_HERE,
- base::Bind(&FakeImageWriterClient::Progress,
- test_utils_.GetUtilityClient(),
- 0));
- content::BrowserThread::PostTask(
- content::BrowserThread::FILE,
- FROM_HERE,
- base::Bind(&FakeImageWriterClient::Progress,
- test_utils_.GetUtilityClient(),
- 50));
- content::BrowserThread::PostTask(
- content::BrowserThread::FILE,
- FROM_HERE,
- base::Bind(&FakeImageWriterClient::Progress,
- test_utils_.GetUtilityClient(),
- 100));
- content::BrowserThread::PostTask(
- content::BrowserThread::FILE,
- FROM_HERE,
- base::Bind(&FakeImageWriterClient::Success,
- test_utils_.GetUtilityClient()));
}
-#endif
-
- protected:
- image_writer::ImageWriterTestUtils test_utils_;
};
IN_PROC_BROWSER_TEST_F(ImageWriterPrivateApiTest, TestListDevices) {
@@ -103,23 +45,4 @@ IN_PROC_BROWSER_TEST_F(ImageWriterPrivateApiTest, TestListDevices) {
<< message_;
}
-IN_PROC_BROWSER_TEST_F(ImageWriterPrivateApiTest, TestWriteFromFile) {
- FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest(
- "test_temp", test_utils_.GetTempDir());
-
- base::FilePath selected_image(test_utils_.GetImagePath());
- FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
- &selected_image);
-
-#if !defined(OS_CHROMEOS)
- test_utils_.GetUtilityClient()->SetWriteCallback(base::Bind(
- &ImageWriterPrivateApiTest::ImageWriterUtilityClientCall, this));
- test_utils_.GetUtilityClient()->SetVerifyCallback(base::Bind(
- &ImageWriterPrivateApiTest::ImageWriterUtilityClientCall, this));
-#endif
-
- ASSERT_TRUE(RunPlatformAppTest("image_writer_private/write_from_file"))
- << message_;
-}
-
} // namespace extensions
diff --git a/chrome/browser/extensions/api/image_writer_private/operation.cc b/chrome/browser/extensions/api/image_writer_private/operation.cc
index 6ffd826..b12f1d4 100644
--- a/chrome/browser/extensions/api/image_writer_private/operation.cc
+++ b/chrome/browser/extensions/api/image_writer_private/operation.cc
@@ -6,7 +6,6 @@
#include "base/file_util.h"
#include "base/files/file_enumerator.h"
-#include "base/lazy_instance.h"
#include "base/threading/worker_pool.h"
#include "chrome/browser/extensions/api/image_writer_private/error_messages.h"
#include "chrome/browser/extensions/api/image_writer_private/operation_manager.h"
@@ -25,11 +24,6 @@ const int kMD5BufferSize = 1024;
const char kChromeOSTempRoot[] = "/var/tmp";
#endif
-#if !defined(OS_CHROMEOS)
-static base::LazyInstance<scoped_refptr<ImageWriterUtilityClient> >
- g_utility_client = LAZY_INSTANCE_INITIALIZER;
-#endif
-
Operation::Operation(base::WeakPtr<OperationManager> manager,
const ExtensionId& extension_id,
const std::string& device_path)
@@ -67,10 +61,11 @@ image_writer_api::Stage Operation::GetStage() {
}
#if !defined(OS_CHROMEOS)
-// static
void Operation::SetUtilityClientForTesting(
scoped_refptr<ImageWriterUtilityClient> client) {
- g_utility_client.Get() = client;
+ image_writer_client_ = client;
+ AddCleanUpFunction(
+ base::Bind(&ImageWriterUtilityClient::Shutdown, image_writer_client_));
}
#endif
@@ -249,10 +244,6 @@ void Operation::CompleteAndContinue(const base::Closure& continuation) {
#if !defined(OS_CHROMEOS)
void Operation::StartUtilityClient() {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);
- if (g_utility_client.Get()) {
- image_writer_client_ = g_utility_client.Get();
- return;
- }
if (!image_writer_client_) {
image_writer_client_ = new ImageWriterUtilityClient();
AddCleanUpFunction(base::Bind(&Operation::StopUtilityClient, this));
diff --git a/chrome/browser/extensions/api/image_writer_private/operation.h b/chrome/browser/extensions/api/image_writer_private/operation.h
index 0069754..b7c4670 100644
--- a/chrome/browser/extensions/api/image_writer_private/operation.h
+++ b/chrome/browser/extensions/api/image_writer_private/operation.h
@@ -74,7 +74,7 @@ class Operation : public base::RefCountedThreadSafe<Operation> {
#if !defined(OS_CHROMEOS)
// Set an ImageWriterClient to use. Should be called only when testing.
- static void SetUtilityClientForTesting(
+ void SetUtilityClientForTesting(
scoped_refptr<ImageWriterUtilityClient> client);
#endif
diff --git a/chrome/browser/extensions/api/image_writer_private/operation_manager_unittest.cc b/chrome/browser/extensions/api/image_writer_private/operation_manager_unittest.cc
index dbda8b0..67844e2 100644
--- a/chrome/browser/extensions/api/image_writer_private/operation_manager_unittest.cc
+++ b/chrome/browser/extensions/api/image_writer_private/operation_manager_unittest.cc
@@ -58,7 +58,8 @@ KeyedService* BuildFakeExtensionSystem(content::BrowserContext* profile) {
namespace {
-class ImageWriterOperationManagerTest : public ImageWriterUnitTestBase {
+class ImageWriterOperationManagerTest
+ : public ImageWriterUnitTestBase {
public:
void StartCallback(bool success, const std::string& error) {
started_ = true;
@@ -110,11 +111,11 @@ TEST_F(ImageWriterOperationManagerTest, WriteFromFile) {
OperationManager manager(&test_profile_);
manager.StartWriteFromFile(
- kDummyExtensionId,
- test_utils_.GetImagePath(),
- test_utils_.GetDevicePath().AsUTF8Unsafe(),
- base::Bind(&ImageWriterOperationManagerTest::StartCallback,
- base::Unretained(this)));
+ kDummyExtensionId,
+ test_image_path_,
+ test_device_path_.AsUTF8Unsafe(),
+ base::Bind(&ImageWriterOperationManagerTest::StartCallback,
+ base::Unretained(this)));
EXPECT_TRUE(started_);
EXPECT_TRUE(start_success_);
@@ -137,7 +138,7 @@ TEST_F(ImageWriterOperationManagerTest, DestroyPartitions) {
manager.DestroyPartitions(
kDummyExtensionId,
- test_utils_.GetDevicePath().AsUTF8Unsafe(),
+ test_device_path_.AsUTF8Unsafe(),
base::Bind(&ImageWriterOperationManagerTest::StartCallback,
base::Unretained(this)));
diff --git a/chrome/browser/extensions/api/image_writer_private/operation_unittest.cc b/chrome/browser/extensions/api/image_writer_private/operation_unittest.cc
index 84d91d8..4a12d72 100644
--- a/chrome/browser/extensions/api/image_writer_private/operation_unittest.cc
+++ b/chrome/browser/extensions/api/image_writer_private/operation_unittest.cc
@@ -71,25 +71,26 @@ class ImageWriterOperationTest : public ImageWriterUnitTestBase {
ImageWriterUnitTestBase::SetUp();
// Create the zip file.
- base::FilePath image_dir = test_utils_.GetTempDir().AppendASCII("zip");
+ base::FilePath image_dir = temp_dir_.path().AppendASCII("zip");
ASSERT_TRUE(base::CreateDirectory(image_dir));
ASSERT_TRUE(base::CreateTemporaryFileInDir(image_dir, &image_path_));
- test_utils_.FillFile(image_path_, kImagePattern, kTestFileSize);
+ FillFile(image_path_, kImagePattern, kTestFileSize);
- zip_file_ = test_utils_.GetTempDir().AppendASCII("test_image.zip");
+ zip_file_ = temp_dir_.path().AppendASCII("test_image.zip");
ASSERT_TRUE(zip::Zip(image_dir, zip_file_, true));
// Operation setup.
- operation_ =
- new OperationForTest(manager_.AsWeakPtr(),
- kDummyExtensionId,
- test_utils_.GetDevicePath().AsUTF8Unsafe());
- operation_->SetImagePath(test_utils_.GetImagePath());
+ operation_ = new OperationForTest(manager_.AsWeakPtr(),
+ kDummyExtensionId,
+ test_device_path_.AsUTF8Unsafe());
+ client_ = FakeImageWriterClient::Create();
+ operation_->SetImagePath(test_image_path_);
}
virtual void TearDown() OVERRIDE {
// Ensure all callbacks have been destroyed and cleanup occurs.
+ client_->Shutdown();
operation_->Cancel();
ImageWriterUnitTestBase::TearDown();
@@ -101,6 +102,7 @@ class ImageWriterOperationTest : public ImageWriterUnitTestBase {
scoped_ptr<TestingProfile> profile_;
MockOperationManager manager_;
+ scoped_refptr<FakeImageWriterClient> client_;
scoped_refptr<OperationForTest> operation_;
};
@@ -152,6 +154,10 @@ TEST_F(ImageWriterOperationTest, UnzipZipFile) {
#if defined(OS_LINUX)
TEST_F(ImageWriterOperationTest, WriteImageToDevice) {
+#if !defined(OS_CHROMEOS)
+ operation_->SetUtilityClientForTesting(client_);
+#endif
+
EXPECT_CALL(manager_, OnError(kDummyExtensionId, _, _, _)).Times(0);
EXPECT_CALL(manager_,
OnProgress(kDummyExtensionId, image_writer_api::STAGE_WRITE, _))
@@ -173,10 +179,10 @@ TEST_F(ImageWriterOperationTest, WriteImageToDevice) {
base::RunLoop().RunUntilIdle();
#if !defined(OS_CHROMEOS)
- test_utils_.GetUtilityClient()->Progress(0);
- test_utils_.GetUtilityClient()->Progress(kTestFileSize / 2);
- test_utils_.GetUtilityClient()->Progress(kTestFileSize);
- test_utils_.GetUtilityClient()->Success();
+ client_->Progress(0);
+ client_->Progress(kTestFileSize / 2);
+ client_->Progress(kTestFileSize);
+ client_->Success();
base::RunLoop().RunUntilIdle();
#endif
@@ -188,6 +194,8 @@ TEST_F(ImageWriterOperationTest, WriteImageToDevice) {
// are skipped.
TEST_F(ImageWriterOperationTest, VerifyFileSuccess) {
+ operation_->SetUtilityClientForTesting(client_);
+
EXPECT_CALL(manager_, OnError(kDummyExtensionId, _, _, _)).Times(0);
EXPECT_CALL(
manager_,
@@ -202,8 +210,7 @@ TEST_F(ImageWriterOperationTest, VerifyFileSuccess) {
OnProgress(kDummyExtensionId, image_writer_api::STAGE_VERIFYWRITE, 100))
.Times(AtLeast(1));
- test_utils_.FillFile(
- test_utils_.GetDevicePath(), kImagePattern, kTestFileSize);
+ FillFile(test_device_path_, kImagePattern, kTestFileSize);
operation_->Start();
content::BrowserThread::PostTask(content::BrowserThread::FILE,
@@ -214,17 +221,17 @@ TEST_F(ImageWriterOperationTest, VerifyFileSuccess) {
base::RunLoop().RunUntilIdle();
-#if !defined(OS_CHROMEOS)
- test_utils_.GetUtilityClient()->Progress(0);
- test_utils_.GetUtilityClient()->Progress(kTestFileSize / 2);
- test_utils_.GetUtilityClient()->Progress(kTestFileSize);
- test_utils_.GetUtilityClient()->Success();
-#endif
+ client_->Progress(0);
+ client_->Progress(kTestFileSize / 2);
+ client_->Progress(kTestFileSize);
+ client_->Success();
base::RunLoop().RunUntilIdle();
}
TEST_F(ImageWriterOperationTest, VerifyFileFailure) {
+ operation_->SetUtilityClientForTesting(client_);
+
EXPECT_CALL(
manager_,
OnProgress(kDummyExtensionId, image_writer_api::STAGE_VERIFYWRITE, _))
@@ -239,8 +246,7 @@ TEST_F(ImageWriterOperationTest, VerifyFileFailure) {
OnError(kDummyExtensionId, image_writer_api::STAGE_VERIFYWRITE, _, _))
.Times(1);
- test_utils_.FillFile(
- test_utils_.GetDevicePath(), kDevicePattern, kTestFileSize);
+ FillFile(test_device_path_, kDevicePattern, kTestFileSize);
operation_->Start();
content::BrowserThread::PostTask(content::BrowserThread::FILE,
@@ -251,9 +257,9 @@ TEST_F(ImageWriterOperationTest, VerifyFileFailure) {
base::RunLoop().RunUntilIdle();
- test_utils_.GetUtilityClient()->Progress(0);
- test_utils_.GetUtilityClient()->Progress(kTestFileSize / 2);
- test_utils_.GetUtilityClient()->Error(error::kVerificationFailed);
+ client_->Progress(0);
+ client_->Progress(kTestFileSize / 2);
+ client_->Error(error::kVerificationFailed);
base::RunLoop().RunUntilIdle();
}
diff --git a/chrome/browser/extensions/api/image_writer_private/test_utils.cc b/chrome/browser/extensions/api/image_writer_private/test_utils.cc
index 25f9e0f..6800574 100644
--- a/chrome/browser/extensions/api/image_writer_private/test_utils.cc
+++ b/chrome/browser/extensions/api/image_writer_private/test_utils.cc
@@ -77,9 +77,6 @@ void FakeImageWriterClient::Write(const ProgressCallback& progress_callback,
progress_callback_ = progress_callback;
success_callback_ = success_callback;
error_callback_ = error_callback;
-
- if (!write_callback_.is_null())
- write_callback_.Run();
}
void FakeImageWriterClient::Verify(const ProgressCallback& progress_callback,
@@ -90,9 +87,6 @@ void FakeImageWriterClient::Verify(const ProgressCallback& progress_callback,
progress_callback_ = progress_callback;
success_callback_ = success_callback;
error_callback_ = error_callback;
-
- if (!verify_callback_.is_null())
- verify_callback_.Run();
}
void FakeImageWriterClient::Cancel(const CancelCallback& cancel_callback) {
@@ -101,55 +95,35 @@ void FakeImageWriterClient::Cancel(const CancelCallback& cancel_callback) {
void FakeImageWriterClient::Shutdown() {
// Clear handlers to not hold any reference to the caller.
- success_callback_.Reset();
- progress_callback_.Reset();
- error_callback_.Reset();
- cancel_callback_.Reset();
-
- write_callback_.Reset();
- verify_callback_.Reset();
-}
-
-void FakeImageWriterClient::SetWriteCallback(
- const base::Closure& write_callback) {
- write_callback_ = write_callback;
-}
-
-void FakeImageWriterClient::SetVerifyCallback(
- const base::Closure& verify_callback) {
- verify_callback_ = verify_callback;
+ success_callback_ = base::Closure();
+ progress_callback_ = base::Callback<void(int64)>();
+ error_callback_ = base::Callback<void(const std::string&)>();
+ cancel_callback_ = base::Closure();
}
void FakeImageWriterClient::Progress(int64 progress) {
- if (!progress_callback_.is_null())
- progress_callback_.Run(progress);
+ progress_callback_.Run(progress);
}
-void FakeImageWriterClient::Success() {
- if (!success_callback_.is_null())
- success_callback_.Run();
-}
+void FakeImageWriterClient::Success() { success_callback_.Run(); }
void FakeImageWriterClient::Error(const std::string& message) {
- if (!error_callback_.is_null())
- error_callback_.Run(message);
+ error_callback_.Run(message);
}
-void FakeImageWriterClient::Cancel() {
- if (!cancel_callback_.is_null())
- cancel_callback_.Run();
-}
+void FakeImageWriterClient::Cancel() { cancel_callback_.Run(); }
-ImageWriterTestUtils::ImageWriterTestUtils() {
-}
-ImageWriterTestUtils::~ImageWriterTestUtils() {
+scoped_refptr<FakeImageWriterClient> FakeImageWriterClient::Create() {
+ return scoped_refptr<FakeImageWriterClient>(new FakeImageWriterClient());
}
-void ImageWriterTestUtils::SetUp() {
- SetUp(false);
-}
+ImageWriterUnitTestBase::ImageWriterUnitTestBase()
+ : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {}
+ImageWriterUnitTestBase::~ImageWriterUnitTestBase() {}
+
+void ImageWriterUnitTestBase::SetUp() {
+ testing::Test::SetUp();
-void ImageWriterTestUtils::SetUp(bool is_browser_test) {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(),
&test_image_path_));
@@ -163,20 +137,11 @@ void ImageWriterTestUtils::SetUp(bool is_browser_test) {
if (!chromeos::DBusThreadManager::IsInitialized()) {
chromeos::FakeDBusThreadManager* fake_dbus_thread_manager =
new chromeos::FakeDBusThreadManager;
- fake_dbus_thread_manager->SetFakeClients();
scoped_ptr<chromeos::ImageBurnerClient>
image_burner_fake(new ImageWriterFakeImageBurnerClient());
fake_dbus_thread_manager->SetImageBurnerClient(image_burner_fake.Pass());
-
- if (is_browser_test) {
- chromeos::DBusThreadManager::SetInstanceForTesting(
- fake_dbus_thread_manager);
- } else {
- chromeos::DBusThreadManager::InitializeForTesting(
- fake_dbus_thread_manager);
- }
+ chromeos::DBusThreadManager::InitializeForTesting(fake_dbus_thread_manager);
}
-
FakeDiskMountManager* disk_manager = new FakeDiskMountManager();
chromeos::disks::DiskMountManager::InitializeForTesting(disk_manager);
@@ -197,53 +162,30 @@ void ImageWriterTestUtils::SetUp(bool is_browser_test) {
true,
false);
disk_manager->SetupDefaultReplies();
-#else
- client_ = new FakeImageWriterClient();
- image_writer::Operation::SetUtilityClientForTesting(client_);
#endif
}
-void ImageWriterTestUtils::TearDown() {
+void ImageWriterUnitTestBase::TearDown() {
#if defined(OS_CHROMEOS)
- if (chromeos::DBusThreadManager::IsInitialized()) {
- chromeos::DBusThreadManager::Shutdown();
- }
+ chromeos::DBusThreadManager::Shutdown();
chromeos::disks::DiskMountManager::Shutdown();
-#else
- image_writer::Operation::SetUtilityClientForTesting(NULL);
#endif
}
-const base::FilePath& ImageWriterTestUtils::GetTempDir() {
- return temp_dir_.path();
-}
-
-const base::FilePath& ImageWriterTestUtils::GetImagePath() {
- return test_image_path_;
-}
-
-const base::FilePath& ImageWriterTestUtils::GetDevicePath() {
- return test_device_path_;
-}
-
-#if !defined(OS_CHROMEOS)
-FakeImageWriterClient* ImageWriterTestUtils::GetUtilityClient() {
- return client_.get();
-}
-#endif
-
-bool ImageWriterTestUtils::ImageWrittenToDevice() {
+bool ImageWriterUnitTestBase::ImageWrittenToDevice(
+ const base::FilePath& image_path,
+ const base::FilePath& device_path) {
scoped_ptr<char[]> image_buffer(new char[kTestFileSize]);
scoped_ptr<char[]> device_buffer(new char[kTestFileSize]);
int image_bytes_read =
- ReadFile(test_image_path_, image_buffer.get(), kTestFileSize);
+ ReadFile(image_path, image_buffer.get(), kTestFileSize);
if (image_bytes_read < 0)
return false;
int device_bytes_read =
- ReadFile(test_device_path_, device_buffer.get(), kTestFileSize);
+ ReadFile(device_path, device_buffer.get(), kTestFileSize);
if (image_bytes_read != device_bytes_read)
return false;
@@ -251,30 +193,14 @@ bool ImageWriterTestUtils::ImageWrittenToDevice() {
return memcmp(image_buffer.get(), device_buffer.get(), image_bytes_read) == 0;
}
-bool ImageWriterTestUtils::FillFile(const base::FilePath& file,
- const int pattern,
- const int length) {
+bool ImageWriterUnitTestBase::FillFile(const base::FilePath& file,
+ const int pattern,
+ const int length) {
scoped_ptr<char[]> buffer(new char[length]);
memset(buffer.get(), pattern, length);
return base::WriteFile(file, buffer.get(), length) == length;
}
-ImageWriterUnitTestBase::ImageWriterUnitTestBase()
- : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {
-}
-ImageWriterUnitTestBase::~ImageWriterUnitTestBase() {
-}
-
-void ImageWriterUnitTestBase::SetUp() {
- testing::Test::SetUp();
- test_utils_.SetUp();
-}
-
-void ImageWriterUnitTestBase::TearDown() {
- testing::Test::TearDown();
- test_utils_.TearDown();
-}
-
} // namespace image_writer
} // namespace extensions
diff --git a/chrome/browser/extensions/api/image_writer_private/test_utils.h b/chrome/browser/extensions/api/image_writer_private/test_utils.h
index 25a6941..80399f6 100644
--- a/chrome/browser/extensions/api/image_writer_private/test_utils.h
+++ b/chrome/browser/extensions/api/image_writer_private/test_utils.h
@@ -65,6 +65,20 @@ class FakeDiskMountManager : public chromeos::disks::MockDiskMountManager {
virtual void UnmountDeviceRecursively(
const std::string& device_path,
const UnmountDeviceRecursivelyCallbackType& callback) OVERRIDE;
+ /*
+ MOCK_METHOD1(AddObserver, void(chromeos::disks::DiskMountManager::Observer*));
+ MOCK_METHOD1(RemoveObserver,
+ void(chromeos::disks::DiskMountManager::Observer*));
+ MOCK_CONST_METHOD0(disks, const DiskMap&());
+ MOCK_CONST_METHOD1(FindDiskBySourcePath, const Disk*(const std::string&));
+ MOCK_CONST_METHOD0(mount_points, const MountPointMap&());
+ MOCK_METHOD0(RequestMountInfoRefresh, void());
+ MOCK_METHOD4(MountPath, void(const std::string&, const std::string&, const
+ std::string&, chromeos::MountType));
+ MOCK_METHOD3(UnmountPath, void(const std::string&, chromeos::UnmountOptions,
+ const UnmountPathCallback&));
+ MOCK_METHOD1(FormatMountedDevice, void(const std::string&));
+ */
private:
DiskMap disks_;
@@ -91,19 +105,11 @@ class FakeImageWriterClient : public ImageWriterUtilityClient {
virtual void Shutdown() OVERRIDE;
- // Sets a callback for when a Write call is made.
- void SetWriteCallback(const base::Closure& write_callback);
- // Sets a callback for when a Verify call is made.
- void SetVerifyCallback(const base::Closure& verify_callback);
-
- // Triggers the progress callback.
void Progress(int64 progress);
- // Triggers the success callback.
void Success();
- // Triggers the error callback.
void Error(const std::string& message);
- // Triggers the cancel callback.
void Cancel();
+ static scoped_refptr<FakeImageWriterClient> Create();
private:
virtual ~FakeImageWriterClient();
@@ -112,20 +118,23 @@ class FakeImageWriterClient : public ImageWriterUtilityClient {
SuccessCallback success_callback_;
ErrorCallback error_callback_;
CancelCallback cancel_callback_;
-
- base::Closure write_callback_;
- base::Closure verify_callback_;
};
-class ImageWriterTestUtils {
- public:
- ImageWriterTestUtils();
- virtual ~ImageWriterTestUtils();
+// Base class for unit tests that manages creating image and device files.
+class ImageWriterUnitTestBase : public testing::Test {
+ protected:
+ ImageWriterUnitTestBase();
+ virtual ~ImageWriterUnitTestBase();
+
+ virtual void SetUp() OVERRIDE;
+
+ virtual void TearDown() OVERRIDE;
// Verifies that the data in image_path was written to the file at
// device_path. This is different from base::ContentsEqual because the device
// may be larger than the image.
- bool ImageWrittenToDevice();
+ bool ImageWrittenToDevice(const base::FilePath& image_path,
+ const base::FilePath& device_path);
// Fills |file| with |length| bytes of |pattern|, overwriting any existing
// data.
@@ -133,47 +142,10 @@ class ImageWriterTestUtils {
const int pattern,
const int length);
- // Set up the test utils, creating temporary folders and such.
- // Note that browser tests should use the alternate form and pass "true" as an
- // argument.
- virtual void SetUp();
- // Set up the test utils, creating temporary folders and such. If
- // |is_browser_test| is true then it will use alternate initialization
- // appropriate for a browser test. This should be run in
- // |SetUpInProcessBrowserTestFixture|.
- virtual void SetUp(bool is_browser_test);
-
- virtual void TearDown();
-
- const base::FilePath& GetTempDir();
- const base::FilePath& GetImagePath();
- const base::FilePath& GetDevicePath();
-
-#if !defined(OS_CHROMEOS)
- FakeImageWriterClient* GetUtilityClient();
-#endif
-
- protected:
base::ScopedTempDir temp_dir_;
base::FilePath test_image_path_;
base::FilePath test_device_path_;
-#if !defined(OS_CHROMEOS)
- scoped_refptr<FakeImageWriterClient> client_;
-#endif
-};
-
-// Base class for unit tests that manages creating image and device files.
-class ImageWriterUnitTestBase : public testing::Test {
- protected:
- ImageWriterUnitTestBase();
- virtual ~ImageWriterUnitTestBase();
-
- virtual void SetUp() OVERRIDE;
- virtual void TearDown() OVERRIDE;
-
- ImageWriterTestUtils test_utils_;
-
private:
content::TestBrowserThreadBundle thread_bundle_;
};
diff --git a/chrome/browser/extensions/api/image_writer_private/write_from_file_operation_unittest.cc b/chrome/browser/extensions/api/image_writer_private/write_from_file_operation_unittest.cc
index 3346489..1de9533 100644
--- a/chrome/browser/extensions/api/image_writer_private/write_from_file_operation_unittest.cc
+++ b/chrome/browser/extensions/api/image_writer_private/write_from_file_operation_unittest.cc
@@ -27,10 +27,10 @@ TEST_F(ImageWriterFromFileTest, InvalidFile) {
scoped_refptr<WriteFromFileOperation> op =
new WriteFromFileOperation(manager_.AsWeakPtr(),
kDummyExtensionId,
- test_utils_.GetImagePath(),
- test_utils_.GetDevicePath().AsUTF8Unsafe());
+ test_image_path_,
+ test_device_path_.AsUTF8Unsafe());
- base::DeleteFile(test_utils_.GetImagePath(), false);
+ base::DeleteFile(test_image_path_, false);
EXPECT_CALL(manager_, OnProgress(kDummyExtensionId, _, _)).Times(0);
EXPECT_CALL(manager_, OnComplete(kDummyExtensionId)).Times(0);
@@ -50,8 +50,13 @@ TEST_F(ImageWriterFromFileTest, WriteFromFileEndToEnd) {
scoped_refptr<WriteFromFileOperation> op =
new WriteFromFileOperation(manager_.AsWeakPtr(),
kDummyExtensionId,
- test_utils_.GetImagePath(),
- test_utils_.GetDevicePath().AsUTF8Unsafe());
+ test_image_path_,
+ test_device_path_.AsUTF8Unsafe());
+#if !defined(OS_CHROMEOS)
+ scoped_refptr<FakeImageWriterClient> client = FakeImageWriterClient::Create();
+ op->SetUtilityClientForTesting(client);
+#endif
+
EXPECT_CALL(manager_,
OnProgress(kDummyExtensionId, image_writer_api::STAGE_WRITE, _))
.Times(AnyNumber());
@@ -85,15 +90,15 @@ TEST_F(ImageWriterFromFileTest, WriteFromFileEndToEnd) {
base::RunLoop().RunUntilIdle();
#if !defined(OS_CHROMEOS)
- test_utils_.GetUtilityClient()->Progress(0);
- test_utils_.GetUtilityClient()->Progress(50);
- test_utils_.GetUtilityClient()->Progress(100);
- test_utils_.GetUtilityClient()->Success();
+ client->Progress(0);
+ client->Progress(50);
+ client->Progress(100);
+ client->Success();
base::RunLoop().RunUntilIdle();
- test_utils_.GetUtilityClient()->Progress(0);
- test_utils_.GetUtilityClient()->Progress(50);
- test_utils_.GetUtilityClient()->Progress(100);
- test_utils_.GetUtilityClient()->Success();
+ client->Progress(0);
+ client->Progress(50);
+ client->Progress(100);
+ client->Success();
base::RunLoop().RunUntilIdle();
#endif
}
diff --git a/chrome/browser/extensions/api/image_writer_private/write_from_url_operation_unittest.cc b/chrome/browser/extensions/api/image_writer_private/write_from_url_operation_unittest.cc
index fdfc3dc..771af5a 100644
--- a/chrome/browser/extensions/api/image_writer_private/write_from_url_operation_unittest.cc
+++ b/chrome/browser/extensions/api/image_writer_private/write_from_url_operation_unittest.cc
@@ -77,8 +77,7 @@ class ImageWriterWriteFromUrlOperationTest : public ImageWriterUnitTestBase {
// Turn on interception and set up our dummy file.
net::URLFetcher::SetEnableInterceptionForTests(true);
get_interceptor_.reset(new GetInterceptor());
- get_interceptor_->SetResponse(GURL(kTestImageUrl),
- test_utils_.GetImagePath());
+ get_interceptor_->SetResponse(GURL(kTestImageUrl), test_image_path_);
}
virtual void TearDown() OVERRIDE {
@@ -96,7 +95,7 @@ class ImageWriterWriteFromUrlOperationTest : public ImageWriterUnitTestBase {
test_profile_.GetRequestContext(),
url,
hash,
- test_utils_.GetDevicePath().AsUTF8Unsafe()));
+ test_device_path_.AsUTF8Unsafe()));
operation->Start();
return operation;
}
@@ -141,8 +140,8 @@ TEST_F(ImageWriterWriteFromUrlOperationTest, DownloadFile) {
scoped_refptr<OperationForTest> operation =
CreateOperation(GURL(kTestImageUrl), "");
- EXPECT_TRUE(base::CreateTemporaryFileInDir(test_utils_.GetTempDir(),
- &download_target_path));
+ EXPECT_TRUE(
+ base::CreateTemporaryFileInDir(temp_dir_.path(), &download_target_path));
operation->SetImagePath(download_target_path);
EXPECT_CALL(
@@ -165,8 +164,7 @@ TEST_F(ImageWriterWriteFromUrlOperationTest, DownloadFile) {
runloop.Run();
- EXPECT_TRUE(base::ContentsEqual(test_utils_.GetImagePath(),
- operation->GetImagePath()));
+ EXPECT_TRUE(base::ContentsEqual(test_image_path_, operation->GetImagePath()));
EXPECT_EQ(1, get_interceptor_->GetHitCount());
@@ -175,7 +173,7 @@ TEST_F(ImageWriterWriteFromUrlOperationTest, DownloadFile) {
TEST_F(ImageWriterWriteFromUrlOperationTest, VerifyFile) {
scoped_ptr<char[]> data_buffer(new char[kTestFileSize]);
- base::ReadFile(test_utils_.GetImagePath(), data_buffer.get(), kTestFileSize);
+ base::ReadFile(test_image_path_, data_buffer.get(), kTestFileSize);
base::MD5Digest expected_digest;
base::MD5Sum(data_buffer.get(), kTestFileSize, &expected_digest);
std::string expected_hash = base::MD5DigestToBase16(expected_digest);
@@ -196,7 +194,7 @@ TEST_F(ImageWriterWriteFromUrlOperationTest, VerifyFile) {
image_writer_api::STAGE_VERIFYDOWNLOAD,
100)).Times(AtLeast(1));
- operation->SetImagePath(test_utils_.GetImagePath());
+ operation->SetImagePath(test_image_path_);
content::BrowserThread::PostTask(content::BrowserThread::FILE,
FROM_HERE,
base::Bind(&OperationForTest::VerifyDownload,
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 2af8588..1fd051d 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1105,7 +1105,6 @@
'browser/extensions/api/idle/idle_apitest.cc',
'browser/extensions/api/idltest/idltest_apitest.cc',
'browser/extensions/api/image_writer_private/image_writer_private_apitest.cc',
- 'browser/extensions/api/image_writer_private/test_utils.cc',
'browser/extensions/api/input_ime/input_ime_apitest_chromeos.cc',
'browser/extensions/api/management/management_api_browsertest.cc',
'browser/extensions/api/management/management_apitest.cc',
diff --git a/chrome/test/data/extensions/api_test/image_writer_private/list_devices/test.js b/chrome/test/data/extensions/api_test/image_writer_private/list_devices/test.js
index 03b7545..5643515 100644
--- a/chrome/test/data/extensions/api_test/image_writer_private/list_devices/test.js
+++ b/chrome/test/data/extensions/api_test/image_writer_private/list_devices/test.js
@@ -2,17 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-
-// storage_unit_id is skipped because it is generated to point at a temporary
-// file.
var expectedDevices = [{
'vendor': 'Vendor 1',
'model': 'Model 1',
- 'capacity': 1 << 15,
+ 'capacity': 1 << 20,
+ 'storageUnitId': '/test/id/1',
}, {
'vendor': 'Vendor 2',
'model': 'Model 2',
- 'capacity': 1 << 17,
+ 'capacity': 1 << 22,
+ 'storageUnitId': '/test/id/2',
}];
@@ -35,6 +34,7 @@ function listRemovableDevicesCallback(deviceList) {
chrome.test.assertEq(expected.vendor, dev.vendor);
chrome.test.assertEq(expected.model, dev.model);
chrome.test.assertEq(expected.capacity, dev.capacity);
+ chrome.test.assertEq(expected.storageUnitId, dev.storageUnitId);
});
}
diff --git a/chrome/test/data/extensions/api_test/image_writer_private/write_from_file/background.js b/chrome/test/data/extensions/api_test/image_writer_private/write_from_file/background.js
deleted file mode 100644
index 44edeac..0000000
--- a/chrome/test/data/extensions/api_test/image_writer_private/write_from_file/background.js
+++ /dev/null
@@ -1,8 +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.
-
-chrome.app.runtime.onLaunched.addListener(function () {
- chrome.app.window.create('test.html');
-});
-
diff --git a/chrome/test/data/extensions/api_test/image_writer_private/write_from_file/manifest.json b/chrome/test/data/extensions/api_test/image_writer_private/write_from_file/manifest.json
deleted file mode 100644
index f95644a..0000000
--- a/chrome/test/data/extensions/api_test/image_writer_private/write_from_file/manifest.json
+++ /dev/null
@@ -1,12 +0,0 @@
-{
- "key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6aedfP5QXnA176+/EKXFwbBoXl3smca9uaO1ytfLCRsH8Ja0xrjJG+/2tvcCL1JzBbc8/31cwWIOiNFawJiIc+nfZAi4rO27yakn4W83kHOhjr7hA4/a+CtmOPTTgpK1DCIpo0Xy+lpzQuqHBKL9/sXMCN4bKqcXMe7XA09VJYD6Rv+CTDfKkgN3oNYhm0KBOwkvJ/P7x7KeBUCusd+UOzJygBP4p2mDgIX/WfUZAuRGq1ty/Eu9dBm29Jhe1YBctFaARyR5FnMsr57Kw/mWrNXkZ2iewrLUzNh1FWLQUbiL4QdqaP9//Xxhsrf+LG1UcJN1HBnn/b0xYLfcH9W7RQIDAQAB",
- "name": "Image Writer Private",
- "version": "0.1",
- "app": {
- "background": {
- "scripts": ["background.js"]
- }
- },
- "permissions": ["imageWriterPrivate", "fileSystem"]
-}
-
diff --git a/chrome/test/data/extensions/api_test/image_writer_private/write_from_file/test.html b/chrome/test/data/extensions/api_test/image_writer_private/write_from_file/test.html
deleted file mode 100644
index 8d7d1db..0000000
--- a/chrome/test/data/extensions/api_test/image_writer_private/write_from_file/test.html
+++ /dev/null
@@ -1,3 +0,0 @@
-<html>
-<script src="test.js"></script>
-</html>
diff --git a/chrome/test/data/extensions/api_test/image_writer_private/write_from_file/test.js b/chrome/test/data/extensions/api_test/image_writer_private/write_from_file/test.js
deleted file mode 100644
index ba9c23a..0000000
--- a/chrome/test/data/extensions/api_test/image_writer_private/write_from_file/test.js
+++ /dev/null
@@ -1,71 +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.
-
-function assertNotNullOrUndefined(value, message) {
- chrome.test.assertTrue(value !== null, message);
- chrome.test.assertTrue(value !== undefined, message);
-}
-
-function testWriteFromFile() {
- var fileEntry;
- var storageDevice;
- var currentStage = "none";
- var currentProgress = -1;
- var started = true;
-
- function chooseEntryCallback(entry) {
- fileEntry = entry;
-
- chrome.imageWriterPrivate.listRemovableStorageDevices(
- listDevicesCallback);
- }
-
- function listDevicesCallback(deviceList) {
- chrome.test.assertTrue(deviceList.length >= 1);
- storageDevice = deviceList[0];
-
- startWrite();
- }
-
- function startWrite() {
- assertNotNullOrUndefined(fileEntry, "FileEntry should be defined.");
- assertNotNullOrUndefined(
- storageDevice.storageUnitId, "Storage Unit should be defined.");
-
- chrome.imageWriterPrivate.writeFromFile(
- storageDevice.storageUnitId,
- fileEntry,
- startWriteCallback);
- }
-
- function startWriteCallback() {
- started = true;
- }
-
- function writeProgressCallback(progressInfo) {
- currentProgress = progressInfo.percentComplete;
- currentStage = progressInfo.stage;
- }
-
- function writeCompleteCallback() {
- chrome.test.assertTrue(started, "Complete triggered before being started.");
- chrome.test.assertEq(100, currentProgress);
- chrome.test.succeed("Write completed successfully.");
- }
-
- function writeErrorCallback(message) {
- chrome.test.fail("An error occurred during writing.");
- }
-
- chrome.imageWriterPrivate.onWriteProgress.
- addListener(writeProgressCallback);
- chrome.imageWriterPrivate.onWriteComplete.
- addListener(writeCompleteCallback);
- chrome.imageWriterPrivate.onWriteError.
- addListener(writeErrorCallback);
-
- chrome.fileSystem.chooseEntry(chooseEntryCallback);
-}
-
-testWriteFromFile();