| 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 "base/prefs/pref_member.h" | 5 #include "base/prefs/pref_member.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
| 10 #include "base/prefs/testing_pref_service.h" | 10 #include "base/prefs/testing_pref_service.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 class GetPrefValueHelper | 31 class GetPrefValueHelper |
| 32 : public base::RefCountedThreadSafe<GetPrefValueHelper> { | 32 : public base::RefCountedThreadSafe<GetPrefValueHelper> { |
| 33 public: | 33 public: |
| 34 GetPrefValueHelper() : value_(false), pref_thread_("pref thread") { | 34 GetPrefValueHelper() : value_(false), pref_thread_("pref thread") { |
| 35 pref_thread_.Start(); | 35 pref_thread_.Start(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void Init(const char* pref_name, PrefService* prefs) { | 38 void Init(const char* pref_name, PrefService* prefs) { |
| 39 pref_.Init(pref_name, prefs); | 39 pref_.Init(pref_name, prefs); |
| 40 pref_.MoveToThread(pref_thread_.message_loop_proxy()); | 40 pref_.MoveToTaskRunner(pref_thread_.message_loop_proxy()); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void Destroy() { | 43 void Destroy() { |
| 44 pref_.Destroy(); | 44 pref_.Destroy(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void FetchValue() { | 47 void FetchValue() { |
| 48 base::WaitableEvent event(true, false); | 48 base::WaitableEvent event(true, false); |
| 49 ASSERT_TRUE( | 49 ASSERT_TRUE( |
| 50 pref_thread_.message_loop_proxy()->PostTask( | 50 pref_thread_.message_loop_proxy()->PostTask( |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 prefs.SetString(kStringPref, "hello"); | 291 prefs.SetString(kStringPref, "hello"); |
| 292 EXPECT_EQ(2, test_obj.observe_cnt_); | 292 EXPECT_EQ(2, test_obj.observe_cnt_); |
| 293 EXPECT_EQ("hello", prefs.GetString(kStringPref)); | 293 EXPECT_EQ("hello", prefs.GetString(kStringPref)); |
| 294 } | 294 } |
| 295 | 295 |
| 296 TEST(PrefMemberTest, NoInit) { | 296 TEST(PrefMemberTest, NoInit) { |
| 297 // Make sure not calling Init on a PrefMember doesn't cause problems. | 297 // Make sure not calling Init on a PrefMember doesn't cause problems. |
| 298 IntegerPrefMember pref; | 298 IntegerPrefMember pref; |
| 299 } | 299 } |
| 300 | 300 |
| 301 TEST(PrefMemberTest, MoveToThread) { | 301 TEST(PrefMemberTest, MoveToTaskRunner) { |
| 302 TestingPrefServiceSimple prefs; | 302 TestingPrefServiceSimple prefs; |
| 303 scoped_refptr<GetPrefValueHelper> helper(new GetPrefValueHelper()); | 303 scoped_refptr<GetPrefValueHelper> helper(new GetPrefValueHelper()); |
| 304 RegisterTestPrefs(prefs.registry()); | 304 RegisterTestPrefs(prefs.registry()); |
| 305 helper->Init(kBoolPref, &prefs); | 305 helper->Init(kBoolPref, &prefs); |
| 306 | 306 |
| 307 helper->FetchValue(); | 307 helper->FetchValue(); |
| 308 EXPECT_FALSE(helper->value()); | 308 EXPECT_FALSE(helper->value()); |
| 309 | 309 |
| 310 prefs.SetBoolean(kBoolPref, true); | 310 prefs.SetBoolean(kBoolPref, true); |
| 311 | 311 |
| 312 helper->FetchValue(); | 312 helper->FetchValue(); |
| 313 EXPECT_TRUE(helper->value()); | 313 EXPECT_TRUE(helper->value()); |
| 314 | 314 |
| 315 helper->Destroy(); | 315 helper->Destroy(); |
| 316 | 316 |
| 317 helper->FetchValue(); | 317 helper->FetchValue(); |
| 318 EXPECT_TRUE(helper->value()); | 318 EXPECT_TRUE(helper->value()); |
| 319 | 319 |
| 320 helper->StopThread(); | 320 helper->StopThread(); |
| 321 } | 321 } |
| OLD | NEW |