OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/child/fileapi/webfilewriter_base.h" | 5 #include "content/child/fileapi/webfilewriter_base.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 } | 45 } |
46 | 46 |
47 void reset() { | 47 void reset() { |
48 received_truncate_ = false; | 48 received_truncate_ = false; |
49 received_truncate_path_ = GURL(); | 49 received_truncate_path_ = GURL(); |
50 received_truncate_offset_ = kNoOffset; | 50 received_truncate_offset_ = kNoOffset; |
51 received_write_ = false; | 51 received_write_ = false; |
52 received_write_path_ = GURL(); | 52 received_write_path_ = GURL(); |
53 received_write_offset_ = kNoOffset; | 53 received_write_offset_ = kNoOffset; |
54 received_write_blob_url_ = GURL(); | 54 received_write_blob_url_ = GURL(); |
| 55 received_write_blob_uuid_ = std::string(); |
55 received_cancel_ = false; | 56 received_cancel_ = false; |
56 } | 57 } |
57 | 58 |
58 bool received_truncate_; | 59 bool received_truncate_; |
59 GURL received_truncate_path_; | 60 GURL received_truncate_path_; |
60 int64 received_truncate_offset_; | 61 int64 received_truncate_offset_; |
61 bool received_write_; | 62 bool received_write_; |
62 GURL received_write_path_; | 63 GURL received_write_path_; |
63 GURL received_write_blob_url_; | 64 GURL received_write_blob_url_; |
| 65 std::string received_write_blob_uuid_; |
64 int64 received_write_offset_; | 66 int64 received_write_offset_; |
65 bool received_cancel_; | 67 bool received_cancel_; |
66 | 68 |
67 protected: | 69 protected: |
68 virtual void DoTruncate(const GURL& path, int64 offset) OVERRIDE { | 70 virtual void DoTruncate(const GURL& path, int64 offset) OVERRIDE { |
69 received_truncate_ = true; | 71 received_truncate_ = true; |
70 received_truncate_path_ = path; | 72 received_truncate_path_ = path; |
71 received_truncate_offset_ = offset; | 73 received_truncate_offset_ = offset; |
72 | 74 |
73 if (offset == kBasicFileTruncate_Offset) { | 75 if (offset == kBasicFileTruncate_Offset) { |
74 DidSucceed(); | 76 DidSucceed(); |
75 } else if (offset == kErrorFileTruncate_Offset) { | 77 } else if (offset == kErrorFileTruncate_Offset) { |
76 DidFail(base::PLATFORM_FILE_ERROR_NOT_FOUND); | 78 DidFail(base::PLATFORM_FILE_ERROR_NOT_FOUND); |
77 } else if (offset == kCancelFileTruncate_Offset) { | 79 } else if (offset == kCancelFileTruncate_Offset) { |
78 cancel(); | 80 cancel(); |
79 DidSucceed(); // truncate completion | 81 DidSucceed(); // truncate completion |
80 DidSucceed(); // cancel completion | 82 DidSucceed(); // cancel completion |
81 } else if (offset == kCancelFailedTruncate_Offset) { | 83 } else if (offset == kCancelFailedTruncate_Offset) { |
82 cancel(); | 84 cancel(); |
83 DidFail(base::PLATFORM_FILE_ERROR_NOT_FOUND); // truncate completion | 85 DidFail(base::PLATFORM_FILE_ERROR_NOT_FOUND); // truncate completion |
84 DidSucceed(); // cancel completion | 86 DidSucceed(); // cancel completion |
85 } else { | 87 } else { |
86 FAIL(); | 88 FAIL(); |
87 } | 89 } |
88 } | 90 } |
89 | 91 |
90 virtual void DoWrite(const GURL& path, const GURL& blob_url, | 92 virtual void DoWriteDeprecated( |
91 int64 offset) OVERRIDE { | 93 const GURL& path, const GURL& blob_url, |
| 94 int64 offset) OVERRIDE { |
92 received_write_ = true; | 95 received_write_ = true; |
93 received_write_path_ = path; | 96 received_write_path_ = path; |
94 received_write_offset_ = offset; | 97 received_write_offset_ = offset; |
95 received_write_blob_url_ = blob_url; | 98 received_write_blob_url_ = blob_url; |
96 | 99 |
97 if (offset == kBasicFileWrite_Offset) { | 100 if (offset == kBasicFileWrite_Offset) { |
98 DidWrite(1, true); | 101 DidWrite(1, true); |
99 } else if (offset == kErrorFileWrite_Offset) { | 102 } else if (offset == kErrorFileWrite_Offset) { |
100 DidFail(base::PLATFORM_FILE_ERROR_NOT_FOUND); | 103 DidFail(base::PLATFORM_FILE_ERROR_NOT_FOUND); |
101 } else if (offset == kMultiFileWrite_Offset) { | 104 } else if (offset == kMultiFileWrite_Offset) { |
(...skipping 12 matching lines...) Expand all Loading... |
114 cancel(); | 117 cancel(); |
115 DidWrite(1, false); | 118 DidWrite(1, false); |
116 DidWrite(1, false); | 119 DidWrite(1, false); |
117 DidWrite(1, true); // write completion | 120 DidWrite(1, true); // write completion |
118 DidFail(base::PLATFORM_FILE_ERROR_FAILED); // cancel completion | 121 DidFail(base::PLATFORM_FILE_ERROR_FAILED); // cancel completion |
119 } else { | 122 } else { |
120 FAIL(); | 123 FAIL(); |
121 } | 124 } |
122 } | 125 } |
123 | 126 |
| 127 virtual void DoWrite( |
| 128 const GURL& path, const std::string& blob_uuid, |
| 129 int64 offset) OVERRIDE { |
| 130 received_write_ = true; |
| 131 received_write_path_ = path; |
| 132 received_write_offset_ = offset; |
| 133 received_write_blob_uuid_ = blob_uuid; |
| 134 |
| 135 if (offset == kBasicFileWrite_Offset) { |
| 136 DidWrite(1, true); |
| 137 } else if (offset == kErrorFileWrite_Offset) { |
| 138 DidFail(base::PLATFORM_FILE_ERROR_NOT_FOUND); |
| 139 } else if (offset == kMultiFileWrite_Offset) { |
| 140 DidWrite(1, false); |
| 141 DidWrite(1, false); |
| 142 DidWrite(1, true); |
| 143 } else if (offset == kCancelFileWriteBeforeCompletion_Offset) { |
| 144 DidWrite(1, false); |
| 145 cancel(); |
| 146 DidWrite(1, false); |
| 147 DidWrite(1, false); |
| 148 DidFail(base::PLATFORM_FILE_ERROR_FAILED); // write completion |
| 149 DidSucceed(); // cancel completion |
| 150 } else if (offset == kCancelFileWriteAfterCompletion_Offset) { |
| 151 DidWrite(1, false); |
| 152 cancel(); |
| 153 DidWrite(1, false); |
| 154 DidWrite(1, false); |
| 155 DidWrite(1, true); // write completion |
| 156 DidFail(base::PLATFORM_FILE_ERROR_FAILED); // cancel completion |
| 157 } else { |
| 158 FAIL(); |
| 159 } |
| 160 } |
| 161 |
124 virtual void DoCancel() OVERRIDE { | 162 virtual void DoCancel() OVERRIDE { |
125 received_cancel_ = true; | 163 received_cancel_ = true; |
126 } | 164 } |
127 }; | 165 }; |
128 | 166 |
129 class FileWriterTest : public testing::Test, | 167 class FileWriterTest : public testing::Test, |
130 public WebKit::WebFileWriterClient { | 168 public WebKit::WebFileWriterClient { |
131 public: | 169 public: |
132 FileWriterTest() { | 170 FileWriterTest() { |
133 reset(); | 171 reset(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 int received_did_write_count_; | 221 int received_did_write_count_; |
184 long long received_did_write_bytes_total_; | 222 long long received_did_write_bytes_total_; |
185 bool received_did_write_complete_; | 223 bool received_did_write_complete_; |
186 bool received_did_truncate_; | 224 bool received_did_truncate_; |
187 bool received_did_fail_; | 225 bool received_did_fail_; |
188 WebKit::WebFileError fail_error_received_; | 226 WebKit::WebFileError fail_error_received_; |
189 | 227 |
190 DISALLOW_COPY_AND_ASSIGN(FileWriterTest); | 228 DISALLOW_COPY_AND_ASSIGN(FileWriterTest); |
191 }; | 229 }; |
192 | 230 |
| 231 |
| 232 // TODO(michaeln): crbug/174200, update the tests once blink is migrated. |
| 233 |
193 TEST_F(FileWriterTest, BasicFileWrite) { | 234 TEST_F(FileWriterTest, BasicFileWrite) { |
194 // Call the webkit facing api. | 235 // Call the webkit facing api. |
195 const GURL kBlobUrl("blob://bloburl/"); | 236 const GURL kBlobUrl("blob://bloburl/"); |
196 writer()->write(kBasicFileWrite_Offset, kBlobUrl); | 237 writer()->write(kBasicFileWrite_Offset, kBlobUrl); |
197 | 238 |
198 // Check that the derived class gets called correctly. | 239 // Check that the derived class gets called correctly. |
199 EXPECT_TRUE(testable_writer_->received_write_); | 240 EXPECT_TRUE(testable_writer_->received_write_); |
200 EXPECT_EQ(testable_writer_->received_write_path_, | 241 EXPECT_EQ(testable_writer_->received_write_path_, |
201 mock_path_as_gurl()); | 242 mock_path_as_gurl()); |
202 EXPECT_EQ(kBasicFileWrite_Offset, | 243 EXPECT_EQ(kBasicFileWrite_Offset, |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 | 443 |
403 reset(); | 444 reset(); |
404 delete_in_client_callback_ = true; | 445 delete_in_client_callback_ = true; |
405 writer()->truncate(kErrorFileTruncate_Offset); | 446 writer()->truncate(kErrorFileTruncate_Offset); |
406 EXPECT_FALSE(testable_writer_.get()); | 447 EXPECT_FALSE(testable_writer_.get()); |
407 | 448 |
408 // Not crashing counts as passing. | 449 // Not crashing counts as passing. |
409 } | 450 } |
410 | 451 |
411 } // namespace content | 452 } // namespace content |
OLD | NEW |