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 040018887e7e94eab9f68be8a805f1e2467376ff..a136a1267f4744dd7b2011a483903a20b1e2d52f 100644 |
--- a/chrome/browser/app_controller_mac_browsertest.mm |
+++ b/chrome/browser/app_controller_mac_browsertest.mm |
@@ -35,11 +35,9 @@ |
#include "chrome/common/pref_names.h" |
#include "chrome/common/url_constants.h" |
#include "chrome/test/base/in_process_browser_test.h" |
-#include "chrome/test/base/ui_test_utils.h" |
#include "components/bookmarks/test/bookmark_test_helpers.h" |
#include "components/signin/core/common/profile_management_switches.h" |
#include "content/public/browser/web_contents.h" |
-#include "content/public/test/browser_test_utils.h" |
#include "content/public/test/test_navigation_observer.h" |
#include "extensions/browser/app_window/app_window_registry.h" |
#include "extensions/common/extension.h" |
@@ -483,144 +481,3 @@ IN_PROC_BROWSER_TEST_F(AppControllerMainMenuBrowserTest, |
} |
} // namespace |
- |
-//--------------------------AppControllerHandoffBrowserTest--------------------- |
- |
-static GURL g_handoff_url; |
- |
-@interface AppController (BrowserTest) |
-- (BOOL)new_shouldUseHandoff; |
-- (void)new_passURLToHandoffManager:(const GURL&)handoffURL; |
-@end |
- |
-@implementation AppController (BrowserTest) |
-- (BOOL)new_shouldUseHandoff { |
- return YES; |
-} |
- |
-- (void)new_passURLToHandoffManager:(const GURL&)handoffURL { |
- g_handoff_url = handoffURL; |
-} |
-@end |
- |
-namespace { |
- |
-class AppControllerHandoffBrowserTest : public InProcessBrowserTest { |
- protected: |
- AppControllerHandoffBrowserTest() {} |
- |
- // Exchanges the implementations of the two selectors on the class |
- // AppController. |
- void ExchangeSelectors(SEL originalMethod, SEL newMethod) { |
- Class appControllerClass = NSClassFromString(@"AppController"); |
- |
- ASSERT_TRUE(appControllerClass != nil); |
- |
- Method original = |
- class_getInstanceMethod(appControllerClass, originalMethod); |
- Method destination = class_getInstanceMethod(appControllerClass, newMethod); |
- |
- ASSERT_TRUE(original != NULL); |
- ASSERT_TRUE(destination != NULL); |
- |
- method_exchangeImplementations(original, destination); |
- } |
- |
- // Swizzle Handoff related implementations. |
- void SetUpInProcessBrowserTestFixture() override { |
- // Handoff is only available on OSX 10.10+. This swizzle makes the logic |
- // run on all OSX versions. |
- SEL originalMethod = @selector(shouldUseHandoff); |
- SEL newMethod = @selector(new_shouldUseHandoff); |
- ExchangeSelectors(originalMethod, newMethod); |
- |
- // This swizzle intercepts the URL that would be sent to the Handoff |
- // Manager, and instead puts it into a variable accessible to this test. |
- originalMethod = @selector(passURLToHandoffManager:); |
- newMethod = @selector(new_passURLToHandoffManager:); |
- ExchangeSelectors(originalMethod, newMethod); |
- } |
- |
- // Closes the tab, and waits for the close to finish. |
- void CloseTab(Browser* browser, int index) { |
- content::WebContentsDestroyedWatcher destroyed_watcher( |
- browser->tab_strip_model()->GetWebContentsAt(index)); |
- browser->tab_strip_model()->CloseWebContentsAt( |
- index, TabStripModel::CLOSE_CREATE_HISTORICAL_TAB); |
- destroyed_watcher.Wait(); |
- } |
-}; |
- |
-// Tests that as a user switches between tabs, navigates within a tab, and |
-// switches between browser windows, the correct URL is being passed to the |
-// Handoff. |
-IN_PROC_BROWSER_TEST_F(AppControllerHandoffBrowserTest, TestHandoffURLs) { |
- ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
- EXPECT_EQ(g_handoff_url, GURL(url::kAboutBlankURL)); |
- |
- // Test that navigating to a URL updates the handoff URL. |
- GURL test_url1 = embedded_test_server()->GetURL("/title1.html"); |
- ui_test_utils::NavigateToURL(browser(), test_url1); |
- EXPECT_EQ(g_handoff_url, test_url1); |
- |
- // Test that opening a new tab updates the handoff URL. |
- GURL test_url2 = embedded_test_server()->GetURL("/title2.html"); |
- chrome::NavigateParams params(browser(), test_url2, ui::PAGE_TRANSITION_LINK); |
- params.disposition = NEW_FOREGROUND_TAB; |
- ui_test_utils::NavigateToURL(¶ms); |
- EXPECT_EQ(g_handoff_url, test_url2); |
- |
- // Test that switching tabs updates the handoff URL. |
- browser()->tab_strip_model()->ActivateTabAt(0, true); |
- EXPECT_EQ(g_handoff_url, test_url1); |
- |
- // Test that closing the current tab updates the handoff URL. |
- CloseTab(browser(), 0); |
- EXPECT_EQ(g_handoff_url, test_url2); |
- |
- // Test that opening a new browser window updates the handoff URL. |
- GURL test_url3 = embedded_test_server()->GetURL("/title3.html"); |
- ui_test_utils::NavigateToURLWithDisposition( |
- browser(), GURL(test_url3), NEW_WINDOW, |
- ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); |
- EXPECT_EQ(g_handoff_url, test_url3); |
- |
- // Check that there are exactly 2 browsers. |
- BrowserList* active_browser_list = |
- BrowserList::GetInstance(chrome::GetActiveDesktop()); |
- EXPECT_EQ(2u, active_browser_list->size()); |
- |
- // Close the one and only tab for the second browser window. |
- Browser* browser2 = active_browser_list->get(1); |
- CloseTab(browser2, 0); |
- base::RunLoop().RunUntilIdle(); |
- EXPECT_EQ(g_handoff_url, test_url2); |
- |
- // The URLs of incognito windows should not be passed to Handoff. |
- GURL test_url4 = embedded_test_server()->GetURL("/simple.html"); |
- ui_test_utils::NavigateToURLWithDisposition( |
- browser(), GURL(test_url4), OFF_THE_RECORD, |
- ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); |
- EXPECT_EQ(g_handoff_url, GURL()); |
- |
- // Open a new tab in the incognito window. |
- EXPECT_EQ(2u, active_browser_list->size()); |
- Browser* browser3 = active_browser_list->get(1); |
- ui_test_utils::NavigateToURLWithDisposition( |
- browser3, test_url4, NEW_FOREGROUND_TAB, |
- ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
- EXPECT_EQ(g_handoff_url, GURL()); |
- |
- // Navigate the current tab in the incognito window. |
- ui_test_utils::NavigateToURLWithDisposition( |
- browser3, test_url1, CURRENT_TAB, |
- ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
- EXPECT_EQ(g_handoff_url, GURL()); |
- |
- // Activate the original browser window. |
- Browser* browser1 = active_browser_list->get(0); |
- browser1->window()->Show(); |
- EXPECT_EQ(g_handoff_url, test_url2); |
-} |
- |
-} // namespace |