summaryrefslogtreecommitdiffstats
path: root/content/browser/fileapi
diff options
context:
space:
mode:
authortyoshino@chromium.org <tyoshino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-25 09:20:43 +0000
committertyoshino@chromium.org <tyoshino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-25 09:20:43 +0000
commita002c33d033f7793f409184b61724be89d3972e8 (patch)
treef7da82189b8a84dc3ed16be8e76c1b482d6c5065 /content/browser/fileapi
parent91b402bb267c28fd2a5b67c336495527a42e55b3 (diff)
downloadchromium_src-a002c33d033f7793f409184b61724be89d3972e8.zip
chromium_src-a002c33d033f7793f409184b61724be89d3972e8.tar.gz
chromium_src-a002c33d033f7793f409184b61724be89d3972e8.tar.bz2
Add a unittest for FileAPIMessageFilter. Tests building an emtpy Blob.
Review URL: https://chromiumcodereview.appspot.com/16961004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@208463 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/fileapi')
-rw-r--r--content/browser/fileapi/fileapi_message_filter.h3
-rw-r--r--content/browser/fileapi/fileapi_message_filter_unittest.cc91
2 files changed, 93 insertions, 1 deletions
diff --git a/content/browser/fileapi/fileapi_message_filter.h b/content/browser/fileapi/fileapi_message_filter.h
index e57d05d..8c09c59 100644
--- a/content/browser/fileapi/fileapi_message_filter.h
+++ b/content/browser/fileapi/fileapi_message_filter.h
@@ -15,6 +15,7 @@
#include "base/id_map.h"
#include "base/platform_file.h"
#include "base/shared_memory.h"
+#include "content/common/content_export.h"
#include "content/public/browser/browser_message_filter.h"
#include "webkit/browser/fileapi/file_system_operation_runner.h"
#include "webkit/common/blob/blob_data.h"
@@ -46,7 +47,7 @@ class ShareableFileReference;
namespace content {
class ChromeBlobStorageContext;
-class FileAPIMessageFilter : public BrowserMessageFilter {
+class CONTENT_EXPORT FileAPIMessageFilter : public BrowserMessageFilter {
public:
// Used by the renderer process host on the UI thread.
FileAPIMessageFilter(
diff --git a/content/browser/fileapi/fileapi_message_filter_unittest.cc b/content/browser/fileapi/fileapi_message_filter_unittest.cc
new file mode 100644
index 0000000..98d8949
--- /dev/null
+++ b/content/browser/fileapi/fileapi_message_filter_unittest.cc
@@ -0,0 +1,91 @@
+// Copyright 2013 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 "content/browser/fileapi/fileapi_message_filter.h"
+
+#include <string>
+#include <vector>
+
+#include "base/memory/ref_counted.h"
+#include "base/message_loop.h"
+#include "content/browser/fileapi/chrome_blob_storage_context.h"
+#include "content/common/fileapi/webblob_messages.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/common/common_param_traits.h"
+#include "content/public/test/mock_render_process_host.h"
+#include "content/public/test/test_browser_context.h"
+#include "content/public/test/test_browser_thread.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/browser/blob/blob_storage_controller.h"
+#include "webkit/browser/fileapi/file_system_context.h"
+#include "webkit/browser/fileapi/mock_file_system_context.h"
+#include "webkit/common/blob/blob_data.h"
+
+namespace content {
+
+class FileAPIMessageFilterTest : public testing::Test {
+ public:
+ FileAPIMessageFilterTest()
+ : io_browser_thread_(BrowserThread::IO, &message_loop_) {
+ }
+
+ protected:
+ virtual void SetUp() OVERRIDE {
+ file_system_context_ =
+ fileapi::CreateFileSystemContextForTesting(NULL, base::FilePath());
+ }
+
+ base::MessageLoop message_loop_;
+ TestBrowserThread io_browser_thread_;
+
+ TestBrowserContext browser_context_;
+ scoped_refptr<fileapi::FileSystemContext> file_system_context_;
+};
+
+TEST_F(FileAPIMessageFilterTest, BuildEmptyBlob) {
+ scoped_refptr<FileAPIMessageFilter> filter(
+ new FileAPIMessageFilter(
+ 0 /* process_id */,
+ browser_context_.GetRequestContext(),
+ file_system_context_.get(),
+ ChromeBlobStorageContext::GetFor(&browser_context_)));
+
+ // Complete initialization.
+ message_loop_.RunUntilIdle();
+
+ webkit_blob::BlobStorageController* controller =
+ ChromeBlobStorageContext::GetFor(&browser_context_)->controller();
+
+ const GURL kUrl("blob:foobar");
+ const GURL kDifferentUrl("blob:barfoo");
+ const std::string kContentType = "fake/type";
+
+ EXPECT_EQ(NULL, controller->GetBlobDataFromUrl(kUrl));
+
+ // Test via OnMessageReceived(const IPC::Message&) which is called by the
+ // channel proxy. Since OnMessageReceived is hidden on FileAPIMessageFilter,
+ // cast it.
+ IPC::ChannelProxy::MessageFilter* casted_filter =
+ static_cast<IPC::ChannelProxy::MessageFilter*>(filter);
+
+ BlobHostMsg_StartBuildingBlob start_message(kUrl);
+ EXPECT_TRUE(casted_filter->OnMessageReceived(start_message));
+
+ // Blob is still being built. Nothing should be returned.
+ EXPECT_EQ(NULL, controller->GetBlobDataFromUrl(kUrl));
+
+ BlobHostMsg_FinishBuildingBlob finish_message(kUrl, kContentType);
+ EXPECT_TRUE(casted_filter->OnMessageReceived(finish_message));
+
+ // Now, Blob is built.
+ webkit_blob::BlobData* blob_data = controller->GetBlobDataFromUrl(kUrl);
+ ASSERT_FALSE(blob_data == NULL);
+ EXPECT_EQ(0U, blob_data->items().size());
+ EXPECT_EQ(kContentType, blob_data->content_type());
+
+ // Nothing should be returned for a URL we didn't use.
+ EXPECT_TRUE(controller->GetBlobDataFromUrl(kDifferentUrl) == NULL);
+}
+
+} // namespace fileapi