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

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

Issue 330843002: Make the policy fetch for first time login blocking (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fixes a build error on android Created 6 years, 5 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
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
bartfab (slow) 2014/07/07 17:40:12 Nit: It's 2014 :).
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/strings/stringprintf.h"
6 #include "chrome/browser/chromeos/login/test/oobe_base_test.h"
7 #include "chrome/browser/chromeos/login/wizard_controller.h"
8 #include "chrome/browser/policy/test/local_policy_test_server.h"
9 #include "chrome/browser/ui/browser_list.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
11 #include "components/policy/core/common/policy_switches.h"
12 #include "google_apis/gaia/gaia_constants.h"
13 #include "google_apis/gaia/gaia_urls.h"
14
15 namespace policy {
16
17 namespace {
18
19 const char kAccountId[] = "dla1@example.com";
20 const char kAccountPassword[] = "letmein";
21 const char* kStartupURLs[] = {"chrome://policy", "chrome://about"};
22 const char kTestAuthCode[] = "fake-auth-code";
23 const char kTestGaiaUberToken[] = "fake-uber-token";
24 const char kTestAuthLoginAccessToken[] = "fake-access-token";
25 const char kTestRefreshToken[] = "fake-refresh-token";
26 const char kTestAuthSIDCookie[] = "fake-auth-SID-cookie";
27 const char kTestAuthLSIDCookie[] = "fake-auth-LSID-cookie";
28 const char kTestSessionSIDCookie[] = "fake-session-SID-cookie";
29 const char kTestSessionLSIDCookie[] = "fake-session-LSID-cookie";
30 const char kTestUserinfoToken[] = "fake-userinfo-token";
31
32 } // namespace
33
34 class UserCloudPolicyManagerTest : public chromeos::OobeBaseTest {
35 protected:
36 UserCloudPolicyManagerTest() {
37 set_open_about_blank_on_browser_launch(false);
38 }
39
40 virtual ~UserCloudPolicyManagerTest() {}
41
42 virtual void SetUp() OVERRIDE {
bartfab (slow) 2014/07/07 17:40:12 Nit: #include "base/compiler_specific.h"
43 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
bartfab (slow) 2014/07/07 17:40:11 #include "testing/gtest/include/gtest/gtest.h"
44 SetServerPolicy();
45
46 test_server_.reset(new LocalPolicyTestServer(policy_file_path()));
47 ASSERT_TRUE(test_server_->Start());
48
49 OobeBaseTest::SetUp();
50 }
51
52 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
53 OobeBaseTest::SetUpCommandLine(command_line);
54 command_line->AppendSwitchASCII(policy::switches::kDeviceManagementUrl,
bartfab (slow) 2014/07/07 17:40:12 Nit: #include "base/command_line.h"
55 test_server_->GetServiceURL().spec());
bartfab (slow) 2014/07/07 17:40:12 #include "url/gurl.h"
56 SetMergeSessionParams(kAccountId);
57 SetupGaiaServerWithAccessTokens();
bartfab (slow) 2014/07/07 17:40:11 Why are these two calls in SetUpCommandLine()? The
58 }
59
60 void SetupGaiaServerWithAccessTokens() {
61 FakeGaia::AccessTokenInfo token_info;
bartfab (slow) 2014/07/07 17:40:13 #include "google_apis/gaia/fake_gaia.h"
62 token_info.token = kTestUserinfoToken;
63 token_info.scopes.insert(GaiaConstants::kDeviceManagementServiceOAuth);
64 token_info.scopes.insert(GaiaConstants::kOAuthWrapBridgeUserInfoScope);
65 token_info.audience = GaiaUrls::GetInstance()->oauth2_chrome_client_id();
66 token_info.email = kAccountId;
67 fake_gaia_->IssueOAuthToken(kTestRefreshToken, token_info);
68 }
69
70 void SetMergeSessionParams(const std::string& email) {
71 FakeGaia::MergeSessionParams params;
72 params.auth_sid_cookie = kTestAuthSIDCookie;
73 params.auth_lsid_cookie = kTestAuthLSIDCookie;
74 params.auth_code = kTestAuthCode;
75 params.refresh_token = kTestRefreshToken;
76 params.access_token = kTestAuthLoginAccessToken;
77 params.gaia_uber_token = kTestGaiaUberToken;
78 params.session_sid_cookie = kTestSessionSIDCookie;
79 params.session_lsid_cookie = kTestSessionLSIDCookie;
80 params.email = email;
81 fake_gaia_->SetMergeSessionParams(params);
82 }
83
84 void SkipToLoginScreen() {
85 chromeos::WizardController::SkipPostLoginScreensForTesting();
86 chromeos::WizardController* wizard_controller =
87 chromeos::WizardController::default_controller();
88 CHECK(wizard_controller);
bartfab (slow) 2014/07/07 17:40:12 Nit: s/CHECK/ASSERT_TRUE/
89 wizard_controller->SkipToLoginForTesting(chromeos::LoginScreenContext());
bartfab (slow) 2014/07/07 17:40:12 Nit: #include "chrome/browser/ui/webui/chromeos/lo
90
91 content::WindowedNotificationObserver(
bartfab (slow) 2014/07/07 17:40:13 #include "content/public/test/test_utils.h"
92 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
93 content::NotificationService::AllSources()).Wait();
94 }
95
96 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
97 GetLoginDisplay()->ShowSigninScreenForCreds(username, password);
98
99 content::WindowedNotificationObserver(
100 chrome::NOTIFICATION_SESSION_STARTED,
bartfab (slow) 2014/07/07 17:40:11 #include "chrome/browser/chrome_notification_types
101 content::NotificationService::AllSources()).Wait();
bartfab (slow) 2014/07/07 17:40:12 #include "content/public/browser/notification_serv
102 }
103
104 void SetServerPolicy() {
105 const char kEmptyPolicy[] =
bartfab (slow) 2014/07/07 17:40:11 Nit: Rename the constant. This policy is not empty
106 "{"
107 " \"%s\": {"
108 " \"mandatory\": {"
109 " \"ShowHomeButton\": true,"
bartfab (slow) 2014/07/07 17:40:12 Nit: Is this necessary?
110 " \"RestoreOnStartup\": 4,"
111 " \"RestoreOnStartupURLs\": ["
112 " \"chrome://policy\","
113 " \"chrome://about\""
114 " ]"
115 " },"
116 " \"recommended\": {}"
117 " },"
118 " \"managed_users\": [ \"*\" ],"
119 " \"policy_user\": \"%s\","
120 " \"current_key_index\": 0"
121 "}";
122
123 std::string policy = base::StringPrintf(
bartfab (slow) 2014/07/07 17:40:13 Nit 1: const. Nit 2: #include <string>
124 kEmptyPolicy, dm_protocol::kChromeUserPolicyType, kAccountId);
bartfab (slow) 2014/07/07 17:40:12 #include "components/policy/core/common/cloud/clou
125
126 int result =
bartfab (slow) 2014/07/07 17:40:12 Nit 1: const. Nit 2: s/result/bytes_written/
127 base::WriteFile(policy_file_path(), policy.data(), policy.size());
bartfab (slow) 2014/07/07 17:40:11 Nit: #include "base/file_util.h"
128 ASSERT_EQ(static_cast<int>(policy.size()), result);
129 }
130
131 base::FilePath policy_file_path() const {
bartfab (slow) 2014/07/07 17:40:11 Nit: #include "base/files/file_path.h"
132 return temp_dir_.path().AppendASCII("policy.json");
133 }
134
135 protected:
bartfab (slow) 2014/07/07 17:40:12 Nit: You are in a protected block already.
136 scoped_ptr<LocalPolicyTestServer> test_server_;
bartfab (slow) 2014/07/07 17:40:13 Nit: #include "base/memory/scoped_ptr.h"
137
138 base::ScopedTempDir temp_dir_;
bartfab (slow) 2014/07/07 17:40:11 Nit: #include "base/files/scoped_temp_dir.h"
139
140 private:
141 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerTest);
bartfab (slow) 2014/07/07 17:40:12 Nit: #include "base/macros.h"
142 };
143
144 IN_PROC_BROWSER_TEST_F(UserCloudPolicyManagerTest, StartSession) {
145 SkipToLoginScreen();
146
147 Login(kAccountId, kAccountPassword);
148
149 // Check that the startup pages specified in policy were opened.
150 BrowserList* browser_list =
151 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
bartfab (slow) 2014/07/07 17:40:12 Nit: #include "chrome/browser/ui/host_desktop.h"
152 EXPECT_EQ(1U, browser_list->size());
153 Browser* browser = browser_list->get(0);
bartfab (slow) 2014/07/07 17:40:11 Nit: #include "chrome/browser/ui/browser.h"
154 ASSERT_TRUE(browser);
155
156 TabStripModel* tabs = browser->tab_strip_model();
157 ASSERT_TRUE(tabs);
158 int expected_tab_count = static_cast<int>(arraysize(kStartupURLs));
bartfab (slow) 2014/07/07 17:40:12 Nit: const.
159 EXPECT_EQ(expected_tab_count, tabs->count());
160 for (int i = 0; i < expected_tab_count && i < tabs->count(); ++i) {
161 EXPECT_EQ(GURL(kStartupURLs[i]),
162 tabs->GetWebContentsAt(i)->GetVisibleURL());
163 }
164 }
165
166 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698