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

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

Issue 12235003: Split out policy code from net/tools/testserver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Saving a file, sherlock? ;) Created 7 years, 10 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) 2012 The Chromium Authors. All rights reserved. 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 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 "base/base_paths.h" 5 #include "base/base_paths.h"
Joao da Silva 2013/02/12 19:06:05 remove
Mattias Nissler (ping if slow) 2013/02/13 11:54:10 Done.
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
Joao da Silva 2013/02/12 19:06:05 remove
Mattias Nissler (ping if slow) 2013/02/13 11:54:10 Done.
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/policy/browser_policy_connector.h" 15 #include "chrome/browser/policy/browser_policy_connector.h"
16 #include "chrome/browser/policy/cloud_policy_client.h" 16 #include "chrome/browser/policy/cloud_policy_client.h"
17 #include "chrome/browser/policy/cloud_policy_constants.h" 17 #include "chrome/browser/policy/cloud_policy_constants.h"
18 #include "chrome/browser/policy/policy_map.h" 18 #include "chrome/browser/policy/policy_map.h"
19 #include "chrome/browser/policy/policy_service.h" 19 #include "chrome/browser/policy/policy_service.h"
20 #include "chrome/browser/policy/proto/chrome_settings.pb.h" 20 #include "chrome/browser/policy/proto/chrome_settings.pb.h"
21 #include "chrome/browser/policy/proto/cloud_policy.pb.h" 21 #include "chrome/browser/policy/proto/cloud_policy.pb.h"
22 #include "chrome/browser/policy/test/local_policy_test_server.h"
22 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/ui/browser.h" 24 #include "chrome/browser/ui/browser.h"
24 #include "chrome/common/chrome_notification_types.h" 25 #include "chrome/common/chrome_notification_types.h"
25 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
26 #include "chrome/test/base/in_process_browser_test.h" 27 #include "chrome/test/base/in_process_browser_test.h"
27 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
28 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
29 #include "content/public/browser/notification_source.h" 30 #include "content/public/browser/notification_source.h"
30 #include "content/public/test/test_utils.h" 31 #include "content/public/test/test_utils.h"
31 #include "googleurl/src/gurl.h" 32 #include "googleurl/src/gurl.h"
32 #include "net/test/test_server.h"
33 #include "policy/policy_constants.h" 33 #include "policy/policy_constants.h"
34 #include "testing/gmock/include/gmock/gmock.h" 34 #include "testing/gmock/include/gmock/gmock.h"
35 #include "testing/gtest/include/gtest/gtest.h" 35 #include "testing/gtest/include/gtest/gtest.h"
36 36
37 #if defined(OS_CHROMEOS) 37 #if defined(OS_CHROMEOS)
38 #include "chrome/browser/chromeos/login/user_manager.h" 38 #include "chrome/browser/chromeos/login/user_manager.h"
39 #include "chrome/browser/policy/user_cloud_policy_manager_chromeos.h" 39 #include "chrome/browser/policy/user_cloud_policy_manager_chromeos.h"
40 #else 40 #else
41 #include "chrome/browser/policy/user_cloud_policy_manager.h" 41 #include "chrome/browser/policy/user_cloud_policy_manager.h"
42 #include "chrome/browser/policy/user_cloud_policy_manager_factory.h" 42 #include "chrome/browser/policy/user_cloud_policy_manager_factory.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 110
111 } // namespace 111 } // namespace
112 112
113 // Tests the cloud policy stack(s). 113 // Tests the cloud policy stack(s).
114 class CloudPolicyTest : public InProcessBrowserTest { 114 class CloudPolicyTest : public InProcessBrowserTest {
115 protected: 115 protected:
116 CloudPolicyTest() {} 116 CloudPolicyTest() {}
117 virtual ~CloudPolicyTest() {} 117 virtual ~CloudPolicyTest() {}
118 118
119 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 119 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
120 // The TestServer wants the docroot as a path relative to the source dir. 120 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
121 base::FilePath source;
122 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &source));
123 ASSERT_TRUE(temp_dir_.CreateUniqueTempDirUnderPath(source));
124 ASSERT_NO_FATAL_FAILURE(SetServerPolicy(GetEmptyPolicy())); 121 ASSERT_NO_FATAL_FAILURE(SetServerPolicy(GetEmptyPolicy()));
125 122
126 test_server_.reset( 123 test_server_.reset(new LocalPolicyTestServer(policy_file_path()));
127 new net::TestServer(
128 net::TestServer::TYPE_HTTP,
129 net::TestServer::kLocalhost,
130 temp_dir_.path().BaseName()));
131 ASSERT_TRUE(test_server_->Start()); 124 ASSERT_TRUE(test_server_->Start());
132 125
133 std::string url = test_server_->GetURL("device_management").spec(); 126 std::string url = test_server_->GetURL("device_management").spec();
Joao da Silva 2013/02/12 19:06:05 GetServiceURL()?
Mattias Nissler (ping if slow) 2013/02/13 11:54:10 Done.
134 127
135 CommandLine* command_line = CommandLine::ForCurrentProcess(); 128 CommandLine* command_line = CommandLine::ForCurrentProcess();
136 command_line->AppendSwitchASCII(switches::kDeviceManagementUrl, url); 129 command_line->AppendSwitchASCII(switches::kDeviceManagementUrl, url);
137 } 130 }
138 131
139 virtual void SetUpOnMainThread() OVERRIDE { 132 virtual void SetUpOnMainThread() OVERRIDE {
140 // Checks that no policies have been loaded by the other providers before 133 // Checks that no policies have been loaded by the other providers before
141 // setting up the cloud connection. Other policies configured in the test 134 // setting up the cloud connection. Other policies configured in the test
142 // machine will interfere with these tests. 135 // machine will interfere with these tests.
143 const PolicyMap& map = g_browser_process->policy_service()->GetPolicies( 136 const PolicyMap& map = g_browser_process->policy_service()->GetPolicies(
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 177
185 // Give a bogus OAuth token to the |policy_manager|. This should make its 178 // Give a bogus OAuth token to the |policy_manager|. This should make its
186 // CloudPolicyClient fetch the DMToken. 179 // CloudPolicyClient fetch the DMToken.
187 policy_manager->RegisterClient("bogus"); 180 policy_manager->RegisterClient("bogus");
188 run_loop.Run(); 181 run_loop.Run();
189 Mock::VerifyAndClearExpectations(&observer); 182 Mock::VerifyAndClearExpectations(&observer);
190 policy_manager->core()->client()->RemoveObserver(&observer); 183 policy_manager->core()->client()->RemoveObserver(&observer);
191 } 184 }
192 185
193 void SetServerPolicy(const std::string& policy) { 186 void SetServerPolicy(const std::string& policy) {
194 int result = file_util::WriteFile( 187 int result = file_util::WriteFile(policy_file_path(), policy.data(),
195 temp_dir_.path().AppendASCII("device_management"), 188 policy.size());
196 policy.data(), policy.size());
197 ASSERT_EQ(static_cast<int>(policy.size()), result); 189 ASSERT_EQ(static_cast<int>(policy.size()), result);
198 } 190 }
199 191
192 FilePath policy_file_path() const {
193 return temp_dir_.path().AppendASCII("policy.json");
194 }
195
200 base::ScopedTempDir temp_dir_; 196 base::ScopedTempDir temp_dir_;
201 scoped_ptr<net::TestServer> test_server_; 197 scoped_ptr<net::TestServer> test_server_;
202 }; 198 };
203 199
204 IN_PROC_BROWSER_TEST_F(CloudPolicyTest, FetchPolicy) { 200 IN_PROC_BROWSER_TEST_F(CloudPolicyTest, FetchPolicy) {
205 PolicyService* policy_service = browser()->profile()->GetPolicyService(); 201 PolicyService* policy_service = browser()->profile()->GetPolicyService();
206 { 202 {
207 base::RunLoop run_loop; 203 base::RunLoop run_loop;
208 policy_service->RefreshPolicies(run_loop.QuitClosure()); 204 policy_service->RefreshPolicies(run_loop.QuitClosure());
209 run_loop.Run(); 205 run_loop.Run();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 276
281 // They should now serialize to the same bytes. 277 // They should now serialize to the same bytes.
282 std::string chrome_settings_serialized; 278 std::string chrome_settings_serialized;
283 std::string cloud_policy_serialized; 279 std::string cloud_policy_serialized;
284 ASSERT_TRUE(chrome_settings.SerializeToString(&chrome_settings_serialized)); 280 ASSERT_TRUE(chrome_settings.SerializeToString(&chrome_settings_serialized));
285 ASSERT_TRUE(cloud_policy.SerializeToString(&cloud_policy_serialized)); 281 ASSERT_TRUE(cloud_policy.SerializeToString(&cloud_policy_serialized));
286 EXPECT_EQ(chrome_settings_serialized, cloud_policy_serialized); 282 EXPECT_EQ(chrome_settings_serialized, cloud_policy_serialized);
287 } 283 }
288 284
289 } // namespace policy 285 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698