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

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

Issue 964503002: Implemented ForceMaximizeBrowserWindowOnFirstRun policy, added unit test and browser test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added JSONWriter and removed depricated function. 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 6
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" 7 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h" 8 #include "chrome/browser/chromeos/policy/login_policy_test_base.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" 9 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_list.h" 10 #include "chrome/browser/ui/browser_list.h"
21 #include "chrome/browser/ui/host_desktop.h" 11 #include "chrome/browser/ui/host_desktop.h"
22 #include "chrome/browser/ui/tabs/tab_strip_model.h" 12 #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 13
34 namespace policy { 14 namespace policy {
35 15
36 namespace { 16 class UserCloudPolicyManagerTest : public LoginPolicyTestBase {
17 protected:
18 UserCloudPolicyManagerTest() : LoginPolicyTestBase() {}
37 19
38 const char kAccountId[] = "dla1@example.com"; 20 base::DictionaryValue* GetMandatoryPoliciesValue() const override {
39 const char kAccountPassword[] = "letmein"; 21 base::ListValue* list = new base::ListValue;
bartfab (slow) 2015/04/02 13:29:32 Nit 1: Use a scoped_ptr. Nit 2: #include "base/val
peletskyi 2015/04/02 15:24:51 Done.
40 const char* const kStartupURLs[] = {"chrome://policy", "chrome://about"}; 22 list->AppendString("chrome://policy");
41 const char kTestAuthCode[] = "fake-auth-code"; 23 list->AppendString("chrome://about");
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 24
51 } // namespace 25 base::DictionaryValue* const dict = new base::DictionaryValue;
bartfab (slow) 2015/04/02 13:29:32 Nit: Use a scoped_ptr.
peletskyi 2015/04/02 15:24:51 Done.
26 dict->Set("RestoreOnStartupURLs", list);
bartfab (slow) 2015/04/02 13:29:32 Nit: You could improve the existing test a bit her
peletskyi 2015/04/02 15:24:51 Done.
bartfab (slow) 2015/04/07 11:37:16 What you did is great. I had missed it that there
peletskyi 2015/04/07 13:14:29 Done.
27 dict->SetInteger("RestoreOnStartup", 4);
52 28
53 class UserCloudPolicyManagerTest : public chromeos::OobeBaseTest { 29 return dict;
54 protected:
55 UserCloudPolicyManagerTest() {
56 set_open_about_blank_on_browser_launch(false);
57 } 30 }
58 31
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 "{"
130 " \"%s\": {"
131 " \"mandatory\": {"
132 " \"RestoreOnStartup\": 4,"
133 " \"RestoreOnStartupURLs\": ["
134 " \"chrome://policy\","
135 " \"chrome://about\""
136 " ]"
137 " },"
138 " \"recommended\": {}"
139 " },"
140 " \"managed_users\": [ \"*\" ],"
141 " \"policy_user\": \"%s\","
142 " \"current_key_index\": 0"
143 "}";
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 }
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: 32 private:
162 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerTest); 33 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerTest);
163 }; 34 };
164 35
165 IN_PROC_BROWSER_TEST_F(UserCloudPolicyManagerTest, StartSession) { 36 IN_PROC_BROWSER_TEST_F(UserCloudPolicyManagerTest, StartSession) {
37 const char* const kStartupURLs[] = {"chrome://policy", "chrome://about"};
38
166 SkipToLoginScreen(); 39 SkipToLoginScreen();
167
168 LogIn(kAccountId, kAccountPassword); 40 LogIn(kAccountId, kAccountPassword);
169 41
170 // Check that the startup pages specified in policy were opened. 42 // Check that the startup pages specified in policy were opened.
171 BrowserList* browser_list = 43 BrowserList* browser_list =
172 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); 44 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
173 EXPECT_EQ(1U, browser_list->size()); 45 EXPECT_EQ(1U, browser_list->size());
174 Browser* browser = browser_list->get(0); 46 Browser* browser = browser_list->get(0);
175 ASSERT_TRUE(browser); 47 ASSERT_TRUE(browser);
176 48
177 TabStripModel* tabs = browser->tab_strip_model(); 49 TabStripModel* tabs = browser->tab_strip_model();
178 ASSERT_TRUE(tabs); 50 ASSERT_TRUE(tabs);
179 const int expected_tab_count = static_cast<int>(arraysize(kStartupURLs)); 51 const int expected_tab_count = static_cast<int>(arraysize(kStartupURLs));
180 EXPECT_EQ(expected_tab_count, tabs->count()); 52 EXPECT_EQ(expected_tab_count, tabs->count());
181 for (int i = 0; i < expected_tab_count && i < tabs->count(); ++i) { 53 for (int i = 0; i < expected_tab_count && i < tabs->count(); ++i) {
182 EXPECT_EQ(GURL(kStartupURLs[i]), 54 EXPECT_EQ(GURL(kStartupURLs[i]),
183 tabs->GetWebContentsAt(i)->GetVisibleURL()); 55 tabs->GetWebContentsAt(i)->GetVisibleURL());
184 } 56 }
185 } 57 }
186 58
187 } // namespace policy 59 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698