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

Side by Side Diff: chrome/browser/policy/asynchronous_policy_test_base.h

Issue 5562002: Refactor FileBasedPolicyProvider, introduce AsynchronousPolicyProvider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove extra provider in tests Created 10 years 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
(Empty)
1 // Copyright (c) 2010 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_POLICY_ASYNCHRONOUS_POLICY_TEST_BASE_H_
6 #define CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_TEST_BASE_H_
7 #pragma once
8
9 #include "base/message_loop.h"
10 #include "base/time.h"
11 #include "chrome/browser/browser_thread.h"
12 #include "chrome/browser/policy/asynchronous_policy_provider.h"
13 #include "chrome/browser/policy/configuration_policy_provider.h"
14 #include "chrome/browser/policy/mock_configuration_policy_store.h"
15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 namespace policy {
19
20 // A delegate for testing that can feed arbitrary information to the loader.
21 class ProviderDelegateMock : public AsynchronousPolicyProvider::Delegate {
22 public:
23 ProviderDelegateMock() : AsynchronousPolicyProvider::Delegate() {}
24 virtual ~ProviderDelegateMock() {}
25
26 MOCK_METHOD1(Init, void(AsynchronousPolicyProvider::PolicyChangeObserver*));
27 MOCK_METHOD0(Stop, void());
28 MOCK_METHOD0(Load, DictionaryValue*());
29 MOCK_METHOD2(IsSafeToReloadPolicy, bool(const base::Time&, base::TimeDelta*));
30
31 private:
32 DISALLOW_COPY_AND_ASSIGN(ProviderDelegateMock);
33 };
34
35 class AsynchronousPolicyTestBase : public testing::Test {
36 public:
37 AsynchronousPolicyTestBase()
38 : run_pending_during_tear_down_(true),
39 ui_thread_(BrowserThread::UI, &loop_),
40 file_thread_(BrowserThread::FILE, &loop_) {}
41
42 virtual ~AsynchronousPolicyTestBase() {}
43
44 virtual void SetUp() {
45 delegate_.reset(new ProviderDelegateMock());
46 store_.reset(new MockConfigurationPolicyStore);
47 }
48
49 virtual void TearDown() {
50 provider_.reset(NULL);
51 if (run_pending_during_tear_down_)
52 loop_.RunAllPending();
53 }
54
55 void DontRunAllPendingDuringTearDown() {
56 run_pending_during_tear_down_ = false;
57 }
58
59 protected:
60 MessageLoop loop_;
61 scoped_ptr<ConfigurationPolicyProvider> provider_;
62
63 // The mocks that are used in the test must outlive the scope of the test
64 // because they still get accessed in the RunAllPending of the TearDown.
65 scoped_ptr<MockConfigurationPolicyStore> store_;
66 scoped_ptr<ProviderDelegateMock> delegate_;
67
68 private:
69 // True if a test guarantees that it's handled all tasks pending in the
70 // message loop and doesn't want RunAllPending run during TearDown.
71 bool run_pending_during_tear_down_;
72 BrowserThread ui_thread_;
73 BrowserThread file_thread_;
74
75 DISALLOW_COPY_AND_ASSIGN(AsynchronousPolicyTestBase);
76 };
77
78 inline static void MessageLoopQuitNow() {
79 MessageLoop::current()->QuitNow();
80 }
81
82 } // namespace policy
83
84 #endif // CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_TEST_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698