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

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

Issue 1737453003: Revert of Reland: No longer start up profile if there was an error fetching policy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 #include <utility> 6 #include <utility>
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/run_loop.h"
11 #include "base/values.h" 10 #include "base/values.h"
12 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/chromeos/login/ui/webui_login_display.h"
14 #include "chrome/browser/chromeos/policy/login_policy_test_base.h" 11 #include "chrome/browser/chromeos/policy/login_policy_test_base.h"
15 #include "chrome/browser/chromeos/policy/user_policy_test_helper.h"
16 #include "chrome/browser/prefs/session_startup_pref.h" 12 #include "chrome/browser/prefs/session_startup_pref.h"
17 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/browser_list.h" 14 #include "chrome/browser/ui/browser_list.h"
19 #include "chrome/browser/ui/host_desktop.h" 15 #include "chrome/browser/ui/host_desktop.h"
20 #include "chrome/browser/ui/tabs/tab_strip_model.h" 16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
21 #include "components/user_manager/user.h"
22 #include "components/user_manager/user_manager.h"
23 #include "content/public/browser/notification_observer.h"
24 #include "content/public/browser/notification_registrar.h"
25 #include "content/public/browser/notification_service.h"
26 #include "policy/policy_constants.h" 17 #include "policy/policy_constants.h"
27 #include "testing/gtest/include/gtest/gtest.h"
28
29 namespace {
30 // Helper class that counts the number of notifications of the specified
31 // type that have been received.
32 class CountNotificationObserver : public content::NotificationObserver {
33 public:
34 CountNotificationObserver(int notification_type_to_count,
35 const content::NotificationSource& source)
36 : notification_count_(0) {
37 registrar_.Add(this, notification_type_to_count, source);
38 }
39
40 // NotificationObserver:
41 void Observe(int type,
42 const content::NotificationSource& source,
43 const content::NotificationDetails& details) override {
44 // Count the number of notifications seen.
45 notification_count_++;
46 }
47
48 int notification_count() const { return notification_count_; }
49
50 private:
51 int notification_count_;
52 content::NotificationRegistrar registrar_;
53
54 DISALLOW_COPY_AND_ASSIGN(CountNotificationObserver);
55 };
56
57 } // namespace
58 18
59 namespace policy { 19 namespace policy {
60 20
61 class UserCloudPolicyManagerTest : public LoginPolicyTestBase { 21 class UserCloudPolicyManagerTest : public LoginPolicyTestBase {
62 protected: 22 protected:
63 UserCloudPolicyManagerTest() {} 23 UserCloudPolicyManagerTest() {}
64 24
65 void GetMandatoryPoliciesValue(base::DictionaryValue* policy) const override { 25 void GetMandatoryPoliciesValue(base::DictionaryValue* policy) const override {
66 scoped_ptr<base::ListValue> list(new base::ListValue); 26 scoped_ptr<base::ListValue> list(new base::ListValue);
67 list->AppendString("chrome://policy"); 27 list->AppendString("chrome://policy");
68 list->AppendString("chrome://about"); 28 list->AppendString("chrome://about");
69 29
70 policy->Set(key::kRestoreOnStartupURLs, std::move(list)); 30 policy->Set(key::kRestoreOnStartupURLs, std::move(list));
71 policy->SetInteger(key::kRestoreOnStartup, 31 policy->SetInteger(key::kRestoreOnStartup,
72 SessionStartupPref::kPrefValueURLs); 32 SessionStartupPref::kPrefValueURLs);
73 } 33 }
74 34
75 private: 35 private:
76 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerTest); 36 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerTest);
77 }; 37 };
78 38
79 IN_PROC_BROWSER_TEST_F(UserCloudPolicyManagerTest, StartSession) { 39 IN_PROC_BROWSER_TEST_F(UserCloudPolicyManagerTest, StartSession) {
80 const char* const kStartupURLs[] = {"chrome://policy", "chrome://about"}; 40 const char* const kStartupURLs[] = {"chrome://policy", "chrome://about"};
81 41
82 SkipToLoginScreen(); 42 SkipToLoginScreen();
83 LogIn(kAccountId, kAccountPassword); 43 LogIn(kAccountId, kAccountPassword);
84 44
85 // User should be marked as having a valid OAuth token.
86 const user_manager::UserManager* const user_manager =
87 user_manager::UserManager::Get();
88 EXPECT_EQ(user_manager::User::OAUTH2_TOKEN_STATUS_VALID,
89 user_manager->GetActiveUser()->oauth_token_status());
90
91 // Check that the startup pages specified in policy were opened. 45 // Check that the startup pages specified in policy were opened.
92 BrowserList* browser_list = BrowserList::GetInstance(); 46 BrowserList* browser_list = BrowserList::GetInstance();
93 EXPECT_EQ(1U, browser_list->size()); 47 EXPECT_EQ(1U, browser_list->size());
94 Browser* browser = browser_list->get(0); 48 Browser* browser = browser_list->get(0);
95 ASSERT_TRUE(browser); 49 ASSERT_TRUE(browser);
96 50
97 TabStripModel* tabs = browser->tab_strip_model(); 51 TabStripModel* tabs = browser->tab_strip_model();
98 ASSERT_TRUE(tabs); 52 ASSERT_TRUE(tabs);
99 const int expected_tab_count = static_cast<int>(arraysize(kStartupURLs)); 53 const int expected_tab_count = static_cast<int>(arraysize(kStartupURLs));
100 EXPECT_EQ(expected_tab_count, tabs->count()); 54 EXPECT_EQ(expected_tab_count, tabs->count());
101 for (int i = 0; i < expected_tab_count && i < tabs->count(); ++i) { 55 for (int i = 0; i < expected_tab_count && i < tabs->count(); ++i) {
102 EXPECT_EQ(GURL(kStartupURLs[i]), 56 EXPECT_EQ(GURL(kStartupURLs[i]),
103 tabs->GetWebContentsAt(i)->GetVisibleURL()); 57 tabs->GetWebContentsAt(i)->GetVisibleURL());
104 } 58 }
105 } 59 }
106 60
107 IN_PROC_BROWSER_TEST_F(UserCloudPolicyManagerTest, ErrorLoadingPolicy) {
108 // Delete the policy file - this will cause a 500 error on policy requests.
109 user_policy_helper()->DeletePolicyFile();
110 SkipToLoginScreen();
111 CountNotificationObserver observer(
112 chrome::NOTIFICATION_SESSION_STARTED,
113 content::NotificationService::AllSources());
114 GetLoginDisplay()->ShowSigninScreenForCreds(kAccountId, kAccountPassword);
115 base::RunLoop().Run();
116 // Should not receive a SESSION_STARTED notification.
117 ASSERT_EQ(0, observer.notification_count());
118
119 // User should not be marked as having a valid OAuth token. That way, if we
120 // try to load the user in the future, we will attempt to load policy again.
121 const user_manager::UserManager* user_manager =
122 user_manager::UserManager::Get();
123 EXPECT_NE(user_manager::User::OAUTH2_TOKEN_STATUS_VALID,
124 user_manager->GetActiveUser()->oauth_token_status());
125 }
126
127 } // namespace policy 61 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698