OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 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" |
5 #include "chrome/browser/extensions/api/image_writer_private/removable_storage_p
rovider.h" | 8 #include "chrome/browser/extensions/api/image_writer_private/removable_storage_p
rovider.h" |
| 9 #include "chrome/browser/extensions/api/image_writer_private/test_utils.h" |
6 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
7 #include "chrome/common/extensions/api/image_writer_private.h" | 11 #include "chrome/common/extensions/api/image_writer_private.h" |
| 12 #include "content/public/browser/browser_thread.h" |
8 | 13 |
9 namespace extensions { | 14 namespace extensions { |
10 | 15 |
11 using api::image_writer_private::RemovableStorageDevice; | 16 using api::image_writer_private::RemovableStorageDevice; |
| 17 using extensions::image_writer::FakeImageWriterClient; |
12 | 18 |
13 class ImageWriterPrivateApiTest : public ExtensionApiTest { | 19 class ImageWriterPrivateApiTest : public ExtensionApiTest { |
14 public: | 20 public: |
15 virtual void SetUpOnMainThread() OVERRIDE { | 21 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 22 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
| 23 test_utils_.SetUp(true); |
| 24 |
| 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)); |
| 31 |
16 scoped_refptr<StorageDeviceList> device_list(new StorageDeviceList); | 32 scoped_refptr<StorageDeviceList> device_list(new StorageDeviceList); |
17 | 33 |
18 RemovableStorageDevice* expected1 = new RemovableStorageDevice(); | 34 RemovableStorageDevice* expected1 = new RemovableStorageDevice(); |
19 expected1->vendor = "Vendor 1"; | 35 expected1->vendor = "Vendor 1"; |
20 expected1->model = "Model 1"; | 36 expected1->model = "Model 1"; |
21 expected1->capacity = 1 << 20; | 37 expected1->capacity = image_writer::kTestFileSize; |
22 expected1->storage_unit_id = "/test/id/1"; | 38 #if defined(OS_WIN) |
| 39 expected1->storage_unit_id = test_utils_.GetDevicePath().AsUTF8Unsafe(); |
| 40 #else |
| 41 expected1->storage_unit_id = test_utils_.GetDevicePath().value(); |
| 42 #endif |
23 | 43 |
24 RemovableStorageDevice* expected2 = new RemovableStorageDevice(); | 44 RemovableStorageDevice* expected2 = new RemovableStorageDevice(); |
25 expected2->vendor = "Vendor 2"; | 45 expected2->vendor = "Vendor 2"; |
26 expected2->model = "Model 2"; | 46 expected2->model = "Model 2"; |
27 expected2->capacity = 1 << 22; | 47 expected2->capacity = image_writer::kTestFileSize << 2; |
28 expected2->storage_unit_id = "/test/id/2"; | 48 #if defined(OS_WIN) |
| 49 expected2->storage_unit_id = test_utils_.GetDevicePath().AsUTF8Unsafe(); |
| 50 #else |
| 51 expected2->storage_unit_id = test_utils_.GetDevicePath().value(); |
| 52 #endif |
29 | 53 |
30 linked_ptr<RemovableStorageDevice> device1(expected1); | 54 linked_ptr<RemovableStorageDevice> device1(expected1); |
31 device_list->data.push_back(device1); | 55 device_list->data.push_back(device1); |
32 linked_ptr<RemovableStorageDevice> device2(expected2); | 56 linked_ptr<RemovableStorageDevice> device2(expected2); |
33 device_list->data.push_back(device2); | 57 device_list->data.push_back(device2); |
34 | 58 |
35 RemovableStorageProvider::SetDeviceListForTesting(device_list); | 59 RemovableStorageProvider::SetDeviceListForTesting(device_list); |
36 } | 60 } |
37 | 61 |
38 virtual void CleanUpOnMainThread() OVERRIDE { | 62 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { |
| 63 ExtensionApiTest::TearDownInProcessBrowserTestFixture(); |
| 64 test_utils_.TearDown(); |
39 RemovableStorageProvider::ClearDeviceListForTesting(); | 65 RemovableStorageProvider::ClearDeviceListForTesting(); |
| 66 FileSystemChooseEntryFunction::StopSkippingPickerForTest(); |
40 } | 67 } |
| 68 |
| 69 #if !defined(OS_CHROMEOS) |
| 70 void ImageWriterUtilityClientCall() { |
| 71 content::BrowserThread::PostTask( |
| 72 content::BrowserThread::FILE, |
| 73 FROM_HERE, |
| 74 base::Bind(&FakeImageWriterClient::Progress, |
| 75 test_utils_.GetUtilityClient(), |
| 76 0)); |
| 77 content::BrowserThread::PostTask( |
| 78 content::BrowserThread::FILE, |
| 79 FROM_HERE, |
| 80 base::Bind(&FakeImageWriterClient::Progress, |
| 81 test_utils_.GetUtilityClient(), |
| 82 50)); |
| 83 content::BrowserThread::PostTask( |
| 84 content::BrowserThread::FILE, |
| 85 FROM_HERE, |
| 86 base::Bind(&FakeImageWriterClient::Progress, |
| 87 test_utils_.GetUtilityClient(), |
| 88 100)); |
| 89 content::BrowserThread::PostTask( |
| 90 content::BrowserThread::FILE, |
| 91 FROM_HERE, |
| 92 base::Bind(&FakeImageWriterClient::Success, |
| 93 test_utils_.GetUtilityClient())); |
| 94 } |
| 95 #endif |
| 96 |
| 97 protected: |
| 98 image_writer::ImageWriterTestUtils test_utils_; |
41 }; | 99 }; |
42 | 100 |
43 IN_PROC_BROWSER_TEST_F(ImageWriterPrivateApiTest, TestListDevices) { | 101 IN_PROC_BROWSER_TEST_F(ImageWriterPrivateApiTest, TestListDevices) { |
44 ASSERT_TRUE(RunExtensionTest("image_writer_private/list_devices")) | 102 ASSERT_TRUE(RunExtensionTest("image_writer_private/list_devices")) |
45 << message_; | 103 << message_; |
46 } | 104 } |
47 | 105 |
| 106 IN_PROC_BROWSER_TEST_F(ImageWriterPrivateApiTest, TestWriteFromFile) { |
| 107 FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest( |
| 108 "test_temp", test_utils_.GetTempDir()); |
| 109 |
| 110 base::FilePath selected_image(test_utils_.GetImagePath()); |
| 111 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 112 &selected_image); |
| 113 |
| 114 #if !defined(OS_CHROMEOS) |
| 115 test_utils_.GetUtilityClient()->SetWriteCallback(base::Bind( |
| 116 &ImageWriterPrivateApiTest::ImageWriterUtilityClientCall, this)); |
| 117 test_utils_.GetUtilityClient()->SetVerifyCallback(base::Bind( |
| 118 &ImageWriterPrivateApiTest::ImageWriterUtilityClientCall, this)); |
| 119 #endif |
| 120 |
| 121 ASSERT_TRUE(RunPlatformAppTest("image_writer_private/write_from_file")) |
| 122 << message_; |
| 123 } |
| 124 |
48 } // namespace extensions | 125 } // namespace extensions |
OLD | NEW |