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

Side by Side Diff: chrome/browser/policy/asynchronous_policy_loader_unittest.cc

Issue 6091002: Refactor the windows policy provider to use AsynchronousPolicyProvider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix windows tests Created 9 years, 12 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) 2010 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/policy/asynchronous_policy_loader.h" 5 #include "chrome/browser/policy/asynchronous_policy_loader.h"
6 #include "chrome/browser/policy/asynchronous_policy_provider.h" 6 #include "chrome/browser/policy/asynchronous_policy_provider.h"
7 #include "chrome/browser/policy/asynchronous_policy_test_base.h" 7 #include "chrome/browser/policy/asynchronous_policy_test_base.h"
8 #include "chrome/browser/policy/mock_configuration_policy_provider.h" 8 #include "chrome/browser/policy/mock_configuration_policy_provider.h"
9 #include "chrome/common/notification_observer_mock.h" 9 #include "chrome/common/notification_observer_mock.h"
10 #include "chrome/common/notification_registrar.h" 10 #include "chrome/common/notification_registrar.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 ACTION(RescheduleImmediatePolicyReload) { 47 ACTION(RescheduleImmediatePolicyReload) {
48 *arg1 = base::TimeDelta(); 48 *arg1 = base::TimeDelta();
49 return false; 49 return false;
50 } 50 }
51 51
52 TEST_F(AsynchronousPolicyLoaderTest, InitialLoad) { 52 TEST_F(AsynchronousPolicyLoaderTest, InitialLoad) {
53 DictionaryValue* template_dict(new DictionaryValue()); 53 DictionaryValue* template_dict(new DictionaryValue());
54 EXPECT_CALL(*delegate_, Load()).WillOnce(Return(template_dict)); 54 EXPECT_CALL(*delegate_, Load()).WillOnce(Return(template_dict));
55 scoped_refptr<AsynchronousPolicyLoader> loader = 55 scoped_refptr<AsynchronousPolicyLoader> loader =
56 new AsynchronousPolicyLoader(delegate_.release()); 56 new AsynchronousPolicyLoader(delegate_.release(), 10);
57 loader->Init(); 57 loader->Init();
58 const DictionaryValue* loaded_dict(loader->policy()); 58 const DictionaryValue* loaded_dict(loader->policy());
59 EXPECT_TRUE(loaded_dict->Equals(template_dict)); 59 EXPECT_TRUE(loaded_dict->Equals(template_dict));
60 } 60 }
61 61
62 // Verify that the fallback policy requests are made. 62 // Verify that the fallback policy requests are made.
63 TEST_F(AsynchronousPolicyLoaderTest, InitialLoadWithFallback) { 63 TEST_F(AsynchronousPolicyLoaderTest, InitialLoadWithFallback) {
64 int dictionary_number = 0; 64 int dictionary_number = 0;
65 InSequence s; 65 InSequence s;
66 EXPECT_CALL(*delegate_, Load()).WillOnce( 66 EXPECT_CALL(*delegate_, Load()).WillOnce(
67 CreateSequencedTestDictionary(&dictionary_number)); 67 CreateSequencedTestDictionary(&dictionary_number));
68 EXPECT_CALL(*delegate_, Load()).WillOnce( 68 EXPECT_CALL(*delegate_, Load()).WillOnce(
69 CreateSequencedTestDictionary(&dictionary_number)); 69 CreateSequencedTestDictionary(&dictionary_number));
70 scoped_refptr<AsynchronousPolicyLoader> loader = 70 scoped_refptr<AsynchronousPolicyLoader> loader =
71 new AsynchronousPolicyLoader(delegate_.release()); 71 new AsynchronousPolicyLoader(delegate_.release(), 10);
72 loader->Init(); 72 loader->Init();
73 loop_.RunAllPending(); 73 loop_.RunAllPending();
74 loader->Reload(); 74 loader->Reload();
75 loop_.RunAllPending(); 75 loop_.RunAllPending();
76 76
77 const DictionaryValue* loaded_dict(loader->policy()); 77 const DictionaryValue* loaded_dict(loader->policy());
78 int loaded_number; 78 int loaded_number;
79 EXPECT_TRUE(loaded_dict->GetInteger("id", &loaded_number)); 79 EXPECT_TRUE(loaded_dict->GetInteger("id", &loaded_number));
80 EXPECT_EQ(dictionary_number, loaded_number); 80 EXPECT_EQ(dictionary_number, loaded_number);
81 } 81 }
82 82
83 // Ensure that calling stop on the loader stops subsequent reloads from 83 // Ensure that calling stop on the loader stops subsequent reloads from
84 // happening. 84 // happening.
85 TEST_F(AsynchronousPolicyLoaderTest, Stop) { 85 TEST_F(AsynchronousPolicyLoaderTest, Stop) {
86 ON_CALL(*delegate_, Load()).WillByDefault(CreateTestDictionary()); 86 ON_CALL(*delegate_, Load()).WillByDefault(CreateTestDictionary());
87 EXPECT_CALL(*delegate_, Load()).Times(1); 87 EXPECT_CALL(*delegate_, Load()).Times(1);
88 scoped_refptr<AsynchronousPolicyLoader> loader = 88 scoped_refptr<AsynchronousPolicyLoader> loader =
89 new AsynchronousPolicyLoader(delegate_.release()); 89 new AsynchronousPolicyLoader(delegate_.release(), 10);
90 loader->Init(); 90 loader->Init();
91 loop_.RunAllPending(); 91 loop_.RunAllPending();
92 loader->Stop(); 92 loader->Stop();
93 loop_.RunAllPending(); 93 loop_.RunAllPending();
94 loader->Reload(); 94 loader->Reload();
95 loop_.RunAllPending(); 95 loop_.RunAllPending();
96 } 96 }
97 97
98 // Verifies that the provider is notified upon policy reload, but only 98 // Verifies that the provider is notified upon policy reload, but only
99 // if the policy changed. 99 // if the policy changed.
(...skipping 11 matching lines...) Expand all
111 CreateSequencedTestDictionary(&dictionary_number_1)); 111 CreateSequencedTestDictionary(&dictionary_number_1));
112 EXPECT_CALL(*delegate_, Load()).WillOnce( 112 EXPECT_CALL(*delegate_, Load()).WillOnce(
113 CreateSequencedTestDictionary(&dictionary_number_2)); 113 CreateSequencedTestDictionary(&dictionary_number_2));
114 EXPECT_CALL(observer, Observe(_, _, _)).Times(0); 114 EXPECT_CALL(observer, Observe(_, _, _)).Times(0);
115 EXPECT_CALL(*delegate_, Load()).WillOnce( 115 EXPECT_CALL(*delegate_, Load()).WillOnce(
116 CreateSequencedTestDictionary(&dictionary_number_2)); 116 CreateSequencedTestDictionary(&dictionary_number_2));
117 EXPECT_CALL(observer, Observe(_, _, _)).Times(1); 117 EXPECT_CALL(observer, Observe(_, _, _)).Times(1);
118 EXPECT_CALL(*delegate_, Load()).WillOnce( 118 EXPECT_CALL(*delegate_, Load()).WillOnce(
119 CreateSequencedTestDictionary(&dictionary_number_1)); 119 CreateSequencedTestDictionary(&dictionary_number_1));
120 scoped_refptr<AsynchronousPolicyLoader> loader = 120 scoped_refptr<AsynchronousPolicyLoader> loader =
121 new AsynchronousPolicyLoader(delegate_.release()); 121 new AsynchronousPolicyLoader(delegate_.release(), 10);
122 AsynchronousPolicyProvider provider(NULL, loader); 122 AsynchronousPolicyProvider provider(NULL, loader);
123 loop_.RunAllPending(); 123 loop_.RunAllPending();
124 loader->Reload(); 124 loader->Reload();
125 loop_.RunAllPending(); 125 loop_.RunAllPending();
126 loader->Reload(); 126 loader->Reload();
127 loop_.RunAllPending(); 127 loop_.RunAllPending();
128 loader->Reload(); 128 loader->Reload();
129 loop_.RunAllPending(); 129 loop_.RunAllPending();
130 } 130 }
131 131
132 } // namespace policy 132 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/asynchronous_policy_loader.cc ('k') | chrome/browser/policy/asynchronous_policy_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698