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..6e4fdf086803f7e863cf32c33dbf122d6a3c5f08 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. |
jsbell
2014/06/19 21:08:47
Wasn't there a thread about a utility for query st
|
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,50 @@ 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 = |
jsbell
2014/06/19 21:08:47
Might be marginally more readable if the vector<>
cmumford
2014/06/19 22:45:58
I switched to url::ExtractQueryKeyValue, and altho
|
+ 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 |
+ NOTREACHED() << "Unknown param: \"" << it->first << "\""; |
+ } |
+ |
+ 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 { |
+ NOTREACHED() << "Unknown method: \"" << fail_method << "\""; |
+ } |
+ } |
+ |
+ DCHECK(instance_num >= 1); |
jsbell
2014/06/19 21:08:47
DCHECK_GE
cmumford
2014/06/19 22:17:11
Done.
|
+ DCHECK(call_num >= 1); |
jsbell
2014/06/19 21:08:47
DCHECK_GE
cmumford
2014/06/19 22:17:11
Done.
|
+ |
+ 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 +581,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(); |