Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Unified Diff: content/child/blob_storage/blob_transport_controller_unittest.cc

Issue 1853333003: [BlobAsync] Faster shortcuttin, make renderer controller leaky & alive. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: git cl owners Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/child/blob_storage/blob_transport_controller_unittest.cc
diff --git a/content/child/blob_storage/blob_transport_controller_unittest.cc b/content/child/blob_storage/blob_transport_controller_unittest.cc
index d10d5a0d41818998149e2f1829fba878f929867e..dd9d65fc83a52a3ad1255fced1b3a96e4c5980c5 100644
--- a/content/child/blob_storage/blob_transport_controller_unittest.cc
+++ b/content/child/blob_storage/blob_transport_controller_unittest.cc
@@ -11,8 +11,10 @@
#include "base/test/test_simple_task_runner.h"
#include "base/tuple.h"
#include "content/child/blob_storage/blob_consolidation.h"
+#include "content/child/thread_safe_sender.h"
#include "content/common/fileapi/webblob_messages.h"
#include "ipc/ipc_sender.h"
+#include "ipc/ipc_sync_message_filter.h"
#include "ipc/ipc_test_sink.h"
#include "storage/common/blob_storage/blob_item_bytes_request.h"
#include "storage/common/blob_storage/blob_item_bytes_response.h"
@@ -26,6 +28,29 @@ using storage::DataElement;
namespace content {
namespace {
+class OtherThreadTestSimpleTaskRunner : public base::TestSimpleTaskRunner {
+ public:
+ bool RunsTasksOnCurrentThread() const override { return false; }
+
+ protected:
+ ~OtherThreadTestSimpleTaskRunner() override {}
+};
+
+class BlobTransportControllerTestSender : public ThreadSafeSender {
+ public:
+ explicit BlobTransportControllerTestSender(IPC::TestSink* ipc_sink)
+ : ThreadSafeSender(nullptr, nullptr), ipc_sink_(ipc_sink) {}
+
+ bool Send(IPC::Message* message) override { return ipc_sink_->Send(message); }
+
+ private:
+ ~BlobTransportControllerTestSender() override {}
+
+ IPC::TestSink* ipc_sink_;
+
+ DISALLOW_COPY_AND_ASSIGN(BlobTransportControllerTestSender);
+};
+
BlobItemBytesResponse ResponseWithData(size_t request_number,
const std::string& str) {
BlobItemBytesResponse response(request_number);
@@ -62,9 +87,11 @@ static blink::WebThreadSafeData CreateData(const std::string& str) {
class BlobTransportControllerTest : public testing::Test {
public:
BlobTransportControllerTest()
- : main_thread_runner_(new base::TestSimpleTaskRunner()) {}
+ : io_thread_runner_(new base::TestSimpleTaskRunner()),
+ main_thread_runner_(new OtherThreadTestSimpleTaskRunner()) {}
void SetUp() override {
+ sender_ = new BlobTransportControllerTestSender(&sink_);
BlobTransportController::GetInstance()->ClearForTesting();
}
@@ -72,7 +99,10 @@ class BlobTransportControllerTest : public testing::Test {
BlobTransportController::GetInstance()->ClearForTesting();
}
- scoped_refptr<base::TestSimpleTaskRunner> main_thread_runner_;
+ IPC::TestSink sink_;
+ scoped_refptr<BlobTransportControllerTestSender> sender_;
+ scoped_refptr<base::TestSimpleTaskRunner> io_thread_runner_;
+ scoped_refptr<OtherThreadTestSimpleTaskRunner> main_thread_runner_;
};
TEST_F(BlobTransportControllerTest, Descriptions) {
@@ -213,20 +243,30 @@ TEST_F(BlobTransportControllerTest, TestPublicMethods) {
const std::string kBlobUUID = "uuid";
const std::string kBlob2UUID = "uuid2";
const std::string KRefBlobUUID = "refuuid";
+ const size_t kLargeDataSize = storage::kBlobStorageIPCThresholdBytes + 1;
+ scoped_ptr<char[]> large_data_array(new char[kLargeDataSize]);
BlobTransportController* holder = BlobTransportController::GetInstance();
- IPC::TestSink sink;
BlobConsolidation* consolidation = new BlobConsolidation();
consolidation->AddBlobItem(KRefBlobUUID, 10, 10);
- holder->InitiateBlobTransfer(kBlobUUID, make_scoped_ptr(consolidation), &sink,
- main_thread_runner_);
+ BlobTransportController::InitiateBlobTransfer(
+ kBlobUUID, make_scoped_ptr(consolidation), sender_, io_thread_runner_,
+ main_thread_runner_);
// Check that we have the 'increase ref' pending task.
EXPECT_TRUE(main_thread_runner_->HasPendingTask());
+ // Check that we have the 'transfer' pending task.
+ EXPECT_TRUE(io_thread_runner_->HasPendingTask());
+ // But we've sent the data because we're below the shortcut.
+ EXPECT_TRUE(
+ sink_.GetUniqueMessageMatching(BlobStorageMsg_StartBuildingBlob::ID));
main_thread_runner_->ClearPendingTasks();
// Check that we got the correct start message.
+ EXPECT_FALSE(holder->IsTransporting(kBlobUUID));
+ io_thread_runner_->RunPendingTasks();
+ EXPECT_TRUE(holder->IsTransporting(kBlobUUID));
const IPC::Message* message =
- sink.GetUniqueMessageMatching(BlobStorageMsg_StartBuildingBlob::ID);
+ sink_.GetUniqueMessageMatching(BlobStorageMsg_StartBuildingBlob::ID);
ASSERT_TRUE(message);
std::vector<DataElement> expected;
expected.push_back(MakeBlobElement(KRefBlobUUID, 10, 10));
@@ -243,34 +283,48 @@ TEST_F(BlobTransportControllerTest, TestPublicMethods) {
EXPECT_TRUE(main_thread_runner_->HasPendingTask());
main_thread_runner_->ClearPendingTasks();
message = nullptr;
- sink.ClearMessages();
+ sink_.ClearMessages();
// Check that we can complete the blob, and check that we only update the
// child process ref on the first and last transfer.
consolidation = new BlobConsolidation();
consolidation->AddBlobItem(KRefBlobUUID, 10, 10);
- holder->InitiateBlobTransfer(kBlobUUID, make_scoped_ptr(consolidation), &sink,
- main_thread_runner_);
+ blink::WebThreadSafeData large_data(large_data_array.get(), kLargeDataSize);
+ consolidation->AddDataItem(large_data);
+ BlobTransportController::InitiateBlobTransfer(
+ kBlobUUID, make_scoped_ptr(consolidation), sender_, io_thread_runner_,
+ main_thread_runner_);
EXPECT_TRUE(main_thread_runner_->HasPendingTask());
main_thread_runner_->ClearPendingTasks();
+ EXPECT_TRUE(io_thread_runner_->HasPendingTask());
+ EXPECT_FALSE(
+ sink_.GetUniqueMessageMatching(BlobStorageMsg_StartBuildingBlob::ID));
+ io_thread_runner_->RunPendingTasks();
EXPECT_TRUE(
- sink.GetUniqueMessageMatching(BlobStorageMsg_StartBuildingBlob::ID));
- sink.ClearMessages();
+ sink_.GetUniqueMessageMatching(BlobStorageMsg_StartBuildingBlob::ID));
+ sink_.ClearMessages();
- // Add the second and check that we don't have a task.
+ // Add the second.
BlobConsolidation* consolidation2 = new BlobConsolidation();
consolidation2->AddBlobItem(KRefBlobUUID, 10, 10);
- holder->InitiateBlobTransfer(kBlob2UUID, make_scoped_ptr(consolidation2),
- &sink, main_thread_runner_);
- EXPECT_FALSE(main_thread_runner_->HasPendingTask());
- sink.ClearMessages();
+ BlobTransportController::InitiateBlobTransfer(
+ kBlob2UUID, make_scoped_ptr(consolidation2), sender_, io_thread_runner_,
+ main_thread_runner_);
+ EXPECT_TRUE(main_thread_runner_->HasPendingTask());
+ main_thread_runner_->ClearPendingTasks();
+ sink_.ClearMessages();
+
+ io_thread_runner_->RunPendingTasks();
+ EXPECT_TRUE(holder->IsTransporting(kBlobUUID));
+ EXPECT_TRUE(holder->IsTransporting(kBlob2UUID));
// Finish the first one.
holder->OnDone(kBlobUUID);
EXPECT_FALSE(holder->IsTransporting(kBlobUUID));
- EXPECT_FALSE(main_thread_runner_->HasPendingTask());
+ EXPECT_TRUE(main_thread_runner_->HasPendingTask());
+ main_thread_runner_->ClearPendingTasks();
- // Finish the second one, and verify that we have the task.
+ // Finish the second one.
holder->OnDone(kBlob2UUID);
EXPECT_FALSE(holder->IsTransporting(kBlob2UUID));
EXPECT_TRUE(main_thread_runner_->HasPendingTask());

Powered by Google App Engine
This is Rietveld 408576698