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
3 // found in the LICENSE file.
7 #include "base/macros.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/values.h"
10 #include "chrome/browser/chromeos/policy/login_policy_test_base.h"
11 #include "chrome/browser/prefs/session_startup_pref.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_list.h"
14 #include "chrome/browser/ui/host_desktop.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "policy/policy_constants.h"
20 class UserCloudPolicyManagerTest
: public LoginPolicyTestBase
{
22 UserCloudPolicyManagerTest() {}
24 void GetMandatoryPoliciesValue(base::DictionaryValue
* policy
) const override
{
25 scoped_ptr
<base::ListValue
> list(new base::ListValue
);
26 list
->AppendString("chrome://policy");
27 list
->AppendString("chrome://about");
29 policy
->Set(key::kRestoreOnStartupURLs
, list
.Pass());
30 policy
->SetInteger(key::kRestoreOnStartup
,
31 SessionStartupPref::kPrefValueURLs
);
35 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerTest
);
38 IN_PROC_BROWSER_TEST_F(UserCloudPolicyManagerTest
, StartSession
) {
39 const char* const kStartupURLs
[] = {"chrome://policy", "chrome://about"};
42 LogIn(kAccountId
, kAccountPassword
);
44 // Check that the startup pages specified in policy were opened.
45 BrowserList
* browser_list
=
46 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH
);
47 EXPECT_EQ(1U, browser_list
->size());
48 Browser
* browser
= browser_list
->get(0);
51 TabStripModel
* tabs
= browser
->tab_strip_model();
53 const int expected_tab_count
= static_cast<int>(arraysize(kStartupURLs
));
54 EXPECT_EQ(expected_tab_count
, tabs
->count());
55 for (int i
= 0; i
< expected_tab_count
&& i
< tabs
->count(); ++i
) {
56 EXPECT_EQ(GURL(kStartupURLs
[i
]),
57 tabs
->GetWebContentsAt(i
)->GetVisibleURL());