OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 #import <EarlGrey/EarlGrey.h> |
| 6 #import <XCTest/XCTest.h> |
| 7 |
| 8 #import "components/handoff/handoff_manager.h" |
| 9 #import "ios/chrome/browser/device_sharing/device_sharing_manager.h" |
| 10 #include "ios/chrome/browser/ui/ui_util.h" |
| 11 #import "ios/chrome/test/app/chrome_test_util.h" |
| 12 #import "ios/chrome/test/app/tab_test_util.h" |
| 13 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |
| 14 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
| 15 #include "ios/web/public/test/http_server.h" |
| 16 #include "ios/web/public/test/http_server_util.h" |
| 17 #import "net/base/mac/url_conversions.h" |
| 18 #include "url/gurl.h" |
| 19 |
| 20 namespace { |
| 21 |
| 22 // Checks that Handoff will report the specified |gurl|. |
| 23 void AssertHandoffURL(const GURL& gurl) { |
| 24 HandoffManager* manager = |
| 25 [chrome_test_util::GetDeviceSharingManager() handoffManager]; |
| 26 GREYAssertTrue(manager != nil, @"Handoff Manager should not be nil"); |
| 27 if (gurl.is_valid()) { |
| 28 NSURL* URL = net::NSURLWithGURL(gurl); |
| 29 GREYAssertTrue([manager.userActivityWebpageURL isEqual:URL], |
| 30 @"Incorrect Handoff URL."); |
| 31 } else { |
| 32 GREYAssertTrue(manager.userActivityWebpageURL == nil, |
| 33 @"Handoff URL is not nil."); |
| 34 } |
| 35 } |
| 36 |
| 37 } // namespace |
| 38 |
| 39 // Tests that HandoffManager reports the correct active URL based on the |
| 40 // active tab. |
| 41 @interface HandoffManagerTestCase : ChromeTestCase |
| 42 @end |
| 43 |
| 44 @implementation HandoffManagerTestCase |
| 45 |
| 46 #pragma mark - Overrides base class |
| 47 |
| 48 - (void)setUp { |
| 49 [super setUp]; |
| 50 web::test::SetUpFileBasedHttpServer(); |
| 51 } |
| 52 |
| 53 #pragma mark - Tests |
| 54 |
| 55 // Tests that an empty new tab page should result in no Handoff URL. |
| 56 - (void)testNewTabPageEmptyURL { |
| 57 AssertHandoffURL(GURL()); |
| 58 } |
| 59 |
| 60 // Tests that the simple case of Handoff URL for a single page. |
| 61 - (void)testTypicalURL { |
| 62 const GURL destinationUrl = web::test::HttpServer::MakeUrl( |
| 63 "http://ios/testing/data/http_server_files/destination.html"); |
| 64 [ChromeEarlGrey loadURL:destinationUrl]; |
| 65 AssertHandoffURL(destinationUrl); |
| 66 } |
| 67 |
| 68 // Tests Handoff URL for a new tab. |
| 69 - (void)testTypicalURLInNewTab { |
| 70 chrome_test_util::OpenNewTab(); |
| 71 const GURL destinationUrl = web::test::HttpServer::MakeUrl( |
| 72 "http://ios/testing/data/http_server_files/pony.html"); |
| 73 [ChromeEarlGrey loadURL:destinationUrl]; |
| 74 AssertHandoffURL(destinationUrl); |
| 75 } |
| 76 |
| 77 // Tests that Handoff URL should never be set for an incognito tab. |
| 78 - (void)testTypicalURLInNewIncognitoTab { |
| 79 // Opens an incognito tab and loads a web page. Check that Handoff URL is nil. |
| 80 chrome_test_util::OpenNewIncognitoTab(); |
| 81 const GURL destinationUrl = web::test::HttpServer::MakeUrl( |
| 82 "http://ios/testing/data/http_server_files/destination.html"); |
| 83 [ChromeEarlGrey loadURL:destinationUrl]; |
| 84 AssertHandoffURL(GURL()); |
| 85 |
| 86 // Loads a second URL on the same incognito tab. Handoff URL should still be |
| 87 // nil. |
| 88 const GURL destinationUrl2 = web::test::HttpServer::MakeUrl( |
| 89 "http://ios/testing/data/http_server_files/pony.html"); |
| 90 [ChromeEarlGrey loadURL:destinationUrl2]; |
| 91 AssertHandoffURL(GURL()); |
| 92 } |
| 93 |
| 94 // Tests the state for Handoff URL when creating, closing tab, and switching |
| 95 // tab. |
| 96 - (void)testMultipleSwitchingTabs { |
| 97 const GURL tab1URL = web::test::HttpServer::MakeUrl( |
| 98 "http://ios/testing/data/http_server_files/destination.html"); |
| 99 const GURL tab2URL = web::test::HttpServer::MakeUrl( |
| 100 "http://ios/testing/data/http_server_files/pony.html"); |
| 101 const GURL tab3URL = web::test::HttpServer::MakeUrl( |
| 102 "http://ios/testing/data/http_server_files/chromium_logo_page.html"); |
| 103 |
| 104 // Sets up the state for 3 tabs. |
| 105 [ChromeEarlGrey loadURL:tab1URL]; |
| 106 chrome_test_util::OpenNewTab(); |
| 107 [ChromeEarlGrey loadURL:tab2URL]; |
| 108 chrome_test_util::OpenNewTab(); |
| 109 [ChromeEarlGrey loadURL:tab3URL]; |
| 110 |
| 111 // When tab 3 is closed, tab 2 is front and Handoff URL should be the URL for |
| 112 // tab 2. |
| 113 chrome_test_util::CloseCurrentTab(); |
| 114 AssertHandoffURL(tab2URL); |
| 115 |
| 116 // Switches back to the first tab. |
| 117 chrome_test_util::SelectTabAtIndexInCurrentMode(0); |
| 118 AssertHandoffURL(tab1URL); |
| 119 } |
| 120 |
| 121 // Tests the state for Handoff URL when switching between normal tabs and |
| 122 // incognito tabs. |
| 123 - (void)testSwitchBetweenNormalAndIncognitoTabs { |
| 124 const GURL tab1URL = web::test::HttpServer::MakeUrl( |
| 125 "http://ios/testing/data/http_server_files/destination.html"); |
| 126 const GURL tab2URL = web::test::HttpServer::MakeUrl( |
| 127 "http://ios/testing/data/http_server_files/pony.html"); |
| 128 const GURL tab3URL = web::test::HttpServer::MakeUrl( |
| 129 "http://ios/testing/data/http_server_files/chromium_logo_page.html"); |
| 130 |
| 131 // Loads one page. |
| 132 [ChromeEarlGrey loadURL:tab1URL]; |
| 133 // Loads page two in incognito and verifies that Handoff URL is nil. |
| 134 chrome_test_util::OpenNewIncognitoTab(); |
| 135 [ChromeEarlGrey loadURL:tab2URL]; |
| 136 AssertHandoffURL(GURL()); |
| 137 |
| 138 // Loads page three in a new normal tab and verify that Handoff URL is not |
| 139 // nil. |
| 140 chrome_test_util::OpenNewTab(); |
| 141 [ChromeEarlGrey loadURL:tab3URL]; |
| 142 AssertHandoffURL(tab3URL); |
| 143 } |
| 144 |
| 145 @end |
OLD | NEW |