1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
// 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.
#include "base/message_loop/message_loop.h"
#include "build/build_config.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:
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 = image_writer::kTestFileSize;
expected1->removable = true;
#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 = image_writer::kTestFileSize << 2;
expected2->removable = false;
#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);
linked_ptr<RemovableStorageDevice> device2(expected2);
device_list->data.push_back(device2);
RemovableStorageProvider::SetDeviceListForTesting(device_list);
}
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:
base::MessageLoopForUI message_loop_;
image_writer::ImageWriterTestUtils test_utils_;
};
IN_PROC_BROWSER_TEST_F(ImageWriterPrivateApiTest, TestListDevices) {
ASSERT_TRUE(RunExtensionTest("image_writer_private/list_devices"))
<< 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
|