OLD | NEW |
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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "chrome/browser/chromeos/login/login_manager_test.h" | 8 #include "chrome/browser/chromeos/login/login_manager_test_helper.h" |
9 #include "chrome/browser/chromeos/login/startup_utils.h" | 9 #include "chrome/browser/chromeos/login/startup_utils.h" |
10 #include "chrome/browser/chromeos/login/user_adding_screen.h" | 10 #include "chrome/browser/chromeos/login/user_adding_screen.h" |
11 #include "chrome/browser/chromeos/login/user_manager.h" | 11 #include "chrome/browser/chromeos/login/user_manager.h" |
12 #include "chrome/browser/chromeos/settings/cros_settings.h" | 12 #include "chrome/browser/chromeos/settings/cros_settings.h" |
13 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" | 13 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 18 #include "chrome/test/base/in_process_browser_test.h" |
18 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
19 #include "chromeos/settings/cros_settings_names.h" | 20 #include "chromeos/settings/cros_settings_names.h" |
20 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
21 #include "content/public/test/browser_test_utils.h" | 22 #include "content/public/test/browser_test_utils.h" |
22 #include "content/public/test/test_utils.h" | 23 #include "content/public/test/test_utils.h" |
23 | 24 |
24 namespace chromeos { | 25 namespace chromeos { |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 const char* kTestUsers[] = { "test-user1@gmail.com", "test-user2@gmail.com" }; | 29 const char* kTestUsers[] = { "test-user1@gmail.com", "test-user2@gmail.com" }; |
29 | 30 |
30 } // namespace | 31 } // namespace |
31 | 32 |
32 class SharedOptionsTest : public LoginManagerTest { | 33 class SharedOptionsTest : public InProcessBrowserTest { |
33 public: | 34 public: |
34 SharedOptionsTest() | 35 SharedOptionsTest() |
35 : LoginManagerTest(false), | 36 : login_manager_test_helper_(new LoginManagerTestHelper(false)), |
36 device_settings_provider_(NULL) { | 37 device_settings_provider_(NULL) { |
| 38 set_exit_when_last_browser_closes(false); |
37 stub_settings_provider_.Set(kDeviceOwner, base::StringValue(kTestUsers[0])); | 39 stub_settings_provider_.Set(kDeviceOwner, base::StringValue(kTestUsers[0])); |
38 } | 40 } |
39 | 41 |
40 virtual ~SharedOptionsTest() { | 42 virtual ~SharedOptionsTest() { |
41 } | 43 } |
42 | 44 |
43 virtual void SetUpOnMainThread() OVERRIDE { | 45 virtual void SetUpOnMainThread() OVERRIDE { |
44 LoginManagerTest::SetUpOnMainThread(); | 46 login_manager_test_helper_->SetUp(); |
45 CrosSettings* settings = CrosSettings::Get(); | 47 CrosSettings* settings = CrosSettings::Get(); |
46 device_settings_provider_ = settings->GetProvider(kDeviceOwner); | 48 device_settings_provider_ = settings->GetProvider(kDeviceOwner); |
47 settings->RemoveSettingsProvider(device_settings_provider_); | 49 settings->RemoveSettingsProvider(device_settings_provider_); |
48 settings->AddSettingsProvider(&stub_settings_provider_); | 50 settings->AddSettingsProvider(&stub_settings_provider_); |
49 } | 51 } |
50 | 52 |
51 virtual void CleanUpOnMainThread() OVERRIDE { | 53 virtual void CleanUpOnMainThread() OVERRIDE { |
52 CrosSettings* settings = CrosSettings::Get(); | 54 CrosSettings* settings = CrosSettings::Get(); |
53 settings->RemoveSettingsProvider(&stub_settings_provider_); | 55 settings->RemoveSettingsProvider(&stub_settings_provider_); |
54 settings->AddSettingsProvider(device_settings_provider_); | 56 settings->AddSettingsProvider(device_settings_provider_); |
55 LoginManagerTest::CleanUpOnMainThread(); | 57 login_manager_test_helper_->CleanUp(); |
56 } | 58 } |
57 | 59 |
58 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 60 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
59 LoginManagerTest::SetUpCommandLine(command_line); | 61 login_manager_test_helper_->SetUpCommandLine(command_line); |
60 command_line->AppendSwitch(::switches::kMultiProfiles); | 62 command_line->AppendSwitch(::switches::kMultiProfiles); |
61 } | 63 } |
62 | 64 |
| 65 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 66 login_manager_test_helper_->SetUpLoginUtils(); |
| 67 } |
| 68 |
63 protected: | 69 protected: |
64 void CheckOptionsUI(const User* user, bool is_primary) { | 70 void CheckOptionsUI(const User* user, bool is_primary) { |
65 Profile* profile = UserManager::Get()->GetProfileByUser(user); | 71 Profile* profile = UserManager::Get()->GetProfileByUser(user); |
66 profile->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 72 profile->GetPrefs()->SetString(prefs::kGoogleServicesUsername, |
67 user->email()); | 73 user->email()); |
68 | 74 |
69 ui_test_utils::BrowserAddedObserver observer; | 75 ui_test_utils::BrowserAddedObserver observer; |
70 Browser* browser = CreateBrowser(profile); | 76 Browser* browser = CreateBrowser(profile); |
71 observer.WaitForSingleNewBrowser(); | 77 observer.WaitForSingleNewBrowser(); |
72 | 78 |
73 ui_test_utils::NavigateToURL(browser, | 79 ui_test_utils::NavigateToURL(browser, |
74 GURL("chrome://settings-frame")); | 80 GURL("chrome://settings-frame")); |
75 content::WebContents* contents = | 81 content::WebContents* contents = |
76 browser->tab_strip_model()->GetActiveWebContents(); | 82 browser->tab_strip_model()->GetActiveWebContents(); |
77 | 83 |
78 bool banner_visible; | 84 bool banner_visible; |
79 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 85 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
80 contents, | 86 contents, |
81 "var e = document.getElementById('secondary-user-banner');" | 87 "var e = document.getElementById('secondary-user-banner');" |
82 "var visible = e.offsetWidth > 0 && e.offsetHeight > 0;" | 88 "var visible = e.offsetWidth > 0 && e.offsetHeight > 0;" |
83 "window.domAutomationController.send(visible);", | 89 "window.domAutomationController.send(visible);", |
84 &banner_visible)); | 90 &banner_visible)); |
85 EXPECT_EQ(is_primary, !banner_visible); | 91 EXPECT_EQ(is_primary, !banner_visible); |
86 } | 92 } |
87 | 93 |
| 94 scoped_ptr<LoginManagerTestHelper> login_manager_test_helper_; |
88 StubCrosSettingsProvider stub_settings_provider_; | 95 StubCrosSettingsProvider stub_settings_provider_; |
89 CrosSettingsProvider* device_settings_provider_; | 96 CrosSettingsProvider* device_settings_provider_; |
90 | 97 |
91 private: | 98 private: |
92 DISALLOW_COPY_AND_ASSIGN(SharedOptionsTest); | 99 DISALLOW_COPY_AND_ASSIGN(SharedOptionsTest); |
93 }; | 100 }; |
94 | 101 |
95 IN_PROC_BROWSER_TEST_F(SharedOptionsTest, PRE_SharedOptions) { | 102 IN_PROC_BROWSER_TEST_F(SharedOptionsTest, PRE_SharedOptions) { |
96 RegisterUser(kTestUsers[0]); | 103 login_manager_test_helper_->RegisterUser(kTestUsers[0]); |
97 RegisterUser(kTestUsers[1]); | 104 login_manager_test_helper_->RegisterUser(kTestUsers[1]); |
98 StartupUtils::MarkOobeCompleted(); | 105 StartupUtils::MarkOobeCompleted(); |
99 } | 106 } |
100 | 107 |
101 IN_PROC_BROWSER_TEST_F(SharedOptionsTest, SharedOptions) { | 108 IN_PROC_BROWSER_TEST_F(SharedOptionsTest, SharedOptions) { |
102 LoginUser(kTestUsers[0]); | 109 login_manager_test_helper_->LogInUser(kTestUsers[0]); |
103 UserAddingScreen::Get()->Start(); | 110 UserAddingScreen::Get()->Start(); |
104 content::RunAllPendingInMessageLoop(); | 111 content::RunAllPendingInMessageLoop(); |
105 AddUser(kTestUsers[1]); | 112 login_manager_test_helper_->AddUser(kTestUsers[1]); |
106 | 113 |
107 UserManager* manager = UserManager::Get(); | 114 UserManager* manager = UserManager::Get(); |
108 ASSERT_EQ(2u, manager->GetLoggedInUsers().size()); | 115 ASSERT_EQ(2u, manager->GetLoggedInUsers().size()); |
109 | 116 |
110 CheckOptionsUI(manager->FindUser(kTestUsers[0]), true /* is_primary */); | 117 CheckOptionsUI(manager->FindUser(kTestUsers[0]), true /* is_primary */); |
111 CheckOptionsUI(manager->FindUser(kTestUsers[1]), false /* is_primary */); | 118 CheckOptionsUI(manager->FindUser(kTestUsers[1]), false /* is_primary */); |
112 } | 119 } |
113 | 120 |
114 } // namespace chromeos | 121 } // namespace chromeos |
OLD | NEW |