Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: chrome/browser/extensions/extension_pref_store_unittest.cc

Issue 3323022: Create a DefaultPrefStore to hold registered application-default preference v... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/scoped_temp_dir.h" 9 #include "base/scoped_temp_dir.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/extensions/extension_pref_store.h" 11 #include "chrome/browser/extensions/extension_pref_store.h"
12 #include "chrome/browser/prefs/default_pref_store.h"
12 #include "chrome/browser/prefs/pref_service.h" 13 #include "chrome/browser/prefs/pref_service.h"
13 #include "chrome/browser/prefs/pref_value_store.h" 14 #include "chrome/browser/prefs/pref_value_store.h"
14 #include "chrome/common/extensions/extension.h" 15 #include "chrome/common/extensions/extension.h"
15 #include "chrome/test/testing_pref_service.h" 16 #include "chrome/test/testing_pref_service.h"
16 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 namespace { 20 namespace {
20 21
21 class TestExtensionPrefStore : public ExtensionPrefStore { 22 class TestExtensionPrefStore : public ExtensionPrefStore {
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 EXPECT_EQ("val4", actual); 322 EXPECT_EQ("val4", actual);
322 EXPECT_TRUE(prefs->GetString(kPref3, &actual)); 323 EXPECT_TRUE(prefs->GetString(kPref3, &actual));
323 EXPECT_EQ("val6", actual); 324 EXPECT_EQ("val6", actual);
324 EXPECT_FALSE(prefs->GetString(kPref4, &actual)); 325 EXPECT_FALSE(prefs->GetString(kPref4, &actual));
325 } 326 }
326 327
327 TEST(ExtensionPrefStoreTest, NotifyWhenNeeded) { 328 TEST(ExtensionPrefStoreTest, NotifyWhenNeeded) {
328 using testing::Mock; 329 using testing::Mock;
329 330
330 TestExtensionPrefStore* eps = new TestExtensionPrefStore; 331 TestExtensionPrefStore* eps = new TestExtensionPrefStore;
332 DefaultPrefStore* dps = new DefaultPrefStore;
331 ASSERT_TRUE(eps->ext1 != NULL); 333 ASSERT_TRUE(eps->ext1 != NULL);
332 334
333 // The PrefValueStore takes ownership of the PrefStores; in this case, that's 335 // The PrefValueStore takes ownership of the PrefStores; in this case, that's
334 // only an ExtensionPrefStore. Likewise, the PrefService takes ownership of 336 // only an ExtensionPrefStore. Likewise, the PrefService takes ownership of
335 // the PrefValueStore and PrefNotifier. 337 // the PrefValueStore and PrefNotifier.
336 PrefValueStore* value_store = new TestingPrefService::TestingPrefValueStore( 338 PrefValueStore* value_store = new TestingPrefService::TestingPrefValueStore(
337 NULL, eps, NULL, NULL, NULL); 339 NULL, eps, NULL, NULL, NULL, dps);
338 scoped_ptr<MockPrefService> pref_service(new MockPrefService(value_store)); 340 scoped_ptr<MockPrefService> pref_service(new MockPrefService(value_store));
339 MockPrefNotifier* pref_notifier = new MockPrefNotifier(pref_service.get(), 341 MockPrefNotifier* pref_notifier = new MockPrefNotifier(pref_service.get(),
340 value_store); 342 value_store);
341 pref_service->SetPrefNotifier(pref_notifier); 343 pref_service->SetPrefNotifier(pref_notifier);
342 344
343 eps->SetPrefService(pref_service.get()); 345 eps->SetPrefService(pref_service.get());
344 pref_service->RegisterStringPref(kPref1, std::string()); 346 pref_service->RegisterStringPref(kPref1, std::string());
345 347
346 EXPECT_CALL(*pref_notifier, FireObservers(kPref1)); 348 EXPECT_CALL(*pref_notifier, FireObservers(kPref1));
347 eps->InstallExtensionPref(eps->ext1, kPref1, 349 eps->InstallExtensionPref(eps->ext1, kPref1,
348 Value::CreateStringValue("https://www.chromium.org")); 350 Value::CreateStringValue("https://www.chromium.org"));
349 Mock::VerifyAndClearExpectations(pref_notifier); 351 Mock::VerifyAndClearExpectations(pref_notifier);
350 352
351 EXPECT_CALL(*pref_notifier, FireObservers(kPref1)).Times(0); 353 EXPECT_CALL(*pref_notifier, FireObservers(kPref1)).Times(0);
352 eps->InstallExtensionPref(eps->ext1, kPref1, 354 eps->InstallExtensionPref(eps->ext1, kPref1,
353 Value::CreateStringValue("https://www.chromium.org")); 355 Value::CreateStringValue("https://www.chromium.org"));
354 Mock::VerifyAndClearExpectations(pref_notifier); 356 Mock::VerifyAndClearExpectations(pref_notifier);
355 357
356 EXPECT_CALL(*pref_notifier, FireObservers(kPref1)).Times(2); 358 EXPECT_CALL(*pref_notifier, FireObservers(kPref1)).Times(2);
357 eps->InstallExtensionPref(eps->ext1, kPref1, 359 eps->InstallExtensionPref(eps->ext1, kPref1,
358 Value::CreateStringValue("chrome://newtab")); 360 Value::CreateStringValue("chrome://newtab"));
359 eps->UninstallExtension(eps->ext1); 361 eps->UninstallExtension(eps->ext1);
360 } 362 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698