| 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 "chrome/browser/sync/test/integration/extension_settings_helper.h" | 5 #include "chrome/browser/sync/test/integration/extension_settings_helper.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 void GetAllSettingsOnFileThread(base::DictionaryValue* out, | 40 void GetAllSettingsOnFileThread(base::DictionaryValue* out, |
| 41 base::WaitableEvent* signal, | 41 base::WaitableEvent* signal, |
| 42 ValueStore* storage) { | 42 ValueStore* storage) { |
| 43 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 43 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 44 out->Swap(&storage->Get()->settings()); | 44 out->Swap(&storage->Get()->settings()); |
| 45 signal->Signal(); | 45 signal->Signal(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 std::unique_ptr<base::DictionaryValue> GetAllSettings(Profile* profile, | 48 std::unique_ptr<base::DictionaryValue> GetAllSettings(Profile* profile, |
| 49 const std::string& id) { | 49 const std::string& id) { |
| 50 base::WaitableEvent signal(false, false); | 50 base::WaitableEvent signal(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 51 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 51 std::unique_ptr<base::DictionaryValue> settings(new base::DictionaryValue()); | 52 std::unique_ptr<base::DictionaryValue> settings(new base::DictionaryValue()); |
| 52 extensions::StorageFrontend::Get(profile)->RunWithStorage( | 53 extensions::StorageFrontend::Get(profile)->RunWithStorage( |
| 53 ExtensionRegistry::Get(profile)->enabled_extensions().GetByID(id), | 54 ExtensionRegistry::Get(profile)->enabled_extensions().GetByID(id), |
| 54 extensions::settings_namespace::SYNC, | 55 extensions::settings_namespace::SYNC, |
| 55 base::Bind(&GetAllSettingsOnFileThread, settings.get(), &signal)); | 56 base::Bind(&GetAllSettingsOnFileThread, settings.get(), &signal)); |
| 56 signal.Wait(); | 57 signal.Wait(); |
| 57 return settings; | 58 return settings; |
| 58 } | 59 } |
| 59 | 60 |
| 60 bool AreSettingsSame(Profile* expected_profile, Profile* actual_profile) { | 61 bool AreSettingsSame(Profile* expected_profile, Profile* actual_profile) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 storage->Set(ValueStore::DEFAULTS, *settings); | 93 storage->Set(ValueStore::DEFAULTS, *settings); |
| 93 signal->Signal(); | 94 signal->Signal(); |
| 94 } | 95 } |
| 95 | 96 |
| 96 } // namespace | 97 } // namespace |
| 97 | 98 |
| 98 void SetExtensionSettings( | 99 void SetExtensionSettings( |
| 99 Profile* profile, | 100 Profile* profile, |
| 100 const std::string& id, | 101 const std::string& id, |
| 101 const base::DictionaryValue& settings) { | 102 const base::DictionaryValue& settings) { |
| 102 base::WaitableEvent signal(false, false); | 103 base::WaitableEvent signal(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 104 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 103 extensions::StorageFrontend::Get(profile)->RunWithStorage( | 105 extensions::StorageFrontend::Get(profile)->RunWithStorage( |
| 104 ExtensionRegistry::Get(profile)->enabled_extensions().GetByID(id), | 106 ExtensionRegistry::Get(profile)->enabled_extensions().GetByID(id), |
| 105 extensions::settings_namespace::SYNC, | 107 extensions::settings_namespace::SYNC, |
| 106 base::Bind(&SetSettingsOnFileThread, &settings, &signal)); | 108 base::Bind(&SetSettingsOnFileThread, &settings, &signal)); |
| 107 signal.Wait(); | 109 signal.Wait(); |
| 108 } | 110 } |
| 109 | 111 |
| 110 void SetExtensionSettingsForAllProfiles( | 112 void SetExtensionSettingsForAllProfiles( |
| 111 const std::string& id, const base::DictionaryValue& settings) { | 113 const std::string& id, const base::DictionaryValue& settings) { |
| 112 for (int i = 0; i < test()->num_clients(); ++i) | 114 for (int i = 0; i < test()->num_clients(); ++i) |
| 113 SetExtensionSettings(test()->GetProfile(i), id, settings); | 115 SetExtensionSettings(test()->GetProfile(i), id, settings); |
| 114 SetExtensionSettings(test()->verifier(), id, settings); | 116 SetExtensionSettings(test()->verifier(), id, settings); |
| 115 } | 117 } |
| 116 | 118 |
| 117 bool AllExtensionSettingsSameAsVerifier() { | 119 bool AllExtensionSettingsSameAsVerifier() { |
| 118 bool all_profiles_same = true; | 120 bool all_profiles_same = true; |
| 119 for (int i = 0; i < test()->num_clients(); ++i) { | 121 for (int i = 0; i < test()->num_clients(); ++i) { |
| 120 // &= so that all profiles are tested; analogous to EXPECT over ASSERT. | 122 // &= so that all profiles are tested; analogous to EXPECT over ASSERT. |
| 121 all_profiles_same &= | 123 all_profiles_same &= |
| 122 AreSettingsSame(test()->verifier(), test()->GetProfile(i)); | 124 AreSettingsSame(test()->verifier(), test()->GetProfile(i)); |
| 123 } | 125 } |
| 124 return all_profiles_same; | 126 return all_profiles_same; |
| 125 } | 127 } |
| 126 | 128 |
| 127 } // namespace extension_settings_helper | 129 } // namespace extension_settings_helper |
| OLD | NEW |