summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa
diff options
context:
space:
mode:
authorpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-27 13:07:38 +0000
committerpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-27 13:07:38 +0000
commitbf2533c6e4d3b38baab0ca906a27191cc5ec779a (patch)
treec91f55e24ba3cf89b01282788920da9b014de4ba /chrome/browser/cocoa
parent97d0465a9b5d453b0921116b80645a356914e00d (diff)
downloadchromium_src-bf2533c6e4d3b38baab0ca906a27191cc5ec779a.zip
chromium_src-bf2533c6e4d3b38baab0ca906a27191cc5ec779a.tar.gz
chromium_src-bf2533c6e4d3b38baab0ca906a27191cc5ec779a.tar.bz2
Add a stub test for TabStripController. It doesn't fully work because of issues
creating WebContents objects. A bug has been filed to come back to it. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14601 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r--chrome/browser/cocoa/tab_contents_controller.mm4
-rw-r--r--chrome/browser/cocoa/tab_strip_controller_unittest.mm128
2 files changed, 131 insertions, 1 deletions
diff --git a/chrome/browser/cocoa/tab_contents_controller.mm b/chrome/browser/cocoa/tab_contents_controller.mm
index cb51275..68fb0de 100644
--- a/chrome/browser/cocoa/tab_contents_controller.mm
+++ b/chrome/browser/cocoa/tab_contents_controller.mm
@@ -4,6 +4,7 @@
#import "chrome/browser/cocoa/tab_contents_controller.h"
+#include "base/mac_util.h"
#include "base/sys_string_conversions.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/tab_contents/tab_contents.h"
@@ -12,7 +13,8 @@
- (id)initWithNibName:(NSString*)name
contents:(TabContents*)contents {
- if ((self = [super initWithNibName:name bundle:nil])) {
+ if ((self = [super initWithNibName:name
+ bundle:mac_util::MainAppBundle()])) {
contents_ = contents;
}
return self;
diff --git a/chrome/browser/cocoa/tab_strip_controller_unittest.mm b/chrome/browser/cocoa/tab_strip_controller_unittest.mm
new file mode 100644
index 0000000..0a70a98d
--- /dev/null
+++ b/chrome/browser/cocoa/tab_strip_controller_unittest.mm
@@ -0,0 +1,128 @@
+// 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.
+
+#import <Cocoa/Cocoa.h>
+
+#include "chrome/browser/cocoa/browser_test_helper.h"
+#import "chrome/browser/cocoa/cocoa_test_helper.h"
+#import "chrome/browser/cocoa/tab_strip_controller.h"
+#include "chrome/browser/tab_contents/web_contents.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+// Stub model delegate
+class TestTabStripDelegate : public TabStripModelDelegate {
+ public:
+ virtual TabContents* AddBlankTab(bool foreground) {
+ return NULL;
+ }
+ virtual TabContents* AddBlankTabAt(int index, bool foreground) {
+ return NULL;
+ }
+ virtual Browser* CreateNewStripWithContents(TabContents* contents,
+ const gfx::Rect& window_bounds,
+ const DockInfo& dock_info) {
+ return NULL;
+ }
+ virtual int GetDragActions() const {
+ return 0;
+ }
+ virtual TabContents* CreateTabContentsForURL(
+ const GURL& url,
+ const GURL& referrer,
+ Profile* profile,
+ PageTransition::Type transition,
+ bool defer_load,
+ SiteInstance* instance) const {
+ return NULL;
+ }
+ virtual bool CanDuplicateContentsAt(int index) { return true; }
+ virtual void DuplicateContentsAt(int index) { }
+ virtual void CloseFrameAfterDragSession() { }
+ virtual void CreateHistoricalTab(TabContents* contents) { }
+ virtual bool RunUnloadListenerBeforeClosing(TabContents* contents) {
+ return true;
+ }
+ virtual bool CanRestoreTab() {
+ return true;
+ }
+ virtual void RestoreTab() { }
+};
+
+class TabStripControllerTest : public testing::Test {
+ public:
+ TabStripControllerTest() {
+ NSView* parent = cocoa_helper_.contentView();
+ NSRect content_frame = [parent frame];
+
+ // Create the "switch view" (view that gets changed out when a tab
+ // switches).
+ NSRect switch_frame = NSMakeRect(0, 0, content_frame.size.width, 500);
+ scoped_nsobject<NSView> switch_view([[NSView alloc]
+ initWithFrame:switch_frame]);
+ [parent addSubview:switch_view.get()];
+
+ // Create the tab strip view. It's expected to have a child button in it
+ // already as the "new tab" button so create that too.
+ NSRect strip_frame = NSMakeRect(0, NSMaxY(switch_frame),
+ content_frame.size.width, 30);
+ tab_strip_.reset([[NSView alloc] initWithFrame:strip_frame]);
+ [parent addSubview:tab_strip_.get()];
+ NSRect button_frame = NSMakeRect(0, 0, 15, 15);
+ scoped_nsobject<NSButton> close_button([[NSButton alloc]
+ initWithFrame:button_frame]);
+ [tab_strip_ addSubview:close_button.get()];
+
+ // Create the controller using that view and a model we create that has
+ // no other Browser ties.
+ delegate_.reset(new TestTabStripDelegate());
+ model_.reset(new TabStripModel(delegate_.get(),
+ browser_helper_.profile()));
+ controller_.reset([[TabStripController alloc]
+ initWithView:(TabStripView*)tab_strip_.get()
+ switchView:switch_view.get()
+ model:model_.get()]);
+ }
+
+ CocoaTestHelper cocoa_helper_;
+ BrowserTestHelper browser_helper_;
+ scoped_ptr<TestTabStripDelegate> delegate_;
+ scoped_ptr<TabStripModel> model_;
+ scoped_nsobject<TabStripController> controller_;
+ scoped_nsobject<NSView> tab_strip_;
+};
+
+TEST_F(TabStripControllerTest, GrowBox) {
+ // TODO(pinkerton): Creating a WebContents crashes an unrelated test, even
+ // if you don't do anything with it. http://crbug.com/10899
+}
+
+// Test adding and removing tabs and making sure that views get added to
+// the tab strip.
+TEST_F(TabStripControllerTest, AddRemoveTabs) {
+ EXPECT_TRUE(model_->empty());
+#if 0
+ // TODO(pinkerton): Creating a WebContents crashes an unrelated test, even
+ // if you don't do anything with it. http://crbug.com/10899
+ SiteInstance* instance =
+ SiteInstance::CreateSiteInstance(browser_helper_.profile());
+ WebContents* tab_contents =
+ new WebContents(browser_helper_.profile(), instance);
+ model_->AppendTabContents(tab_contents, true);
+ EXPECT_EQ(model_->count(), 1);
+#endif
+}
+
+TEST_F(TabStripControllerTest, SelectTab) {
+ // TODO(pinkerton): Creating a WebContents crashes an unrelated test, even
+ // if you don't do anything with it. http://crbug.com/10899
+}
+
+TEST_F(TabStripControllerTest, RearrangeTabs) {
+ // TODO(pinkerton): Creating a WebContents crashes an unrelated test, even
+ // if you don't do anything with it. http://crbug.com/10899
+}
+
+} // namespace