| 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/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "base/scoped_temp_dir.h" | 7 #include "base/scoped_temp_dir.h" |
| 8 #include "base/stl_util-inl.h" | 8 #include "base/stl_util-inl.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| 11 #include "chrome/browser/extensions/extension_prefs.h" | 11 #include "chrome/browser/extensions/extension_prefs.h" |
| 12 #include "chrome/browser/extensions/test_extension_prefs.h" | 12 #include "chrome/browser/extensions/test_extension_prefs.h" |
| 13 #include "chrome/browser/prefs/pref_change_registrar.h" | 13 #include "chrome/browser/prefs/pref_change_registrar.h" |
| 14 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
| 15 #include "chrome/common/extensions/extension_constants.h" | 15 #include "chrome/common/extensions/extension_constants.h" |
| 16 #include "content/common/notification_details.h" | 16 #include "content/common/notification_details.h" |
| 17 #include "content/common/notification_observer_mock.h" | 17 #include "content/common/notification_observer_mock.h" |
| 18 #include "content/common/notification_source.h" | 18 #include "content/common/notification_source.h" |
| 19 #include "content/browser/browser_thread.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 21 |
| 21 using base::Time; | 22 using base::Time; |
| 22 using base::TimeDelta; | 23 using base::TimeDelta; |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 const char kPref1[] = "path1.subpath"; | 27 const char kPref1[] = "path1.subpath"; |
| 27 const char kPref2[] = "path2"; | 28 const char kPref2[] = "path2"; |
| 28 const char kPref3[] = "path3"; | 29 const char kPref3[] = "path3"; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 54 std::set<std::string> strings2; | 55 std::set<std::string> strings2; |
| 55 for (size_t i = 0; i < patterns2.size(); ++i) | 56 for (size_t i = 0; i < patterns2.size(); ++i) |
| 56 strings2.insert(patterns2.at(i).GetAsString()); | 57 strings2.insert(patterns2.at(i).GetAsString()); |
| 57 | 58 |
| 58 EXPECT_EQ(strings1, strings2); | 59 EXPECT_EQ(strings1, strings2); |
| 59 } | 60 } |
| 60 | 61 |
| 61 // Base class for tests. | 62 // Base class for tests. |
| 62 class ExtensionPrefsTest : public testing::Test { | 63 class ExtensionPrefsTest : public testing::Test { |
| 63 public: | 64 public: |
| 64 ExtensionPrefsTest() {} | 65 ExtensionPrefsTest() |
| 66 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 67 file_thread_(BrowserThread::FILE, &message_loop_) { |
| 68 } |
| 65 | 69 |
| 66 // This function will get called once, and is the right place to do operations | 70 // This function will get called once, and is the right place to do operations |
| 67 // on ExtensionPrefs that write data. | 71 // on ExtensionPrefs that write data. |
| 68 virtual void Initialize() = 0; | 72 virtual void Initialize() = 0; |
| 69 | 73 |
| 70 // This function will be called twice - once while the original ExtensionPrefs | 74 // This function will be called twice - once while the original ExtensionPrefs |
| 71 // object is still alive, and once after recreation. Thus, it tests that | 75 // object is still alive, and once after recreation. Thus, it tests that |
| 72 // things don't break after any ExtensionPrefs startup work. | 76 // things don't break after any ExtensionPrefs startup work. |
| 73 virtual void Verify() = 0; | 77 virtual void Verify() = 0; |
| 74 | 78 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 85 | 89 |
| 86 // Reset ExtensionPrefs, and re-verify. | 90 // Reset ExtensionPrefs, and re-verify. |
| 87 prefs_.RecreateExtensionPrefs(); | 91 prefs_.RecreateExtensionPrefs(); |
| 88 RegisterPreferences(); | 92 RegisterPreferences(); |
| 89 Verify(); | 93 Verify(); |
| 90 } | 94 } |
| 91 | 95 |
| 92 protected: | 96 protected: |
| 93 ExtensionPrefs* prefs() { return prefs_.prefs(); } | 97 ExtensionPrefs* prefs() { return prefs_.prefs(); } |
| 94 | 98 |
| 99 MessageLoop message_loop_; |
| 100 BrowserThread ui_thread_; |
| 101 BrowserThread file_thread_; |
| 102 |
| 95 TestExtensionPrefs prefs_; | 103 TestExtensionPrefs prefs_; |
| 96 | 104 |
| 97 private: | 105 private: |
| 98 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefsTest); | 106 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefsTest); |
| 99 }; | 107 }; |
| 100 | 108 |
| 101 // Tests the LastPingDay/SetLastPingDay functions. | 109 // Tests the LastPingDay/SetLastPingDay functions. |
| 102 class ExtensionPrefsLastPingDay : public ExtensionPrefsTest { | 110 class ExtensionPrefsLastPingDay : public ExtensionPrefsTest { |
| 103 public: | 111 public: |
| 104 ExtensionPrefsLastPingDay() | 112 ExtensionPrefsLastPingDay() |
| (...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 testing::Mock::VerifyAndClearExpectations(v1i); | 912 testing::Mock::VerifyAndClearExpectations(v1i); |
| 905 testing::Mock::VerifyAndClearExpectations(v2); | 913 testing::Mock::VerifyAndClearExpectations(v2); |
| 906 testing::Mock::VerifyAndClearExpectations(v2i); | 914 testing::Mock::VerifyAndClearExpectations(v2i); |
| 907 } | 915 } |
| 908 | 916 |
| 909 virtual void Verify() { | 917 virtual void Verify() { |
| 910 } | 918 } |
| 911 }; | 919 }; |
| 912 TEST_F(ExtensionPrefsSetExtensionControlledPref, | 920 TEST_F(ExtensionPrefsSetExtensionControlledPref, |
| 913 ExtensionPrefsSetExtensionControlledPref) {} | 921 ExtensionPrefsSetExtensionControlledPref) {} |
| OLD | NEW |