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 // Boolean parameter is used to run this test for webview (true) and for
21 // iframe (false) GAIA sign in.
22 class UserCloudPolicyManagerTest
: public LoginPolicyTestBase
,
23 public testing::WithParamInterface
<bool> {
25 UserCloudPolicyManagerTest() : LoginPolicyTestBase() {
26 set_use_webview(GetParam());
29 void GetMandatoryPoliciesValue(base::DictionaryValue
* policy
) const override
{
30 scoped_ptr
<base::ListValue
> list(new base::ListValue
);
31 list
->AppendString("chrome://policy");
32 list
->AppendString("chrome://about");
34 policy
->Set(key::kRestoreOnStartupURLs
, list
.Pass());
35 policy
->SetInteger(key::kRestoreOnStartup
,
36 SessionStartupPref::kPrefValueURLs
);
40 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerTest
);
43 IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest
, StartSession
) {
44 const char* const kStartupURLs
[] = {"chrome://policy", "chrome://about"};
47 LogIn(kAccountId
, kAccountPassword
);
49 // Check that the startup pages specified in policy were opened.
50 BrowserList
* browser_list
=
51 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH
);
52 EXPECT_EQ(1U, browser_list
->size());
53 Browser
* browser
= browser_list
->get(0);
56 TabStripModel
* tabs
= browser
->tab_strip_model();
58 const int expected_tab_count
= static_cast<int>(arraysize(kStartupURLs
));
59 EXPECT_EQ(expected_tab_count
, tabs
->count());
60 for (int i
= 0; i
< expected_tab_count
&& i
< tabs
->count(); ++i
) {
61 EXPECT_EQ(GURL(kStartupURLs
[i
]),
62 tabs
->GetWebContentsAt(i
)->GetVisibleURL());
66 INSTANTIATE_TEST_CASE_P(UserCloudPolicyManagerTestSuite
,
67 UserCloudPolicyManagerTest
,