Commit a9bf3a5f authored by jeremya@chromium.org's avatar jeremya@chromium.org

Fix a crash in FullscreenExitBubbleController when the user clicks the "Exit full screen" button.

The crash was due to the fact that Browser::OnDenyFullscreenPermission causes BrowserWindow::ExitFullscreen to be called, which causes the FullscreenExitBubbleController to be destroyed. [FullscreenExitBubbleController deny:] was sending a -hideSoon message to its zombie self following the call to Browser::OnDenyFullscreenPermission.

BUG=101835
TEST=The browser doesn't crash when you click "Exit full screen" on a fullscreened page.


Review URL: http://codereview.chromium.org/8399017

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107841 0039d316-1c4b-4281-b951-d872f2087c98
parent 374b33fb
...@@ -870,6 +870,8 @@ class Browser : public TabHandlerDelegate, ...@@ -870,6 +870,8 @@ class Browser : public TabHandlerDelegate,
FRIEND_TEST_ALL_PREFIXES(BrowserTest, TestTabExitsItselfFromFullscreen); FRIEND_TEST_ALL_PREFIXES(BrowserTest, TestTabExitsItselfFromFullscreen);
FRIEND_TEST_ALL_PREFIXES(BrowserTest, TestFullscreenBubbleMouseLockState); FRIEND_TEST_ALL_PREFIXES(BrowserTest, TestFullscreenBubbleMouseLockState);
FRIEND_TEST_ALL_PREFIXES(BrowserTest, TabEntersPresentationModeFromWindowed); FRIEND_TEST_ALL_PREFIXES(BrowserTest, TabEntersPresentationModeFromWindowed);
FRIEND_TEST_ALL_PREFIXES(FullscreenExitBubbleControllerTest,
DenyExitsFullscreen);
FRIEND_TEST_ALL_PREFIXES(BrowserInitTest, OpenAppShortcutNoPref); FRIEND_TEST_ALL_PREFIXES(BrowserInitTest, OpenAppShortcutNoPref);
FRIEND_TEST_ALL_PREFIXES(BrowserInitTest, OpenAppShortcutWindowPref); FRIEND_TEST_ALL_PREFIXES(BrowserInitTest, OpenAppShortcutWindowPref);
FRIEND_TEST_ALL_PREFIXES(BrowserInitTest, OpenAppShortcutTabPref); FRIEND_TEST_ALL_PREFIXES(BrowserInitTest, OpenAppShortcutTabPref);
......
...@@ -460,6 +460,9 @@ class TabContents; ...@@ -460,6 +460,9 @@ class TabContents;
// |source| rect doesn't fit into |target|. // |source| rect doesn't fit into |target|.
- (NSSize)overflowFrom:(NSRect)source - (NSSize)overflowFrom:(NSRect)source
to:(NSRect)target; to:(NSRect)target;
// The fullscreen exit bubble controller, or nil if the bubble isn't showing.
- (FullscreenExitBubbleController*)fullscreenExitBubbleController;
@end // @interface BrowserWindowController (TestingAPI) @end // @interface BrowserWindowController (TestingAPI)
......
...@@ -1852,6 +1852,11 @@ willAnimateFromState:(bookmarks::VisualState)oldState ...@@ -1852,6 +1852,11 @@ willAnimateFromState:(bookmarks::VisualState)oldState
return NSMakeSize(x, y); return NSMakeSize(x, y);
} }
// (Private/TestingAPI)
- (FullscreenExitBubbleController*)fullscreenExitBubbleController {
return fullscreenExitBubbleController_.get();
}
- (void)showInstant:(TabContents*)previewContents { - (void)showInstant:(TabContents*)previewContents {
[previewableContentsController_ showPreview:previewContents]; [previewableContentsController_ showPreview:previewContents];
[self updateBookmarkBarVisibilityWithAnimation:NO]; [self updateBookmarkBarVisibilityWithAnimation:NO];
......
...@@ -93,7 +93,6 @@ const float kHideDuration = 0.7; ...@@ -93,7 +93,6 @@ const float kHideDuration = 0.7;
- (void)deny:(id)sender { - (void)deny:(id)sender {
DCHECK(fullscreen_bubble::ShowButtonsForType(bubbleType_)); DCHECK(fullscreen_bubble::ShowButtonsForType(bubbleType_));
browser_->OnDenyFullscreenPermission(bubbleType_); browser_->OnDenyFullscreenPermission(bubbleType_);
[self hideSoon];
} }
- (void)showButtons:(BOOL)show { - (void)showButtons:(BOOL)show {
......
...@@ -4,7 +4,14 @@ ...@@ -4,7 +4,14 @@
#import "chrome/browser/ui/cocoa/fullscreen_exit_bubble_controller.h" #import "chrome/browser/ui/cocoa/fullscreen_exit_bubble_controller.h"
#include "chrome/browser/ui/cocoa/cocoa_test_helper.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/cocoa/browser_window_controller.h"
#include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
#include "chrome/browser/tabs/tab_strip_model.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/browser/site_instance.h"
#include "testing/gtest_mac.h" #include "testing/gtest_mac.h"
#include "ui/base/models/accelerator_cocoa.h" #include "ui/base/models/accelerator_cocoa.h"
...@@ -29,14 +36,16 @@ ...@@ -29,14 +36,16 @@
} }
@end @end
class FullscreenExitBubbleControllerTest : public CocoaTest { class FullscreenExitBubbleControllerTest : public CocoaProfileTest {
public: public:
virtual void SetUp() { virtual void SetUp() {
CocoaTest::SetUp(); CocoaProfileTest::SetUp();
ASSERT_TRUE(profile());
site_instance_ = SiteInstance::CreateSiteInstance(profile());
controller_.reset( controller_.reset(
[[FullscreenExitBubbleController alloc] initWithOwner:nil [[FullscreenExitBubbleController alloc] initWithOwner:nil
browser:nil browser:browser()
url:GURL() url:GURL()
bubbleType:FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION]); bubbleType:FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION]);
EXPECT_TRUE([controller_ window]); EXPECT_TRUE([controller_ window]);
...@@ -45,12 +54,52 @@ class FullscreenExitBubbleControllerTest : public CocoaTest { ...@@ -45,12 +54,52 @@ class FullscreenExitBubbleControllerTest : public CocoaTest {
virtual void TearDown() { virtual void TearDown() {
[controller_ close]; [controller_ close];
controller_.reset(); controller_.reset();
CocoaTest::TearDown(); CocoaProfileTest::TearDown();
} }
void AppendTabToStrip() {
TabContentsWrapper* tab_contents = Browser::TabContentsFactory(
profile(), site_instance_, MSG_ROUTING_NONE,
NULL, NULL);
browser()->tabstrip_model()->AppendTabContents(
tab_contents, /*foreground=*/true);
}
scoped_refptr<SiteInstance> site_instance_;
scoped_nsobject<FullscreenExitBubbleController> controller_; scoped_nsobject<FullscreenExitBubbleController> controller_;
}; };
TEST_F(FullscreenExitBubbleControllerTest, DenyExitsFullscreen) {
CreateBrowserWindow();
AppendTabToStrip();
TabContents* fullscreen_tab = browser()->GetSelectedTabContents();
{
base::mac::ScopedNSAutoreleasePool pool;
ui_test_utils::WindowedNotificationObserver fullscreen_observer(
chrome::NOTIFICATION_FULLSCREEN_CHANGED,
content::NotificationService::AllSources());
browser()->ToggleFullscreenModeForTab(fullscreen_tab, true);
fullscreen_observer.Wait();
ASSERT_TRUE(browser()->window()->IsFullscreen());
}
NSWindow* window = browser()->window()->GetNativeHandle();
BrowserWindowController* bwc = [BrowserWindowController
browserWindowControllerForWindow:window];
FullscreenExitBubbleController* bubble = [bwc fullscreenExitBubbleController];
ASSERT_TRUE(bubble);
{
ui_test_utils::WindowedNotificationObserver fullscreen_observer(
chrome::NOTIFICATION_FULLSCREEN_CHANGED,
content::NotificationService::AllSources());
[bubble deny:nil];
fullscreen_observer.Wait();
}
EXPECT_FALSE([bwc fullscreenExitBubbleController]);
EXPECT_FALSE(browser()->window()->IsFullscreen());
CloseBrowserWindow();
}
TEST_F(FullscreenExitBubbleControllerTest, LabelWasReplaced) { TEST_F(FullscreenExitBubbleControllerTest, LabelWasReplaced) {
EXPECT_FALSE([controller_ exitLabelPlaceholder]); EXPECT_FALSE([controller_ exitLabelPlaceholder]);
EXPECT_TRUE([controller_ exitLabel]); EXPECT_TRUE([controller_ exitLabel]);
......
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