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

Unified Diff: chrome/browser/ui/webui/profile_helper_browsertest.cc

Issue 2747293003: Added profile deletion browsertests. (Closed)
Patch Set: Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/profile_helper_browsertest.cc
diff --git a/chrome/browser/ui/webui/profile_helper_browsertest.cc b/chrome/browser/ui/webui/profile_helper_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b3d09eecd3c7ee39734a40e6d058c2311d68af3c
--- /dev/null
+++ b/chrome/browser/ui/webui/profile_helper_browsertest.cc
@@ -0,0 +1,141 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/run_loop.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chrome_notification_types.h"
+#include "chrome/browser/profiles/profile_attributes_storage.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/webui/profile_helper.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/test/test_utils.h"
+#include "content/public/test/test_web_ui.h"
+
+namespace {
+
+// An observer that returns back to test code after a new profile is
+// initialized.
+void UnblockOnProfileCreation(base::RunLoop* run_loop,
+ Profile* profile,
+ Profile::CreateStatus status) {
+ if (status == Profile::CREATE_STATUS_INITIALIZED)
+ run_loop->Quit();
+}
+
+Profile* CreateProfile() {
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ base::FilePath new_path = profile_manager->GenerateNextProfileDirectoryPath();
+ base::RunLoop run_loop;
+ profile_manager->CreateProfileAsync(
+ new_path, base::Bind(&UnblockOnProfileCreation, &run_loop),
+ base::string16(), std::string(), std::string());
+ run_loop.Run();
+ return profile_manager->GetProfileByPath(new_path);
+}
+
+} // namespace
+
+using ProfileHelperTest = InProcessBrowserTest;
+
+IN_PROC_BROWSER_TEST_F(ProfileHelperTest, OpenNewWindowForProfile) {
+ BrowserList* browser_list = BrowserList::GetInstance();
+
+ Browser* original_browser = browser();
+ Profile* original_profile = original_browser->profile();
+
+ // Sanity checks.
+ EXPECT_EQ(1u, browser_list->size());
+ EXPECT_TRUE(base::ContainsValue(*browser_list, original_browser));
+
+ // Opening existing browser profile shouldn't open additional browser windows.
+ webui::OpenNewWindowForProfile(original_profile);
+ EXPECT_EQ(1u, browser_list->size());
+ EXPECT_EQ(original_browser, browser_list->GetLastActive());
+
+ // Open additional browser will add new window and activates it.
+ Profile* additional_profile = CreateProfile();
+ webui::OpenNewWindowForProfile(additional_profile);
+ EXPECT_EQ(2u, browser_list->size());
+ EXPECT_NE(original_browser, browser_list->GetLastActive());
+
+ // Swith to original browser. Only LastActive should change.
+ webui::OpenNewWindowForProfile(original_profile);
+ EXPECT_EQ(2u, browser_list->size());
+ EXPECT_EQ(original_browser, browser_list->GetLastActive());
+}
+
+IN_PROC_BROWSER_TEST_F(ProfileHelperTest, DeleteSoleProfile) {
+ content::TestWebUI web_ui;
+ Browser* original_browser = browser();
+
+ BrowserList* browser_list = BrowserList::GetInstance();
+ EXPECT_EQ(1u, browser_list->size());
+ EXPECT_TRUE(base::ContainsValue(*browser_list, original_browser));
+
+ // Original browser will be closed, and browser with the new profile created.
+ content::WindowedNotificationObserver open_observer(
+ chrome::NOTIFICATION_BROWSER_OPENED,
+ content::NotificationService::AllSources());
+ content::WindowedNotificationObserver close_observer(
+ chrome::NOTIFICATION_BROWSER_CLOSED,
+ content::Source<Browser>(browser()));
+ webui::DeleteProfileAtPath(original_browser->profile()->GetPath(), &web_ui,
+ ProfileMetrics::DELETE_PROFILE_SETTINGS);
+ open_observer.Wait();
+ close_observer.Wait();
+
+ EXPECT_EQ(1u, browser_list->size());
+ EXPECT_FALSE(base::ContainsValue(*browser_list, original_browser));
+}
+
+IN_PROC_BROWSER_TEST_F(ProfileHelperTest, DeleteActiveProfile) {
+ content::TestWebUI web_ui;
+ Browser* original_browser = browser();
+
+ BrowserList* browser_list = BrowserList::GetInstance();
+ EXPECT_EQ(1u, browser_list->size());
+ EXPECT_TRUE(base::ContainsValue(*browser_list, original_browser));
+
+ Profile* additional_profile = CreateProfile();
+
+ // Original browser will be closed, and browser with the new profile created.
+ content::WindowedNotificationObserver open_observer(
+ chrome::NOTIFICATION_BROWSER_OPENED,
+ content::NotificationService::AllSources());
+ content::WindowedNotificationObserver close_observer(
+ chrome::NOTIFICATION_BROWSER_CLOSED,
+ content::Source<Browser>(browser()));
+ webui::DeleteProfileAtPath(original_browser->profile()->GetPath(), &web_ui,
+ ProfileMetrics::DELETE_PROFILE_SETTINGS);
+ open_observer.Wait();
+ close_observer.Wait();
+
+ EXPECT_EQ(1u, browser_list->size());
+ EXPECT_EQ(additional_profile, browser_list->get(0)->profile());
+}
+
+IN_PROC_BROWSER_TEST_F(ProfileHelperTest, DeleteInctiveProfile) {
Bernhard Bauer 2017/03/16 16:31:52 Nit: DeleteInactiveProfile
+ content::TestWebUI web_ui;
+ Browser* original_browser = browser();
+ ProfileAttributesStorage& storage =
+ g_browser_process->profile_manager()->GetProfileAttributesStorage();
+
+ BrowserList* browser_list = BrowserList::GetInstance();
+ EXPECT_EQ(1u, browser_list->size());
+ EXPECT_TRUE(base::ContainsValue(*browser_list, original_browser));
+ EXPECT_EQ(1u, storage.GetNumberOfProfiles());
+
+ Profile* additional_profile = CreateProfile();
+ EXPECT_EQ(2u, storage.GetNumberOfProfiles());
+
+ webui::DeleteProfileAtPath(additional_profile->GetPath(), &web_ui,
+ ProfileMetrics::DELETE_PROFILE_SETTINGS);
+
+ EXPECT_EQ(1u, browser_list->size());
+ EXPECT_TRUE(base::ContainsValue(*browser_list, original_browser));
+ EXPECT_EQ(1u, storage.GetNumberOfProfiles());
+}

Powered by Google App Engine
This is Rietveld 408576698