Chromium Code Reviews| 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"); | |
| 85 pref_store->SetValue( | |
| 86 prefs::kBrowserWindowPlacement + std::string("_") + kAppName, | |
| 87 single_app_placement_dict.release()); | |
| 88 | |
| 89 #if !defined(OS_ANDROID) | |
|
Bernhard Bauer
2014/09/11 09:48:28
I would be okay with excluding the whole test on A
| |
| 90 scoped_ptr<base::DictionaryValue> devtools_placement_dict( | |
| 91 new base::DictionaryValue); | |
| 92 devtools_placement_dict->SetInteger("left", 700); | |
| 93 pref_store->SetValue(prefs::kBrowserWindowPlacement + std::string("_") + | |
| 94 DevToolsWindow::kDevToolsApp, | |
| 95 devtools_placement_dict.release()); | |
| 96 #endif | |
| 97 | |
| 98 pref_store->AddObserver(new BrowserUIPrefsMigrator(pref_store.get())); | |
| 99 pref_store->SignalObservers(); | |
| 100 | |
| 101 EXPECT_FALSE(pref_store->GetValue( | |
| 102 prefs::kBrowserWindowPlacement + std::string("_") + kAppName, NULL)); | |
| 103 #if !defined(OS_ANDROID) | |
| 104 EXPECT_FALSE(pref_store->GetValue(prefs::kBrowserWindowPlacement + | |
| 105 std::string("_") + | |
| 106 DevToolsWindow::kDevToolsApp, | |
| 107 NULL)); | |
| 108 #endif | |
| 109 | |
| 110 const base::Value* value = NULL; | |
| 111 const base::DictionaryValue* dictionary = NULL; | |
| 112 int out_value; | |
| 113 ASSERT_TRUE(pref_store->GetValue( | |
| 114 prefs::kAppWindowPlacement + std::string(".") + kAppName, &value)); | |
| 115 ASSERT_TRUE(value->GetAsDictionary(&dictionary)); | |
| 116 EXPECT_TRUE(dictionary->GetInteger("right", &out_value)); | |
| 117 EXPECT_EQ(986, out_value); | |
| 118 | |
| 119 #if !defined(OS_ANDROID) | |
| 120 ASSERT_TRUE(pref_store->GetValue(prefs::kAppWindowPlacement + | |
| 121 std::string(".") + | |
| 122 DevToolsWindow::kDevToolsApp, | |
| 123 &value)); | |
| 124 ASSERT_TRUE(value->GetAsDictionary(&dictionary)); | |
| 125 EXPECT_TRUE(dictionary->GetInteger("left", &out_value)); | |
| 126 EXPECT_EQ(700, out_value); | |
| 127 #endif | |
| 128 | |
| 129 ASSERT_TRUE(pref_store->GetValue(prefs::kBrowserWindowPlacement, &value)); | |
| 130 ASSERT_TRUE(value->GetAsDictionary(&dictionary)); | |
| 131 EXPECT_TRUE(dictionary->GetInteger("bottom", &out_value)); | |
| 132 EXPECT_EQ(1000, out_value); | |
| 133 } | |
| OLD | NEW |