summaryrefslogtreecommitdiffstats
path: root/chrome/browser/idbbindingutilities_browsertest.cc
diff options
context:
space:
mode:
authorhans@chromium.org <hans@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-17 12:56:09 +0000
committerhans@chromium.org <hans@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-17 12:56:09 +0000
commitd20e0b986707dd49ae7a2cad347f4e50140ec86e (patch)
treeb0cef7b8dcf072f4640ec9d24b9e546c501df52a /chrome/browser/idbbindingutilities_browsertest.cc
parent7e58a5a1b1a11dd3571127dc952e32fc841a50ad (diff)
downloadchromium_src-d20e0b986707dd49ae7a2cad347f4e50140ec86e.zip
chromium_src-d20e0b986707dd49ae7a2cad347f4e50140ec86e.tar.gz
chromium_src-d20e0b986707dd49ae7a2cad347f4e50140ec86e.tar.bz2
IndexedDB: Allow injection of keys into values via key path.
BUG=70118 TEST=browser_tests Review URL: http://codereview.chromium.org/6529021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75258 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/idbbindingutilities_browsertest.cc')
-rw-r--r--chrome/browser/idbbindingutilities_browsertest.cc116
1 files changed, 89 insertions, 27 deletions
diff --git a/chrome/browser/idbbindingutilities_browsertest.cc b/chrome/browser/idbbindingutilities_browsertest.cc
index 581e736..9d25d17 100644
--- a/chrome/browser/idbbindingutilities_browsertest.cc
+++ b/chrome/browser/idbbindingutilities_browsertest.cc
@@ -98,14 +98,18 @@ class IDBKeyPathHelper : public UtilityProcessHost::Client {
new MessageLoop::QuitTask());
}
- void SetExpected(int expected_id,
- const std::vector<IndexedDBKey>& expected_values,
- bool failed) {
+ void SetExpectedKeys(int expected_id,
+ const std::vector<IndexedDBKey>& expected_keys,
+ bool failed) {
expected_id_ = expected_id;
- expected_values_ = expected_values;
+ expected_keys_ = expected_keys;
value_for_key_path_failed_ = failed;
}
+ void SetExpectedValue(const SerializedScriptValue& expected_value) {
+ expected_value_ = expected_value;
+ }
+
void CheckValuesForKeyPath(
int id, const std::vector<SerializedScriptValue>& serialized_values,
const string16& key_path) {
@@ -123,20 +127,35 @@ class IDBKeyPathHelper : public UtilityProcessHost::Client {
ASSERT_TRUE(ret);
}
+ void CheckInjectValue(const IndexedDBKey& key,
+ const SerializedScriptValue& value,
+ const string16& key_path) {
+ if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ NewRunnableMethod(this, &IDBKeyPathHelper::CheckInjectValue,
+ key, value, key_path));
+ return;
+ }
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ bool ret = utility_process_host_->StartInjectIDBKey(key, value, key_path);
+ ASSERT_TRUE(ret);
+ }
+
// UtilityProcessHost::Client
virtual void OnIDBKeysFromValuesAndKeyPathSucceeded(
int id, const std::vector<IndexedDBKey>& values) {
EXPECT_EQ(expected_id_, id);
EXPECT_FALSE(value_for_key_path_failed_);
- ASSERT_EQ(expected_values_.size(), values.size());
+ ASSERT_EQ(expected_keys_.size(), values.size());
size_t pos = 0;
for (std::vector<IndexedDBKey>::const_iterator i(values.begin());
i != values.end(); ++i, ++pos) {
- ASSERT_EQ(expected_values_[pos].type(), i->type());
+ ASSERT_EQ(expected_keys_[pos].type(), i->type());
if (i->type() == WebKit::WebIDBKey::StringType) {
- ASSERT_EQ(expected_values_[pos].string(), i->string());
+ ASSERT_EQ(expected_keys_[pos].string(), i->string());
} else if (i->type() == WebKit::WebIDBKey::NumberType) {
- ASSERT_EQ(expected_values_[pos].number(), i->number());
+ ASSERT_EQ(expected_keys_[pos].number(), i->number());
}
}
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
@@ -149,11 +168,20 @@ class IDBKeyPathHelper : public UtilityProcessHost::Client {
new MessageLoop::QuitTask());
}
+ virtual void OnInjectIDBKeyFinished(
+ const SerializedScriptValue& new_value) {
+ EXPECT_EQ(expected_value_.data(), new_value.data());
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ new MessageLoop::QuitTask());
+ }
+
+
private:
int expected_id_;
- std::vector<IndexedDBKey> expected_values_;
+ std::vector<IndexedDBKey> expected_keys_;
UtilityProcessHost* utility_process_host_;
bool value_for_key_path_failed_;
+ SerializedScriptValue expected_value_;
};
// This test fixture runs in the UI thread. However, most of the work done by
@@ -175,9 +203,13 @@ class ScopedIDBKeyPathHelper {
ui_test_utils::RunMessageLoop();
}
- void SetExpected(int id, const std::vector<IndexedDBKey>& expected_values,
+ void SetExpectedKeys(int id, const std::vector<IndexedDBKey>& expected_keys,
bool failed) {
- key_path_helper_->SetExpected(id, expected_values, failed);
+ key_path_helper_->SetExpectedKeys(id, expected_keys, failed);
+ }
+
+ void SetExpectedValue(const SerializedScriptValue& expected_value) {
+ key_path_helper_->SetExpectedValue(expected_value);
}
void CheckValuesForKeyPath(
@@ -189,6 +221,13 @@ class ScopedIDBKeyPathHelper {
ui_test_utils::RunMessageLoop();
}
+ void CheckInjectValue(const IndexedDBKey& key,
+ const SerializedScriptValue& value,
+ const string16& key_path) {
+ key_path_helper_->CheckInjectValue(key, value, key_path);
+ ui_test_utils::RunMessageLoop();
+ }
+
private:
scoped_refptr<IDBKeyPathHelper> key_path_helper_;
};
@@ -196,16 +235,16 @@ class ScopedIDBKeyPathHelper {
IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, IDBKeyPathExtract) {
ScopedIDBKeyPathHelper scoped_helper;
const int kId = 7;
- std::vector<IndexedDBKey> expected_values;
+ std::vector<IndexedDBKey> expected_keys;
IndexedDBKey value;
value.SetString(UTF8ToUTF16("zoo"));
- expected_values.push_back(value);
+ expected_keys.push_back(value);
IndexedDBKey invalid_value;
invalid_value.SetInvalid();
- expected_values.push_back(invalid_value);
+ expected_keys.push_back(invalid_value);
- scoped_helper.SetExpected(kId, expected_values, false);
+ scoped_helper.SetExpectedKeys(kId, expected_keys, false);
char16 data[] = {0x0353,0x6f66,0x536f,0x7a03,0x6f6f,0x017b};
std::vector<SerializedScriptValue> serialized_values;
@@ -220,13 +259,13 @@ IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, IDBKeyPathExtract) {
IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, IDBKeyPathPropertyNotAvailable) {
ScopedIDBKeyPathHelper scoped_helper;
const int kId = 7;
- std::vector<IndexedDBKey> expected_values;
+ std::vector<IndexedDBKey> expected_keys;
IndexedDBKey invalid_value;
invalid_value.SetInvalid();
- expected_values.push_back(invalid_value);
- expected_values.push_back(invalid_value);
+ expected_keys.push_back(invalid_value);
+ expected_keys.push_back(invalid_value);
- scoped_helper.SetExpected(kId, expected_values, false);
+ scoped_helper.SetExpectedKeys(kId, expected_keys, false);
char16 data[] = {0x0353,0x6f66,0x536f,0x7a03,0x6f6f,0x017b};
std::vector<SerializedScriptValue> serialized_values;
@@ -241,13 +280,13 @@ IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, IDBKeyPathPropertyNotAvailable) {
IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, IDBKeyPathMultipleCalls) {
ScopedIDBKeyPathHelper scoped_helper;
const int kId = 7;
- std::vector<IndexedDBKey> expected_values;
+ std::vector<IndexedDBKey> expected_keys;
IndexedDBKey invalid_value;
invalid_value.SetInvalid();
- expected_values.push_back(invalid_value);
- expected_values.push_back(invalid_value);
+ expected_keys.push_back(invalid_value);
+ expected_keys.push_back(invalid_value);
- scoped_helper.SetExpected(kId, expected_values, true);
+ scoped_helper.SetExpectedKeys(kId, expected_keys, true);
char16 data[] = {0x0353,0x6f66,0x536f,0x7a03,0x6f6f,0x017b};
std::vector<SerializedScriptValue> serialized_values;
@@ -259,12 +298,35 @@ IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, IDBKeyPathMultipleCalls) {
UTF8ToUTF16("!+Invalid[KeyPath[[["));
// Call again with the Utility process in batch mode and with valid keys.
- expected_values.clear();
+ expected_keys.clear();
IndexedDBKey value;
value.SetString(UTF8ToUTF16("zoo"));
- expected_values.push_back(value);
- expected_values.push_back(invalid_value);
- scoped_helper.SetExpected(kId + 1, expected_values, false);
+ expected_keys.push_back(value);
+ expected_keys.push_back(invalid_value);
+ scoped_helper.SetExpectedKeys(kId + 1, expected_keys, false);
scoped_helper.CheckValuesForKeyPath(kId + 1, serialized_values,
UTF8ToUTF16("foo"));
}
+
+IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, InjectIDBKey) {
+ // {foo: 'zoo'}
+ const char16 data[] = {0x0353,0x6f66,0x536f,0x7a03,0x6f6f,0x017b};
+ SerializedScriptValue value(false, false, string16(data, arraysize(data)));
+ IndexedDBKey key;
+ key.SetString(UTF8ToUTF16("myNewKey"));
+
+ // {foo: 'zoo', bar: 'myNewKey'}
+ const char16 expected_data[] = {0x353, 0x6f66, 0x536f, 0x7a03, 0x6f6f, 0x353,
+ 0x6162, 0x5372, 0x6d08, 0x4e79, 0x7765,
+ 0x654b, 0x7b79, 0x2};
+ SerializedScriptValue expected_value(false, false,
+ string16(expected_data,
+ arraysize(expected_data)));
+
+ ScopedIDBKeyPathHelper scoped_helper;
+ scoped_helper.SetExpectedValue(expected_value);
+ scoped_helper.CheckInjectValue(key, value, UTF8ToUTF16("bar"));
+
+ scoped_helper.SetExpectedValue(SerializedScriptValue()); // Expect null.
+ scoped_helper.CheckInjectValue(key, value, UTF8ToUTF16("bad.key.path"));
+}