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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/scoped_temp_dir.h" | 11 #include "base/scoped_temp_dir.h" |
12 #include "chrome/browser/extensions/extension_settings_backend.h" | 12 #include "chrome/browser/extensions/extension_settings_backend.h" |
13 #include "chrome/browser/extensions/extension_settings_frontend.h" | 13 #include "chrome/browser/extensions/extension_settings_frontend.h" |
14 #include "chrome/browser/extensions/extension_settings_storage.h" | 14 #include "chrome/browser/extensions/extension_settings_storage.h" |
15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
16 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
17 | 17 |
18 class ExtensionSettingsFrontendTest : public testing::Test { | 18 class ExtensionSettingsFrontendTest : public testing::Test { |
19 public: | 19 public: |
20 ExtensionSettingsFrontendTest() | 20 ExtensionSettingsFrontendTest() |
21 : ui_thread_(BrowserThread::UI, MessageLoop::current()), | 21 : ui_thread_(BrowserThread::UI, MessageLoop::current()), |
22 file_thread_(BrowserThread::FILE, MessageLoop::current()) {} | 22 file_thread_(BrowserThread::FILE, MessageLoop::current()) {} |
23 | 23 |
24 virtual void SetUp() OVERRIDE { | 24 virtual void SetUp() OVERRIDE { |
25 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 25 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
26 frontend_.reset(new ExtensionSettingsFrontend(temp_dir_.path())); | |
27 profile_.reset(new TestingProfile(temp_dir_.path())); | 26 profile_.reset(new TestingProfile(temp_dir_.path())); |
| 27 frontend_.reset(new ExtensionSettingsFrontend(profile_.get())); |
28 } | 28 } |
29 | 29 |
30 virtual void TearDown() OVERRIDE { | 30 virtual void TearDown() OVERRIDE { |
| 31 frontend_.reset(); |
31 profile_.reset(); | 32 profile_.reset(); |
32 frontend_.reset(); | |
33 } | 33 } |
34 | 34 |
35 protected: | 35 protected: |
36 // Puts the settings backend in |backend|. | 36 // Puts the settings backend in |backend|. |
37 void GetBackend(ExtensionSettingsBackend** backend) { | 37 void GetBackend(ExtensionSettingsBackend** backend) { |
38 frontend_->RunWithBackend( | 38 frontend_->RunWithBackend( |
39 base::Bind( | 39 base::Bind( |
40 &ExtensionSettingsFrontendTest::AssignBackend, | 40 &ExtensionSettingsFrontendTest::AssignBackend, |
41 base::Unretained(this), | 41 base::Unretained(this), |
42 backend)); | 42 backend)); |
43 MessageLoop::current()->RunAllPending(); | 43 MessageLoop::current()->RunAllPending(); |
44 ASSERT_TRUE(*backend); | 44 ASSERT_TRUE(*backend); |
45 } | 45 } |
46 | 46 |
47 ScopedTempDir temp_dir_; | 47 ScopedTempDir temp_dir_; |
| 48 scoped_ptr<TestingProfile> profile_; |
48 scoped_ptr<ExtensionSettingsFrontend> frontend_; | 49 scoped_ptr<ExtensionSettingsFrontend> frontend_; |
49 scoped_ptr<TestingProfile> profile_; | |
50 | 50 |
51 private: | 51 private: |
52 // Intended as a ExtensionSettingsFrontend::BackendCallback from GetBackend. | 52 // Intended as a ExtensionSettingsFrontend::BackendCallback from GetBackend. |
53 void AssignBackend( | 53 void AssignBackend( |
54 ExtensionSettingsBackend** dst, ExtensionSettingsBackend* src) { | 54 ExtensionSettingsBackend** dst, ExtensionSettingsBackend* src) { |
55 *dst = src; | 55 *dst = src; |
56 } | 56 } |
57 | 57 |
58 MessageLoop message_loop_; | 58 MessageLoop message_loop_; |
59 BrowserThread ui_thread_; | 59 BrowserThread ui_thread_; |
(...skipping 10 matching lines...) Expand all Loading... |
70 // The correctness of Get/Set/Remove/Clear is tested elsewhere so no need to | 70 // The correctness of Get/Set/Remove/Clear is tested elsewhere so no need to |
71 // be too rigorous. | 71 // be too rigorous. |
72 StringValue bar("bar"); | 72 StringValue bar("bar"); |
73 ExtensionSettingsStorage::Result result = storage->Set("foo", bar); | 73 ExtensionSettingsStorage::Result result = storage->Set("foo", bar); |
74 ASSERT_FALSE(result.HasError()); | 74 ASSERT_FALSE(result.HasError()); |
75 | 75 |
76 result = storage->Get(); | 76 result = storage->Get(); |
77 ASSERT_FALSE(result.HasError()); | 77 ASSERT_FALSE(result.HasError()); |
78 EXPECT_FALSE(result.GetSettings()->empty()); | 78 EXPECT_FALSE(result.GetSettings()->empty()); |
79 | 79 |
80 frontend_.reset(new ExtensionSettingsFrontend(temp_dir_.path())); | 80 frontend_.reset(new ExtensionSettingsFrontend(profile_.get())); |
81 GetBackend(&backend); | 81 GetBackend(&backend); |
82 storage = backend->GetStorage(id); | 82 storage = backend->GetStorage(id); |
83 | 83 |
84 result = storage->Get(); | 84 result = storage->Get(); |
85 ASSERT_FALSE(result.HasError()); | 85 ASSERT_FALSE(result.HasError()); |
86 EXPECT_FALSE(result.GetSettings()->empty()); | 86 EXPECT_FALSE(result.GetSettings()->empty()); |
87 } | 87 } |
88 | 88 |
89 TEST_F(ExtensionSettingsFrontendTest, SettingsClearedOnUninstall) { | 89 TEST_F(ExtensionSettingsFrontendTest, SettingsClearedOnUninstall) { |
90 ExtensionSettingsBackend* backend; | 90 ExtensionSettingsBackend* backend; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 ASSERT_FALSE(result.HasError()); | 125 ASSERT_FALSE(result.HasError()); |
126 EXPECT_TRUE(file_util::PathExists(temp_dir_.path())); | 126 EXPECT_TRUE(file_util::PathExists(temp_dir_.path())); |
127 | 127 |
128 frontend_.reset(); | 128 frontend_.reset(); |
129 MessageLoop::current()->RunAllPending(); | 129 MessageLoop::current()->RunAllPending(); |
130 // TODO(kalman): Figure out why this fails, despite appearing to work. | 130 // TODO(kalman): Figure out why this fails, despite appearing to work. |
131 // Leaving this commented out rather than disabling the whole test so that the | 131 // Leaving this commented out rather than disabling the whole test so that the |
132 // deletion code paths are at least exercised. | 132 // deletion code paths are at least exercised. |
133 //EXPECT_FALSE(file_util::PathExists(temp_dir_.path())); | 133 //EXPECT_FALSE(file_util::PathExists(temp_dir_.path())); |
134 } | 134 } |
OLD | NEW |