Chromium Code Reviews| Index: chrome/browser/ui/webui/options/chromeos/shared_options_browsertest.cc |
| diff --git a/chrome/browser/ui/webui/options/chromeos/shared_options_browsertest.cc b/chrome/browser/ui/webui/options/chromeos/shared_options_browsertest.cc |
| index ac9841bf511c73a21b5ad137694a5d3cb2afefbd..dced64106d2a69021e50a87ade90cfb7b4666edd 100644 |
| --- a/chrome/browser/ui/webui/options/chromeos/shared_options_browsertest.cc |
| +++ b/chrome/browser/ui/webui/options/chromeos/shared_options_browsertest.cc |
| @@ -2,113 +2,196 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "base/basictypes.h" |
| -#include "base/compiler_specific.h" |
| +#include "chrome/browser/ui/webui/options/chromeos/shared_options_browsertest.h" |
| + |
| +// todo |
| #include "base/prefs/pref_service.h" |
| -#include "chrome/browser/chromeos/login/login_manager_test.h" |
| #include "chrome/browser/chromeos/login/startup_utils.h" |
| #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" |
| #include "chrome/browser/chromeos/login/users/user_manager.h" |
| #include "chrome/browser/chromeos/settings/cros_settings.h" |
| #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" |
| #include "chrome/browser/ui/browser.h" |
| -#include "chrome/browser/ui/tabs/tab_strip_model.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/common/pref_names.h" |
| #include "chrome/test/base/ui_test_utils.h" |
| +#include "chrome/browser/ui/tabs/tab_strip_model.h" |
| #include "chromeos/settings/cros_settings_names.h" |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/test/browser_test_utils.h" |
| #include "content/public/test/test_utils.h" |
| +#include "base/bind.h" |
| +#include "base/prefs/pref_service.h" |
| +#include "base/values.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/tabs/tab_strip_model.h" |
| +#include "content/public/browser/navigation_controller.h" |
| +#include "content/public/browser/navigation_entry.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "content/public/browser/web_ui.h" |
| +#include "url/gurl.h" |
| + |
| +#include "content/public/test/browser_test_utils.h" |
| +#include "content/public/test/test_utils.h" |
| + |
| +#include "testing/gmock/include/gmock/gmock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +using ::testing::AnyNumber; |
| +using ::testing::Invoke; |
| +using ::testing::InvokeWithoutArgs; |
| +using ::testing::Return; |
| +using ::testing::ReturnNull; |
| +using ::testing::Sequence; |
| +using ::testing::WithArg; |
| +using ::testing::_; |
| + |
| namespace chromeos { |
| namespace { |
| -const char* kTestUsers[] = { "test-user1@gmail.com", "test-user2@gmail.com" }; |
| +const char* kTestOwner = "test-user0@example.com"; |
| } // namespace |
| -class SharedOptionsTest : public LoginManagerTest { |
| - public: |
| - SharedOptionsTest() |
| - : LoginManagerTest(false), |
| - device_settings_provider_(NULL) { |
| - stub_settings_provider_.Set(kDeviceOwner, base::StringValue(kTestUsers[0])); |
| - } |
| +SharedOptionsTest::SharedOptionsTest() |
| + : device_settings_provider_(NULL), |
| + login_manager_test_helper_(new LoginManagerTestHelper) { |
| + set_exit_when_last_browser_closes(false); |
| + stub_settings_provider_.Set(kDeviceOwner, base::StringValue(kTestOwner)); |
| +} |
| - virtual ~SharedOptionsTest() { |
| - } |
| +SharedOptionsTest::~SharedOptionsTest() { |
| +} |
| - virtual void SetUpOnMainThread() OVERRIDE { |
| - LoginManagerTest::SetUpOnMainThread(); |
| - CrosSettings* settings = CrosSettings::Get(); |
| - device_settings_provider_ = settings->GetProvider(kDeviceOwner); |
| - settings->RemoveSettingsProvider(device_settings_provider_); |
| - settings->AddSettingsProvider(&stub_settings_provider_); |
| - } |
| +void SharedOptionsTest::RegisterMessages() { |
| + web_ui()->RegisterMessageCallback( |
| + "sharedOptionsTestRegisterUsers", |
| + base::Bind(&SharedOptionsTest::RegisterUsers, |
| + base::Unretained(this))); |
| + web_ui()->RegisterMessageCallback( |
| + "sharedOptionsTestLogInUser", |
| + base::Bind(&SharedOptionsTest::LogInUser, |
| + base::Unretained(this))); |
| + web_ui()->RegisterMessageCallback( |
| + "sharedOptionsTestAddUser", |
| + base::Bind(&SharedOptionsTest::AddUser, |
| + base::Unretained(this))); |
| +} |
| - virtual void CleanUpOnMainThread() OVERRIDE { |
| - CrosSettings* settings = CrosSettings::Get(); |
| - settings->RemoveSettingsProvider(&stub_settings_provider_); |
| - settings->AddSettingsProvider(device_settings_provider_); |
| - LoginManagerTest::CleanUpOnMainThread(); |
| - } |
| +void SharedOptionsTest::SetUpLoginDisplay() { |
| + // for existing_user_controller.cc:login_display_.get() |
| + /* EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) |
| + .Times(1) |
| + .WillOnce(Return(mock_login_display_));*/ |
| +} |
| - virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| - LoginManagerTest::SetUpCommandLine(command_line); |
| - command_line->AppendSwitch(::switches::kMultiProfiles); |
| - } |
| +void SharedOptionsTest::SetUpOnMainThread() { |
| + /* |
| + // Create a mock login display host so we can create an |
| + // ExistingUserController. |
|
michaelpg
2014/05/20 00:41:37
This is similar to what existing_user_controller_b
|
| + mock_login_display_host_.reset(new MockLoginDisplayHost); |
| + mock_login_display_ = new MockLoginDisplay(); |
| + SetUpLoginDisplay(); |
| + |
| + // Create an ExistingUserController. Otherwise |
| + // ExistingUserController::current_controller() won't exist and test fails. |
| + // Umm, now this isn't true anymore. |
| + // existing_user_controller_.reset( |
|
michaelpg
2014/05/20 00:41:37
I'm confused, because at first the test wouldn't r
|
| + // new ExistingUserController(mock_login_display_host_.get())); |
| + */ |
| + |
| + // login_manager_test_helper_->WaitForLoginWebUI(); |
|
michaelpg
2014/05/20 00:41:37
Normally a LoginManagerTest would wait for the Log
|
| + CrosSettings* settings = CrosSettings::Get(); |
| + device_settings_provider_ = settings->GetProvider(kDeviceOwner); |
| + settings->RemoveSettingsProvider(device_settings_provider_); |
| + settings->AddSettingsProvider(&stub_settings_provider_); |
| + WebUIBrowserTest::SetUpOnMainThread(); |
| + LOG(ERROR) << "Set up"; |
| +} |
| - protected: |
| - void CheckOptionsUI(const User* user, bool is_primary) { |
| - Profile* profile = UserManager::Get()->GetProfileByUser(user); |
| - profile->GetPrefs()->SetString(prefs::kGoogleServicesUsername, |
| - user->email()); |
| - |
| - ui_test_utils::BrowserAddedObserver observer; |
| - Browser* browser = CreateBrowser(profile); |
| - observer.WaitForSingleNewBrowser(); |
| - |
| - ui_test_utils::NavigateToURL(browser, |
| - GURL("chrome://settings-frame")); |
| - content::WebContents* contents = |
| - browser->tab_strip_model()->GetActiveWebContents(); |
| - |
| - bool banner_visible; |
| - ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| - contents, |
| - "var e = document.getElementById('secondary-user-banner');" |
| - "var visible = e.offsetWidth > 0 && e.offsetHeight > 0;" |
| - "window.domAutomationController.send(visible);", |
| - &banner_visible)); |
| - EXPECT_EQ(is_primary, !banner_visible); |
| - } |
| +void SharedOptionsTest::CleanUpOnMainThread() { |
| + existing_user_controller_.reset(); |
| + CrosSettings* settings = CrosSettings::Get(); |
| + settings->RemoveSettingsProvider(&stub_settings_provider_); |
| + settings->AddSettingsProvider(device_settings_provider_); |
| + login_manager_test_helper_->CloseLoginWebUI(); |
| + WebUIBrowserTest::CleanUpOnMainThread(); |
| +} |
| + |
| +void SharedOptionsTest::SetUpCommandLine(CommandLine* command_line) { |
| + // Don't add kLoginManager switches, or running PRE_ test will fail with no |
| + // error message. |
| + // login_manager_test_helper_->SetUpCommandLine(command_line); |
|
michaelpg
2014/05/20 00:41:37
This would add kLoginManager and kForceLoginManage
Nikita (slow)
2014/05/20 12:50:35
As far as I remember the issue with WebUIBrowserTe
|
| + command_line->AppendSwitch(::switches::kMultiProfiles); |
| + WebUIBrowserTest::SetUpCommandLine(command_line); |
| +} |
| + |
| +void SharedOptionsTest::SetUpInProcessBrowserTestFixture() { |
| + LOG(ERROR) << "Setting up in process browser test fixture"; |
| + login_manager_test_helper_->SetUpLoginUtils(false /* ? */); |
| +} |
| + |
| +void SharedOptionsTest::RegisterUsers(const base::ListValue* list_value) { |
| + LOG(ERROR) << "Register users called"; |
| + int num_users; |
| + ASSERT_TRUE(list_value->GetInteger(0, &num_users)); |
| - StubCrosSettingsProvider stub_settings_provider_; |
| - CrosSettingsProvider* device_settings_provider_; |
| + LOG(ERROR) << "num users: " << num_users;; |
| - private: |
| - DISALLOW_COPY_AND_ASSIGN(SharedOptionsTest); |
| -}; |
| + char user_name[28]; |
| + for (int i = 0; i < num_users; i++) { |
| + sprintf(user_name, "test-user%d@example.com", i); |
| + login_manager_test_helper_->RegisterUser(user_name); |
| + LOG(ERROR) << "Registered " << user_name; |
| + } |
| -IN_PROC_BROWSER_TEST_F(SharedOptionsTest, PRE_SharedOptions) { |
| - RegisterUser(kTestUsers[0]); |
| - RegisterUser(kTestUsers[1]); |
| StartupUtils::MarkOobeCompleted(); |
| + |
| + web_ui()->CallJavascriptFunction( |
| + "SharedOptionsTest.registerUsersCallback"); |
| } |
| -IN_PROC_BROWSER_TEST_F(SharedOptionsTest, SharedOptions) { |
| - LoginUser(kTestUsers[0]); |
| +void SharedOptionsTest::LogInUser(const base::ListValue* list_value) { |
| + int user_num; |
| + ASSERT_TRUE(list_value->GetInteger(0, &user_num)); |
| + |
| + char user_name[28]; |
| + sprintf(user_name, "test-user%d@example.com", user_num); |
| + login_manager_test_helper_->LogInUser(user_name); |
| + |
| UserAddingScreen::Get()->Start(); |
| content::RunAllPendingInMessageLoop(); |
| - AddUser(kTestUsers[1]); |
| - UserManager* manager = UserManager::Get(); |
| - ASSERT_EQ(2u, manager->GetLoggedInUsers().size()); |
| + web_ui()->CallJavascriptFunction( |
| + "SharedOptionsTest.logInUserCallback"); |
| +} |
| + |
| +void SharedOptionsTest::AddUser(const base::ListValue* list_value) { |
| + int user_num; |
| + LOG(ERROR) << "Adding user"; |
| + ASSERT_TRUE(list_value->GetInteger(0, &user_num)); |
| + |
| + char user_name[28]; |
| + sprintf(user_name, "test-user%d@example.com", user_num); |
| + LOG(ERROR) << "Adding user " << user_name; |
| + |
| + login_manager_test_helper_->AddUser(user_name); |
|
michaelpg
2014/05/20 00:41:37
This is where the test is failing now.
|
| + |
| + // There are 3 of these lines output. |
| + // I don't know if that's causing this test to fail: |
| + // [22018:22018:0519/172540:INFO:CONSOLE(1)] "Uncaught ReferenceError: |
| + // cr is not defined", source: (1) |
| + |
| + LOG(ERROR) << "Calling addUserCallback"; |
| + web_ui()->CallJavascriptFunction( |
| + "SharedOptionsTest.addUserCallback"); |
| +} |
| - CheckOptionsUI(manager->FindUser(kTestUsers[0]), true /* is_primary */); |
| - CheckOptionsUI(manager->FindUser(kTestUsers[1]), false /* is_primary */); |
| +content::WebUIMessageHandler* SharedOptionsTest::GetMockMessageHandler() { |
| + return this; |
| } |
| } // namespace chromeos |