| 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 "chrome/browser/extensions/test_extension_prefs.h" | 5 #include "chrome/browser/extensions/test_extension_prefs.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| 11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
| 12 #include "base/test/signaling_task.h" |
| 12 #include "base/values.h" | 13 #include "base/values.h" |
| 13 #include "chrome/browser/extensions/extension_pref_store.h" | 14 #include "chrome/browser/extensions/extension_pref_store.h" |
| 14 #include "chrome/browser/extensions/extension_pref_value_map.h" | 15 #include "chrome/browser/extensions/extension_pref_value_map.h" |
| 15 #include "chrome/browser/extensions/extension_prefs.h" | 16 #include "chrome/browser/extensions/extension_prefs.h" |
| 16 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
| 17 #include "chrome/browser/prefs/pref_service_mock_builder.h" | 18 #include "chrome/browser/prefs/pref_service_mock_builder.h" |
| 18 #include "chrome/browser/prefs/pref_value_store.h" | 19 #include "chrome/browser/prefs/pref_value_store.h" |
| 19 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
| 20 #include "chrome/common/extensions/extension_constants.h" | 21 #include "chrome/common/extensions/extension_constants.h" |
| 21 #include "chrome/common/json_pref_store.h" | 22 #include "chrome/common/json_pref_store.h" |
| 22 #include "chrome/test/base/signaling_task.h" | |
| 23 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 // Mock ExtensionPrefs class with artificial clock to guarantee that no two | 28 // Mock ExtensionPrefs class with artificial clock to guarantee that no two |
| 29 // extensions get the same installation time stamp and we can reliably | 29 // extensions get the same installation time stamp and we can reliably |
| 30 // assert the installation order in the tests below. | 30 // assert the installation order in the tests below. |
| 31 class MockExtensionPrefs : public ExtensionPrefs { | 31 class MockExtensionPrefs : public ExtensionPrefs { |
| 32 public: | 32 public: |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 // We persist and reload the PrefService's PrefStores because this process | 65 // We persist and reload the PrefService's PrefStores because this process |
| 66 // deletes all empty dictionaries. The ExtensionPrefs implementation | 66 // deletes all empty dictionaries. The ExtensionPrefs implementation |
| 67 // needs to be able to handle this situation. | 67 // needs to be able to handle this situation. |
| 68 if (pref_service_.get()) { | 68 if (pref_service_.get()) { |
| 69 // The PrefService writes its persistent file on the file thread, so we | 69 // The PrefService writes its persistent file on the file thread, so we |
| 70 // need to wait for any pending I/O to complete before creating a new | 70 // need to wait for any pending I/O to complete before creating a new |
| 71 // PrefService. | 71 // PrefService. |
| 72 base::WaitableEvent io_finished(false, false); | 72 base::WaitableEvent io_finished(false, false); |
| 73 pref_service_->SavePersistentPrefs(); | 73 pref_service_->SavePersistentPrefs(); |
| 74 EXPECT_TRUE(BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 74 EXPECT_TRUE(BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 75 new SignalingTask(&io_finished))); | 75 new base::SignalingTask(&io_finished))); |
| 76 | 76 |
| 77 // If the FILE thread is in fact the current thread (possible in testing | 77 // If the FILE thread is in fact the current thread (possible in testing |
| 78 // scenarios), we have to ensure the task has a chance to run. If the FILE | 78 // scenarios), we have to ensure the task has a chance to run. If the FILE |
| 79 // thread is a different thread, the test must ensure that thread is running | 79 // thread is a different thread, the test must ensure that thread is running |
| 80 // (otherwise the Wait below will hang). | 80 // (otherwise the Wait below will hang). |
| 81 MessageLoop::current()->RunAllPending(); | 81 MessageLoop::current()->RunAllPending(); |
| 82 | 82 |
| 83 io_finished.Wait(); | 83 io_finished.Wait(); |
| 84 } | 84 } |
| 85 | 85 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 } | 147 } |
| 148 | 148 |
| 149 PrefService* TestExtensionPrefs::CreateIncognitoPrefService() const { | 149 PrefService* TestExtensionPrefs::CreateIncognitoPrefService() const { |
| 150 return pref_service_->CreateIncognitoPrefService( | 150 return pref_service_->CreateIncognitoPrefService( |
| 151 new ExtensionPrefStore(extension_pref_value_map_.get(), true)); | 151 new ExtensionPrefStore(extension_pref_value_map_.get(), true)); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void TestExtensionPrefs::set_extensions_disabled(bool extensions_disabled) { | 154 void TestExtensionPrefs::set_extensions_disabled(bool extensions_disabled) { |
| 155 extensions_disabled_ = extensions_disabled; | 155 extensions_disabled_ = extensions_disabled; |
| 156 } | 156 } |
| OLD | NEW |