Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / restore_on_startup_browsertest_chromeos.cc
blob570427db0359583cc6bbea552b095dc7520f8bee
1 // Copyright 2015 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.
5 #include "base/command_line.h"
6 #include "base/macros.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/values.h"
9 #include "chrome/browser/chrome_notification_types.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 "chrome/common/chrome_switches.h"
17 #include "content/public/browser/notification_service.h"
18 #include "content/public/browser/web_contents.h"
19 #include "content/public/test/test_utils.h"
20 #include "policy/policy_constants.h"
21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "url/gurl.h"
24 namespace policy {
26 namespace {
27 const char kStartUpURL1[] = "chrome://chrome/";
28 const char kStartUpURL2[] = "chrome://version/";
31 // Verifies that the |kRestoreOnStartup| and |kRestoreOnStartupURLs| policies
32 // are honored on Chrome OS.
33 class RestoreOnStartupTestChromeOS : public LoginPolicyTestBase {
34 public:
35 RestoreOnStartupTestChromeOS();
37 // LoginPolicyTestBase:
38 void SetUpCommandLine(base::CommandLine* command_line) override;
39 void GetMandatoryPoliciesValue(base::DictionaryValue* policy) const override;
41 void LogInAndVerifyStartUpURLs();
43 private:
44 DISALLOW_COPY_AND_ASSIGN(RestoreOnStartupTestChromeOS);
47 RestoreOnStartupTestChromeOS::RestoreOnStartupTestChromeOS() {
50 void RestoreOnStartupTestChromeOS::SetUpCommandLine(
51 base::CommandLine* command_line) {
52 LoginPolicyTestBase::SetUpCommandLine(command_line);
53 command_line->AppendSwitch(switches::kDisableChildAccountDetection);
56 void RestoreOnStartupTestChromeOS::GetMandatoryPoliciesValue(
57 base::DictionaryValue* policy) const {
58 policy->SetInteger(key::kRestoreOnStartup,
59 SessionStartupPref::kPrefValueURLs);
60 scoped_ptr<base::ListValue> urls(new base::ListValue);
61 urls->AppendString(kStartUpURL1);
62 urls->AppendString(kStartUpURL2);
63 policy->Set(key::kRestoreOnStartupURLs, urls.Pass());
66 void RestoreOnStartupTestChromeOS::LogInAndVerifyStartUpURLs() {
67 LogIn(kAccountId, kAccountPassword);
69 const BrowserList* const browser_list =
70 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
71 ASSERT_EQ(1U, browser_list->size());
72 const Browser* const browser = browser_list->get(0);
73 ASSERT_TRUE(browser);
74 const TabStripModel* tabs = browser->tab_strip_model();
75 ASSERT_TRUE(tabs);
76 ASSERT_EQ(2, tabs->count());
77 EXPECT_EQ(GURL(kStartUpURL1), tabs->GetWebContentsAt(0)->GetURL());
78 EXPECT_EQ(GURL(kStartUpURL2), tabs->GetWebContentsAt(1)->GetURL());
81 // Verify that the policies are honored on a new user's login.
82 IN_PROC_BROWSER_TEST_F(RestoreOnStartupTestChromeOS, PRE_LogInAndVerify) {
83 SkipToLoginScreen();
84 LogInAndVerifyStartUpURLs();
87 // Verify that the policies are honored on an existing user's login.
88 IN_PROC_BROWSER_TEST_F(RestoreOnStartupTestChromeOS, LogInAndVerify) {
89 content::WindowedNotificationObserver(
90 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
91 content::NotificationService::AllSources()).Wait();
92 LogInAndVerifyStartUpURLs();
95 } // namespace policy