| OLD | NEW |
| 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" |
| 15 #include "chrome/browser/chromeos/login/ui/webui_login_display.h" | 16 #include "chrome/browser/chromeos/login/ui/webui_login_display.h" |
| 16 #include "chrome/browser/chromeos/login/wizard_controller.h" | 17 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 17 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 18 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 18 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | 19 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |
| 19 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" | 20 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" |
| 20 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 21 #include "chrome/test/base/in_process_browser_test.h" | 22 #include "chrome/test/base/in_process_browser_test.h" |
| 22 #include "chromeos/chromeos_switches.h" | 23 #include "chromeos/chromeos_switches.h" |
| 23 #include "components/policy/core/common/cloud/device_management_service.h" | 24 #include "components/policy/core/common/cloud/device_management_service.h" |
| 24 #include "components/policy/core/common/policy_switches.h" | 25 #include "components/policy/core/common/policy_switches.h" |
| 25 #include "components/user_manager/user_manager.h" | 26 #include "components/user_manager/user_manager.h" |
| 26 #include "content/public/browser/notification_observer.h" | 27 #include "content/public/browser/notification_observer.h" |
| 27 #include "content/public/browser/notification_registrar.h" | 28 #include "content/public/browser/notification_registrar.h" |
| 28 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
| 29 #include "content/public/test/test_utils.h" | 30 #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 Loading... |
| 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 InProcessBrowserTest, | 84 : public OobeBaseTest, |
| 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 // Initialize the test server early, so that we can use its base url for | 91 OobeBaseTest::SetUpCommandLine(command_line); |
| 92 // the command line flags. | |
| 93 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | |
| 94 | 92 |
| 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"); | |
| 99 command_line->AppendSwitchASCII(::switches::kAuthExtensionPath, | 93 command_line->AppendSwitchASCII(::switches::kAuthExtensionPath, |
| 100 "gaia_auth"); | 94 "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()); | |
| 107 command_line->AppendSwitchASCII( | 95 command_line->AppendSwitchASCII( |
| 108 policy::switches::kDeviceManagementUrl, | 96 policy::switches::kDeviceManagementUrl, |
| 109 embedded_test_server()->GetURL("/device_management").spec()); | 97 embedded_test_server()->GetURL("/device_management").spec()); |
| 110 } | 98 } |
| 111 | 99 |
| 112 void SetUpOnMainThread() override { | 100 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 | |
| 120 registrar_.Add(this, | 101 registrar_.Add(this, |
| 121 chrome::NOTIFICATION_PROFILE_ADDED, | 102 chrome::NOTIFICATION_PROFILE_ADDED, |
| 122 content::NotificationService::AllSources()); | 103 content::NotificationService::AllSources()); |
| 104 |
| 105 OobeBaseTest::SetUpOnMainThread(); |
| 123 } | 106 } |
| 124 | 107 |
| 125 void TearDownOnMainThread() override { | 108 void TearDownOnMainThread() override { |
| 126 RunUntilIdle(); | 109 RunUntilIdle(); |
| 127 EXPECT_TRUE(responses_.empty()); | 110 EXPECT_TRUE(responses_.empty()); |
| 128 STLDeleteElements(&responses_); | 111 STLDeleteElements(&responses_); |
| 129 EXPECT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete()); | 112 OobeBaseTest::TearDownOnMainThread(); |
| 130 } | 113 } |
| 131 | 114 |
| 132 void Observe(int type, | 115 void Observe(int type, |
| 133 const content::NotificationSource& source, | 116 const content::NotificationSource& source, |
| 134 const content::NotificationDetails& details) override { | 117 const content::NotificationDetails& details) override { |
| 135 ASSERT_EQ(chrome::NOTIFICATION_PROFILE_ADDED, type); | 118 ASSERT_EQ(chrome::NOTIFICATION_PROFILE_ADDED, type); |
| 136 ASSERT_FALSE(profile_added_); | 119 ASSERT_FALSE(profile_added_); |
| 137 profile_added_ = content::Source<Profile>(source).ptr(); | 120 profile_added_ = content::Source<Profile>(source).ptr(); |
| 138 } | 121 } |
| 139 | 122 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 // Returns the body of the fetch response from the policy server. | 221 // Returns the body of the fetch response from the policy server. |
| 239 std::string GetPolicyResponse() { | 222 std::string GetPolicyResponse() { |
| 240 em::DeviceManagementResponse response; | 223 em::DeviceManagementResponse response; |
| 241 response.mutable_policy_response()->add_response(); | 224 response.mutable_policy_response()->add_response(); |
| 242 std::string data; | 225 std::string data; |
| 243 EXPECT_TRUE(response.SerializeToString(&data)); | 226 EXPECT_TRUE(response.SerializeToString(&data)); |
| 244 return data; | 227 return data; |
| 245 } | 228 } |
| 246 | 229 |
| 247 protected: | 230 protected: |
| 231 void RegisterAdditionalRequestHandlers() override { |
| 232 embedded_test_server()->RegisterRequestHandler( |
| 233 base::Bind(&BlockingLoginTest::HandleRequest, base::Unretained(this))); |
| 234 } |
| 235 |
| 248 Profile* profile_added_; | 236 Profile* profile_added_; |
| 249 | 237 |
| 250 private: | 238 private: |
| 251 FakeGaia fake_gaia_; | |
| 252 std::vector<net::test_server::HttpResponse*> responses_; | 239 std::vector<net::test_server::HttpResponse*> responses_; |
| 253 content::NotificationRegistrar registrar_; | 240 content::NotificationRegistrar registrar_; |
| 254 | 241 |
| 255 DISALLOW_COPY_AND_ASSIGN(BlockingLoginTest); | 242 DISALLOW_COPY_AND_ASSIGN(BlockingLoginTest); |
| 256 }; | 243 }; |
| 257 | 244 |
| 258 IN_PROC_BROWSER_TEST_P(BlockingLoginTest, LoginBlocksForUser) { | 245 IN_PROC_BROWSER_TEST_P(BlockingLoginTest, LoginBlocksForUser) { |
| 259 // Verify that there isn't a logged in user when the test starts. | 246 // Verify that there isn't a logged in user when the test starts. |
| 260 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 247 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| 261 EXPECT_FALSE(user_manager->IsUserLoggedIn()); | 248 EXPECT_FALSE(user_manager->IsUserLoggedIn()); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 { 3, kUsernameOtherDomain, true }, | 334 { 3, kUsernameOtherDomain, true }, |
| 348 { 4, kUsernameOtherDomain, true }, | 335 { 4, kUsernameOtherDomain, true }, |
| 349 { 5, kUsernameOtherDomain, true }, | 336 { 5, kUsernameOtherDomain, true }, |
| 350 }; | 337 }; |
| 351 | 338 |
| 352 INSTANTIATE_TEST_CASE_P(BlockingLoginTestInstance, | 339 INSTANTIATE_TEST_CASE_P(BlockingLoginTestInstance, |
| 353 BlockingLoginTest, | 340 BlockingLoginTest, |
| 354 testing::ValuesIn(kBlockinLoginTestCases)); | 341 testing::ValuesIn(kBlockinLoginTestCases)); |
| 355 | 342 |
| 356 } // namespace chromeos | 343 } // namespace chromeos |
| OLD | NEW |