1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/message_loop/message_loop.h"
6 #include "chrome/browser/extensions/api/file_system/file_system_api.h"
7 #include "chrome/browser/extensions/api/image_writer_private/operation.h"
8 #include "chrome/browser/extensions/api/image_writer_private/removable_storage_provider.h"
9 #include "chrome/browser/extensions/api/image_writer_private/test_utils.h"
10 #include "chrome/browser/extensions/extension_apitest.h"
11 #include "chrome/common/extensions/api/image_writer_private.h"
12 #include "content/public/browser/browser_thread.h"
14 namespace extensions
{
16 using api::image_writer_private::RemovableStorageDevice
;
17 using extensions::image_writer::FakeImageWriterClient
;
19 class ImageWriterPrivateApiTest
: public ExtensionApiTest
{
21 void SetUpInProcessBrowserTestFixture() override
{
22 ExtensionApiTest::SetUpInProcessBrowserTestFixture();
23 test_utils_
.SetUp(true);
25 ASSERT_TRUE(test_utils_
.FillFile(test_utils_
.GetImagePath(),
26 image_writer::kImagePattern
,
27 image_writer::kTestFileSize
));
28 ASSERT_TRUE(test_utils_
.FillFile(test_utils_
.GetDevicePath(),
29 image_writer::kDevicePattern
,
30 image_writer::kTestFileSize
));
32 scoped_refptr
<StorageDeviceList
> device_list(new StorageDeviceList
);
34 RemovableStorageDevice
* expected1
= new RemovableStorageDevice();
35 expected1
->vendor
= "Vendor 1";
36 expected1
->model
= "Model 1";
37 expected1
->capacity
= image_writer::kTestFileSize
;
38 expected1
->removable
= true;
40 expected1
->storage_unit_id
= test_utils_
.GetDevicePath().AsUTF8Unsafe();
42 expected1
->storage_unit_id
= test_utils_
.GetDevicePath().value();
45 RemovableStorageDevice
* expected2
= new RemovableStorageDevice();
46 expected2
->vendor
= "Vendor 2";
47 expected2
->model
= "Model 2";
48 expected2
->capacity
= image_writer::kTestFileSize
<< 2;
49 expected2
->removable
= false;
51 expected2
->storage_unit_id
= test_utils_
.GetDevicePath().AsUTF8Unsafe();
53 expected2
->storage_unit_id
= test_utils_
.GetDevicePath().value();
56 linked_ptr
<RemovableStorageDevice
> device1(expected1
);
57 device_list
->data
.push_back(device1
);
58 linked_ptr
<RemovableStorageDevice
> device2(expected2
);
59 device_list
->data
.push_back(device2
);
61 RemovableStorageProvider::SetDeviceListForTesting(device_list
);
64 void TearDownInProcessBrowserTestFixture() override
{
65 ExtensionApiTest::TearDownInProcessBrowserTestFixture();
66 test_utils_
.TearDown();
67 RemovableStorageProvider::ClearDeviceListForTesting();
68 FileSystemChooseEntryFunction::StopSkippingPickerForTest();
71 #if !defined(OS_CHROMEOS)
72 void ImageWriterUtilityClientCall() {
73 content::BrowserThread::PostTask(
74 content::BrowserThread::FILE,
76 base::Bind(&FakeImageWriterClient::Progress
,
77 test_utils_
.GetUtilityClient(),
79 content::BrowserThread::PostTask(
80 content::BrowserThread::FILE,
82 base::Bind(&FakeImageWriterClient::Progress
,
83 test_utils_
.GetUtilityClient(),
85 content::BrowserThread::PostTask(
86 content::BrowserThread::FILE,
88 base::Bind(&FakeImageWriterClient::Progress
,
89 test_utils_
.GetUtilityClient(),
91 content::BrowserThread::PostTask(
92 content::BrowserThread::FILE,
94 base::Bind(&FakeImageWriterClient::Success
,
95 test_utils_
.GetUtilityClient()));
100 image_writer::ImageWriterTestUtils test_utils_
;
103 IN_PROC_BROWSER_TEST_F(ImageWriterPrivateApiTest
, TestListDevices
) {
104 ASSERT_TRUE(RunExtensionTest("image_writer_private/list_devices"))
108 IN_PROC_BROWSER_TEST_F(ImageWriterPrivateApiTest
, TestWriteFromFile
) {
109 FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest(
110 "test_temp", test_utils_
.GetTempDir());
112 base::FilePath
selected_image(test_utils_
.GetImagePath());
113 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
116 #if !defined(OS_CHROMEOS)
117 test_utils_
.GetUtilityClient()->SetWriteCallback(base::Bind(
118 &ImageWriterPrivateApiTest::ImageWriterUtilityClientCall
, this));
119 test_utils_
.GetUtilityClient()->SetVerifyCallback(base::Bind(
120 &ImageWriterPrivateApiTest::ImageWriterUtilityClientCall
, this));
123 ASSERT_TRUE(RunPlatformAppTest("image_writer_private/write_from_file"))
127 } // namespace extensions