Chromium Code Reviews| Index: chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos_browsertest.cc |
| diff --git a/chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos_browsertest.cc b/chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..af63b391e08e86c17237dc0b23502f6b8533a2ce |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos_browsertest.cc |
| @@ -0,0 +1,166 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
|
bartfab (slow)
2014/07/07 17:40:12
Nit: It's 2014 :).
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/strings/stringprintf.h" |
| +#include "chrome/browser/chromeos/login/test/oobe_base_test.h" |
| +#include "chrome/browser/chromeos/login/wizard_controller.h" |
| +#include "chrome/browser/policy/test/local_policy_test_server.h" |
| +#include "chrome/browser/ui/browser_list.h" |
| +#include "chrome/browser/ui/tabs/tab_strip_model.h" |
| +#include "components/policy/core/common/policy_switches.h" |
| +#include "google_apis/gaia/gaia_constants.h" |
| +#include "google_apis/gaia/gaia_urls.h" |
| + |
| +namespace policy { |
| + |
| +namespace { |
| + |
| +const char kAccountId[] = "dla1@example.com"; |
| +const char kAccountPassword[] = "letmein"; |
| +const char* kStartupURLs[] = {"chrome://policy", "chrome://about"}; |
| +const char kTestAuthCode[] = "fake-auth-code"; |
| +const char kTestGaiaUberToken[] = "fake-uber-token"; |
| +const char kTestAuthLoginAccessToken[] = "fake-access-token"; |
| +const char kTestRefreshToken[] = "fake-refresh-token"; |
| +const char kTestAuthSIDCookie[] = "fake-auth-SID-cookie"; |
| +const char kTestAuthLSIDCookie[] = "fake-auth-LSID-cookie"; |
| +const char kTestSessionSIDCookie[] = "fake-session-SID-cookie"; |
| +const char kTestSessionLSIDCookie[] = "fake-session-LSID-cookie"; |
| +const char kTestUserinfoToken[] = "fake-userinfo-token"; |
| + |
| +} // namespace |
| + |
| +class UserCloudPolicyManagerTest : public chromeos::OobeBaseTest { |
| + protected: |
| + UserCloudPolicyManagerTest() { |
| + set_open_about_blank_on_browser_launch(false); |
| + } |
| + |
| + virtual ~UserCloudPolicyManagerTest() {} |
| + |
| + virtual void SetUp() OVERRIDE { |
|
bartfab (slow)
2014/07/07 17:40:12
Nit: #include "base/compiler_specific.h"
|
| + ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
|
bartfab (slow)
2014/07/07 17:40:11
#include "testing/gtest/include/gtest/gtest.h"
|
| + SetServerPolicy(); |
| + |
| + test_server_.reset(new LocalPolicyTestServer(policy_file_path())); |
| + ASSERT_TRUE(test_server_->Start()); |
| + |
| + OobeBaseTest::SetUp(); |
| + } |
| + |
| + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| + OobeBaseTest::SetUpCommandLine(command_line); |
| + command_line->AppendSwitchASCII(policy::switches::kDeviceManagementUrl, |
|
bartfab (slow)
2014/07/07 17:40:12
Nit: #include "base/command_line.h"
|
| + test_server_->GetServiceURL().spec()); |
|
bartfab (slow)
2014/07/07 17:40:12
#include "url/gurl.h"
|
| + SetMergeSessionParams(kAccountId); |
| + SetupGaiaServerWithAccessTokens(); |
|
bartfab (slow)
2014/07/07 17:40:11
Why are these two calls in SetUpCommandLine()? The
|
| + } |
| + |
| + void SetupGaiaServerWithAccessTokens() { |
| + FakeGaia::AccessTokenInfo token_info; |
|
bartfab (slow)
2014/07/07 17:40:13
#include "google_apis/gaia/fake_gaia.h"
|
| + token_info.token = kTestUserinfoToken; |
| + token_info.scopes.insert(GaiaConstants::kDeviceManagementServiceOAuth); |
| + token_info.scopes.insert(GaiaConstants::kOAuthWrapBridgeUserInfoScope); |
| + token_info.audience = GaiaUrls::GetInstance()->oauth2_chrome_client_id(); |
| + token_info.email = kAccountId; |
| + fake_gaia_->IssueOAuthToken(kTestRefreshToken, token_info); |
| + } |
| + |
| + void SetMergeSessionParams(const std::string& email) { |
| + FakeGaia::MergeSessionParams params; |
| + params.auth_sid_cookie = kTestAuthSIDCookie; |
| + params.auth_lsid_cookie = kTestAuthLSIDCookie; |
| + params.auth_code = kTestAuthCode; |
| + params.refresh_token = kTestRefreshToken; |
| + params.access_token = kTestAuthLoginAccessToken; |
| + params.gaia_uber_token = kTestGaiaUberToken; |
| + params.session_sid_cookie = kTestSessionSIDCookie; |
| + params.session_lsid_cookie = kTestSessionLSIDCookie; |
| + params.email = email; |
| + fake_gaia_->SetMergeSessionParams(params); |
| + } |
| + |
| + void SkipToLoginScreen() { |
| + chromeos::WizardController::SkipPostLoginScreensForTesting(); |
| + chromeos::WizardController* wizard_controller = |
| + chromeos::WizardController::default_controller(); |
| + CHECK(wizard_controller); |
|
bartfab (slow)
2014/07/07 17:40:12
Nit: s/CHECK/ASSERT_TRUE/
|
| + wizard_controller->SkipToLoginForTesting(chromeos::LoginScreenContext()); |
|
bartfab (slow)
2014/07/07 17:40:12
Nit: #include "chrome/browser/ui/webui/chromeos/lo
|
| + |
| + content::WindowedNotificationObserver( |
|
bartfab (slow)
2014/07/07 17:40:13
#include "content/public/test/test_utils.h"
|
| + chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
| + content::NotificationService::AllSources()).Wait(); |
| + } |
| + |
| + void Login(const std::string username, const std::string password) { |
|
bartfab (slow)
2014/07/07 17:40:12
Nit 1: s/Login/LogIn/ (verb in the imperative form
|
| + GetLoginDisplay()->ShowSigninScreenForCreds(username, password); |
| + |
| + content::WindowedNotificationObserver( |
| + chrome::NOTIFICATION_SESSION_STARTED, |
|
bartfab (slow)
2014/07/07 17:40:11
#include "chrome/browser/chrome_notification_types
|
| + content::NotificationService::AllSources()).Wait(); |
|
bartfab (slow)
2014/07/07 17:40:12
#include "content/public/browser/notification_serv
|
| + } |
| + |
| + void SetServerPolicy() { |
| + const char kEmptyPolicy[] = |
|
bartfab (slow)
2014/07/07 17:40:11
Nit: Rename the constant. This policy is not empty
|
| + "{" |
| + " \"%s\": {" |
| + " \"mandatory\": {" |
| + " \"ShowHomeButton\": true," |
|
bartfab (slow)
2014/07/07 17:40:12
Nit: Is this necessary?
|
| + " \"RestoreOnStartup\": 4," |
| + " \"RestoreOnStartupURLs\": [" |
| + " \"chrome://policy\"," |
| + " \"chrome://about\"" |
| + " ]" |
| + " }," |
| + " \"recommended\": {}" |
| + " }," |
| + " \"managed_users\": [ \"*\" ]," |
| + " \"policy_user\": \"%s\"," |
| + " \"current_key_index\": 0" |
| + "}"; |
| + |
| + std::string policy = base::StringPrintf( |
|
bartfab (slow)
2014/07/07 17:40:13
Nit 1: const.
Nit 2: #include <string>
|
| + kEmptyPolicy, dm_protocol::kChromeUserPolicyType, kAccountId); |
|
bartfab (slow)
2014/07/07 17:40:12
#include "components/policy/core/common/cloud/clou
|
| + |
| + int result = |
|
bartfab (slow)
2014/07/07 17:40:12
Nit 1: const.
Nit 2: s/result/bytes_written/
|
| + base::WriteFile(policy_file_path(), policy.data(), policy.size()); |
|
bartfab (slow)
2014/07/07 17:40:11
Nit: #include "base/file_util.h"
|
| + ASSERT_EQ(static_cast<int>(policy.size()), result); |
| + } |
| + |
| + base::FilePath policy_file_path() const { |
|
bartfab (slow)
2014/07/07 17:40:11
Nit: #include "base/files/file_path.h"
|
| + return temp_dir_.path().AppendASCII("policy.json"); |
| + } |
| + |
| + protected: |
|
bartfab (slow)
2014/07/07 17:40:12
Nit: You are in a protected block already.
|
| + scoped_ptr<LocalPolicyTestServer> test_server_; |
|
bartfab (slow)
2014/07/07 17:40:13
Nit: #include "base/memory/scoped_ptr.h"
|
| + |
| + base::ScopedTempDir temp_dir_; |
|
bartfab (slow)
2014/07/07 17:40:11
Nit: #include "base/files/scoped_temp_dir.h"
|
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerTest); |
|
bartfab (slow)
2014/07/07 17:40:12
Nit: #include "base/macros.h"
|
| +}; |
| + |
| +IN_PROC_BROWSER_TEST_F(UserCloudPolicyManagerTest, StartSession) { |
| + SkipToLoginScreen(); |
| + |
| + Login(kAccountId, kAccountPassword); |
| + |
| + // Check that the startup pages specified in policy were opened. |
| + BrowserList* browser_list = |
| + BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); |
|
bartfab (slow)
2014/07/07 17:40:12
Nit: #include "chrome/browser/ui/host_desktop.h"
|
| + EXPECT_EQ(1U, browser_list->size()); |
| + Browser* browser = browser_list->get(0); |
|
bartfab (slow)
2014/07/07 17:40:11
Nit: #include "chrome/browser/ui/browser.h"
|
| + ASSERT_TRUE(browser); |
| + |
| + TabStripModel* tabs = browser->tab_strip_model(); |
| + ASSERT_TRUE(tabs); |
| + int expected_tab_count = static_cast<int>(arraysize(kStartupURLs)); |
|
bartfab (slow)
2014/07/07 17:40:12
Nit: const.
|
| + EXPECT_EQ(expected_tab_count, tabs->count()); |
| + for (int i = 0; i < expected_tab_count && i < tabs->count(); ++i) { |
| + EXPECT_EQ(GURL(kStartupURLs[i]), |
| + tabs->GetWebContentsAt(i)->GetVisibleURL()); |
| + } |
| +} |
| + |
| +} // namespace policy |