OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/observer_list.h" | |
6 #include "base/prefs/writeable_pref_store.h" | |
7 #include "base/values.h" | |
8 #include "chrome/browser/devtools/devtools_window.h" | |
9 #include "chrome/browser/prefs/browser_ui_prefs_migrator.h" | |
10 #include "chrome/common/pref_names.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 namespace { | |
14 | |
15 class DictionaryPrefStore : public WriteablePrefStore { | |
16 public: | |
17 DictionaryPrefStore() : WriteablePrefStore() {} | |
18 | |
19 // Overrides from PrefStore. | |
20 virtual void AddObserver(Observer* observer) OVERRIDE { | |
21 observers_.AddObserver(observer); | |
22 } | |
23 | |
24 virtual void RemoveObserver(Observer* observer) OVERRIDE { | |
25 observers_.RemoveObserver(observer); | |
26 } | |
27 | |
28 virtual bool GetValue(const std::string& key, | |
29 const base::Value** result) const OVERRIDE { | |
30 return prefs_.Get(key, result); | |
31 } | |
32 | |
33 // Overrides from WriteablePrefStore. | |
34 virtual void SetValue(const std::string& key, base::Value* value) OVERRIDE { | |
35 DCHECK(value); | |
36 prefs_.Set(key, value); | |
37 ReportValueChanged(key); | |
38 } | |
39 | |
40 virtual void RemoveValue(const std::string& key) OVERRIDE { | |
41 if (prefs_.RemovePath(key, NULL)) | |
42 ReportValueChanged(key); | |
43 } | |
44 | |
45 virtual bool GetMutableValue(const std::string& key, | |
46 base::Value** result) OVERRIDE { | |
47 return prefs_.Get(key, result); | |
48 } | |
49 | |
50 virtual void ReportValueChanged(const std::string& key) OVERRIDE {} | |
51 | |
52 virtual void SetValueSilently(const std::string& key, | |
53 base::Value* value) OVERRIDE { | |
54 NOTIMPLEMENTED(); | |
55 } | |
56 | |
57 void SignalObservers() { | |
58 FOR_EACH_OBSERVER( | |
59 PrefStore::Observer, observers_, OnInitializationCompleted(true)); | |
60 } | |
61 | |
62 private: | |
63 virtual ~DictionaryPrefStore() {} | |
64 | |
65 base::DictionaryValue prefs_; | |
66 ObserverList<PrefStore::Observer, true> observers_; | |
67 | |
68 DISALLOW_COPY_AND_ASSIGN(DictionaryPrefStore); | |
69 }; | |
70 | |
71 } // namespace | |
72 | |
73 TEST(UIPrefsMigratorTest, MigrateTest) { | |
74 scoped_refptr<DictionaryPrefStore> pref_store(new DictionaryPrefStore); | |
75 scoped_ptr<base::DictionaryValue> browser_window_placement( | |
76 new base::DictionaryValue); | |
77 browser_window_placement->SetInteger("bottom", 1000); | |
78 pref_store->SetValue(prefs::kBrowserWindowPlacement, | |
79 browser_window_placement.release()); | |
80 | |
81 scoped_ptr<base::DictionaryValue> single_app_placement_dict( | |
82 new base::DictionaryValue); | |
83 single_app_placement_dict->SetInteger("right", 986); | |
84 const char* kAppName("localhost_/chrome/6/src/chrome/test/data/title1.html"); | |
gab
2014/09/12 13:47:56
Why such a specific test name? Where does this com
dgrogan
2014/09/12 19:05:39
I copy/pasted that from my local Preferences file
| |
85 pref_store->SetValue( | |
86 prefs::kBrowserWindowPlacement + std::string("_") + kAppName, | |
87 single_app_placement_dict.release()); | |
88 | |
89 scoped_ptr<base::DictionaryValue> devtools_placement_dict( | |
90 new base::DictionaryValue); | |
91 devtools_placement_dict->SetInteger("left", 700); | |
92 pref_store->SetValue(prefs::kBrowserWindowPlacement + std::string("_") + | |
93 DevToolsWindow::kDevToolsApp, | |
94 devtools_placement_dict.release()); | |
95 | |
96 pref_store->AddObserver(new BrowserUIPrefsMigrator(pref_store.get())); | |
97 pref_store->SignalObservers(); | |
98 | |
99 EXPECT_FALSE(pref_store->GetValue( | |
100 prefs::kBrowserWindowPlacement + std::string("_") + kAppName, NULL)); | |
gab
2014/09/12 13:47:56
To test the test itself (i.e. to make sure this re
dgrogan
2014/09/12 19:05:39
Done.
| |
101 EXPECT_FALSE(pref_store->GetValue(prefs::kBrowserWindowPlacement + | |
102 std::string("_") + | |
103 DevToolsWindow::kDevToolsApp, | |
104 NULL)); | |
105 const base::Value* value = NULL; | |
106 const base::DictionaryValue* dictionary = NULL; | |
107 int out_value; | |
108 ASSERT_TRUE(pref_store->GetValue( | |
109 prefs::kAppWindowPlacement + std::string(".") + kAppName, &value)); | |
110 ASSERT_TRUE(value->GetAsDictionary(&dictionary)); | |
111 EXPECT_TRUE(dictionary->GetInteger("right", &out_value)); | |
112 EXPECT_EQ(986, out_value); | |
113 | |
114 ASSERT_TRUE(pref_store->GetValue(prefs::kAppWindowPlacement + | |
115 std::string(".") + | |
116 DevToolsWindow::kDevToolsApp, | |
117 &value)); | |
118 ASSERT_TRUE(value->GetAsDictionary(&dictionary)); | |
119 EXPECT_TRUE(dictionary->GetInteger("left", &out_value)); | |
120 EXPECT_EQ(700, out_value); | |
121 | |
122 ASSERT_TRUE(pref_store->GetValue(prefs::kBrowserWindowPlacement, &value)); | |
123 ASSERT_TRUE(value->GetAsDictionary(&dictionary)); | |
124 EXPECT_TRUE(dictionary->GetInteger("bottom", &out_value)); | |
125 EXPECT_EQ(1000, out_value); | |
gab
2014/09/12 13:47:56
Also test kBrowserWindowPlacementPopup to have ful
dgrogan
2014/09/12 19:05:39
Done.
| |
126 } | |
OLD | NEW |