Chromium Code Reviews| Index: chrome/browser/ui/cocoa/tab_contents/sad_tab_controller_unittest.mm |
| diff --git a/chrome/browser/ui/cocoa/tab_contents/sad_tab_controller_unittest.mm b/chrome/browser/ui/cocoa/tab_contents/sad_tab_controller_unittest.mm |
| index f9c47faf1c8d53d090cf1292088d83164f74d848..43d3feea9dc17633c9690a01fe2f8f4145c57d3f 100644 |
| --- a/chrome/browser/ui/cocoa/tab_contents/sad_tab_controller_unittest.mm |
| +++ b/chrome/browser/ui/cocoa/tab_contents/sad_tab_controller_unittest.mm |
| @@ -11,6 +11,8 @@ |
| #include "chrome/common/url_constants.h" |
| #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| #include "chrome/test/base/testing_profile.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "content/public/browser/web_contents_delegate.h" |
| #import "ui/base/cocoa/controls/hyperlink_text_view.h" |
| @interface SadTabView (ExposedForTesting) |
| @@ -31,14 +33,24 @@ |
| namespace { |
| +struct ContentsDelegate : public content::WebContentsDelegate { |
|
Avi (use Gerrit)
2016/08/12 23:06:22
This should be a class.
https://google.github.io/
Sidney San Martín
2016/08/12 23:35:10
Done.
|
| + GURL opened_url; |
| + |
| + content::WebContents* OpenURLFromTab( |
| + content::WebContents* source, |
| + const content::OpenURLParams& params) override { |
| + opened_url = params.url; |
| + return nullptr; |
| + } |
| +}; |
| + |
| class SadTabControllerTest : public ChromeRenderViewHostTestHarness { |
| public: |
| - SadTabControllerTest() : test_window_(nil) { |
| - link_clicked_ = false; |
| - } |
| + SadTabControllerTest() : test_window_(nil) {} |
| void SetUp() override { |
| ChromeRenderViewHostTestHarness::SetUp(); |
| + web_contents()->SetDelegate(&contents_delegate_); |
| // Inherting from ChromeRenderViewHostTestHarness means we can't inherit |
| // from from CocoaTest, so do a bootstrap and create test window. |
| CocoaTest::BootstrapCocoa(); |
| @@ -74,32 +86,17 @@ class SadTabControllerTest : public ChromeRenderViewHostTestHarness { |
| return ([view helpTextView]); |
| } |
| - static bool link_clicked_; |
| + ContentsDelegate contents_delegate_; |
| CocoaTestHelperWindow* test_window_; |
| }; |
| -// static |
| -bool SadTabControllerTest::link_clicked_; |
| - |
| TEST_F(SadTabControllerTest, ClickOnLink) { |
| base::scoped_nsobject<SadTabController> controller(CreateController()); |
| HyperlinkTextView* help = GetHelpTextView(controller); |
| EXPECT_TRUE(help); |
| - EXPECT_FALSE(link_clicked_); |
| + EXPECT_TRUE(contents_delegate_.opened_url.is_empty()); |
| [help clickedOnLink:@(chrome::kCrashReasonURL) atIndex:0]; |
| - EXPECT_TRUE(link_clicked_); |
| + EXPECT_EQ(contents_delegate_.opened_url, GURL(chrome::kCrashReasonURL)); |
| } |
| } // namespace |
| - |
| -@implementation NSApplication (SadTabControllerUnitTest) |
| -// Add handler for the openLearnMoreAboutCrashLink: action to NSApp for testing |
| -// purposes. Normally this would be sent up the responder tree correctly, but |
| -// since tests run in the background, key window and main window are never set |
| -// on NSApplication. Adding it to NSApplication directly removes the need for |
| -// worrying about what the current window with focus is. |
| -- (void)openLearnMoreAboutCrashLink:(id)sender { |
| - SadTabControllerTest::link_clicked_ = true; |
| -} |
| - |
| -@end |