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

Unified Diff: content/browser/indexed_db/indexed_db_browsertest.cc

Issue 334303002: Using a mock LevelDBTransaction for corruption tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Factored the new browser IDB content test objects into own file. Created 6 years, 6 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/browser/indexed_db/indexed_db_browsertest.cc
diff --git a/content/browser/indexed_db/indexed_db_browsertest.cc b/content/browser/indexed_db/indexed_db_browsertest.cc
index 0d62a1336749cddc3cdb854f2c44e8292fe0cdc2..a73f2dd9f77bfcd0c326ae025699cd6463a5f3f4 100644
--- a/content/browser/indexed_db/indexed_db_browsertest.cc
+++ b/content/browser/indexed_db/indexed_db_browsertest.cc
@@ -8,11 +8,15 @@
#include "base/files/file.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_path.h"
+#include "base/lazy_instance.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop.h"
+#include "base/strings/string_split.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/thread_test_helper.h"
#include "content/browser/browser_main_loop.h"
+#include "content/browser/indexed_db/indexed_db_browsertest_mock_factory.h"
+#include "content/browser/indexed_db/indexed_db_class_factory.h"
#include "content/browser/indexed_db/indexed_db_context_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/browser_context.h"
@@ -45,6 +49,25 @@ class IndexedDBBrowserTest : public ContentBrowserTest {
public:
IndexedDBBrowserTest() : disk_usage_(-1) {}
+ virtual void SetUp() OVERRIDE {
+ GetTestClassFactory()->Reset();
+ IndexedDBClassFactory::SetIndexedDBClassFactoryGetter(GetIDBClassFactory);
+ ContentBrowserTest::SetUp();
+ }
+
+ virtual void TearDown() OVERRIDE {
+ IndexedDBClassFactory::SetIndexedDBClassFactoryGetter(NULL);
+ ContentBrowserTest::TearDown();
+ }
+
+ void FailOperation(FailClass failure_class,
+ FailMethod failure_method,
+ int fail_on_instance_num,
+ int fail_on_call_num) {
+ GetTestClassFactory()->FailOperation(
+ failure_class, failure_method, fail_on_instance_num, fail_on_call_num);
+ }
+
void SimpleTest(const GURL& test_url, bool incognito = false) {
// The test page will perform tests on IndexedDB, then navigate to either
// a #pass or #fail ref.
@@ -127,6 +150,16 @@ class IndexedDBBrowserTest : public ContentBrowserTest {
}
private:
+ static IndexedDBBrowserTestClassFactory* GetTestClassFactory() {
+ static ::base::LazyInstance<IndexedDBBrowserTestClassFactory>::Leaky
+ s_factory = LAZY_INSTANCE_INITIALIZER;
+ return s_factory.Pointer();
+ }
+
+ static IndexedDBClassFactory* GetIDBClassFactory() {
+ return GetTestClassFactory();
+ }
+
virtual void DidGetDiskUsage(int64 bytes) {
EXPECT_GT(bytes, 0);
disk_usage_ = bytes;
@@ -442,8 +475,8 @@ static scoped_ptr<net::test_server::HttpResponse> CorruptDBRequestHandler(
IndexedDBContextImpl* context,
const GURL& origin_url,
const std::string& path,
+ IndexedDBBrowserTest* test,
const net::test_server::HttpRequest& request) {
-
std::string request_path;
if (path.find(s_corrupt_db_test_prefix) != std::string::npos)
request_path = request.relative_url.substr(s_corrupt_db_test_prefix.size());
@@ -452,10 +485,12 @@ static scoped_ptr<net::test_server::HttpResponse> CorruptDBRequestHandler(
// Remove the query string if present.
std::string request_query;
+ std::vector<std::pair<std::string, std::string> > query_params;
size_t query_pos = request_path.find('?');
if (query_pos != std::string::npos) {
request_query = request_path.substr(query_pos + 1);
request_path = request_path.substr(0, query_pos);
+ base::SplitStringIntoKeyValuePairs(request_query, '=', '&', &query_params);
}
if (request_path == "corruptdb" && !request_query.empty()) {
@@ -472,6 +507,53 @@ static scoped_ptr<net::test_server::HttpResponse> CorruptDBRequestHandler(
new net::test_server::BasicHttpResponse);
http_response->set_code(net::HTTP_OK);
return http_response.PassAs<net::test_server::HttpResponse>();
+ } else if (request_path == "fail" && !query_params.empty()) {
+ FailClass failure_class = FAIL_CLASS_NOTHING;
+ FailMethod failure_method = FAIL_METHOD_NOTHING;
+ int instance_num = 1;
+ int call_num = 1;
+ std::string fail_class;
+ std::string fail_method;
+
+ for (std::vector<std::pair<std::string, std::string> >::iterator it =
+ query_params.begin();
+ it != query_params.end();
+ it++) {
+ if (it->first == "method")
+ fail_method = it->second;
+ else if (it->first == "class")
+ fail_class = it->second;
+ else if (it->first == "instNum")
+ instance_num = atoi(it->second.c_str());
+ else if (it->first == "callNum")
+ call_num = atoi(it->second.c_str());
+ else {
jsbell 2014/06/18 17:03:08 Nit: If any if/elseif/else branch has braces, all
+ VLOG(0) << "Unknown param: \"" << it->first << '"';
+ NOTREACHED();
jsbell 2014/06/18 17:03:08 Just `NOTREACHED() << message` ? (And then it can
cmumford 2014/06/18 18:06:44 Done.
+ }
+ }
+
+ if (fail_class == "LevelDBTransaction") {
+ failure_class = FAIL_CLASS_LEVELDB_TRANSACTION;
+ if (fail_method == "Get")
+ failure_method = FAIL_METHOD_GET;
+ else if (fail_method == "Commit")
+ failure_method = FAIL_METHOD_COMMIT;
+ else {
jsbell 2014/06/18 17:03:08 Ditto.
+ VLOG(0) << "Unknown method: \"" << fail_method << "\"";
+ NOTREACHED();
jsbell 2014/06/18 17:03:08 NOTREACHED() << ... ?
cmumford 2014/06/18 18:06:44 Done.
+ }
+ }
+
+ DCHECK(instance_num >= 1);
+ DCHECK(call_num >= 1);
+
+ test->FailOperation(failure_class, failure_method, instance_num, call_num);
+
+ scoped_ptr<net::test_server::BasicHttpResponse> http_response(
+ new net::test_server::BasicHttpResponse);
+ http_response->set_code(net::HTTP_OK);
+ return http_response.PassAs<net::test_server::HttpResponse>();
}
// A request for a test resource
@@ -502,7 +584,8 @@ IN_PROC_BROWSER_TEST_P(IndexedDBBrowserCorruptionTest,
base::Bind(&CorruptDBRequestHandler,
base::ConstRef(GetContext()),
origin_url,
- s_corrupt_db_test_prefix));
+ s_corrupt_db_test_prefix,
+ this));
std::string test_file = s_corrupt_db_test_prefix +
"corrupted_open_db_detection.html#" + GetParam();

Powered by Google App Engine
This is Rietveld 408576698