| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
| 7 #include "chrome/test/base/in_process_browser_test.h" | 7 #include "chrome/test/base/in_process_browser_test.h" |
| 8 #include "chrome/test/base/ui_test_utils.h" | 8 #include "chrome/test/base/ui_test_utils.h" |
| 9 #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" | 10 #include "content/browser/utility_process_host_impl.h" |
| 11 #include "content/public/browser/utility_process_host_client.h" |
| 11 #include "content/common/indexed_db/indexed_db_key.h" | 12 #include "content/common/indexed_db/indexed_db_key.h" |
| 12 #include "content/common/utility_messages.h" | 13 #include "content/common/utility_messages.h" |
| 13 #include "content/common/webkitplatformsupport_impl.h" | 14 #include "content/common/webkitplatformsupport_impl.h" |
| 14 #include "content/public/common/serialized_script_value.h" | 15 #include "content/public/common/serialized_script_value.h" |
| 15 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerialize
dScriptValue.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerialize
dScriptValue.h" |
| 19 #include "webkit/glue/idb_bindings.h" | 20 #include "webkit/glue/idb_bindings.h" |
| 20 #include "webkit/glue/web_io_operators.h" | 21 #include "webkit/glue/web_io_operators.h" |
| 21 | 22 |
| 22 using content::BrowserThread; | 23 using content::BrowserThread; |
| 24 using content::UtilityProcessHost; |
| 25 using content::UtilityProcessHostClient; |
| 23 using WebKit::WebSerializedScriptValue; | 26 using WebKit::WebSerializedScriptValue; |
| 24 | 27 |
| 25 // Enables calling WebKit::shutdown no matter where a "return" happens. | 28 // Enables calling WebKit::shutdown no matter where a "return" happens. |
| 26 class ScopedShutdownWebKit { | 29 class ScopedShutdownWebKit { |
| 27 public: | 30 public: |
| 28 ScopedShutdownWebKit() { | 31 ScopedShutdownWebKit() { |
| 29 } | 32 } |
| 30 | 33 |
| 31 ~ScopedShutdownWebKit() { | 34 ~ScopedShutdownWebKit() { |
| 32 WebKit::shutdown(); | 35 WebKit::shutdown(); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 serialized_values, key_path, &values); | 100 serialized_values, key_path, &values); |
| 98 | 101 |
| 99 ASSERT_TRUE(error); | 102 ASSERT_TRUE(error); |
| 100 ASSERT_EQ(size_t(4), values.size()); | 103 ASSERT_EQ(size_t(4), values.size()); |
| 101 ASSERT_EQ(WebKit::WebIDBKey::NullType, values[0].type()); | 104 ASSERT_EQ(WebKit::WebIDBKey::NullType, values[0].type()); |
| 102 ASSERT_EQ(WebKit::WebIDBKey::NullType, values[1].type()); | 105 ASSERT_EQ(WebKit::WebIDBKey::NullType, values[1].type()); |
| 103 ASSERT_EQ(WebKit::WebIDBKey::NullType, values[2].type()); | 106 ASSERT_EQ(WebKit::WebIDBKey::NullType, values[2].type()); |
| 104 ASSERT_EQ(WebKit::WebIDBKey::NullType, values[3].type()); | 107 ASSERT_EQ(WebKit::WebIDBKey::NullType, values[3].type()); |
| 105 } | 108 } |
| 106 | 109 |
| 107 class IDBKeyPathHelper : public UtilityProcessHost::Client { | 110 class IDBKeyPathHelper : public UtilityProcessHostClient { |
| 108 public: | 111 public: |
| 109 IDBKeyPathHelper() | 112 IDBKeyPathHelper() |
| 110 : expected_id_(0), | 113 : expected_id_(0), |
| 111 value_for_key_path_failed_(false) { | 114 value_for_key_path_failed_(false) { |
| 112 } | 115 } |
| 113 | 116 |
| 114 void CreateUtilityProcess() { | 117 void CreateUtilityProcess() { |
| 115 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 118 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 116 BrowserThread::PostTask( | 119 BrowserThread::PostTask( |
| 117 BrowserThread::IO, FROM_HERE, | 120 BrowserThread::IO, FROM_HERE, |
| 118 base::Bind(&IDBKeyPathHelper::CreateUtilityProcess, this)); | 121 base::Bind(&IDBKeyPathHelper::CreateUtilityProcess, this)); |
| 119 return; | 122 return; |
| 120 } | 123 } |
| 121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 122 utility_process_host_ = | 125 utility_process_host_ = |
| 123 (new UtilityProcessHost(this, BrowserThread::IO))->AsWeakPtr(); | 126 (new UtilityProcessHostImpl(this, BrowserThread::IO))->AsWeakPtr(); |
| 124 utility_process_host_->set_use_linux_zygote(true); | 127 utility_process_host_->EnableZygote(); |
| 125 utility_process_host_->StartBatchMode(); | 128 utility_process_host_->StartBatchMode(); |
| 126 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 129 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 127 MessageLoop::QuitClosure()); | 130 MessageLoop::QuitClosure()); |
| 128 } | 131 } |
| 129 | 132 |
| 130 void DestroyUtilityProcess() { | 133 void DestroyUtilityProcess() { |
| 131 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 134 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 132 BrowserThread::PostTask( | 135 BrowserThread::PostTask( |
| 133 BrowserThread::IO, FROM_HERE, | 136 BrowserThread::IO, FROM_HERE, |
| 134 base::Bind(&IDBKeyPathHelper::DestroyUtilityProcess, this)); | 137 base::Bind(&IDBKeyPathHelper::DestroyUtilityProcess, this)); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 base::Bind(&IDBKeyPathHelper::CheckInjectValue, this, key, value, | 183 base::Bind(&IDBKeyPathHelper::CheckInjectValue, this, key, value, |
| 181 key_path)); | 184 key_path)); |
| 182 return; | 185 return; |
| 183 } | 186 } |
| 184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 185 bool ret = utility_process_host_->Send(new UtilityMsg_InjectIDBKey( | 188 bool ret = utility_process_host_->Send(new UtilityMsg_InjectIDBKey( |
| 186 key, value, key_path)); | 189 key, value, key_path)); |
| 187 ASSERT_TRUE(ret); | 190 ASSERT_TRUE(ret); |
| 188 } | 191 } |
| 189 | 192 |
| 190 // UtilityProcessHost::Client | 193 // UtilityProcessHostClient |
| 191 bool OnMessageReceived(const IPC::Message& message) { | 194 bool OnMessageReceived(const IPC::Message& message) { |
| 192 bool msg_is_ok = true; | 195 bool msg_is_ok = true; |
| 193 bool handled = true; | 196 bool handled = true; |
| 194 IPC_BEGIN_MESSAGE_MAP_EX(IDBKeyPathHelper, message, msg_is_ok) | 197 IPC_BEGIN_MESSAGE_MAP_EX(IDBKeyPathHelper, message, msg_is_ok) |
| 195 IPC_MESSAGE_HANDLER(UtilityHostMsg_IDBKeysFromValuesAndKeyPath_Succeeded, | 198 IPC_MESSAGE_HANDLER(UtilityHostMsg_IDBKeysFromValuesAndKeyPath_Succeeded, |
| 196 OnIDBKeysFromValuesAndKeyPathSucceeded) | 199 OnIDBKeysFromValuesAndKeyPathSucceeded) |
| 197 IPC_MESSAGE_HANDLER(UtilityHostMsg_IDBKeysFromValuesAndKeyPath_Failed, | 200 IPC_MESSAGE_HANDLER(UtilityHostMsg_IDBKeysFromValuesAndKeyPath_Failed, |
| 198 OnIDBKeysFromValuesAndKeyPathFailed) | 201 OnIDBKeysFromValuesAndKeyPathFailed) |
| 199 IPC_MESSAGE_HANDLER(UtilityHostMsg_InjectIDBKey_Finished, | 202 IPC_MESSAGE_HANDLER(UtilityHostMsg_InjectIDBKey_Finished, |
| 200 OnInjectIDBKeyFinished) | 203 OnInjectIDBKeyFinished) |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 0x6f6f, 0x013f, 0x0353, 0x6f7a, 0x3f6f, | 429 0x6f6f, 0x013f, 0x0353, 0x6f7a, 0x3f6f, |
| 427 0x5301, 0x6203, 0x7261, 0x013f, 0x3f6f, | 430 0x5301, 0x6203, 0x7261, 0x013f, 0x3f6f, |
| 428 0x5302, 0x6203, 0x7a61, 0x023f, 0x0853, | 431 0x5302, 0x6203, 0x7a61, 0x023f, 0x0853, |
| 429 0x796d, 0x654e, 0x4b77, 0x7965, 0x017b, | 432 0x796d, 0x654e, 0x4b77, 0x7965, 0x017b, |
| 430 0x027b}; | 433 0x027b}; |
| 431 content::SerializedScriptValue expected_value2( | 434 content::SerializedScriptValue expected_value2( |
| 432 false, false, string16(expected_data2, arraysize(expected_data2))); | 435 false, false, string16(expected_data2, arraysize(expected_data2))); |
| 433 scoped_helper.SetExpectedValue(expected_value2); | 436 scoped_helper.SetExpectedValue(expected_value2); |
| 434 scoped_helper.CheckInjectValue(key, value, UTF8ToUTF16("bar.baz")); | 437 scoped_helper.CheckInjectValue(key, value, UTF8ToUTF16("bar.baz")); |
| 435 } | 438 } |
| OLD | NEW |