summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/browser_window_cocoa_unittest.mm
diff options
context:
space:
mode:
authorjrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-23 01:18:13 +0000
committerjrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-23 01:18:13 +0000
commitf6314009810a5ee6c606328c41c8ff4e1dacd05e (patch)
tree3c530eb3c209f23e369f0a8f35849a94e502cbc8 /chrome/browser/cocoa/browser_window_cocoa_unittest.mm
parentec85e6880806202737a4d32c94817f0ecad4ca8b (diff)
downloadchromium_src-f6314009810a5ee6c606328c41c8ff4e1dacd05e.zip
chromium_src-f6314009810a5ee6c606328c41c8ff4e1dacd05e.tar.gz
chromium_src-f6314009810a5ee6c606328c41c8ff4e1dacd05e.tar.bz2
Fix problem with bookmark bar introduced by window sharing; pref
change needs to change all open windows with the same preferences, not just the current one). Improve unit testing. Limit bookmark menu size width (1st pass). Cleanup/delete of code which no longer does much. Review URL: http://codereview.chromium.org/79068 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14282 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/browser_window_cocoa_unittest.mm')
-rw-r--r--chrome/browser/cocoa/browser_window_cocoa_unittest.mm93
1 files changed, 93 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/browser_window_cocoa_unittest.mm b/chrome/browser/cocoa/browser_window_cocoa_unittest.mm
new file mode 100644
index 0000000..4308bc2
--- /dev/null
+++ b/chrome/browser/cocoa/browser_window_cocoa_unittest.mm
@@ -0,0 +1,93 @@
+// Copyright (c) 2009 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/scoped_nsobject.h"
+#include "base/scoped_nsautorelease_pool.h"
+#include "base/scoped_ptr.h"
+#include "base/string_util.h"
+#include "chrome/browser/bookmarks/bookmark_utils.h"
+#include "chrome/browser/cocoa/browser_test_helper.h"
+#include "chrome/browser/cocoa/browser_window_cocoa.h"
+#include "chrome/browser/cocoa/browser_window_controller.h"
+#include "chrome/browser/cocoa/cocoa_test_helper.h"
+#include "chrome/common/notification_type.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+// A BrowserWindowCocoa that goes PONG when
+// BOOKMARK_BAR_VISIBILITY_PREF_CHANGED is sent. This is so we can be
+// sure we are observing it.
+class BrowserWindowCocoaPong : public BrowserWindowCocoa {
+ public:
+ BrowserWindowCocoaPong(Browser* browser,
+ BrowserWindowController* controller,
+ NSWindow* window) :
+ BrowserWindowCocoa(browser, controller, window) {
+ pong_ = false;
+ }
+ virtual ~BrowserWindowCocoaPong() { }
+
+ void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (type.value == NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED)
+ pong_ = true;
+ BrowserWindowCocoa::Observe(type, source, details);
+ }
+
+ bool pong_;
+};
+
+// Main test class.
+class BrowserWindowCocoaTest : public testing::Test {
+
+ virtual void SetUp() {
+ controller_.reset([[BrowserWindowController alloc]
+ initWithBrowser:browser_helper_.browser()
+ takeOwnership:NO]);
+ }
+
+ public:
+ // Order is very important here. We want the controller deleted
+ // before the pool, and want the pool deleted before
+ // BrowserTestHelper.
+ CocoaTestHelper cocoa_helper_;
+ BrowserTestHelper browser_helper_;
+ base::ScopedNSAutoreleasePool pool_;
+ scoped_nsobject<BrowserWindowController> controller_;
+};
+
+
+TEST_F(BrowserWindowCocoaTest, TestNotification) {
+ BrowserWindowCocoaPong *bwc = new BrowserWindowCocoaPong(
+ browser_helper_.browser(),
+ controller_.get(),
+ cocoa_helper_.window());
+
+ EXPECT_FALSE(bwc->pong_);
+ bookmark_utils::ToggleWhenVisible(browser_helper_.profile());
+ // Confirm we are listening
+ EXPECT_TRUE(bwc->pong_);
+
+ delete bwc;
+ // If this does NOT crash it confirms we stopped listening in the destructor.
+ bookmark_utils::ToggleWhenVisible(browser_helper_.profile());
+}
+
+
+TEST_F(BrowserWindowCocoaTest, TestBookmarkBarVisible) {
+ BrowserWindowCocoaPong *bwc = new BrowserWindowCocoaPong(
+ browser_helper_.browser(),
+ controller_.get(),
+ cocoa_helper_.window());
+ scoped_ptr<BrowserWindowCocoaPong> scoped_bwc(bwc);
+
+ bool before = bwc->IsBookmarkBarVisible();
+ bookmark_utils::ToggleWhenVisible(browser_helper_.profile());
+ EXPECT_NE(before, bwc->IsBookmarkBarVisible());
+
+ bookmark_utils::ToggleWhenVisible(browser_helper_.profile());
+ EXPECT_EQ(before, bwc->IsBookmarkBarVisible());
+}
+
+/* TODO(???): test other methods of BrowserWindowCocoa */