| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <deque> | 5 #include <deque> |
| 6 #include <limits> | 6 #include <limits> |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/memory/scoped_callback_factory.h" | |
| 12 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 13 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 14 #include "base/platform_file.h" | 13 #include "base/platform_file.h" |
| 15 #include "base/scoped_temp_dir.h" | 14 #include "base/scoped_temp_dir.h" |
| 16 #include "base/task.h" | 15 #include "base/task.h" |
| 17 #include "webkit/plugins/ppapi/mock_plugin_delegate.h" | 16 #include "webkit/plugins/ppapi/mock_plugin_delegate.h" |
| 18 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 17 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 19 #include "webkit/plugins/ppapi/ppapi_unittest.h" | 18 #include "webkit/plugins/ppapi/ppapi_unittest.h" |
| 20 #include "webkit/plugins/ppapi/quota_file_io.h" | 19 #include "webkit/plugins/ppapi/quota_file_io.h" |
| 21 | 20 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 int will_update_count_; | 77 int will_update_count_; |
| 79 GURL file_path_; | 78 GURL file_path_; |
| 80 scoped_refptr<MessageLoopProxy> file_thread_; | 79 scoped_refptr<MessageLoopProxy> file_thread_; |
| 81 base::WeakPtrFactory<QuotaMockPluginDelegate> weak_factory_; | 80 base::WeakPtrFactory<QuotaMockPluginDelegate> weak_factory_; |
| 82 }; | 81 }; |
| 83 } // namespace | 82 } // namespace |
| 84 | 83 |
| 85 class QuotaFileIOTest : public PpapiUnittest { | 84 class QuotaFileIOTest : public PpapiUnittest { |
| 86 public: | 85 public: |
| 87 QuotaFileIOTest() | 86 QuotaFileIOTest() |
| 88 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)), | 87 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {} |
| 89 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {} | |
| 90 | 88 |
| 91 virtual void SetUp() OVERRIDE { | 89 virtual void SetUp() OVERRIDE { |
| 92 PpapiUnittest::SetUp(); | 90 PpapiUnittest::SetUp(); |
| 93 ASSERT_TRUE(dir_.CreateUniqueTempDir()); | 91 ASSERT_TRUE(dir_.CreateUniqueTempDir()); |
| 94 FilePath path; | 92 FilePath path; |
| 95 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(dir_.path(), &path)); | 93 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(dir_.path(), &path)); |
| 96 int file_flags = base::PLATFORM_FILE_OPEN | | 94 int file_flags = base::PLATFORM_FILE_OPEN | |
| 97 base::PLATFORM_FILE_READ | | 95 base::PLATFORM_FILE_READ | |
| 98 base::PLATFORM_FILE_WRITE | | 96 base::PLATFORM_FILE_WRITE | |
| 99 base::PLATFORM_FILE_WRITE_ATTRIBUTES; | 97 base::PLATFORM_FILE_WRITE_ATTRIBUTES; |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 void SetPlatformFileSize(int64_t length) { | 421 void SetPlatformFileSize(int64_t length) { |
| 424 EXPECT_TRUE(base::TruncatePlatformFile(file_, length)); | 422 EXPECT_TRUE(base::TruncatePlatformFile(file_, length)); |
| 425 } | 423 } |
| 426 | 424 |
| 427 private: | 425 private: |
| 428 ScopedTempDir dir_; | 426 ScopedTempDir dir_; |
| 429 PlatformFile file_; | 427 PlatformFile file_; |
| 430 scoped_ptr<QuotaFileIO> quota_file_io_; | 428 scoped_ptr<QuotaFileIO> quota_file_io_; |
| 431 std::deque<int> bytes_written_; | 429 std::deque<int> bytes_written_; |
| 432 std::deque<PlatformFileError> status_; | 430 std::deque<PlatformFileError> status_; |
| 433 base::ScopedCallbackFactory<QuotaFileIOTest> callback_factory_; | |
| 434 base::WeakPtrFactory<QuotaFileIOTest> weak_factory_; | 431 base::WeakPtrFactory<QuotaFileIOTest> weak_factory_; |
| 435 }; | 432 }; |
| 436 | 433 |
| 437 TEST_F(QuotaFileIOTest, Write) { | 434 TEST_F(QuotaFileIOTest, Write) { |
| 438 WriteTestBody(false); | 435 WriteTestBody(false); |
| 439 } | 436 } |
| 440 | 437 |
| 441 TEST_F(QuotaFileIOTest, WillWrite) { | 438 TEST_F(QuotaFileIOTest, WillWrite) { |
| 442 WriteTestBody(true); | 439 WriteTestBody(true); |
| 443 } | 440 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 pop_result(); | 491 pop_result(); |
| 495 | 492 |
| 496 EXPECT_EQ(22 - 15, quota_plugin_delegate()->available_space()); | 493 EXPECT_EQ(22 - 15, quota_plugin_delegate()->available_space()); |
| 497 EXPECT_EQ(15, GetPlatformFileSize()); | 494 EXPECT_EQ(15, GetPlatformFileSize()); |
| 498 ReadPlatformFile(&read_buffer); | 495 ReadPlatformFile(&read_buffer); |
| 499 EXPECT_EQ("123355559012345", read_buffer); | 496 EXPECT_EQ("123355559012345", read_buffer); |
| 500 } | 497 } |
| 501 | 498 |
| 502 } // namespace ppapi | 499 } // namespace ppapi |
| 503 } // namespace webkit | 500 } // namespace webkit |
| OLD | NEW |