Chromium Code Reviews| 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 | 6 #include "chrome/browser/chromeos/policy/login_policy_base_test.h" |
|
bartfab (slow)
2015/03/12 11:54:47
Nit: Add a blank line above.
peletskyi
2015/03/18 13:28:13
Done.
| |
| 7 #include "base/command_line.h" | |
| 8 #include "base/compiler_specific.h" | |
| 9 #include "base/files/file_path.h" | |
| 10 #include "base/files/file_util.h" | |
| 11 #include "base/files/scoped_temp_dir.h" | |
| 12 #include "base/macros.h" | |
|
bartfab (slow)
2015/03/12 11:54:47
Nit: Keep this.
peletskyi
2015/03/18 13:28:13
Done. Added DISALLOW_COPY_AND_ASSIGN
| |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/strings/stringprintf.h" | |
| 15 #include "chrome/browser/chrome_notification_types.h" | |
| 16 #include "chrome/browser/chromeos/login/test/oobe_base_test.h" | |
| 17 #include "chrome/browser/chromeos/login/wizard_controller.h" | |
| 18 #include "chrome/browser/policy/test/local_policy_test_server.h" | |
| 19 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/browser_list.h" | 8 #include "chrome/browser/ui/browser_list.h" |
| 21 #include "chrome/browser/ui/host_desktop.h" | |
|
bartfab (slow)
2015/03/12 11:54:47
Nit: Still used.
peletskyi
2015/03/18 13:28:13
Done.
| |
| 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 9 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 23 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" | |
| 24 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | |
| 25 #include "components/policy/core/common/policy_switches.h" | |
| 26 #include "content/public/browser/notification_service.h" | |
| 27 #include "content/public/test/test_utils.h" | |
| 28 #include "google_apis/gaia/fake_gaia.h" | |
| 29 #include "google_apis/gaia/gaia_constants.h" | |
| 30 #include "google_apis/gaia/gaia_urls.h" | |
| 31 #include "testing/gtest/include/gtest/gtest.h" | |
| 32 #include "url/gurl.h" | |
| 33 | 10 |
| 34 namespace policy { | 11 namespace policy { |
| 35 | 12 |
| 36 namespace { | 13 class UserCloudPolicyManagerTest : public LoginPolicyBaseTest { |
| 37 | 14 std::string GetPolicy() const override { |
|
bartfab (slow)
2015/03/12 11:54:47
Nit: Mark this as public: or protected:.
peletskyi
2015/03/18 13:28:13
Done.
| |
| 38 const char kAccountId[] = "dla1@example.com"; | 15 return std::string( |
| 39 const char kAccountPassword[] = "letmein"; | |
| 40 const char* const kStartupURLs[] = {"chrome://policy", "chrome://about"}; | |
| 41 const char kTestAuthCode[] = "fake-auth-code"; | |
| 42 const char kTestGaiaUberToken[] = "fake-uber-token"; | |
| 43 const char kTestAuthLoginAccessToken[] = "fake-access-token"; | |
| 44 const char kTestRefreshToken[] = "fake-refresh-token"; | |
| 45 const char kTestAuthSIDCookie[] = "fake-auth-SID-cookie"; | |
| 46 const char kTestAuthLSIDCookie[] = "fake-auth-LSID-cookie"; | |
| 47 const char kTestSessionSIDCookie[] = "fake-session-SID-cookie"; | |
| 48 const char kTestSessionLSIDCookie[] = "fake-session-LSID-cookie"; | |
| 49 const char kTestUserinfoToken[] = "fake-userinfo-token"; | |
| 50 | |
| 51 } // namespace | |
| 52 | |
| 53 class UserCloudPolicyManagerTest : public chromeos::OobeBaseTest { | |
| 54 protected: | |
| 55 UserCloudPolicyManagerTest() { | |
| 56 set_open_about_blank_on_browser_launch(false); | |
| 57 } | |
| 58 | |
| 59 ~UserCloudPolicyManagerTest() override {} | |
| 60 | |
| 61 void SetUp() override { | |
| 62 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
| 63 SetServerPolicy(); | |
| 64 | |
| 65 test_server_.reset(new LocalPolicyTestServer(policy_file_path())); | |
| 66 ASSERT_TRUE(test_server_->Start()); | |
| 67 | |
| 68 OobeBaseTest::SetUp(); | |
| 69 } | |
| 70 | |
| 71 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 72 command_line->AppendSwitchASCII(policy::switches::kDeviceManagementUrl, | |
| 73 test_server_->GetServiceURL().spec()); | |
| 74 OobeBaseTest::SetUpCommandLine(command_line); | |
| 75 } | |
| 76 | |
| 77 void SetUpOnMainThread() override { | |
| 78 SetMergeSessionParams(kAccountId); | |
| 79 SetupGaiaServerWithAccessTokens(); | |
| 80 OobeBaseTest::SetUpOnMainThread(); | |
| 81 } | |
| 82 | |
| 83 void SetupGaiaServerWithAccessTokens() { | |
| 84 FakeGaia::AccessTokenInfo token_info; | |
| 85 token_info.token = kTestUserinfoToken; | |
| 86 token_info.scopes.insert(GaiaConstants::kDeviceManagementServiceOAuth); | |
| 87 token_info.scopes.insert(GaiaConstants::kOAuthWrapBridgeUserInfoScope); | |
| 88 token_info.audience = GaiaUrls::GetInstance()->oauth2_chrome_client_id(); | |
| 89 token_info.email = kAccountId; | |
| 90 fake_gaia_->IssueOAuthToken(kTestRefreshToken, token_info); | |
| 91 } | |
| 92 | |
| 93 void SetMergeSessionParams(const std::string& email) { | |
| 94 FakeGaia::MergeSessionParams params; | |
| 95 params.auth_sid_cookie = kTestAuthSIDCookie; | |
| 96 params.auth_lsid_cookie = kTestAuthLSIDCookie; | |
| 97 params.auth_code = kTestAuthCode; | |
| 98 params.refresh_token = kTestRefreshToken; | |
| 99 params.access_token = kTestAuthLoginAccessToken; | |
| 100 params.gaia_uber_token = kTestGaiaUberToken; | |
| 101 params.session_sid_cookie = kTestSessionSIDCookie; | |
| 102 params.session_lsid_cookie = kTestSessionLSIDCookie; | |
| 103 params.email = email; | |
| 104 fake_gaia_->SetMergeSessionParams(params); | |
| 105 } | |
| 106 | |
| 107 void SkipToLoginScreen() { | |
| 108 chromeos::WizardController::SkipPostLoginScreensForTesting(); | |
| 109 chromeos::WizardController* wizard_controller = | |
| 110 chromeos::WizardController::default_controller(); | |
| 111 ASSERT_TRUE(wizard_controller); | |
| 112 wizard_controller->SkipToLoginForTesting(chromeos::LoginScreenContext()); | |
| 113 | |
| 114 content::WindowedNotificationObserver( | |
| 115 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | |
| 116 content::NotificationService::AllSources()).Wait(); | |
| 117 } | |
| 118 | |
| 119 void LogIn(const std::string& user_id, const std::string& password) { | |
| 120 GetLoginDisplay()->ShowSigninScreenForCreds(user_id, password); | |
| 121 | |
| 122 content::WindowedNotificationObserver( | |
| 123 chrome::NOTIFICATION_SESSION_STARTED, | |
| 124 content::NotificationService::AllSources()).Wait(); | |
| 125 } | |
| 126 | |
| 127 void SetServerPolicy() { | |
| 128 const char kPolicy[] = | |
| 129 "{" | 16 "{" |
| 130 " \"%s\": {" | 17 " \"%s\": {" |
| 131 " \"mandatory\": {" | 18 " \"mandatory\": {" |
| 132 " \"RestoreOnStartup\": 4," | 19 " \"RestoreOnStartup\": 4," |
| 133 " \"RestoreOnStartupURLs\": [" | 20 " \"RestoreOnStartupURLs\": [" |
| 134 " \"chrome://policy\"," | 21 " \"chrome://policy\"," |
| 135 " \"chrome://about\"" | 22 " \"chrome://about\"" |
| 136 " ]" | 23 " ]" |
| 137 " }," | 24 " }," |
| 138 " \"recommended\": {}" | 25 " \"recommended\": {}" |
| 139 " }," | 26 " }," |
| 140 " \"managed_users\": [ \"*\" ]," | 27 " \"managed_users\": [ \"*\" ]," |
| 141 " \"policy_user\": \"%s\"," | 28 " \"policy_user\": \"%s\"," |
| 142 " \"current_key_index\": 0" | 29 " \"current_key_index\": 0" |
| 143 "}"; | 30 "}"); |
| 144 | |
| 145 const std::string policy = base::StringPrintf( | |
| 146 kPolicy, dm_protocol::kChromeUserPolicyType, kAccountId); | |
| 147 | |
| 148 const int bytes_written = | |
| 149 base::WriteFile(policy_file_path(), policy.data(), policy.size()); | |
| 150 ASSERT_EQ(static_cast<int>(policy.size()), bytes_written); | |
| 151 } | 31 } |
| 152 | |
| 153 base::FilePath policy_file_path() const { | |
| 154 return temp_dir_.path().AppendASCII("policy.json"); | |
| 155 } | |
| 156 | |
| 157 scoped_ptr<LocalPolicyTestServer> test_server_; | |
| 158 | |
| 159 base::ScopedTempDir temp_dir_; | |
| 160 | |
| 161 private: | |
| 162 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerTest); | |
|
bartfab (slow)
2015/03/12 11:54:47
Nit: Keep this.
peletskyi
2015/03/18 13:28:13
Done.
| |
| 163 }; | 32 }; |
| 164 | 33 |
| 165 IN_PROC_BROWSER_TEST_F(UserCloudPolicyManagerTest, StartSession) { | 34 IN_PROC_BROWSER_TEST_F(UserCloudPolicyManagerTest, StartSession) { |
| 35 const char* const kStartupURLs[] = {"chrome://policy", "chrome://about"}; | |
| 166 SkipToLoginScreen(); | 36 SkipToLoginScreen(); |
| 167 | 37 |
| 168 LogIn(kAccountId, kAccountPassword); | 38 LogIn(kAccountId, kAccountPassword); |
| 169 | 39 |
| 170 // Check that the startup pages specified in policy were opened. | 40 // Check that the startup pages specified in policy were opened. |
| 171 BrowserList* browser_list = | 41 BrowserList* browser_list = |
| 172 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); | 42 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); |
| 173 EXPECT_EQ(1U, browser_list->size()); | 43 EXPECT_EQ(1U, browser_list->size()); |
| 174 Browser* browser = browser_list->get(0); | 44 Browser* browser = browser_list->get(0); |
| 175 ASSERT_TRUE(browser); | 45 ASSERT_TRUE(browser); |
| 176 | 46 |
| 177 TabStripModel* tabs = browser->tab_strip_model(); | 47 TabStripModel* tabs = browser->tab_strip_model(); |
| 178 ASSERT_TRUE(tabs); | 48 ASSERT_TRUE(tabs); |
| 179 const int expected_tab_count = static_cast<int>(arraysize(kStartupURLs)); | 49 const int expected_tab_count = static_cast<int>(arraysize(kStartupURLs)); |
| 180 EXPECT_EQ(expected_tab_count, tabs->count()); | 50 EXPECT_EQ(expected_tab_count, tabs->count()); |
| 181 for (int i = 0; i < expected_tab_count && i < tabs->count(); ++i) { | 51 for (int i = 0; i < expected_tab_count && i < tabs->count(); ++i) { |
| 182 EXPECT_EQ(GURL(kStartupURLs[i]), | 52 EXPECT_EQ(GURL(kStartupURLs[i]), |
| 183 tabs->GetWebContentsAt(i)->GetVisibleURL()); | 53 tabs->GetWebContentsAt(i)->GetVisibleURL()); |
| 184 } | 54 } |
| 185 } | 55 } |
| 186 | 56 |
| 187 } // namespace policy | 57 } // namespace policy |
| OLD | NEW |