| OLD | NEW |
| 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/bind.h" |
| 5 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
| 6 #include "chrome/test/base/in_process_browser_test.h" | 7 #include "chrome/test/base/in_process_browser_test.h" |
| 7 #include "chrome/test/base/ui_test_utils.h" | 8 #include "chrome/test/base/ui_test_utils.h" |
| 8 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 9 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
| 9 #include "content/browser/utility_process_host.h" | 10 #include "content/browser/utility_process_host.h" |
| 10 #include "content/common/indexed_db_key.h" | 11 #include "content/common/indexed_db_key.h" |
| 11 #include "content/common/utility_messages.h" | 12 #include "content/common/utility_messages.h" |
| 12 #include "content/common/webkitplatformsupport_impl.h" | 13 #include "content/common/webkitplatformsupport_impl.h" |
| 13 #include "content/public/common/serialized_script_value.h" | 14 #include "content/public/common/serialized_script_value.h" |
| 14 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 IDBKeyPathHelper() | 86 IDBKeyPathHelper() |
| 86 : expected_id_(0), | 87 : expected_id_(0), |
| 87 utility_process_host_(NULL), | 88 utility_process_host_(NULL), |
| 88 value_for_key_path_failed_(false) { | 89 value_for_key_path_failed_(false) { |
| 89 } | 90 } |
| 90 | 91 |
| 91 void CreateUtilityProcess() { | 92 void CreateUtilityProcess() { |
| 92 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 93 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 93 BrowserThread::PostTask( | 94 BrowserThread::PostTask( |
| 94 BrowserThread::IO, FROM_HERE, | 95 BrowserThread::IO, FROM_HERE, |
| 95 NewRunnableMethod(this, &IDBKeyPathHelper::CreateUtilityProcess)); | 96 base::Bind(&IDBKeyPathHelper::CreateUtilityProcess, this)); |
| 96 return; | 97 return; |
| 97 } | 98 } |
| 98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 99 utility_process_host_ = | 100 utility_process_host_ = |
| 100 new UtilityProcessHost(this, BrowserThread::IO); | 101 new UtilityProcessHost(this, BrowserThread::IO); |
| 101 utility_process_host_->StartBatchMode(); | 102 utility_process_host_->StartBatchMode(); |
| 102 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 103 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 103 new MessageLoop::QuitTask()); | 104 new MessageLoop::QuitTask()); |
| 104 } | 105 } |
| 105 | 106 |
| 106 void DestroyUtilityProcess() { | 107 void DestroyUtilityProcess() { |
| 107 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 108 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 108 BrowserThread::PostTask( | 109 BrowserThread::PostTask( |
| 109 BrowserThread::IO, FROM_HERE, | 110 BrowserThread::IO, FROM_HERE, |
| 110 NewRunnableMethod(this, &IDBKeyPathHelper::DestroyUtilityProcess)); | 111 base::Bind(&IDBKeyPathHelper::DestroyUtilityProcess, this)); |
| 111 return; | 112 return; |
| 112 } | 113 } |
| 113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 114 utility_process_host_->EndBatchMode(); | 115 utility_process_host_->EndBatchMode(); |
| 115 utility_process_host_ = NULL; | 116 utility_process_host_ = NULL; |
| 116 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 117 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 117 new MessageLoop::QuitTask()); | 118 new MessageLoop::QuitTask()); |
| 118 } | 119 } |
| 119 | 120 |
| 120 void SetExpectedKeys(int expected_id, | 121 void SetExpectedKeys(int expected_id, |
| 121 const std::vector<IndexedDBKey>& expected_keys, | 122 const std::vector<IndexedDBKey>& expected_keys, |
| 122 bool failed) { | 123 bool failed) { |
| 123 expected_id_ = expected_id; | 124 expected_id_ = expected_id; |
| 124 expected_keys_ = expected_keys; | 125 expected_keys_ = expected_keys; |
| 125 value_for_key_path_failed_ = failed; | 126 value_for_key_path_failed_ = failed; |
| 126 } | 127 } |
| 127 | 128 |
| 128 void SetExpectedValue(const content::SerializedScriptValue& expected_value) { | 129 void SetExpectedValue(const content::SerializedScriptValue& expected_value) { |
| 129 expected_value_ = expected_value; | 130 expected_value_ = expected_value; |
| 130 } | 131 } |
| 131 | 132 |
| 132 void CheckValuesForKeyPath( | 133 void CheckValuesForKeyPath( |
| 133 int id, | 134 int id, |
| 134 const std::vector<content::SerializedScriptValue>& serialized_values, | 135 const std::vector<content::SerializedScriptValue>& serialized_values, |
| 135 const string16& key_path) { | 136 const string16& key_path) { |
| 136 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 137 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 137 BrowserThread::PostTask( | 138 BrowserThread::PostTask( |
| 138 BrowserThread::IO, FROM_HERE, | 139 BrowserThread::IO, FROM_HERE, |
| 139 NewRunnableMethod(this, &IDBKeyPathHelper::CheckValuesForKeyPath, | 140 base::Bind(&IDBKeyPathHelper::CheckValuesForKeyPath, this, id, |
| 140 id, serialized_values, key_path)); | 141 serialized_values, key_path)); |
| 141 return; | 142 return; |
| 142 } | 143 } |
| 143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 144 bool ret = utility_process_host_->Send( | 145 bool ret = utility_process_host_->Send( |
| 145 new UtilityMsg_IDBKeysFromValuesAndKeyPath( | 146 new UtilityMsg_IDBKeysFromValuesAndKeyPath( |
| 146 id, serialized_values, key_path)); | 147 id, serialized_values, key_path)); |
| 147 ASSERT_TRUE(ret); | 148 ASSERT_TRUE(ret); |
| 148 } | 149 } |
| 149 | 150 |
| 150 void CheckInjectValue(const IndexedDBKey& key, | 151 void CheckInjectValue(const IndexedDBKey& key, |
| 151 const content::SerializedScriptValue& value, | 152 const content::SerializedScriptValue& value, |
| 152 const string16& key_path) { | 153 const string16& key_path) { |
| 153 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 154 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 154 BrowserThread::PostTask( | 155 BrowserThread::PostTask( |
| 155 BrowserThread::IO, FROM_HERE, | 156 BrowserThread::IO, FROM_HERE, |
| 156 NewRunnableMethod(this, &IDBKeyPathHelper::CheckInjectValue, | 157 base::Bind(&IDBKeyPathHelper::CheckInjectValue, this, key, value, |
| 157 key, value, key_path)); | 158 key_path)); |
| 158 return; | 159 return; |
| 159 } | 160 } |
| 160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 161 bool ret = utility_process_host_->Send(new UtilityMsg_InjectIDBKey( | 162 bool ret = utility_process_host_->Send(new UtilityMsg_InjectIDBKey( |
| 162 key, value, key_path)); | 163 key, value, key_path)); |
| 163 ASSERT_TRUE(ret); | 164 ASSERT_TRUE(ret); |
| 164 } | 165 } |
| 165 | 166 |
| 166 // UtilityProcessHost::Client | 167 // UtilityProcessHost::Client |
| 167 bool OnMessageReceived(const IPC::Message& message) { | 168 bool OnMessageReceived(const IPC::Message& message) { |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 ScopedIDBKeyPathHelper scoped_helper; | 362 ScopedIDBKeyPathHelper scoped_helper; |
| 362 scoped_helper.SetExpectedValue(expected_value); | 363 scoped_helper.SetExpectedValue(expected_value); |
| 363 // TODO(lukezarko@gmail.com): re-enable this after the changes described at | 364 // TODO(lukezarko@gmail.com): re-enable this after the changes described at |
| 364 // https://bugs.webkit.org/show_bug.cgi?id=63481 land. | 365 // https://bugs.webkit.org/show_bug.cgi?id=63481 land. |
| 365 // scoped_helper.CheckInjectValue(key, value, UTF8ToUTF16("bar")); | 366 // scoped_helper.CheckInjectValue(key, value, UTF8ToUTF16("bar")); |
| 366 | 367 |
| 367 // Expect null. | 368 // Expect null. |
| 368 scoped_helper.SetExpectedValue(content::SerializedScriptValue()); | 369 scoped_helper.SetExpectedValue(content::SerializedScriptValue()); |
| 369 scoped_helper.CheckInjectValue(key, value, UTF8ToUTF16("bad.key.path")); | 370 scoped_helper.CheckInjectValue(key, value, UTF8ToUTF16("bad.key.path")); |
| 370 } | 371 } |
| OLD | NEW |