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

Side by Side Diff: chrome/browser/idbbindingutilities_browsertest.cc

Issue 6995095: Move UtilityProcessHost to content and move the message sending/dispatching to the clients. This... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/utf_string_conversions.h" 5 #include "base/utf_string_conversions.h"
6 #include "chrome/browser/browser_process.h" 6 #include "chrome/browser/browser_process.h"
7 #include "chrome/browser/utility_process_host.h"
8 #include "chrome/test/in_process_browser_test.h" 7 #include "chrome/test/in_process_browser_test.h"
9 #include "chrome/test/ui_test_utils.h" 8 #include "chrome/test/ui_test_utils.h"
10 #include "content/browser/renderer_host/resource_dispatcher_host.h" 9 #include "content/browser/renderer_host/resource_dispatcher_host.h"
10 #include "content/browser/utility_process_host.h"
11 #include "content/common/indexed_db_key.h" 11 #include "content/common/indexed_db_key.h"
12 #include "content/common/serialized_script_value.h" 12 #include "content/common/serialized_script_value.h"
13 #include "content/common/utility_messages.h"
13 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSerializedScriptVa lue.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSerializedScriptVa lue.h"
16 #include "webkit/glue/idb_bindings.h" 17 #include "webkit/glue/idb_bindings.h"
17 #include "webkit/glue/web_io_operators.h" 18 #include "webkit/glue/web_io_operators.h"
18 19
19 using WebKit::WebSerializedScriptValue; 20 using WebKit::WebSerializedScriptValue;
20 21
21 // Sanity test, check the function call directly outside the sandbox. 22 // Sanity test, check the function call directly outside the sandbox.
22 TEST(IDBKeyPathWithoutSandbox, Value) { 23 TEST(IDBKeyPathWithoutSandbox, Value) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 int id, const std::vector<SerializedScriptValue>& serialized_values, 113 int id, const std::vector<SerializedScriptValue>& serialized_values,
113 const string16& key_path) { 114 const string16& key_path) {
114 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 115 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
115 BrowserThread::PostTask( 116 BrowserThread::PostTask(
116 BrowserThread::IO, FROM_HERE, 117 BrowserThread::IO, FROM_HERE,
117 NewRunnableMethod(this, &IDBKeyPathHelper::CheckValuesForKeyPath, 118 NewRunnableMethod(this, &IDBKeyPathHelper::CheckValuesForKeyPath,
118 id, serialized_values, key_path)); 119 id, serialized_values, key_path));
119 return; 120 return;
120 } 121 }
121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
122 bool ret = 123 bool ret = utility_process_host_->Send(
123 utility_process_host_->StartIDBKeysFromValuesAndKeyPath( 124 new UtilityMsg_IDBKeysFromValuesAndKeyPath(
124 id, serialized_values, key_path); 125 id, serialized_values, key_path));
125 ASSERT_TRUE(ret); 126 ASSERT_TRUE(ret);
126 } 127 }
127 128
128 void CheckInjectValue(const IndexedDBKey& key, 129 void CheckInjectValue(const IndexedDBKey& key,
129 const SerializedScriptValue& value, 130 const SerializedScriptValue& value,
130 const string16& key_path) { 131 const string16& key_path) {
131 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 132 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
132 BrowserThread::PostTask( 133 BrowserThread::PostTask(
133 BrowserThread::IO, FROM_HERE, 134 BrowserThread::IO, FROM_HERE,
134 NewRunnableMethod(this, &IDBKeyPathHelper::CheckInjectValue, 135 NewRunnableMethod(this, &IDBKeyPathHelper::CheckInjectValue,
135 key, value, key_path)); 136 key, value, key_path));
136 return; 137 return;
137 } 138 }
138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 139 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
139 bool ret = utility_process_host_->StartInjectIDBKey(key, value, key_path); 140 bool ret = utility_process_host_->Send(new UtilityMsg_InjectIDBKey(
141 key, value, key_path));
140 ASSERT_TRUE(ret); 142 ASSERT_TRUE(ret);
141 } 143 }
142 144
143 // UtilityProcessHost::Client 145 // UtilityProcessHost::Client
144 virtual void OnIDBKeysFromValuesAndKeyPathSucceeded( 146 bool OnMessageReceived(const IPC::Message& message) {
147 bool handled = true;
148 IPC_BEGIN_MESSAGE_MAP(IDBKeyPathHelper, message)
149 IPC_MESSAGE_HANDLER(UtilityHostMsg_IDBKeysFromValuesAndKeyPath_Succeeded,
150 OnIDBKeysFromValuesAndKeyPathSucceeded)
151 IPC_MESSAGE_HANDLER(UtilityHostMsg_IDBKeysFromValuesAndKeyPath_Failed,
152 OnIDBKeysFromValuesAndKeyPathFailed)
153 IPC_MESSAGE_HANDLER(UtilityHostMsg_InjectIDBKey_Finished,
154 OnInjectIDBKeyFinished)
155 IPC_MESSAGE_UNHANDLED(handled = false)
156 IPC_END_MESSAGE_MAP_EX()
157 return handled;
158 }
159
160 void OnIDBKeysFromValuesAndKeyPathSucceeded(
145 int id, const std::vector<IndexedDBKey>& values) { 161 int id, const std::vector<IndexedDBKey>& values) {
146 EXPECT_EQ(expected_id_, id); 162 EXPECT_EQ(expected_id_, id);
147 EXPECT_FALSE(value_for_key_path_failed_); 163 EXPECT_FALSE(value_for_key_path_failed_);
148 ASSERT_EQ(expected_keys_.size(), values.size()); 164 ASSERT_EQ(expected_keys_.size(), values.size());
149 size_t pos = 0; 165 size_t pos = 0;
150 for (std::vector<IndexedDBKey>::const_iterator i(values.begin()); 166 for (std::vector<IndexedDBKey>::const_iterator i(values.begin());
151 i != values.end(); ++i, ++pos) { 167 i != values.end(); ++i, ++pos) {
152 ASSERT_EQ(expected_keys_[pos].type(), i->type()); 168 ASSERT_EQ(expected_keys_[pos].type(), i->type());
153 if (i->type() == WebKit::WebIDBKey::StringType) { 169 if (i->type() == WebKit::WebIDBKey::StringType) {
154 ASSERT_EQ(expected_keys_[pos].string(), i->string()); 170 ASSERT_EQ(expected_keys_[pos].string(), i->string());
155 } else if (i->type() == WebKit::WebIDBKey::NumberType) { 171 } else if (i->type() == WebKit::WebIDBKey::NumberType) {
156 ASSERT_EQ(expected_keys_[pos].number(), i->number()); 172 ASSERT_EQ(expected_keys_[pos].number(), i->number());
157 } 173 }
158 } 174 }
159 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 175 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
160 new MessageLoop::QuitTask()); 176 new MessageLoop::QuitTask());
161 } 177 }
162 178
163 virtual void OnIDBKeysFromValuesAndKeyPathFailed(int id) { 179 void OnIDBKeysFromValuesAndKeyPathFailed(int id) {
164 EXPECT_TRUE(value_for_key_path_failed_); 180 EXPECT_TRUE(value_for_key_path_failed_);
165 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 181 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
166 new MessageLoop::QuitTask()); 182 new MessageLoop::QuitTask());
167 } 183 }
168 184
169 virtual void OnInjectIDBKeyFinished( 185 void OnInjectIDBKeyFinished(const SerializedScriptValue& new_value) {
170 const SerializedScriptValue& new_value) {
171 EXPECT_EQ(expected_value_.data(), new_value.data()); 186 EXPECT_EQ(expected_value_.data(), new_value.data());
172 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 187 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
173 new MessageLoop::QuitTask()); 188 new MessageLoop::QuitTask());
174 } 189 }
175 190
176 191
177 private: 192 private:
178 int expected_id_; 193 int expected_id_;
179 std::vector<IndexedDBKey> expected_keys_; 194 std::vector<IndexedDBKey> expected_keys_;
180 UtilityProcessHost* utility_process_host_; 195 UtilityProcessHost* utility_process_host_;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 string16(expected_data, 335 string16(expected_data,
321 arraysize(expected_data))); 336 arraysize(expected_data)));
322 337
323 ScopedIDBKeyPathHelper scoped_helper; 338 ScopedIDBKeyPathHelper scoped_helper;
324 scoped_helper.SetExpectedValue(expected_value); 339 scoped_helper.SetExpectedValue(expected_value);
325 scoped_helper.CheckInjectValue(key, value, UTF8ToUTF16("bar")); 340 scoped_helper.CheckInjectValue(key, value, UTF8ToUTF16("bar"));
326 341
327 scoped_helper.SetExpectedValue(SerializedScriptValue()); // Expect null. 342 scoped_helper.SetExpectedValue(SerializedScriptValue()); // Expect null.
328 scoped_helper.CheckInjectValue(key, value, UTF8ToUTF16("bad.key.path")); 343 scoped_helper.CheckInjectValue(key, value, UTF8ToUTF16("bad.key.path"));
329 } 344 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698