| 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.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 ASSERT_TRUE(error); | 79 ASSERT_TRUE(error); |
| 80 ASSERT_EQ(size_t(2), values.size()); | 80 ASSERT_EQ(size_t(2), values.size()); |
| 81 ASSERT_EQ(WebKit::WebIDBKey::InvalidType, values[0].type()); | 81 ASSERT_EQ(WebKit::WebIDBKey::InvalidType, values[0].type()); |
| 82 ASSERT_EQ(WebKit::WebIDBKey::InvalidType, values[1].type()); | 82 ASSERT_EQ(WebKit::WebIDBKey::InvalidType, values[1].type()); |
| 83 } | 83 } |
| 84 | 84 |
| 85 class IDBKeyPathHelper : public UtilityProcessHost::Client { | 85 class IDBKeyPathHelper : public UtilityProcessHost::Client { |
| 86 public: | 86 public: |
| 87 IDBKeyPathHelper() | 87 IDBKeyPathHelper() |
| 88 : expected_id_(0), | 88 : expected_id_(0), |
| 89 utility_process_host_(NULL), | |
| 90 value_for_key_path_failed_(false) { | 89 value_for_key_path_failed_(false) { |
| 91 } | 90 } |
| 92 | 91 |
| 93 void CreateUtilityProcess() { | 92 void CreateUtilityProcess() { |
| 94 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 93 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 95 BrowserThread::PostTask( | 94 BrowserThread::PostTask( |
| 96 BrowserThread::IO, FROM_HERE, | 95 BrowserThread::IO, FROM_HERE, |
| 97 base::Bind(&IDBKeyPathHelper::CreateUtilityProcess, this)); | 96 base::Bind(&IDBKeyPathHelper::CreateUtilityProcess, this)); |
| 98 return; | 97 return; |
| 99 } | 98 } |
| 100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 101 utility_process_host_ = | 100 utility_process_host_ = |
| 102 new UtilityProcessHost(this, BrowserThread::IO); | 101 (new UtilityProcessHost(this, BrowserThread::IO))->AsWeakPtr(); |
| 103 utility_process_host_->set_use_linux_zygote(true); | 102 utility_process_host_->set_use_linux_zygote(true); |
| 104 utility_process_host_->StartBatchMode(); | 103 utility_process_host_->StartBatchMode(); |
| 105 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 104 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 106 MessageLoop::QuitClosure()); | 105 MessageLoop::QuitClosure()); |
| 107 } | 106 } |
| 108 | 107 |
| 109 void DestroyUtilityProcess() { | 108 void DestroyUtilityProcess() { |
| 110 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 109 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 111 BrowserThread::PostTask( | 110 BrowserThread::PostTask( |
| 112 BrowserThread::IO, FROM_HERE, | 111 BrowserThread::IO, FROM_HERE, |
| 113 base::Bind(&IDBKeyPathHelper::DestroyUtilityProcess, this)); | 112 base::Bind(&IDBKeyPathHelper::DestroyUtilityProcess, this)); |
| 114 return; | 113 return; |
| 115 } | 114 } |
| 116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 115 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 117 utility_process_host_->EndBatchMode(); | 116 utility_process_host_->EndBatchMode(); |
| 118 utility_process_host_ = NULL; | 117 utility_process_host_.reset(); |
| 119 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 118 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 120 MessageLoop::QuitClosure()); | 119 MessageLoop::QuitClosure()); |
| 121 } | 120 } |
| 122 | 121 |
| 123 void SetExpectedKeys(int expected_id, | 122 void SetExpectedKeys(int expected_id, |
| 124 const std::vector<IndexedDBKey>& expected_keys, | 123 const std::vector<IndexedDBKey>& expected_keys, |
| 125 bool failed) { | 124 bool failed) { |
| 126 expected_id_ = expected_id; | 125 expected_id_ = expected_id; |
| 127 expected_keys_ = expected_keys; | 126 expected_keys_ = expected_keys; |
| 128 value_for_key_path_failed_ = failed; | 127 value_for_key_path_failed_ = failed; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 void OnInjectIDBKeyFinished(const content::SerializedScriptValue& new_value) { | 209 void OnInjectIDBKeyFinished(const content::SerializedScriptValue& new_value) { |
| 211 EXPECT_EQ(expected_value_.data(), new_value.data()); | 210 EXPECT_EQ(expected_value_.data(), new_value.data()); |
| 212 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 211 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 213 MessageLoop::QuitClosure()); | 212 MessageLoop::QuitClosure()); |
| 214 } | 213 } |
| 215 | 214 |
| 216 | 215 |
| 217 private: | 216 private: |
| 218 int expected_id_; | 217 int expected_id_; |
| 219 std::vector<IndexedDBKey> expected_keys_; | 218 std::vector<IndexedDBKey> expected_keys_; |
| 220 UtilityProcessHost* utility_process_host_; | 219 base::WeakPtr<UtilityProcessHost> utility_process_host_; |
| 221 bool value_for_key_path_failed_; | 220 bool value_for_key_path_failed_; |
| 222 content::SerializedScriptValue expected_value_; | 221 content::SerializedScriptValue expected_value_; |
| 223 }; | 222 }; |
| 224 | 223 |
| 225 // This test fixture runs in the UI thread. However, most of the work done by | 224 // This test fixture runs in the UI thread. However, most of the work done by |
| 226 // UtilityProcessHost (and wrapped by IDBKeyPathHelper above) happens on the IO | 225 // UtilityProcessHost (and wrapped by IDBKeyPathHelper above) happens on the IO |
| 227 // thread. This fixture delegates to IDBKeyPathHelper and blocks via | 226 // thread. This fixture delegates to IDBKeyPathHelper and blocks via |
| 228 // "ui_test_utils::RunMessageLoop()", until IDBKeyPathHelper posts a quit | 227 // "ui_test_utils::RunMessageLoop()", until IDBKeyPathHelper posts a quit |
| 229 // message the MessageLoop. | 228 // message the MessageLoop. |
| 230 class ScopedIDBKeyPathHelper { | 229 class ScopedIDBKeyPathHelper { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 0x6f6f, 0x013f, 0x0353, 0x6f7a, 0x3f6f, | 375 0x6f6f, 0x013f, 0x0353, 0x6f7a, 0x3f6f, |
| 377 0x5301, 0x6203, 0x7261, 0x013f, 0x3f6f, | 376 0x5301, 0x6203, 0x7261, 0x013f, 0x3f6f, |
| 378 0x5302, 0x6203, 0x7a61, 0x023f, 0x0853, | 377 0x5302, 0x6203, 0x7a61, 0x023f, 0x0853, |
| 379 0x796d, 0x654e, 0x4b77, 0x7965, 0x017b, | 378 0x796d, 0x654e, 0x4b77, 0x7965, 0x017b, |
| 380 0x027b}; | 379 0x027b}; |
| 381 content::SerializedScriptValue expected_value2( | 380 content::SerializedScriptValue expected_value2( |
| 382 false, false, string16(expected_data2, arraysize(expected_data2))); | 381 false, false, string16(expected_data2, arraysize(expected_data2))); |
| 383 scoped_helper.SetExpectedValue(expected_value2); | 382 scoped_helper.SetExpectedValue(expected_value2); |
| 384 scoped_helper.CheckInjectValue(key, value, UTF8ToUTF16("bar.baz")); | 383 scoped_helper.CheckInjectValue(key, value, UTF8ToUTF16("bar.baz")); |
| 385 } | 384 } |
| OLD | NEW |