Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(638)

Unified Diff: chrome/browser/extensions/api/image_writer_private/image_writer_private_apitest.cc

Issue 382053004: Adds API test for imageWriterPrivate.writeFromFile (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes memory leak. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/image_writer_private/image_writer_private_apitest.cc
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 1c5fab924d081bcbcccbecdca5cecd4409717aef..43ec859e514d4b0e5494a6e9bfddea3ec40e88ed 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,30 +2,54 @@
// 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 SetUpOnMainThread() OVERRIDE {
+ 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));
+
scoped_refptr<StorageDeviceList> device_list(new StorageDeviceList);
RemovableStorageDevice* expected1 = new RemovableStorageDevice();
expected1->vendor = "Vendor 1";
expected1->model = "Model 1";
- expected1->capacity = 1 << 20;
- expected1->storage_unit_id = "/test/id/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
RemovableStorageDevice* expected2 = new RemovableStorageDevice();
expected2->vendor = "Vendor 2";
expected2->model = "Model 2";
- expected2->capacity = 1 << 22;
- expected2->storage_unit_id = "/test/id/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
linked_ptr<RemovableStorageDevice> device1(expected1);
device_list->data.push_back(device1);
@@ -35,9 +59,43 @@ class ImageWriterPrivateApiTest : public ExtensionApiTest {
RemovableStorageProvider::SetDeviceListForTesting(device_list);
}
- virtual void CleanUpOnMainThread() OVERRIDE {
+ virtual void TearDownInProcessBrowserTestFixture() OVERRIDE {
+ ExtensionApiTest::TearDownInProcessBrowserTestFixture();
+ test_utils_.TearDown();
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) {
@@ -45,4 +103,23 @@ 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

Powered by Google App Engine
This is Rietveld 408576698