summaryrefslogtreecommitdiffstats
path: root/extensions/browser/extensions_test.h
blob: e930421a1e1c7fda437e560af79621c16643a393 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef EXTENSIONS_BROWSER_EXTENSIONS_TEST_H_
#define EXTENSIONS_BROWSER_EXTENSIONS_TEST_H_

#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "content/public/test/test_renderer_host.h"
#include "extensions/browser/mock_extension_system.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace content {
class BrowserContext;
class ContentBrowserClient;
class ContentClient;
class ContentUtilityClient;
class RenderViewHostTestEnabler;
}

namespace extensions {
class TestExtensionsBrowserClient;

// Base class for extensions module unit tests of browser process code. Sets up
// the content module and extensions module client interfaces. Initializes
// services for a browser context.
//
// NOTE: Use this class only in extensions_unittests, not in Chrome unit_tests.
// BrowserContextKeyedServiceFactory singletons persist between tests.
// In Chrome those factories assume any BrowserContext is a Profile and will
// cause crashes if it is not. http://crbug.com/395820
class ExtensionsTest : public testing::Test {
 public:
  ExtensionsTest();
  ~ExtensionsTest() override;

  // Returned as a BrowserContext since most users don't need methods from
  // TestBrowserContext.
  content::BrowserContext* browser_context() { return browser_context_.get(); }

  // Returned as a TestExtensionsBrowserClient since most users need to call
  // test-specific methods on it.
  TestExtensionsBrowserClient* extensions_browser_client() {
    return extensions_browser_client_.get();
  }

  // testing::Test overrides:
  void SetUp() override;
  void TearDown() override;

 private:
  // TODO(yoz): Add a NotificationService here; it's used widely enough.
  scoped_ptr<content::ContentClient> content_client_;
  scoped_ptr<content::ContentUtilityClient> content_utility_client_;
  scoped_ptr<content::ContentBrowserClient> content_browser_client_;
  scoped_ptr<content::BrowserContext> browser_context_;
  scoped_ptr<TestExtensionsBrowserClient> extensions_browser_client_;

  // The existence of this object enables tests via
  // RenderViewHostTester.
  content::RenderViewHostTestEnabler rvh_test_enabler_;

  MockExtensionSystemFactory<MockExtensionSystem> extension_system_factory_;

  DISALLOW_COPY_AND_ASSIGN(ExtensionsTest);
};

}  // namespace extensions

#endif  // EXTENSIONS_BROWSER_EXTENSIONS_TEST_H_