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

Unified Diff: chrome/browser/nacl_host/pnacl_translation_cache_unittest.cc

Issue 16232011: Add PNaCl translation cache based on Chrome disk_cache (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win build, disable_nacl=1, clang build Created 7 years, 7 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: chrome/browser/nacl_host/pnacl_translation_cache_unittest.cc
diff --git a/chrome/browser/nacl_host/pnacl_translation_cache_unittest.cc b/chrome/browser/nacl_host/pnacl_translation_cache_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..68a10204891cd58019c0bce7aded9ae747e3acaf
--- /dev/null
+++ b/chrome/browser/nacl_host/pnacl_translation_cache_unittest.cc
@@ -0,0 +1,78 @@
+// Copyright (c) 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 "chrome/browser/nacl_host/pnacl_translation_cache.h"
+
+#include "base/files/file_path.h"
+#include "base/files/scoped_temp_dir.h"
+#include "base/message_loop.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/test/test_browser_thread.h"
+#include "net/base/test_completion_callback.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using content::BrowserThread;
+
+namespace pnacl_cache {
+
+class PNaClTranslationCacheTest : public testing::Test {
+ protected:
+ PNaClTranslationCacheTest()
+ : cache_thread_(BrowserThread::CACHE, &message_loop_),
+ io_thread_(BrowserThread::IO, &message_loop_) {}
+ virtual ~PNaClTranslationCacheTest() {}
+ virtual void SetUp() { cache_ = new PNaClTranslationCache(); }
+ virtual void TearDown() { delete cache_; }
+
+ protected:
+ PNaClTranslationCache* cache_;
+ base::MessageLoopForIO message_loop_;
+ content::TestBrowserThread cache_thread_;
+ content::TestBrowserThread io_thread_;
+};
+
+TEST_F(PNaClTranslationCacheTest, StoreOneInMem) {
+ net::TestCompletionCallback init_cb;
+ int rv = cache_->InitCache(base::FilePath(), true, init_cb.callback());
+ EXPECT_EQ(net::OK, rv);
+ ASSERT_EQ(net::OK, init_cb.GetResult(rv));
+ net::TestCompletionCallback store_cb;
+ EXPECT_EQ(0, cache_->Size());
+ cache_->StoreNexe("1", "a", store_cb.callback());
+ // Using ERR_IO_PENDING here causes the callback to wait for the result
+ // which should be harmless even if it returns OK immediately. This is because
+ // we don't plumb the intermediate writing stages all the way out.
+ EXPECT_EQ(net::OK, store_cb.GetResult(net::ERR_IO_PENDING));
+ EXPECT_EQ(1, cache_->Size());
+}
+
+TEST_F(PNaClTranslationCacheTest, StoreOneOnDisk) {
+ base::ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+ net::TestCompletionCallback init_cb;
+ int rv = cache_->InitCache(temp_dir.path(), false, init_cb.callback());
+ EXPECT_TRUE(rv);
+ ASSERT_EQ(net::OK, init_cb.GetResult(rv));
+ EXPECT_EQ(0, cache_->Size());
+ net::TestCompletionCallback store_cb;
+ cache_->StoreNexe("1", "a", store_cb.callback());
+ EXPECT_EQ(net::OK, store_cb.GetResult(net::ERR_IO_PENDING));
+ EXPECT_EQ(1, cache_->Size());
+}
+
+TEST_F(PNaClTranslationCacheTest, InMemSizeLimit) {
+ net::TestCompletionCallback init_cb;
+ bool rv = cache_->InitCache(base::FilePath(), true, init_cb.callback());
+ EXPECT_EQ(rv, net::OK);
+ ASSERT_EQ(init_cb.GetResult(rv), net::OK);
+ EXPECT_EQ(cache_->Size(), 0);
+ std::string large_buffer(kMaxMemCacheSize + 1, 'a');
+ net::TestCompletionCallback store_cb;
+ cache_->StoreNexe("1", large_buffer, store_cb.callback());
+ EXPECT_EQ(net::ERR_FAILED, store_cb.GetResult(net::ERR_IO_PENDING));
+ // Why does the backend still return 1 for the size here?
+ //EXPECT_EQ(0, cache_->Size());
jvoung (off chromium) 2013/05/31 01:12:14 It only hits an error after it's created the entry
Derek Schuff 2013/05/31 23:15:31 OK. Now we do doom the entry in case of an error,
jvoung (off chromium) 2013/06/01 00:48:41 Does the EXPECT_EQ(0, cache_->Size()) work, or doe
+}
+
+} // namespace nacl_cache

Powered by Google App Engine
This is Rietveld 408576698