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

Side by Side Diff: chrome/browser/chromeos/policy/blocking_login_browsertest.cc

Issue 1083683003: Speculative revert by sheriff (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed an unrelated commit that had accidentally slipped in. Created 5 years, 8 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/chrome_notification_types.h" 13 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/chromeos/login/existing_user_controller.h" 14 #include "chrome/browser/chromeos/login/existing_user_controller.h"
15 #include "chrome/browser/chromeos/login/test/oobe_base_test.h"
16 #include "chrome/browser/chromeos/login/ui/webui_login_display.h" 15 #include "chrome/browser/chromeos/login/ui/webui_login_display.h"
17 #include "chrome/browser/chromeos/login/wizard_controller.h" 16 #include "chrome/browser/chromeos/login/wizard_controller.h"
18 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 17 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
19 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" 18 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h"
20 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" 19 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
21 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
22 #include "chrome/test/base/in_process_browser_test.h" 21 #include "chrome/test/base/in_process_browser_test.h"
23 #include "chromeos/chromeos_switches.h" 22 #include "chromeos/chromeos_switches.h"
24 #include "components/policy/core/common/cloud/device_management_service.h" 23 #include "components/policy/core/common/cloud/device_management_service.h"
25 #include "components/policy/core/common/policy_switches.h" 24 #include "components/policy/core/common/policy_switches.h"
26 #include "components/user_manager/user_manager.h" 25 #include "components/user_manager/user_manager.h"
27 #include "content/public/browser/notification_observer.h" 26 #include "content/public/browser/notification_observer.h"
28 #include "content/public/browser/notification_registrar.h" 27 #include "content/public/browser/notification_registrar.h"
29 #include "content/public/browser/notification_service.h" 28 #include "content/public/browser/notification_service.h"
30 #include "content/public/test/test_utils.h" 29 #include "content/public/test/test_utils.h"
30 #include "google_apis/gaia/fake_gaia.h"
31 #include "google_apis/gaia/gaia_switches.h" 31 #include "google_apis/gaia/gaia_switches.h"
32 #include "google_apis/gaia/gaia_urls.h" 32 #include "google_apis/gaia/gaia_urls.h"
33 #include "net/http/http_status_code.h" 33 #include "net/http/http_status_code.h"
34 #include "net/test/embedded_test_server/embedded_test_server.h" 34 #include "net/test/embedded_test_server/embedded_test_server.h"
35 #include "net/test/embedded_test_server/http_request.h" 35 #include "net/test/embedded_test_server/http_request.h"
36 #include "net/test/embedded_test_server/http_response.h" 36 #include "net/test/embedded_test_server/http_response.h"
37 #include "policy/proto/device_management_backend.pb.h" 37 #include "policy/proto/device_management_backend.pb.h"
38 #include "testing/gtest/include/gtest/gtest.h" 38 #include "testing/gtest/include/gtest/gtest.h"
39 39
40 namespace chromeos { 40 namespace chromeos {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 74
75 } // namespace 75 } // namespace
76 76
77 struct BlockingLoginTestParam { 77 struct BlockingLoginTestParam {
78 const int steps; 78 const int steps;
79 const char* username; 79 const char* username;
80 const bool enroll_device; 80 const bool enroll_device;
81 }; 81 };
82 82
83 class BlockingLoginTest 83 class BlockingLoginTest
84 : public OobeBaseTest, 84 : public InProcessBrowserTest,
85 public content::NotificationObserver, 85 public content::NotificationObserver,
86 public testing::WithParamInterface<BlockingLoginTestParam> { 86 public testing::WithParamInterface<BlockingLoginTestParam> {
87 public: 87 public:
88 BlockingLoginTest() : profile_added_(NULL) {} 88 BlockingLoginTest() : profile_added_(NULL) {}
89 89
90 void SetUpCommandLine(base::CommandLine* command_line) override { 90 void SetUpCommandLine(base::CommandLine* command_line) override {
91 OobeBaseTest::SetUpCommandLine(command_line); 91 // Initialize the test server early, so that we can use its base url for
92 // the command line flags.
93 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
92 94
95 // Use the login manager screens and the gaia auth extension.
96 command_line->AppendSwitch(switches::kLoginManager);
97 command_line->AppendSwitch(switches::kForceLoginManagerInTests);
98 command_line->AppendSwitchASCII(switches::kLoginProfile, "user");
93 command_line->AppendSwitchASCII(::switches::kAuthExtensionPath, 99 command_line->AppendSwitchASCII(::switches::kAuthExtensionPath,
94 "gaia_auth"); 100 "gaia_auth");
101
102 // Redirect requests to gaia and the policy server to the test server.
103 command_line->AppendSwitchASCII(::switches::kGaiaUrl,
104 embedded_test_server()->base_url().spec());
105 command_line->AppendSwitchASCII(::switches::kLsoUrl,
106 embedded_test_server()->base_url().spec());
95 command_line->AppendSwitchASCII( 107 command_line->AppendSwitchASCII(
96 policy::switches::kDeviceManagementUrl, 108 policy::switches::kDeviceManagementUrl,
97 embedded_test_server()->GetURL("/device_management").spec()); 109 embedded_test_server()->GetURL("/device_management").spec());
98 } 110 }
99 111
100 void SetUpOnMainThread() override { 112 void SetUpOnMainThread() override {
113 fake_gaia_.Initialize();
114
115 embedded_test_server()->RegisterRequestHandler(
116 base::Bind(&BlockingLoginTest::HandleRequest, base::Unretained(this)));
117 embedded_test_server()->RegisterRequestHandler(
118 base::Bind(&FakeGaia::HandleRequest, base::Unretained(&fake_gaia_)));
119
101 registrar_.Add(this, 120 registrar_.Add(this,
102 chrome::NOTIFICATION_PROFILE_ADDED, 121 chrome::NOTIFICATION_PROFILE_ADDED,
103 content::NotificationService::AllSources()); 122 content::NotificationService::AllSources());
104
105 OobeBaseTest::SetUpOnMainThread();
106 } 123 }
107 124
108 void TearDownOnMainThread() override { 125 void TearDownOnMainThread() override {
109 RunUntilIdle(); 126 RunUntilIdle();
110 EXPECT_TRUE(responses_.empty()); 127 EXPECT_TRUE(responses_.empty());
111 STLDeleteElements(&responses_); 128 STLDeleteElements(&responses_);
112 OobeBaseTest::TearDownOnMainThread(); 129 EXPECT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete());
113 } 130 }
114 131
115 void Observe(int type, 132 void Observe(int type,
116 const content::NotificationSource& source, 133 const content::NotificationSource& source,
117 const content::NotificationDetails& details) override { 134 const content::NotificationDetails& details) override {
118 ASSERT_EQ(chrome::NOTIFICATION_PROFILE_ADDED, type); 135 ASSERT_EQ(chrome::NOTIFICATION_PROFILE_ADDED, type);
119 ASSERT_FALSE(profile_added_); 136 ASSERT_FALSE(profile_added_);
120 profile_added_ = content::Source<Profile>(source).ptr(); 137 profile_added_ = content::Source<Profile>(source).ptr();
121 } 138 }
122 139
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 // Returns the body of the fetch response from the policy server. 238 // Returns the body of the fetch response from the policy server.
222 std::string GetPolicyResponse() { 239 std::string GetPolicyResponse() {
223 em::DeviceManagementResponse response; 240 em::DeviceManagementResponse response;
224 response.mutable_policy_response()->add_response(); 241 response.mutable_policy_response()->add_response();
225 std::string data; 242 std::string data;
226 EXPECT_TRUE(response.SerializeToString(&data)); 243 EXPECT_TRUE(response.SerializeToString(&data));
227 return data; 244 return data;
228 } 245 }
229 246
230 protected: 247 protected:
231 void RegisterAdditionalRequestHandlers() override {
232 embedded_test_server()->RegisterRequestHandler(
233 base::Bind(&BlockingLoginTest::HandleRequest, base::Unretained(this)));
234 }
235
236 Profile* profile_added_; 248 Profile* profile_added_;
237 249
238 private: 250 private:
251 FakeGaia fake_gaia_;
239 std::vector<net::test_server::HttpResponse*> responses_; 252 std::vector<net::test_server::HttpResponse*> responses_;
240 content::NotificationRegistrar registrar_; 253 content::NotificationRegistrar registrar_;
241 254
242 DISALLOW_COPY_AND_ASSIGN(BlockingLoginTest); 255 DISALLOW_COPY_AND_ASSIGN(BlockingLoginTest);
243 }; 256 };
244 257
245 IN_PROC_BROWSER_TEST_P(BlockingLoginTest, LoginBlocksForUser) { 258 IN_PROC_BROWSER_TEST_P(BlockingLoginTest, LoginBlocksForUser) {
246 // Verify that there isn't a logged in user when the test starts. 259 // Verify that there isn't a logged in user when the test starts.
247 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); 260 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
248 EXPECT_FALSE(user_manager->IsUserLoggedIn()); 261 EXPECT_FALSE(user_manager->IsUserLoggedIn());
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 { 3, kUsernameOtherDomain, true }, 347 { 3, kUsernameOtherDomain, true },
335 { 4, kUsernameOtherDomain, true }, 348 { 4, kUsernameOtherDomain, true },
336 { 5, kUsernameOtherDomain, true }, 349 { 5, kUsernameOtherDomain, true },
337 }; 350 };
338 351
339 INSTANTIATE_TEST_CASE_P(BlockingLoginTestInstance, 352 INSTANTIATE_TEST_CASE_P(BlockingLoginTestInstance,
340 BlockingLoginTest, 353 BlockingLoginTest,
341 testing::ValuesIn(kBlockinLoginTestCases)); 354 testing::ValuesIn(kBlockinLoginTestCases));
342 355
343 } // namespace chromeos 356 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/wizard_controller_browsertest.cc ('k') | chrome/browser/resources/extensions/extension_list.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698