| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/debug/debugger.h" | |
| 6 #import "base/mac/foundation_util.h" | |
| 7 #include "base/mac/scoped_nsobject.h" | |
| 8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | |
| 9 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h" | |
| 10 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_view_cocoa.h" | |
| 11 #include "chrome/common/url_constants.h" | |
| 12 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | |
| 13 #include "chrome/test/base/testing_profile.h" | |
| 14 #include "content/public/browser/web_contents.h" | |
| 15 #include "content/public/browser/web_contents_delegate.h" | |
| 16 #import "ui/base/cocoa/controls/hyperlink_text_view.h" | |
| 17 | |
| 18 @interface SadTabView (ExposedForTesting) | |
| 19 // Implementation is below. | |
| 20 - (HyperlinkTextView*)helpTextView; | |
| 21 @end | |
| 22 | |
| 23 @implementation SadTabView (ExposedForTesting) | |
| 24 - (HyperlinkTextView*)helpTextView { | |
| 25 NSView* containerView = [[self subviews] lastObject]; | |
| 26 for (NSView* view in [containerView subviews]) { | |
| 27 if (auto textView = base::mac::ObjCCast<HyperlinkTextView>(view)) | |
| 28 return textView; | |
| 29 } | |
| 30 return nil; | |
| 31 } | |
| 32 @end | |
| 33 | |
| 34 namespace { | |
| 35 | |
| 36 class ContentsDelegate : public content::WebContentsDelegate { | |
| 37 public: | |
| 38 content::WebContents* OpenURLFromTab( | |
| 39 content::WebContents* source, | |
| 40 const content::OpenURLParams& params) override { | |
| 41 opened_url_ = params.url; | |
| 42 return nullptr; | |
| 43 } | |
| 44 | |
| 45 const GURL& OpenedURL() { return opened_url_; } | |
| 46 | |
| 47 private: | |
| 48 GURL opened_url_; | |
| 49 }; | |
| 50 | |
| 51 class SadTabControllerTest : public ChromeRenderViewHostTestHarness { | |
| 52 public: | |
| 53 SadTabControllerTest() : test_window_(nil) {} | |
| 54 | |
| 55 void SetUp() override { | |
| 56 ChromeRenderViewHostTestHarness::SetUp(); | |
| 57 web_contents()->SetDelegate(&contents_delegate_); | |
| 58 // Inherting from ChromeRenderViewHostTestHarness means we can't inherit | |
| 59 // from from CocoaTest, so do a bootstrap and create test window. | |
| 60 CocoaTest::BootstrapCocoa(); | |
| 61 test_window_ = [[CocoaTestHelperWindow alloc] init]; | |
| 62 if (base::debug::BeingDebugged()) { | |
| 63 [test_window_ orderFront:nil]; | |
| 64 } else { | |
| 65 [test_window_ orderBack:nil]; | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 void TearDown() override { | |
| 70 [test_window_ close]; | |
| 71 test_window_ = nil; | |
| 72 ChromeRenderViewHostTestHarness::TearDown(); | |
| 73 } | |
| 74 | |
| 75 // Creates the controller and adds its view to contents, caller has ownership. | |
| 76 SadTabController* CreateController() { | |
| 77 SadTabController* controller = | |
| 78 [[SadTabController alloc] initWithWebContents:web_contents()]; | |
| 79 EXPECT_TRUE(controller); | |
| 80 NSView* view = [controller view]; | |
| 81 EXPECT_TRUE(view); | |
| 82 NSView* contentView = [test_window_ contentView]; | |
| 83 [contentView addSubview:view]; | |
| 84 | |
| 85 return controller; | |
| 86 } | |
| 87 | |
| 88 HyperlinkTextView* GetHelpTextView(SadTabController* controller) { | |
| 89 SadTabView* view = static_cast<SadTabView*>([controller view]); | |
| 90 return ([view helpTextView]); | |
| 91 } | |
| 92 | |
| 93 ContentsDelegate contents_delegate_; | |
| 94 CocoaTestHelperWindow* test_window_; | |
| 95 }; | |
| 96 | |
| 97 TEST_F(SadTabControllerTest, ClickOnLink) { | |
| 98 base::scoped_nsobject<SadTabController> controller(CreateController()); | |
| 99 HyperlinkTextView* help = GetHelpTextView(controller); | |
| 100 EXPECT_TRUE(help); | |
| 101 EXPECT_TRUE(contents_delegate_.OpenedURL().is_empty()); | |
| 102 [help clickedOnLink:@(chrome::kCrashReasonURL) atIndex:0]; | |
| 103 EXPECT_EQ(contents_delegate_.OpenedURL(), GURL(chrome::kCrashReasonURL)); | |
| 104 } | |
| 105 | |
| 106 } // namespace | |
| OLD | NEW |