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

Unified Diff: chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm

Issue 10823130: [Mac] Position the avatar and fullscreen buttons when adding the first profile. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 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/cocoa/browser_window_controller_browsertest.mm
diff --git a/chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm b/chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..1bb0cf2a4495d7897895279d488edee3870c6362
--- /dev/null
+++ b/chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm
@@ -0,0 +1,100 @@
+// Copyright (c) 2012 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.
+
+#import "chrome/browser/ui/cocoa/browser_window_controller.h"
+
+#import "base/mac/mac_util.h"
+#include "base/run_loop.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_window.h"
+#import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h"
+#include "chrome/test/base/in_process_browser_test.h"
+
+#if !defined(MAC_OS_X_VERSION_10_7) || \
+ MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
+enum {
+ NSWindowDocumentVersionsButton = 6,
+ NSWindowFullScreenButton
+};
+#endif // MAC_OS_X_VERSION_10_7
+
+typedef InProcessBrowserTest BrowserWindowControllerTest;
+
+void CreateProfileCallback(const base::Closure& quit_closure,
+ Profile* profile,
+ Profile::CreateStatus status) {
+ EXPECT_TRUE(profile);
+ EXPECT_NE(Profile::CREATE_STATUS_FAIL, status);
+ // This will be called multiple times. Wait until the profile is initialized
+ // fully to quit the loop.
+ if (status == Profile::CREATE_STATUS_INITIALIZED)
+ quit_closure.Run();
+}
+
+// Tests that adding the first profile moves the Lion fullscreen button over
+// correctly.
+IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest,
+ ProfileAvatarFullscreenButton) {
+ if (base::mac::IsOSSnowLeopardOrEarlier())
+ return;
+
+ // Initialize the locals.
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ ASSERT_TRUE(profile_manager);
+
+ NSWindow* window = browser()->window()->GetNativeWindow();
+ ASSERT_TRUE(window);
+
+ BrowserWindowController* controller =
+ static_cast<BrowserWindowController*>([window windowController]);
sail 2012/08/02 00:12:40 you can also use browser()->window()->cocoa_contro
Robert Sesek 2012/08/02 00:23:40 Cool!
+ ASSERT_TRUE([controller isKindOfClass:[BrowserWindowController class]]);
+
+ // With only one profile, the fullscreen button should be visible, but the
+ // avatar button should not.
+ EXPECT_EQ(1u, profile_manager->GetNumberOfProfiles());
+
+ NSButton* fullscreen_button =
+ [window standardWindowButton:NSWindowFullScreenButton];
+ EXPECT_TRUE(fullscreen_button);
+ EXPECT_FALSE([fullscreen_button isHidden]);
+
+ AvatarButtonController* avatar_controller =
+ [controller avatarButtonController];
+ NSView* avatar = [avatar_controller view];
+ EXPECT_TRUE(avatar);
+ EXPECT_TRUE([avatar isHidden]);
+
+ // Create a profile asynchronously and run the loop until its creation
+ // is complete.
+ base::RunLoop run_loop;
+
+ ProfileManager::CreateCallback create_callback =
+ base::Bind(&CreateProfileCallback, run_loop.QuitClosure());
+ profile_manager->CreateProfileAsync(
+ profile_manager->user_data_dir().Append("test"),
+ create_callback,
+ ASCIIToUTF16("avatar_test"),
+ string16());
+
+ run_loop.Run();
+
+ // There should now be two profiles, and the avatar button and fullscreen
+ // button are both visible.
+ EXPECT_EQ(2u, profile_manager->GetNumberOfProfiles());
+ EXPECT_FALSE([avatar isHidden]);
+ EXPECT_FALSE([fullscreen_button isHidden]);
+ EXPECT_EQ([avatar window], [fullscreen_button window]);
+
+ // Make sure the visual order of the buttons is correct and that they don't
+ // overlap.
+ NSRect avatar_frame = [avatar frame];
+ NSRect fullscreen_frame = [fullscreen_button frame];
+
+ EXPECT_LT(NSMinX(fullscreen_frame), NSMinX(avatar_frame));
sail 2012/08/02 00:12:40 I don't think you need this line
Robert Sesek 2012/08/02 00:23:40 I wanted to have the fullscreen_frame MinX if it f
+ EXPECT_LT(NSMaxX(fullscreen_frame), NSMinX(avatar_frame));
+}

Powered by Google App Engine
This is Rietveld 408576698