1// Copyright (c) 2012 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#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_UNITTEST_H_
6#define CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_UNITTEST_H_
7
8#include "base/message_loop/message_loop.h"
9#include "chrome/browser/extensions/test_extension_prefs.h"
10#include "content/public/test/test_browser_thread.h"
11#include "testing/gtest/include/gtest/gtest.h"
12
13namespace base {
14class Value;
15}
16
17namespace user_prefs {
18class PrefRegistrySyncable;
19}
20
21namespace extensions {
22class Extension;
23
24// Base class for extension preference-related unit tests.
25class ExtensionPrefsTest : public testing::Test {
26 public:
27  ExtensionPrefsTest();
28  virtual ~ExtensionPrefsTest();
29
30  // This function will get called once, and is the right place to do operations
31  // on ExtensionPrefs that write data.
32  virtual void Initialize() = 0;
33
34  // This function will be called twice - once while the original ExtensionPrefs
35  // object is still alive, and once after recreation. Thus, it tests that
36  // things don't break after any ExtensionPrefs startup work.
37  virtual void Verify() = 0;
38
39  // This function is called to Register preference default values.
40  virtual void RegisterPreferences(user_prefs::PrefRegistrySyncable* registry);
41
42  virtual void SetUp() OVERRIDE;
43
44  virtual void TearDown() OVERRIDE;
45
46 protected:
47  ExtensionPrefs* prefs() { return prefs_.prefs(); }
48
49  base::MessageLoop message_loop_;
50  content::TestBrowserThread ui_thread_;
51
52  TestExtensionPrefs prefs_;
53
54 private:
55  DISALLOW_COPY_AND_ASSIGN(ExtensionPrefsTest);
56};
57
58
59class PrefsPrepopulatedTestBase : public ExtensionPrefsTest {
60 public:
61  static const size_t kNumInstalledExtensions = 4;
62
63  PrefsPrepopulatedTestBase();
64  virtual ~PrefsPrepopulatedTestBase();
65
66  Extension* extension1() { return extension1_.get(); }
67  Extension* extension2() { return extension2_.get(); }
68  Extension* extension3() { return extension3_.get(); }
69  Extension* extension4() { return extension4_.get(); }
70
71 protected:
72  bool installed_[kNumInstalledExtensions];
73
74  scoped_refptr<Extension> extension1_;
75  scoped_refptr<Extension> extension2_;
76  scoped_refptr<Extension> extension3_;
77  scoped_refptr<Extension> extension4_;
78
79 private:
80  DISALLOW_COPY_AND_ASSIGN(PrefsPrepopulatedTestBase);
81};
82
83}  // namespace extensions
84
85#endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_UNITTEST_H_
86