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

Unified Diff: chrome/browser/ui/cocoa/tab_contents/sad_tab_controller_unittest.mm

Issue 2247493003: [Mac] Clean up SadTabView and let SadTabController provide its content (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use base::mac::ObjCCast Created 4 years, 4 months 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 side-by-side diff with in-line comments
Download patch
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..f7fee6b223e52672568f7e3199d4a581829dd809 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,28 @@
namespace {
-class SadTabControllerTest : public ChromeRenderViewHostTestHarness {
+class ContentsDelegate : public content::WebContentsDelegate {
public:
- SadTabControllerTest() : test_window_(nil) {
- link_clicked_ = false;
+ content::WebContents* OpenURLFromTab(
+ content::WebContents* source,
+ const content::OpenURLParams& params) override {
+ opened_url_ = params.url;
+ return nullptr;
}
+ const GURL& OpenedURL() { return opened_url_; }
+
+ private:
+ GURL opened_url_;
+};
+
+class SadTabControllerTest : public ChromeRenderViewHostTestHarness {
+ public:
+ 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 +90,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_.OpenedURL().is_empty());
[help clickedOnLink:@(chrome::kCrashReasonURL) atIndex:0];
- EXPECT_TRUE(link_clicked_);
+ EXPECT_EQ(contents_delegate_.OpenedURL(), 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
« no previous file with comments | « chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.mm ('k') | chrome/browser/ui/cocoa/tab_contents/sad_tab_view_cocoa.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698