| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <gtest/gtest.h> | 5 #include <gtest/gtest.h> |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| 11 #include "base/scoped_temp_dir.h" | 11 #include "base/scoped_temp_dir.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/extensions/extension_pref_store.h" | 13 #include "chrome/browser/extensions/extension_pref_store.h" |
| 14 #include "chrome/browser/pref_service.h" | 14 #include "chrome/browser/pref_service.h" |
| 15 #include "chrome/browser/pref_value_store.h" | 15 #include "chrome/browser/pref_value_store.h" |
| 16 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
| 17 #include "chrome/test/testing_pref_service.h" |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 class TestExtensionPrefStore : public ExtensionPrefStore { | 21 class TestExtensionPrefStore : public ExtensionPrefStore { |
| 21 public: | 22 public: |
| 22 TestExtensionPrefStore() : ExtensionPrefStore(NULL), | 23 TestExtensionPrefStore() : ExtensionPrefStore(NULL), |
| 23 ext1(NULL), | 24 ext1(NULL), |
| 24 ext2(NULL), | 25 ext2(NULL), |
| 25 ext3(NULL), | 26 ext3(NULL), |
| 26 pref_service_(NULL) { | 27 pref_service_(NULL) { |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 EXPECT_FALSE(prefs->GetString(kPref4, &actual)); | 315 EXPECT_FALSE(prefs->GetString(kPref4, &actual)); |
| 315 } | 316 } |
| 316 | 317 |
| 317 TEST(ExtensionPrefStoreTest, NotifyWhenNeeded) { | 318 TEST(ExtensionPrefStoreTest, NotifyWhenNeeded) { |
| 318 TestExtensionPrefStore* eps = new TestExtensionPrefStore; | 319 TestExtensionPrefStore* eps = new TestExtensionPrefStore; |
| 319 ASSERT_TRUE(eps->ext1 != NULL); | 320 ASSERT_TRUE(eps->ext1 != NULL); |
| 320 | 321 |
| 321 // The PrefValueStore takes ownership of the PrefStores; in this case, that's | 322 // The PrefValueStore takes ownership of the PrefStores; in this case, that's |
| 322 // only an ExtensionPrefStore. Likewise, the PrefService takes ownership of | 323 // only an ExtensionPrefStore. Likewise, the PrefService takes ownership of |
| 323 // the PrefValueStore. | 324 // the PrefValueStore. |
| 324 PrefValueStore* value_store = new PrefValueStore(NULL, eps, NULL, NULL, NULL); | 325 PrefValueStore* value_store = new TestingPrefService::TestingPrefValueStore( |
| 326 NULL, eps, NULL, NULL, NULL); |
| 325 scoped_ptr<MockPrefService> pref_service(new MockPrefService(value_store)); | 327 scoped_ptr<MockPrefService> pref_service(new MockPrefService(value_store)); |
| 326 eps->SetPrefService(pref_service.get()); | 328 eps->SetPrefService(pref_service.get()); |
| 327 pref_service->RegisterStringPref(kPref1, std::string()); | 329 pref_service->RegisterStringPref(kPref1, std::string()); |
| 328 | 330 |
| 329 eps->InstallExtensionPref(eps->ext1, kPref1, | 331 eps->InstallExtensionPref(eps->ext1, kPref1, |
| 330 Value::CreateStringValue("https://www.chromium.org")); | 332 Value::CreateStringValue("https://www.chromium.org")); |
| 331 EXPECT_TRUE(pref_service->fired_observers_); | 333 EXPECT_TRUE(pref_service->fired_observers_); |
| 332 eps->InstallExtensionPref(eps->ext1, kPref1, | 334 eps->InstallExtensionPref(eps->ext1, kPref1, |
| 333 Value::CreateStringValue("https://www.chromium.org")); | 335 Value::CreateStringValue("https://www.chromium.org")); |
| 334 EXPECT_FALSE(pref_service->fired_observers_); | 336 EXPECT_FALSE(pref_service->fired_observers_); |
| 335 eps->InstallExtensionPref(eps->ext1, kPref1, | 337 eps->InstallExtensionPref(eps->ext1, kPref1, |
| 336 Value::CreateStringValue("chrome://newtab")); | 338 Value::CreateStringValue("chrome://newtab")); |
| 337 EXPECT_TRUE(pref_service->fired_observers_); | 339 EXPECT_TRUE(pref_service->fired_observers_); |
| 338 | 340 |
| 339 eps->UninstallExtension(eps->ext1); | 341 eps->UninstallExtension(eps->ext1); |
| 340 EXPECT_TRUE(pref_service->fired_observers_); | 342 EXPECT_TRUE(pref_service->fired_observers_); |
| 341 } | 343 } |
| OLD | NEW |