Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: chrome/browser/extensions/extension_settings_frontend_unittest.cc

Issue 8177022: Add onChanged events to the extension settings API, both from sync and between (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "content/common/notification_service.h" 17 #include "content/common/notification_service.h"
18 #include "content/common/notification_source.h" 18 #include "content/common/notification_source.h"
19 #include "content/common/notification_details.h" 19 #include "content/common/notification_details.h"
20 20
21 class ExtensionSettingsFrontendTest : public testing::Test { 21 class ExtensionSettingsFrontendTest : public testing::Test {
22 public: 22 public:
23 ExtensionSettingsFrontendTest() 23 ExtensionSettingsFrontendTest()
24 : ui_thread_(BrowserThread::UI, MessageLoop::current()), 24 : ui_thread_(BrowserThread::UI, MessageLoop::current()),
25 file_thread_(BrowserThread::FILE, MessageLoop::current()) {} 25 file_thread_(BrowserThread::FILE, MessageLoop::current()) {}
26 26
27 virtual void SetUp() OVERRIDE { 27 virtual void SetUp() OVERRIDE {
28 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 28 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
29 frontend_.reset(new ExtensionSettingsFrontend(temp_dir_.path()));
30 profile_.reset(new TestingProfile(temp_dir_.path())); 29 profile_.reset(new TestingProfile(temp_dir_.path()));
30 frontend_.reset(new ExtensionSettingsFrontend(profile_.get()));
31 } 31 }
32 32
33 virtual void TearDown() OVERRIDE { 33 virtual void TearDown() OVERRIDE {
34 frontend_.reset();
34 profile_.reset(); 35 profile_.reset();
35 frontend_.reset();
36 } 36 }
37 37
38 protected: 38 protected:
39 // Puts the settings backend in |backend|. 39 // Puts the settings backend in |backend|.
40 void GetBackend(ExtensionSettingsBackend** backend) { 40 void GetBackend(ExtensionSettingsBackend** backend) {
41 frontend_->RunWithBackend( 41 frontend_->RunWithBackend(
42 base::Bind( 42 base::Bind(
43 &ExtensionSettingsFrontendTest::AssignBackend, 43 &ExtensionSettingsFrontendTest::AssignBackend,
44 base::Unretained(this), 44 base::Unretained(this),
45 backend)); 45 backend));
46 MessageLoop::current()->RunAllPending(); 46 MessageLoop::current()->RunAllPending();
47 ASSERT_TRUE(*backend); 47 ASSERT_TRUE(*backend);
48 } 48 }
49 49
50 ScopedTempDir temp_dir_; 50 ScopedTempDir temp_dir_;
51 scoped_ptr<TestingProfile> profile_;
51 scoped_ptr<ExtensionSettingsFrontend> frontend_; 52 scoped_ptr<ExtensionSettingsFrontend> frontend_;
52 scoped_ptr<TestingProfile> profile_;
53 53
54 private: 54 private:
55 // Intended as a ExtensionSettingsFrontend::BackendCallback from GetBackend. 55 // Intended as a ExtensionSettingsFrontend::BackendCallback from GetBackend.
56 void AssignBackend( 56 void AssignBackend(
57 ExtensionSettingsBackend** dst, ExtensionSettingsBackend* src) { 57 ExtensionSettingsBackend** dst, ExtensionSettingsBackend* src) {
58 *dst = src; 58 *dst = src;
59 } 59 }
60 60
61 MessageLoop message_loop_; 61 MessageLoop message_loop_;
62 BrowserThread ui_thread_; 62 BrowserThread ui_thread_;
(...skipping 10 matching lines...) Expand all
73 // The correctness of Get/Set/Remove/Clear is tested elsewhere so no need to 73 // The correctness of Get/Set/Remove/Clear is tested elsewhere so no need to
74 // be too rigorous. 74 // be too rigorous.
75 StringValue bar("bar"); 75 StringValue bar("bar");
76 ExtensionSettingsStorage::Result result = storage->Set("foo", bar); 76 ExtensionSettingsStorage::Result result = storage->Set("foo", bar);
77 ASSERT_FALSE(result.HasError()); 77 ASSERT_FALSE(result.HasError());
78 78
79 result = storage->Get(); 79 result = storage->Get();
80 ASSERT_FALSE(result.HasError()); 80 ASSERT_FALSE(result.HasError());
81 EXPECT_FALSE(result.GetSettings()->empty()); 81 EXPECT_FALSE(result.GetSettings()->empty());
82 82
83 frontend_.reset(new ExtensionSettingsFrontend(temp_dir_.path())); 83 frontend_.reset(new ExtensionSettingsFrontend(profile_.get()));
84 GetBackend(&backend); 84 GetBackend(&backend);
85 storage = backend->GetStorage(id); 85 storage = backend->GetStorage(id);
86 86
87 result = storage->Get(); 87 result = storage->Get();
88 ASSERT_FALSE(result.HasError()); 88 ASSERT_FALSE(result.HasError());
89 EXPECT_FALSE(result.GetSettings()->empty()); 89 EXPECT_FALSE(result.GetSettings()->empty());
90 } 90 }
91 91
92 TEST_F(ExtensionSettingsFrontendTest, SettingsClearedOnUninstall) { 92 TEST_F(ExtensionSettingsFrontendTest, SettingsClearedOnUninstall) {
93 ExtensionSettingsBackend* backend; 93 ExtensionSettingsBackend* backend;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 ASSERT_FALSE(result.HasError()); 128 ASSERT_FALSE(result.HasError());
129 EXPECT_TRUE(file_util::PathExists(temp_dir_.path())); 129 EXPECT_TRUE(file_util::PathExists(temp_dir_.path()));
130 130
131 frontend_.reset(); 131 frontend_.reset();
132 MessageLoop::current()->RunAllPending(); 132 MessageLoop::current()->RunAllPending();
133 // TODO(kalman): Figure out why this fails, despite appearing to work. 133 // TODO(kalman): Figure out why this fails, despite appearing to work.
134 // Leaving this commented out rather than disabling the whole test so that the 134 // Leaving this commented out rather than disabling the whole test so that the
135 // deletion code paths are at least exercised. 135 // deletion code paths are at least exercised.
136 //EXPECT_FALSE(file_util::PathExists(temp_dir_.path())); 136 //EXPECT_FALSE(file_util::PathExists(temp_dir_.path()));
137 } 137 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698