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

Unified Diff: chrome/browser/app_controller_mac_browsertest.mm

Issue 678423003: mac: Opening a URL should replace the NTP. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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/app_controller_mac_browsertest.mm
diff --git a/chrome/browser/app_controller_mac_browsertest.mm b/chrome/browser/app_controller_mac_browsertest.mm
index f8442c765f5f930221905f2775829d82b536a28c..fe8fe2d93b108d977284f52d94b38e837bd68f78 100644
--- a/chrome/browser/app_controller_mac_browsertest.mm
+++ b/chrome/browser/app_controller_mac_browsertest.mm
@@ -41,6 +41,36 @@ namespace {
GURL g_open_shortcut_url = GURL::EmptyGURL();
+// Returns an Apple Event that instructs the application to open |url|.
+NSAppleEventDescriptor* AppleEventToOpenUrl(const GURL& url) {
+ NSAppleEventDescriptor* shortcut_event = [[[NSAppleEventDescriptor alloc]
+ initWithEventClass:kASAppleScriptSuite
+ eventID:kASSubroutineEvent
+ targetDescriptor:nil
+ returnID:kAutoGenerateReturnID
+ transactionID:kAnyTransactionID] autorelease];
+ NSString* url_string = [NSString stringWithUTF8String:url.spec().c_str()];
+ [shortcut_event setParamDescriptor:[NSAppleEventDescriptor
+ descriptorWithString:url_string]
+ forKeyword:keyDirectObject];
+ return shortcut_event;
+}
+
+// Instructs the NSApp's delegate to open |url|.
+void SendAppleEventToOpenUrlToAppController(const GURL& url) {
+ AppController* controller =
+ base::mac::ObjCCast<AppController>([NSApp delegate]);
+ Method get_url =
+ class_getInstanceMethod([controller class], @selector(getUrl:withReply:));
+
+ ASSERT_TRUE(get_url);
+
+ NSAppleEventDescriptor* shortcut_event =
+ AppleEventToOpenUrl(g_open_shortcut_url);
+
+ method_invoke(controller, get_url, shortcut_event, NULL);
+}
+
} // namespace
@interface TestOpenShortcutOnStartup : NSObject
@@ -53,28 +83,7 @@ GURL g_open_shortcut_url = GURL::EmptyGURL();
if (!g_open_shortcut_url.is_valid())
return;
- AppController* controller =
- base::mac::ObjCCast<AppController>([NSApp delegate]);
- Method getUrl = class_getInstanceMethod([controller class],
- @selector(getUrl:withReply:));
-
- if (getUrl == nil)
- return;
-
- base::scoped_nsobject<NSAppleEventDescriptor> shortcutEvent(
- [[NSAppleEventDescriptor alloc]
- initWithEventClass:kASAppleScriptSuite
- eventID:kASSubroutineEvent
- targetDescriptor:nil
- returnID:kAutoGenerateReturnID
- transactionID:kAnyTransactionID]);
- NSString* url =
- [NSString stringWithUTF8String:g_open_shortcut_url.spec().c_str()];
- [shortcutEvent setParamDescriptor:
- [NSAppleEventDescriptor descriptorWithString:url]
- forKeyword:keyDirectObject];
-
- method_invoke(controller, getUrl, shortcutEvent.get(), NULL);
+ SendAppleEventToOpenUrlToAppController(g_open_shortcut_url);
}
@end
@@ -330,4 +339,36 @@ IN_PROC_BROWSER_TEST_F(AppControllerOpenShortcutBrowserTest,
->GetLastCommittedURL());
}
+class AppControllerReplaceNTPBrowserTest : public InProcessBrowserTest {
+ protected:
+ AppControllerReplaceNTPBrowserTest() {}
+};
+
+// Tests that when a GURL is opened after startup, it replaces the NTP.
+IN_PROC_BROWSER_TEST_F(AppControllerReplaceNTPBrowserTest,
+ ReplaceNTPAfterStartup) {
+ // Ensure that there is exactly 1 tab showing, and the tab is the NTP.
+ GURL ntp(chrome::kChromeUINewTabURL);
+ ui_test_utils::NavigateToURLWithDisposition(
+ browser(),
+ ntp,
+ CURRENT_TAB,
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
+ EXPECT_EQ(1, browser()->tab_strip_model()->count());
+ EXPECT_EQ(ntp,
+ browser()
+ ->tab_strip_model()
+ ->GetActiveWebContents()
+ ->GetLastCommittedURL());
+
+ GURL simple(embedded_test_server()->GetURL("/simple.html"));
+ SendAppleEventToOpenUrlToAppController(simple);
+ EXPECT_EQ(1, browser()->tab_strip_model()->count());
+ EXPECT_EQ(simple,
+ browser()
+ ->tab_strip_model()
+ ->GetActiveWebContents()
+ ->GetLastCommittedURL());
+}
+
} // namespace
« chrome/browser/app_controller_mac.mm ('K') | « chrome/browser/app_controller_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698