OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/debug/debugger.h" | 5 #include "base/debug/debugger.h" |
6 #include "base/memory/scoped_nsobject.h" | 6 #include "base/memory/scoped_nsobject.h" |
7 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 7 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
8 #import "chrome/browser/ui/cocoa/hyperlink_text_view.h" | 8 #import "chrome/browser/ui/cocoa/hyperlink_text_view.h" |
9 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h" | 9 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h" |
10 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_view.h" | 10 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_view.h" |
| 11 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
11 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
12 #include "content/browser/renderer_host/test_render_view_host.h" | |
13 #include "content/browser/tab_contents/test_tab_contents.h" | 13 #include "content/browser/tab_contents/test_tab_contents.h" |
14 | 14 |
15 @interface SadTabView (ExposedForTesting) | 15 @interface SadTabView (ExposedForTesting) |
16 // Implementation is below. | 16 // Implementation is below. |
17 - (HyperlinkTextView*)helpTextView; | 17 - (HyperlinkTextView*)helpTextView; |
18 @end | 18 @end |
19 | 19 |
20 @implementation SadTabView (ExposedForTesting) | 20 @implementation SadTabView (ExposedForTesting) |
21 - (HyperlinkTextView*)helpTextView { | 21 - (HyperlinkTextView*)helpTextView { |
22 return help_.get(); | 22 return help_.get(); |
23 } | 23 } |
24 @end | 24 @end |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 class SadTabControllerTest : public RenderViewHostTestHarness { | 28 class SadTabControllerTest : public ChromeRenderViewHostTestHarness { |
29 public: | 29 public: |
30 SadTabControllerTest() : test_window_(nil) { | 30 SadTabControllerTest() : test_window_(nil) { |
31 link_clicked_ = false; | 31 link_clicked_ = false; |
32 } | 32 } |
33 | 33 |
34 virtual void SetUp() { | 34 virtual void SetUp() { |
35 RenderViewHostTestHarness::SetUp(); | 35 ChromeRenderViewHostTestHarness::SetUp(); |
36 // Inherting from RenderViewHostTestHarness means we can't inherit from | 36 // Inherting from ChromeRenderViewHostTestHarness means we can't inherit |
37 // from CocoaTest, so do a bootstrap and create test window. | 37 // from from CocoaTest, so do a bootstrap and create test window. |
38 CocoaTest::BootstrapCocoa(); | 38 CocoaTest::BootstrapCocoa(); |
39 test_window_ = [[CocoaTestHelperWindow alloc] init]; | 39 test_window_ = [[CocoaTestHelperWindow alloc] init]; |
40 if (base::debug::BeingDebugged()) { | 40 if (base::debug::BeingDebugged()) { |
41 [test_window_ orderFront:nil]; | 41 [test_window_ orderFront:nil]; |
42 } else { | 42 } else { |
43 [test_window_ orderBack:nil]; | 43 [test_window_ orderBack:nil]; |
44 } | 44 } |
45 } | 45 } |
46 | 46 |
47 virtual void TearDown() { | 47 virtual void TearDown() { |
48 [test_window_ close]; | 48 [test_window_ close]; |
49 test_window_ = nil; | 49 test_window_ = nil; |
50 RenderViewHostTestHarness::TearDown(); | 50 ChromeRenderViewHostTestHarness::TearDown(); |
51 } | 51 } |
52 | 52 |
53 // Creates the controller and adds its view to contents, caller has ownership. | 53 // Creates the controller and adds its view to contents, caller has ownership. |
54 SadTabController* CreateController() { | 54 SadTabController* CreateController() { |
55 NSView* contentView = [test_window_ contentView]; | 55 NSView* contentView = [test_window_ contentView]; |
56 SadTabController* controller = | 56 SadTabController* controller = |
57 [[SadTabController alloc] initWithTabContents:contents() | 57 [[SadTabController alloc] initWithTabContents:contents() |
58 superview:contentView]; | 58 superview:contentView]; |
59 EXPECT_TRUE(controller); | 59 EXPECT_TRUE(controller); |
60 NSView* view = [controller view]; | 60 NSView* view = [controller view]; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 // Add handler for the openLearnMoreAboutCrashLink: action to NSApp for testing | 105 // Add handler for the openLearnMoreAboutCrashLink: action to NSApp for testing |
106 // purposes. Normally this would be sent up the responder tree correctly, but | 106 // purposes. Normally this would be sent up the responder tree correctly, but |
107 // since tests run in the background, key window and main window are never set | 107 // since tests run in the background, key window and main window are never set |
108 // on NSApplication. Adding it to NSApplication directly removes the need for | 108 // on NSApplication. Adding it to NSApplication directly removes the need for |
109 // worrying about what the current window with focus is. | 109 // worrying about what the current window with focus is. |
110 - (void)openLearnMoreAboutCrashLink:(id)sender { | 110 - (void)openLearnMoreAboutCrashLink:(id)sender { |
111 SadTabControllerTest::link_clicked_ = true; | 111 SadTabControllerTest::link_clicked_ = true; |
112 } | 112 } |
113 | 113 |
114 @end | 114 @end |
OLD | NEW |