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

Side by Side Diff: chrome/browser/cocoa/sad_tab_controller_unittest.mm

Issue 507023: fix leakages in SadTabControllerTest (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/scoped_nsobject.h" 5 #include "base/scoped_nsobject.h"
6 #include "chrome/browser/cocoa/browser_test_helper.h"
7 #import "chrome/browser/cocoa/cocoa_test_helper.h" 6 #import "chrome/browser/cocoa/cocoa_test_helper.h"
8 #import "chrome/browser/cocoa/sad_tab_controller.h" 7 #import "chrome/browser/cocoa/sad_tab_controller.h"
9 #import "chrome/browser/cocoa/sad_tab_view.h" 8 #import "chrome/browser/cocoa/sad_tab_view.h"
10 #include "chrome/browser/renderer_host/site_instance.h" 9 #include "chrome/browser/renderer_host/test/test_render_view_host.h"
11 #include "chrome/browser/tab_contents/tab_contents.h"
12 10
13 @interface SadTabView (ExposedForTesting) 11 @interface SadTabView (ExposedForTesting)
14 // Implementation is below. 12 // Implementation is below.
15 - (NSButton*)linkButton; 13 - (NSButton*)linkButton;
16 @end 14 @end
17 15
18 @implementation SadTabView (ExposedForTesting) 16 @implementation SadTabView (ExposedForTesting)
19 - (NSButton*)linkButton { 17 - (NSButton*)linkButton {
20 return linkButton_; 18 return linkButton_;
21 } 19 }
22 @end 20 @end
23 21
24 namespace { 22 namespace {
25 23
26 class SadTabControllerTest : public CocoaTest { 24 class SadTabControllerTest : public RenderViewHostTestHarness {
27 public: 25 public:
28 SadTabControllerTest() { 26 SadTabControllerTest() : test_window_(nil) {
29 link_clicked_ = false; 27 link_clicked_ = false;
30 } 28 }
31 29
32 TabContents* CreateTabContents() { 30 virtual void SetUp() {
33 SiteInstance* instance = 31 RenderViewHostTestHarness::SetUp();
34 SiteInstance::CreateSiteInstance(browser_helper_.profile()); 32 // Inherting from RenderViewHostTestHarness means we can't inherit from
35 TabContents* tab_contents = new TabContents(browser_helper_.profile(), 33 // from CocoaTest, so do a bootstrap and create test window.
36 instance, MSG_ROUTING_NONE, NULL); 34 CocoaTest::BootstrapCocoa();
37 return tab_contents; 35 test_window_ = [[CocoaTestHelperWindow alloc] init];
36 if (DebugUtil::BeingDebugged()) {
37 [test_window_ orderFront:nil];
38 } else {
39 [test_window_ orderBack:nil];
40 }
41 }
42
43 virtual void TearDown() {
44 [test_window_ close];
45 test_window_ = nil;
46 RenderViewHostTestHarness::TearDown();
38 } 47 }
39 48
40 // Creates the controller and adds its view to contents, caller has ownership. 49 // Creates the controller and adds its view to contents, caller has ownership.
41 SadTabController* CreateController(TabContents* tab_contents) { 50 SadTabController* CreateController() {
42 NSView* contentView = [test_window() contentView]; 51 NSView* contentView = [test_window_ contentView];
43 SadTabController* controller = 52 SadTabController* controller =
44 [[SadTabController alloc] initWithTabContents:tab_contents 53 [[SadTabController alloc] initWithTabContents:contents()
45 superview:contentView]; 54 superview:contentView];
46 EXPECT_TRUE(controller); 55 EXPECT_TRUE(controller);
47 NSView* view = [controller view]; 56 NSView* view = [controller view];
48 EXPECT_TRUE(view); 57 EXPECT_TRUE(view);
49 58
50 return controller; 59 return controller;
51 } 60 }
52 61
53 NSButton* GetLinkButton(SadTabController* controller) { 62 NSButton* GetLinkButton(SadTabController* controller) {
54 SadTabView* view = static_cast<SadTabView*>([controller view]); 63 SadTabView* view = static_cast<SadTabView*>([controller view]);
55 return ([view linkButton]); 64 return ([view linkButton]);
56 } 65 }
57 66
58 BrowserTestHelper browser_helper_;
59 static bool link_clicked_; 67 static bool link_clicked_;
68 CocoaTestHelperWindow* test_window_;
60 }; 69 };
61 70
62 /* TODO(kuan): (BUG:30522) enable this test when leak is fixed 71 TEST_F(SadTabControllerTest, WithTabContents) {
63 TEST_F(SadTabControllerTest, TestWithTabContents) { 72 scoped_nsobject<SadTabController> controller(CreateController());
64 scoped_ptr<TabContents> tab_contents(CreateTabContents());
65 scoped_nsobject<SadTabController>
66 controller(CreateController(tab_contents.get()));
67 EXPECT_TRUE(controller); 73 EXPECT_TRUE(controller);
68 NSButton* link = GetLinkButton(controller); 74 NSButton* link = GetLinkButton(controller);
69 EXPECT_TRUE(link); 75 EXPECT_TRUE(link);
70 } 76 }
71 */
72 77
73 TEST_F(SadTabControllerTest, TestWithoutTabContents) { 78 TEST_F(SadTabControllerTest, WithoutTabContents) {
74 scoped_nsobject<SadTabController> controller(CreateController(NULL)); 79 contents_.reset();
80 scoped_nsobject<SadTabController> controller(CreateController());
75 EXPECT_TRUE(controller); 81 EXPECT_TRUE(controller);
76 NSButton* link = GetLinkButton(controller); 82 NSButton* link = GetLinkButton(controller);
77 EXPECT_FALSE(link); 83 EXPECT_FALSE(link);
78 } 84 }
79 85
80 /* TODO(kuan): (BUG:30522) enable this when leak is fixed 86 TEST_F(SadTabControllerTest, ClickOnLink) {
81 TEST_F(SadTabControllerTest, TestClickOnLink) { 87 scoped_nsobject<SadTabController> controller(CreateController());
82 scoped_ptr<TabContents> tab_contents(CreateTabContents());
83 scoped_nsobject<SadTabController>
84 controller(CreateController(tab_contents.get()));
85 NSButton* link = GetLinkButton(controller); 88 NSButton* link = GetLinkButton(controller);
86 EXPECT_TRUE(link); 89 EXPECT_TRUE(link);
87 EXPECT_FALSE(link_clicked_); 90 EXPECT_FALSE(link_clicked_);
88 [link performClick:link]; 91 [link performClick:link];
89 EXPECT_TRUE(link_clicked_); 92 EXPECT_TRUE(link_clicked_);
90 } 93 }
91 */
92 94
93 } // namespace 95 } // namespace
94 96
95 @implementation NSApplication (SadTabControllerUnitTest) 97 @implementation NSApplication (SadTabControllerUnitTest)
96 // Add handler for the openLearnMoreAboutCrashLink: action to NSApp for testing 98 // Add handler for the openLearnMoreAboutCrashLink: action to NSApp for testing
97 // purposes. Normally this would be sent up the responder tree correctly, but 99 // purposes. Normally this would be sent up the responder tree correctly, but
98 // since tests run in the background, key window and main window are never set 100 // since tests run in the background, key window and main window are never set
99 // on NSApplication. Adding it to NSApplication directly removes the need for 101 // on NSApplication. Adding it to NSApplication directly removes the need for
100 // worrying about what the current window with focus is. 102 // worrying about what the current window with focus is.
101 - (void)openLearnMoreAboutCrashLink:(id)sender { 103 - (void)openLearnMoreAboutCrashLink:(id)sender {
102 SadTabControllerTest::link_clicked_ = true; 104 SadTabControllerTest::link_clicked_ = true;
103 } 105 }
104 106
105 @end 107 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698