Commit b6e1bf29 authored by Owen Min's avatar Owen Min Committed by Commit Bot

Add browser test for AppController

Browser test for crrev.com/027059d8.

Bug: 820649
Change-Id: I8f9cd3a53b702ce67b62fd6986b469c426ad1f84
Reviewed-on: https://chromium-review.googlesource.com/961541Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Commit-Queue: Owen Min <zmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543453}
parent d23ee3c1
...@@ -176,7 +176,10 @@ class AppControllerPlatformAppBrowserTest ...@@ -176,7 +176,10 @@ class AppControllerPlatformAppBrowserTest
// open then a reopen event does nothing. // open then a reopen event does nothing.
IN_PROC_BROWSER_TEST_F(AppControllerPlatformAppBrowserTest, IN_PROC_BROWSER_TEST_F(AppControllerPlatformAppBrowserTest,
PlatformAppReopenWithWindows) { PlatformAppReopenWithWindows) {
base::scoped_nsobject<AppController> ac([[AppController alloc] init]); AppController* ac = base::mac::ObjCCast<AppController>(
[[NSApplication sharedApplication] delegate]);
ASSERT_TRUE(ac);
NSUInteger old_window_count = [[NSApp windows] count]; NSUInteger old_window_count = [[NSApp windows] count];
EXPECT_EQ(1u, active_browser_list_->size()); EXPECT_EQ(1u, active_browser_list_->size());
[ac applicationShouldHandleReopen:NSApp hasVisibleWindows:YES]; [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:YES];
...@@ -190,8 +193,9 @@ IN_PROC_BROWSER_TEST_F(AppControllerPlatformAppBrowserTest, ...@@ -190,8 +193,9 @@ IN_PROC_BROWSER_TEST_F(AppControllerPlatformAppBrowserTest,
IN_PROC_BROWSER_TEST_F(AppControllerPlatformAppBrowserTest, IN_PROC_BROWSER_TEST_F(AppControllerPlatformAppBrowserTest,
ActivationFocusesBrowserWindow) { ActivationFocusesBrowserWindow) {
base::scoped_nsobject<AppController> app_controller( AppController* app_controller = base::mac::ObjCCast<AppController>(
[[AppController alloc] init]); [[NSApplication sharedApplication] delegate]);
ASSERT_TRUE(app_controller);
ExtensionTestMessageListener listener("Launched", false); ExtensionTestMessageListener listener("Launched", false);
const extensions::Extension* app = const extensions::Extension* app =
...@@ -233,7 +237,10 @@ class AppControllerWebAppBrowserTest : public InProcessBrowserTest { ...@@ -233,7 +237,10 @@ class AppControllerWebAppBrowserTest : public InProcessBrowserTest {
// Test that in web app mode a reopen event opens the app URL. // Test that in web app mode a reopen event opens the app URL.
IN_PROC_BROWSER_TEST_F(AppControllerWebAppBrowserTest, IN_PROC_BROWSER_TEST_F(AppControllerWebAppBrowserTest,
WebAppReopenWithNoWindows) { WebAppReopenWithNoWindows) {
base::scoped_nsobject<AppController> ac([[AppController alloc] init]); AppController* ac = base::mac::ObjCCast<AppController>(
[[NSApplication sharedApplication] delegate]);
ASSERT_TRUE(ac);
EXPECT_EQ(1u, active_browser_list_->size()); EXPECT_EQ(1u, active_browser_list_->size());
BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:NO]; BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:NO];
...@@ -284,7 +291,10 @@ class AppControllerNewProfileManagementBrowserTest ...@@ -284,7 +291,10 @@ class AppControllerNewProfileManagementBrowserTest
// Test that for a regular last profile, a reopen event opens a browser. // Test that for a regular last profile, a reopen event opens a browser.
IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest, IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest,
RegularProfileReopenWithNoWindows) { RegularProfileReopenWithNoWindows) {
base::scoped_nsobject<AppController> ac([[AppController alloc] init]); AppController* ac = base::mac::ObjCCast<AppController>(
[[NSApplication sharedApplication] delegate]);
ASSERT_TRUE(ac);
EXPECT_EQ(1u, active_browser_list_->size()); EXPECT_EQ(1u, active_browser_list_->size());
BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:NO]; BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:NO];
...@@ -300,7 +310,9 @@ IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest, ...@@ -300,7 +310,9 @@ IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest,
// minimize flakiness due to the scheduling/descheduling of tasks on the // minimize flakiness due to the scheduling/descheduling of tasks on the
// different threads, pre-initialize the guest profile before it is needed. // different threads, pre-initialize the guest profile before it is needed.
CreateAndWaitForSystemProfile(); CreateAndWaitForSystemProfile();
base::scoped_nsobject<AppController> ac([[AppController alloc] init]); AppController* ac = base::mac::ObjCCast<AppController>(
[[NSApplication sharedApplication] delegate]);
ASSERT_TRUE(ac);
// Lock the active profile. // Lock the active profile.
base::ScopedAllowBlockingForTesting allow_blocking; base::ScopedAllowBlockingForTesting allow_blocking;
...@@ -322,6 +334,46 @@ IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest, ...@@ -322,6 +334,46 @@ IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest,
UserManager::Hide(); UserManager::Hide();
} }
// Test that for a guest last profile, commandDispatch should open UserManager
// if guest mode is disabled. Note that this test might be flaky under ASAN
// due to https://crbug.com/674475. Please disable this test under ASAN
// as the tests below if that happened.
IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest,
OpenGuestProfileOnlyIfGuestModeIsEnabled) {
CreateAndWaitForSystemProfile();
PrefService* local_state = g_browser_process->local_state();
local_state->SetString(prefs::kProfileLastUsed, chrome::kGuestProfileDir);
local_state->SetBoolean(prefs::kBrowserGuestModeEnabled, false);
AppController* ac = base::mac::ObjCCast<AppController>(
[[NSApplication sharedApplication] delegate]);
ASSERT_TRUE(ac);
base::ScopedAllowBlockingForTesting allow_blocking;
Profile* profile = [ac lastProfile];
EXPECT_TRUE(profile->IsGuestSession());
NSMenu* menu = [ac applicationDockMenu:NSApp];
ASSERT_TRUE(menu);
NSMenuItem* item = [menu itemWithTag:IDC_NEW_WINDOW];
ASSERT_TRUE(item);
EXPECT_EQ(1u, active_browser_list_->size());
[ac commandDispatch:item];
base::RunLoop().RunUntilIdle();
EXPECT_EQ(1u, active_browser_list_->size());
EXPECT_TRUE(UserManager::IsShowing());
UserManager::Hide();
local_state->SetBoolean(prefs::kBrowserGuestModeEnabled, true);
[ac commandDispatch:item];
base::RunLoop().RunUntilIdle();
EXPECT_EQ(2u, active_browser_list_->size());
EXPECT_FALSE(UserManager::IsShowing());
}
#if defined(ADDRESS_SANITIZER) #if defined(ADDRESS_SANITIZER)
// Flaky under ASAN. See https://crbug.com/674475. // Flaky under ASAN. See https://crbug.com/674475.
#define MAYBE_GuestProfileReopenWithNoWindows DISABLED_GuestProfileReopenWithNoWindows #define MAYBE_GuestProfileReopenWithNoWindows DISABLED_GuestProfileReopenWithNoWindows
...@@ -337,7 +389,9 @@ IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest, ...@@ -337,7 +389,9 @@ IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest,
PrefService* local_state = g_browser_process->local_state(); PrefService* local_state = g_browser_process->local_state();
local_state->SetString(prefs::kProfileLastUsed, chrome::kGuestProfileDir); local_state->SetString(prefs::kProfileLastUsed, chrome::kGuestProfileDir);
base::scoped_nsobject<AppController> ac([[AppController alloc] init]); AppController* ac = base::mac::ObjCCast<AppController>(
[[NSApplication sharedApplication] delegate]);
ASSERT_TRUE(ac);
base::ScopedAllowBlockingForTesting allow_blocking; base::ScopedAllowBlockingForTesting allow_blocking;
Profile* profile = [ac lastProfile]; Profile* profile = [ac lastProfile];
...@@ -363,7 +417,9 @@ IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest, ...@@ -363,7 +417,9 @@ IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest,
#endif #endif
IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest, IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest,
MAYBE_AboutChromeForcesUserManager) { MAYBE_AboutChromeForcesUserManager) {
base::scoped_nsobject<AppController> ac([[AppController alloc] init]); AppController* ac = base::mac::ObjCCast<AppController>(
[[NSApplication sharedApplication] delegate]);
ASSERT_TRUE(ac);
// Create the guest profile, and set it as the last used profile so the // Create the guest profile, and set it as the last used profile so the
// app controller can use it on init. // app controller can use it on init.
...@@ -577,7 +633,10 @@ IN_PROC_BROWSER_TEST_F(AppControllerMainMenuBrowserTest, ...@@ -577,7 +633,10 @@ IN_PROC_BROWSER_TEST_F(AppControllerMainMenuBrowserTest,
IN_PROC_BROWSER_TEST_F(AppControllerMainMenuBrowserTest, IN_PROC_BROWSER_TEST_F(AppControllerMainMenuBrowserTest,
BookmarksMenuIsRestoredAfterProfileSwitch) { BookmarksMenuIsRestoredAfterProfileSwitch) {
ProfileManager* profile_manager = g_browser_process->profile_manager(); ProfileManager* profile_manager = g_browser_process->profile_manager();
base::scoped_nsobject<AppController> ac([[AppController alloc] init]); AppController* ac = base::mac::ObjCCast<AppController>(
[[NSApplication sharedApplication] delegate]);
ASSERT_TRUE(ac);
[ac awakeFromNib]; [ac awakeFromNib];
// Constants for bookmarks that we will create later. // Constants for bookmarks that we will create later.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment